-
Notifications
You must be signed in to change notification settings - Fork 0
Memory Management
JNode is a monolithic Java OS with a single shared address space. Memory management involves both hardware paging (x86) and object-level Garbage Collection (GC).
Unlike traditional operating systems that isolate processes into separate virtual address spaces, JNode operates in a Single Address Space. All code—kernel, drivers, applications—shares the same memory space. Process isolation is achieved purely through Java's type safety and JNode's Isolate abstraction.
Memory management in JNode bridges the gap between raw physical memory pages (managed by assembly) and Java objects (managed by the GC).
┌──────────────────────────────────────────────────┐
│ Isolates (Applications) │
├──────────────────────────────────────────────────┤
│ Garbage Collector (MMTk) │
│ Allocates objects, reclaims unreachable memory │
├──────────────────────────────────────────────────┤
│ VmHeapManager / MemoryBlockManager │
│ Requests blocks of memory from the system │
├──────────────────────────────────────────────────┤
│ Paging (mm32.asm / mm64.asm) │
│ Maps virtual addresses to physical pages │
└──────────────────────────────────────────────────┘
Physical memory layout and hardware page tables are initialized in assembly during boot:
-
32-bit (
core/src/native/x86/mm32.asm): Sets up a flat 4GB address space. The first 4MB are mapped using 4KB pages (with page 0 unmapped to catch null pointer dereferences). The rest of the address space uses 4MB pages. -
64-bit (
core/src/native/x86/mm64.asm): Sets up the Page Map Level 4 (PML4) tables, transitioning the CPU into long mode and establishing a flat 64-bit address space.
Once initialized, the VM abstracts physical memory regions via the MemoryResource API.
JNode supports pluggable heap managers.
-
Location:
core/src/core/org/jnode/vm/memmgr/def/ - Mechanism: A basic, stop-the-world, mark-and-sweep garbage collector native to JNode.
-
Components:
-
DefaultHeapManager: Manages the overall heap. -
GCManager: Orchestrates the GC cycle. -
GCMarkVisitor/GCSweepVisitor: Traverses the object graph and frees memory. -
DefaultWriteBarrier: Used to track cross-generational or cross-region references.
-
-
Location:
core/src/mmtk-vm/org/jnode/vm/memmgr/ - Mechanism: JNode includes bindings for the Memory Management Toolkit (MMTk), a high-performance memory management framework originating from the Jikes RVM. MMTk provides advanced algorithms like generational and concurrent collection.
-
Supported Plans: JNode integrates MMTk plans such as
genrc(Generational Reference Counting),ms(Mark-Sweep), andnogc(No Garbage Collection).
Because Java objects are created during the build process (by BootImageBuilder), the boot image itself contains a serialized Java heap.
-
VmBootHeap: A special heap representation that wraps the pre-allocated objects baked into the.iso. This heap is immutable at runtime (objects cannot be freed), but new objects are allocated in the dynamic heaps.
Drivers often need to interact with physical hardware via DMA (Direct Memory Access). This requires bridging Java references with raw physical addresses.
-
org.jnode.system.resource.MemoryResource: Represents a raw chunk of mapped memory (e.g., video RAM). -
Address Unboxing: JNode uses
org.vmmagic.unboxed.Addressto pass raw memory pointers through Java code without incurring the overhead of object allocation.
-
Boot-Sequence — How
kernel.asmandmm32.asminitialize memory. - Paging-Implementation — Deep dive into x86 page table setup, identity mapping, and guard pages.
-
VM-Magic — Explanation of
Addressand other unboxed types used for memory access. - Architecture — How Isolates provide separation in a single address space.