Search in sources :

Example 36 with TypeReference

use of org.jikesrvm.classloader.TypeReference in project JikesRVM by JikesRVM.

the class LoadElimination method appendMove.

/**
 * Append a move instruction after a store instruction that caches
 * value in register r.
 *
 * @param r move target
 * @param src move source
 * @param store the instruction after which the move will be inserted
 */
static void appendMove(Register r, Operand src, Instruction store) {
    TypeReference type = src.getType();
    RegisterOperand rop = new RegisterOperand(r, type);
    store.insertAfter(Move.create(IRTools.getMoveOp(type), rop, src.copy()));
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 37 with TypeReference

use of org.jikesrvm.classloader.TypeReference in project JikesRVM by JikesRVM.

the class MachineReflection method packageParameters.

/**
 * Collects parameters into arrays of registers/spills, as required to
 * call specified method.
 *
 * @param method method whose parameters are to be packaged
 * @param thisArg the receiver argument
 * @param otherArgs all other arguments (primitives are boxed)
 * @param GPRs space for GPRs (empty array if none needed)
 * @param FPRs space for FPRs (empty array if none needed)
 * @param FPRmeta meta-data for FPRs ({@code null} if no SSE2)
 * @param Parameters more space for parameters. Refer to the source code
 *  to get all the details.
 *
 * @see #countParameters(RVMMethod) more machine-specific details
 */
@UnpreemptibleNoWarn("GC is disabled as Objects are turned into Words." + "avoid preemption but still allow calls to preemptible unboxing routines")
public static void packageParameters(RVMMethod method, Object thisArg, Object[] otherArgs, WordArray GPRs, double[] FPRs, byte[] FPRmeta, WordArray Parameters) {
    int GPR = 0;
    int FPR = SSE2_FULL ? 0 : FPRs.length;
    int parameter = 0;
    // 0, 1, 2
    int gp = NUM_PARAMETER_GPRS;
    // 0-8
    int fp = NUM_PARAMETER_FPRS;
    if (!method.isStatic()) {
        Word val = Magic.objectAsAddress(thisArg).toWord();
        if (gp > 0) {
            gp--;
            GPRs.set(GPR++, val);
        }
        Parameters.set(parameter++, val);
    }
    TypeReference[] types = method.getParameterTypes();
    for (int i = 0; i < types.length; i++) {
        TypeReference t = types[i];
        if (!t.isPrimitiveType()) {
            Word val = Magic.objectAsAddress(otherArgs[i]).toWord();
            if (gp > 0) {
                gp--;
                GPRs.set(GPR++, val);
            }
            Parameters.set(parameter++, val);
        } else if (t.isLongType()) {
            long l = (Long) otherArgs[i];
            if (VM.BuildFor32Addr) {
                if (gp > 0) {
                    gp--;
                    GPRs.set(GPR++, Word.fromIntZeroExtend((int) (l >>> 32)));
                    if (gp > 0) {
                        gp--;
                        GPRs.set(GPR++, Word.fromIntZeroExtend((int) (l)));
                    }
                }
                Parameters.set(parameter++, Word.fromIntZeroExtend((int) (l >>> 32)));
                Parameters.set(parameter++, Word.fromIntZeroExtend((int) l));
            } else {
                Word val = Word.fromLong(l);
                if (gp > 0) {
                    gp--;
                    GPRs.set(GPR++, val);
                }
                Parameters.set(parameter++, val);
                Parameters.set(parameter++, val);
            }
        } else if (t.isFloatType()) {
            if (fp > 0) {
                fp--;
                if (SSE2_FULL) {
                    FPRs[FPR] = (Float) otherArgs[i];
                    FPRmeta[FPR] = 0x0;
                    FPR++;
                } else {
                    FPRs[--FPR] = (Float) otherArgs[i];
                }
            }
            float f = (Float) otherArgs[i];
            Parameters.set(parameter++, Word.fromIntZeroExtend(Float.floatToIntBits(f)));
        } else if (t.isDoubleType()) {
            if (VM.BuildFor32Addr) {
                if (fp > 0) {
                    fp--;
                    if (SSE2_FULL) {
                        FPRs[FPR] = (Double) otherArgs[i];
                        FPRmeta[FPR] = 0x1;
                        FPR++;
                    } else {
                        FPRs[--FPR] = (Double) otherArgs[i];
                    }
                }
                double d = (Double) otherArgs[i];
                long l = Double.doubleToLongBits(d);
                Parameters.set(parameter++, Word.fromIntZeroExtend((int) (l >>> 32)));
                Parameters.set(parameter++, Word.fromIntZeroExtend((int) l));
            } else {
                if (fp > 0) {
                    fp--;
                    if (SSE2_FULL) {
                        FPRs[FPR] = (Double) otherArgs[i];
                        FPRmeta[FPR] = 0x1;
                        FPR++;
                    } else {
                        FPRs[--FPR] = (Double) otherArgs[i];
                    }
                }
                double d = (Double) otherArgs[i];
                long l = Double.doubleToLongBits(d);
                Word val = Word.fromLong(l);
                Parameters.set(parameter++, val);
                Parameters.set(parameter++, val);
            }
        } else if (t.isBooleanType()) {
            boolean b = (Boolean) otherArgs[i];
            Word val = Word.fromIntZeroExtend(b ? 1 : 0);
            if (gp > 0) {
                gp--;
                GPRs.set(GPR++, val);
            }
            Parameters.set(parameter++, val);
        } else if (t.isCharType()) {
            char c = (Character) otherArgs[i];
            Word val = Word.fromIntZeroExtend(c);
            if (gp > 0) {
                gp--;
                GPRs.set(GPR++, val);
            }
            Parameters.set(parameter++, val);
        } else {
            if (VM.VerifyAssertions)
                VM._assert(t.isByteType() || t.isShortType() || t.isIntType());
            int x = ((Number) otherArgs[i]).intValue();
            Word val = Word.fromIntZeroExtend(x);
            if (gp > 0) {
                gp--;
                GPRs.set(GPR++, val);
            }
            Parameters.set(parameter++, val);
        }
    }
}
Also used : Word(org.vmmagic.unboxed.Word) TypeReference(org.jikesrvm.classloader.TypeReference) UnpreemptibleNoWarn(org.vmmagic.pragma.UnpreemptibleNoWarn)

Example 38 with TypeReference

use of org.jikesrvm.classloader.TypeReference in project JikesRVM by JikesRVM.

the class MultianewarrayHelper method newArrayArray.

/**
 * Allocate something like {@code new Foo[cnt0][cnt1]...[cntN-1]},
 *                      or {@code new int[cnt0][cnt1]...[cntN-1]}.
 * @param methodId method id of caller
 * @param numDimensions number of array dimensions
 * @param typeId type id of type reference for array
 * @param argOffset position of word *above* `cnt0' argument within
 * caller's frame This is used to access the number of elements to
 * be allocated for each dimension.
 *
 * See also: bytecode 0xc5 ("multianewarray") in BaselineCompilerImpl
 *
 * @return newly allocated multidimensional array
 */
@Entrypoint
static Object newArrayArray(int methodId, int numDimensions, int typeId, int argOffset) throws NoClassDefFoundError, NegativeArraySizeException, OutOfMemoryError {
    if (numDimensions == 2) {
        int dim0, dim1;
        // fetch number of elements to be allocated for each array dimension
        VM.disableGC();
        Address argp = Magic.getFramePointer().plus(argOffset);
        argp = argp.minus(BYTES_IN_WORD);
        dim0 = argp.loadInt();
        argp = argp.minus(BYTES_IN_WORD);
        dim1 = argp.loadInt();
        VM.enableGC();
        // validate arguments
        if ((dim0 < 0) || (dim1 < 0))
            throw new NegativeArraySizeException();
        // create array
        TypeReference tRef = TypeReference.getTypeRef(typeId);
        RVMArray array = tRef.resolve().asArray();
        return RuntimeEntrypoints.buildTwoDimensionalArray(methodId, dim0, dim1, array);
    } else {
        // fetch number of elements to be allocated for each array dimension
        int[] numElements = new int[numDimensions];
        VM.disableGC();
        Address argp = Magic.getFramePointer().plus(argOffset);
        for (int i = 0; i < numDimensions; ++i) {
            argp = argp.minus(BYTES_IN_WORD);
            numElements[i] = argp.loadInt();
        }
        VM.enableGC();
        // validate arguments
        for (int elements : numElements) {
            if (elements < 0)
                throw new NegativeArraySizeException();
        }
        // create array
        TypeReference tRef = TypeReference.getTypeRef(typeId);
        RVMArray array = tRef.resolve().asArray();
        return RuntimeEntrypoints.buildMultiDimensionalArray(methodId, numElements, array);
    }
}
Also used : Address(org.vmmagic.unboxed.Address) RVMArray(org.jikesrvm.classloader.RVMArray) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 39 with TypeReference

use of org.jikesrvm.classloader.TypeReference in project JikesRVM by JikesRVM.

the class VMCommonLibrarySupport method getInt.

@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 1 })
static int getInt(Object object, RVMField field, Field jlrField, RVMClass accessingClass) throws IllegalAccessException, IllegalArgumentException {
    checkReadAccess(object, field, jlrField, accessingClass);
    TypeReference type = field.getType();
    if (type.isIntType()) {
        return field.getIntValueUnchecked(object);
    } else if (type.isShortType()) {
        return field.getShortValueUnchecked(object);
    } else if (type.isCharType()) {
        return field.getCharValueUnchecked(object);
    } else if (type.isByteType()) {
        return field.getByteValueUnchecked(object);
    } else {
        throwNewIllegalArgumentException("field type mismatch");
        return 0;
    }
}
Also used : TypeReference(org.jikesrvm.classloader.TypeReference) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Example 40 with TypeReference

use of org.jikesrvm.classloader.TypeReference in project JikesRVM by JikesRVM.

the class VMCommonLibrarySupport method getDouble.

@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 1 })
static double getDouble(Object object, RVMField field, Field jlrField, RVMClass accessingClass) throws IllegalAccessException, IllegalArgumentException {
    checkReadAccess(object, field, jlrField, accessingClass);
    TypeReference type = field.getType();
    if (type.isDoubleType()) {
        return field.getDoubleValueUnchecked(object);
    } else if (type.isFloatType()) {
        return field.getFloatValueUnchecked(object);
    } else if (type.isLongType()) {
        return field.getLongValueUnchecked(object);
    } else if (type.isIntType()) {
        return field.getIntValueUnchecked(object);
    } else if (type.isShortType()) {
        return field.getShortValueUnchecked(object);
    } else if (type.isCharType()) {
        return field.getCharValueUnchecked(object);
    } else if (type.isByteType()) {
        return field.getByteValueUnchecked(object);
    } else {
        throwNewIllegalArgumentException("field type mismatch");
        return 0.0d;
    }
}
Also used : TypeReference(org.jikesrvm.classloader.TypeReference) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

TypeReference (org.jikesrvm.classloader.TypeReference)164 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)58 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)43 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)38 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)30 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)28 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)27 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)25 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)24 RVMClass (org.jikesrvm.classloader.RVMClass)23 RVMField (org.jikesrvm.classloader.RVMField)21 Register (org.jikesrvm.compilers.opt.ir.Register)21 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)21 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)21 Address (org.vmmagic.unboxed.Address)21 RVMType (org.jikesrvm.classloader.RVMType)18 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)18 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)18 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)18 RVMMethod (org.jikesrvm.classloader.RVMMethod)17