Package org.qbicc.runtime.gc.heap
Class Heap
java.lang.Object
org.qbicc.runtime.gc.heap.Heap
Heap management utilities.
The heap index values follow this rule:
0 ≤ allocated ≤ Xms ≤ committed ≤ limit(Xmx)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final OutOfMemoryErrorAn OOME that can always be safely thrown without allocating anything on the heap. -
Method Summary
Modifier and TypeMethodDescriptionstatic longallocateRegion(long expectedOffset, long size) Allocate space on the heap, throwing OOME if the allocation fails.static booleancheckInit(boolean printErrors) Check on the status of heap initialization and return a flag if the heap is usable.static voidcommitUpTo(long index) static longGet the build-time-configured minimum heap alignment.static longGet the build-time-configured minimum heap size.static longGet the build-time-configured maximum heap size.static intGet the constant, build-time-configured minimum object alignment, in bytes.static longGet the current heap offset.static longGet the amount of free heap.static longGet the max size of the heap in bytes (for Runtime.maxMemory())static longGet the detected page size.static booleaninitHeap(int argc, CNative.char_ptr_ptr argv) static booleanisHeapArgument(CNative.ptr<CNative.c_char> argPtr) static CNative.void_ptrpointerToOffset(long offset) Get a pointer to the given heap offset.
-
Field Details
-
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 thatInteger.bitCount(getConfiguredObjectAlignment()) == 1.- Returns:
- the configured object alignment
-
pointerToOffset
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
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
public static long getMaxHeapSize()Get the max size of the heap in bytes (for Runtime.maxMemory()) -
getPageSize
public static long getPageSize()Get the detected page size.- Returns:
- the page size
-
getCurrentHeapOffset
public static long getCurrentHeapOffset()Get the current heap offset.- Returns:
- the heap offset
-
allocateRegion
public static long allocateRegion(long expectedOffset, long size) throws IllegalArgumentException, OutOfMemoryError Allocate space on the heap, throwing OOME if the allocation fails. If theexpectedOffsetargument is not-1and the returned value does not equalexpectedOffset, nothing will be allocated and the call must be repeated.- Parameters:
expectedOffset- the expected region offset, or-1if it does not mattersize- 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 sizeOutOfMemoryError- if some heap could not be committed
-
commitUpTo
-
checkInit
public static boolean checkInit(boolean printErrors) Check on the status of heap initialization and return a flag if the heap is usable.- Parameters:
printErrors-trueto print errors tostderr,falseto skip printing- Returns:
trueif the heap is usable,falseotherwise
-
isHeapArgument
-
initHeap
-