To design a memory model that guarantees crash-proof execution in Ring 0 while remaining perfectly isomorphic in JS, we must treat all memory as a flat, pre-allocated arena. Pointers do not exist; everything is an index offset. Here is the architectural specification for Phase 2. The Memory Arena The Host environment allocates a single, contiguous block of memory at boot. In JS, this is a SharedArrayBuffer; on bare-metal, it is a reserved physical memory space. This contiguous design guarantees CPU cache locality, setting the stage for future AVX2 SIMD vectorization over object arrays. The arena is logically partitioned into two primary registries: the Global Handle Ledger (for dynamic data) and the Master Object Index (for LPC objects). The Global Handle Ledger (GHL) The GHL tracks every dynamically allocated string, array, and mapping. It is a pre-allocated array of 24-byte nodes operating as an intrusive doubly-linked list. When a Tagged Pointer resolves to a Handle ID, it serves as the exact index into this array. | Offset | Type (32-bit) | Field | Description | |---|---|---|---| | 0x00 | uint32 | ref_count | Number of active variables holding this handle. | | 0x04 | uint32 | type_tag | Identifies the payload (e.g., String, Array). | | 0x08 | uint32 | prev_handle | Intrusive link to the previous active node. | | 0x0C | uint32 | next_handle | Intrusive link to the next active node. | | 0x10 | uint32 | payload_size | Size of the allocated data for memory accounting. | | 0x14 | uint32 | data_offset | The byte-offset into the arena where the actual string/array bytes live. | * Zero-copy cloning: When an array is duplicated, the engine simply increments the ref_count and passes the Handle ID. * Deallocation: When ref_count hits 0, the node is immediately unlinked and moved to the FREE_HEAD chain. The Master Object Index (MOI) LPC objects are not structs in the traditional sense; they are execution contexts. The MOI is a strict array mapping an Object ID (OID) to its state. | Offset | Type (32-bit) | Field | Description | |---|---|---|---| | 0x00 | uint32 | blueprint_id | Index pointing to the shared Code Segment (RX). | | 0x04 | uint32 | state_offset | Pointer into the arena where variables live (RW). | | 0x08 | uint32 | flags | Bitmask (e.g., IS_CLONE, HEART_BEAT_ACTIVE). | | 0x0C | uint32 | var_count | Number of variables allocated in the state block. | Resolving State and Inheritance LPC heavily utilizes inheritance, but at the bytecode level, inheritance is flattened during compilation. * State Block: The state_offset points to a flat array of 32-bit Tagged Pointers. If an object inherits two files and has a total of 15 global variables, the Host allocates exactly 60 bytes. * Execution Flow: When bytecode executes LOAD_VAR 5, the engine reads the current OID from the Shadow Stack, looks up the MOI record, jumps to state_offset, and copies the 5th Tagged Pointer into a register. * Hot-reloading: To hot-patch an active object, the Host simply compiles a new Blueprint, updates the blueprint_id in the MOI, and leaves the state_offset untouched.