Search in sources :

Example 61 with RVMMethod

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

the class Class method getConstructors.

public Constructor<?>[] getConstructors() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        return new Constructor[0];
    RVMMethod[] methods = type.asClass().getConstructorMethods();
    ArrayList<Constructor<T>> coll = new ArrayList<Constructor<T>>(methods.length);
    for (RVMMethod method : methods) {
        if (method.isPublic()) {
            @SuppressWarnings("unchecked") Constructor<T> x = (Constructor<T>) JikesRVMSupport.createConstructor(method);
            coll.add(x);
        }
    }
    return coll.toArray(new Constructor[coll.size()]);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList)

Example 62 with RVMMethod

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

the class Class method getEnclosingConstructor.

public Constructor<?> getEnclosingConstructor() {
    if (!(isAnonymousClass() || isLocalClass())) {
        return null;
    }
    MethodReference enclosingMethodRef = type.asClass().getEnclosingMethod();
    if (enclosingMethodRef == null) {
        return null;
    }
    RVMMethod method = enclosingMethodRef.resolve();
    if (!method.isObjectInitializer()) {
        return null;
    }
    return JikesRVMSupport.createConstructor(method);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) MethodReference(org.jikesrvm.classloader.MethodReference)

Example 63 with RVMMethod

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

the class Class method getDeclaredMethods.

public Method[] getDeclaredMethods() throws SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType())
        return new Method[0];
    RVMMethod[] methods = type.asClass().getDeclaredMethods();
    ArrayList<Method> coll = new ArrayList<Method>(methods.length);
    for (RVMMethod meth : methods) {
        if (!meth.isClassInitializer() && !meth.isObjectInitializer()) {
            coll.add(JikesRVMSupport.createMethod(meth));
        }
    }
    return coll.toArray(new Method[coll.size()]);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) RVMMethod(org.jikesrvm.classloader.RVMMethod)

Example 64 with RVMMethod

use of org.jikesrvm.classloader.RVMMethod 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 65 with RVMMethod

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

RVMMethod (org.jikesrvm.classloader.RVMMethod)86 RVMClass (org.jikesrvm.classloader.RVMClass)29 TypeReference (org.jikesrvm.classloader.TypeReference)17 RVMType (org.jikesrvm.classloader.RVMType)15 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)14 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)13 Atom (org.jikesrvm.classloader.Atom)11 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)11 Offset (org.vmmagic.unboxed.Offset)11 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)10 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)10 Address (org.vmmagic.unboxed.Address)9 MethodReference (org.jikesrvm.classloader.MethodReference)8 NormalMethod (org.jikesrvm.classloader.NormalMethod)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 Method (java.lang.reflect.Method)7 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)7 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)7