Search in sources :

Example 61 with RVMType

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

the class RuntimeEntrypoints method unresolvedNewScalar.

// ---------------------------------------------------------------//
// Object Allocation.                        //
// ---------------------------------------------------------------//
/**
 * Allocate something like "new Foo()".
 * @param id id of type reference of class to create
 * @param site the site id of the calling allocation site
 * @return object with header installed and all fields set to zero/null
 *           (ready for initializer to be run on it)
 * See also: bytecode 0xbb ("new")
 */
@Entrypoint
static Object unresolvedNewScalar(int id, int site) throws NoClassDefFoundError, OutOfMemoryError {
    TypeReference tRef = TypeReference.getTypeRef(id);
    RVMType t = tRef.peekType();
    if (t == null) {
        t = tRef.resolve();
    }
    RVMClass cls = t.asClass();
    if (!cls.isInitialized()) {
        initializeClassForDynamicLink(cls);
    }
    int allocator = MemoryManager.pickAllocator(cls);
    int align = ObjectModel.getAlignment(cls);
    int offset = ObjectModel.getOffsetForAlignment(cls, false);
    return resolvedNewScalar(cls.getInstanceSize(), cls.getTypeInformationBlock(), cls.hasFinalizer(), allocator, align, offset, site);
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Entrypoint(org.vmmagic.pragma.Entrypoint) RVMClass(org.jikesrvm.classloader.RVMClass) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 62 with RVMType

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

the class RuntimeEntrypoints method deliverException.

/**
 * Deliver an exception to current java thread.
 * <STRONG> Precondition: </STRONG> VM.disableGC has already been called.
 *  <ol>
 *   <li> exceptionRegisters may not match any reasonable stack
 *          frame at this point.
 *   <li> we're going to be playing with raw addresses (fp, ip).
 *  </ol>
 * <p>
 * Does not return:
 * <ul>
 *  <li> stack is unwound and execution resumes in a catch block
 *  <li> <em> or </em> current thread is terminated if no catch block is found
 * </ul>
 *
 * @param exceptionObject exception object to deliver
 * @param exceptionRegisters register state corresponding to exception site
 */
@Unpreemptible("Deliver exception trying to avoid preemption")
private static void deliverException(Throwable exceptionObject, AbstractRegisters exceptionRegisters) {
    if (VM.TraceExceptionDelivery) {
        VM.sysWriteln("RuntimeEntrypoints.deliverException() entered; just got an exception object.");
    }
    // 
    if (VM.TraceExceptionDelivery) {
        VM.sysWrite("Hunting for a catch block...");
    }
    RVMType exceptionType = Magic.getObjectType(exceptionObject);
    Address fp = exceptionRegisters.getInnermostFramePointer();
    Address hijackedCalleeFp = RVMThread.getCurrentThread().getHijackedReturnCalleeFp();
    boolean leapfroggedReturnBarrier = false;
    if (VM.VerifyAssertions)
        VM._assert(hijackedCalleeFp.isZero() || hijackedCalleeFp.GE(fp));
    while (Magic.getCallerFramePointer(fp).NE(StackFrameLayout.getStackFrameSentinelFP())) {
        if (!hijackedCalleeFp.isZero() && hijackedCalleeFp.LE(fp)) {
            leapfroggedReturnBarrier = true;
        }
        int compiledMethodId = Magic.getCompiledMethodID(fp);
        if (compiledMethodId != StackFrameLayout.getInvisibleMethodID()) {
            CompiledMethod compiledMethod = CompiledMethods.getCompiledMethod(compiledMethodId);
            ExceptionDeliverer exceptionDeliverer = compiledMethod.getExceptionDeliverer();
            Address ip = exceptionRegisters.getInnermostInstructionAddress();
            Offset ipOffset = compiledMethod.getInstructionOffset(ip);
            int catchBlockOffset = compiledMethod.findCatchBlockForInstruction(ipOffset, exceptionType);
            if (catchBlockOffset >= 0) {
                // found an appropriate catch block
                if (VM.TraceExceptionDelivery) {
                    VM.sysWriteln("found one; delivering.");
                }
                if (leapfroggedReturnBarrier) {
                    RVMThread t = RVMThread.getCurrentThread();
                    if (RVMThread.DEBUG_STACK_TRAMPOLINE)
                        VM.sysWriteln("leapfrogged...");
                    t.deInstallStackTrampoline();
                }
                Address catchBlockStart = compiledMethod.getInstructionAddress(Offset.fromIntSignExtend(catchBlockOffset));
                exceptionDeliverer.deliverException(compiledMethod, catchBlockStart, exceptionObject, exceptionRegisters);
                if (VM.VerifyAssertions)
                    VM._assert(NOT_REACHED);
            }
            exceptionDeliverer.unwindStackFrame(compiledMethod, exceptionRegisters);
        } else {
            unwindInvisibleStackFrame(exceptionRegisters);
        }
        fp = exceptionRegisters.getInnermostFramePointer();
    }
    if (VM.TraceExceptionDelivery) {
        VM.sysWriteln("Nope.");
        VM.sysWriteln("RuntimeEntrypoints.deliverException() found no catch block.");
    }
    /* No appropriate catch block found. */
    if (RVMThread.DEBUG_STACK_TRAMPOLINE && leapfroggedReturnBarrier)
        VM.sysWriteln("Leapfrogged, and unhandled!");
    handleUncaughtException(exceptionObject);
}
Also used : Address(org.vmmagic.unboxed.Address) RVMThread(org.jikesrvm.scheduler.RVMThread) RVMType(org.jikesrvm.classloader.RVMType) Entrypoint(org.vmmagic.pragma.Entrypoint) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) Offset(org.vmmagic.unboxed.Offset) Unpreemptible(org.vmmagic.pragma.Unpreemptible)

Example 63 with RVMType

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

the class JNIFunctions method IsInstanceOf.

/**
 * IsInstanceOf: determine if an object is an instance of the class.
 * <p>
 * NOTE: the function behaviour is defined via the behaviour of checkcast
 * and NOT instanceof as the name of this function would suggest. See
 * the JNI spec for details.
 *
 * @param env A JREF index for the JNI environment object
 * @param objJREF a JREF index for the object to check
 * @param classJREF a JREF index for the class to check
 * @return true if the object is an instance of the class
 */
private static int IsInstanceOf(JNIEnvironment env, int objJREF, int classJREF) {
    if (traceJNI)
        VM.sysWriteln("JNI called: IsInstanceOf");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
        Object obj = env.getJNIRef(objJREF);
        // checkcast. So we're actually checking "(T) null" which will always succeed.
        if (obj == null)
            return 1;
        RVMType RHStype = ObjectModel.getObjectType(obj);
        RVMType LHStype = java.lang.JikesRVMSupport.getTypeForClass(cls);
        return (LHStype == RHStype || RuntimeEntrypoints.isAssignableWith(LHStype, RHStype)) ? 1 : 0;
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 64 with RVMType

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

the class JNIFunctions method DefineClass.

/**
 * DefineClass:  Loads a class from a buffer of raw class data.
 * @param env A JREF index for the JNI environment object
 * @param classNameAddress a raw address to a null-terminated string in C for the class name
 * @param classLoader a JREF index for the class loader assigned to the defined class
 * @param data buffer containing the <tt>.class</tt> file
 * @param dataLen buffer length
 * @return a JREF index for the Java Class object, or 0 if not found
 * @throws ClassFormatError if the class data does not specify a valid class
 * @throws ClassCircularityError (not implemented)
 * @throws OutOfMemoryError (not implemented)
 */
private static int DefineClass(JNIEnvironment env, Address classNameAddress, int classLoader, Address data, int dataLen) {
    if (traceJNI)
        VM.sysWriteln("JNI called: DefineClass");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        String classString = null;
        if (!classNameAddress.isZero()) {
            JNIGenericHelpers.createStringFromC(classNameAddress);
        }
        ClassLoader cl;
        if (classLoader == 0) {
            cl = RVMClass.getClassLoaderFromStackFrame(1);
        } else {
            cl = (ClassLoader) env.getJNIRef(classLoader);
        }
        AddressInputStream reader = new AddressInputStream(data, Extent.fromIntZeroExtend(dataLen));
        final RVMType vmType = RVMClassLoader.defineClassInternal(classString, reader, cl);
        return env.pushJNIRef(vmType.getClassForType());
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) RVMClassLoader(org.jikesrvm.classloader.RVMClassLoader) AddressInputStream(org.jikesrvm.util.AddressInputStream)

Example 65 with RVMType

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

the class JNIFunctions method GetArrayLength.

/**
 * GetArrayLength: return array length
 * @param env A JREF index for the JNI environment object
 * @param arrayJREF a JREF index for the source array
 * @return the array length, or -1 if it's not an array
 */
private static int GetArrayLength(JNIEnvironment env, int arrayJREF) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetArrayLength");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object theArray = env.getJNIRef(arrayJREF);
        RVMType arrayType = Magic.getObjectType(theArray);
        return arrayType.isArrayType() ? Magic.getArrayLength(theArray) : -1;
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return -1;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType)

Aggregations

RVMType (org.jikesrvm.classloader.RVMType)77 RVMClass (org.jikesrvm.classloader.RVMClass)23 TypeReference (org.jikesrvm.classloader.TypeReference)18 Address (org.vmmagic.unboxed.Address)16 RVMMethod (org.jikesrvm.classloader.RVMMethod)15 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)15 TIB (org.jikesrvm.objectmodel.TIB)13 Entrypoint (org.vmmagic.pragma.Entrypoint)13 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)12 RVMArray (org.jikesrvm.classloader.RVMArray)11 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)11 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)11 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)10 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)10 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)10 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)10 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)9 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)9 Offset (org.vmmagic.unboxed.Offset)8