Search in sources :

Example 1 with Atom

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

use of org.jikesrvm.classloader.Atom 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 3 with Atom

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

the class Class method getDeclaredField.

public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType() || name == null)
        throwNoSuchFieldException(name);
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    RVMField answer = type.asClass().findDeclaredField(aName);
    if (answer == null) {
        throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Atom(org.jikesrvm.classloader.Atom)

Example 4 with Atom

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

the class Class method getField.

public Field getField(String name) throws NoSuchFieldException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throw new NoSuchFieldException();
    Atom aName = Atom.findUnicodeAtom(name);
    if (aName == null)
        throwNoSuchFieldException(name);
    RVMField answer = getFieldInternal(aName);
    if (answer == null) {
        throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Atom(org.jikesrvm.classloader.Atom)

Example 5 with Atom

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

the class JNIFunctions method RegisterNatives.

/**
 * RegisterNatives: registers implementation of native methods
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the class to register native methods in
 * @param methodsAddress the address of an array of native methods to be registered
 * @param nmethods the number of native methods in the array
 * @return 0 is successful -1 if failed
 * @throws NoSuchMethodError if a specified method cannot be found or is not native
 */
private static int RegisterNatives(JNIEnvironment env, int classJREF, Address methodsAddress, int nmethods) {
    if (traceJNI)
        VM.sysWriteln("JNI called: RegisterNatives");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        // get the target class
        Class<?> jcls = (Class<?>) env.getJNIRef(classJREF);
        RVMType type = java.lang.JikesRVMSupport.getTypeForClass(jcls);
        if (!type.isClassType()) {
            env.recordException(new NoSuchMethodError());
            return 0;
        }
        RVMClass klass = type.asClass();
        if (!klass.isInitialized()) {
            RuntimeEntrypoints.initializeClassForDynamicLink(klass);
        }
        // Create list of methods and verify them to avoid partial success
        NativeMethod[] methods = new NativeMethod[nmethods];
        AddressArray symbols = AddressArray.create(nmethods);
        Address curMethod = methodsAddress;
        for (int i = 0; i < nmethods; i++) {
            String methodString = JNIGenericHelpers.createStringFromC(curMethod.loadAddress());
            Atom methodName = Atom.findOrCreateAsciiAtom(methodString);
            String sigString = JNIGenericHelpers.createStringFromC(curMethod.loadAddress(Offset.fromIntSignExtend(BYTES_IN_ADDRESS)));
            Atom sigName = Atom.findOrCreateAsciiAtom(sigString);
            // Find the target method
            RVMMethod meth = klass.findDeclaredMethod(methodName, sigName);
            if (meth == null || !meth.isNative()) {
                env.recordException(new NoSuchMethodError(klass + ": " + methodName + " " + sigName));
                return -1;
            }
            methods[i] = (NativeMethod) meth;
            symbols.set(i, curMethod.loadAddress(Offset.fromIntSignExtend(BYTES_IN_ADDRESS * 2)));
            curMethod = curMethod.plus(3 * BYTES_IN_ADDRESS);
        }
        // Register methods
        for (int i = 0; i < nmethods; i++) {
            methods[i].registerNativeSymbol(symbols.get(i));
        }
        return 0;
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return -1;
    }
}
Also used : AddressArray(org.vmmagic.unboxed.AddressArray) Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass) RVMMethod(org.jikesrvm.classloader.RVMMethod) NativeMethod(org.jikesrvm.classloader.NativeMethod) RVMClass(org.jikesrvm.classloader.RVMClass)

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