Search in sources :

Example 71 with RVMField

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

the class JNIFunctions method SetIntField.

/**
 * SetIntField: set 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
 * @param value   integer value to assign
 */
private static void SetIntField(JNIEnvironment env, int objJREF, int fieldID, int value) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetIntField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setIntValueUnchecked(obj, value);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 72 with RVMField

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

the class JNIFunctions method SetBooleanField.

/**
 * SetBooleanField: set an instance field of type boolean
 * @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 value   boolean value to assign
 */
private static void SetBooleanField(JNIEnvironment env, int objJREF, int fieldID, boolean value) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetBooleanField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setBooleanValueUnchecked(obj, value);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 73 with RVMField

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

the class JNIFunctions method SetStaticIntField.

/**
 * SetStaticIntField:  set a static field of type integer
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldID the id for the RVMField that describes this field
 * @param fieldValue  The value to assign
 */
private static void SetStaticIntField(JNIEnvironment env, int classJREF, int fieldID, int fieldValue) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetStaticIntField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setIntValueUnchecked(null, fieldValue);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 74 with RVMField

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

the class JNIFunctions method SetFloatField.

/**
 * SetFloatField: set an instance field of type float
 * @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 value   float value to assign
 */
private static void SetFloatField(JNIEnvironment env, int objJREF, int fieldID, float value) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetFloatField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object obj = env.getJNIRef(objJREF);
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setFloatValueUnchecked(obj, value);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Example 75 with RVMField

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

the class JNIFunctions method GetStaticFieldID.

/**
 * GetStaticFieldID:  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 offset of a static 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 GetStaticFieldID(JNIEnvironment env, int classJREF, Address fieldNameAddress, Address descriptorAddress) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetStaticFieldID");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
        String fieldString = JNIGenericHelpers.createStringFromC(fieldNameAddress);
        Atom fieldName = Atom.findOrCreateAsciiAtom(fieldString);
        String descriptorString = JNIGenericHelpers.createStringFromC(descriptorAddress);
        Atom descriptor = Atom.findOrCreateAsciiAtom(descriptorString);
        RVMType rvmType = java.lang.JikesRVMSupport.getTypeForClass(cls);
        if (rvmType.isClassType()) {
            // First search for the fields in the class and its superclasses
            for (RVMClass curClass = rvmType.asClass(); curClass != null; curClass = curClass.getSuperClass()) {
                for (RVMField field : curClass.getStaticFields()) {
                    if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
                        return field.getId();
                    }
                }
            }
            // Now search all implemented interfaces (includes inherited interfaces)
            for (RVMClass curClass : rvmType.asClass().getAllImplementedInterfaces()) {
                for (RVMField field : curClass.getStaticFields()) {
                    if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
                        return field.getId();
                    }
                }
            }
        }
        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 : RVMType(org.jikesrvm.classloader.RVMType) RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

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