Skip to content

feat(memory): PlatformStorage — common door to platform storage kinds; Kotlin/Native malloc/mmap; JS/Wasm heap fallback (SKEEP-003 P2, S1.1c) - #1064

Merged
michalharakal merged 1 commit into
developfrom
feature/1020-storage-native-wasm
Aug 23, 2026
Merged

michalharakal merged 1 commit into
developfrom
feature/1020-storage-native-wasm

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Summary

SKEEP-003 slice S1.1c (milestone M1 #1002): PlatformStorage — the one common door to the platform's storage kinds (§4.8: where bytes live is a policy decision; how long they live is a scope decision; neither is made by a layer, a loader or a kernel), plus the Kotlin/Native and JS/Wasm bindings.

  • commonMain expect object PlatformStorage: supports(domain), supportsMappedFiles, allocate(bytes, domain, scope, origin, sink), mapFile(path, offset, length, scope, origin, sink); PlatformStorageInfo for describe()/planner notes.
  • Actuals: JVM → SegmentStorage / MappedFileStorage; Android → DirectBufferStorage / MappedBufferStorage; Kotlin/Native → new NativeMallocStorage (malloc + memset, free on close; borrow(pointer) never freed; raw pointer() is what a C kernel receives) and NativeMappedStorage (mmap PROT_READ/MAP_PRIVATE with page-aligned offsets, munmap on close); JS / Wasm → linear memory only: off-heap requests resolve to the heap and supports() says so (the planner records the fallback), mapFile throws UnsupportedOperationException (weights arrive via the suspend source into heap slabs, [S2.4] P5: IO as a pipeline — quantPolicy × staging = MAPPED|HEAP in one loader; suspend RandomAccessSource in io-core #1037).
  • PlatformStorageTest (commonTest — runs on every target: heap everywhere, off-heap or documented fallback, non-allocatable domains, mapped-file capability) and PlatformStorageJvmTest. Compiles for linuxX64, JVM, JS, wasmJs, wasmWasi; JVM 49/49 and linuxX64 40/40 memory tests.
  • BCV: lang-core jvm dump regenerated (additions only).

Stacked on #1063 (#1019); retarget to develop as the chain merges. Apple/iOS and androidNative are covered by the same nativeMain code (POSIX) but only linuxX64 runs in CI.

Test plan

Full local gate (scripts/pr-gate.sh, JDK 25); results in the first comment.

Closes #1020

🤖 Generated with Claude Code

…ge kinds; Kotlin/Native malloc/mmap bindings; JS/Wasm heap fallback (SKEEP-003 P2)

Milestone M1 (#1002). SKEEP-003 §4.8: where bytes live is a policy
decision; each target binds the kinds to what it has.

- commonMain expect object PlatformStorage: supports(domain),
  supportsMappedFiles, allocate(bytes, domain, scope, origin, sink),
  mapFile(path, offset, length, scope, origin, sink); PlatformStorageInfo.
- jvmMain actual: HOST_OFFHEAP → SegmentStorage, HOST_HEAP → Heap,
  mapFile → MappedFileStorage. androidMain actual: DirectBufferStorage /
  MappedBufferStorage. nativeMain actual: NativeMallocStorage (malloc +
  memset, free on close; borrow(pointer) never freed) and
  NativeMappedStorage (mmap PROT_READ/MAP_PRIVATE with page-aligned
  offset handling, munmap on close). jsMain / wasmJsMain / wasmWasiMain
  actuals: linear memory only — off-heap requests resolve to the heap
  (supports() says so for the planner), mapFile throws
  UnsupportedOperationException.
- PlatformStorageTest (commonTest, every target: heap everywhere, off-heap
  or fallback, non-allocatable domains, mapped-file capability);
  PlatformStorageJvmTest. BCV: lang-core jvm dump regenerated.

Closes #1020

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@michalharakal

Copy link
Copy Markdown
Contributor Author

Local gate scripts/pr-gate.sh (JDK 25) on 27a3d87: all legs passed — jvmTest · apiCheck · JS/Wasm · linuxX64Test · assemble · Java API tests.

Targeted: JVM 49/49 and linuxX64 40/40 sk.ainet.lang.memory.* tests; compiles for linuxX64, JVM, JS, wasmJs, wasmWasi and Android.

Base automatically changed from feature/1019-storage-jvm-offheap-mapped to develop August 23, 2026 12:45
@michalharakal
michalharakal merged commit 6a74b53 into develop Aug 23, 2026
3 checks passed
@michalharakal
michalharakal deleted the feature/1020-storage-native-wasm branch August 23, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[S1.1c] P2: Kotlin/Native and WASM/JS Storage bindings (malloc/mmap; WASM → Heap)

1 participant