public static Address align(Address address, int alignment) { int value = address.toInt(); if (value == 0) { return address; } value = ((value - 1) / alignment + 1) * alignment; return Address.fromInt(value); }
@Unmanaged private static int getEnumConstantsSizeImpl(RuntimeClass cls) { Address enumValues = cls.enumValues; if (enumValues == null) { return -1; } return enumValues.getAddress().toInt(); }
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; }
private static void slowMemoryMove(Address source, Address target, int count) { if (source.toInt() > target.toInt()) { while (count-- > 0) { target.putByte(source.getByte()); target = target.add(1); source = source.add(1); } } else { source = source.add(count); target = target.add(count); while (count-- > 0) { target = target.add(-1); source = source.add(-1); target.putByte(source.getByte()); } } }
int diff = source.toInt() - target.toInt(); if (diff == 0) { return; Address alignedSourceStart = Address.fromInt(source.toInt() >>> 2 << 2); Address alignedTargetStart = Address.fromInt(target.toInt() >>> 2 << 2); Address alignedSourceEnd = Address.fromInt((source.toInt() + count) >>> 2 << 2); Address alignedTargetEnd = Address.fromInt((target.toInt() + count) >>> 2 << 2); if (source.toInt() > target.toInt()) { switch (source.toInt() - alignedSourceStart.toInt()) { case 0: alignedTargetStart.putInt(alignedSourceStart.getInt()); while (alignedSourceStart.toInt() < alignedSourceEnd.toInt()) { alignedTargetStart.putInt(alignedSourceStart.getInt()); alignedSourceStart = alignedSourceStart.add(4); switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; while (alignedSourceEnd.toInt() > alignedSourceStart.toInt()) { alignedSourceEnd = alignedSourceEnd.add(-4);
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 align(Address address, int alignment) { int value = address.toInt(); if (value == 0) { return address; } value = ((value - 1) / alignment + 1) * alignment; return Address.fromInt(value); }
@Unmanaged private static int getEnumConstantsSizeImpl(RuntimeClass cls) { Address enumValues = cls.enumValues; if (enumValues == null) { return -1; } return enumValues.getAddress().toInt(); }
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 Address allocate(RuntimeClass tag) { RuntimeObject object = GC.alloc(tag.size); fillZero(object.toAddress(), tag.size); object.classReference = tag.toAddress().toInt() >> 3; return object.toAddress(); }
private static void slowMemoryMove(Address source, Address target, int count) { if (source.toInt() > target.toInt()) { while (count-- > 0) { target.putByte(source.getByte()); target = target.add(1); source = source.add(1); } } else { source.add(count); target.add(count); while (count-- > 0) { target = target.add(-1); source = source.add(-1); target.putByte(source.getByte()); } } }
int diff = source.toInt() - target.toInt(); if (diff == 0) { return; Address alignedSourceStart = Address.fromInt(source.toInt() >>> 2 << 2); Address alignedTargetStart = Address.fromInt(target.toInt() >>> 2 << 2); Address alignedSourceEnd = Address.fromInt((source.toInt() + count) >>> 2 << 2); Address alignedTargetEnd = Address.fromInt((target.toInt() + count) >>> 2 << 2); if (source.toInt() > target.toInt()) { switch (source.toInt() - alignedSourceStart.toInt()) { case 0: alignedTargetStart.putInt(alignedSourceStart.getInt()); while (alignedSourceStart.toInt() < alignedSourceEnd.toInt()) { alignedTargetStart.putInt(alignedSourceStart.getInt()); alignedSourceStart = alignedSourceStart.add(4); switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; switch (source.toInt() + count - alignedSourceEnd.toInt()) { case 0: break; while (alignedSourceEnd.toInt() > alignedSourceStart.toInt()) { alignedTargetEnd.putInt(alignedSourceEnd.getInt());
private static int objectSize(RuntimeObject object) { if (object.classReference == 0) { return ((FreeChunk) object).size; } else { RuntimeClass cls = RuntimeClass.getClass(object); if (cls.itemType == null) { return cls.size; } else { int itemSize = (cls.itemType.flags & RuntimeClass.PRIMITIVE) == 0 ? Address.sizeOf() : cls.itemType.size; RuntimeArray array = (RuntimeArray) object; Address address = Address.fromInt(Structure.sizeOf(RuntimeArray.class)); address = Address.align(address, itemSize); address = address.add(itemSize * array.size); address = Address.align(address, 4); return address.toInt(); } } }