Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when java jvm compiles bytecode, where does that code go in process space?

When the jvm (hotspot in my case) permanently compiles certain code paths into machine code, where is that machine code being stored? in the .text segment of process memory? in the process's heap??

I am not talking about JITing. From my understandning, JIT will compile and run bytecode without ever saving the compiled code anywhere. But what about when the jvm is saving that code -- where in process space does it save it? ... as the comments and answers point out, everything I was asking for is, in fact, a part of JIT.

EDIT:

as per my comment below, the situation I'm specifically referring to is documented here as "Adaptive optimization": http://www.oracle.com/technetwork/java/whitepaper-135217.html#hotspot

like image 863
Alexander Bird Avatar asked Jun 25 '13 21:06

Alexander Bird


1 Answers

Firstly, what you are describing is JIT - specifically how it works in Hotspot

To answer your question about where the code is saved at runtime - it's in the process heap and the pointers to the method code in the object's Klass file is updated to point to it. There's also something called OSR (on stack replacement) for compiling long running loops directly on the stack.

like image 95
selig Avatar answered Nov 02 '22 05:11

selig