L2Chunk
A Level Two chunk represents an optimized implementation of a compiled code object.
An A_RawFunction refers to the L2Chunk that it should run in its place. An A_Continuation also refers to the L2Chunk that allows the continuation to be returned into, restarted, or resumed after an interrupt. The Generation mechanism maintains approximate age information of chunks, in particular how long it has been since a chunk was last used, so that the least recently used chunks can be evicted when there are too many chunks in memory.
A chunk also keeps track of the methods that it depends on, and the methods keep track of which chunks depend on them. New method definitions can be added – or existing ones removed – only while all fiber execution is paused. At this time, the chunks that depend on the changed method are marked as invalid. Each A_RawFunction associated (1:1) with an invalidated chunk has its A_RawFunction.startingChunk reset to the default chunk. Existing continuations may still be referring to the invalid chunk – but not Java call frames, since all fibers are paused. When resuming a continuation, its chunk's validity is immediately checked, and if it's invalid, the default chunk is resumed at a suitable entry point instead.
Author
Mark van Gulik
Types
A group of chunks with approximately equal most-recent access time.
An enumeration of reasons why a chunk might be invalidated.
Functions
Dump the chunk to disk for debugging. This is expected to be called directly from the debugger, and should result in the production of three files: JVMChunk_«uuid».l1, JVMChunk_«uuid».l2, and JVMChunk_«uuid».class. This momentarily sets the JVMTranslator.debugJVM flag to true, but restores it to its original value on return.
Something that this L2Chunk depended on has changed. This must have been because it was optimized in a way that relied on some aspect of the available definitions (e.g., monomorphic inlining), so we need to invalidate the chunk now, so that an attempt to invoke it or return into it will be detected and converted into using the unoptimizedChunk. Also remove this chunk from the contingent set of each object on which it was depending.
Properties
Answer the Avail pojo associated with this L2Chunk.
An indication of how recently this chunk has been accessed, expressed as a reference to a Generation.
The L2AbstractInstructions constituting this chunk.
A flag indicating whether this chunk is valid or if it has been invalidated by the addition or removal of a method signature. It doesn't have to be volatile, since it can only be set when Avail code execution is temporarily suspended in all fibers, which involves synchronization (and therefore memory coherence) before it can start running again.
The level two offset at which to start if the corresponding A_RawFunction is a primitive, and it has already been attempted and failed. If it's not a primitive, this is the offset of the start of the code (0).
The WeakReference that points to this L2Chunk.