Class Heap

java.lang.Object
org.qbicc.runtime.gc.heap.Heap

public final class Heap extends Object
Heap management utilities.

The heap index values follow this rule:

0 ≤ allocated ≤ Xms ≤ committed ≤ limit(Xmx)

  • Field Details

    • OOME

      public static final OutOfMemoryError OOME
      An OOME that can always be safely thrown without allocating anything on the heap.
  • Method Details

    • getConfiguredMinHeapSize

      public static long getConfiguredMinHeapSize()
      Get the build-time-configured maximum heap size.
      Returns:
      the configured maximum heap size in bytes
    • getConfiguredMaxHeapSize

      public static long getConfiguredMaxHeapSize()
      Get the build-time-configured minimum heap size.
      Returns:
      the configured minimum heap size in bytes
    • getConfiguredHeapAlignment

      public static long getConfiguredHeapAlignment()
      Get the build-time-configured minimum heap alignment.
      Returns:
      the configured heap alignment
    • getConfiguredObjectAlignment

      public static int getConfiguredObjectAlignment()
      Get the constant, build-time-configured minimum object alignment, in bytes. It is always the case that Integer.bitCount(getConfiguredObjectAlignment()) == 1.
      Returns:
      the configured object alignment
    • pointerToOffset

      @export public static CNative.void_ptr pointerToOffset(long offset)
      Get a pointer to the given heap offset. No checking is performed on the value.
      Parameters:
      offset - the offset
      Returns:
      the pointer (not null)
    • getHeapUnallocated

      @export public static long getHeapUnallocated()
      Get the amount of free heap. This does not include free space within allocated regions, which can only be established by the garbage collector.
      Returns:
      the amount of unallocated space, in bytes
    • getMaxHeapSize

      @export public static long getMaxHeapSize()
      Get the max size of the heap in bytes (for Runtime.maxMemory())
    • getPageSize

      @export public static long getPageSize()
      Get the detected page size.
      Returns:
      the page size
    • getCurrentHeapOffset

      @export public static long getCurrentHeapOffset()
      Get the current heap offset.
      Returns:
      the heap offset
    • allocateRegion

      @export public static long allocateRegion(long expectedOffset, long size) throws IllegalArgumentException, OutOfMemoryError
      Allocate space on the heap, throwing OOME if the allocation fails. If the expectedOffset argument is not -1 and the returned value does not equal expectedOffset, nothing will be allocated and the call must be repeated.
      Parameters:
      expectedOffset - the expected region offset, or -1 if it does not matter
      size - the number of bytes to allocate (must be a multiple of the page size)
      Returns:
      the previous heap region offset
      Throws:
      IllegalArgumentException - if the size is not a valid allocation size
      OutOfMemoryError - if some heap could not be committed
    • commitUpTo

      @export public static void commitUpTo(long index) throws IllegalArgumentException, OutOfMemoryError
      Throws:
      IllegalArgumentException
      OutOfMemoryError
    • checkInit

      @export public static boolean checkInit(boolean printErrors)
      Check on the status of heap initialization and return a flag if the heap is usable.
      Parameters:
      printErrors - true to print errors to stderr, false to skip printing
      Returns:
      true if the heap is usable, false otherwise
    • isHeapArgument

      @export public static boolean isHeapArgument(CNative.ptr<CNative.c_char> argPtr)
    • initHeap

      @export public static boolean initHeap(int argc, CNative.char_ptr_ptr argv)