Search in sources :

Example 76 with RVMField

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

the class JNIFunctions method GetIntField.

/**
 * GetIntField:  read an instance field of type integer
 * @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 integer field, or 0 if the fieldID is incorrect
 */
private static int GetIntField(JNIEnvironment env, int objJREF, int fieldID) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetIntField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        return field.getIntValueUnchecked(obj);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 77 with RVMField

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

the class SSADictionary method registerDef.

/**
 * Register that instruction <code>s</code> writes a heap variable for
 * a given field.
 *
 * @param s the instruction in question
 * @param b  <code>s</code>'s basic block
 * @param fr the field heap variable the instruction modifies
 */
private void registerDef(Instruction s, BasicBlock b, FieldReference fr) {
    if (VM.VerifyAssertions)
        VM._assert(s.operator() != PHI);
    RVMField f = fr.peekResolvedField();
    HeapOperand<Object> H;
    if (f == null) {
        // can't resolve field at compile time.
        // This isn't quite correct, but is somewhat close.
        // See bug #1147433
        H = new HeapOperand<Object>(findOrCreateHeapVariable(fr));
    } else {
        // not included in the set
        if (heapTypes != null) {
            if (!heapTypes.contains(f)) {
                return;
            }
        }
        H = new HeapOperand<Object>(findOrCreateHeapVariable(f));
    }
    H.value.registerDef(b);
    HeapOperand<Object>[] Hprime = new HeapOperand[1];
    Hprime[0] = H;
    Hprime[0].setInstruction(s);
    defs.put(s, Hprime);
}
Also used : HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) RVMField(org.jikesrvm.classloader.RVMField)

Example 78 with RVMField

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

the class FieldLayout method layoutInstanceFields.

/**
 * This is where a class gets laid out.  Differences in layout strategy
 * are largely encapsulated in the layoutContext object.
 *
 * @param klass The class to lay out.
 */
public void layoutInstanceFields(RVMClass klass) {
    /*
     * Determine available field slots from parent classes, and allocate
     * a new context object for this class and its children.
     */
    FieldLayoutContext fieldLayout = getLayoutContext(klass);
    // Preferred alignment of object - modified to reflect added fields
    // New fields to be allocated for this object
    RVMField[] fields = klass.getDeclaredFields();
    if (DEBUG) {
        VM.sysWriteln("Laying out: ", klass.toString());
    }
    /*
    * Layout reference fields first pre-pass - This can help some
    * GC schemes.
    */
    if (clusterReferenceFields) {
        // For every field
        for (RVMField field : fields) {
            if (!field.isStatic() && !field.hasOffset()) {
                if (field.isReferenceType()) {
                    layoutField(fieldLayout, klass, field, BYTES_IN_ADDRESS);
                }
            }
        }
    }
    /*
    * Layout 8byte values first pre-pass - do this to avoid unnecessary
    * holes for object layouts such as an int followed by a long
    */
    if (largeFieldsFirst) {
        // For every field
        for (RVMField field : fields) {
            // Should we allocate space in the object now?
            if (!field.isStatic() && !field.hasOffset()) {
                if (field.getSize() == BYTES_IN_LONG) {
                    layoutField(fieldLayout, klass, field, BYTES_IN_LONG);
                }
            }
        }
    }
    for (RVMField field : fields) {
        // For every field
        // size of field
        int fieldSize = field.getSize();
        if (!field.isStatic() && !field.hasOffset()) {
            // Allocate space in the object?
            layoutField(fieldLayout, klass, field, fieldSize);
        }
    }
    // JavaHeader requires objects to be int sized/aligned
    if (VM.VerifyAssertions)
        VM._assert((fieldLayout.getObjectSize() & 0x3) == 0);
    /* Update class to reflect changes */
    updateClass(klass, fieldLayout);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 79 with RVMField

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

the class JNIFunctions method GetFieldID.

/**
 * GetFieldID:  return a field id, which can be cached in native code and reused
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldNameAddress a raw address to a null-terminated string in C for the field name
 * @param descriptorAddress a raw address to a null-terminated string in C for the descriptor
 * @return the fieldID of an instance field given the class, field name
 *         and type. Return 0 if the field is not found
 * @throws NoSuchFieldError if the specified field cannot be found
 * @throws ExceptionInInitializerError if the class initializer fails
 * @throws OutOfMemoryError if the system runs out of memory
 */
private static int GetFieldID(JNIEnvironment env, int classJREF, Address fieldNameAddress, Address descriptorAddress) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetFieldID");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        if (traceJNI)
            VM.sysWriteln("called GetFieldID with classJREF = ", classJREF);
        Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
        if (VM.VerifyAssertions)
            VM._assert(cls != null);
        String fieldString = JNIGenericHelpers.createStringFromC(fieldNameAddress);
        Atom fieldName = Atom.findOrCreateAsciiAtom(fieldString);
        String descriptorString = JNIGenericHelpers.createStringFromC(descriptorAddress);
        Atom descriptor = Atom.findOrCreateAsciiAtom(descriptorString);
        // list of all instance fields including superclasses.
        // Iterate in reverse order since if there are multiple instance
        // fields of the same name & descriptor we want to find the most derived one.
        RVMField[] fields = java.lang.JikesRVMSupport.getTypeForClass(cls).getInstanceFields();
        for (int i = fields.length - 1; i >= 0; i--) {
            RVMField f = fields[i];
            if (f.getName() == fieldName && f.getDescriptor() == descriptor) {
                return f.getId();
            }
        }
        // create exception and return 0 if not found
        env.recordException(new NoSuchFieldError(fieldString + ", " + descriptorString + " of " + cls));
        return 0;
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass) Atom(org.jikesrvm.classloader.Atom)

Example 80 with RVMField

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

the class JNIFunctions method SetObjectField.

/**
 * SetObjectField: set a instance field of type Object
 * @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
 * @param valueJREF a JREF index for the value to assign
 */
private static void SetObjectField(JNIEnvironment env, int objJREF, int fieldID, int valueJREF) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetObjectField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        Object value = env.getJNIRef(valueJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setObjectValueUnchecked(obj, value);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
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