Search in sources :

Example 61 with RVMField

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

the class ConvertToLowLevelIR method expandSysCallTarget.

/**
 * Expand symbolic SysCall target into a chain of loads from the bootrecord to
 * the desired target address.
 *
 * @param s the call instruction
 * @param ir the governing IR
 */
public static void expandSysCallTarget(Instruction s, IR ir) {
    MethodOperand sysM = Call.getMethod(s);
    if (sysM.getMemberRef().isFieldReference()) {
        RegisterOperand t1 = getStatic(s, ir, Entrypoints.the_boot_recordField);
        RVMField target = sysM.getMemberRef().asFieldReference().resolve();
        Operand ip = getField(s, ir, t1, target);
        Call.setAddress(s, ip);
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand) RVMField(org.jikesrvm.classloader.RVMField) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand)

Example 62 with RVMField

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

the class RuntimeEntrypoints method cloneClass2.

/**
 * Clone an object implementing a class - the actual clone
 *
 * @param obj the object to clone
 * @param type the type information for the class
 * @return the cloned object
 */
private static Object cloneClass2(Object obj, RVMType type) throws OutOfMemoryError {
    RVMClass cls = type.asClass();
    Object newObj = resolvedNewScalar(cls);
    for (RVMField f : cls.getInstanceFields()) {
        if (f.isReferenceType()) {
            // Writing a reference
            // Do via slower "VM-internal reflection" to enable
            // collectors to do the right thing wrt reference counting
            // and write barriers.
            f.setObjectValueUnchecked(newObj, f.getObjectValueUnchecked(obj));
        } else {
            // Primitive type
            // Check if we need to go via the slower barried path
            TypeReference fieldType = f.getType();
            if (Barriers.NEEDS_BOOLEAN_PUTFIELD_BARRIER && fieldType.isBooleanType()) {
                f.setBooleanValueUnchecked(newObj, f.getBooleanValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_BYTE_PUTFIELD_BARRIER && fieldType.isByteType()) {
                f.setByteValueUnchecked(newObj, f.getByteValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_CHAR_PUTFIELD_BARRIER && fieldType.isCharType()) {
                f.setCharValueUnchecked(newObj, f.getCharValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_DOUBLE_PUTFIELD_BARRIER && fieldType.isDoubleType()) {
                f.setDoubleValueUnchecked(newObj, f.getDoubleValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_FLOAT_PUTFIELD_BARRIER && fieldType.isFloatType()) {
                f.setFloatValueUnchecked(newObj, f.getFloatValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_INT_PUTFIELD_BARRIER && fieldType.isIntType()) {
                f.setIntValueUnchecked(newObj, f.getIntValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_LONG_PUTFIELD_BARRIER && fieldType.isLongType()) {
                f.setLongValueUnchecked(newObj, f.getLongValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_SHORT_PUTFIELD_BARRIER && fieldType.isShortType()) {
                f.setShortValueUnchecked(newObj, f.getShortValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_WORD_PUTFIELD_BARRIER && fieldType.isWordType()) {
                f.setWordValueUnchecked(newObj, f.getWordValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_ADDRESS_PUTFIELD_BARRIER && fieldType.isAddressType()) {
                f.setAddressValueUnchecked(newObj, f.getAddressValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_EXTENT_PUTFIELD_BARRIER && fieldType.isExtentType()) {
                f.setExtentValueUnchecked(newObj, f.getExtentValueUnchecked(obj));
                continue;
            } else if (Barriers.NEEDS_OFFSET_PUTFIELD_BARRIER && fieldType.isOffsetType()) {
                f.setOffsetValueUnchecked(newObj, f.getOffsetValueUnchecked(obj));
                continue;
            } else {
                // Can perform raw copy of field
                int size = f.getSize();
                Offset offset = f.getOffset();
                if (VM.BuildFor32Addr) {
                    // case first
                    if (size == BYTES_IN_INT) {
                        int bits = Magic.getIntAtOffset(obj, offset);
                        Magic.setIntAtOffset(newObj, offset, bits);
                        continue;
                    } else if (size == BYTES_IN_LONG) {
                        long bits = Magic.getLongAtOffset(obj, offset);
                        Magic.setLongAtOffset(newObj, offset, bits);
                        continue;
                    }
                } else {
                    // case first
                    if (size == BYTES_IN_LONG) {
                        long bits = Magic.getLongAtOffset(obj, offset);
                        Magic.setLongAtOffset(newObj, offset, bits);
                        continue;
                    } else if (size == BYTES_IN_INT) {
                        int bits = Magic.getIntAtOffset(obj, offset);
                        Magic.setIntAtOffset(newObj, offset, bits);
                        continue;
                    }
                }
                if (size == BYTES_IN_CHAR) {
                    char bits = Magic.getCharAtOffset(obj, offset);
                    Magic.setCharAtOffset(newObj, offset, bits);
                } else {
                    if (VM.VerifyAssertions)
                        VM._assert(size == BYTES_IN_BYTE);
                    byte bits = Magic.getByteAtOffset(obj, offset);
                    Magic.setByteAtOffset(newObj, offset, bits);
                }
            }
        }
    }
    return newObj;
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint) RVMClass(org.jikesrvm.classloader.RVMClass) Offset(org.vmmagic.unboxed.Offset)

Example 63 with RVMField

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

the class EntrypointHelper method getField.

/**
 * Get description of virtual machine field.
 * @param klass class containing field
 * @param member member name - something like "invokestatic"
 * @param type of field
 * @return corresponding RVMField
 */
static RVMField getField(String klass, String member, Class<?> type) {
    if (!VM.runningVM) {
        // avoid compiling this code into the boot image
        try {
            TypeReference tRef = TypeReference.findOrCreate(klass);
            RVMClass cls = tRef.resolve().asClass();
            cls.resolve();
            Atom memName = Atom.findOrCreateAsciiAtom(member);
            Atom typeName = TypeReference.findOrCreate(type).getName();
            RVMField field = cls.findDeclaredField(memName, typeName);
            if (field != null) {
                verifyPresenceOfEntrypointAnnotation(field);
                verifyThatFieldIsNotFinal(field);
                return field;
            }
        } catch (Throwable t) {
            throw new Error("Entrypoints.getField: can't resolve class=" + klass + " member=" + member + " desc=" + type, t);
        }
    }
    throw new Error("Entrypoints.getField: can't resolve class=" + klass + " member=" + member + " desc=" + type);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 64 with RVMField

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

the class JNIFunctions method GetShortField.

/**
 * GetShortField:  read an instance field of type short
 * @param env A JREF index for the JNI environment object
 * @param objJREF a JREF index for the target object
 * @param fieldID the id for the RVMField that describes this field
 * @return the value of the short field, or 0 if the fieldID is incorrect
 */
private static int GetShortField(JNIEnvironment env, int objJREF, int fieldID) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetShortField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        return field.getShortValueUnchecked(obj);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 65 with RVMField

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

the class JNIFunctions method GetDoubleField.

/**
 * GetDoubleField:  read an instance field of type double
 * @param env A JREF index for the JNI environment object
 * @param objJREF a JREF index for the target object
 * @param fieldID the id for the RVMField that describes this field
 * @return the value of the double field or 0 if the fieldID is incorrect
 */
private static double GetDoubleField(JNIEnvironment env, int objJREF, int fieldID) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetDoubleField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        return field.getDoubleValueUnchecked(obj);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0.0;
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Aggregations

RVMField (org.jikesrvm.classloader.RVMField)80 TypeReference (org.jikesrvm.classloader.TypeReference)21 Offset (org.vmmagic.unboxed.Offset)14 RVMClass (org.jikesrvm.classloader.RVMClass)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)9 Field (java.lang.reflect.Field)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 Atom (org.jikesrvm.classloader.Atom)7 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)6 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)6 RVMType (org.jikesrvm.classloader.RVMType)5 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)5 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)5 Address (org.vmmagic.unboxed.Address)5 FieldReference (org.jikesrvm.classloader.FieldReference)4 RVMMethod (org.jikesrvm.classloader.RVMMethod)4 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)4 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)4 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)4