@Unmanaged private void setSimpleNameCacheLowLevel(RuntimeObject object) { Address.ofObject(this).<RuntimeClass>toStructure().simpleName = object; }
@SuppressWarnings("unused") @Unmanaged private static RuntimeObject newInstanceLowLevel(RuntimeClass cls, int length) { return Allocator.allocateArray(cls.arrayType, length).toStructure(); }
@Unmanaged @PluggableDependency(ClassDependencyListener.class) private RuntimeObject getSimpleNameCacheLowLevel() { return Address.ofObject(this).<RuntimeClass>toStructure().simpleName; }
@Unmanaged private boolean isAssignableFromLowLevel(RuntimeClass other) { return Address.ofObject(this).<RuntimeClass>toStructure().isSupertypeOf.apply(other); }
static RuntimeObject dequeue() { Address result = GC.gcStorageAddress().add(Address.sizeOf() * head).getAddress(); if (++head >= limit) { head = 0; } return result.toStructure(); }
public static Address lookupResource(Address map, String string) { RuntimeString runtimeString = Address.ofObject(string).toStructure(); int hashCode = hashCode(runtimeString); int sz = map.getInt(); Address content = contentStart(map); for (int i = 0; i < sz; ++i) { int index = (hashCode + i) % sz; if (index < 0) { index += sz; } Address entry = content.add(index * Address.sizeOf() * 2); Address key = entry.getAddress(); if (key == null) { return null; } if (equals(key.toStructure(), runtimeString)) { return entry; } } return null; }
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(); }
private static int objectSize(FreeChunk object) { if (object.classReference == 0) { return object.size; } else { RuntimeClass cls = RuntimeClass.getClass(object.toAddress().toStructure()); if (cls.itemType == null) { return cls.size; } else { int itemSize = (cls.itemType.flags & RuntimeClass.PRIMITIVE) == 0 ? Address.sizeOf() : cls.itemType.size; RuntimeArray array = object.toAddress().toStructure(); Address address = Address.fromInt(Structure.sizeOf(RuntimeArray.class)); address = Address.align(address, itemSize); address = address.add(itemSize * array.size); address = Address.align(address, Address.sizeOf()); return address.toInt(); } } }
@SuppressWarnings("unused") private static RuntimeObject cloneLowLevel(RuntimeObject self) { RuntimeClass cls = RuntimeClass.getClass(self); int skip = Structure.sizeOf(RuntimeObject.class); int size; RuntimeObject copy; if (cls.itemType == null) { copy = Allocator.allocate(cls).toStructure(); size = cls.size; } else { RuntimeArray array = (RuntimeArray) self; copy = Allocator.allocateArray(cls, array.size).toStructure(); int itemSize = (cls.itemType.flags & RuntimeClass.PRIMITIVE) == 0 ? Address.sizeOf() : cls.itemType.size; Address headerSize = Address.align(Address.fromInt(Structure.sizeOf(RuntimeArray.class)), itemSize); size = itemSize * array.size + headerSize.toInt(); } if (size > skip) { Allocator.moveMemoryBlock(self.toAddress().add(skip), copy.toAddress().add(skip), size - skip); } return copy; }
public static Address allocateArray(RuntimeClass tag, int size) { int itemSize = (tag.itemType.flags & RuntimeClass.PRIMITIVE) != 0 ? tag.itemType.size : Address.sizeOf(); int sizeInBytes = Address.align(Address.fromInt(Structure.sizeOf(RuntimeArray.class)), itemSize).toInt(); sizeInBytes += itemSize * size; sizeInBytes = Address.align(Address.fromInt(sizeInBytes), Address.sizeOf()).toInt(); Address result = GC.alloc(sizeInBytes).toAddress(); fillZero(result, sizeInBytes); RuntimeArray array = result.toStructure(); array.classReference = tag.pack(); array.size = size; return result; }
@Unmanaged public static void throwException(Throwable exception) { thrownException = exception; RuntimeObject exceptionPtr = Address.ofObject(exception).toStructure(); RuntimeClass exceptionClass = RuntimeClass.getClass(exceptionPtr); Address stackFrame = ShadowStack.getStackTop(); stackLoop: while (stackFrame != null) { int callSiteId = ShadowStack.getCallSiteId(stackFrame); CallSite callSite = findCallSiteById(callSiteId); ExceptionHandler handler = callSite.firstHandler; for (int i = 0; i < callSite.handlerCount; ++i) { if (handler.exceptionClass == null || handler.exceptionClass.isSupertypeOf.apply(exceptionClass)) { ShadowStack.setExceptionHandlerId(stackFrame, handler.id); break stackLoop; } handler = Structure.add(ExceptionHandler.class, handler, 1); } ShadowStack.setExceptionHandlerId(stackFrame, callSiteId - 1); stackFrame = ShadowStack.getNextStackFrame(stackFrame); } }
private static void mark() { Allocator.fillZero(regionsAddress().toAddress(), regionMaxCount() * Structure.sizeOf(Region.class)); Address staticRoots = Mutator.getStaticGCRoots(); int staticCount = staticRoots.getInt(); staticRoots = staticRoots.add(Address.sizeOf()); while (staticCount-- > 0) { RuntimeObject object = staticRoots.getAddress().getAddress().toStructure(); if (object != null) { mark(object); } staticRoots = staticRoots.add(Address.sizeOf()); } for (Address stackRoots = ShadowStack.getStackTop(); stackRoots != null; stackRoots = ShadowStack.getNextStackFrame(stackRoots)) { int count = ShadowStack.getStackRootCount(stackRoots); Address stackRootsPtr = ShadowStack.getStackRootPointer(stackRoots); while (count-- > 0) { RuntimeObject obj = stackRootsPtr.getAddress().toStructure(); mark(obj); stackRootsPtr = stackRootsPtr.add(Address.sizeOf()); } } }
@Unmanaged public static RuntimeArray allocateMultiArray(RuntimeClass tag, Address dimensions, int dimensionCount) { int size = dimensions.getInt(); RuntimeArray array = allocateArray(tag, dimensions.getInt()).toStructure(); if (dimensionCount > 1) { Address arrayData = Structure.add(RuntimeArray.class, array, 1).toAddress(); arrayData = Address.align(arrayData, Address.sizeOf()); for (int i = 0; i < size; ++i) { RuntimeArray innerArray = allocateMultiArray(tag.itemType, dimensions.add(4), dimensionCount - 1); arrayData.putAddress(innerArray.toAddress()); arrayData = arrayData.add(Address.sizeOf()); } } return array; }
private static void sweep() { FreeChunkHolder freeChunkPtr = gcStorageAddress().toStructure(); freeChunks = 0; FreeChunk object = heapAddress().toStructure(); FreeChunk lastFreeSpace = null; long heapSize = availableBytes(); do { if (++currentRegionIndex == regionsCount) { object = limit.toStructure(); break loop; object = object.toAddress().add(size).toStructure(); currentChunkPointer = gcStorageAddress().toStructure(); sortFreeChunks(0, freeChunks - 1); currentChunk = currentChunkPointer.value;
layout = layout.add(2); int fieldOffset = layout.getShort(); RuntimeObject reference = object.toAddress().add(fieldOffset).getAddress().toStructure(); if (reference != null && !isMarked(reference)) { MarkQueue.enqueue(reference); Address base = Address.align(array.toAddress().add(RuntimeArray.class, 1), Address.sizeOf()); for (int i = 0; i < array.size; ++i) { RuntimeObject reference = base.getAddress().toStructure(); if (reference != null && !isMarked(reference)) { MarkQueue.enqueue(reference);
@Unmanaged public static RuntimeClass getClass(RuntimeObject object) { return Address.fromInt(object.classReference << 3).toStructure(); } }
static RuntimeObject dequeue() { Address result = GC.gcStorageAddress().add(Address.sizeOf() * head).getAddress(); if (++head >= limit) { head = 0; } return result.toStructure(); }
public static Address allocateArray(RuntimeClass tag, int size) { int itemSize = (tag.itemType.flags & RuntimeClass.PRIMITIVE) != 0 ? tag.itemType.size : 4; int sizeInBytes = Address.align(Address.fromInt(Structure.sizeOf(RuntimeArray.class)), itemSize).toInt(); sizeInBytes += itemSize * size; sizeInBytes = Address.align(Address.fromInt(sizeInBytes), 4).toInt(); Address result = GC.alloc(sizeInBytes).toAddress(); fillZero(result, sizeInBytes); RuntimeArray array = result.toStructure(); array.classReference = tag.toAddress().toInt() >> 3; array.size = size; return result; }
public static RuntimeArray allocateMultiArray(RuntimeClass tag, Address dimensions, int dimensionCount) { int size = dimensions.getInt(); RuntimeArray array = allocateArray(tag, dimensions.getInt()).toStructure(); if (dimensionCount > 1) { Address arrayData = Structure.add(RuntimeArray.class, array, 1).toAddress(); arrayData = Address.align(arrayData, Address.sizeOf()); for (int i = 0; i < size; ++i) { RuntimeArray innerArray = allocateMultiArray(tag.itemType, dimensions.add(4), dimensionCount - 1); arrayData.putAddress(innerArray.toAddress()); arrayData = arrayData.add(Address.sizeOf()); } } return array; }
@Unmanaged public static void throwException(Throwable exception) { thrownException = exception; RuntimeObject exceptionPtr = Address.ofObject(exception).toStructure(); RuntimeClass exceptionClass = RuntimeClass.getClass(exceptionPtr); Address stackFrame = ShadowStack.getStackTop(); stackLoop: while (stackFrame != null) { int callSiteId = ShadowStack.getCallSiteId(stackFrame); CallSite callSite = findCallSiteById(callSiteId); ExceptionHandler handler = callSite.firstHandler; for (int i = 0; i < callSite.handlerCount; ++i) { if (handler.exceptionClass == null || handler.exceptionClass.isSupertypeOf.apply(exceptionClass)) { ShadowStack.setExceptionHandlerId(stackFrame, handler.id); break stackLoop; } handler = Structure.add(ExceptionHandler.class, handler, 1); } ShadowStack.setExceptionHandlerId(stackFrame, callSiteId - 1); stackFrame = ShadowStack.getNextStackFrame(stackFrame); } }