Search in sources :

Example 6 with Atom

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

the class JNIFunctions method GetStaticMethodID.

/**
 * GetStaticMethodID:  return the method ID for invocation later
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the class object
 * @param methodNameAddress a raw address to a null-terminated string in C for the method name
 * @param methodSigAddress a raw address to a null-terminated string in C for (TODO: document me)
 * @return a method ID or null if it fails
 * @throws NoSuchMethodError if the method is not found
 * @throws ExceptionInInitializerError if the initializer fails
 * @throws OutOfMemoryError if the system runs out of memory
 */
private static int GetStaticMethodID(JNIEnvironment env, int classJREF, Address methodNameAddress, Address methodSigAddress) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetStaticMethodID");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        // obtain the names as String from the native space
        String methodString = JNIGenericHelpers.createStringFromC(methodNameAddress);
        Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
        String sigString = JNIGenericHelpers.createStringFromC(methodSigAddress);
        Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
        // get the target class
        Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
        RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
        if (!type.isClassType()) {
            env.recordException(new NoSuchMethodError());
            return 0;
        }
        RVMClass klass = type.asClass();
        if (!klass.isInitialized()) {
            RuntimeEntrypoints.initializeClassForDynamicLink(klass);
        }
        // Find the target method
        RVMMethod meth = klass.findStaticMethod(methodName, sigName);
        if (meth == null) {
            env.recordException(new NoSuchMethodError());
            return 0;
        }
        if (traceJNI)
            VM.sysWriteln("got method " + meth);
        return meth.getId();
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMType(org.jikesrvm.classloader.RVMType) RVMClass(org.jikesrvm.classloader.RVMClass) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 7 with Atom

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

the class JNIFunctions method GetMethodID.

/**
 * GetMethodID:  get the virtual method ID given the name and the signature
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the class object
 * @param methodNameAddress a raw address to a null-terminated string in C for the method name
 * @param methodSigAddress a raw address to a null-terminated string in C for the method signature
 * @return id of a MethodReference
 * @throws NoSuchMethodError if the method cannot be found
 * @throws ExceptionInInitializerError if the class or interface static initializer fails
 * @throws OutOfMemoryError if the system runs out of memory
 */
private static int GetMethodID(JNIEnvironment env, int classJREF, Address methodNameAddress, Address methodSigAddress) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetMethodID");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        // obtain the names as String from the native space
        String methodString = JNIGenericHelpers.createStringFromC(methodNameAddress);
        Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
        String sigString = JNIGenericHelpers.createStringFromC(methodSigAddress);
        Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
        // get the target class
        Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
        RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
        if (!type.isClassType()) {
            env.recordException(new NoSuchMethodError());
            return 0;
        }
        RVMClass klass = type.asClass();
        if (!klass.isInitialized()) {
            RuntimeEntrypoints.initializeClassForDynamicLink(klass);
        }
        // Find the target method
        final RVMMethod meth;
        if (methodString.equals("<init>")) {
            meth = klass.findInitializerMethod(sigName);
        } else {
            meth = klass.findVirtualMethod(methodName, sigName);
        }
        if (meth == null) {
            env.recordException(new NoSuchMethodError(klass + ": " + methodName + " " + sigName));
            return 0;
        }
        if (traceJNI)
            VM.sysWriteln("got method " + meth);
        return meth.getId();
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMType(org.jikesrvm.classloader.RVMType) RVMClass(org.jikesrvm.classloader.RVMClass) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 8 with Atom

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

the class InterfaceHierarchy method getUniqueImplementation.

/**
 * If, in the current class hierarchy, there is exactly one method that
 * defines the interface method foo, then return the unique
 * implementation.  If there is not a unique implementation, return
 * null.
 *
 * @param foo an interface method
 * @return the unique implementation if it exists, {@code null} otherwise
 */
public static synchronized RVMMethod getUniqueImplementation(RVMMethod foo) {
    RVMClass I = foo.getDeclaringClass();
    ImmutableEntryHashSetRVM<RVMClass> classes = allImplementors(I);
    RVMMethod firstMethod = null;
    Atom name = foo.getName();
    Atom desc = foo.getDescriptor();
    for (RVMClass klass : classes) {
        RVMMethod m = klass.findDeclaredMethod(name, desc);
        if (firstMethod == null) {
            firstMethod = m;
        }
        if (m != firstMethod) {
            return null;
        }
    }
    return firstMethod;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 9 with Atom

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

the class CompilerAdviceInfoReader method readOneAttribute.

/**
 * Actual reading is done here.  This method reads one attribute
 * from a single line of an input stream.  There are six elements
 * per line corresponding to each call site. First three are
 * strings, <i>class name</i>, <i>method name</i>, <i>method
 * signature</i>, followed by one number,
 * <i>compiler advice</i>.
 *
 * @param st an input stream
 * @return an compileration advice atribute
 */
private static CompilerAdviceAttribute readOneAttribute(StringTokenizer st) {
    int compiler, optLevel = -1;
    try {
        Atom cls = Atom.findOrCreateUnicodeAtom(st.nextToken());
        Atom mth = Atom.findOrCreateUnicodeAtom(st.nextToken());
        Atom sig = Atom.findOrCreateUnicodeAtom(st.nextToken());
        compiler = Integer.parseInt(st.nextToken());
        optLevel = Integer.parseInt(st.nextToken());
        // this is the attribute which will be returned
        CompilerAdviceAttribute newAttrib;
        if (optLevel >= 0) {
            newAttrib = new CompilerAdviceAttribute(cls, mth, sig, compiler, optLevel);
        } else {
            newAttrib = new CompilerAdviceAttribute(cls, mth, sig, compiler);
        }
        return newAttrib;
    } catch (NoSuchElementException e) {
        return null;
    }
}
Also used : Atom(org.jikesrvm.classloader.Atom) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with Atom

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

the class OptTestHarness method findDeclaredOrFirstMethod.

/**
 * Finds a method, either one with a given descriptor or the first matching
 * one in in the given class.
 * @param klass the class to search
 * @param methname the method's name
 * @param methdesc a descriptor of the method's signature if a specific
 *  method is desired or "-" to find the first method with the given name
 * @return the method or {@code null} if no method was found
 */
RVMMethod findDeclaredOrFirstMethod(RVMClass klass, String methname, String methdesc) {
    if (klass == null)
        return null;
    Atom methodName = Atom.findOrCreateAsciiAtom(methname);
    Atom methodDesc = "-".equals(methdesc) ? null : Atom.findOrCreateAsciiAtom(methdesc);
    for (RVMMethod method : klass.getDeclaredMethods()) {
        if (method.getName() == methodName && ((methodDesc == null) || (methodDesc == method.getDescriptor()))) {
            return method;
        }
    }
    if (methodDesc == null) {
        output.sysErrPrintln("No method named " + methodName + " found in class " + klass);
    } else {
        output.sysErrPrintln("No method matching " + methodName + " " + methodDesc + " found in class " + klass);
    }
    return null;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) 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