JITs can identify and address certain conditions that can only be known at run time. A striking example is the elimination of virtual calls used by modern virtual machines - for example, when the JVM finds an invokevirtual or invokeinterface , if only one class overriding the called method has been loaded, the virtual machine can actually make this virtual call static and thus can inline him. On the other hand, for program C, a function pointer is always a pointer to a function, and a call to it cannot be embedded (in the general case, one way or another).
Here's a situation where the JVM can embed a virtual call:
interface I { I INSTANCE = Boolean.getBoolean("someCondition")? new A() : new B(); void doIt(); } class A implements I { void doIt(){ ... } } class B implements I { void doIt(){ ... } }
Assuming we do not go around creating instances of A or B elsewhere and that someCondition set to true , the JVM knows that calling doIt() always means A.doIt and therefore can avoid looking up the method table and then embed the call. A similar design in a non-JIT environment would not be permeable.
gustafc Dec 10 '09 at 7:45 2009-12-10 07:45
source share