use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNullObject method readVolatileWordField.
private static Word readVolatileWordField(ClassWithVolatileWordField c) {
try {
Word readVolatile = c.w;
System.out.println("Read value " + readVolatile.toLong() + " from field");
return readVolatile;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Word field");
return NPE_WORD;
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class TestNullChecks_Unresolved_ReadFromNullObject method readWordField.
private static Word readWordField(ClassWithWordField c) {
try {
Word read = c.w;
System.out.println("Read value " + read.toLong() + " from field");
return read;
} catch (NullPointerException npe) {
System.out.println("Caught NPE when reading Word field");
return NPE_WORD;
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class TestSynchronization method testTryCompareAndSwapWord.
private static void testTryCompareAndSwapWord() throws SecurityException, NoSuchFieldException {
System.out.println("--- testTryCompareAndSwapWord ----");
ClassWithWordField to = createClassWithWordField();
Offset off = java.lang.reflect.JikesRVMSupport.getFieldOf((ClassWithWordField.class.getField("word"))).getOffset();
Word firstWord = VM.BuildFor64Addr ? Word.fromLong(Long.MIN_VALUE) : Word.fromIntSignExtend(Integer.MIN_VALUE);
boolean swap = Synchronization.tryCompareAndSwap(to, off, Word.zero(), firstWord);
wordTest("Synchronization.tryCompareAndSwap(to, off, Word.zero(), firstWord)", to.word, firstWord);
booleanTest("return value", swap, true);
to.word = firstWord;
Word secondWord = Word.max();
swap = Synchronization.tryCompareAndSwap(to, off, firstWord, secondWord);
wordTest("Synchronization.tryCompareAndSwap(to, off, firstWord, secondWord)", to.word, secondWord);
booleanTest("return value", swap, true);
to.word = secondWord;
swap = Synchronization.tryCompareAndSwap(to, off, secondWord, firstWord);
wordTest("Synchronization.tryCompareAndSwap(to, off, secondWord, firstWord)", to.word, firstWord);
booleanTest("return value", swap, true);
to.word = secondWord;
swap = Synchronization.tryCompareAndSwap(to, off, secondWord, secondWord);
wordTest("Synchronization.tryCompareAndSwap(to, off, secondWord, secondWord)", to.word, secondWord);
booleanTest("return value", swap, true);
to.word = firstWord;
swap = Synchronization.tryCompareAndSwap(to, off, secondWord, firstWord);
wordTest("Synchronization.tryCompareAndSwap(to, off, secondWord, firstWord)", to.word, firstWord);
booleanTest("return value", swap, false);
}
use of org.vmmagic.unboxed.Word 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.Word in project JikesRVM by JikesRVM.
the class BootImageWriter method copyArrayToBootImage.
/**
* Write array to boot image
* @param arrayCount
* @param arrayImageAddress
* @param jdkObject
* @param jdkType
* @param rvmArrayType
* @param allocOnly
* @param overwriteAddress
* @param parentObject
* @param untraced
* @return
* @throws IllegalAccessException
*/
private static Address copyArrayToBootImage(int arrayCount, Address arrayImageAddress, Object jdkObject, Class<?> jdkType, RVMArray rvmArrayType, boolean allocOnly, Address overwriteAddress, Object parentObject, boolean untraced) throws IllegalAccessException {
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 ", jdkType.getName(), " length=", String.valueOf(arrayCount), (arraySize >= LARGE_ARRAY_SIZE) ? " large object!!!" : "");
}
}
RVMType rvmElementType = rvmArrayType.getElementType();
// recurse on values that are references
if (rvmElementType.isPrimitiveType()) {
// array element is logical or numeric type
if (rvmElementType.equals(RVMType.BooleanType)) {
boolean[] values = (boolean[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setByte(arrayImageAddress.plus(i), values[i] ? 1 : 0);
} else if (rvmElementType.equals(RVMType.ByteType)) {
byte[] values = (byte[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setByte(arrayImageAddress.plus(i), values[i]);
} else if (rvmElementType.equals(RVMType.CharType)) {
char[] values = (char[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setHalfWord(arrayImageAddress.plus(i << LOG_BYTES_IN_CHAR), values[i]);
} else if (rvmElementType.equals(RVMType.ShortType)) {
short[] values = (short[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setHalfWord(arrayImageAddress.plus(i << LOG_BYTES_IN_SHORT), values[i]);
} else if (rvmElementType.equals(RVMType.IntType)) {
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.LongType)) {
long[] values = (long[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setDoubleWord(arrayImageAddress.plus(i << LOG_BYTES_IN_LONG), values[i]);
} else if (rvmElementType.equals(RVMType.FloatType)) {
float[] values = (float[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setFullWord(arrayImageAddress.plus(i << LOG_BYTES_IN_FLOAT), Float.floatToIntBits(values[i]));
} else if (rvmElementType.equals(RVMType.DoubleType)) {
double[] values = (double[]) jdkObject;
for (int i = 0; i < arrayCount; ++i) bootImage.setDoubleWord(arrayImageAddress.plus(i << LOG_BYTES_IN_DOUBLE), Double.doubleToLongBits(values[i]));
} else {
fail("unexpected primitive array type: " + rvmArrayType);
}
} else {
// array element is reference type
boolean isTIB = parentObject instanceof TIB;
Object[] values = (Object[]) jdkObject;
Class<?> jdkClass = jdkObject.getClass();
if (!allocOnly) {
for (int i = 0; i < arrayCount; ++i) {
if (values[i] != null) {
if (verbosity.isAtLeast(DETAILED))
traceContext.push(values[i].getClass().getName(), jdkClass.getName(), i);
if (isTIB && values[i] instanceof Word) {
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), (Word) values[i], false, false);
} else if (isTIB && values[i] == LazyCompilationTrampoline.getInstructions()) {
Address codeAddress = arrayImageAddress.plus(((TIB) parentObject).lazyMethodInvokerTrampolineIndex() << LOG_BYTES_IN_ADDRESS);
bootImage.setAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), codeAddress.toWord(), false, false);
} else {
copyReferenceFieldToBootImage(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), values[i], jdkObject, !untraced, !untraced, null, null);
}
if (verbosity.isAtLeast(DETAILED))
traceContext.pop();
} else {
bootImage.setNullAddressWord(arrayImageAddress.plus(i << LOG_BYTES_IN_ADDRESS), !untraced, !untraced, true);
}
}
}
}
return arrayImageAddress;
}
Aggregations