L2JVMChunk

class L2JVMChunk : 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

Parameters

code

The A_RawFunction that this is for, or null for the default chunk.

offsetAfterInitialTryPrimitive

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.

instructions

The instructions to execute.

controlFlowGraph

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.

contingentValues

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).

executableChunk

The JVMChunk permanently associated with this L2Chunk.

Types

Link copied to clipboard
enum ChunkEntryPoint : Enum<L2JVMChunk.ChunkEntryPoint>

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.

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun beforeRunChunk(offset: Int)

Called just before running the JVMChunk inside this L2Chunk. This gives the opportunity for logging the chunk execution.

Link copied to clipboard
fun controlFlowGraph(): L2ControlFlowGraph

Answer this chunk's control flow graph. Do not modify it.

Link copied to clipboard
open override fun dumpChunk(): String

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.

Link copied to clipboard
fun invalidate(reason: L2Chunk.InvalidationReason)

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.

Link copied to clipboard
fun name(): String
Link copied to clipboard
open override fun toString(): String

Properties

Link copied to clipboard
val chunkPojo: AvailObject

Answer the Avail pojo associated with this L2Chunk.

Link copied to clipboard
val code: A_RawFunction?

The code that was translated to L2. Null for the default (L1) chunk.

Link copied to clipboard
open override val executableChunk: JVMChunk

The JVMChunk permanently associated with this L2Chunk.

Link copied to clipboard
var generation: L2Chunk.Generation?

An indication of how recently this chunk has been accessed, expressed as a reference to a Generation.

Link copied to clipboard
open override val instructions: List<L2Instruction>
Link copied to clipboard
val isValid: Boolean = true

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.

Link copied to clipboard
val offsetAfterInitialTryPrimitive: Int

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).

Link copied to clipboard
val weakReference: WeakReference<L2Chunk>

The WeakReference that points to this L2Chunk.