Search in sources :

Example 21 with Word

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();
    }
}
Also used : Word(org.vmmagic.unboxed.Word) Entrypoint(org.vmmagic.pragma.Entrypoint) Uninterruptible(org.vmmagic.pragma.Uninterruptible) NoNullCheck(org.vmmagic.pragma.NoNullCheck)

Example 22 with Word

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);
        }
    }
}
Also used : Word(org.vmmagic.unboxed.Word) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 23 with Word

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;
}
Also used : Word(org.vmmagic.unboxed.Word) TreeSet(java.util.TreeSet) WordComparator(org.vmmagic.unboxed.harness.WordComparator)

Example 24 with Word

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;
}
Also used : Word(org.vmmagic.unboxed.Word) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Example 25 with Word

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;
}
Also used : Word(org.vmmagic.unboxed.Word) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Aggregations

Word (org.vmmagic.unboxed.Word)62 Inline (org.vmmagic.pragma.Inline)15 Address (org.vmmagic.unboxed.Address)14 NoInline (org.vmmagic.pragma.NoInline)11 Offset (org.vmmagic.unboxed.Offset)10 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)8 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)8 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)8 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)8 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)8 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)8 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)8 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8