Search in sources :

Example 76 with RVMType

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

the class JNIFunctions method AllocObject.

/**
 * AllocObject:  allocate the space for an object without running any constructor
 *               the header is filled and the fields are initialized to null
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the class object
 * @return a JREF index for the uninitialized object
 * @throws InstantiationException if the class is abstract or is an interface
 * @throws OutOfMemoryError if no more memory to allocate
 */
private static int AllocObject(JNIEnvironment env, int classJREF) throws InstantiationException, OutOfMemoryError {
    if (traceJNI)
        VM.sysWriteln("JNI called: AllocObject");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Class<?> javaCls = (Class<?>) env.getJNIRef(classJREF);
        RVMType type = java.lang.JikesRVMSupport.getTypeForClass(javaCls);
        if (type.isArrayType() || type.isPrimitiveType() || type.isUnboxedType()) {
            env.recordException(new InstantiationException());
            return 0;
        }
        RVMClass cls = type.asClass();
        if (cls.isAbstract() || cls.isInterface()) {
            env.recordException(new InstantiationException());
            return 0;
        }
        Object newObj = RuntimeEntrypoints.resolvedNewScalar(cls);
        return env.pushJNIRef(newObj);
    } 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) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 77 with RVMType

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

the class JNIFunctions method GetObjectArrayElement.

/**
 * GetObjectArrayElement: retrieve an object from an object array
 * @param env A JREF index for the JNI environment object
 * @param arrayJREF a JREF index for the source array
 * @param index the index for the targeted element
 * @return the object at the specified index
 * @throws ArrayIndexOutOfBoundsException if the index is out of range
 */
private static int GetObjectArrayElement(JNIEnvironment env, int arrayJREF, int index) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetObjectArrayElement");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Object[] sourceArray = (Object[]) env.getJNIRef(arrayJREF);
        if (sourceArray == null) {
            return 0;
        }
        RVMArray arrayType = Magic.getObjectType(sourceArray).asArray();
        RVMType elementType = arrayType.getElementType();
        if (elementType.isPrimitiveType() || elementType.isUnboxedType()) {
            return 0;
        }
        if (index >= Magic.getArrayLength(sourceArray)) {
            env.recordException(new ArrayIndexOutOfBoundsException());
            return 0;
        }
        return env.pushJNIRef(sourceArray[index]);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMArray(org.jikesrvm.classloader.RVMArray) 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