use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class BootImageWriter method copyMagicArrayToBootImage.
/**
* Copy a unboxed array type to the boot image
* @param jdkObject object representation
* @param rvmArrayType type of array
* @param allocOnly allocate object don't write to fields
* @param overwriteAddress addresss to write to if overwriting
* @param parentObject object containing array
* @return address of array
* @throws IllegalAccessException
*/
private static Address copyMagicArrayToBootImage(Object jdkObject, RVMArray rvmArrayType, boolean allocOnly, Address overwriteAddress, Object parentObject) throws IllegalAccessException {
// Return object if it is already copied and not being overwritten
BootImageMap.Entry mapEntry = BootImageMap.findOrCreateEntry(jdkObject);
if ((!mapEntry.imageAddress.EQ(OBJECT_NOT_ALLOCATED)) && overwriteAddress.isMax()) {
return mapEntry.imageAddress;
}
if (verbosity.isAtLeast(DETAILED))
depth++;
RVMType rvmElementType = rvmArrayType.getElementType();
// allocate space in image
int arrayCount = Array.getLength(jdkObject);
Address arrayImageAddress;
if (overwriteAddress.isMax()) {
if (rvmElementType.equals(RVMType.CodeType)) {
arrayImageAddress = bootImage.allocateCode(rvmArrayType, arrayCount);
} else {
boolean needsIdentityHash = mapEntry.requiresIdentityHashCode();
int identityHashValue = mapEntry.getIdentityHashCode();
arrayImageAddress = bootImage.allocateArray(rvmArrayType, arrayCount, needsIdentityHash, identityHashValue, AlignmentEncoding.ALIGN_CODE_NONE);
}
} else {
arrayImageAddress = overwriteAddress;
}
mapEntry.imageAddress = arrayImageAddress;
if (verbosity.isAtLeast(DETAILED)) {
if (depth == DEPTH_CUTOFF)
say(SPACES.substring(0, depth + 1), "TOO DEEP: cutting off");
else if (depth < DEPTH_CUTOFF) {
String tab = SPACES.substring(0, depth + 1);
if (depth == 0 && jtocCount >= 0)
tab = tab + "jtoc #" + String.valueOf(jtocCount) + ": ";
int arraySize = rvmArrayType.getInstanceSize(arrayCount);
say(tab, "Copying array ", rvmArrayType.toString(), " length=", String.valueOf(arrayCount), (arraySize >= LARGE_ARRAY_SIZE) ? " large object!!!" : "");
}
}
// copy array elements from host jdk address space into image
if (rvmElementType.equals(RVMType.CodeType)) {
if (VM.BuildForIA32) {
byte[] values = (byte[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setByte(arrayImageAddress.plus(i), values[i]);
} else {
int[] values = (int[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setFullWord(arrayImageAddress.plus(i << LOG_BYTES_IN_INT), values[i]);
}
} else if (rvmElementType.equals(RVMType.AddressType)) {
Address[] values = (Address[]) jdkObject;
for (int i = 0; i < arrayCount; i++) {
Address addr = values[i];
String msg = "Address array element";
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, true), false, false);
}
} else if (rvmElementType.equals(RVMType.WordType)) {
Word[] values = (Word[]) jdkObject;
for (int i = 0; i < arrayCount; i++) {
String msg = "Word array element ";
Word addr = values[i];
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
}
} else if (rvmElementType.equals(RVMType.OffsetType)) {
Offset[] values = (Offset[]) jdkObject;
for (int i = 0; i < arrayCount; i++) {
String msg = "Offset array element " + i;
Offset addr = values[i];
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
}
} else if (rvmElementType.equals(RVMType.ExtentType)) {
Extent[] values = (Extent[]) jdkObject;
for (int i = 0; i < arrayCount; i++) {
String msg = "Extent array element ";
Extent addr = values[i];
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), getWordValue(addr, msg, false), false, false);
}
} else {
fail("unexpected magic array type: " + rvmArrayType);
}
// copy object's TIB into image, if it's not there already
if (!allocOnly) {
copyTIBToBootImage(rvmArrayType, jdkObject, mapEntry.imageAddress);
}
if (verbosity.isAtLeast(DETAILED))
depth--;
return mapEntry.imageAddress;
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class AbstractSpaceDescriptorTest method testCreateDescriptorAddressAddress.
@Test
public void testCreateDescriptorAddressAddress() throws Throwable {
Thread t = new MMTkThread() {
public void run() {
Extent chunkSize = Extent.fromLong(1L << VMLayoutConstants.LOG_BYTES_IN_CHUNK);
Extent increment = chunkSize.toWord().rshl(2).toExtent();
Extent size = chunkSize;
Address base = Address.zero().plus(chunkSize);
while (size.LE(VMLayoutConstants.MAX_SPACE_EXTENT)) {
int d = SpaceDescriptor.createDescriptor(base, base.plus(size));
for (Address addr = base; addr.LT(base.plus(size)); addr = addr.plus(increment)) {
if (VERBOSE)
System.out.printf("Testing address %s in space (%s,%s)%n", addr, base, base.plus(size));
Assert.assertTrue("addr " + addr + ", bounds(" + base + "," + base.plus(size) + ")", Space.isInSpace(d, addr));
}
Assert.assertFalse(Space.isInSpace(d, base.minus(4)));
Assert.assertFalse(Space.isInSpace(d, base.plus(size)));
size = size.plus(size);
}
}
};
runMMTkThread(t);
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Resolved method readVolatileExtentField.
private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
try {
Extent readVolatile = c.e;
System.out.println("Read value " + readVolatile.toLong() + " from field");
return readVolatile;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNonNullObject method readVolatileExtentField.
private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
try {
Extent readVolatile = c.e;
System.out.println("Read value " + readVolatile.toLong() + " from field");
return readVolatile;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
use of org.vmmagic.unboxed.Extent in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNullObject method readVolatileExtentField.
private static Extent readVolatileExtentField(ClassWithVolatileExtentField c) {
try {
Extent readVolatile = c.e;
System.out.println("Read value " + readVolatile.toLong() + " from field");
return readVolatile;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Extent field");
return NPE_EXTENT;
}
}
Aggregations