L2SimpleExecutableChunk

L2SimpleExecutableChunk is a subclass of ExecutableChunk. It contains a simple sequence of instructions, executed in turn, unless one of them returns a StackReifier. If the last instruction in the sequence answers null, the final element of the register array is answered from the execution. If a reification happens, the registers are used to synthesize an A_Continuation that will resume as an L1 continuation (i.e., using the default L2Chunk).

Very little optimization is performed at this level. A bit of type deduction helps eliminate spurious checks that would be necessary if method definitions could be added or removed, but the invalidation mechanism handles that. Calls can often be statically transformed to simple monomorphic invocation, avoiding the dispatch trees. When the target is proven to be monomorphic, some primitives can be directly embedded (e.g., P_InvokeWithTuple), if they can be proven not to fail, skipping unnecessary type safety checks. Similarly, unnecessary return type checks can often be omitted as well.

There is no register coloring, no dead code elimination, no special rewriting of most primitives, or reworking into unboxed integer or floating point operations. Folding is attempted, however, if a monomorphic call indicates it would be a Primitive function with the Flag.CanFold flag set.

Flow is linear, and each instruction is responsible for handling reification, if it can happen. If the flow of instructions is to be restarted at any point beyond the first, the continuation's slots are transferred to a fresh array,

Boxed register values are maintained in an array, in the same manner as for L1InstructionStepper. The current function occupies register[0], then the frame slots.

Author

Mark van Gulik

Constructors

Link copied to clipboard
constructor(code: A_RawFunction, instructions: Array<L2SimpleInstruction>, nextOptimizationLevel: OptimizationLevel)

Functions

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

Answer a descriptive (non-unique) name for the ExecutableChunk.

Link copied to clipboard
open override fun runChunk(interpreter: Interpreter, offset: Int): StackReifier?

Run the ExecutableChunk to completion. Note that a reification request may cut this short. For an initial invocation, the Interpreter.argsBuffer will have been set up for the call. For a return into this continuation, the offset will refer to code that will rebuild the register set from the top reified continuation, using the Interpreter.getLatestResult. For resuming the continuation, the offset will point to code that also rebuilds the register set from the top reified continuation, but it won't expect a return value. These re-entry points should perform validity checks on the chunk, allowing an orderly off-ramp into the unoptimizedChunk (which simply interprets the L1 nybblecodes).