* src/cacaoh/dummy.c (resolve_handle_pending_exception): New function.
[cacao.git] / src / native / vm / sun / jvm.c
index 3bd28843cae3bdc105c3dab6f51b4a985eed0169..91545dd36438e3eccd93682d200207f831d84776 100644 (file)
@@ -68,7 +68,6 @@
 #include "native/vm/reflect.h"
 
 #include "threads/lock-common.h"
-#include "threads/threadlist.h"
 #include "threads/threads-common.h"
 
 #include "toolbox/logging.h"
 
 #if !defined(NDEBUG)
 
-# define TRACEJVMCALLS(...)                                            \
-    do {                                                                               \
-        if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {                           \
-            log_println(__VA_ARGS__);                  \
-        }                                                                              \
+# define TRACEJVMCALLS(x)                                                                              \
+    do {                                                                                                               \
+        if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {   \
+            log_println x;                                                                             \
+        }                                                                                                              \
     } while (0)
 
 # define TRACEJVMCALLSVERBOSE(x)                               \
         }                                                                              \
     } while (0)
 
-# define PRINTJVMWARNINGS(...)
+# define PRINTJVMWARNINGS(x)
 /*     do { \ */
 /*         if (opt_PrintJVMWarnings) { \ */
-/*             log_println(__VA_ARGS__); \ */
+/*             log_println x; \ */
 /*         } \ */
 /*     } while (0) */
 
 #else
 
-# define TRACEJVMCALLS(...)
+# define TRACEJVMCALLS(x)
 # define TRACEJVMCALLSVERBOSE(x)
-# define PRINTJVMWARNINGS(...)
+# define PRINTJVMWARNINGS(x)
 
 #endif
 
@@ -229,7 +228,7 @@ jint JVM_GetInterfaceVersion()
 
 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
 {
-       TRACEJVMCALLS("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored);
+       TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
 
        return (jlong) builtin_currenttimemillis();
 }
@@ -239,7 +238,7 @@ jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
 
 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
 {
-       TRACEJVMCALLS("JVM_NanoTime(env=%p, ignored=%p)", env, ignored);
+       TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
 
        return (jlong) builtin_nanotime();
 }
@@ -267,7 +266,7 @@ jobject JVM_InitProperties(JNIEnv *env, jobject properties)
 {
        java_handle_t *h;
 
-       TRACEJVMCALLS("JVM_InitProperties(env=%p, properties=%p)", env, properties);
+       TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
 
        h = (java_handle_t *) properties;
 
@@ -289,7 +288,7 @@ void JVM_Exit(jint code)
 
 void JVM_Halt(jint code)
 {
-       TRACEJVMCALLS("JVM_Halt(code=%d)", code);
+       TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
 
 /*     vm_exit(code); */
        vm_shutdown(code);
@@ -308,7 +307,7 @@ void JVM_OnExit(void (*func)(void))
 
 void JVM_GC(void)
 {
-       TRACEJVMCALLS("JVM_GC()");
+       TRACEJVMCALLS(("JVM_GC()"));
 
        gc_call();
 }
@@ -344,7 +343,7 @@ void JVM_TraceMethodCalls(jboolean on)
 
 jlong JVM_TotalMemory(void)
 {
-       TRACEJVMCALLS("JVM_TotalMemory()");
+       TRACEJVMCALLS(("JVM_TotalMemory()"));
 
        return gc_get_heap_size();
 }
@@ -354,7 +353,7 @@ jlong JVM_TotalMemory(void)
 
 jlong JVM_FreeMemory(void)
 {
-       TRACEJVMCALLS("JVM_FreeMemory()");
+       TRACEJVMCALLS(("JVM_FreeMemory()"));
 
        return gc_get_free_bytes();
 }
@@ -364,7 +363,7 @@ jlong JVM_FreeMemory(void)
 
 jlong JVM_MaxMemory(void)
 {
-       TRACEJVMCALLS("JVM_MaxMemory()");
+       TRACEJVMCALLS(("JVM_MaxMemory()"));
 
        return gc_get_max_heap_size();
 }
@@ -374,7 +373,7 @@ jlong JVM_MaxMemory(void)
 
 jint JVM_ActiveProcessorCount(void)
 {
-       TRACEJVMCALLS("JVM_ActiveProcessorCount()");
+       TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
 
        return system_processors_online();
 }
@@ -387,7 +386,7 @@ void JVM_FillInStackTrace(JNIEnv *env, jobject receiver)
        java_lang_Throwable     *o;
        java_handle_bytearray_t *ba;
 
-       TRACEJVMCALLS("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver);
+       TRACEJVMCALLS(("JVM_FillInStackTrace(env=%p, receiver=%p)", env, receiver));
 
        o = (java_lang_Throwable *) receiver;
 
@@ -412,21 +411,24 @@ void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
 
 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
 {
-       java_lang_Throwable     *t;
+       java_lang_Throwable     *to;
+       java_lang_Object        *o;
        java_handle_bytearray_t *ba;
        stacktrace_t            *st;
        int32_t                  depth;
 
-       TRACEJVMCALLS("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable);
+       TRACEJVMCALLS(("JVM_GetStackTraceDepth(env=%p, throwable=%p)", env, throwable));
 
        if (throwable == NULL) {
                exceptions_throw_nullpointerexception();
                return 0;
        }
 
-       t = (java_lang_Throwable *) throwable;
+       to = (java_lang_Throwable *) throwable;
 
-       LLNI_field_get_ref(t, backtrace, ba);
+       LLNI_field_get_ref(to, backtrace, o);
+
+       ba = (java_handle_bytearray_t *) o;
 
        if (ba == NULL)
                return 0;
@@ -450,23 +452,26 @@ jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
 
 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 {
-       java_lang_Throwable         *t;
+       java_lang_Throwable         *to;
+       java_lang_Object            *o;
        java_handle_bytearray_t     *ba;
        stacktrace_t                *st;
        stacktrace_entry_t          *ste;
        codeinfo                    *code;
        methodinfo                  *m;
        classinfo                   *c;
-       java_lang_StackTraceElement *o;
+       java_lang_StackTraceElement *steo;
        java_lang_String            *declaringclass;
        java_lang_String            *filename;
        int32_t                      linenumber;
 
-       TRACEJVMCALLS("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index);
+       TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
+
+       to = (java_lang_Throwable *) throwable;
 
-       t = (java_lang_Throwable *) throwable;
+       LLNI_field_get_ref(to, backtrace, o);
 
-       LLNI_field_get_ref(t, backtrace, ba);
+       ba = (java_handle_bytearray_t *) o;
 
        /* FIXME critical section */
 
@@ -492,10 +497,10 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
        /* allocate a new StackTraceElement */
 
-       o = (java_lang_StackTraceElement *)
+       steo = (java_lang_StackTraceElement *)
                builtin_new(class_java_lang_StackTraceElement);
 
-       if (o == NULL)
+       if (steo == NULL)
                return NULL;
 
        /* get filename */
@@ -530,12 +535,12 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
        /* FIXME critical section */
 
-       o->declaringClass = declaringclass;
-       o->methodName     = (java_lang_String *) javastring_new(m->name);
-       o->fileName       = filename;
-       o->lineNumber     = linenumber;
+       steo->declaringClass = declaringclass;
+       steo->methodName     = (java_lang_String *) javastring_new(m->name);
+       steo->fileName       = filename;
+       steo->lineNumber     = linenumber;
 
-       return (jobject) o;
+       return (jobject) steo;
 }
 
 
@@ -543,7 +548,7 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
 jint JVM_IHashCode(JNIEnv* env, jobject handle)
 {
-       TRACEJVMCALLS("JVM_IHashCode(env=%p, jobject=%p)", env, handle);
+       TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
 
        return (jint) ((ptrint) handle);
 }
@@ -557,7 +562,7 @@ void JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms)
        java_handle_t *o;
 #endif
 
-       TRACEJVMCALLS("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms);
+       TRACEJVMCALLS(("JVM_MonitorWait(env=%p, handle=%p, ms=%ld)", env, handle, ms));
     if (ms < 0) {
 /*             exceptions_throw_illegalargumentexception("argument out of range"); */
                exceptions_throw_illegalargumentexception();
@@ -580,7 +585,7 @@ void JVM_MonitorNotify(JNIEnv* env, jobject handle)
        java_handle_t *o;
 #endif
 
-       TRACEJVMCALLS("JVM_MonitorNotify(env=%p, handle=%p)", env, handle);
+       TRACEJVMCALLS(("JVM_MonitorNotify(env=%p, handle=%p)", env, handle));
 
 #if defined(ENABLE_THREADS)
        o = (java_handle_t *) handle;
@@ -598,7 +603,7 @@ void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
        java_handle_t *o;
 #endif
 
-       TRACEJVMCALLS("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle);
+       TRACEJVMCALLS(("JVM_MonitorNotifyAll(env=%p, handle=%p)", env, handle));
 
 #if defined(ENABLE_THREADS)
        o = (java_handle_t *) handle;
@@ -612,7 +617,7 @@ void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
 
 jobject JVM_Clone(JNIEnv* env, jobject handle)
 {
-       TRACEJVMCALLS("JVM_Clone(env=%p, handle=%p)", env, handle);
+       TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
 
        return (jobject) builtin_clone(env, (java_handle_t *) handle);
 }
@@ -670,8 +675,8 @@ jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
 
 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
 {
-       TRACEJVMCALLS("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls);
-       PRINTJVMWARNINGS("JVM_EnableCompiler not supported");
+       TRACEJVMCALLS(("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls));
+       PRINTJVMWARNINGS(("JVM_EnableCompiler not supported"));
 }
 
 
@@ -679,8 +684,8 @@ void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
 
 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
 {
-       TRACEJVMCALLS("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls);
-       PRINTJVMWARNINGS("JVM_DisableCompiler not supported");
+       TRACEJVMCALLS(("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls));
+       PRINTJVMWARNINGS(("JVM_DisableCompiler not supported"));
 }
 
 
@@ -714,7 +719,7 @@ jint JVM_GetLastErrorString(char *buf, int len)
 
 char *JVM_NativePath(char *path)
 {
-       TRACEJVMCALLS("JVM_NativePath(path=%s)", path);
+       TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
 
        /* XXX is this correct? */
 
@@ -726,20 +731,13 @@ char *JVM_NativePath(char *path)
 
 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
 {
-       java_handle_objectarray_t *oa;
-
-       TRACEJVMCALLS("JVM_GetCallerClass(env=%p, depth=%d)", env, depth);
-
-       oa = stacktrace_getClassContext();
-
-       if (oa == NULL)
-               return NULL;
+       classinfo *c;
 
-       if (oa->header.size < depth)
-               return NULL;
+       TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
 
-       return (jclass) oa->data[depth - 1];
+       c = stacktrace_get_caller_class(depth);
 
+       return (jclass) c;
 }
 
 
@@ -750,7 +748,7 @@ jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
        classinfo *c;
        utf       *u;
 
-       TRACEJVMCALLS("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s);
+       TRACEJVMCALLS(("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s));
 
        u = utf_new_char(s);
        c = primitive_class_get_by_name(u);
@@ -763,8 +761,8 @@ jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
 
 void JVM_ResolveClass(JNIEnv* env, jclass cls)
 {
-       TRACEJVMCALLS("JVM_ResolveClass(env=%p, cls=%p)", env, cls);
-       PRINTJVMWARNINGS("JVM_ResolveClass not implemented");
+       TRACEJVMCALLS(("JVM_ResolveClass(env=%p, cls=%p)", env, cls));
+       PRINTJVMWARNINGS(("JVM_ResolveClass not implemented"));
 }
 
 
@@ -776,7 +774,12 @@ jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init
        utf         *u;
        classloader *cl;
 
-       TRACEJVMCALLS("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError);
+       TRACEJVMCALLS(("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError));
+
+       /* As of now, OpenJDK does not call this function with throwError
+          is true. */
+
+       assert(throwError == false);
 
        u  = utf_new_char(name);
        cl = loader_hashtable_classloader_add((java_handle_t *) loader);
@@ -823,7 +826,7 @@ jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
        utf         *u;
        classloader *cl;
 
-       TRACEJVMCALLS("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source);
+       TRACEJVMCALLS(("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source));
 
        if (name != NULL)
                u = utf_new_char(name);
@@ -848,7 +851,7 @@ jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
        utf         *u;
        classinfo   *c;
 
-       TRACEJVMCALLS("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name);
+       TRACEJVMCALLS(("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name));
 
        cl = loader_hashtable_classloader_add((java_handle_t *) loader);
 
@@ -863,7 +866,7 @@ jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
 
 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
 {
-       TRACEJVMCALLS("JVM_GetClassName(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
 
        return (jstring) _Jv_java_lang_Class_getName((java_lang_Class *) cls);
 }
@@ -876,7 +879,7 @@ jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
        classinfo                 *c;
        java_handle_objectarray_t *oa;
 
-       TRACEJVMCALLS("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -893,7 +896,7 @@ jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
        classinfo   *c;
        classloader *cl;
 
-       TRACEJVMCALLS("JVM_GetClassLoader(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
 
        c  = LLNI_classinfo_unwrap(cls);
        cl = class_get_classloader(c);
@@ -908,7 +911,7 @@ jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       TRACEJVMCALLS("JVM_IsInterface(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -933,7 +936,7 @@ void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
        classinfo                 *c;
        java_handle_objectarray_t *hoa;
 
-       TRACEJVMCALLS("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers);
+       TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -957,7 +960,7 @@ jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       TRACEJVMCALLS("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -987,16 +990,16 @@ void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
 
 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
 {
-       java_handle_t *o;
+       java_handle_t *h;
        classinfo     *c;
        methodinfo    *m;
        java_handle_t *result;
        java_handle_t *e;
 
-       TRACEJVMCALLS("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException);
+       TRACEJVMCALLS(("JVM_DoPrivileged(env=%p, cls=%p, action=%p, context=%p, wrapException=%d)", env, cls, action, context, wrapException));
 
-       o = (java_handle_t *) action;
-       c = o->vftbl->class;
+       h = (java_handle_t *) action;
+       LLNI_class_get(h, c);
 
        if (action == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1016,12 +1019,17 @@ jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject contex
        /* XXX It seems something with a privileged stack needs to be done
           here. */
 
-       result = vm_call_method(m, o);
+       result = vm_call_method(m, h);
 
-       e = exceptions_get_and_clear_exception();
+       e = exceptions_get_exception();
 
        if (e != NULL) {
-               exceptions_throw_privilegedactionexception(e);
+               if ( builtin_instanceof(e, class_java_lang_Exception) &&
+                       !builtin_instanceof(e, class_java_lang_RuntimeException)) {
+                       exceptions_clear_exception();
+                       exceptions_throw_privilegedactionexception(e);
+               }
+
                return NULL;
        }
 
@@ -1043,7 +1051,7 @@ jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
 
 jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
 {
-       TRACEJVMCALLS("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls);
+       TRACEJVMCALLS(("JVM_GetStackAccessControlContext(env=%p, cls=%p): IMPLEMENT ME!", env, cls));
 
        /* XXX All stuff I tested so far works without that function.  At
           some point we have to implement it, but I disable the output
@@ -1059,7 +1067,7 @@ jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       TRACEJVMCALLS("JVM_IsArrayClass(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1073,7 +1081,7 @@ jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       TRACEJVMCALLS("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1088,7 +1096,7 @@ jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
        classinfo *component;
        classinfo *c;
        
-       TRACEJVMCALLS("JVM_GetComponentType(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetComponentType(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
        
@@ -1105,7 +1113,7 @@ jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
        classinfo *c;
        int32_t    flags;
 
-       TRACEJVMCALLS("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassModifiers(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1122,7 +1130,7 @@ jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
        classinfo                 *c;
        java_handle_objectarray_t *oa;
 
-       TRACEJVMCALLS("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass);
+       TRACEJVMCALLS(("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass));
 
        c = LLNI_classinfo_unwrap(ofClass);
 
@@ -1139,7 +1147,7 @@ jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
        classinfo *c;
        classinfo *dc;
 
-       TRACEJVMCALLS("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass);
+       TRACEJVMCALLS(("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass));
 
        c = LLNI_classinfo_unwrap(ofClass);
 
@@ -1157,7 +1165,7 @@ jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
        utf           *u;
        java_handle_t *s;
 
-       TRACEJVMCALLS("JVM_GetClassSignature(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassSignature(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1183,7 +1191,7 @@ jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
        classinfo               *c           = NULL; /* classinfo for 'cls'  */
        java_handle_bytearray_t *annotations = NULL; /* unparsed annotations */
 
-       TRACEJVMCALLS("JVM_GetClassAnnotations: cls=%p", cls);
+       TRACEJVMCALLS(("JVM_GetClassAnnotations: cls=%p", cls));
 
        if (cls == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1206,7 +1214,7 @@ jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
        java_lang_reflect_Field *rf = NULL; /* java.lang.reflect.Field for 'field' */
        java_handle_bytearray_t *ba = NULL; /* unparsed annotations */
 
-       TRACEJVMCALLS("JVM_GetFieldAnnotations: field=%p", field);
+       TRACEJVMCALLS(("JVM_GetFieldAnnotations: field=%p", field));
 
        if (field == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1228,7 +1236,7 @@ jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
        java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
        java_handle_bytearray_t  *ba = NULL; /* unparsed annotations */
 
-       TRACEJVMCALLS("JVM_GetMethodAnnotations: method=%p", method);
+       TRACEJVMCALLS(("JVM_GetMethodAnnotations: method=%p", method));
 
        if (method == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1250,7 +1258,7 @@ jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
        java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
        java_handle_bytearray_t  *ba = NULL; /* unparsed annotation default value */
 
-       TRACEJVMCALLS("JVM_GetMethodDefaultAnnotationValue: method=%p", method);
+       TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue: method=%p", method));
 
        if (method == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1272,7 +1280,7 @@ jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
        java_lang_reflect_Method *rm = NULL; /* java.lang.reflect.Method for 'method' */
        java_handle_bytearray_t  *ba = NULL; /* unparsed parameter annotations */
 
-       TRACEJVMCALLS("JVM_GetMethodParameterAnnotations: method=%p", method);
+       TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations: method=%p", method));
 
        if (method == NULL) {
                exceptions_throw_nullpointerexception();
@@ -1291,7 +1299,7 @@ jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
 
 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-       TRACEJVMCALLS("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly);
+       TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
 
        return (jobjectArray) _Jv_java_lang_Class_getDeclaredFields((java_lang_Class *) ofClass, publicOnly);
 }
@@ -1301,7 +1309,7 @@ jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean pu
 
 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-       TRACEJVMCALLS("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly);
+       TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
 
        return (jobjectArray) _Jv_java_lang_Class_getDeclaredMethods((java_lang_Class *) ofClass, publicOnly);
 }
@@ -1311,7 +1319,7 @@ jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean p
 
 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-       TRACEJVMCALLS("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly);
+       TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
 
        return (jobjectArray) _Jv_java_lang_Class_getDeclaredConstructors((java_lang_Class *) ofClass, publicOnly);
 }
@@ -1323,7 +1331,7 @@ jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       TRACEJVMCALLS("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassAccessFlags(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1343,7 +1351,7 @@ jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
        java_lang_Object         *constantPoolOop = (java_lang_Object*)cls;
                      /* constantPoolOop field of the constant pool object   */
 
-       TRACEJVMCALLS("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLS(("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls));
 
        constantPool = 
                (sun_reflect_ConstantPool*)native_new_and_init(
@@ -1370,7 +1378,7 @@ jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
 {
        classinfo *c; /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool));
 
        c = LLNI_classinfo_unwrap(jcpool);
 
@@ -1386,7 +1394,7 @@ jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, j
        classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
        classinfo         *result; /* classinfo of the class at constant pool index 'index' */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index));
 
        c = LLNI_classinfo_unwrap(jcpool);
 
@@ -1411,7 +1419,7 @@ jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject j
        classinfo         *c;      /* classinfo of the class for which 'this' is the constant pool */
        classinfo         *result; /* classinfo of the class at constant pool index 'index' */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index));
 
        c = LLNI_classinfo_unwrap(jcpool);
 
@@ -1441,7 +1449,7 @@ jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool,
        constant_FMIref *ref; /* reference to the method in constant pool at index 'index' */
        classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
        
-       TRACEJVMCALLS("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index));
        
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
@@ -1464,7 +1472,7 @@ jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject
        classinfo *c = NULL;  /* resolved declaring class of the method */
        classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
@@ -1493,7 +1501,7 @@ jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool,
        constant_FMIref *ref; /* reference to the field in constant pool at index 'index' */
        classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
        
-       TRACEJVMCALLS("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
@@ -1515,7 +1523,7 @@ jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject
        classinfo *c;         /* resolved declaring class for the field */
        classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
@@ -1556,7 +1564,7 @@ jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint
        constant_integer *ref; /* reference to the int value in constant pool at index 'index' */
        classinfo *cls;        /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
@@ -1577,7 +1585,7 @@ jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jin
        constant_long *ref; /* reference to the long value in constant pool at index 'index' */
        classinfo *cls;     /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
@@ -1598,7 +1606,7 @@ jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, j
        constant_float *ref; /* reference to the float value in constant pool at index 'index' */
        classinfo *cls;      /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
@@ -1619,7 +1627,7 @@ jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool,
        constant_double *ref; /* reference to the double value in constant pool at index 'index' */
        classinfo *cls;       /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
@@ -1640,7 +1648,7 @@ jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool,
        utf *ref;       /* utf object for the string in constant pool at index 'index' */
        classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index));
        
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
@@ -1662,7 +1670,7 @@ jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, j
        utf *ref; /* utf object for the utf8 data in constant pool at index 'index' */
        classinfo *cls; /* classinfo of the class for which 'this' is the constant pool */
 
-       TRACEJVMCALLS("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index);
+       TRACEJVMCALLS(("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index));
 
        cls = LLNI_classinfo_unwrap(jcpool);
        ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
@@ -1687,7 +1695,7 @@ jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
        jboolean           status;
        utf               *name;
 
-       TRACEJVMCALLS("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls);
+       TRACEJVMCALLS(("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -1736,7 +1744,7 @@ jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
        s4                                     i, j;
 #endif
 
-       TRACEJVMCALLS("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused);
+       TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
 
        c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
 
@@ -2124,7 +2132,7 @@ jint JVM_Open(const char *fname, jint flags, jint mode)
 {
        int result;
 
-       TRACEJVMCALLS("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode);
+       TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
 
        result = system_open(fname, flags, mode);
 
@@ -2146,7 +2154,7 @@ jint JVM_Open(const char *fname, jint flags, jint mode)
 
 jint JVM_Close(jint fd)
 {
-       TRACEJVMCALLS("JVM_Close(fd=%d)", fd);
+       TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
 
        return system_close(fd);
 }
@@ -2156,7 +2164,7 @@ jint JVM_Close(jint fd)
 
 jint JVM_Read(jint fd, char *buf, jint nbytes)
 {
-       TRACEJVMCALLS("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes);
+       TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
 
        return system_read(fd, buf, nbytes);
 }
@@ -2166,7 +2174,7 @@ jint JVM_Read(jint fd, char *buf, jint nbytes)
 
 jint JVM_Write(jint fd, char *buf, jint nbytes)
 {
-       TRACEJVMCALLS("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes);
+       TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
 
        return system_write(fd, buf, nbytes);
 }
@@ -2180,7 +2188,7 @@ jint JVM_Available(jint fd, jlong *pbytes)
        int bytes;
        int result;
 
-       TRACEJVMCALLS("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes);
+       TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
 
        *pbytes = 0;
 
@@ -2202,7 +2210,7 @@ jint JVM_Available(jint fd, jlong *pbytes)
 
 jlong JVM_Lseek(jint fd, jlong offset, jint whence)
 {
-       TRACEJVMCALLS("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence);
+       TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
 
        return (jlong) system_lseek(fd, (off_t) offset, whence);
 }
@@ -2212,7 +2220,7 @@ jlong JVM_Lseek(jint fd, jlong offset, jint whence)
 
 jint JVM_SetLength(jint fd, jlong length)
 {
-       TRACEJVMCALLS("JVM_SetLength(fd=%d, length=%ld)", length);
+       TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
 
        return system_ftruncate(fd, length);
 }
@@ -2222,7 +2230,7 @@ jint JVM_SetLength(jint fd, jlong length)
 
 jint JVM_Sync(jint fd)
 {
-       TRACEJVMCALLS("JVM_Sync(fd=%d)", fd);
+       TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
 
        return system_fsync(fd);
 }
@@ -2232,7 +2240,7 @@ jint JVM_Sync(jint fd)
 
 void JVM_StartThread(JNIEnv* env, jobject jthread)
 {
-       TRACEJVMCALLS("JVM_StartThread(env=%p, jthread=%p)", env, jthread);
+       TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
 
        threads_thread_start((java_handle_t *) jthread);
 }
@@ -2250,20 +2258,14 @@ void JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable)
 
 jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
 {
-       threadobject *t;
-       bool          equal;
-       bool          result;
-
-       TRACEJVMCALLS("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread);
-
-       /* XXX this is just a quick hack */
+       java_handle_t *h;
+       threadobject  *t;
+       bool           result;
 
-       for (t = threadlist_first(); t != NULL; t = threadlist_next(t)) {
-               LLNI_equals(t->object, jthread, equal);
+       TRACEJVMCALLS(("JVM_IsThreadAlive(env=%p, jthread=%p)", env, jthread));
 
-               if (equal == true)
-                       break;
-       }
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
 
        /* The threadobject is null when a thread is created in Java. The
           priority is set later during startup. */
@@ -2300,16 +2302,10 @@ void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
        java_handle_t *h;
        threadobject  *t;
 
-       TRACEJVMCALLS("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio);
+       TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
 
        h = (java_handle_t *) jthread;
-
-       /* XXX this is just a quick hack */
-
-       for (t = threadlist_first(); t != NULL; t = threadlist_next(t)) {
-               if (t->object == h)
-                       break;
-       }
+       t = thread_get_thread(h);
 
        /* The threadobject is null when a thread is created in Java. The
           priority is set later during startup. */
@@ -2325,7 +2321,7 @@ void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
 
 void JVM_Yield(JNIEnv *env, jclass threadClass)
 {
-       TRACEJVMCALLS("JVM_Yield(env=%p, threadClass=%p)", env, threadClass);
+       TRACEJVMCALLS(("JVM_Yield(env=%p, threadClass=%p)", env, threadClass));
 
        threads_yield();
 }
@@ -2335,7 +2331,7 @@ void JVM_Yield(JNIEnv *env, jclass threadClass)
 
 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
 {
-       TRACEJVMCALLS("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis);
+       TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
 
        threads_sleep(millis, 0);
 }
@@ -2369,7 +2365,18 @@ jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
 
 void JVM_Interrupt(JNIEnv* env, jobject jthread)
 {
-       log_println("JVM_Interrupt: IMPLEMENT ME!");
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_Interrupt(env=%p, jthread=%p)", env, jthread));
+
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
+
+       if (t == NULL)
+               return;
+
+       threads_thread_interrupt(t);
 }
 
 
@@ -2380,19 +2387,13 @@ jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrup
        java_handle_t *h;
        threadobject  *t;
 
-       TRACEJVMCALLS("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted);
+       TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
 
        h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
 
        /* XXX do something with clear_interrupted */
 
-       /* XXX this is just a quick hack */
-
-       for (t = threadlist_first(); t != NULL; t = threadlist_next(t)) {
-               if (t->object == h)
-                       break;
-       }
-
        return threads_thread_has_been_interrupted(t);
 }
 
@@ -2404,7 +2405,7 @@ jboolean JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj)
        java_handle_t *h;
        bool           result;
 
-       TRACEJVMCALLS("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj);
+       TRACEJVMCALLS(("JVM_HoldsLock(env=%p, threadClass=%p, obj=%p)", env, threadClass, obj));
 
        h = (java_handle_t *) obj;
 
@@ -2454,7 +2455,7 @@ jobject JVM_CurrentClassLoader(JNIEnv *env)
 
 jobjectArray JVM_GetClassContext(JNIEnv *env)
 {
-       TRACEJVMCALLS("JVM_GetClassContext(env=%p)", env);
+       TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
 
        return (jobjectArray) stacktrace_getClassContext();
 }
@@ -2488,7 +2489,7 @@ jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
        utf *u;
        utf *result;
 
-       TRACEJVMCALLS("JVM_GetSystemPackage(env=%p, name=%p)", env, name);
+       TRACEJVMCALLS(("JVM_GetSystemPackage(env=%p, name=%p)", env, name));
 
 /*     s = package_find(name); */
        u = javastring_toutf((java_handle_t *) name, false);
@@ -2540,7 +2541,7 @@ jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
 {
        classloader *cl;
 
-       TRACEJVMCALLS("JVM_LatestUserDefinedLoader(env=%p)", env);
+       TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
 
        cl = stacktrace_first_nonnull_classloader();
 
@@ -2564,7 +2565,7 @@ jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
 {
        java_handle_t *a;
 
-       TRACEJVMCALLS("JVM_GetArrayLength(arr=%p)", arr);
+       TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
 
        a = (java_handle_t *) arr;
 
@@ -2579,7 +2580,7 @@ jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
        java_handle_t *a;
        java_handle_t *o;
 
-       TRACEJVMCALLS("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index);
+       TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
 
        a = (java_handle_t *) arr;
 
@@ -2615,7 +2616,7 @@ void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
        java_handle_t *a;
        java_handle_t *value;
 
-       TRACEJVMCALLS("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val);
+       TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
 
        a     = (java_handle_t *) arr;
        value = (java_handle_t *) val;
@@ -2641,7 +2642,7 @@ jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
        java_handle_t             *a;
        java_handle_objectarray_t *oa;
 
-       TRACEJVMCALLS("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length);
+       TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
 
        if (eltClass == NULL) {
                exceptions_throw_nullpointerexception();
@@ -2652,10 +2653,18 @@ jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
 
        c = LLNI_classinfo_unwrap(eltClass);
 
-       /* create primitive or object array */
+       /* Create primitive or object array. */
 
        if (class_is_primitive(c)) {
                pc = primitive_arrayclass_get_by_name(c->name);
+
+               /* void arrays are not allowed. */
+
+               if (pc == NULL) {
+                       exceptions_throw_illegalargumentexception();
+                       return NULL;
+               }
+
                a = builtin_newarray(length, pc);
 
                return (jobject) a;
@@ -2681,7 +2690,7 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
        classinfo                 *ac;
        java_handle_objectarray_t *a;
 
-       TRACEJVMCALLS("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim);
+       TRACEJVMCALLS(("JVM_NewMultiArray(env=%p, eltClass=%p, dim=%p)", env, eltClass, dim));
 
        if (eltClass == NULL) {
                exceptions_throw_nullpointerexception();
@@ -2692,12 +2701,24 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
 
        c = LLNI_classinfo_unwrap(eltClass);
 
-       /* XXX This is just a quick hack to get it working. */
-
        ia = (java_handle_intarray_t *) dim;
 
        length = array_length_get((java_handle_t *) ia);
 
+       /* We check here for exceptions thrown in array_length_get,
+          otherwise these exceptions get overwritten by the following
+          IllegalArgumentException. */
+
+       if (length < 0)
+               return NULL;
+
+       if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
+               exceptions_throw_illegalargumentexception();
+               return NULL;
+       }
+
+       /* XXX This is just a quick hack to get it working. */
+
        dims = MNEW(long, length);
 
        for (i = 0; i < length; i++) {
@@ -2735,7 +2756,7 @@ jint JVM_InitializeSocketLibrary()
 
 jint JVM_Socket(jint domain, jint type, jint protocol)
 {
-       TRACEJVMCALLS("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol);
+       TRACEJVMCALLS(("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol));
 
        return system_socket(domain, type, protocol);
 }
@@ -2745,7 +2766,7 @@ jint JVM_Socket(jint domain, jint type, jint protocol)
 
 jint JVM_SocketClose(jint fd)
 {
-       TRACEJVMCALLS("JVM_SocketClose(fd=%d)", fd);
+       TRACEJVMCALLS(("JVM_SocketClose(fd=%d)", fd));
 
        return system_close(fd);
 }
@@ -2755,7 +2776,7 @@ jint JVM_SocketClose(jint fd)
 
 jint JVM_SocketShutdown(jint fd, jint howto)
 {
-       TRACEJVMCALLS("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto);
+       TRACEJVMCALLS(("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto));
 
        return system_shutdown(fd, howto);
 }
@@ -2795,7 +2816,7 @@ jint JVM_Timeout(int fd, long timeout)
 
 jint JVM_Listen(jint fd, jint count)
 {
-       TRACEJVMCALLS("JVM_Listen(fd=%d, count=%d)", fd, count);
+       TRACEJVMCALLS(("JVM_Listen(fd=%d, count=%d)", fd, count));
 
        return system_listen(fd, count);
 }
@@ -2805,7 +2826,7 @@ jint JVM_Listen(jint fd, jint count)
 
 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
 {
-       TRACEJVMCALLS("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len);
+       TRACEJVMCALLS(("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len));
 
        return system_connect(fd, him, len);
 }
@@ -2825,7 +2846,7 @@ jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
 
 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
 {
-       TRACEJVMCALLS("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len);
+       TRACEJVMCALLS(("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len));
 
        return system_accept(fd, him, (socklen_t *) len);
 }
@@ -2845,7 +2866,7 @@ jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *fr
 
 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
 {
-       TRACEJVMCALLS("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len);
+       TRACEJVMCALLS(("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len));
 
        return system_getsockname(fd, him, (socklen_t *) len);
 }
@@ -2869,7 +2890,7 @@ jint JVM_SocketAvailable(jint fd, jint *pbytes)
        int bytes;
        int result;
 
-       TRACEJVMCALLS("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes);
+       TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
 
        *pbytes = 0;
 
@@ -2891,7 +2912,7 @@ jint JVM_SocketAvailable(jint fd, jint *pbytes)
 
 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
 {
-       TRACEJVMCALLS("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen);
+       TRACEJVMCALLS(("JVM_GetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%p)", fd, level, optname, optval, optlen));
 
        return system_getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
 }
@@ -2901,7 +2922,7 @@ jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
 
 jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)
 {
-       TRACEJVMCALLS("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen);
+       TRACEJVMCALLS(("JVM_SetSockOpt(fd=%d, level=%d, optname=%d, optval=%s, optlen=%d)", fd, level, optname, optval, optlen));
 
        return system_setsockopt(fd, level, optname, optval, optlen);
 }
@@ -2911,7 +2932,7 @@ jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int opt
 
 int JVM_GetHostName(char *name, int namelen)
 {
-       TRACEJVMCALLS("JVM_GetHostName(name=%s, namelen=%d)", name, namelen);
+       TRACEJVMCALLS(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
 
        return system_gethostname(name, namelen);
 }
@@ -2953,7 +2974,7 @@ void *JVM_LoadLibrary(const char *name)
 {
        utf *u;
 
-       TRACEJVMCALLS("JVM_LoadLibrary(name=%s)", name);
+       TRACEJVMCALLS(("JVM_LoadLibrary(name=%s)", name));
 
        u = utf_new_char(name);
 
@@ -2965,7 +2986,7 @@ void *JVM_LoadLibrary(const char *name)
 
 void JVM_UnloadLibrary(void* handle)
 {
-       TRACEJVMCALLS("JVM_UnloadLibrary(handle=%p)", handle);
+       TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
 
        native_library_close(handle);
 }
@@ -2977,7 +2998,7 @@ void *JVM_FindLibraryEntry(void *handle, const char *name)
 {
        lt_ptr symbol;
 
-       TRACEJVMCALLS("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name);
+       TRACEJVMCALLS(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
 
        symbol = lt_dlsym(handle, name);
 
@@ -2999,7 +3020,7 @@ jboolean JVM_IsNaN(jdouble a)
 
 jboolean JVM_IsSupportedJNIVersion(jint version)
 {
-       TRACEJVMCALLS("JVM_IsSupportedJNIVersion(version=%d)", version);
+       TRACEJVMCALLS(("JVM_IsSupportedJNIVersion(version=%d)", version));
 
        return jni_version_check(version);
 }
@@ -3009,7 +3030,7 @@ jboolean JVM_IsSupportedJNIVersion(jint version)
 
 jstring JVM_InternString(JNIEnv *env, jstring str)
 {
-       TRACEJVMCALLS("JVM_InternString(env=%p, str=%p)", env, str);
+       TRACEJVMCALLS(("JVM_InternString(env=%p, str=%p)", env, str));
 
        return (jstring) javastring_intern((java_handle_t *) str);
 }
@@ -3021,7 +3042,7 @@ JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 {
        java_object_t *o;
 
-       TRACEJVMCALLS("JVM_RawMonitorCreate()");
+       TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
 
        o = NEW(java_object_t);
 
@@ -3035,7 +3056,7 @@ JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 
 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
 {
-       TRACEJVMCALLS("JVM_RawMonitorDestroy(mon=%p)", mon);
+       TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
 
        FREE(mon, java_object_t);
 }
@@ -3045,7 +3066,7 @@ JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
 
 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 {
-       TRACEJVMCALLS("JVM_RawMonitorEnter(mon=%p)", mon);
+       TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
 
        (void) lock_monitor_enter((java_object_t *) mon);
 
@@ -3057,7 +3078,7 @@ JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 
 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
 {
-       TRACEJVMCALLS("JVM_RawMonitorExit(mon=%p)", mon);
+       TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
 
        (void) lock_monitor_exit((java_object_t *) mon);
 }
@@ -3221,7 +3242,7 @@ void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, un
 
 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
 {
-       TRACEJVMCALLS("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0);
+       TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
 
        return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
 }
@@ -3231,7 +3252,7 @@ jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray
 
 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)
 {
-       TRACEJVMCALLS("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, c, args0);
+       TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, c, args0));
 
        return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
 }
@@ -3241,7 +3262,7 @@ jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args
 
 jboolean JVM_SupportsCX8()
 {
-       TRACEJVMCALLS("JVM_SupportsCX8()");
+       TRACEJVMCALLS(("JVM_SupportsCX8()"));
 
        /* IMPLEMENT ME */
 
@@ -3283,7 +3304,7 @@ jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threa
 
 void *JVM_GetManagement(jint version)
 {
-       TRACEJVMCALLS("JVM_GetManagement(version=%d)", version);
+       TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
 
        /* TODO We current don't support the management interface. */
 
@@ -3309,7 +3330,7 @@ jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
        methodinfo                *m;
        java_handle_objectarray_t *oa;
 
-       TRACEJVMCALLS("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass);
+       TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
 
        c = LLNI_classinfo_unwrap(ofClass);
 
@@ -3340,8 +3361,8 @@ jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
 {
        java_handle_intarray_t *ia;
 
-       TRACEJVMCALLS("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
-                                 env, javaThreadState);
+       TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
+                                 env, javaThreadState));
 
        /* If new thread states are added in future JDK and VM versions,
           this should check if the JDK version is compatible with thread
@@ -3428,8 +3449,8 @@ jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArra
        java_handle_objectarray_t *oa;
        java_object_t             *s;
 
-       TRACEJVMCALLS("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
-                                 env, javaThreadState, values);
+       TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
+                                 env, javaThreadState, values));
 
        ia = (java_handle_intarray_t *) values;
 
@@ -3561,7 +3582,7 @@ void *JVM_RegisterSignal(jint sig, void *handler)
 {
        functionptr newHandler;
 
-       TRACEJVMCALLS("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler);
+       TRACEJVMCALLS(("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler));
 
        if (handler == (void *) 2)
                newHandler = (functionptr) signal_thread_handler;
@@ -3612,7 +3633,7 @@ jboolean JVM_RaiseSignal(jint sig)
 
 jint JVM_FindSignal(const char *name)
 {
-       TRACEJVMCALLS("JVM_FindSignal(name=%s)", name);
+       TRACEJVMCALLS(("JVM_FindSignal(name=%s)", name));
 
 #if defined(__LINUX__)
        if (strcmp(name, "HUP") == 0)