3 ms·
It can only make safe assumptions. Assuming a global mutable variable will never change is generally not a safe assumption. I suppose, at least in principle,
by mumblemumble 5y ago
It can only make safe assumptions.
Assuming a global mutable variable will never change is generally not a safe assumption.
I suppose, at least in principle, that something like the GraalVM AOT compiler has the option to scan all of the code to verify that it never is mutated. But HotSpot cannot, because it only JITs code as it is loaded.
- chrisseaton 5y ago> Assuming a global mutable variable will never change is generally not a safe assumption. Put your logging level behind a switch point and C2 will treat it as a constant but still let it be changed - that works today.
- eropple 5y agoObviously with your background you know this offhand, but is there a mere-mortals reference for JVM JIT behaviors and capabilities to keep in one's back pocket? I have a pretty strong understanding of a lot of the Java universe (particularly around the JMM) but modern JVM JIT behaviors are a black box to me.
- hyperman1 5y agoActually this is not true. Hotspot can deoptimize code. It optimizes making some assumptions. If these assumptions stop holding, code gets deoptimized, measured for a while, and reoptimized with new assumptions. For example, an interface implemented by only 1 class might get the class inlined. If a second implementer pops up (which can happen at runtime for e.g. some dynamically generated class), all of this will get undone. There was a series of small articles with all these things, but I can't seem to find them right now.