Search in sources :

Example 1 with RVMClass

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

the class VM method runClassInitializer.

/**
 * Run {@code <clinit>} method of specified class, if that class appears
 * in bootimage and actually has a clinit method (we are flexible to
 * allow one list of classes to work with different bootimages and
 * different version of classpath (eg 0.05 vs. cvs head).
 * <p>
 * This method is called only while the VM boots.
 *
 * @param className class whose initializer needs to be run
 */
@Interruptible
static void runClassInitializer(String className) {
    if (verboseBoot >= 2) {
        sysWrite("running class initializer for ");
        sysWriteln(className);
    }
    Atom classDescriptor = Atom.findOrCreateAsciiAtom(className.replace('.', '/')).descriptorFromClassName();
    TypeReference tRef = TypeReference.findOrCreate(BootstrapClassLoader.getBootstrapClassLoader(), classDescriptor);
    RVMClass cls = (RVMClass) tRef.peekType();
    if (null == cls) {
        sysWrite("Failed to run class initializer for ");
        sysWrite(className);
        sysWriteln(" as the class does not exist.");
    } else if (!cls.isInBootImage()) {
        sysWrite("Failed to run class initializer for ");
        sysWrite(className);
        sysWriteln(" as the class is not in the boot image.");
    } else {
        RVMMethod clinit = cls.getClassInitializerMethod();
        if (clinit != null) {
            clinit.compile();
            if (verboseBoot >= 10)
                VM.sysWriteln("invoking method " + clinit);
            try {
                Magic.invokeClassInitializer(clinit.getCurrentEntryCodeArray());
            } catch (Error e) {
                throw e;
            } catch (Throwable t) {
                ExceptionInInitializerError eieio = new ExceptionInInitializerError(t);
                throw eieio;
            }
            // <clinit> is no longer needed: reclaim space by removing references to it
            clinit.invalidateCompiledMethod(clinit.getCurrentCompiledMethod());
        } else {
            if (verboseBoot >= 10)
                VM.sysWriteln("has no clinit method ");
        }
        cls.setAllFinalStaticJTOCEntries();
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass) Interruptible(org.vmmagic.pragma.Interruptible)

Example 2 with RVMClass

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

the class Class method getDeclaredClasses.

public Class<?>[] getDeclaredClasses() throws SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType())
        return new Class[0];
    // Get array of declared classes from RVMClass object
    RVMClass cls = type.asClass();
    TypeReference[] declaredClasses = cls.getDeclaredClasses();
    // The array can be null if the class has no declared inner class members
    if (declaredClasses == null)
        return new Class[0];
    // Count the number of actual declared inner and static classes.
    // (The array may contain null elements, which we want to skip.)
    int count = 0;
    int length = declaredClasses.length;
    for (int i = 0; i < length; ++i) {
        if (declaredClasses[i] != null) {
            ++count;
        }
    }
    // Now build actual result array.
    Class<?>[] result = new Class[count];
    count = 0;
    for (int i = 0; i < length; ++i) {
        if (declaredClasses[i] != null) {
            result[count++] = declaredClasses[i].resolve().getClassForType();
        }
    }
    return result;
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass) TypeReference(org.jikesrvm.classloader.TypeReference) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 3 with RVMClass

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

the class Class method getTypeParameters.

@Override
@SuppressWarnings("unchecked")
public TypeVariable<Class<T>>[] getTypeParameters() {
    if (!type.isClassType()) {
        return new TypeVariable[0];
    } else {
        RVMClass klass = type.asClass();
        Atom sig = klass.getSignature();
        if (sig == null) {
            return new TypeVariable[0];
        } else {
            return JikesRVMHelpers.getTypeParameters(this, sig);
        }
    }
}
Also used : TypeVariable(java.lang.reflect.TypeVariable) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 4 with RVMClass

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

the class Class method newInstance.

// --- newInstance ---
@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 0 })
public T newInstance() throws IllegalAccessException, InstantiationException, ExceptionInInitializerError, SecurityException {
    // Basic checks
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throw new InstantiationException();
    RVMClass cls = type.asClass();
    if (cls.isAbstract() || cls.isInterface())
        throw new InstantiationException();
    // Ensure that the class is initialized
    if (!cls.isInitialized()) {
        RuntimeEntrypoints.initializeClassForDynamicLink(cls);
    }
    // Find the defaultConstructor
    RVMMethod defaultConstructor = getDefaultConstructor();
    if (defaultConstructor == null)
        throw new InstantiationException();
    // Check that caller is allowed to access it
    if (!defaultConstructor.isPublic()) {
        RVMClass accessingClass = RVMClass.getClassFromStackFrame(1);
        VMCommonLibrarySupport.checkAccess(defaultConstructor, accessingClass);
    }
    // Allocate an uninitialized instance;
    // yes, we're giving an anonymous object a type.
    @SuppressWarnings("unchecked") T obj = (T) RuntimeEntrypoints.resolvedNewScalar(cls);
    // Run the default constructor on the it.
    Reflection.invoke(defaultConstructor, null, obj, null, true);
    return obj;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMClass(org.jikesrvm.classloader.RVMClass) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Example 5 with RVMClass

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

the class VMCommonLibrarySupport method checkAccess.

/* ---- General Reflection Support ---- */
/**
 * Check to see if a method declared by the accessingClass
 * should be allowed to access the argument RVMMember.
 * Assumption: member is not public.  This trivial case should
 * be approved by the caller without needing to call this method.
 */
static void checkAccess(RVMMember member, RVMClass accessingClass) throws IllegalAccessException {
    RVMClass declaringClass = member.getDeclaringClass();
    if (member.isPrivate()) {
        // access from the declaringClass is allowed
        if (accessingClass == declaringClass)
            return;
    } else if (member.isProtected()) {
        // access within the package is allowed.
        if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
            return;
        // access by subclasses is allowed.
        for (RVMClass cls = accessingClass; cls != null; cls = cls.getSuperClass()) {
            if (accessingClass == declaringClass)
                return;
        }
    } else {
        // default: access within package is allowed
        if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
            return;
    }
    throwNewIllegalAccessException(member, accessingClass);
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass)

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