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;
}
}
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;
}
}
Aggregations