* src/native/jni.c (_Jv_JNI_FindClass): Renamed to jni_FindClass, call
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Tue, 1 Apr 2008 14:47:19 +0000 (16:47 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Tue, 1 Apr 2008 14:47:19 +0000 (16:47 +0200)
resolve_handle_pending_exception in exception case.
(_Jv_JNI_ExceptionDescribe): Renamed to jni_ExceptionDescribe, use
exceptions_print_stacktrace.
(_Jv_JNI_ExceptionClear): Renamed to jni_ExceptionClear.

* src/threads/thread.h (threads_thread_get_object): Renamed to
thread_get_object.
(threads_thread_set_object): Renamed to thread_set_object.
(threads_get_current_object): Renamed to thread_get_current_object.
(thread_is_attached): Use new function names.
(thread_fprint_name): Export.

* src/threads/none/threads.h (threads_get_current_object): Renamed to
thread_get_current_object.

* src/native/vm/cldc1.1/java_lang_Thread.c (currentThread): Use new
function names.
* src/native/vm/gnu/java_lang_VMThread.c (currentThread): Likewise.
* src/native/vm/sun/jvm.c (JVM_CurrentThread): Likewise.
* src/threads/posix/thread-posix.c (threads_startup_thread): Likewise.
(threads_detach_thread): Likewise.
* src/threads/thread.c (thread_create_object): Likewise.
(thread_free): Likewise.
(threads_thread_start): Likewise.
(thread_fprint_name): New function.
(threads_thread_print_info): Use thread_fprint_name.

* src/vm/exceptions.c (exceptions_print_stacktrace): Implemented
(mostly) as in HotSpot.

src/native/jni.c
src/native/vm/cldc1.1/java_lang_Thread.c
src/native/vm/gnu/java_lang_VMThread.c
src/native/vm/sun/jvm.c
src/threads/none/threads.h
src/threads/posix/thread-posix.c
src/threads/thread.c
src/threads/thread.h
src/vm/exceptions.c

index 50a19fd46ac1a5aa1b393edc38b41a8a415db347..ffd652c6291d1ccc3a22683aec39d60316c6fcdc 100644 (file)
@@ -942,7 +942,7 @@ jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
 
 *******************************************************************************/
 
-jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
+jclass jni_FindClass(JNIEnv *env, const char *name)
 {
 #if defined(ENABLE_JAVASE)
 
@@ -951,10 +951,17 @@ jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
        classinfo       *c;
        java_lang_Class *co;
 
-       TRACEJNICALLS(("_Jv_JNI_FindClass(env=%p, name=%s)", env, name));
+       TRACEJNICALLS(("jni_FindClass(env=%p, name=%s)", env, name));
+
+       /* FIXME If name is NULL we have a problem here. */
 
        u = utf_new_char_classname((char *) name);
 
+       if ((u == NULL) /*|| (int)strlen(name) > symbolOopDesc::max_length() */) {
+               exceptions_throw_noclassdeffounderror(u);
+               return NULL;
+       }
+
        /* Check stacktrace for classloader, if one found use it,
           otherwise use the system classloader. */
 
@@ -976,8 +983,10 @@ jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
        else
                c = load_class_from_classloader(u, cc->classloader);
 
-       if (c == NULL)
+       if (c == NULL) {
+               resolve_handle_pending_exception(true);
                return NULL;
+       }
 
        if (!link_class(c))
                return NULL;
@@ -991,13 +1000,15 @@ jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
        utf       *u;
        classinfo *c;
 
-       TRACEJNICALLS(("_Jv_JNI_FindClass(env=%p, name=%s)", env, name));
+       TRACEJNICALLS(("jni_FindClass(env=%p, name=%s)", env, name));
 
        u = utf_new_char_classname((char *) name);
        c = load_class_bootstrap(u);
 
-       if (c == NULL)
+       if (c == NULL) {
+               resolve_handle_pending_exception(true);
                return NULL;
+       }
 
        if (!link_class(c))
                return NULL;
@@ -1005,7 +1016,7 @@ jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
        return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
        
 #else
-       vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
+       vm_abort("jni_FindClass: not implemented in this configuration");
 
        /* keep compiler happy */
 
@@ -1145,37 +1156,11 @@ jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
 
 *******************************************************************************/
 
-void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
+void jni_ExceptionDescribe(JNIEnv *env)
 {
-       java_handle_t *o;
-       classinfo     *c;
-       methodinfo    *m;
+       TRACEJNICALLS(("jni_ExceptionDescribe(env=%p)", env));
 
-       TRACEJNICALLS(("_Jv_JNI_ExceptionDescribe(env=%p)", env));
-
-       /* Clear exception, because we are probably calling Java code
-          again. */
-
-       o = exceptions_get_and_clear_exception();
-
-       if (o != NULL) {
-               /* get printStackTrace method from exception class */
-
-               LLNI_class_get(o, c);
-
-               m = class_resolveclassmethod(c,
-                                                                        utf_printStackTrace,
-                                                                        utf_void__void,
-                                                                        NULL,
-                                                                        true);
-
-               if (m == NULL)
-                       vm_abort("_Jv_JNI_ExceptionDescribe: could not find printStackTrace");
-
-               /* Print the stacktrace. */
-
-               (void) vm_call_method(m, o);
-       }
+       exceptions_print_stacktrace();
 }
 
 
@@ -1186,9 +1171,9 @@ void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
 
 *******************************************************************************/
 
-void _Jv_JNI_ExceptionClear(JNIEnv *env)
+void jni_ExceptionClear(JNIEnv *env)
 {
-       STATISTICS(jniinvokation());
+       TRACEJNICALLS(("jni_ExceptionClear(env=%p)", env));
 
        exceptions_clear_exception();
 }
@@ -4052,7 +4037,7 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = {
        _Jv_JNI_GetVersion,
 
        _Jv_JNI_DefineClass,
-       _Jv_JNI_FindClass,
+       jni_FindClass,
        _Jv_JNI_FromReflectedMethod,
        _Jv_JNI_FromReflectedField,
        _Jv_JNI_ToReflectedMethod,
@@ -4063,8 +4048,8 @@ struct JNINativeInterface_ _Jv_JNINativeInterface = {
        _Jv_JNI_Throw,
        _Jv_JNI_ThrowNew,
        _Jv_JNI_ExceptionOccurred,
-       _Jv_JNI_ExceptionDescribe,
-       _Jv_JNI_ExceptionClear,
+       jni_ExceptionDescribe,
+       jni_ExceptionClear,
        _Jv_JNI_FatalError,
        _Jv_JNI_PushLocalFrame,
        _Jv_JNI_PopLocalFrame,
index 22c0dbb2852f0a5b30c4b804a7ef4a8f088a463a..da9ffd01a604c358179e4883a802ab22e1945a0f 100644 (file)
@@ -82,11 +82,11 @@ void _Jv_java_lang_Thread_init(void)
  */
 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
 {
-       java_lang_Thread *thread;
+       java_lang_Thread *to;
 
-       thread = (java_lang_Thread *) threads_get_current_object();
+       to = (java_lang_Thread *) thread_get_current_object();
 
-       return thread;
+       return to;
 }
 
 
index 1b2ea7147d36ec2d29c5674bfca109ad05e98cb4..7d01381c606ccc89e743a708ba0ef278597c2b78 100644 (file)
@@ -221,11 +221,11 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang
  */
 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
 {
-       java_lang_Thread *thread;
+       java_lang_Thread *to;
 
-       thread = (java_lang_Thread *) threads_get_current_object();
+       to = (java_lang_Thread *) thread_get_current_object();
 
-       return thread;
+       return to;
 }
 
 
index 0321039f9e9e499c19611a5da95b234160772c34..902a7c51d5f4f1e498fd9bdecca06e8f4c5d6b14 100644 (file)
@@ -2324,7 +2324,7 @@ jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
 
        TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
 
-       o = threads_get_current_object();
+       o = thread_get_current_object();
 
        return (jobject) o;
 }
index 182b0de40bd099cacb1ce045f4b9d8d3dc6b62dd..f8b63be96d1f17516605998ce81d290f8f0a8384 100644 (file)
@@ -68,7 +68,7 @@ extern u4 _no_threads_tracejavacallcount;
 
 /* inline functions ***********************************************************/
 
-inline static java_handle_t *threads_get_current_object(void)
+inline static java_handle_t *thread_get_current_object(void)
 {
        java_handle_t *o;
 
index b31a0978f24f7ba86a3fa42c83631667afca8d28..d04335335ca17468b686222e61472a4807ffca37 100644 (file)
@@ -1059,7 +1059,7 @@ static void *threads_startup_thread(void *arg)
 
        /* get the java.lang.Thread object for this thread */
 
-       object = (java_lang_Thread *) threads_thread_get_object(thread);
+       object = (java_lang_Thread *) thread_get_object(thread);
 
        /* set our priority */
 
@@ -1303,7 +1303,7 @@ bool threads_detach_thread(threadobject *t)
 
        DEBUGTHREADS("detaching", t);
 
-       object = (java_lang_Thread *) threads_thread_get_object(t);
+       object = (java_lang_Thread *) thread_get_object(t);
 
 #if defined(ENABLE_JAVASE)
        LLNI_field_get_ref(object, group, group);
index afa21e8d62536859a74e54f48e4da5c0978a8c21..be644169547620cee1a851f49fbdbe991aa2f4a5 100644 (file)
@@ -252,7 +252,7 @@ static bool thread_create_object(threadobject *t, java_handle_t *name, java_hand
        /* Set the Java object in the thread data-structure.  This
           indicates that the thread is attached to the VM. */
 
-       threads_thread_set_object(t, (java_handle_t *) to);
+       thread_set_object(t, (java_handle_t *) to);
 
 #if defined(WITH_CLASSPATH_GNU)
 
@@ -578,7 +578,7 @@ void thread_free(threadobject *t)
 
        /* Set the reference to the Java object to NULL. */
 
-       threads_thread_set_object(t, NULL);
+       thread_set_object(t, NULL);
 
        /* Add the thread data structure to the free list. */
 
@@ -685,7 +685,7 @@ void threads_thread_start(java_handle_t *object)
 
        /* Link the two objects together. */
 
-       threads_thread_set_object(t, object);
+       thread_set_object(t, object);
 
 #if defined(WITH_CLASSPATH_GNU)
 
@@ -808,48 +808,76 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
 }
 
 
-/* threads_thread_print_info ***************************************************
+/* thread_fprint_name **********************************************************
+
+   Print the name of the given thread to the given stream.
+
+   ARGUMENTS:
+       t ........ thread data-structure
+       stream ... stream to print to
 
-   Print information of the passed thread.
-   
 *******************************************************************************/
 
-void threads_thread_print_info(threadobject *t)
+void thread_fprint_name(threadobject *t, FILE *stream)
 {
-       java_lang_Thread *object;
+       java_lang_Thread *to;
+
 #if defined(WITH_CLASSPATH_GNU)
-       java_lang_String *namestring;
+       java_lang_String *name;
+#elif defined(WITH_CLASSPATH_SUN) || defined(WITH_CLASSPATH_CLDC1_1)
+       java_chararray_t *name;
 #endif
-       utf              *name;
-
-       assert(t->state != THREAD_STATE_NEW);
 
-       /* the thread may be currently in initalization, don't print it */
+       to = (java_lang_Thread *) thread_get_object(t);
 
-       object = (java_lang_Thread *) threads_thread_get_object(t);
+       if (to == NULL)
+               vm_abort("");
 
-       if (object != NULL) {
-               /* get thread name */
+       LLNI_field_get_ref(to, name, name);
 
 #if defined(WITH_CLASSPATH_GNU)
-               LLNI_field_get_ref(object, name, namestring);
-               name = javastring_toutf((java_handle_t *) namestring, false);
+
+       javastring_fprint((java_handle_t *) name, stream);
+
 #elif defined(WITH_CLASSPATH_SUN) || defined(WITH_CLASSPATH_CLDC1_1)
-               /* FIXME: In cldc the name is a char[] */
-/*             name = object->name; */
-               name = utf_null;
+
+       /* FIXME: In OpenJDK and CLDC the name is a char[]. */
+       /* FIXME This prints to stdout. */
+       utf_display_printable_ascii(utf_null);
+
 #else
 # error unknown classpath configuration
 #endif
+}
+
+
+/* threads_thread_print_info ***************************************************
+
+   Print information of the passed thread.
+   
+*******************************************************************************/
+
+void threads_thread_print_info(threadobject *t)
+{
+       java_lang_Thread *to;
+
+       assert(t->state != THREAD_STATE_NEW);
+
+       /* If the thread is currently in initalization, don't print it. */
+
+       to = (java_lang_Thread *) thread_get_object(t);
+
+       if (to != NULL) {
+               /* Print thread name. */
 
                printf("\"");
-               utf_display_printable_ascii(name);
+               thread_fprint_name(t, stdout);
                printf("\"");
 
                if (thread_is_daemon(t))
                        printf(" daemon");
 
-               printf(" prio=%d", LLNI_field_direct(object, priority));
+               printf(" prio=%d", LLNI_field_direct(to, priority));
 
 #if SIZEOF_VOID_P == 8
                printf(" t=0x%016lx tid=0x%016lx (%ld)",
index 0b44b7452ef3f12e8ebb3b2bec7816eccc810f4e..e1152878eaec17200019f290b7b0640ca2eba5e1 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "config.h"
 
+#include "vmcore/system.h"
+
 #if defined(ENABLE_THREADS)
 # include "threads/posix/thread-posix.h"
 #else
@@ -91,13 +93,19 @@ extern bool threads_pthreads_implementation_nptl;
 
 /* inline functions ***********************************************************/
 
-/* threads_thread_get_object ***************************************************
+/* thread_get_object ***********************************************************
+
+   Return the Java for the given thread.
+
+   ARGUMENTS:
+       t ... thread
 
-   Return the java.lang.Thread object for the given thread.
+   RETURN:
+       the Java object
 
 *******************************************************************************/
 
-static inline java_handle_t *threads_thread_get_object(threadobject *t)
+inline static java_handle_t *thread_get_object(threadobject *t)
 {
        return LLNI_WRAP(t->object);
 }
@@ -105,17 +113,21 @@ static inline java_handle_t *threads_thread_get_object(threadobject *t)
 
 /* threads_thread_set_object ***************************************************
 
-   Set the java.lang.Thread object for the given thread.
+   Set the Java object for the given thread.
+
+   ARGUMENTS:
+       t ... thread
+          o ... Java object
 
 *******************************************************************************/
 
-static inline void threads_thread_set_object(threadobject *t, java_handle_t *object)
+inline static void thread_set_object(threadobject *t, java_handle_t *o)
 {
-       t->object = LLNI_DIRECT(object);
+       t->object = LLNI_DIRECT(o);
 }
 
 
-/* threads_get_current_object **************************************************
+/* thread_get_current_object **************************************************
 
    Return the Java object of the current thread.
    
@@ -124,13 +136,13 @@ static inline void threads_thread_set_object(threadobject *t, java_handle_t *obj
 
 *******************************************************************************/
 
-inline static java_handle_t *threads_get_current_object(void)
+inline static java_handle_t *thread_get_current_object(void)
 {
        threadobject  *t;
        java_handle_t *o;
 
        t = THREADOBJECT;
-       o = threads_thread_get_object(t);
+       o = thread_get_object(t);
 
        return o;
 }
@@ -150,7 +162,7 @@ inline static bool thread_is_attached(threadobject *t)
 {
        java_handle_t *o;
 
-       o = threads_thread_get_object(t);
+       o = thread_get_object(t);
 
        if (o != NULL)
                return true;
@@ -212,6 +224,7 @@ void          threads_thread_start(java_handle_t *object);
 
 bool          threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 
+void          thread_fprint_name(threadobject *t, FILE *stream);
 void          threads_thread_print_info(threadobject *t);
 
 intptr_t      threads_get_current_tid(void);
index b0a23012a7ff9f9fd6a9ab3fe9a225bdc05b697e..2b3f71ba8eb52a82de096d86b3e03c9290824369 100644 (file)
@@ -42,6 +42,7 @@
 #include "native/native.h"
 
 #include "native/include/java_lang_String.h"
+#include "native/include/java_lang_Thread.h"
 #include "native/include/java_lang_Throwable.h"
 
 #include "threads/lock-common.h"
@@ -2012,63 +2013,100 @@ void exceptions_print_current_exception(void)
 
 void exceptions_print_stacktrace(void)
 {
-       java_handle_t *oxptr;
-       java_handle_t *xptr;
-       classinfo     *c;
-       methodinfo    *m;
+       java_handle_t    *e;
+       java_handle_t    *ne;
+       classinfo        *c;
+       methodinfo       *m;
 
-       /* get original exception */
+#if defined(ENABLE_THREADS)
+       threadobject     *t;
+       java_lang_Thread *to;
+#endif
 
-       oxptr = exceptions_get_and_clear_exception();
+       /* Get and clear exception because we are calling Java code
+          again. */
 
-       if (oxptr == NULL)
-               vm_abort("exceptions_print_stacktrace: no exception thrown");
+       e = exceptions_get_and_clear_exception();
 
-       /* clear exception, because we are calling jit code again */
+       if (e == NULL)
+               return;
 
-       LLNI_class_get(oxptr, c);
+#if 0
+       /* FIXME Enable me. */
+       if (builtin_instanceof(e, class_java_lang_ThreadDeath)) {
+               /* Don't print anything if we are being killed. */
+       }
+       else
+#endif
+       {
+               /* Get the exception class. */
 
-       /* find the printStackTrace() method */
+               LLNI_class_get(e, c);
 
-       m = class_resolveclassmethod(c,
-                                                                utf_printStackTrace,
-                                                                utf_void__void,
-                                                                class_java_lang_Object,
-                                                                false);
+               /* Find the printStackTrace() method. */
 
-       if (m == NULL)
-               vm_abort("exceptions_print_stacktrace: printStackTrace()V not found");
+               m = class_resolveclassmethod(c,
+                                                                        utf_printStackTrace,
+                                                                        utf_void__void,
+                                                                        class_java_lang_Object,
+                                                                        false);
 
-       /* print compatibility message */
+               if (m == NULL)
+                       vm_abort("exceptions_print_stacktrace: printStackTrace()V not found");
 
-       fprintf(stderr, "Exception in thread \"main\" ");
+               /* Print message. */
 
-       /* print the stacktrace */
+               fprintf(stderr, "Exception ");
 
-       (void) vm_call_method(m, oxptr);
+#if defined(ENABLE_THREADS)
+               /* Print thread name.  We get the thread here explicitly as we
+                  need it afterwards. */
 
-       /* This normally means, we are EXTREMLY out of memory or
-          have a serious problem while printStackTrace. But may
-          be another exception, so print it. */
+               t  = thread_get_current();
+               to = (java_lang_Thread *) thread_get_object(t);
 
-       xptr = exceptions_get_exception();
+               if (to != NULL) {
+                       fprintf(stderr, "in thread \"");
+                       thread_fprint_name(t, stderr);
+                       fprintf(stderr, "\" ");
+               }
+#endif
 
-       if (xptr != NULL) {
-               fprintf(stderr, "Exception while printStackTrace(): ");
+               /* Print the stacktrace. */
 
-               /* now print original exception */
+               if (builtin_instanceof(e, class_java_lang_Throwable)) {
+                       (void) vm_call_method(m, e);
 
-               exceptions_print_exception(xptr);
-               stacktrace_print_exception(xptr);
+                       /* If this happens we are EXTREMLY out of memory or have a
+                          serious problem while printStackTrace.  But may be
+                          another exception, so print it. */
 
-               /* now print original exception */
+                       ne = exceptions_get_exception();
 
-               fprintf(stderr, "Original exception was: ");
-               exceptions_print_exception(oxptr);
-               stacktrace_print_exception(oxptr);
-       }
+                       if (ne != NULL) {
+                               fprintf(stderr, "Exception while printStackTrace(): ");
+
+                               /* Print the current exception. */
+
+                               exceptions_print_exception(ne);
+                               stacktrace_print_exception(ne);
+
+                               /* Now print the original exception. */
 
-       fflush(stderr);
+                               fprintf(stderr, "Original exception was: ");
+                               exceptions_print_exception(e);
+                               stacktrace_print_exception(e);
+                       }
+               }
+               else {
+                       fprintf(stderr, ". Uncaught exception of type ");
+                       /* FIXME This prints to stdout. */
+                       class_print(c);
+                       fprintf(stderr, ".");
+               }
+
+               fflush(stderr);
+       }
 }