use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class OptExecutionStateExtractor method dumpStackContent.
@SuppressWarnings("unused")
private static void dumpStackContent(byte[] stack, Offset fpOffset) {
VM.disableGC();
Address upper = Magic.objectAsAddress(stack).loadAddress(fpOffset);
Offset upOffset = upper.diff(Magic.objectAsAddress(stack));
VM.enableGC();
int cmid = Magic.getIntAtOffset(stack, fpOffset.plus(STACKFRAME_METHOD_ID_OFFSET));
OptCompiledMethod cm = (OptCompiledMethod) CompiledMethods.getCompiledMethod(cmid);
VM.sysWriteln("stack of " + cm.getMethod());
VM.sysWriteln(" NV area offset " + cm.getUnsignedNonVolatileOffset());
VM.sysWriteln(" first NV GPR " + cm.getFirstNonVolatileGPR());
VM.sysWriteln(" first NV FPR " + cm.getFirstNonVolatileFPR());
for (int i = 0; fpOffset.sLT(upOffset); i += BYTES_IN_STACKSLOT, fpOffset = fpOffset.plus(BYTES_IN_STACKSLOT)) {
Word content = Magic.getWordAtOffset(stack, fpOffset);
VM.sysWrite(" 0x");
VM.sysWrite(content);
VM.sysWriteln(" " + i);
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class Registers method adjustESP.
@Uninterruptible
@Override
public void adjustESP(Offset delta, boolean traceAdjustments) {
Word old = getGPRs().get(FRAME_POINTER.value());
getGPRs().set(FRAME_POINTER.value(), old.plus(delta));
if (traceAdjustments) {
VM.sysWrite(" esp =");
VM.sysWrite(getGPRs().get(FRAME_POINTER.value()));
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class JNIGenericHelpers method strlen.
/**
* Computes the length of the given null-terminated string.
* <p>
* <strong>NOTE: This method may read undefined memory if {@link #ALLOW_READS_OF_UNDEFINED_MEMORY}
* is true. However, the behaviour of this method is always well-defined.</strong>
*
* @param ptr address of string in memory
* @return the length of the string in bytes
*/
public static int strlen(Address ptr) {
int length = 0;
// page level (or even coarser).
if (ALLOW_READS_OF_UNDEFINED_MEMORY) {
// align address to size of machine
while (!ptr.toWord().and(Word.fromIntZeroExtend(BYTES_IN_ADDRESS - 1)).isZero()) {
byte bits = ptr.loadByte(Offset.fromIntZeroExtend(length));
if (bits == 0) {
return length;
}
length++;
}
// Ascii characters are normally in the range 1 to 128, if we subtract 1
// from each byte and look if the top bit of the byte is set then if it is
// the chances are the byte's value is 0. Loop over words doing this quick
// test and then do byte by byte tests when we think we have the 0
Word onesToSubtract;
Word maskToTestHighBits;
if (VM.BuildFor32Addr) {
onesToSubtract = Word.fromIntZeroExtend(0x01010101);
maskToTestHighBits = Word.fromIntZeroExtend(0x80808080);
} else {
onesToSubtract = Word.fromLong(0x0101010101010101L);
maskToTestHighBits = Word.fromLong(0x8080808080808080L);
}
while (true) {
Word bytes = ptr.loadWord(Offset.fromIntZeroExtend(length));
if (!bytes.minus(onesToSubtract).and(maskToTestHighBits).isZero()) {
if (VM.LittleEndian) {
for (int byteOff = 0; byteOff < BYTES_IN_ADDRESS; byteOff++) {
if (bytes.and(Word.fromIntZeroExtend(0xFF)).isZero()) {
return length + byteOff;
}
bytes = bytes.rshl(BITS_IN_BYTE);
}
} else {
for (int byteOff = BYTES_IN_ADDRESS - 1; byteOff >= 0; byteOff--) {
if (bytes.rshl(byteOff * 8).and(Word.fromIntZeroExtend(0xFF)).isZero()) {
return length + (BYTES_IN_ADDRESS - 1 - byteOff);
}
}
}
}
length += BYTES_IN_ADDRESS;
}
} else {
// Avoid reads of undefined memory by proceeding one byte at a time
Address currentAddress = ptr;
byte currentByte = currentAddress.loadByte(Offset.fromIntSignExtend(length));
while (currentByte != 0) {
length++;
currentByte = currentAddress.loadByte(Offset.fromIntSignExtend(length));
}
return length;
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class Registers method adjustESP.
/**
* A thread's stack has been moved or resized.
* Adjust the ESP register to reflect new position.
*
* @param delta The displacement to be applied
* @param traceAdjustments Log all adjustments to stderr if true
*/
@Uninterruptible
@Override
public void adjustESP(Offset delta, boolean traceAdjustments) {
Word old = getGPRs().get(ESP.value());
getGPRs().set(ESP.value(), old.plus(delta));
if (traceAdjustments) {
VM.sysWrite(" esp =");
VM.sysWrite(getGPRs().get(ESP.value()));
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class JavaHeader method installHashCode.
@NoInline
@Interruptible
protected static int installHashCode(Object o) {
Word hashCode;
do {
hashCodeGenerator = hashCodeGenerator.plus(Word.one().lsh(HASH_CODE_SHIFT));
hashCode = hashCodeGenerator.and(HASH_CODE_MASK);
} while (hashCode.isZero());
while (true) {
Word statusWord = Magic.prepareWord(o, STATUS_OFFSET);
if (!(statusWord.and(HASH_CODE_MASK).isZero())) {
// some other thread installed a hashcode
return statusWord.and(HASH_CODE_MASK).rshl(HASH_CODE_SHIFT).toInt();
}
if (Magic.attemptWord(o, STATUS_OFFSET, statusWord, statusWord.or(hashCode))) {
// we installed the hash code
return hashCode.rshl(HASH_CODE_SHIFT).toInt();
}
}
}
Aggregations