Search in sources :

Example 46 with RVMClass

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

the class Class method getClasses.

public Class<?>[] getClasses() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        return new Class[0];
    ArrayList<Class<?>> publicClasses = new ArrayList<Class<?>>();
    for (Class<?> c = this; c != null; c = c.getSuperclass()) {
        c.checkMemberAccess(Member.PUBLIC);
        TypeReference[] declaredClasses = c.type.asClass().getDeclaredClasses();
        if (declaredClasses != null) {
            for (TypeReference declaredClass : declaredClasses) {
                if (declaredClass != null) {
                    RVMClass dc = declaredClass.resolve().asClass();
                    if (dc.isPublic()) {
                        publicClasses.add(dc.getClassForType());
                    }
                }
            }
        }
    }
    Class<?>[] result = new Class[publicClasses.size()];
    result = publicClasses.toArray(result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) RVMClass(org.jikesrvm.classloader.RVMClass) TypeReference(org.jikesrvm.classloader.TypeReference) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 47 with RVMClass

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

the class Class method getFieldInternal.

// --- Fields ---
@Pure
private RVMField getFieldInternal(Atom name) {
    RVMClass ctype = type.asClass();
    // (1) Check my public declared fields
    RVMField[] fields = ctype.getDeclaredFields();
    for (RVMField field : fields) {
        if (field.isPublic() && field.getName() == name) {
            return field;
        }
    }
    // (2) Check superinterfaces
    RVMClass[] interfaces = ctype.getDeclaredInterfaces();
    for (RVMClass anInterface : interfaces) {
        RVMField ans = anInterface.getClassForType().getFieldInternal(name);
        if (ans != null)
            return ans;
    }
    // (3) Check superclass (if I have one).
    if (ctype.getSuperClass() != null) {
        return ctype.getSuperClass().getClassForType().getFieldInternal(name);
    }
    return null;
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass) Pure(org.vmmagic.pragma.Pure)

Example 48 with RVMClass

use of org.jikesrvm.classloader.RVMClass 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 49 with RVMClass

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

the class VMCommonLibrarySupport method setSystemStreamField.

/**
 * Set the value of a static final stream field of the System class
 * @param fieldName name of field to set
 * @param stream value
 */
static void setSystemStreamField(String fieldName, Object stream) {
    try {
        RVMField field = ((RVMClass) JikesRVMSupport.getTypeForClass(System.class)).findDeclaredField(Atom.findOrCreateUnicodeAtom(fieldName));
        field.setObjectValueUnchecked(null, stream);
    } catch (Exception e) {
        throw new Error("Error setting stream field " + fieldName + " of java.lang.System", e);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 50 with RVMClass

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

the class VMCommonLibrarySupport method construct.

/* ---- Constructor Support ---- */
/**
 * Construct an object from the given constructor args, called from the accessing class
 */
@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 0 })
static Object construct(RVMMethod constructor, Constructor<?> cons, Object[] args, RVMClass accessingClass, ReflectionBase invoker) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    // Check accessibility
    if (!constructor.isPublic() && !cons.isAccessible()) {
        checkAccess(constructor, accessingClass);
    }
    // validate number and types of arguments to constructor
    if (Reflection.needsCheckArgs(invoker) && !checkArguments(args, constructor)) {
        args = makeArgumentsCompatible(args, constructor);
    }
    RVMClass cls = constructor.getDeclaringClass();
    if (cls.isAbstract()) {
        throwNewInstantiationException("Abstract class");
    }
    // Ensure that the class is initialized
    if (!cls.isInitialized()) {
        runClassInitializer(cls);
    }
    // Allocate an uninitialized instance;
    Object obj = RuntimeEntrypoints.resolvedNewScalar(cls);
    // Run the constructor on the instance.
    try {
        Reflection.invoke(constructor, invoker, obj, args, true);
    } catch (Throwable e) {
        throw new InvocationTargetException(e);
    }
    return obj;
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Aggregations

RVMClass (org.jikesrvm.classloader.RVMClass)69 RVMMethod (org.jikesrvm.classloader.RVMMethod)28 TypeReference (org.jikesrvm.classloader.TypeReference)22 RVMType (org.jikesrvm.classloader.RVMType)20 Atom (org.jikesrvm.classloader.Atom)14 RVMField (org.jikesrvm.classloader.RVMField)11 RVMArray (org.jikesrvm.classloader.RVMArray)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)7 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)7 Address (org.vmmagic.unboxed.Address)7 NormalMethod (org.jikesrvm.classloader.NormalMethod)6 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)6 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)6 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)5