Multiple this$1 fields when mixing subclassing and inner classes
Stefan Reich
stefan.reich.maker.of.eye at googlemail.com
Mon Sep 9 22:24:41 UTC 2019
Consider these classes:
class A {
class InnerA {}
}
class B extends A {
class InnerB extends InnerA {}
}
When I run some introspection on B.InnerB, I find HotSpot producing this
object layout:
Size of object B$InnerB: 24 bytes
Field A$InnerA . this$1 is at offset 12
Field B$InnerB . this$1 is at offset 16
So the object has *two* outer references, one of type A and one of type B.
That is all fair and good, but: These two references *will always point to
the same object*. This follows from the syntactic rules on the Java level.
(<< Crucial part of the argument, so - is this correct?)
So, the question is: Wouldn't it save some RAM to just have one "this$1"
field?
The only downside would be that accesses to this$1 from code inside InnerB
would require a cast, as the remaining this$1 field would formally only
have type A.
I'm curious as to where there has ever been deliberation of this?
Best regards,
Stefan
--
Stefan Reich
BotCompany.de // Java-based operating systems
More information about the hotspot-dev
mailing list