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.
*******************************************************************************/
-jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
+jclass jni_FindClass(JNIEnv *env, const char *name)
{
#if defined(ENABLE_JAVASE)
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. */
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;
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;
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 */
*******************************************************************************/
-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();
}
*******************************************************************************/
-void _Jv_JNI_ExceptionClear(JNIEnv *env)
+void jni_ExceptionClear(JNIEnv *env)
{
- STATISTICS(jniinvokation());
+ TRACEJNICALLS(("jni_ExceptionClear(env=%p)", env));
exceptions_clear_exception();
}
_Jv_JNI_GetVersion,
_Jv_JNI_DefineClass,
- _Jv_JNI_FindClass,
+ jni_FindClass,
_Jv_JNI_FromReflectedMethod,
_Jv_JNI_FromReflectedField,
_Jv_JNI_ToReflectedMethod,
_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,
*/
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;
}
*/
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;
}
TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
- o = threads_get_current_object();
+ o = thread_get_current_object();
return (jobject) o;
}
/* 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;
/* 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 */
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);
/* 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)
/* 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. */
/* Link the two objects together. */
- threads_thread_set_object(t, object);
+ thread_set_object(t, object);
#if defined(WITH_CLASSPATH_GNU)
}
-/* 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)",
#include "config.h"
+#include "vmcore/system.h"
+
#if defined(ENABLE_THREADS)
# include "threads/posix/thread-posix.h"
#else
/* 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);
}
/* 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.
*******************************************************************************/
-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;
}
{
java_handle_t *o;
- o = threads_thread_get_object(t);
+ o = thread_get_object(t);
if (o != NULL)
return true;
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);
#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"
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);
+ }
}