use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class ThinLock method holdsLock.
@Uninterruptible
@NoNullCheck
public static boolean holdsLock(Object o, Offset lockOffset, RVMThread thread) {
for (int cnt = 0; ; ++cnt) {
int tid = thread.getLockingId();
Word bits = Magic.getWordAtOffset(o, lockOffset);
if (bits.and(TL_STAT_MASK).EQ(TL_STAT_BIASABLE)) {
// if locked, then it is locked with a thin lock
return bits.and(TL_THREAD_ID_MASK).toInt() == tid && !bits.and(TL_LOCK_COUNT_MASK).isZero();
} else if (bits.and(TL_STAT_MASK).EQ(TL_STAT_THIN)) {
return bits.and(TL_THREAD_ID_MASK).toInt() == tid;
} else {
if (VM.VerifyAssertions)
VM._assert(bits.and(TL_STAT_MASK).EQ(TL_STAT_FAT));
// if locked, then it is locked with a fat lock
Lock l = Lock.getLock(getLockIndex(bits));
if (l != null) {
l.mutex.lock();
boolean result = (l.getOwnerId() == tid && l.getLockedObject() == o);
l.mutex.unlock();
return result;
}
}
RVMThread.yieldNoHandshake();
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class MachineReflection method packageParameters.
/**
* Collect parameters into arrays of registers/spills, as required to call specified method.
*/
public static void packageParameters(RVMMethod method, Object thisArg, Object[] otherArgs, WordArray GPRs, double[] FPRs, byte[] FPRmeta, WordArray Spills) {
int GPR = GPRs.length();
int FPR = FPRs.length;
int Spill = Spills.length();
int gp = FIRST_VOLATILE_GPR.value();
int fp = FIRST_VOLATILE_FPR.value();
if (!method.isStatic()) {
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, Reflection.unwrapObject(thisArg).toWord());
} else {
gp++;
GPRs.set(--GPR, Reflection.unwrapObject(thisArg).toWord());
}
}
TypeReference[] types = method.getParameterTypes();
for (int i = 0; i < types.length; i++) {
TypeReference t = types[i];
if (t.isLongType()) {
long l = Reflection.unwrapLong(otherArgs[i]);
if (VM.BuildFor64Addr) {
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, Word.fromLong(l));
} else {
gp++;
GPRs.set(--GPR, Word.fromLong(l));
}
} else {
Word hi = Word.fromIntZeroExtend((int) (l >>> 32));
Word lo = Word.fromIntZeroExtend((int) l);
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, hi);
Spills.set(--Spill, lo);
} else {
gp++;
GPRs.set(--GPR, hi);
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, lo);
} else {
gp++;
GPRs.set(--GPR, lo);
}
}
}
} else if (t.isFloatType()) {
float f = Reflection.unwrapFloat(otherArgs[i]);
if (fp > LAST_VOLATILE_FPR.value()) {
Spills.set(--Spill, Word.fromIntZeroExtend(Float.floatToIntBits(f)));
} else {
fp++;
FPRs[--FPR] = f;
}
} else if (t.isDoubleType()) {
if (fp > LAST_VOLATILE_FPR.value()) {
double d = Reflection.unwrapDouble(otherArgs[i]);
long l = Double.doubleToLongBits(d);
if (VM.BuildFor64Addr) {
Spills.set(--Spill, Word.fromLong(l));
} else {
Spills.set(--Spill, Word.fromIntZeroExtend((int) (l >>> 32)));
Spills.set(--Spill, Word.fromIntZeroExtend((int) l));
}
} else {
fp++;
FPRs[--FPR] = Reflection.unwrapDouble(otherArgs[i]);
}
} else if (t.isBooleanType()) {
Word val = Word.fromIntZeroExtend(Reflection.unwrapBooleanAsInt(otherArgs[i]));
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else if (t.isByteType()) {
Word val = Word.fromIntZeroExtend(Reflection.unwrapByte(otherArgs[i]));
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else if (t.isCharType()) {
Word val = Word.fromIntZeroExtend(Reflection.unwrapChar(otherArgs[i]));
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else if (t.isShortType()) {
Word val = Word.fromIntZeroExtend(Reflection.unwrapShort(otherArgs[i]));
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else if (t.isIntType()) {
Word val = Word.fromIntZeroExtend(Reflection.unwrapInt(otherArgs[i]));
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else if (!t.isPrimitiveType()) {
Word val = Reflection.unwrapObject(otherArgs[i]).toWord();
if (gp > LAST_VOLATILE_GPR.value()) {
Spills.set(--Spill, val);
} else {
gp++;
GPRs.set(--GPR, val);
}
} else {
if (VM.VerifyAssertions)
VM._assert(NOT_REACHED);
}
}
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class HarnessOptionSet method parseWordSet.
private Word[] parseWordSet(String str) {
TreeSet<Word> values = new TreeSet<Word>(new WordComparator());
for (String element : str.split(",")) {
Long value;
if (element.startsWith("0x")) {
value = Long.valueOf(element.substring(2), 16);
} else {
value = Long.valueOf(element);
}
values.add(Word.fromLong(value));
}
Word[] result = new Word[values.size()];
for (int i = 0; i < result.length; i++) {
result[i] = values.pollFirst();
}
return result;
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class Simplifier method refUshr.
private static DefUseEffect refUshr(Instruction s, OptOptions opts) {
if (opts.SIMPLIFY_REF_OPS) {
Operand op2 = Binary.getVal2(s);
Operand op1 = Binary.getVal1(s);
if (op2.isIntConstant()) {
int val2 = op2.asIntConstant().value;
if (op1.isConstant() && !op1.isMovableObjectConstant()) {
// BOTH CONSTANTS: FOLD
Word val1 = getAddressValue(op1).toWord();
Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(val1.rshl(val2).toAddress()));
return DefUseEffect.MOVE_FOLDED;
} else {
// ONLY OP2 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
if (val2 == 0) {
// x >>> 0 == x
Move.mutate(s, REF_MOVE, Binary.getClearResult(s), Binary.getClearVal1(s));
return DefUseEffect.MOVE_REDUCED;
}
if ((val2 >= BITS_IN_ADDRESS) || (val2 < 0)) {
// x >>> 32 == 0
Move.mutate(s, REF_MOVE, Binary.getClearResult(s), IC(0));
return DefUseEffect.MOVE_FOLDED;
}
}
} else if (op1.isConstant() && !op1.isMovableObjectConstant()) {
Word val1 = getAddressValue(op1).toWord();
// ONLY OP1 IS CONSTANT: ATTEMPT TO APPLY AXIOMS
if (val1.EQ(Word.zero())) {
// 0 >>> x == 0
Move.mutate(s, REF_MOVE, Binary.getClearResult(s), AC(Address.zero()));
return DefUseEffect.MOVE_FOLDED;
}
}
}
return DefUseEffect.UNCHANGED;
}
use of org.vmmagic.unboxed.Word in project JikesRVM by JikesRVM.
the class Simplifier method refNot.
private static DefUseEffect refNot(Instruction s, OptOptions opts) {
if (opts.SIMPLIFY_REF_OPS) {
Operand op = Unary.getVal(s);
if (op.isConstant() && !op.isMovableObjectConstant()) {
// CONSTANT: FOLD
Word val = getAddressValue(op).toWord();
Move.mutate(s, REF_MOVE, Unary.getClearResult(s), AC(val.not().toAddress()));
return DefUseEffect.MOVE_FOLDED;
}
}
return DefUseEffect.UNCHANGED;
}
Aggregations