GraalVM Standard Development Kit providing APIs for polyglot language embedding, native AOT compilation, memory-efficient collections, low-level memory access, JNI utilities, and native bridge communication.
—
Type-safe APIs for machine-word-sized values and direct memory access, designed to compile to efficient native code without overhead from Java object model.
Base interfaces for machine-word-sized values with arithmetic operations that compile directly to native instructions.
/**
* Base interface for all word-sized value types
*/
public interface WordBase {
/** Convert word to raw long value */
long rawValue();
}
/**
* Word values that support comparison operations
*/
public interface ComparableWord extends WordBase {
/** Test equality with another word */
boolean equal(ComparableWord val);
/** Test inequality with another word */
boolean notEqual(ComparableWord val);
/** Test if this word is less than another */
boolean lessThan(ComparableWord val);
/** Test if this word is less than or equal to another */
boolean lessOrEqual(ComparableWord val);
/** Test if this word is greater than another */
boolean greaterThan(ComparableWord val);
/** Test if this word is greater than or equal to another */
boolean greaterOrEqual(ComparableWord val);
/** Get word representing value above this word */
ComparableWord aboveThan(ComparableWord val);
/** Get word representing value below this word */
ComparableWord belowThan(ComparableWord val);
/** Get word representing value above or equal to this word */
ComparableWord aboveOrEqual(ComparableWord val);
/** Get word representing value below or equal to this word */
ComparableWord belowOrEqual(ComparableWord val);
}Usage Examples:
import org.graalvm.word.*;
public class WordComparison {
public void compareWords() {
UnsignedWord a = WordFactory.unsigned(100);
UnsignedWord b = WordFactory.unsigned(200);
if (a.lessThan(b)) {
System.out.println("a is less than b");
}
if (a.notEqual(b)) {
System.out.println("a and b are different");
}
// Raw value access
long rawA = a.rawValue(); // 100
}
}Unsigned word operations providing overflow-safe arithmetic that compiles to efficient native code.
/**
* Unsigned word with arithmetic operations
*/
public interface UnsignedWord extends ComparableWord {
/** Add unsigned value */
UnsignedWord add(UnsignedWord val);
/** Add signed integer value */
UnsignedWord add(int val);
/** Subtract unsigned value */
UnsignedWord subtract(UnsignedWord val);
/** Subtract signed integer value */
UnsignedWord subtract(int val);
/** Multiply by unsigned value */
UnsignedWord multiply(UnsignedWord val);
/** Multiply by signed integer value */
UnsignedWord multiply(int val);
/** Unsigned division */
UnsignedWord unsignedDivide(UnsignedWord val);
/** Unsigned remainder */
UnsignedWord unsignedRemainder(UnsignedWord val);
/** Shift left by number of bits */
UnsignedWord shiftLeft(UnsignedWord n);
/** Unsigned shift right by number of bits */
UnsignedWord unsignedShiftRight(UnsignedWord n);
/** Bitwise AND operation */
UnsignedWord and(UnsignedWord val);
/** Bitwise OR operation */
UnsignedWord or(UnsignedWord val);
/** Bitwise XOR operation */
UnsignedWord xor(UnsignedWord val);
/** Bitwise NOT operation */
UnsignedWord not();
}Usage Examples:
public class UnsignedArithmetic {
public void performCalculations() {
UnsignedWord size = WordFactory.unsigned(1024);
UnsignedWord blockSize = WordFactory.unsigned(64);
// Calculate number of blocks
UnsignedWord numBlocks = size.unsignedDivide(blockSize);
System.out.println("Number of blocks: " + numBlocks.rawValue()); // 16
// Align size to block boundary
UnsignedWord mask = blockSize.subtract(1);
UnsignedWord aligned = size.add(mask).and(mask.not());
// Safe overflow handling
UnsignedWord maxValue = WordFactory.unsigned(Long.MAX_VALUE);
UnsignedWord result = maxValue.add(1); // Wraps around safely
// Bit manipulation
UnsignedWord flags = WordFactory.unsigned(0);
flags = flags.or(WordFactory.unsigned(0x01)); // Set bit 0
flags = flags.and(WordFactory.unsigned(0xFE).not()); // Clear bit 0
}
}Signed word operations with overflow detection and two's complement arithmetic.
/**
* Signed word with arithmetic operations
*/
public interface SignedWord extends ComparableWord {
/** Add signed value */
SignedWord add(SignedWord val);
/** Add integer value */
SignedWord add(int val);
/** Subtract signed value */
SignedWord subtract(SignedWord val);
/** Subtract integer value */
SignedWord subtract(int val);
/** Multiply by signed value */
SignedWord multiply(SignedWord val);
/** Multiply by integer value */
SignedWord multiply(int val);
/** Signed division */
SignedWord signedDivide(SignedWord val);
/** Signed remainder */
SignedWord signedRemainder(SignedWord val);
/** Shift left by number of bits */
SignedWord shiftLeft(UnsignedWord n);
/** Signed shift right by number of bits */
SignedWord signedShiftRight(UnsignedWord n);
/** Bitwise AND operation */
SignedWord and(SignedWord val);
/** Bitwise OR operation */
SignedWord or(SignedWord val);
/** Bitwise XOR operation */
SignedWord xor(SignedWord val);
/** Bitwise NOT operation */
SignedWord not();
}Type-safe pointer arithmetic and memory access operations.
/**
* Base interface for pointer types
*/
public interface PointerBase extends ComparableWord {
/** Check if pointer is null */
boolean isNull();
/** Check if pointer is not null */
boolean isNonNull();
}
/**
* Pointer with arithmetic and memory access operations
*/
public interface Pointer extends UnsignedWord, PointerBase {
/** Read byte at offset */
byte readByte(UnsignedWord offset);
/** Read byte at word-sized offset */
byte readByte(int wordOffset);
/** Write byte at offset */
void writeByte(UnsignedWord offset, byte val);
/** Write byte at word-sized offset */
void writeByte(int wordOffset, byte val);
/** Read char at offset */
char readChar(UnsignedWord offset);
/** Write char at offset */
void writeChar(UnsignedWord offset, char val);
/** Read short at offset */
short readShort(UnsignedWord offset);
/** Write short at offset */
void writeShort(UnsignedWord offset, short val);
/** Read int at offset */
int readInt(UnsignedWord offset);
/** Write int at offset */
void writeInt(UnsignedWord offset, int val);
/** Read long at offset */
long readLong(UnsignedWord offset);
/** Write long at offset */
void writeLong(UnsignedWord offset, long val);
/** Read float at offset */
float readFloat(UnsignedWord offset);
/** Write float at offset */
void writeFloat(UnsignedWord offset, float val);
/** Read double at offset */
double readDouble(UnsignedWord offset);
/** Write double at offset */
void writeDouble(UnsignedWord offset, double val);
/** Read word at offset */
<T extends WordBase> T readWord(UnsignedWord offset);
/** Write word at offset */
void writeWord(UnsignedWord offset, WordBase val);
/** Read object reference at offset */
Object readObject(UnsignedWord offset);
/** Write object reference at offset */
void writeObject(UnsignedWord offset, Object val);
/** Compare memory regions */
int compareAndSwapInt(UnsignedWord offset, int expectedValue, int newValue);
/** Compare memory regions for long values */
long compareAndSwapLong(UnsignedWord offset, long expectedValue, long newValue);
/** Compare memory regions for word values */
<T extends WordBase> T compareAndSwapWord(UnsignedWord offset, T expectedValue, T newValue);
/** Compare memory regions for object references */
Object compareAndSwapObject(UnsignedWord offset, Object expectedValue, Object newValue);
}Usage Examples:
public class PointerOperations {
public void accessMemory() {
// Allocate native memory (conceptual - actual allocation varies)
Pointer memory = allocateMemory(1024);
if (memory.isNonNull()) {
// Write data to memory
memory.writeInt(WordFactory.unsigned(0), 42);
memory.writeInt(WordFactory.unsigned(4), 100);
// Read data back
int first = memory.readInt(WordFactory.unsigned(0));
int second = memory.readInt(WordFactory.unsigned(4));
System.out.println("First: " + first + ", Second: " + second);
// Pointer arithmetic
Pointer secondInt = memory.add(4);
int value = secondInt.readInt(WordFactory.unsigned(0));
// Atomic operations
int oldValue = memory.compareAndSwapInt(
WordFactory.unsigned(0), 42, 84);
if (oldValue == 42) {
System.out.println("Successfully updated value");
}
}
}
// Placeholder for memory allocation
private native Pointer allocateMemory(int size);
}Factory methods for creating word values from primitive types.
/**
* Factory for creating word values from primitives
*/
public final class WordFactory {
/** Create zero-valued unsigned word */
public static UnsignedWord zero();
/** Create null pointer */
public static <T extends PointerBase> T nullPointer();
/** Create unsigned word from long value */
public static UnsignedWord unsigned(long val);
/** Create unsigned word from int value */
public static UnsignedWord unsigned(int val);
/** Create signed word from long value */
public static SignedWord signed(long val);
/** Create signed word from int value */
public static SignedWord signed(int val);
/** Create pointer from long address */
public static <T extends PointerBase> T pointer(long val);
/** Create word from raw value */
public static <T extends WordBase> T fromRawValue(Class<T> type, long rawValue);
}Usage Examples:
public class WordFactoryUsage {
public void createWords() {
// Create various word types
UnsignedWord pageSize = WordFactory.unsigned(4096);
SignedWord offset = WordFactory.signed(-100);
Pointer nullPtr = WordFactory.nullPointer();
// Zero and max values
UnsignedWord zero = WordFactory.zero();
UnsignedWord maxUnsigned = WordFactory.unsigned(-1L); // All bits set
// Convert between types
long rawValue = pageSize.rawValue();
UnsignedWord restored = WordFactory.unsigned(rawValue);
// Null checks
if (nullPtr.isNull()) {
System.out.println("Pointer is null");
}
// Create typed pointers
Pointer buffer = WordFactory.pointer(0x1000L);
if (buffer.isNonNull()) {
// Use buffer...
}
}
}Low-level synchronization primitives for concurrent access to memory.
/**
* Memory synchronization and barriers
*/
public final class MemoryBarriers {
/** Full memory barrier */
public static void fullBarrier();
/** Load memory barrier */
public static void loadBarrier();
/** Store memory barrier */
public static void storeBarrier();
/** Load-store memory barrier */
public static void loadStoreBarrier();
/** Store-load memory barrier */
public static void storeLoadBarrier();
}
/**
* Atomic operations on word values
*/
public final class AtomicOperations {
/** Atomic load with acquire semantics */
public static <T extends WordBase> T loadAcquire(Pointer address);
/** Atomic store with release semantics */
public static void storeRelease(Pointer address, WordBase value);
/** Atomic compare-and-swap */
public static <T extends WordBase> T compareAndSwap(
Pointer address, T expectedValue, T newValue);
/** Atomic fetch-and-add */
public static UnsignedWord fetchAndAdd(Pointer address, UnsignedWord delta);
/** Atomic fetch-and-subtract */
public static UnsignedWord fetchAndSubtract(Pointer address, UnsignedWord delta);
}// Platform-specific word sizes
public interface WordSize {
/** Get size of machine word in bytes */
static int wordSize();
/** Get size of pointer in bytes */
static int pointerSize();
}
// Word type constants
public final class WordConstants {
/** Maximum unsigned word value */
public static final UnsignedWord MAX_UNSIGNED;
/** Maximum signed word value */
public static final SignedWord MAX_SIGNED;
/** Minimum signed word value */
public static final SignedWord MIN_SIGNED;
/** Word size in bits */
public static final int WORD_SIZE_BITS;
/** Word size in bytes */
public static final int WORD_SIZE_BYTES;
}
// Exception types
public class WordException extends RuntimeException {
public WordException(String message);
public WordException(String message, Throwable cause);
}Install with Tessl CLI
npx tessl i tessl/maven-org-graalvm-sdk--graal-sdk