java - Confusion about HotSpot JVM JIT -


for example,a loop 10000 times in method.when runs 1000 times, backedge_counter triggers jit compilation. , interpreter continue executing. when loops 4000 times, jit compilation completes.

my question is, how remainder 6000 times executed, interpreter, or execute native code?or native code not executed until method invoked next time? , happens when method invoked next time?

assuming asking hotspot jvm, answer remaining interations executed in compiled code.

hotspot jvm has technique known 'on-stack replacement' switch interpreter compiled code while method running.

http://openjdk.java.net/groups/hotspot/docs/hotspotglossary.html

on-stack replacement
known 'osr'. process of converting interpreted (or less optimized) stack frame compiled (or more optimized) stack frame. happens when interpreter discovers method looping, requests compiler generate special nmethod entry point somewhere in loop (specifically, @ backward branch), , transfers control nmethod. rough inverse deoptimization.

if run jvm -xx:+printcompilation flag, osr compilations marked % sign:

    274   27       3       java.lang.string::lastindexof (52 bytes)     275   29       3       java.lang.string::startswith (72 bytes)     275   28       3       java.lang.string::startswith (7 bytes)     275   30       3       java.util.arrays::copyof (19 bytes)     276   32       4       java.lang.abstractstringbuilder::append (29 bytes)     276   31  s    3       java.lang.stringbuffer::append (13 bytes)     283   33 %     3       looptest::mylongloop @ 13 (43 bytes)              ^                                    ^             osr                            bytecode index of osr entry 

update

typically after osr compilation regular compilation queued, next time method called, start running directly in compiled mode.

    187   32 %     3       looptest::mylongloop @ 13 (43 bytes)     187   33       3       looptest::mylongloop (43 bytes) 

however, if regular compilation not complete time method called again, method start running in interpreter, , switch osr entry inside loop.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -