Search in sources :

Example 1 with RVMMethod

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

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

the class Class method getDeclaredConstructor.

public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType())
        throwNoSuchMethodException("<init>", parameterTypes);
    RVMMethod answer = null;
    if (parameterTypes == null || parameterTypes.length == 0) {
        answer = getDefaultConstructor();
    } else {
        RVMMethod[] methods = type.asClass().getConstructorMethods();
        for (RVMMethod method : methods) {
            if (parametersMatch(method.getParameterTypes(), parameterTypes)) {
                answer = method;
                break;
            }
        }
    }
    if (answer == null) {
        throwNoSuchMethodException("<init>", parameterTypes);
    }
    return JikesRVMSupport.createConstructor(answer);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod)

Example 3 with RVMMethod

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

the class Class method getDefaultConstructor.

// --- Constructors ---
@Pure
private RVMMethod getDefaultConstructor() {
    if (this.defaultConstructor == null) {
        RVMMethod defaultConstructor = null;
        RVMMethod[] methods = type.asClass().getConstructorMethods();
        for (RVMMethod method : methods) {
            if (method.getParameterTypes().length == 0) {
                defaultConstructor = method;
                break;
            }
        }
        this.defaultConstructor = defaultConstructor;
    }
    return this.defaultConstructor;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Pure(org.vmmagic.pragma.Pure)

Example 4 with RVMMethod

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

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

the class Class method getConstructor.

public Constructor<T> getConstructor(Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throwNoSuchMethodException("<init>", parameterTypes);
    RVMMethod answer = null;
    if (parameterTypes == null || parameterTypes.length == 0) {
        answer = getDefaultConstructor();
    } else {
        RVMMethod[] methods = type.asClass().getConstructorMethods();
        for (RVMMethod method : methods) {
            if (method.isPublic() && parametersMatch(method.getParameterTypes(), parameterTypes)) {
                answer = method;
                break;
            }
        }
    }
    if (answer == null) {
        throwNoSuchMethodException("<init>", parameterTypes);
    }
    return JikesRVMSupport.createConstructor(answer);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod)

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