Skip to content

all-an/java-systems-programming

Repository files navigation

Java Systems Programming with GraalVM

This project demonstrates Java systems programming capabilities using GraalVM Native Image with unmanaged memory operations and the Epsilon no-op garbage collector.

Features

  • Unmanaged Memory Operations: malloc, calloc, realloc, and free
  • Epsilon GC: No-op garbage collector for minimal GC overhead
  • Native Image: Compiled to native executable with GraalVM

Prerequisites

  • GraalVM 25+ with Native Image
  • Maven 3.6+
  • Java 21+

Build & Run

Manual Native Image Build

mvn clean package
./build-native.bat
./com.example.systemsprogrammingdemo.exe

Systems Programming Demos

The application demonstrates:

  1. malloc() - Allocate uninitialized memory
  2. calloc() - Allocate zero-initialized memory
  3. realloc() - Resize allocated memory
  4. Memory Operations - Pointer arithmetic and addressing
  5. Large Allocations - Performance testing with 1MB allocations

Epsilon GC

The --gc=epsilon flag enables the Epsilon garbage collector:

  • No-op GC that doesn't actually collect garbage
  • Minimal overhead for applications that manage their own memory
  • Perfect for systems programming with manual memory management
  • Application terminates when heap is exhausted

Unmanaged Memory API

// Allocate uninitialized memory
CIntPointer ptr = UnmanagedMemory.malloc(size);

// Allocate zero-initialized memory
CLongPointer ptr = UnmanagedMemory.calloc(size);

// Resize allocated memory
ptr = UnmanagedMemory.realloc(ptr, newSize);

// Free memory
UnmanagedMemory.free(ptr);

Notes

  • Unmanaged memory is not managed by the garbage collector
  • Always free unmanaged memory to avoid leaks
  • Epsilon GC is ideal for short-lived applications or those with manual memory management
  • Native Image provides fast startup and low memory footprint

About

java-systems-programming

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published