X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libjava%2Fjni.cc;h=a54aea949ff018bce0b7ea121c4d7410c7628794;hb=2ba1fcba384fb6390f858783fbabc0137a9e9007;hp=49779078639253edf6d2381df737e097cf852fab;hpb=3d87d8d538a940c979325ef48b6e3970b939c420;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libjava/jni.cc b/libjava/jni.cc index 49779078639..a54aea949ff 100644 --- a/libjava/jni.cc +++ b/libjava/jni.cc @@ -1,6 +1,7 @@ // jni.cc - JNI implementation, including the jump table. -/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation +/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 + Free Software Foundation This file is part of libgcj. @@ -27,6 +28,7 @@ details. */ #include #include #include +#include #include #include #include @@ -39,9 +41,12 @@ details. */ #include #include #include +#include #include +#include #include #include +#include #include #include @@ -67,7 +72,7 @@ extern struct JNIInvokeInterface _Jv_JNI_InvokeFunctions; // Number of slots in the default frame. The VM must allow at least // 16. -#define FRAME_SIZE 32 +#define FRAME_SIZE 16 // Mark value indicating this is an overflow frame. #define MARK_NONE 0 @@ -81,10 +86,13 @@ struct _Jv_JNI_LocalFrame { // This is true if this frame object represents a pushed frame (eg // from PushLocalFrame). - int marker : 2; + int marker; + + // Flag to indicate some locals were allocated. + int allocated_p; // Number of elements in frame. - int size : 30; + int size; // Next frame in chain. _Jv_JNI_LocalFrame *next; @@ -220,8 +228,8 @@ unwrap (T *obj) -static jobject -(JNICALL _Jv_JNI_NewGlobalRef) (JNIEnv *, jobject obj) +static jobject JNICALL +_Jv_JNI_NewGlobalRef (JNIEnv *, jobject obj) { // This seems weird but I think it is correct. obj = unwrap (obj); @@ -229,16 +237,16 @@ static jobject return obj; } -static void -(JNICALL _Jv_JNI_DeleteGlobalRef) (JNIEnv *, jobject obj) +static void JNICALL +_Jv_JNI_DeleteGlobalRef (JNIEnv *, jobject obj) { // This seems weird but I think it is correct. obj = unwrap (obj); unmark_for_gc (obj, global_ref_table); } -static void -(JNICALL _Jv_JNI_DeleteLocalRef) (JNIEnv *env, jobject obj) +static void JNICALL +_Jv_JNI_DeleteLocalRef (JNIEnv *env, jobject obj) { _Jv_JNI_LocalFrame *frame; @@ -264,8 +272,8 @@ static void JvAssert (0); } -static jint -(JNICALL _Jv_JNI_EnsureLocalCapacity) (JNIEnv *env, jint size) +static jint JNICALL +_Jv_JNI_EnsureLocalCapacity (JNIEnv *env, jint size) { // It is easier to just always allocate a new frame of the requested // size. This isn't the most efficient thing, but for now we don't @@ -285,6 +293,7 @@ static jint frame->marker = MARK_NONE; frame->size = size; + frame->allocated_p = 0; memset (&frame->vec[0], 0, size * sizeof (jobject)); frame->next = env->locals; env->locals = frame; @@ -292,8 +301,8 @@ static jint return 0; } -static jint -(JNICALL _Jv_JNI_PushLocalFrame) (JNIEnv *env, jint size) +static jint JNICALL +_Jv_JNI_PushLocalFrame (JNIEnv *env, jint size) { jint r = _Jv_JNI_EnsureLocalCapacity (env, size); if (r < 0) @@ -305,8 +314,8 @@ static jint return 0; } -static jobject -(JNICALL _Jv_JNI_NewLocalRef) (JNIEnv *env, jobject obj) +static jobject JNICALL +_Jv_JNI_NewLocalRef (JNIEnv *env, jobject obj) { // This seems weird but I think it is correct. obj = unwrap (obj); @@ -323,6 +332,7 @@ static jobject set = true; done = true; frame->vec[i] = obj; + frame->allocated_p = 1; break; } } @@ -340,14 +350,15 @@ static jobject _Jv_JNI_EnsureLocalCapacity (env, 16); // We know the first element of the new frame will be ok. env->locals->vec[0] = obj; + env->locals->allocated_p = 1; } mark_for_gc (obj, local_ref_table); return obj; } -static jobject -(JNICALL _Jv_JNI_PopLocalFrame) (JNIEnv *env, jobject result, int stop) +static jobject JNICALL +_Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result, int stop) { _Jv_JNI_LocalFrame *rf = env->locals; @@ -362,12 +373,14 @@ static jobject done = (rf->marker == stop); _Jv_JNI_LocalFrame *n = rf->next; - // When N==NULL, we've reached the stack-allocated frame, and we - // must not free it. However, we must be sure to clear all its - // elements, since we might conceivably reuse it. + // When N==NULL, we've reached the reusable bottom_locals, and we must + // not free it. However, we must be sure to clear all its elements. if (n == NULL) { - memset (&rf->vec[0], 0, rf->size * sizeof (jobject)); + if (rf->allocated_p) + memset (&rf->vec[0], 0, rf->size * sizeof (jobject)); + rf->allocated_p = 0; + rf = NULL; break; } @@ -381,8 +394,8 @@ static jobject return result == NULL ? NULL : _Jv_JNI_NewLocalRef (env, result); } -static jobject -(JNICALL _Jv_JNI_PopLocalFrame) (JNIEnv *env, jobject result) +static jobject JNICALL +_Jv_JNI_PopLocalFrame (JNIEnv *env, jobject result) { return _Jv_JNI_PopLocalFrame (env, result, MARK_USER); } @@ -408,9 +421,17 @@ _Jv_JNI_check_types (JNIEnv *env, JArray *array, jclass K) extern "C" void _Jv_JNI_PopSystemFrame (JNIEnv *env) { - _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM); + // Only enter slow path when we're not at the bottom, or there have been + // allocations. Usually this is false and we can just null out the locals + // field. - if (env->ex) + if (__builtin_expect ((env->locals->next + || env->locals->allocated_p), false)) + _Jv_JNI_PopLocalFrame (env, NULL, MARK_SYSTEM); + else + env->locals = NULL; + + if (__builtin_expect (env->ex != NULL, false)) { jthrowable t = env->ex; env->ex = NULL; @@ -453,15 +474,15 @@ wrap_value (JNIEnv *env, T *value) -static jint -(JNICALL _Jv_JNI_GetVersion) (JNIEnv *) +static jint JNICALL +_Jv_JNI_GetVersion (JNIEnv *) { return JNI_VERSION_1_4; } -static jclass -(JNICALL _Jv_JNI_DefineClass) (JNIEnv *env, const char *name, jobject loader, - const jbyte *buf, jsize bufLen) +static jclass JNICALL +_Jv_JNI_DefineClass (JNIEnv *env, const char *name, jobject loader, + const jbyte *buf, jsize bufLen) { try { @@ -486,8 +507,8 @@ static jclass } } -static jclass -(JNICALL _Jv_JNI_FindClass) (JNIEnv *env, const char *name) +static jclass JNICALL +_Jv_JNI_FindClass (JNIEnv *env, const char *name) { // FIXME: assume that NAME isn't too long. int len = strlen (name); @@ -522,20 +543,20 @@ static jclass return (jclass) wrap_value (env, r); } -static jclass -(JNICALL _Jv_JNI_GetSuperclass) (JNIEnv *env, jclass clazz) +static jclass JNICALL +_Jv_JNI_GetSuperclass (JNIEnv *env, jclass clazz) { return (jclass) wrap_value (env, unwrap (clazz)->getSuperclass ()); } -static jboolean -(JNICALL _Jv_JNI_IsAssignableFrom) (JNIEnv *, jclass clazz1, jclass clazz2) +static jboolean JNICALL +_Jv_JNI_IsAssignableFrom (JNIEnv *, jclass clazz1, jclass clazz2) { return unwrap (clazz1)->isAssignableFrom (unwrap (clazz2)); } -static jint -(JNICALL _Jv_JNI_Throw) (JNIEnv *env, jthrowable obj) +static jint JNICALL +_Jv_JNI_Throw (JNIEnv *env, jthrowable obj) { // We check in case the user did some funky cast. obj = unwrap (obj); @@ -544,8 +565,8 @@ static jint return 0; } -static jint -(JNICALL _Jv_JNI_ThrowNew) (JNIEnv *env, jclass clazz, const char *message) +static jint JNICALL +_Jv_JNI_ThrowNew (JNIEnv *env, jclass clazz, const char *message) { using namespace java::lang::reflect; @@ -560,11 +581,12 @@ static jint NULL); jclass *elts = elements (argtypes); - elts[0] = &StringClass; + elts[0] = &java::lang::String::class$; Constructor *cons = clazz->getConstructor (argtypes); - jobjectArray values = JvNewObjectArray (1, &StringClass, NULL); + jobjectArray values = JvNewObjectArray (1, &java::lang::String::class$, + NULL); jobject *velts = elements (values); velts[0] = JvNewStringUTF (message); @@ -581,47 +603,47 @@ static jint return r; } -static jthrowable -(JNICALL _Jv_JNI_ExceptionOccurred) (JNIEnv *env) +static jthrowable JNICALL +_Jv_JNI_ExceptionOccurred (JNIEnv *env) { return (jthrowable) wrap_value (env, env->ex); } -static void -(JNICALL _Jv_JNI_ExceptionDescribe) (JNIEnv *env) +static void JNICALL +_Jv_JNI_ExceptionDescribe (JNIEnv *env) { if (env->ex != NULL) env->ex->printStackTrace(); } -static void -(JNICALL _Jv_JNI_ExceptionClear) (JNIEnv *env) +static void JNICALL +_Jv_JNI_ExceptionClear (JNIEnv *env) { env->ex = NULL; } -static jboolean -(JNICALL _Jv_JNI_ExceptionCheck) (JNIEnv *env) +static jboolean JNICALL +_Jv_JNI_ExceptionCheck (JNIEnv *env) { return env->ex != NULL; } -static void -(JNICALL _Jv_JNI_FatalError) (JNIEnv *, const char *message) +static void JNICALL +_Jv_JNI_FatalError (JNIEnv *, const char *message) { JvFail (message); } -static jboolean -(JNICALL _Jv_JNI_IsSameObject) (JNIEnv *, jobject obj1, jobject obj2) +static jboolean JNICALL +_Jv_JNI_IsSameObject (JNIEnv *, jobject obj1, jobject obj2) { return unwrap (obj1) == unwrap (obj2); } -static jobject -(JNICALL _Jv_JNI_AllocObject) (JNIEnv *env, jclass clazz) +static jobject JNICALL +_Jv_JNI_AllocObject (JNIEnv *env, jclass clazz) { jobject obj = NULL; using namespace java::lang::reflect; @@ -633,7 +655,7 @@ static jobject if (clazz->isInterface() || Modifier::isAbstract(clazz->getModifiers())) env->ex = new java::lang::InstantiationException (); else - obj = JvAllocObject (clazz); + obj = _Jv_AllocObject (clazz); } catch (jthrowable t) { @@ -643,16 +665,16 @@ static jobject return wrap_value (env, obj); } -static jclass -(JNICALL _Jv_JNI_GetObjectClass) (JNIEnv *env, jobject obj) +static jclass JNICALL +_Jv_JNI_GetObjectClass (JNIEnv *env, jobject obj) { obj = unwrap (obj); JvAssert (obj); return (jclass) wrap_value (env, obj->getClass()); } -static jboolean -(JNICALL _Jv_JNI_IsInstanceOf) (JNIEnv *, jobject obj, jclass clazz) +static jboolean JNICALL +_Jv_JNI_IsInstanceOf (JNIEnv *, jobject obj, jclass clazz) { return unwrap (clazz)->isInstance(unwrap (obj)); } @@ -664,9 +686,9 @@ static jboolean // template -static jmethodID -(JNICALL _Jv_JNI_GetAnyMethodID) (JNIEnv *env, jclass clazz, - const char *name, const char *sig) +static jmethodID JNICALL +_Jv_JNI_GetAnyMethodID (JNIEnv *env, jclass clazz, + const char *name, const char *sig) { try { @@ -705,7 +727,10 @@ static jmethodID clazz = clazz->getSuperclass (); } - env->ex = new java::lang::NoSuchMethodError (); + java::lang::StringBuffer *name_sig = + new java::lang::StringBuffer (JvNewStringUTF (name)); + name_sig->append ((jchar) ' ')->append (JvNewStringUTF (s)); + env->ex = new java::lang::NoSuchMethodError (name_sig->toString ()); } catch (jthrowable t) { @@ -760,16 +785,13 @@ array_from_valist (jvalue *values, JArray *arg_types, va_list vargs) // This can call any sort of method: virtual, "nonvirtual", static, or // constructor. template -static T -(JNICALL _Jv_JNI_CallAnyMethodV) (JNIEnv *env, jobject obj, jclass klass, - jmethodID id, va_list vargs) +static T JNICALL +_Jv_JNI_CallAnyMethodV (JNIEnv *env, jobject obj, jclass klass, + jmethodID id, va_list vargs) { obj = unwrap (obj); klass = unwrap (klass); - if (style == normal) - id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature); - jclass decl_class = klass ? klass : obj->getClass (); JvAssert (decl_class != NULL); @@ -791,6 +813,7 @@ static T jvalue result; _Jv_CallAnyMethodA (obj, return_type, id, style == constructor, + style == normal, arg_types, args, &result); return wrap_value (env, extract_from_jvalue(result)); @@ -804,9 +827,9 @@ static T } template -static T -(JNICALL _Jv_JNI_CallAnyMethod) (JNIEnv *env, jobject obj, jclass klass, - jmethodID method, ...) +static T JNICALL +_Jv_JNI_CallAnyMethod (JNIEnv *env, jobject obj, jclass klass, + jmethodID method, ...) { va_list args; T result; @@ -819,16 +842,13 @@ static T } template -static T -(JNICALL _Jv_JNI_CallAnyMethodA) (JNIEnv *env, jobject obj, jclass klass, - jmethodID id, jvalue *args) +static T JNICALL +_Jv_JNI_CallAnyMethodA (JNIEnv *env, jobject obj, jclass klass, + jmethodID id, jvalue *args) { obj = unwrap (obj); klass = unwrap (klass); - if (style == normal) - id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature); - jclass decl_class = klass ? klass : obj->getClass (); JvAssert (decl_class != NULL); @@ -857,6 +877,7 @@ static T jvalue result; _Jv_CallAnyMethodA (obj, return_type, id, style == constructor, + style == normal, arg_types, arg_copy, &result); return wrap_value (env, extract_from_jvalue(result)); @@ -870,16 +891,13 @@ static T } template -static void -(JNICALL _Jv_JNI_CallAnyVoidMethodV) (JNIEnv *env, jobject obj, jclass klass, - jmethodID id, va_list vargs) +static void JNICALL +_Jv_JNI_CallAnyVoidMethodV (JNIEnv *env, jobject obj, jclass klass, + jmethodID id, va_list vargs) { obj = unwrap (obj); klass = unwrap (klass); - if (style == normal) - id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature); - jclass decl_class = klass ? klass : obj->getClass (); JvAssert (decl_class != NULL); @@ -899,6 +917,7 @@ static void _Jv_CallAnyMethodA (obj, return_type, id, style == constructor, + style == normal, arg_types, args, NULL); } catch (jthrowable t) @@ -908,9 +927,9 @@ static void } template -static void -(JNICALL _Jv_JNI_CallAnyVoidMethod) (JNIEnv *env, jobject obj, jclass klass, - jmethodID method, ...) +static void JNICALL +_Jv_JNI_CallAnyVoidMethod (JNIEnv *env, jobject obj, jclass klass, + jmethodID method, ...) { va_list args; @@ -920,13 +939,10 @@ static void } template -static void -(JNICALL _Jv_JNI_CallAnyVoidMethodA) (JNIEnv *env, jobject obj, jclass klass, - jmethodID id, jvalue *args) +static void JNICALL +_Jv_JNI_CallAnyVoidMethodA (JNIEnv *env, jobject obj, jclass klass, + jmethodID id, jvalue *args) { - if (style == normal) - id = _Jv_LookupDeclaredMethod (obj->getClass (), id->name, id->signature); - jclass decl_class = klass ? klass : obj->getClass (); JvAssert (decl_class != NULL); @@ -950,6 +966,7 @@ static void _Jv_CallAnyMethodA (obj, return_type, id, style == constructor, + style == normal, arg_types, args, NULL); } catch (jthrowable t) @@ -961,9 +978,9 @@ static void // Functions with this signature are used to implement functions in // the CallMethod family. template -static T -(JNICALL _Jv_JNI_CallMethodV) (JNIEnv *env, jobject obj, - jmethodID id, va_list args) +static T JNICALL +_Jv_JNI_CallMethodV (JNIEnv *env, jobject obj, + jmethodID id, va_list args) { return _Jv_JNI_CallAnyMethodV (env, obj, NULL, id, args); } @@ -971,8 +988,8 @@ static T // Functions with this signature are used to implement functions in // the CallMethod family. template -static T -(JNICALL _Jv_JNI_CallMethod) (JNIEnv *env, jobject obj, jmethodID id, ...) +static T JNICALL +_Jv_JNI_CallMethod (JNIEnv *env, jobject obj, jmethodID id, ...) { va_list args; T result; @@ -987,22 +1004,22 @@ static T // Functions with this signature are used to implement functions in // the CallMethod family. template -static T -(JNICALL _Jv_JNI_CallMethodA) (JNIEnv *env, jobject obj, - jmethodID id, jvalue *args) +static T JNICALL +_Jv_JNI_CallMethodA (JNIEnv *env, jobject obj, + jmethodID id, jvalue *args) { return _Jv_JNI_CallAnyMethodA (env, obj, NULL, id, args); } -static void -(JNICALL _Jv_JNI_CallVoidMethodV) (JNIEnv *env, jobject obj, - jmethodID id, va_list args) +static void JNICALL +_Jv_JNI_CallVoidMethodV (JNIEnv *env, jobject obj, + jmethodID id, va_list args) { _Jv_JNI_CallAnyVoidMethodV (env, obj, NULL, id, args); } -static void -(JNICALL _Jv_JNI_CallVoidMethod) (JNIEnv *env, jobject obj, jmethodID id, ...) +static void JNICALL +_Jv_JNI_CallVoidMethod (JNIEnv *env, jobject obj, jmethodID id, ...) { va_list args; @@ -1011,9 +1028,9 @@ static void va_end (args); } -static void -(JNICALL _Jv_JNI_CallVoidMethodA) (JNIEnv *env, jobject obj, - jmethodID id, jvalue *args) +static void JNICALL +_Jv_JNI_CallVoidMethodA (JNIEnv *env, jobject obj, + jmethodID id, jvalue *args) { _Jv_JNI_CallAnyVoidMethodA (env, obj, NULL, id, args); } @@ -1021,9 +1038,9 @@ static void // Functions with this signature are used to implement functions in // the CallStaticMethod family. template -static T -(JNICALL _Jv_JNI_CallStaticMethodV) (JNIEnv *env, jclass klass, - jmethodID id, va_list args) +static T JNICALL +_Jv_JNI_CallStaticMethodV (JNIEnv *env, jclass klass, + jmethodID id, va_list args) { JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC)); JvAssert (java::lang::Class::class$.isInstance (unwrap (klass))); @@ -1034,9 +1051,9 @@ static T // Functions with this signature are used to implement functions in // the CallStaticMethod family. template -static T -(JNICALL _Jv_JNI_CallStaticMethod) (JNIEnv *env, jclass klass, - jmethodID id, ...) +static T JNICALL +_Jv_JNI_CallStaticMethod (JNIEnv *env, jclass klass, + jmethodID id, ...) { va_list args; T result; @@ -1055,9 +1072,9 @@ static T // Functions with this signature are used to implement functions in // the CallStaticMethod family. template -static T -(JNICALL _Jv_JNI_CallStaticMethodA) (JNIEnv *env, jclass klass, jmethodID id, - jvalue *args) +static T JNICALL +_Jv_JNI_CallStaticMethodA (JNIEnv *env, jclass klass, jmethodID id, + jvalue *args) { JvAssert (((id->accflags) & java::lang::reflect::Modifier::STATIC)); JvAssert (java::lang::Class::class$.isInstance (unwrap (klass))); @@ -1065,16 +1082,16 @@ static T return _Jv_JNI_CallAnyMethodA (env, NULL, klass, id, args); } -static void -(JNICALL _Jv_JNI_CallStaticVoidMethodV) (JNIEnv *env, jclass klass, - jmethodID id, va_list args) +static void JNICALL +_Jv_JNI_CallStaticVoidMethodV (JNIEnv *env, jclass klass, + jmethodID id, va_list args) { _Jv_JNI_CallAnyVoidMethodV (env, NULL, klass, id, args); } -static void -(JNICALL _Jv_JNI_CallStaticVoidMethod) (JNIEnv *env, jclass klass, - jmethodID id, ...) +static void JNICALL +_Jv_JNI_CallStaticVoidMethod (JNIEnv *env, jclass klass, + jmethodID id, ...) { va_list args; @@ -1083,16 +1100,16 @@ static void va_end (args); } -static void -(JNICALL _Jv_JNI_CallStaticVoidMethodA) (JNIEnv *env, jclass klass, - jmethodID id, jvalue *args) +static void JNICALL +_Jv_JNI_CallStaticVoidMethodA (JNIEnv *env, jclass klass, + jmethodID id, jvalue *args) { _Jv_JNI_CallAnyVoidMethodA (env, NULL, klass, id, args); } -static jobject -(JNICALL _Jv_JNI_NewObjectV) (JNIEnv *env, jclass klass, - jmethodID id, va_list args) +static jobject JNICALL +_Jv_JNI_NewObjectV (JNIEnv *env, jclass klass, + jmethodID id, va_list args) { JvAssert (klass && ! klass->isArray ()); JvAssert (! strcmp (id->name->data, "") @@ -1105,8 +1122,8 @@ static jobject id, args); } -static jobject -(JNICALL _Jv_JNI_NewObject) (JNIEnv *env, jclass klass, jmethodID id, ...) +static jobject JNICALL +_Jv_JNI_NewObject (JNIEnv *env, jclass klass, jmethodID id, ...) { JvAssert (klass && ! klass->isArray ()); JvAssert (! strcmp (id->name->data, "") @@ -1126,9 +1143,9 @@ static jobject return result; } -static jobject -(JNICALL _Jv_JNI_NewObjectA) (JNIEnv *env, jclass klass, jmethodID id, - jvalue *args) +static jobject JNICALL +_Jv_JNI_NewObjectA (JNIEnv *env, jclass klass, jmethodID id, + jvalue *args) { JvAssert (klass && ! klass->isArray ()); JvAssert (! strcmp (id->name->data, "") @@ -1144,8 +1161,8 @@ static jobject template -static T -(JNICALL _Jv_JNI_GetField) (JNIEnv *env, jobject obj, jfieldID field) +static T JNICALL +_Jv_JNI_GetField (JNIEnv *env, jobject obj, jfieldID field) { obj = unwrap (obj); JvAssert (obj); @@ -1154,8 +1171,8 @@ static T } template -static void -(JNICALL _Jv_JNI_SetField) (JNIEnv *, jobject obj, jfieldID field, T value) +static void JNICALL +_Jv_JNI_SetField (JNIEnv *, jobject obj, jfieldID field, T value) { obj = unwrap (obj); value = unwrap (value); @@ -1166,9 +1183,9 @@ static void } template -static jfieldID -(JNICALL _Jv_JNI_GetAnyFieldID) (JNIEnv *env, jclass clazz, - const char *name, const char *sig) +static jfieldID JNICALL +_Jv_JNI_GetAnyFieldID (JNIEnv *env, jclass clazz, + const char *name, const char *sig) { try { @@ -1183,11 +1200,11 @@ static jfieldID char s[len + 1]; for (int i = 0; i <= len; ++i) s[i] = (sig[i] == '/') ? '.' : sig[i]; - jclass field_class = _Jv_FindClassFromSignature ((char *) s, NULL); - - // FIXME: what if field_class == NULL? - java::lang::ClassLoader *loader = clazz->getClassLoaderInternal (); + jclass field_class = _Jv_FindClassFromSignature ((char *) s, loader); + if (! field_class) + throw new java::lang::ClassNotFoundException(JvNewStringUTF(s)); + while (clazz != NULL) { // We acquire the class lock so that fields aren't resolved @@ -1206,7 +1223,7 @@ static jfieldID // The field might be resolved or it might not be. It // is much simpler to always resolve it. - _Jv_ResolveField (field, loader); + _Jv_Linker::resolve_field (field, loader); if (_Jv_equalUtf8Consts (f_name, a_name) && field->getClass() == field_class) return field; @@ -1227,24 +1244,24 @@ static jfieldID } template -static T -(JNICALL _Jv_JNI_GetStaticField) (JNIEnv *env, jclass, jfieldID field) +static T JNICALL +_Jv_JNI_GetStaticField (JNIEnv *env, jclass, jfieldID field) { T *ptr = (T *) field->u.addr; return wrap_value (env, *ptr); } template -static void -(JNICALL _Jv_JNI_SetStaticField) (JNIEnv *, jclass, jfieldID field, T value) +static void JNICALL +_Jv_JNI_SetStaticField (JNIEnv *, jclass, jfieldID field, T value) { value = unwrap (value); T *ptr = (T *) field->u.addr; *ptr = value; } -static jstring -(JNICALL _Jv_JNI_NewString) (JNIEnv *env, const jchar *unichars, jsize len) +static jstring JNICALL +_Jv_JNI_NewString (JNIEnv *env, const jchar *unichars, jsize len) { try { @@ -1258,14 +1275,14 @@ static jstring } } -static jsize -(JNICALL _Jv_JNI_GetStringLength) (JNIEnv *, jstring string) +static jsize JNICALL +_Jv_JNI_GetStringLength (JNIEnv *, jstring string) { return unwrap (string)->length(); } -static const jchar * -(JNICALL _Jv_JNI_GetStringChars) (JNIEnv *, jstring string, jboolean *isCopy) +static const jchar * JNICALL +_Jv_JNI_GetStringChars (JNIEnv *, jstring string, jboolean *isCopy) { string = unwrap (string); jchar *result = _Jv_GetStringChars (string); @@ -1275,14 +1292,14 @@ static const jchar * return (const jchar *) result; } -static void -(JNICALL _Jv_JNI_ReleaseStringChars) (JNIEnv *, jstring string, const jchar *) +static void JNICALL +_Jv_JNI_ReleaseStringChars (JNIEnv *, jstring string, const jchar *) { unmark_for_gc (unwrap (string), global_ref_table); } -static jstring -(JNICALL _Jv_JNI_NewStringUTF) (JNIEnv *env, const char *bytes) +static jstring JNICALL +_Jv_JNI_NewStringUTF (JNIEnv *env, const char *bytes) { try { @@ -1296,22 +1313,24 @@ static jstring } } -static jsize -(JNICALL _Jv_JNI_GetStringUTFLength) (JNIEnv *, jstring string) +static jsize JNICALL +_Jv_JNI_GetStringUTFLength (JNIEnv *, jstring string) { return JvGetStringUTFLength (unwrap (string)); } -static const char * -(JNICALL _Jv_JNI_GetStringUTFChars) (JNIEnv *env, jstring string, - jboolean *isCopy) +static const char * JNICALL +_Jv_JNI_GetStringUTFChars (JNIEnv *env, jstring string, + jboolean *isCopy) { - string = unwrap (string); - jsize len = JvGetStringUTFLength (string); try { + string = unwrap (string); + if (string == NULL) + return NULL; + jsize len = JvGetStringUTFLength (string); char *r = (char *) _Jv_Malloc (len + 1); - JvGetStringUTFRegion (string, 0, len, r); + JvGetStringUTFRegion (string, 0, string->length(), r); r[len] = '\0'; if (isCopy) @@ -1326,15 +1345,15 @@ static const char * } } -static void -(JNICALL _Jv_JNI_ReleaseStringUTFChars) (JNIEnv *, jstring, const char *utf) +static void JNICALL +_Jv_JNI_ReleaseStringUTFChars (JNIEnv *, jstring, const char *utf) { _Jv_Free ((void *) utf); } -static void -(JNICALL _Jv_JNI_GetStringRegion) (JNIEnv *env, jstring string, jsize start, - jsize len, jchar *buf) +static void JNICALL +_Jv_JNI_GetStringRegion (JNIEnv *env, jstring string, jsize start, + jsize len, jchar *buf) { string = unwrap (string); jchar *result = _Jv_GetStringChars (string); @@ -1354,9 +1373,9 @@ static void memcpy (buf, &result[start], len * sizeof (jchar)); } -static void -(JNICALL _Jv_JNI_GetStringUTFRegion) (JNIEnv *env, jstring str, jsize start, - jsize len, char *buf) +static void JNICALL +_Jv_JNI_GetStringUTFRegion (JNIEnv *env, jstring str, jsize start, + jsize len, char *buf) { str = unwrap (str); @@ -1376,8 +1395,8 @@ static void _Jv_GetStringUTFRegion (str, start, len, buf); } -static const jchar * -(JNICALL _Jv_JNI_GetStringCritical) (JNIEnv *, jstring str, jboolean *isCopy) +static const jchar * JNICALL +_Jv_JNI_GetStringCritical (JNIEnv *, jstring str, jboolean *isCopy) { jchar *result = _Jv_GetStringChars (unwrap (str)); if (isCopy) @@ -1385,21 +1404,21 @@ static const jchar * return result; } -static void -(JNICALL _Jv_JNI_ReleaseStringCritical) (JNIEnv *, jstring, const jchar *) +static void JNICALL +_Jv_JNI_ReleaseStringCritical (JNIEnv *, jstring, const jchar *) { // Nothing. } -static jsize -(JNICALL _Jv_JNI_GetArrayLength) (JNIEnv *, jarray array) +static jsize JNICALL +_Jv_JNI_GetArrayLength (JNIEnv *, jarray array) { return unwrap (array)->length; } -static jarray -(JNICALL _Jv_JNI_NewObjectArray) (JNIEnv *env, jsize length, - jclass elementClass, jobject init) +static jobjectArray JNICALL +_Jv_JNI_NewObjectArray (JNIEnv *env, jsize length, + jclass elementClass, jobject init) { try { @@ -1408,7 +1427,7 @@ static jarray _Jv_CheckCast (elementClass, init); jarray result = JvNewObjectArray (length, elementClass, init); - return (jarray) wrap_value (env, result); + return (jobjectArray) wrap_value (env, result); } catch (jthrowable t) { @@ -1417,9 +1436,9 @@ static jarray } } -static jobject -(JNICALL _Jv_JNI_GetObjectArrayElement) (JNIEnv *env, jobjectArray array, - jsize index) +static jobject JNICALL +_Jv_JNI_GetObjectArrayElement (JNIEnv *env, jobjectArray array, + jsize index) { if ((unsigned) index >= (unsigned) array->length) _Jv_ThrowBadArrayIndex (index); @@ -1427,9 +1446,9 @@ static jobject return wrap_value (env, elts[index]); } -static void -(JNICALL _Jv_JNI_SetObjectArrayElement) (JNIEnv *env, jobjectArray array, - jsize index, jobject value) +static void JNICALL +_Jv_JNI_SetObjectArrayElement (JNIEnv *env, jobjectArray array, + jsize index, jobject value) { try { @@ -1449,8 +1468,8 @@ static void } template -static JArray * -(JNICALL _Jv_JNI_NewPrimitiveArray) (JNIEnv *env, jsize length) +static JArray * JNICALL +_Jv_JNI_NewPrimitiveArray (JNIEnv *env, jsize length) { try { @@ -1464,9 +1483,9 @@ static JArray * } template -static T * -(JNICALL _Jv_JNI_GetPrimitiveArrayElements) (JNIEnv *env, JArray *array, - jboolean *isCopy) +static T * JNICALL +_Jv_JNI_GetPrimitiveArrayElements (JNIEnv *env, JArray *array, + jboolean *isCopy) { array = unwrap (array); if (! _Jv_JNI_check_types (env, array, K)) @@ -1482,9 +1501,9 @@ static T * } template -static void -(JNICALL _Jv_JNI_ReleasePrimitiveArrayElements) (JNIEnv *env, JArray *array, - T *, jint /* mode */) +static void JNICALL +_Jv_JNI_ReleasePrimitiveArrayElements (JNIEnv *env, JArray *array, + T *, jint /* mode */) { array = unwrap (array); _Jv_JNI_check_types (env, array, K); @@ -1495,9 +1514,9 @@ static void } template -static void -(JNICALL _Jv_JNI_GetPrimitiveArrayRegion) (JNIEnv *env, JArray *array, - jsize start, jsize len, +static void JNICALL +_Jv_JNI_GetPrimitiveArrayRegion (JNIEnv *env, JArray *array, + jsize start, jsize len, T *buf) { array = unwrap (array); @@ -1527,9 +1546,9 @@ static void } template -static void -(JNICALL _Jv_JNI_SetPrimitiveArrayRegion) (JNIEnv *env, JArray *array, - jsize start, jsize len, T *buf) +static void JNICALL +_Jv_JNI_SetPrimitiveArrayRegion (JNIEnv *env, JArray *array, + jsize start, jsize len, T *buf) { array = unwrap (array); if (! _Jv_JNI_check_types (env, array, K)) @@ -1556,9 +1575,9 @@ static void } } -static void * -(JNICALL _Jv_JNI_GetPrimitiveArrayCritical) (JNIEnv *, jarray array, - jboolean *isCopy) +static void * JNICALL +_Jv_JNI_GetPrimitiveArrayCritical (JNIEnv *, jarray array, + jboolean *isCopy) { array = unwrap (array); // FIXME: does this work? @@ -1570,14 +1589,14 @@ static void * return r; } -static void -(JNICALL _Jv_JNI_ReleasePrimitiveArrayCritical) (JNIEnv *, jarray, void *, jint) +static void JNICALL +_Jv_JNI_ReleasePrimitiveArrayCritical (JNIEnv *, jarray, void *, jint) { // Nothing. } -static jint -(JNICALL _Jv_JNI_MonitorEnter) (JNIEnv *env, jobject obj) +static jint JNICALL +_Jv_JNI_MonitorEnter (JNIEnv *env, jobject obj) { try { @@ -1591,8 +1610,8 @@ static jint return JNI_ERR; } -static jint -(JNICALL _Jv_JNI_MonitorExit) (JNIEnv *env, jobject obj) +static jint JNICALL +_Jv_JNI_MonitorExit (JNIEnv *env, jobject obj) { try { @@ -1607,9 +1626,9 @@ static jint } // JDK 1.2 -jobject -(JNICALL _Jv_JNI_ToReflectedField) (JNIEnv *env, jclass cls, jfieldID fieldID, - jboolean) +jobject JNICALL +_Jv_JNI_ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID, + jboolean) { try { @@ -1628,8 +1647,8 @@ jobject } // JDK 1.2 -static jfieldID -(JNICALL _Jv_JNI_FromReflectedField) (JNIEnv *, jobject f) +static jfieldID JNICALL +_Jv_JNI_FromReflectedField (JNIEnv *, jobject f) { using namespace java::lang::reflect; @@ -1638,9 +1657,9 @@ static jfieldID return _Jv_FromReflectedField (field); } -jobject -(JNICALL _Jv_JNI_ToReflectedMethod) (JNIEnv *env, jclass klass, jmethodID id, - jboolean) +jobject JNICALL +_Jv_JNI_ToReflectedMethod (JNIEnv *env, jclass klass, jmethodID id, + jboolean) { using namespace java::lang::reflect; @@ -1673,8 +1692,8 @@ jobject return wrap_value (env, result); } -static jmethodID -(JNICALL _Jv_JNI_FromReflectedMethod) (JNIEnv *, jobject method) +static jmethodID JNICALL +_Jv_JNI_FromReflectedMethod (JNIEnv *, jobject method) { using namespace java::lang::reflect; method = unwrap (method); @@ -1685,8 +1704,8 @@ static jmethodID } // JDK 1.2. -jweak -(JNICALL _Jv_JNI_NewWeakGlobalRef) (JNIEnv *env, jobject obj) +jweak JNICALL +_Jv_JNI_NewWeakGlobalRef (JNIEnv *env, jobject obj) { using namespace gnu::gcj::runtime; JNIWeakRef *ref = NULL; @@ -1706,8 +1725,8 @@ jweak return reinterpret_cast (ref); } -void -(JNICALL _Jv_JNI_DeleteWeakGlobalRef) (JNIEnv *, jweak obj) +void JNICALL +_Jv_JNI_DeleteWeakGlobalRef (JNIEnv *, jweak obj) { using namespace gnu::gcj::runtime; JNIWeakRef *ref = reinterpret_cast (obj); @@ -1719,29 +1738,35 @@ void // Direct byte buffers. -static jobject -(JNICALL _Jv_JNI_NewDirectByteBuffer) (JNIEnv *, void *address, jlong length) +static jobject JNICALL +_Jv_JNI_NewDirectByteBuffer (JNIEnv *, void *address, jlong length) { using namespace gnu::gcj; using namespace java::nio; - return new DirectByteBufferImpl (reinterpret_cast (address), - length); + return new DirectByteBufferImpl$ReadWrite + (reinterpret_cast (address), length); } -static void * -(JNICALL _Jv_JNI_GetDirectBufferAddress) (JNIEnv *, jobject buffer) +static void * JNICALL +_Jv_JNI_GetDirectBufferAddress (JNIEnv *, jobject buffer) { using namespace java::nio; - DirectByteBufferImpl* bb = static_cast (buffer); - return reinterpret_cast (bb->address); + if (! _Jv_IsInstanceOf (buffer, &Buffer::class$)) + return NULL; + Buffer *tmp = static_cast (buffer); + return reinterpret_cast (tmp->address); } -static jlong -(JNICALL _Jv_JNI_GetDirectBufferCapacity) (JNIEnv *, jobject buffer) +static jlong JNICALL +_Jv_JNI_GetDirectBufferCapacity (JNIEnv *, jobject buffer) { using namespace java::nio; - DirectByteBufferImpl* bb = static_cast (buffer); - return bb->capacity(); + if (! _Jv_IsInstanceOf (buffer, &Buffer::class$)) + return -1; + Buffer *tmp = static_cast (buffer); + if (tmp->address == NULL) + return -1; + return tmp->capacity(); } @@ -1822,7 +1847,6 @@ natrehash () nathash = (JNINativeMethod *) _Jv_AllocBytes (nathash_size * sizeof (JNINativeMethod)); - memset (nathash, 0, nathash_size * sizeof (JNINativeMethod)); } else { @@ -1832,7 +1856,6 @@ natrehash () nathash = (JNINativeMethod *) _Jv_AllocBytes (nathash_size * sizeof (JNINativeMethod)); - memset (nathash, 0, nathash_size * sizeof (JNINativeMethod)); for (int i = 0; i < savesize; ++i) { @@ -1856,20 +1879,23 @@ nathash_add (const JNINativeMethod *method) return; // FIXME slot->name = strdup (method->name); - slot->signature = strdup (method->signature); + // This was already strduped in _Jv_JNI_RegisterNatives. + slot->signature = method->signature; slot->fnPtr = method->fnPtr; } -static jint -(JNICALL _Jv_JNI_RegisterNatives) (JNIEnv *env, jclass klass, - const JNINativeMethod *methods, - jint nMethods) +static jint JNICALL +_Jv_JNI_RegisterNatives (JNIEnv *env, jclass klass, + const JNINativeMethod *methods, + jint nMethods) { // Synchronize while we do the work. This must match // synchronization in some other functions that manipulate or use // the nathash table. JvSynchronize sync (global_ref_table); + JNINativeMethod dottedMethod; + // Look at each descriptor given us, and find the corresponding // method in the class. for (int j = 0; j < nMethods; ++j) @@ -1881,16 +1907,28 @@ static jint { _Jv_Method *self = &imeths[i]; - if (! strcmp (self->name->data, methods[j].name) - && ! strcmp (self->signature->data, methods[j].signature)) + // Copy this JNINativeMethod and do a slash to dot + // conversion on the signature. + dottedMethod.name = methods[j].name; + dottedMethod.signature = strdup (methods[j].signature); + dottedMethod.fnPtr = methods[j].fnPtr; + char *c = dottedMethod.signature; + while (*c) + { + if (*c == '/') + *c = '.'; + c++; + } + + if (! strcmp (self->name->chars (), dottedMethod.name) + && ! strcmp (self->signature->chars (), dottedMethod.signature)) { - if (! (self->accflags - & java::lang::reflect::Modifier::NATIVE)) + if (! (self->accflags & java::lang::reflect::Modifier::NATIVE)) break; // Found a match that is native. found = true; - nathash_add (&methods[j]); + nathash_add (&dottedMethod); break; } @@ -1901,7 +1939,7 @@ static jint jstring m = JvNewStringUTF (methods[j].name); try { - env->ex =new java::lang::NoSuchMethodError (m); + env->ex = new java::lang::NoSuchMethodError (m); } catch (jthrowable t) { @@ -1914,8 +1952,8 @@ static jint return JNI_OK; } -static jint -(JNICALL _Jv_JNI_UnregisterNatives) (JNIEnv *, jclass) +static jint JNICALL +_Jv_JNI_UnregisterNatives (JNIEnv *, jclass) { // FIXME -- we could implement this. return JNI_ERR; @@ -1986,8 +2024,8 @@ mangled_name (jclass klass, _Jv_Utf8Const *func_name, // Don't use add_char because we need a literal `_'. buf[here++] = '_'; - const unsigned char *fn = (const unsigned char *) func_name->data; - const unsigned char *limit = fn + func_name->length; + const unsigned char *fn = (const unsigned char *) func_name->chars (); + const unsigned char *limit = fn + func_name->len (); for (int i = 0; ; ++i) { int ch = UTF8_GET (fn, limit); @@ -2001,8 +2039,8 @@ mangled_name (jclass klass, _Jv_Utf8Const *func_name, buf[here++] = '_'; buf[here++] = '_'; - const unsigned char *sig = (const unsigned char *) signature->data; - limit = sig + signature->length; + const unsigned char *sig = (const unsigned char *) signature->chars (); + limit = sig + signature->len (); JvAssert (sig[0] == '('); ++sig; while (1) @@ -2023,7 +2061,7 @@ extern "C" JNIEnv * _Jv_GetJNIEnvNewFrame (jclass klass) { JNIEnv *env = _Jv_GetCurrentJNIEnv (); - if (env == NULL) + if (__builtin_expect (env == NULL, false)) { env = (JNIEnv *) _Jv_MallocUnchecked (sizeof (JNIEnv)); env->p = &_Jv_JNIFunctions; @@ -2031,35 +2069,80 @@ _Jv_GetJNIEnvNewFrame (jclass klass) env->locals = NULL; // We set env->ex below. + // Set up the bottom, reusable frame. + env->bottom_locals = (_Jv_JNI_LocalFrame *) + _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame) + + (FRAME_SIZE + * sizeof (jobject))); + + env->bottom_locals->marker = MARK_SYSTEM; + env->bottom_locals->size = FRAME_SIZE; + env->bottom_locals->next = NULL; + env->bottom_locals->allocated_p = 0; + memset (&env->bottom_locals->vec[0], 0, + env->bottom_locals->size * sizeof (jobject)); + _Jv_SetCurrentJNIEnv (env); } - _Jv_JNI_LocalFrame *frame - = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame) - + (FRAME_SIZE - * sizeof (jobject))); + // If we're in a simple JNI call (non-nested), we can just reuse the + // locals frame we allocated many calls ago, back when the env was first + // built, above. - frame->marker = MARK_SYSTEM; - frame->size = FRAME_SIZE; - frame->next = env->locals; + if (__builtin_expect (env->locals == NULL, true)) + env->locals = env->bottom_locals; - for (int i = 0; i < frame->size; ++i) - frame->vec[i] = NULL; + else + { + // Alternatively, we might be re-entering JNI, in which case we can't + // reuse the bottom_locals frame, because it is already underneath + // us. So we need to make a new one. + + _Jv_JNI_LocalFrame *frame + = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame) + + (FRAME_SIZE + * sizeof (jobject))); + + frame->marker = MARK_SYSTEM; + frame->size = FRAME_SIZE; + frame->allocated_p = 0; + frame->next = env->locals; + + memset (&frame->vec[0], 0, + frame->size * sizeof (jobject)); + + env->locals = frame; + } - env->locals = frame; env->ex = NULL; return env; } +// Destroy the env's reusable resources. This is called from the thread +// destructor "finalize_native" in natThread.cc +void +_Jv_FreeJNIEnv (_Jv_JNIEnv *env) +{ + if (env == NULL) + return; + + if (env->bottom_locals != NULL) + _Jv_Free (env->bottom_locals); + + _Jv_Free (env); +} + // Return the function which implements a particular JNI method. If // we can't find the function, we throw the appropriate exception. // This is `extern "C"' because the compiler uses it. extern "C" void * _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name, - _Jv_Utf8Const *signature, int args_size) + _Jv_Utf8Const *signature, MAYBE_UNUSED int args_size) { - char buf[10 + 6 * (name->length + signature->length) + 12]; + int name_length = name->len(); + int sig_length = signature->len(); + char buf[10 + 6 * (name_length + sig_length) + 12]; int long_start; void *function; @@ -2067,13 +2150,13 @@ _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name, JvSynchronize sync (global_ref_table); // First see if we have an override in the hash table. - strncpy (buf, name->data, name->length); - buf[name->length] = '\0'; - strncpy (buf + name->length + 1, signature->data, signature->length); - buf[name->length + signature->length + 1] = '\0'; + strncpy (buf, name->chars (), name_length); + buf[name_length] = '\0'; + strncpy (buf + name_length + 1, signature->chars (), sig_length); + buf[name_length + sig_length + 1] = '\0'; JNINativeMethod meth; meth.name = buf; - meth.signature = buf + name->length + 1; + meth.signature = buf + name_length + 1; function = nathash_find (&meth); if (function != NULL) return function; @@ -2118,9 +2201,7 @@ _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name, function = _Jv_FindSymbolInExecutable (buf + 1); } } -#else /* WIN32 */ - args_size; /* Dummy statement to avoid unused parameter warning */ -#endif /* ! WIN32 */ +#endif /* WIN32 */ if (function == NULL) { @@ -2142,7 +2223,7 @@ _Jv_LookupJNIMethod (jclass klass, _Jv_Utf8Const *name, if (function == NULL) #endif /* WIN32 */ { - jstring str = JvNewStringUTF (name->data); + jstring str = JvNewStringUTF (name->chars ()); throw new java::lang::UnsatisfiedLinkError (str); } } @@ -2215,8 +2296,13 @@ _Jv_JNIMethod::call (ffi_cif *, void *ret, ffi_raw *args, void *__this) memcpy (&real_args[offset], args, _this->args_raw_size); // The actual call to the JNI function. +#if FFI_NATIVE_RAW_API ffi_raw_call (&_this->jni_cif, (void (*)()) _this->function, ret, real_args); +#else + ffi_java_raw_call (&_this->jni_cif, (void (*)()) _this->function, + ret, real_args); +#endif if (sync != NULL) _Jv_MonitorExit (sync); @@ -2262,16 +2348,18 @@ _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, env->p = &_Jv_JNIFunctions; env->ex = NULL; env->klass = NULL; - env->locals + env->bottom_locals = (_Jv_JNI_LocalFrame *) _Jv_MallocUnchecked (sizeof (_Jv_JNI_LocalFrame) + (FRAME_SIZE * sizeof (jobject))); + env->locals = env->bottom_locals; if (env->locals == NULL) { _Jv_Free (env); return JNI_ERR; } + env->locals->allocated_p = 0; env->locals->marker = MARK_SYSTEM; env->locals->size = FRAME_SIZE; env->locals->next = NULL; @@ -2303,21 +2391,21 @@ _Jv_JNI_AttachCurrentThread (JavaVM *, jstring name, void **penv, } // This is the one actually used by JNI. -static jint -(JNICALL _Jv_JNI_AttachCurrentThread) (JavaVM *vm, void **penv, void *args) +static jint JNICALL +_Jv_JNI_AttachCurrentThread (JavaVM *vm, void **penv, void *args) { return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, false); } -static jint -(JNICALL _Jv_JNI_AttachCurrentThreadAsDaemon) (JavaVM *vm, void **penv, - void *args) +static jint JNICALL +_Jv_JNI_AttachCurrentThreadAsDaemon (JavaVM *vm, void **penv, + void *args) { return _Jv_JNI_AttachCurrentThread (vm, NULL, penv, args, true); } -static jint -(JNICALL _Jv_JNI_DestroyJavaVM) (JavaVM *vm) +static jint JNICALL +_Jv_JNI_DestroyJavaVM (JavaVM *vm) { JvAssert (the_vm && vm == the_vm); @@ -2350,15 +2438,15 @@ static jint return JNI_ERR; } -jint -(JNICALL _Jv_JNI_DetachCurrentThread) (JavaVM *) +jint JNICALL +_Jv_JNI_DetachCurrentThread (JavaVM *) { jint code = _Jv_DetachCurrentThread (); return code ? JNI_EDETACHED : 0; } -static jint -(JNICALL _Jv_JNI_GetEnv) (JavaVM *, void **penv, jint version) +static jint JNICALL +_Jv_JNI_GetEnv (JavaVM *, void **penv, jint version) { if (_Jv_ThreadCurrent () == NULL) { @@ -2387,7 +2475,7 @@ static jint return 0; } -JNIEXPORT jint JNICALL +jint JNICALL JNI_GetDefaultJavaVMInitArgs (void *args) { jint version = * (jint *) args; @@ -2404,12 +2492,21 @@ JNI_GetDefaultJavaVMInitArgs (void *args) return 0; } -JNIEXPORT jint JNICALL +jint JNICALL JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args) { JvAssert (! the_vm); - _Jv_CreateJavaVM (NULL); + jint version = * (jint *) args; + // We only support 1.2 and 1.4. + if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4) + return JNI_EVERSION; + + JvVMInitArgs* vm_args = reinterpret_cast (args); + + jint result = _Jv_CreateJavaVM (vm_args); + if (result) + return result; // FIXME: synchronize JavaVM *nvm = (JavaVM *) _Jv_MallocUnchecked (sizeof (JavaVM)); @@ -2417,48 +2514,6 @@ JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args) return JNI_ERR; nvm->functions = &_Jv_JNI_InvokeFunctions; - // Parse the arguments. - if (args != NULL) - { - jint version = * (jint *) args; - // We only support 1.2 and 1.4. - if (version != JNI_VERSION_1_2 && version != JNI_VERSION_1_4) - return JNI_EVERSION; - JavaVMInitArgs *ia = reinterpret_cast (args); - for (int i = 0; i < ia->nOptions; ++i) - { - if (! strcmp (ia->options[i].optionString, "vfprintf") - || ! strcmp (ia->options[i].optionString, "exit") - || ! strcmp (ia->options[i].optionString, "abort")) - { - // We are required to recognize these, but for now we - // don't handle them in any way. FIXME. - continue; - } - else if (! strncmp (ia->options[i].optionString, - "-verbose", sizeof ("-verbose") - 1)) - { - // We don't do anything with this option either. We - // might want to make sure the argument is valid, but we - // don't really care all that much for now. - continue; - } - else if (! strncmp (ia->options[i].optionString, "-D", 2)) - { - // FIXME. - continue; - } - else if (ia->ignoreUnrecognized) - { - if (ia->options[i].optionString[0] == '_' - || ! strncmp (ia->options[i].optionString, "-X", 2)) - continue; - } - - return JNI_ERR; - } - } - jint r =_Jv_JNI_AttachCurrentThread (nvm, penv, NULL); if (r < 0) return r; @@ -2469,7 +2524,7 @@ JNI_CreateJavaVM (JavaVM **vm, void **penv, void *args) return 0; } -JNIEXPORT jint JNICALL +jint JNICALL JNI_GetCreatedJavaVMs (JavaVM **vm_buffer, jsize buf_len, jsize *n_vms) { if (buf_len <= 0) @@ -2509,8 +2564,8 @@ _Jv_GetJavaVM () return the_vm; } -static jint -(JNICALL _Jv_JNI_GetJavaVM) (JNIEnv *, JavaVM **vm) +static jint JNICALL +_Jv_JNI_GetJavaVM (JNIEnv *, JavaVM **vm) { *vm = _Jv_GetJavaVM (); return *vm == NULL ? JNI_ERR : JNI_OK;