L2JVMChunk
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
Parameters
The A_RawFunction that this is for, or null for the default chunk.
The offset into my instructions at which to begin if this chunk's code was primitive and that primitive has already been attempted and failed.
The instructions to execute.
The optimized, non-SSA L2ControlFlowGraph. Useful for debugging. Eventually we'll want to capture a copy of the graph prior to conversion from SSA to support inlining.
The set of contingent values on which this chunk depends. If one of these changes significantly, this chunk must be invalidated (at which time this set will be emptied).
The JVMChunk permanently associated with this L2Chunk.
Types
An enumeration of different ways to enter or re-enter a continuation. In the event that the continuation's chunk has been invalidated, these enumeration values indicate the offset that should be used within the default chunk.
Functions
Answer this chunk's control flow graph. Do not modify it.
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.
The JVMChunk permanently associated with this L2Chunk.
An indication of how recently this chunk has been accessed, expressed as a reference to a Generation.
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.