From: Christian Thalinger Date: Fri, 29 Aug 2008 13:22:35 +0000 (+0200) Subject: * src/native/jni.hpp: We typedef the JNI types to the CACAO internal X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=cacao.git;a=commitdiff_plain;h=79c1f3f6d7847231db61bcdff0ca81872fa80556 * src/native/jni.hpp: We typedef the JNI types to the CACAO internal types. This should make the code smaller and more robust. (_CLASSPATH_VM_JNI_TYPES_DEFINED): Defined. (JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H): Likewise. * src/vm/global.h (java_handle_array_t): Added. * src/vm/javaobjects.hpp: Removed all constructors with JNI types. The constructors with the CACAO types can now be used. * src/native/vm/openjdk/hpi.c (native/jni.hpp): Removed. (INCLUDE_HPI_MD_H, INCLUDE_HPI_H): Added. * tests/regression/native/checkjni.c: Likewise. * tests/regression/native/testarguments.c: Likewise. --- diff --git a/src/native/jni.hpp b/src/native/jni.hpp index 616cafd3a..16933eca1 100644 --- a/src/native/jni.hpp +++ b/src/native/jni.hpp @@ -23,7 +23,7 @@ */ -/* jni.h *********************************************************************** +/* jni.hpp ********************************************************************* ATTENTION: We include this file before we actually define our own jni.h. We do this because otherwise we can get into unresolvable @@ -49,23 +49,108 @@ CLASSPATH_JNI_MD_H and CLASSPATH_JNI_H are defined in config.h. -*******************************************************************************/ - -#include "config.h" + We include both headers (jni.h and jni_md.h) with the absolute path + so we can be sure that the preprocessor does not pick up another + header from the search path. Furthermore we include jni_md.h + before jni.h as the latter includes the former. -/* We include both headers with the absolute path so we can be sure - that the preprocessor does not take another header. Furthermore we - include jni_md.h before jni.h as the latter includes the former. */ +*******************************************************************************/ -#include INCLUDE_JNI_MD_H -#include INCLUDE_JNI_H #ifndef _JNI_HPP #define _JNI_HPP +#include "config.h" + #include #include + +// Define these to override the typedefs in jni.h +#define _CLASSPATH_VM_JNI_TYPES_DEFINED 1 // GNU Classpath +#define JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H 1 // OpenJDK + +// First include jni_md.h so we have the Java primitive types. +#include INCLUDE_JNI_MD_H + + +// Include the C++ wrapper classes. +//#include "vm/javaobjects.hpp" +#include "vm/global.h" + +// Typedef the JNI types. +typedef java_handle_t* jobject; +typedef java_handle_t* jclass; +typedef java_handle_t* jstring; +typedef java_handle_t* jthrowable; +typedef java_handle_t* jweak; // FIXME +typedef java_handle_array_t* jarray; +typedef java_handle_objectarray_t* jobjectArray; +typedef java_handle_booleanarray_t* jbooleanArray; +typedef java_handle_bytearray_t* jbyteArray; +typedef java_handle_chararray_t* jcharArray; +typedef java_handle_shortarray_t* jshortArray; +typedef java_handle_intarray_t* jintArray; +typedef java_handle_longarray_t* jlongArray; +typedef java_handle_floatarray_t* jfloatArray; +typedef java_handle_doublearray_t* jdoubleArray; + + +// We need some additional stuff for the various JNI headers. +#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1) + +// These typedefs and defines are copied from GNU Classpath's jni.h +#define JNI_TRUE true +#define JNI_FALSE false + +typedef struct _Jv_JNIEnv JNIEnv; +typedef struct _Jv_JavaVM JavaVM; + +#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) + +// These typedefs are copied from OpenJDK's jni.h +typedef unsigned char jboolean; +typedef unsigned short jchar; +typedef short jshort; +typedef float jfloat; +typedef double jdouble; + +typedef jint jsize; + +typedef union jvalue { + jboolean z; + jbyte b; + jchar c; + jshort s; + jint i; + jlong j; + jfloat f; + jdouble d; + jobject l; +} jvalue; + +struct _jfieldID; +typedef struct _jfieldID *jfieldID; + +struct _jmethodID; +typedef struct _jmethodID *jmethodID; + +/* Return values from jobjectRefType */ +typedef enum _jobjectType { + JNIInvalidRefType = 0, + JNILocalRefType = 1, + JNIGlobalRefType = 2, + JNIWeakGlobalRefType = 3 +} jobjectRefType; + +#endif + + +// Now include jni.h to complete the JNI header. +#include INCLUDE_JNI_H + + +// Includes. #include "vm/global.h" diff --git a/src/native/vm/openjdk/hpi.c b/src/native/vm/openjdk/hpi.c index 50cdab472..3f4eeb7d9 100644 --- a/src/native/vm/openjdk/hpi.c +++ b/src/native/vm/openjdk/hpi.c @@ -25,15 +25,17 @@ #include "config.h" -/* We include hpi_md.h before hpi.h as the latter includes the - former. */ +// Include our JNI header before the HPI headers, because the HPI +// headers include jni.h and we want to override the typedefs in +// jni.h. +#include "native/jni.hpp" +// We include hpi_md.h before hpi.h as the latter includes the former. #include INCLUDE_HPI_MD_H #include INCLUDE_HPI_H #include "mm/memory.h" -#include "native/jni.hpp" #include "native/native.hpp" #include "native/vm/openjdk/hpi.h" diff --git a/src/vm/global.h b/src/vm/global.h index a9ec8c8f9..3157d6c90 100644 --- a/src/vm/global.h +++ b/src/vm/global.h @@ -326,6 +326,7 @@ typedef struct java_handle_t { java_object_t *heap_object; } java_handle_t; +typedef struct java_handle_array_t { java_array_t *heap_object; } java_handle_array_t; typedef struct java_handle_objectarray_t { java_objectarray_t *heap_object; } java_handle_objectarray_t; typedef struct java_handle_booleanarray_t { java_booleanarray_t *heap_object; } java_handle_booleanarray_t; typedef struct java_handle_bytearray_t { java_bytearray_t *heap_object; } java_handle_bytearray_t; @@ -337,6 +338,7 @@ typedef struct java_handle_floatarray_t { java_floatarray_t *heap_object; } typedef struct java_handle_doublearray_t { java_doublearray_t *heap_object; } java_handle_doublearray_t; #else typedef java_object_t java_handle_t; +typedef java_array_t java_handle_array_t; typedef java_objectarray_t java_handle_objectarray_t; typedef java_booleanarray_t java_handle_booleanarray_t; typedef java_bytearray_t java_handle_bytearray_t; diff --git a/src/vm/javaobjects.hpp b/src/vm/javaobjects.hpp index 4ecd9dd49..0b4aa46e9 100644 --- a/src/vm/javaobjects.hpp +++ b/src/vm/javaobjects.hpp @@ -166,7 +166,6 @@ protected: public: java_lang_Object() : _handle(NULL) {} java_lang_Object(java_handle_t* h) : _handle(h) {} - java_lang_Object(jobject h) : _handle((java_handle_t*) h) {} virtual ~java_lang_Object() {} // Getters. @@ -562,7 +561,6 @@ public: // Setters. inline void set_pd(java_handle_t* value); - inline void set_pd(jobject value); }; inline void java_lang_Class::set_pd(java_handle_t* value) @@ -570,11 +568,6 @@ inline void java_lang_Class::set_pd(java_handle_t* value) set(_handle, offset_pd, value); } -inline void java_lang_Class::set_pd(jobject value) -{ - set_pd((java_handle_t*) value); -} - /** * GNU Classpath java/lang/StackTraceElement @@ -637,7 +630,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -651,11 +643,6 @@ public: inline void set_offset(int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} - inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { set_value(value); @@ -814,7 +801,6 @@ private: public: java_lang_VMThread(java_handle_t* h) : java_lang_Object(h) {} - java_lang_VMThread(jobject h); java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata); // Getters. @@ -827,11 +813,6 @@ public: }; -inline java_lang_VMThread::java_lang_VMThread(jobject h) : java_lang_Object(h) -{ - java_lang_VMThread((java_handle_t*) h); -} - inline java_lang_VMThread::java_lang_VMThread(java_handle_t* h, java_handle_t* thread, threadobject* vmdata) : java_lang_Object(h) { set_thread(thread); @@ -923,16 +904,11 @@ private: public: java_lang_VMThrowable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_VMThrowable(jobject h); inline java_handle_bytearray_t* get_vmdata() const; inline void set_vmdata(java_handle_bytearray_t* value); }; -inline java_lang_VMThrowable::java_lang_VMThrowable(jobject h) : java_lang_Object(h) -{ - java_lang_VMThrowable((java_handle_t*) h); -} inline java_handle_bytearray_t* java_lang_VMThrowable::get_vmdata() const { @@ -971,7 +947,6 @@ private: public: java_lang_reflect_VMConstructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMConstructor(jobject h); java_lang_reflect_VMConstructor(methodinfo* m); // Getters. @@ -995,11 +970,6 @@ public: }; -inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMConstructor((java_handle_t*) h); -} - inline java_lang_reflect_VMConstructor::java_lang_reflect_VMConstructor(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_VMConstructor); @@ -1107,7 +1077,6 @@ private: public: java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Constructor(jobject h); java_lang_reflect_Constructor(methodinfo* m); java_handle_t* new_instance(java_handle_objectarray_t* args); @@ -1125,11 +1094,6 @@ public: }; -inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Constructor((java_handle_t*) h); -} - inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m) { java_lang_reflect_VMConstructor jlrvmc(m); @@ -1203,7 +1167,6 @@ private: public: java_lang_reflect_VMField(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMField(jobject h); java_lang_reflect_VMField(fieldinfo* f); // Getters. @@ -1226,11 +1189,6 @@ public: }; -inline java_lang_reflect_VMField::java_lang_reflect_VMField(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMField((java_handle_t*) h); -} - inline java_lang_reflect_VMField::java_lang_reflect_VMField(fieldinfo* f) { _handle = builtin_new(class_java_lang_reflect_VMField); @@ -1334,7 +1292,6 @@ private: public: java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Field(jobject h); java_lang_reflect_Field(fieldinfo* f); // Getters. @@ -1349,11 +1306,6 @@ public: }; -inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Field((java_handle_t*) h); -} - inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f) { java_lang_reflect_VMField jlrvmf(f); @@ -1426,7 +1378,6 @@ private: public: java_lang_reflect_VMMethod(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_VMMethod(jobject h); java_lang_reflect_VMMethod(methodinfo* m); // Getters. @@ -1452,10 +1403,6 @@ public: inline methodinfo* get_method() const; }; -inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_VMMethod((java_handle_t*) h); -} inline java_lang_reflect_VMMethod::java_lang_reflect_VMMethod(methodinfo* m) { @@ -1582,7 +1529,6 @@ private: public: java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Method(jobject h); java_lang_reflect_Method(methodinfo* m); java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args); @@ -1600,11 +1546,6 @@ public: }; -inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Method((java_handle_t*) h); -} - inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m) { java_lang_reflect_VMMethod jlrvmm(m); @@ -1719,16 +1660,11 @@ private: public: java_nio_DirectByteBufferImpl(java_handle_t* h) : java_lang_Object(h) {} - java_nio_DirectByteBufferImpl(jobject h); // Getters. inline java_handle_t* get_address() const; }; -inline java_nio_DirectByteBufferImpl::java_nio_DirectByteBufferImpl(jobject h) : java_lang_Object(h) -{ - java_nio_DirectByteBufferImpl((java_handle_t*) h); -} inline java_handle_t* java_nio_DirectByteBufferImpl::get_address() const { @@ -1892,7 +1828,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -1906,11 +1841,6 @@ public: inline void set_count (int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} - inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { set_value(value); @@ -2078,8 +2008,7 @@ private: public: java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Throwable(jobject h); - java_lang_Throwable(jobject h, java_handle_bytearray_t* backtrace); + java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace); // Getters. inline java_handle_bytearray_t* get_backtrace () const; @@ -2091,14 +2020,8 @@ public: }; -inline java_lang_Throwable::java_lang_Throwable(jobject h) : java_lang_Object(h) -{ - java_lang_Throwable((java_handle_t*) h); -} - -inline java_lang_Throwable::java_lang_Throwable(jobject h, java_handle_bytearray_t* backtrace) : java_lang_Object(h) +inline java_lang_Throwable::java_lang_Throwable(java_handle_t* h, java_handle_bytearray_t* backtrace) : java_lang_Object(h) { - java_lang_Throwable((java_handle_t*) h); set_backtrace(backtrace); } @@ -2167,7 +2090,6 @@ private: public: java_lang_reflect_Constructor(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Constructor(jobject h); java_lang_reflect_Constructor(methodinfo* m); java_handle_t* new_instance(java_handle_objectarray_t* args); @@ -2193,11 +2115,6 @@ public: }; -inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Constructor((java_handle_t*) h); -} - inline java_lang_reflect_Constructor::java_lang_reflect_Constructor(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_Constructor); @@ -2337,7 +2254,6 @@ private: public: java_lang_reflect_Field(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Field(jobject h); java_lang_reflect_Field(fieldinfo* f); // Getters. @@ -2360,11 +2276,6 @@ public: }; -inline java_lang_reflect_Field::java_lang_reflect_Field(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Field((java_handle_t*) h); -} - inline java_lang_reflect_Field::java_lang_reflect_Field(fieldinfo* f) { _handle = builtin_new(class_java_lang_reflect_Field); @@ -2499,7 +2410,6 @@ private: public: java_lang_reflect_Method(java_handle_t* h) : java_lang_Object(h) {} - java_lang_reflect_Method(jobject h); java_lang_reflect_Method(methodinfo* m); java_handle_t* invoke(java_handle_t* o, java_handle_objectarray_t* args); @@ -2519,11 +2429,6 @@ public: }; -inline java_lang_reflect_Method::java_lang_reflect_Method(jobject h) : java_lang_Object(h) -{ - java_lang_reflect_Method((java_handle_t*) h); -} - inline java_lang_reflect_Method::java_lang_reflect_Method(methodinfo* m) { _handle = builtin_new(class_java_lang_reflect_Method); @@ -2609,7 +2514,6 @@ private: public: java_nio_Buffer(java_handle_t* h) : java_lang_Object(h) {} - java_nio_Buffer(jobject h) : java_lang_Object(h) {} // Getters. inline void* get_address() const; @@ -2646,7 +2550,6 @@ private: public: com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h) : java_lang_Object(h) {} - com_sun_cldchi_jvm_FileDescriptor(jobject h); com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length); com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, com_sun_cldchi_jvm_FileDescriptor& fd); @@ -2662,11 +2565,6 @@ public: }; -inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(jobject h) : java_lang_Object(h) -{ - com_sun_cldchi_jvm_FileDescriptor((java_handle_t*) h); -} - inline com_sun_cldchi_jvm_FileDescriptor::com_sun_cldchi_jvm_FileDescriptor(java_handle_t* h, int64_t pointer, int32_t position, int32_t length) : java_lang_Object(h) { set_pointer(pointer); @@ -2732,7 +2630,6 @@ private: public: java_lang_String(java_handle_t* h) : java_lang_Object(h) {} - java_lang_String(jstring h); java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset = 0); // Getters. @@ -2746,10 +2643,6 @@ public: inline void set_count (int32_t value); }; -inline java_lang_String::java_lang_String(jstring h) : java_lang_Object(h) -{ - java_lang_String((java_handle_t*) h); -} inline java_lang_String::java_lang_String(java_handle_t* h, java_handle_chararray_t* value, int32_t count, int32_t offset) : java_lang_Object(h) { @@ -2815,7 +2708,6 @@ private: public: java_lang_Thread(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Thread(jobject h); // java_lang_Thread(threadobject* t); // Getters. @@ -2828,11 +2720,6 @@ public: }; -inline java_lang_Thread::java_lang_Thread(jobject h) : java_lang_Object(h) -{ - java_lang_Thread((java_handle_t*) h); -} - // inline java_lang_Thread::java_lang_Thread(threadobject* t) : java_lang_Object(h) // { // java_lang_Thread(thread_get_object(t)); @@ -2879,7 +2766,6 @@ private: public: java_lang_Throwable(java_handle_t* h) : java_lang_Object(h) {} - java_lang_Throwable(jobject h); // Getters. inline java_handle_t* get_detailMessage() const; @@ -2890,12 +2776,6 @@ public: }; -inline java_lang_Throwable::java_lang_Throwable(jobject h) : java_lang_Object(h) -{ - java_lang_Throwable((java_handle_t*) h); -} - - inline java_handle_t* java_lang_Throwable::get_detailMessage() const { return get(_handle, offset_detailMessage); diff --git a/tests/regression/native/checkjni.c b/tests/regression/native/checkjni.c index 68337d49e..5d7eca624 100644 --- a/tests/regression/native/checkjni.c +++ b/tests/regression/native/checkjni.c @@ -28,7 +28,8 @@ #include #include -#include "native/jni.hpp" +#include INCLUDE_JNI_MD_H +#include INCLUDE_JNI_H JNIEXPORT jboolean JNICALL Java_checkjni_IsAssignableFrom(JNIEnv *env, jclass clazz, jclass sub, jclass sup) diff --git a/tests/regression/native/testarguments.c b/tests/regression/native/testarguments.c index 8c95c8a69..d2b3f36c3 100644 --- a/tests/regression/native/testarguments.c +++ b/tests/regression/native/testarguments.c @@ -25,10 +25,12 @@ #include "config.h" +#include #include #include -#include "native/jni.hpp" +#include INCLUDE_JNI_MD_H +#include INCLUDE_JNI_H JNIEXPORT jobject JNICALL Java_testarguments_adr(JNIEnv *env, jclass clazz, jint i)