L2Simple Chunk
A Level Two chunk represents a simply optimized implementation of an A_RawFunction. It's composed of L2SimpleInstructions, and doesn't have any deep optimizations. It does, however, attempt to eliminate dispatches for monomorphic call sites, as well as return type checks, whenever possible.
Author
Mark van Gulik
Parameters
The L2SimpleInstructions to execute.
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 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 L2SimpleExecutableChunk permanently associated with this L2SimpleChunk.
Properties
Answer the Avail pojo associated with this L2Chunk.
The code that was translated to L2. Null for the default (L1) chunk.
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.
Functions
Dump the chunk to disk for debugging. This is expected to be called directly from the Kotlin 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.