Do compiler threads allocate metaspace?

Vladimir Kozlov vladimir.kozlov at
Tue Nov 13 18:15:33 UTC 2018

Yes, compilers (C1 and C2) do allocations in Metaspace - MethodData and MethodCounter objects.

On 11/13/18 9:26 AM, Thomas Stüfe wrote:
> Hi all,
> can compiler threads allocate Metaspace?
> Background:
> Clients of us use a "jvmkill" jvmti agent in their cloudfoundry
> infrastructure. That agent (see
> subscribes to the JVMTI
> ResourceExhausted Event and then, in the handler, uses JVMTI
> FollowReferences() to produce a heap histogram.
> What seems to happen is this: We run into a Metaspace OOM, then the
> JVMTI agent attempts to print its histogram, walks part of the heap,
> then we run into a "guarantee(!thread->is_Compiler_thread())".
> Therefore I wonder whether compiler threads can allocate Metaspace?
> Looking at the sources, I see potential call paths from the compiler,
> e.g. Method::build_interpreter_method_data(), which will allocate
> space in Metaspace for a MethodData object, and which in turn, to me,
> looks like it could be invoked from compiler code (e.g. during
> deoptimization).

MethodData and MethodCounter are used for profiling (the main purpose) and record deoptimization reasons as you pointed. 
Interpreter and C1 generated code are accessing it to write profiling data. Both C1 and C2 can create such objects 
during compilation if Interpreter did not create them yet. The profiling data is accesses by C2 during compilation - 
this is the main purpose.

> If yes - compiler can allocate metaspace - how would they deal with
> Metaspace OOMs?

If MethodData is not available (failed to allocate) we create empty ciMethodData and use it during C2 compilation 
(compilation will be similar to -Xcomp compilation):

We bailout C1 Tier3 compilation (with profiling) if no data available:


> Also note that I am not sure at all whether that type of usage -
> calling FollowReferences() when handling ResourceExhausted - is even
> allowed in JVMTI.
> Thanks a lot,
> Best Regards, Thomas

More information about the hotspot-compiler-dev mailing list