Search in sources :

Example 26 with Atom

use of org.jikesrvm.classloader.Atom 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 27 with Atom

use of org.jikesrvm.classloader.Atom 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)

Example 28 with Atom

use of org.jikesrvm.classloader.Atom 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 29 with Atom

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

the class OptTestHarnessTest method getTypeReferenceForClass.

private TypeReference getTypeReferenceForClass(String className) {
    Atom classDescriptorAsAtom = Atom.findAsciiAtom(className).descriptorFromClassName();
    ClassLoader appCl = ApplicationClassLoader.getSystemClassLoader();
    return TypeReference.findOrCreate(appCl, classDescriptorAsAtom);
}
Also used : ApplicationClassLoader(org.jikesrvm.classloader.ApplicationClassLoader) Atom(org.jikesrvm.classloader.Atom)

Aggregations

Atom (org.jikesrvm.classloader.Atom)29 RVMClass (org.jikesrvm.classloader.RVMClass)14 RVMMethod (org.jikesrvm.classloader.RVMMethod)11 TypeReference (org.jikesrvm.classloader.TypeReference)10 RVMField (org.jikesrvm.classloader.RVMField)7 RVMType (org.jikesrvm.classloader.RVMType)5 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)3 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)3 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)3 IRTools.offsetOperand (org.jikesrvm.compilers.opt.ir.IRTools.offsetOperand)2 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)2 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)2 Method (java.lang.reflect.Method)1 TypeVariable (java.lang.reflect.TypeVariable)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 ApplicationClassLoader (org.jikesrvm.classloader.ApplicationClassLoader)1 NativeMethod (org.jikesrvm.classloader.NativeMethod)1 NormalMethod (org.jikesrvm.classloader.NormalMethod)1 RVMArray (org.jikesrvm.classloader.RVMArray)1