Search in sources :

Example 16 with Atom

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

the class ClassLoaderProxy method lookupMethod.

// --------------------------------------------------------------------------
// Querry classloader data structures
// --------------------------------------------------------------------------
/**
 * Find the method of the given class that matches the given descriptor.
 *
 * @param cls the method's class
 * @param ref name and descriptor of the method
 * @return a matching method or {@code null} if none was found
 */
public static RVMMethod lookupMethod(RVMClass cls, MethodReference ref) {
    RVMMethod newmeth = null;
    if (cls.isResolved() && !cls.isInterface()) {
        Atom mn = ref.getName();
        Atom md = ref.getDescriptor();
        for (; (newmeth == null) && (cls != null); cls = cls.getSuperClass()) {
            newmeth = cls.findDeclaredMethod(mn, md);
        }
    }
    return newmeth;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom)

Example 17 with Atom

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

the class Class method forNameInternal.

private static Class<?> forNameInternal(String className, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException, LinkageError, ExceptionInInitializerError {
    if (className == null) {
        throw new ClassNotFoundException("Cannot load a class with a name of null");
    }
    try {
        if (className.startsWith("[")) {
            if (!validArrayDescriptor(className)) {
                throw new ClassNotFoundException(className);
            }
        }
        Atom descriptor = Atom.findOrCreateAsciiAtom(className.replace('.', '/')).descriptorFromClassName();
        TypeReference tRef = TypeReference.findOrCreate(classLoader, descriptor);
        RVMType ans = tRef.resolve();
        Callbacks.notifyForName(ans);
        if (initialize && !ans.isInitialized()) {
            ans.prepareForFirstUse();
        }
        return ans.getClassForType();
    } catch (NoClassDefFoundError ncdfe) {
        Throwable cause2 = ncdfe.getCause();
        ClassNotFoundException cnf;
        // If we get a NCDFE that was caused by a CNFE, throw the original CNFE.
        if (cause2 instanceof ClassNotFoundException)
            cnf = (ClassNotFoundException) cause2;
        else
            cnf = new ClassNotFoundException(className, ncdfe);
        throw cnf;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom)

Example 18 with Atom

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

the class Class method getMethod.

public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throwNoSuchMethodException(name, parameterTypes);
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    if (aName == RVMClassLoader.StandardClassInitializerMethodName || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
        // <init> and <clinit> are not methods.
        throwNoSuchMethodException(name, parameterTypes);
    }
    // (1) Scan the declared public methods of this class and each of its superclasses
    RVMMethod answer = getMethodInternal1(aName, parameterTypes);
    if (answer == null) {
        // (2) Now we need to consider methods inherited from interfaces.
        // Because we inject the requisite Miranda methods, we can do this simply
        // by looking at this class's virtual methods instead of searching interface hierarchies.
        answer = getMethodInternal2(aName, parameterTypes);
    }
    if (answer == null) {
        throwNoSuchMethodException(name, parameterTypes);
    }
    return JikesRVMSupport.createMethod(answer);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom)

Example 19 with Atom

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

the class Class method getMethods.

public Method[] getMethods() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);
    RVMMethod[] static_methods = type.getStaticMethods();
    RVMMethod[] virtual_methods = type.getVirtualMethods();
    HashSet<Method> coll = new HashSet<Method>(static_methods.length + virtual_methods.length);
    for (RVMMethod meth : static_methods) {
        if (meth.isPublic()) {
            coll.add(JikesRVMSupport.createMethod(meth));
        }
    }
    for (RVMMethod meth : virtual_methods) {
        if (meth.isPublic()) {
            coll.add(JikesRVMSupport.createMethod(meth));
        }
    }
    // The Java API says that duplicate versions are returned if multiple
    // versions of a method are defined by a class. This only applies to
    // abstract classes and interfaces because normal classes always have
    // exactly one definition for a given signature-name pair.
    RVMClass thisClass = type.asClass();
    boolean isAbstract = thisClass.isAbstract();
    if (isInterface() || isAbstract) {
        // For each virtual method , search all superinterfaces
        // to find all declarations that aren't shadowed by superinterfaces and
        // add those to the set of methods.
        HashSet<Method> methods = new HashSet<Method>();
        for (RVMMethod m : virtual_methods) {
            Atom name = m.getName();
            Atom desc = m.getDescriptor();
            if (isAbstract && !m.getDeclaringClass().isInterface()) {
                // method.
                continue;
            }
            collectDeclarations(thisClass, name, desc, methods);
        }
        coll.addAll(methods);
    }
    return coll.toArray(new Method[coll.size()]);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Method(java.lang.reflect.Method) RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom) HashSet(java.util.HashSet) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 20 with Atom

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

the class Class method getDeclaredMethod.

public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType())
        throwNoSuchMethodException(name, parameterTypes);
    if (name == null) {
        throwNoSuchMethodException(name, parameterTypes);
    }
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    if (aName == RVMClassLoader.StandardClassInitializerMethodName || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
        // <init> and <clinit> are not methods.
        throwNoSuchMethodException(name, parameterTypes);
    }
    RVMMethod[] methods = type.asClass().getDeclaredMethods();
    RVMMethod answer = null;
    for (RVMMethod meth : methods) {
        if (meth.getName() == aName && parametersMatch(meth.getParameterTypes(), parameterTypes)) {
            if (answer == null) {
                answer = meth;
            } else {
                RVMMethod m2 = meth;
                if (answer.getReturnType().resolve().isAssignableFrom(m2.getReturnType().resolve())) {
                    answer = m2;
                }
            }
        }
    }
    if (answer == null) {
        throwNoSuchMethodException(name, parameterTypes);
    }
    return JikesRVMSupport.createMethod(answer);
}
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