[vmkit-commits] [vmkit] r198898 - Add few openjdk/jni functions

Gael Thomas gael.thomas at lip6.fr
Thu Jan 9 14:59:49 PST 2014


Author: gthomas
Date: Thu Jan  9 16:59:48 2014
New Revision: 198898

URL: http://llvm.org/viewvc/llvm-project?rev=198898&view=rev
Log:
Add few openjdk/jni functions

Modified:
    vmkit/branches/mcjit/include/j3/j3.h
    vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
    vmkit/branches/mcjit/lib/j3/vm/j3.cc
    vmkit/branches/mcjit/lib/j3/vm/j3jni.cc

Modified: vmkit/branches/mcjit/include/j3/j3.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3.h?rev=198898&r1=198897&r2=198898&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3.h (original)
+++ vmkit/branches/mcjit/include/j3/j3.h Thu Jan  9 16:59:48 2014
@@ -151,6 +151,7 @@ namespace j3 {
 		static void    nullPointerException() __attribute__((noreturn));
 		static void    classCastException() __attribute__((noreturn));
 
+		static void    negativeArraySizeException(int32_t length) __attribute__((noreturn));
 		static void    arrayStoreException() __attribute__((noreturn));
 		static void    arrayIndexOutOfBoundsException() __attribute__((noreturn));
 

Modified: vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc?rev=198898&r1=198897&r2=198898&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc (original)
+++ vmkit/branches/mcjit/lib/j3/openjdk/j3openjdk.cc Thu Jan  9 16:59:48 2014
@@ -443,7 +443,16 @@ jobject JNICALL JVM_GetArrayElement(JNIE
 jvalue JNICALL JVM_GetPrimitiveArrayElement(JNIEnv* env, jobject arr, jint index, jint wCode) { enterJVM(); NYI(); leaveJVM(); }
 void JNICALL JVM_SetArrayElement(JNIEnv* env, jobject arr, jint index, jobject val) { enterJVM(); NYI(); leaveJVM(); }
 void JNICALL JVM_SetPrimitiveArrayElement(JNIEnv* env, jobject arr, jint index, jvalue v, unsigned char vCode) { enterJVM(); NYI(); leaveJVM(); }
-jobject JNICALL JVM_NewArray(JNIEnv* env, jclass eltClass, jint length) { enterJVM(); NYI(); leaveJVM(); }
+
+jobject JNICALL JVM_NewArray(JNIEnv* env, jclass eltClass, jint length) { 
+	jobject res;
+	enterJVM(); 
+  if(length < 0) J3::negativeArraySizeException(length);
+	res = J3ObjectHandle::doNewArray(J3Class::nativeClass(eltClass)->getArray(), length);
+	leaveJVM(); 
+	return res;
+}
+
 jobject JNICALL JVM_NewMultiArray(JNIEnv* env, jclass eltClass, jintArray dim) { enterJVM(); NYI(); leaveJVM(); }
 
 /*

Modified: vmkit/branches/mcjit/lib/j3/vm/j3.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3.cc?rev=198898&r1=198897&r2=198898&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3.cc Thu Jan  9 16:59:48 2014
@@ -273,6 +273,10 @@ void J3::linkageError(J3Method* method)
 								method->signature()->name()->cStr());
 }
 
+void J3::negativeArraySizeException(int32_t length) {
+	internalError("negative array size exception: %ld", length);
+}
+
 void J3::arrayStoreException() {
 	internalError("array store exception");
 }

Modified: vmkit/branches/mcjit/lib/j3/vm/j3jni.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3jni.cc?rev=198898&r1=198897&r2=198898&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3jni.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3jni.cc Thu Jan  9 16:59:48 2014
@@ -486,9 +486,37 @@ jsize JNICALL GetArrayLength(JNIEnv* env
 	return res;
 }
 
-jobjectArray JNICALL NewObjectArray(JNIEnv* env, jsize len, jclass clazz, jobject init) { enterJVM(); leaveJVM(); NYI(); }
-jobject JNICALL GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) { enterJVM(); leaveJVM(); NYI(); }
-void JNICALL SetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index, jobject val) { enterJVM(); leaveJVM(); NYI(); }
+jobjectArray JNICALL NewObjectArray(JNIEnv* env, jsize length, jclass elementClass, jobject initialElement) { 
+	jobjectArray res;
+	enterJVM(); 
+  if((signed)length < 0) J3::negativeArraySizeException(length);
+	res = J3ObjectHandle::doNewArray(J3ObjectType::nativeClass(elementClass)->getArray(), length);
+	if(initialElement)
+		for(jsize i=0; i<length; i++)
+			res->setObjectAt(i, initialElement);
+	leaveJVM(); 
+	return res;
+}
+
+jobject JNICALL GetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index) { 
+	jobject res;
+	enterJVM(); 
+	if(index >= array->arrayLength())
+		J3::arrayIndexOutOfBoundsException();
+	res = array->getObjectAt(index);
+	leaveJVM(); 
+	return res;
+}
+
+void JNICALL SetObjectArrayElement(JNIEnv* env, jobjectArray array, jsize index, jobject val) { 
+	enterJVM(); 
+	if(index >= array->arrayLength())
+		J3::arrayIndexOutOfBoundsException();
+	if(!val->vt()->type()->isAssignableTo(array->vt()->type()->asArrayClass()->component()))
+		J3::arrayStoreException();
+	array->setObjectAt(index, val);
+	leaveJVM(); 
+}
 
 jboolean* JNICALL GetBooleanArrayElements(JNIEnv* env, jbooleanArray array, jboolean* isCopy) { enterJVM(); leaveJVM(); NYI(); }
 jbyte* JNICALL GetByteArrayElements(JNIEnv* env, jbyteArray array, jboolean* isCopy) { enterJVM(); leaveJVM(); NYI(); }





More information about the vmkit-commits mailing list