private static boolean getAvailableChunkIfPossible(int size) { if (freeChunks == 0) { return false; } while (true) { if (currentChunk.toAddress().add(size) == currentChunkLimit) { break; } if (currentChunk.toAddress().add(size + Structure.sizeOf(FreeChunk.class)).isLessThan(currentChunkLimit)) { break; } if (--freeChunks == 0) { return false; } freeMemory -= currentChunk.size; currentChunkPointer = Structure.add(FreeChunkHolder.class, currentChunkPointer, 1); currentChunk = currentChunkPointer.value; currentChunkLimit = currentChunk.toAddress().add(currentChunk.size); } return true; }
public static RuntimeObject alloc(int size) { FreeChunk current = currentChunk; Address next = current.toAddress().add(size); if (!next.add(Structure.sizeOf(FreeChunk.class)).isLessThan(currentChunkLimit)) { getAvailableChunk(size); current = currentChunk; next = currentChunk.toAddress().add(size); } int freeSize = current.size; freeSize -= size; if (freeSize > 0) { currentChunk = next.toStructure(); currentChunk.size = freeSize; } else { freeMemory -= size; getAvailableChunkIfPossible(currentChunk.size + 1); } currentChunk.classReference = 0; freeMemory -= size; return current.toAddress().toStructure(); }
Address limit = heapAddress().add(heapSize); loop: while (object.toAddress().isLessThan(limit)) { int tag = object.classReference; boolean free; if (!object.toAddress().isLessThan(currentRegionEnd)) { currentRegionIndex = (int) ((object.toAddress().toLong() - heapAddress().toLong()) / regionSize()); Region currentRegion = Structure.add(Region.class, regionsAddress(), currentRegionIndex);
private static boolean getAvailableChunkIfPossible(int size) { if (freeChunks == 0) { return false; } while (true) { if (currentChunk.toAddress().add(size) == currentChunkLimit) { break; } if (currentChunk.toAddress().add(size + Structure.sizeOf(FreeChunk.class)).isLessThan(currentChunkLimit)) { break; } if (--freeChunks == 0) { return false; } freeMemory -= currentChunk.size; currentChunkPointer = Structure.add(FreeChunkHolder.class, currentChunkPointer, 1); currentChunk = currentChunkPointer.value; currentChunkLimit = currentChunk.toAddress().add(currentChunk.size); } return true; }
public static RuntimeObject alloc(int size) { FreeChunk current = currentChunk; Address next = currentChunk.toAddress().add(size); if (!next.add(Structure.sizeOf(FreeChunk.class)).isLessThan(currentChunkLimit)) { getAvailableChunk(size); current = currentChunk; next = currentChunk.toAddress().add(size); } int freeSize = current.size; freeSize -= size; if (freeSize > 0) { currentChunk = next.toStructure(); currentChunk.size = freeSize; } else { freeMemory -= size; getAvailableChunkIfPossible(currentChunk.size + 1); } currentChunk.classReference = 0; freeMemory -= size; return current; }
Address limit = heapAddress().add(heapSize); loop: while (object.toAddress().isLessThan(limit)) { int tag = object.classReference; boolean free; if (!object.toAddress().isLessThan(currentRegionEnd)) { currentRegionIndex = (int) ((object.toAddress().toLong() - heapAddress().toLong()) / regionSize()); Region currentRegion = Structure.add(Region.class, regionsAddress(), currentRegionIndex);