|
|
|
|
|
by pjmlp
3796 days ago
|
|
Because JIT compilers are able to bend the rules if proven correct. For example, if you declare something like final class Point {
final int x, y;
//...
}
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. |
|
Why ? Because it just went from O(N) with no allocations to O(N^2) because it has to constantly extend and walk a list (the free memory list, which is lower bounded by the number of iterations of the loop) on every iteration of the loop (malloc is O(N), so calling malloc in a loop automatically increases it's complexity, and compilers change stack allocations into mallocs due to optimizations).
I've seen this happen many times. And then, after 2 weeks of searching you find the cause : someone changed 3 * i into i * 3 in a method which caused autoboxing to suddenly actually occur.
Counting on compiler optimizations to save your ass is incredibly, incredibly brittle.