|
|
|
|
|
by iofj
3796 days ago
|
|
Maybe I'm unclear on some of the details here, but here goes https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.htm... "Whenever a new class instance is created, memory space is allocated for it with room for all the instance variables declared in the class type and all the instance variables declared in each superclass of the class type, including all the instance variables that may be hidden (ยง8.3)." Doesn't seem to allow for escape analysis eliminating the object. Plus escape analysis wouldn't really save you. These are class instances, you pretty much have to declare them before the scope you use them in, if you're using them in the condition of a while loop (which would be the way to use them). I seem to have this experience in practice. If you have a value type and loop over it, creating a "dummy" instance of it outside of the loop, then erase and reset it's inner state on every loop iteration is far faster than creating an instance inside the loop. So I don't think escape analysis optimizes this case. |
|
For example, if you declare something like
The Azul JIT compiler will transform it into a struct, just like in C, via their "StructuredArray and ObjectLayout" optimizations.IBM J9 also does similar optimizations via packed objects, as they call it.
JIT compilers also remove locks and synchronized blocks if heuristics prove their are never needed in the dataflow.
In any case, by Java 10, real value types are expected to be part of the language.