feat(memory): Storage — the one byte owner: sealed kinds, Owner, StorageId, StorageClosedException, Heap on every target (SKEEP-003 P2, S1.1a) - #1062
Merged
michalharakal merged 1 commit intoAug 23, 2026
Conversation
…ageId, StorageClosedException, Heap on every target (SKEEP-003 P2) Milestone M1 (#1002), PRD M1-F1 (core). SKEEP-003 §4.2–4.4, rules 1–2: exactly one byte owner; ownership is a constructor argument and then enforced. - sk.ainet.lang.memory.Storage (sealed, AutoCloseable): id, sizeBytes, owner, domain, scope (from the owner), debugOrigin TensorId, isAlive, isMutable, checkAlive() → StorageClosedException(id, origin), close() (idempotent; owned = freed once, borrowed = forgotten, alias = detached; emits TraceEvent.Free), slice() → Owner.Alias view that keeps the parent alive, delegates mutability and dies with it. Kinds: Heap (final, common), OffHeap / Mapped / Device (abstract, bound per platform in #1019/#1020; Device is a placeholder). - Storage.Heap: one Kotlin array (floats | ints | bytes) + arrayOffset + sizeBytes; floats()/ints()/bytes() allocate owned storage for a scope kind and emit TraceEvent.Allocation; wrap(array, …) borrows without copying (the #782 copyOf replacement) and is never freed by us. Kernels unwrap once per call (floats/ints/bytes + arrayOffset), per the Phase-2 spike (#1016). - Owner (sealed): Owned(scope) | Borrowed(external) | Alias(parent). StorageId: monotonic per-process value class (kotlin.concurrent.atomics). MemoryDomain gains HOST_OFFHEAP (additive). - StorageTest: owned lifecycle + trace events, ids, borrowed release without touching the lender's bytes, alias lifetime/mutability/ nesting, slice bounds/alignment, rendering. BCV: lang-core jvm dump regenerated (additions only). Closes #1018 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Local gate Targeted: lang-core |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SKEEP-003 slice S1.1a (milestone M1 #1002, PRD M1-F1 core):
Storage— the one and only owner of bytes (§4.2–4.4, rules 1–2), with the commonHeapkind on every target.TensorView(S1.3) interprets a storage;Tensoris the DSL handle over a view — neither owns bytes.sk.ainet.lang.memory.Storage(sealed,AutoCloseable, opt-in):id: StorageId,sizeBytes,owner: Owner,domain,scope(derived from the owner),debugOrigin: TensorId?,isAlive,isMutable,checkAlive()→StorageClosedException(id, origin)(not a JVM crash, not silent corruption), idempotentclose()(owned = freed exactly once, borrowed = forgotten — lender's bytes untouched, alias = detached; emitsTraceEvent.Free),slice(offset, length)→ anOwner.Aliasview that keeps its parent alive, delegates mutability, and dies with the parent. Kinds:Heap(final, common),OffHeap/Mapped(abstract, bound per platform in [S1.1b] P2: JVM/AndroidStorage.OffHeap(FFM MemorySegment / direct ByteBuffer) andStorage.Mapped(FileChannel.map) #1019 JVM/Android, [S1.1c] P2: Kotlin/Native and WASM/JSStoragebindings (malloc/mmap; WASM → Heap) #1020 Native/Wasm),Device(placeholder).Storage.Heap: one Kotlin array (floats | ints | bytes) +arrayOffset+sizeBytes;floats()/ints()/bytes()allocate owned storage for aScopeKindand emitTraceEvent.Allocation;wrap(array, …)borrows without copying (the GGUF DEQUANTIZE_TO_FP32 over-allocates: 1.1B Q4_K_M needs >12 GB heap transiently (~4.4 GB legit) #782copyOfreplacement) and is never freed by us. Kernels unwrap once per call (floats/ints/bytes+arrayOffset) — the access-path rule from the Phase-2 spike ([S1.0] P2 spike (decision #6): prototypeTensorView/Storageaccess-path benchmark on JVM + Android, flat-RSS loop — report only #1016).Owner(sealed):Owned(scope)|Borrowed(external)|Alias(parent);StorageIdmonotonic per-process value class (kotlin.concurrent.atomics.AtomicLong);MemoryDomain.HOST_OFFHEAPadded (additive; no exhaustivewhenover the enum exists).StorageTest: owned lifecycle with trace events, id monotonicity, borrowed release, alias lifetime/mutability/nesting and invalidation on parent close, slice bounds/alignment, rendering.Storageyet (façades come in S1.4).Stacked on #1017 (
TraceSink— allocation events); retarget todevelopafter it merges.Test plan
Full local gate (
scripts/pr-gate.sh, JDK 25); results in the first comment. Targeted: lang-coresk.ainet.lang.memory.*36/36.Closes #1018
🤖 Generated with Claude Code