2 ms·
> * I want to allocate an object (by value - not by pointer) straight onto the stack (not the heap). The JVM does escape analysis to perform this in cases wher
by singron 6y ago
> * I want to allocate an object (by value - not by pointer) straight onto the stack (not the heap).
The JVM does escape analysis to perform this in cases where it can prove the lifetimes will work.
> * I want to specify that a class completely opts out of inheritance so that the compiler knows which exact method I'm calling (static dispatch) and can inline appropriately.
I think this is the final modifier?
The problem with all of these are that despite java having static types, the JVM is fairly dynamic. It's difficult to really guarantee anything at the source level because you don't know what classes will actually get loaded into the JVM. Even without inheritance, you can even load multiple versions of the same class simultaneously with different classloaders. Thus it's difficult to guarantee any optimizations at the source level in java. The JVM has to see what classes actually get loaded before it can make optimization decisions.
Having different classes at runtime and compile time is actually pretty common too. E.g. in gradle if you have a implementation dependency on liba, which depends on libb=2.0, you can also have a runtime dependency on libc, which depends on libb=3.0. This would cause you to compile against libb=2.0 but run against libb=3.0.