Path: blob/master/doc/compiler/runtime/MetadataReclamation.md
6000 views
Metadata Reclamation Design {#MetadataReclamation}
When an ordinary java method aJavaMethod gets recompiled, this is the sequence of operations:
The first instruction of the old body of aJavaMethod gets patched to branch to a runtime helper routine which:
Patches the caller to call the new body
Tranfers control the new body in such a way that when it returns, it returns to the caller and not the helper routine
All new invocations of aJavaMethod call the new body either directly or because it got patched to do so
The old body continues to exist until GC, at which point a JIT hook checks the stacks of all threads to verify that it is no longer in use
Once the JIT determines that the old body is safe to reclaim, at any Global GC it:
Reclaims the majority of the body for code cache reuse leaving behind a stub
Updates the J9JITExceptionTable to describe just the stub
The J9JITExceptionTable (also referred to as the metadata) is a struct that is used to describe the code body. It also has a variable length section that contains data specific to the body like exception ranges, GC Maps, etc. This table continues to persist even when all it's describing is the stub. This can be a big waste of memory since the variable length section can get quite large. This design aims to reclaim the J9JITExceptionTable when a body gets reclaimed and replace it with a "stub" J9JITExceptionTable to describe a code stub.
J9JITExeptionTable reclamation occurs when jitReleaseCodeCollectMetaData
is called, the JIT tries to allocate a new J9JITExeptionTable without any variable length section
If it fails, it reuses the existing J9JITExceptionTable and does nothing else.
If it succeeds, it:
memcpy
s the non-variable lenth section from the existing J9JITExceptionTableUpdates the various
prevMethod
andnextMethod
pointersSets the following fields to
NULL
:inlinedCalls - This is pointer to the list of inlined calls in the variable length section
gcStackAtlas - This is a pointer to the J9JITStackAtlas struct in the variable length section
gpuCode - This is a pointer to the GPU Data in the variable length section
riData - This is a pointer to the RI Data in the variable length section
osrInfo - This is a pointer to OSR info tn the variable length section
runtimeAssumptionList - This is a pointer to the list of Runtime Assumptions that gets reclaimed along with the old body
Frees the Fast Walk Cache
Sets the
JIT_METADATA_IS_STUB
flag so anyone with a PC in the stub knows as muchAdds the new J9JITExceptionTable to the AVL Trees
Frees the old J9JITExceptionTable
The options to enable/disable this are enableMetadataReclamation
/ disableMetadataReclamation
.