This post talks about the CLI virtual machine instead of the JVM, but each of them is capable of doing such things, so I think this is relevant.
I solve this specific problem in a special way for my JIT. Note that the description here is conceptual, and the code implements it somewhat differently for performance reasons. When I load the assembly, I make a note in the method descriptor if it simply returns a member field. When I use other methods again, I replace all call instructions with these methods in byte code with the ldfld instruction before passing it to the native code generator. That way I can:
- Save time in JIT (
ldfld reduces CPU time to JIT than call ). - Built-in properties even in the base compiler .
- By and large, ensuring that using the public properties / private fields template does not result in a performance penalty of any kind when the debugger is disconnected. (When a debugger is connected, I cannot embed accessors.)
I have no doubt that big names in VM technologies already implement something similar (and probably better) in their products.
source share