Force method compilation in HotSpot JVM

Krystal Mok rednaxelafx at
Sun Jun 12 03:59:33 PDT 2011

Hi Antoine,

With the HotSpot server compiler (C2), even if you forced some methods to
get compiled, if you haven't let it run in the interpreter for a couple of
times before the compilation, you may well get a false sense of compilation
due to unloaded classes. When the interpreter runs, it'll load classes on
demand, where as when C2 compiles a method, if it sees a point in the method
that encounters a class not-yet-loaded or already-unloaded, it'll generate a
call to a trampoline that jumps back into the interpreter; that's called an
"uncommon trap".

There's are some documentation on the HotSpot VM here:
<>But I don't think there's any
official documentation that describes the whole compilation process, yet.
Parts of it are described in a few papers. "The Java HotSpot Server
Compiler"( might
be a good starting point; the "2. Runtime Environment" part should have what
you want to know. Although it doesn't cover how the tiered compilation
system in current version of HotSpot works.

Compiled methods are managed with an "nmethod" object. There's a field,
"_code" in the methodOopDesc of the method compiled that keeps track of the
compiled code.
There are two separate entry points in a methodOopDesc, one
is _from_compiled_entry, the other is _from_interpreted_entry. Read the
comments in oops/methodOop.hpp, it explains what these two entry points are
for.Depending on whether the caller is interpreted or compiled, going
through the entry point may go into a c2i (compiled-to-interpreted) or i2c
(interpreted-to-compiled) adapter.

An nmethod has two entry points by itself, one is the "entry point" and the
other is the "verified entry point". These are used to implement inline
caching for virtual call dispatch. More details described here:

Kris Mok

On Sat, Jun 11, 2011 at 12:46 AM, Igor Veresov <igor.veresov at>wrote:

> On 6/10/11 8:52 AM, antoine artaud-macari wrote:
>>  Dear HotSpot developers !
>> We are working on performance optimization for a Java critical system
>> and we would like to force the compilation of some Java methods (chosen
>> by our own algorithm).
>> So we have looked at the OpenJDK HotSpot source code and for time being
>> we succeeded in forcing compilation of these methods but the interpreter
>> still executes the bytecode.
>> For example, we used :
>>    nmethod * nm = CompileBroker::compile_method(m, 0, m, 0,"forced
>>    compilation", THREAD);
>> where m is a methodHandle on the method to be compiled.
>> Would you please send us some technical reference or documentation about
>> compilation process or how compiled method are executed ?
> For osr_bci parameter you should specify the InvocationEntryBci constant
> (which is -1).
> igor
>> Best regards,
>> --
>> *Antoine ARTAUD-MACARI *****
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the hotspot-compiler-dev mailing list