You can't. In a JITted VM, there's a fairly vague relationship between
the bytecodes in the class file and what actually happens at runtime,
and practically all current VMs not on mobile devices are JITted.
agreed...
a JIT is not "particularly" difficult to implement (vs many other things
likely found around in a VM, ...), and a JIT (even a very naive one)
usually offers a fairly drastic speedup vs an interpreter.
about the only real time then not to use a JIT is when one is operating
within a fairly confined memory footprint (since one needs memory for
both the bytecode, the produced machine code, and any temporary memory
needed for the JIT to "do its thing"...), or otherwise finds keeping
code size or complexity down is a bigger concern than raw performance.
Yes. So don't use it in real-time programs.
yep. if one really wants to be fussy, one can say not to use Java or C++
in real-time programs, and should instead stick purely to C and ASM.
in my experiences (mostly with soft-real-time), the bigger concern is
usually that operations don't take "too long", but the exact timing of
individual operations is usually not too important so long as they get
done "sufficiently quickly" (and any long and potentially obvious stalls
can be avoided).
but, anyways, the costs of a dynamic call need not be much different
than that associated with calling via an interface (depending on
implementation specifics).
Yes, but not cleanly or efficiently.
yes. method calls are not free...
absent special-case trickery (hacking class/method specific logic into
the JIT, ...), there is no real way to work around the various costs of
performing a method call, whereas a special opcode may be much easier to
optimize (the JIT can emit machine-code or similar directly for the
opcode in question).
also shoving more special-case logic into a single instruction also
tends to make it more expensive to execute with or JIT.
granted, in my custom VM I have put in quite a few added instructions
(mostly escape-coded opcodes), but thus far none of them are really used
at present (errm, mostly because I am using the thing mostly for Java
and compiling said code with a standard-ish compiler, namely IBM's...).
I tried using the Sun/Oracle JDK's compiler, but it seemed to refuse to
accept a lot of my code, probably either because I am building my own
custom class libraries (for my VM), or because some of the internal
class-library classes have underscores in their classnames, I have not
really looked into it (if it is the underscores, I may need to get
around to changing them eventually).
or such...