Java – where does JIT compiled code reside?

So I have this method written in Java:

public void myMethod(int y){
    int x = 5 + y;
    doSomething(x);
}

And suppose my application calls many times

When running compiled code for this method on the Java virtual machine, the JVM will first interpret the method Then after a period of time, if I understand it correctly, it will decide to compile it into machine language

At this moment,

Will it be overwritten by machine code in memory? If it is covered, how will the problem of size difference be solved? If it is written to another location in memory, will the bytecode loaded into memory be released? Moreover, if both bytecode and JIT compiled code are in memory, how does the JVM decide to execute JIT compiled code instead of bytecode when the application encounters this method again?

Solution

The hotspot JVM has a method structure in Metaspace (or permgen in earlier versions)

Methods may have multiple entry points:

> _ i2i_ Entry – pointer to bytecode interpreter. >_ code-> entry_ Point () – the entry point for JIT compiled code The compilation method resides in codecache – a special area of native memory where VM dynamically generates code. > I2C and c2i adapters call compiled code from the interpreter and vice versa These adapters are necessary because the interpreted method and the compiled method have different calling conventions (how to pass parameters, how to construct frames, etc.)

In some rare cases, compiled methods may have unusual traps that go back to the interpreter In addition, Java methods can be dynamically recompiled multiple times, so the JVM cannot discard the original bytecode It makes no sense to release it anyway, because bytecode is usually much smaller than compiled code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>