Or, what actually goes on in the inner loop of the JVM?
I suppose this is a rather implementation-specific question, but how actually does the JVM run bytecodes? The most naive method might consist of a giant switch case - using C syntax:
while(bytecode = *instruction_pointer++){
switch(bytecode){
case AALOAD:
//...
case AASTORE:
//...
case ACONST_NULL:
//...
//... 256 cases ...
}
}
Obviously, this is exceedingly slow and would not be remotely capable of the speeds we see Java reaching in the real world.
Another way might be to compile longer "runs" of bytecodes into machine code, then JMPing to this machine code, with a JMP back to the JVM at the end after it's done. This seems possibly more efficient, but whether it's actually possible to efficiently translate bytecodes into equivalent machine language instructions (especially cross-platform!) is dubious.
This is obviously a question that could be answered with multiple PhD-thesis-long papers, but could anyone give a general, high-level idea of how the bytecodes are actually processed? Or mention a few clever tricks that are used in the real JVM?
Thanks in advance! JITs are amazingly cool.