* src/native/vm/sun/jvm.c (JVM_GetEnclosingMethodInfo): Use
[cacao.git] / src / native / vm / sun / jvm.c
index 8f71b4e76a567d54e2e59b1699957979d9c5b8ee..be21f58c99e757cc1bac5661886ff18fc717d2d6 100644 (file)
@@ -1,9 +1,7 @@
 /* src/native/vm/sun/jvm.c - HotSpot JVM interface functions
 
-   Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
-   C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
-   E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
-   J. Wenninger, Institut f. Computersprachen - TU Wien
+   Copyright (C) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 */
 
 
-#define PRINTJVM 0
-
 #include "config.h"
 
 #include <assert.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <ltdl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include "native/include/java_lang_StackTraceElement.h"
 #include "native/include/java_lang_Throwable.h"
 #include "native/include/java_security_ProtectionDomain.h"
-#include "native/include/java_lang_Integer.h"
-#include "native/include/java_lang_Long.h"
-#include "native/include/java_lang_Short.h"
-#include "native/include/java_lang_Byte.h"
-#include "native/include/java_lang_Character.h"
-#include "native/include/java_lang_Boolean.h"
-#include "native/include/java_lang_Float.h"
-#include "native/include/java_lang_Double.h"
 
 #if defined(ENABLE_ANNOTATIONS)
 #include "native/include/sun_reflect_ConstantPool.h"
 #endif
 
-#include "native/vm/java_lang_Class.h"
-#include "native/vm/java_lang_ClassLoader.h"
-#include "native/vm/java_lang_Runtime.h"
-#include "native/vm/java_lang_Thread.h"
-#include "native/vm/java_lang_reflect_Constructor.h"
-#include "native/vm/java_lang_reflect_Method.h"
 #include "native/vm/reflect.h"
 
+#include "native/vm/sun/hpi.h"
+
 #include "threads/lock-common.h"
-#include "threads/threads-common.h"
+#include "threads/thread.h"
 
 #include "toolbox/logging.h"
 #include "toolbox/list.h"
 
 #if !defined(NDEBUG)
 
-# define TRACEJVMCALLS(...)                                            \
+# define TRACEJVMCALLS(x)                                                                              \
+    do {                                                                                                               \
+        if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {   \
+            log_println x;                                                                             \
+        }                                                                                                              \
+    } while (0)
+
+# define TRACEJVMCALLSENTER(x)                                                                 \
+    do {                                                                                                               \
+        if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {   \
+                       log_start();                                                                            \
+            log_print x;                                                                               \
+        }                                                                                                              \
+    } while (0)
+
+# define TRACEJVMCALLSEXIT(x)                                                                  \
+    do {                                                                                                               \
+        if (opt_TraceJVMCalls || opt_TraceJVMCallsVerbose) {   \
+                       log_print x;                                                                            \
+                       log_finish();                                                                           \
+        }                                                                                                              \
+    } while (0)
+
+# define TRACEJVMCALLSVERBOSE(x)                               \
     do {                                                                               \
-        if (opt_TraceJVMCalls) {                               \
-            log_println(__VA_ARGS__);                  \
+        if (opt_TraceJVMCallsVerbose) {                        \
+            log_println 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 PRINTJVMWARNINGS(...)
+# define TRACEJVMCALLS(x)
+# define TRACEJVMCALLSENTER(x)
+# define TRACEJVMCALLSEXIT(x)
+# define TRACEJVMCALLSVERBOSE(x)
+# define PRINTJVMWARNINGS(x)
 
 #endif
 
@@ -199,18 +208,24 @@ int jio_snprintf(char *str, size_t count, const char *fmt, ...)
 int jio_fprintf(FILE* f, const char *fmt, ...)
 {
        log_println("jio_fprintf: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
 int jio_vfprintf(FILE* f, const char *fmt, va_list args)
 {
        log_println("jio_vfprintf: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
 int jio_printf(const char *fmt, ...)
 {
        log_println("jio_printf: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -230,9 +245,8 @@ jint JVM_GetInterfaceVersion()
 
 jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
 {
-#if PRINTJVM
-       log_println("JVM_CurrentTimeMillis");
-#endif
+       TRACEJVMCALLS(("JVM_CurrentTimeMillis(env=%p, ignored=%p)", env, ignored));
+
        return (jlong) builtin_currenttimemillis();
 }
 
@@ -241,9 +255,8 @@ jlong JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored)
 
 jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
 {
-#if PRINTJVM
-       log_println("JVM_NanoTime");
-#endif
+       TRACEJVMCALLS(("JVM_NanoTime(env=%p, ignored=%p)", env, ignored));
+
        return (jlong) builtin_nanotime();
 }
 
@@ -258,9 +271,7 @@ void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobje
        s = (java_handle_t *) src;
        d = (java_handle_t *) dst;
 
-#if PRINTJVM
-       log_println("JVM_ArrayCopy: src=%p, src_pos=%d, dst=%p, dst_pos=%d, length=%d", src, src_pos, dst, dst_pos, length);
-#endif
+       TRACEJVMCALLSVERBOSE(("JVM_ArrayCopy(env=%p, ignored=%p, src=%p, src_pos=%d, dst=%p, dst_pos=%d, length=%d)", env, ignored, src, src_pos, dst, dst_pos, length));
 
        builtin_arraycopy(s, src_pos, d, dst_pos, length);
 }
@@ -271,11 +282,22 @@ void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobje
 jobject JVM_InitProperties(JNIEnv *env, jobject properties)
 {
        java_handle_t *h;
+       char           buf[256];
 
-       TRACEJVMCALLS("JVM_InitProperties(env=%p, properties=%p)", env, properties);
+       TRACEJVMCALLS(("JVM_InitProperties(env=%p, properties=%p)", env, properties));
 
        h = (java_handle_t *) properties;
 
+       /* Convert the -XX:MaxDirectMemorySize= command line flag to the
+          sun.nio.MaxDirectMemorySize property.  Do this after setting
+          user properties to prevent people from setting the value with a
+          -D option, as requested. */
+
+       jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
+       properties_add("sun.nio.MaxDirectMemorySize", buf);
+
+       /* Add all properties. */
+
        properties_system_add_all(h);
 
        return properties;
@@ -294,9 +316,8 @@ void JVM_Exit(jint code)
 
 void JVM_Halt(jint code)
 {
-#if PRINTJVM
-       log_println("JVM_Halt: code=%d", code);
-#endif
+       TRACEJVMCALLS(("JVM_Halt(code=%d)", code));
+
 /*     vm_exit(code); */
        vm_shutdown(code);
 }
@@ -314,7 +335,7 @@ void JVM_OnExit(void (*func)(void))
 
 void JVM_GC(void)
 {
-       TRACEJVMCALLS("JVM_GC()");
+       TRACEJVMCALLS(("JVM_GC()"));
 
        gc_call();
 }
@@ -325,6 +346,8 @@ void JVM_GC(void)
 jlong JVM_MaxObjectInspectionAge(void)
 {
        log_println("JVM_MaxObjectInspectionAge: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -348,7 +371,7 @@ void JVM_TraceMethodCalls(jboolean on)
 
 jlong JVM_TotalMemory(void)
 {
-       TRACEJVMCALLS("JVM_TotalMemory()");
+       TRACEJVMCALLS(("JVM_TotalMemory()"));
 
        return gc_get_heap_size();
 }
@@ -358,7 +381,7 @@ jlong JVM_TotalMemory(void)
 
 jlong JVM_FreeMemory(void)
 {
-       TRACEJVMCALLS("JVM_FreeMemory()");
+       TRACEJVMCALLS(("JVM_FreeMemory()"));
 
        return gc_get_free_bytes();
 }
@@ -368,7 +391,7 @@ jlong JVM_FreeMemory(void)
 
 jlong JVM_MaxMemory(void)
 {
-       TRACEJVMCALLS("JVM_MaxMemory()");
+       TRACEJVMCALLS(("JVM_MaxMemory()"));
 
        return gc_get_max_heap_size();
 }
@@ -378,7 +401,7 @@ jlong JVM_MaxMemory(void)
 
 jint JVM_ActiveProcessorCount(void)
 {
-       TRACEJVMCALLS("JVM_ActiveProcessorCount()");
+       TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
 
        return system_processors_online();
 }
@@ -391,16 +414,16 @@ 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;
 
-       ba = stacktrace_fillInStackTrace();
+       ba = stacktrace_get_current();
 
        if (ba == NULL)
                return;
 
-       o->backtrace = (java_lang_Object *) ba;
+       LLNI_field_set_ref(o, backtrace, (java_lang_Object *) ba);
 }
 
 
@@ -416,26 +439,40 @@ void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
 
 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
 {
-       java_lang_Throwable     *o;
+       java_lang_Throwable     *to;
+       java_lang_Object        *o;
        java_handle_bytearray_t *ba;
-       stacktracebuffer        *stb;
+       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;
        }
 
-       o   = (java_lang_Throwable *) throwable;
-       ba  = (java_handle_bytearray_t *) o->backtrace;
+       to = (java_lang_Throwable *) throwable;
+
+       LLNI_field_get_ref(to, backtrace, o);
+
+       ba = (java_handle_bytearray_t *) o;
 
        if (ba == NULL)
                return 0;
 
-       stb = (stacktracebuffer *) LLNI_array_data(ba);
+       /* We need a critical section here as the stacktrace structure is
+          mapped onto a Java byte-array. */
+
+       LLNI_CRITICAL_START;
+
+       st = (stacktrace_t *) LLNI_array_data(ba);
+
+       depth = st->length;
+
+       LLNI_CRITICAL_END;
 
-       return stb->used;
+       return depth;
 }
 
 
@@ -443,22 +480,32 @@ 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;
-       stacktracebuffer            *stb;
-       stacktrace_entry            *ste;
-       java_lang_StackTraceElement *o;
-       java_lang_String            *declaringclass;
+       stacktrace_t                *st;
+       stacktrace_entry_t          *ste;
+       codeinfo                    *code;
+       methodinfo                  *m;
+       classinfo                   *c;
+       java_lang_StackTraceElement *steo;
+       java_handle_t*               declaringclass;
        java_lang_String            *filename;
-       s4                           linenumber;
+       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));
 
-       t   = (java_lang_Throwable *) throwable;
-       ba  = (java_handle_bytearray_t *) t->backtrace;
-       stb = (stacktracebuffer *) LLNI_array_data(ba);
+       to = (java_lang_Throwable *) throwable;
 
-       if ((index < 0) || (index >= stb->used)) {
+       LLNI_field_get_ref(to, backtrace, o);
+
+       ba = (java_handle_bytearray_t *) o;
+
+       /* FIXME critical section */
+
+       st = (stacktrace_t *) LLNI_array_data(ba);
+
+       if ((index < 0) || (index >= st->length)) {
                /* XXX This should be an IndexOutOfBoundsException (check this
                   again). */
 
@@ -466,21 +513,29 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
                return NULL;
        }
 
-       ste = &(stb->entries[index]);
+       /* Get the stacktrace entry. */
+
+       ste = &(st->entries[index]);
+
+       /* Get the codeinfo, methodinfo and classinfo. */
+
+       code = ste->code;
+       m    = code->m;
+       c    = m->clazz;
 
        /* 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 */
 
-       if (!(ste->method->flags & ACC_NATIVE)) {
-               if (ste->method->class->sourcefile)
-                       filename = (java_lang_String *) javastring_new(ste->method->class->sourcefile);
+       if (!(m->flags & ACC_NATIVE)) {
+               if (c->sourcefile != NULL)
+                       filename = (java_lang_String *) javastring_new(c->sourcefile);
                else
                        filename = NULL;
        }
@@ -489,24 +544,31 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
        /* get line number */
 
-       if (ste->method->flags & ACC_NATIVE)
+       if (m->flags & ACC_NATIVE) {
                linenumber = -2;
-       else
-               linenumber = (ste->linenumber == 0) ? -1 : ste->linenumber;
+       }
+       else {
+               /* FIXME The linenumbertable_linenumber_for_pc could change
+                  the methodinfo pointer when hitting an inlined method. */
+
+               linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
+               linenumber = (linenumber == 0) ? -1 : linenumber;
+       }
 
        /* get declaring class name */
 
-       declaringclass =
-               _Jv_java_lang_Class_getName(LLNI_classinfo_wrap(ste->method->class));
+       declaringclass = class_get_classname(c);
 
        /* fill the java.lang.StackTraceElement element */
 
-       o->declaringClass = declaringclass;
-       o->methodName     = (java_lang_String *) javastring_new(ste->method->name);
-       o->fileName       = filename;
-       o->lineNumber     = linenumber;
+       /* FIXME critical section */
 
-       return (jobject) o;
+       steo->declaringClass = (java_lang_String*) declaringclass;
+       steo->methodName     = (java_lang_String*) javastring_new(m->name);
+       steo->fileName       = filename;
+       steo->lineNumber     = linenumber;
+
+       return (jobject) steo;
 }
 
 
@@ -514,7 +576,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);
 }
@@ -528,7 +590,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();
@@ -551,7 +613,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;
@@ -569,7 +631,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;
@@ -583,9 +645,8 @@ void JVM_MonitorNotifyAll(JNIEnv* env, jobject handle)
 
 jobject JVM_Clone(JNIEnv* env, jobject handle)
 {
-#if PRINTJVM
-       log_println("JVM_Clone: handle=%p", handle);
-#endif
+       TRACEJVMCALLS(("JVM_Clone(env=%p, handle=%p)", env, handle));
+
        return (jobject) builtin_clone(env, (java_handle_t *) handle);
 }
 
@@ -603,6 +664,8 @@ void JVM_InitializeCompiler (JNIEnv *env, jclass compCls)
 jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
 {
        log_println("JVM_IsSilentCompiler: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -611,6 +674,8 @@ jboolean JVM_IsSilentCompiler(JNIEnv *env, jclass compCls)
 jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
 {
        log_println("JVM_CompileClass: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -619,6 +684,8 @@ jboolean JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls)
 jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
 {
        log_println("JVM_CompileClasses: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -627,6 +694,8 @@ jboolean JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname)
 jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
 {
        log_println("JVM_CompilerCommand: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -634,8 +703,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"));
 }
 
 
@@ -643,8 +712,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"));
 }
 
 
@@ -652,25 +721,9 @@ void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
 
 jint JVM_GetLastErrorString(char *buf, int len)
 {
-       const char *s;
-       int n;
+       TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
 
-    if (errno == 0) {
-               return 0;
-    }
-       else {
-               s = strerror(errno);
-               n = strlen(s);
-
-               if (n >= len)
-                       n = len - 1;
-
-               strncpy(buf, s, n);
-
-               buf[n] = '\0';
-
-               return n;
-    }
+       return hpi_system->GetLastErrorString(buf, len);
 }
 
 
@@ -678,11 +731,9 @@ jint JVM_GetLastErrorString(char *buf, int len)
 
 char *JVM_NativePath(char *path)
 {
-       TRACEJVMCALLS("JVM_NativePath(path=%s)", path);
-
-       /* XXX is this correct? */
+       TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
 
-       return path;
+       return hpi_file->NativePath(path);
 }
 
 
@@ -690,20 +741,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);
+       classinfo *c;
 
-       oa = stacktrace_getClassContext();
+       TRACEJVMCALLS(("JVM_GetCallerClass(env=%p, depth=%d)", env, depth));
 
-       if (oa == NULL)
-               return NULL;
-
-       if (oa->header.size < depth)
-               return NULL;
-
-       return (jclass) oa->data[depth - 1];
+       c = stacktrace_get_caller_class(depth);
 
+       return (jclass) c;
 }
 
 
@@ -714,7 +758,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);
@@ -727,8 +771,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"));
 }
 
 
@@ -736,11 +780,16 @@ void JVM_ResolveClass(JNIEnv* env, jclass cls)
 
 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
 {
-       classinfo   *c;
-       utf         *u;
-       classloader *cl;
+       classinfo     *c;
+       utf           *u;
+       classloader_t *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);
@@ -764,6 +813,8 @@ jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init
 jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jclass from)
 {
        log_println("JVM_FindClassFromClass: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -772,6 +823,8 @@ jclass JVM_FindClassFromClass(JNIEnv *env, const char *name, jboolean init, jcla
 jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd)
 {
        log_println("JVM_DefineClass: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -779,11 +832,11 @@ jclass JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyt
 
 jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source)
 {
-       classinfo   *c;
-       utf         *u;
-       classloader *cl;
+       classinfo     *c;
+       utf           *u;
+       classloader_t *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);
@@ -794,7 +847,7 @@ jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
 
        /* XXX do something with source */
 
-       c = class_define(u, cl, len, (const uint8_t *) buf, (java_handle_t *) pd);
+       c = class_define(u, cl, len, (uint8_t *) buf, (java_handle_t *) pd);
 
        return (jclass) LLNI_classinfo_wrap(c);
 }
@@ -804,11 +857,11 @@ jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
 
 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
 {
-       classloader *cl;
-       utf         *u;
-       classinfo   *c;
+       classloader_t *cl;
+       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);
 
@@ -823,10 +876,13 @@ jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
 
 jstring JVM_GetClassName(JNIEnv *env, jclass cls)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassName: cls=%p", cls);
-#endif
-       return (jstring) _Jv_java_lang_Class_getName((java_lang_Class *) cls);
+       classinfo* c;
+
+       TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
+
+       c = LLNI_classinfo_unwrap(cls);
+
+       return (jstring) class_get_classname(c);
 }
 
 
@@ -837,7 +893,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);
 
@@ -851,14 +907,16 @@ jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
 
 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
 {
-       classinfo   *c;
-       classloader *cl;
+       classinfo     *c;
+       classloader_t *cl;
 
-       TRACEJVMCALLS("JVM_GetClassLoader(env=%p, cls=%p)", env, cls);
+       TRACEJVMCALLSENTER(("JVM_GetClassLoader(env=%p, cls=%p)", env, cls));
 
        c  = LLNI_classinfo_unwrap(cls);
        cl = class_get_classloader(c);
 
+       TRACEJVMCALLSEXIT(("->%p", cl));
+
        return (jobject) cl;
 }
 
@@ -869,9 +927,7 @@ jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-#if PRINTJVM
-       log_println("JVM_IsInterface: cls=%p", cls);
-#endif
+       TRACEJVMCALLS(("JVM_IsInterface(env=%p, cls=%p)", env, cls));
 
        c = LLNI_classinfo_unwrap(cls);
 
@@ -884,6 +940,8 @@ jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
 jobjectArray JVM_GetClassSigners(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetClassSigners: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -894,7 +952,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);
 
@@ -918,7 +976,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);
 
@@ -948,18 +1006,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;
 
-#if PRINTJVM
-       log_println("JVM_DoPrivileged: action=%p, context=%p, wrapException=%d", action, context, wrapException);
-#endif
+       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();
@@ -979,12 +1035,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;
        }
 
@@ -997,6 +1058,8 @@ jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject contex
 jobject JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetInheritedAccessControlContext: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -1004,7 +1067,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
@@ -1018,10 +1081,13 @@ jobject JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls)
 
 jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
 {
-#if PRINTJVM
-       log_println("JVM_IsArrayClass: cls=%p", cls);
-#endif
-       return class_is_array(LLNI_classinfo_unwrap(cls));
+       classinfo *c;
+
+       TRACEJVMCALLS(("JVM_IsArrayClass(env=%p, cls=%p)", env, cls));
+
+       c = LLNI_classinfo_unwrap(cls);
+
+       return class_is_array(c);
 }
 
 
@@ -1031,11 +1097,9 @@ jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       c = LLNI_classinfo_unwrap(cls);
+       TRACEJVMCALLS(("JVM_IsPrimitiveClass(env=%p, cls=%p)", env, cls));
 
-#if PRINTJVM
-       log_println("JVM_IsPrimitiveClass(cls=%p)", cls);
-#endif
+       c = LLNI_classinfo_unwrap(cls);
 
        return class_is_primitive(c);
 }
@@ -1048,7 +1112,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);
        
@@ -1065,7 +1129,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);
 
@@ -1082,7 +1146,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);
 
@@ -1099,7 +1163,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);
 
@@ -1117,7 +1181,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);
 
@@ -1143,7 +1207,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();
@@ -1166,7 +1230,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();
@@ -1188,7 +1252,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();
@@ -1210,7 +1274,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();
@@ -1232,7 +1296,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();
@@ -1251,10 +1315,16 @@ jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
 
 jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassDeclaredFields: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
-#endif
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredFields((java_lang_Class *) ofClass, publicOnly);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredfields(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1262,10 +1332,16 @@ jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean pu
 
 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassDeclaredMethods: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
-#endif
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredMethods((java_lang_Class *) ofClass, publicOnly);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredmethods(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1273,10 +1349,16 @@ jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean p
 
 jobjectArray JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassDeclaredConstructors: ofClass=%p, publicOnly=%d", ofClass, publicOnly);
-#endif
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredConstructors((java_lang_Class *) ofClass, publicOnly);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredconstructors(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1286,7 +1368,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);
 
@@ -1306,7 +1388,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(
@@ -1333,7 +1415,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);
 
@@ -1349,7 +1431,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);
 
@@ -1374,7 +1456,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);
 
@@ -1404,7 +1486,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);
@@ -1427,7 +1509,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);
@@ -1456,7 +1538,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);
@@ -1478,7 +1560,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);
@@ -1519,7 +1601,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);
@@ -1540,7 +1622,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);
@@ -1561,7 +1643,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);
@@ -1582,7 +1664,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);
@@ -1603,7 +1685,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);
@@ -1625,7 +1707,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);
@@ -1650,7 +1732,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);
 
@@ -1699,7 +1781,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"));
 
@@ -1786,9 +1868,11 @@ jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
 
 /* JVM_GetClassNameUTF */
 
-const charJVM_GetClassNameUTF(JNIEnv *env, jclass cls)
+const char *JVM_GetClassNameUTF(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetClassNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -1805,6 +1889,8 @@ void JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types)
 jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetClassCPEntriesCount: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1813,6 +1899,8 @@ jint JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls)
 jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetClassFieldsCount: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1821,6 +1909,8 @@ jint JVM_GetClassFieldsCount(JNIEnv *env, jclass cls)
 jint JVM_GetClassMethodsCount(JNIEnv *env, jclass cls)
 {
        log_println("JVM_GetClassMethodsCount: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1837,6 +1927,8 @@ void JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index,
 jint JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index)
 {
        log_println("JVM_GetMethodIxExceptionsCount: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1853,6 +1945,8 @@ void JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigne
 jint JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index)
 {
        log_println("JVM_GetMethodIxByteCodeLength: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1869,6 +1963,8 @@ void JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_ind
 jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_GetMethodIxExceptionTableLength: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1877,6 +1973,8 @@ jint JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_ind
 jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_GetMethodIxModifiers: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1885,6 +1983,8 @@ jint JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index)
 jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
 {
        log_println("JVM_GetFieldIxModifiers: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1893,6 +1993,8 @@ jint JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index)
 jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_GetMethodIxLocalsCount: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1901,6 +2003,8 @@ jint JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index)
 jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_GetMethodIxArgsSize: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1909,6 +2013,8 @@ jint JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index)
 jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_GetMethodIxMaxStack: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -1917,78 +2023,98 @@ jint JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index)
 jboolean JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index)
 {
        log_println("JVM_IsConstructorIx: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
 /* JVM_GetMethodIxNameUTF */
 
-const charJVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
+const char *JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index)
 {
        log_println("JVM_GetMethodIxNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetMethodIxSignatureUTF */
 
-const charJVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
+const char *JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index)
 {
        log_println("JVM_GetMethodIxSignatureUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPFieldNameUTF */
 
-const charJVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPFieldNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPMethodNameUTF */
 
-const charJVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPMethodNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPMethodSignatureUTF */
 
-const charJVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPMethodSignatureUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPFieldSignatureUTF */
 
-const charJVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPFieldSignatureUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPClassNameUTF */
 
-const charJVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPClassNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPFieldClassNameUTF */
 
-const charJVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPFieldClassNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetCPMethodClassNameUTF */
 
-const charJVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
+const char *JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 {
        log_println("JVM_GetCPMethodClassNameUTF: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -1997,6 +2123,8 @@ const char* JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index)
 jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
 {
        log_println("JVM_GetCPFieldModifiers: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2005,6 +2133,8 @@ jint JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass calle
 jint JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls)
 {
        log_println("JVM_GetCPMethodModifiers: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2021,30 +2151,35 @@ void JVM_ReleaseUTF(const char *utf)
 jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
 {
        log_println("JVM_IsSameClassPackage: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
 /* JVM_Open */
 
+/* Taken from: hotspot/src/share/vm/prims/jvm.h */
+
+/*
+ * JVM I/O error codes
+ */
+#define JVM_EEXIST       -100
+
 jint JVM_Open(const char *fname, jint flags, jint mode)
 {
        int result;
 
-#if PRINTJVM
-       log_println("JVM_Open: fname=%s, flags=%d, mode=%d", fname, flags, mode);
-#endif
+       TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
 
-       result = open(fname, flags, mode);
+       result = hpi_file->Open(fname, flags, mode);
 
        if (result >= 0) {
                return result;
        }
        else {
-               switch(errno) {
+               switch (errno) {
                case EEXIST:
-                       /* XXX don't know what to do here */
-/*                     return JVM_EEXIST; */
-                       return -1;
+                       return JVM_EEXIST;
                default:
                        return -1;
                }
@@ -2056,10 +2191,9 @@ jint JVM_Open(const char *fname, jint flags, jint mode)
 
 jint JVM_Close(jint fd)
 {
-#if PRINTJVM
-       log_println("JVM_Close: fd=%d", fd);
-#endif
-       return close(fd);
+       TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
+
+       return hpi_file->Close(fd);
 }
 
 
@@ -2067,10 +2201,9 @@ jint JVM_Close(jint fd)
 
 jint JVM_Read(jint fd, char *buf, jint nbytes)
 {
-#if PRINTJVM
-       log_println("JVM_Read: fd=%d, buf=%p, nbytes=%d", fd, buf, nbytes);
-#endif
-       return read(fd, buf, nbytes);
+       TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
+
+       return (jint) hpi_file->Read(fd, buf, nbytes);
 }
 
 
@@ -2078,10 +2211,9 @@ jint JVM_Read(jint fd, char *buf, jint nbytes)
 
 jint JVM_Write(jint fd, char *buf, jint nbytes)
 {
-#if PRINTJVM
-       log_println("JVM_Write: fd=%d, buf=%s, nbytes=%d", fd, buf, nbytes);
-#endif
-       return write(fd, buf, nbytes);
+       TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
+
+       return (jint) hpi_file->Write(fd, buf, nbytes);
 }
 
 
@@ -2089,22 +2221,9 @@ jint JVM_Write(jint fd, char *buf, jint nbytes)
 
 jint JVM_Available(jint fd, jlong *pbytes)
 {
-#if defined(FIONREAD)
-       int bytes;
-
-       TRACEJVMCALLS("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes);
+       TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
 
-       *pbytes = 0;
-
-       if (ioctl(fd, FIONREAD, &bytes) < 0)
-               return 0;
-
-       *pbytes = bytes;
-
-       return 1;
-#else
-# error FIONREAD not defined
-#endif
+       return hpi_file->Available(fd, pbytes);
 }
 
 
@@ -2112,9 +2231,9 @@ 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) lseek(fd, (off_t) offset, whence);
+       return hpi_file->Seek(fd, (off_t) offset, whence);
 }
 
 
@@ -2122,9 +2241,9 @@ 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 ftruncate(fd, length);
+       return hpi_file->SetLength(fd, length);
 }
 
 
@@ -2132,9 +2251,9 @@ 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 fsync(fd);
+       return hpi_file->Sync(fd);
 }
 
 
@@ -2142,10 +2261,9 @@ jint JVM_Sync(jint fd)
 
 void JVM_StartThread(JNIEnv* env, jobject jthread)
 {
-#if PRINTJVM
-       log_println("JVM_StartThread: jthread=%p", jthread);
-#endif
-       _Jv_java_lang_Thread_start((java_lang_Thread *) jthread, 0);
+       TRACEJVMCALLS(("JVM_StartThread(env=%p, jthread=%p)", env, jthread));
+
+       threads_thread_start((java_handle_t *) jthread);
 }
 
 
@@ -2161,20 +2279,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 = threads_list_first(); t != NULL; t = threads_list_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. */
@@ -2208,10 +2320,21 @@ void JVM_ResumeThread(JNIEnv* env, jobject jthread)
 
 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
 {
-#if PRINTJVM
-       log_println("JVM_SetThreadPriority: jthread=%p, prio=%d", jthread, prio);
-#endif
-       _Jv_java_lang_Thread_setPriority((java_lang_Thread *) jthread, prio);
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, jthread, prio));
+
+       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. */
+
+       if (t == NULL)
+               return;
+
+       threads_set_thread_priority(t->tid, prio);
 }
 
 
@@ -2219,7 +2342,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();
 }
@@ -2229,10 +2352,9 @@ void JVM_Yield(JNIEnv *env, jclass threadClass)
 
 void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
 {
-#if PRINTJVM
-       log_println("JVM_Sleep: threadClass=%p, millis=%ld", threadClass, millis);
-#endif
-       _Jv_java_lang_Thread_sleep(millis);
+       TRACEJVMCALLS(("JVM_Sleep(env=%p, threadClass=%p, millis=%ld)", env, threadClass, millis));
+
+       threads_sleep(millis, 0);
 }
 
 
@@ -2240,10 +2362,13 @@ void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
 
 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
 {
-#if PRINTJVM
-       log_println("JVM_CurrentThread: threadClass=%p", threadClass);
-#endif
-       return (jobject) _Jv_java_lang_Thread_currentThread();
+       java_object_t *o;
+
+       TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
+
+       o = thread_get_current_object();
+
+       return (jobject) o;
 }
 
 
@@ -2252,6 +2377,8 @@ jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
 jint JVM_CountStackFrames(JNIEnv* env, jobject jthread)
 {
        log_println("JVM_CountStackFrames: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2259,7 +2386,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);
 }
 
 
@@ -2267,11 +2405,21 @@ void JVM_Interrupt(JNIEnv* env, jobject jthread)
 
 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
 {
-#if PRINTJVM
-       log_println("JVM_IsInterrupted: jthread=%p, clear_interrupted=%d", jthread, clear_interrupted);
-#endif
-       /* XXX do something with clear_interrupted */
-       return _Jv_java_lang_Thread_isInterrupted((java_lang_Thread *) jthread);
+       java_handle_t *h;
+       threadobject  *t;
+       jboolean       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);
+
+       interrupted = thread_is_interrupted(t);
+
+       if (interrupted && clear_interrupted)
+               thread_set_interrupted(t, false);
+
+       return interrupted;
 }
 
 
@@ -2282,7 +2430,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;
 
@@ -2310,6 +2458,8 @@ void JVM_DumpAllStacks(JNIEnv* env, jclass unused)
 jclass JVM_CurrentLoadedClass(JNIEnv *env)
 {
        log_println("JVM_CurrentLoadedClass: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2321,6 +2471,8 @@ jobject JVM_CurrentClassLoader(JNIEnv *env)
           doPrivileged, return NULL */
 
        log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2328,9 +2480,8 @@ jobject JVM_CurrentClassLoader(JNIEnv *env)
 
 jobjectArray JVM_GetClassContext(JNIEnv *env)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassContext");
-#endif
+       TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
+
        return (jobjectArray) stacktrace_getClassContext();
 }
 
@@ -2340,6 +2491,8 @@ jobjectArray JVM_GetClassContext(JNIEnv *env)
 jint JVM_ClassDepth(JNIEnv *env, jstring name)
 {
        log_println("JVM_ClassDepth: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2348,6 +2501,8 @@ jint JVM_ClassDepth(JNIEnv *env, jstring name)
 jint JVM_ClassLoaderDepth(JNIEnv *env)
 {
        log_println("JVM_ClassLoaderDepth: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2359,11 +2514,13 @@ 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(name, false);
+       u = javastring_toutf((java_handle_t *) name, false);
+
        result = package_find(u);
+
        if (result != NULL)
                s = javastring_new(result);
        else
@@ -2378,6 +2535,8 @@ jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
 jobjectArray JVM_GetSystemPackages(JNIEnv *env)
 {
        log_println("JVM_GetSystemPackages: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2386,6 +2545,8 @@ jobjectArray JVM_GetSystemPackages(JNIEnv *env)
 jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass)
 {
        log_println("JVM_AllocateNewObject: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2394,6 +2555,8 @@ jobject JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, j
 jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length)
 {
        log_println("JVM_AllocateNewArray: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2401,7 +2564,13 @@ jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint le
 
 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
 {
-       log_println("JVM_LatestUserDefinedLoader: IMPLEMENT ME!");
+       classloader_t *cl;
+
+       TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
+
+       cl = stacktrace_first_nonnull_classloader();
+
+       return (jobject) cl;
 }
 
 
@@ -2410,6 +2579,8 @@ jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
 jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring currClassName)
 {
        log_println("JVM_LoadClass0: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2419,7 +2590,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;
 
@@ -2434,7 +2605,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;
 
@@ -2453,7 +2624,13 @@ jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
 
 jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode)
 {
+       jvalue jv;
+
        log_println("JVM_GetPrimitiveArrayElement: IMPLEMENT ME!");
+
+       jv.l = NULL;
+
+       return jv;
 }
 
 
@@ -2464,7 +2641,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;
@@ -2490,7 +2667,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();
@@ -2501,10 +2678,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;
@@ -2530,7 +2715,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();
@@ -2541,11 +2726,23 @@ 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(ia);
+       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);
 
@@ -2564,7 +2761,7 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
        if (ac == NULL)
                return NULL;
 
-       a = builtin_multianewarray(length, ac, dims);
+       a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
 
        return (jobject) a;
 }
@@ -2574,7 +2771,9 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
 
 jint JVM_InitializeSocketLibrary()
 {
-       log_println("JVM_InitializeSocketLibrary: IMPLEMENT ME!");
+       TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
+
+       return hpi_initialize_socket_library();
 }
 
 
@@ -2582,9 +2781,9 @@ 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 socket(domain, type, protocol);
+       return system_socket(domain, type, protocol);
 }
 
 
@@ -2592,9 +2791,9 @@ 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 close(fd);
+       return system_close(fd);
 }
 
 
@@ -2602,9 +2801,9 @@ 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 shutdown(fd, howto);
+       return system_shutdown(fd, howto);
 }
 
 
@@ -2613,6 +2812,8 @@ jint JVM_SocketShutdown(jint fd, jint howto)
 jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
 {
        log_println("JVM_Recv: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2621,6 +2822,8 @@ jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
 {
        log_println("JVM_Send: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2629,6 +2832,8 @@ jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
 jint JVM_Timeout(int fd, long timeout)
 {
        log_println("JVM_Timeout: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2636,9 +2841,9 @@ 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 listen(fd, count);
+       return system_listen(fd, count);
 }
 
 
@@ -2646,9 +2851,9 @@ 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 connect(fd, him, len);
+       return system_connect(fd, him, len);
 }
 
 
@@ -2657,6 +2862,8 @@ jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
 jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
 {
        log_println("JVM_Bind: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2664,9 +2871,9 @@ 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 accept(fd, him, (socklen_t *) len);
+       return system_accept(fd, him, (socklen_t *) len);
 }
 
 
@@ -2675,6 +2882,8 @@ jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
 jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)
 {
        log_println("JVM_RecvFrom: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2682,9 +2891,9 @@ 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 getsockname(fd, him, (socklen_t *) len);
+       return system_getsockname(fd, him, (socklen_t *) len);
 }
 
 
@@ -2693,6 +2902,8 @@ jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
 jint JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)
 {
        log_println("JVM_SendTo: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2702,12 +2913,15 @@ jint JVM_SocketAvailable(jint fd, jint *pbytes)
 {
 #if defined(FIONREAD)
        int bytes;
+       int result;
 
-       TRACEJVMCALLS("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes);
+       TRACEJVMCALLS(("JVM_SocketAvailable(fd=%d, pbytes=%p)", fd, pbytes));
 
        *pbytes = 0;
 
-       if (ioctl(fd, FIONREAD, &bytes) < 0)
+       result = ioctl(fd, FIONREAD, &bytes);
+
+       if (result < 0)
                return 0;
 
        *pbytes = bytes;
@@ -2723,13 +2937,9 @@ jint JVM_SocketAvailable(jint fd, jint *pbytes)
 
 jint JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)
 {
-#if defined(HAVE_GETSOCKOPT)
-       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 getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
-#else
-# error getsockopt not available
-#endif
+       return system_getsockopt(fd, level, optname, optval, (socklen_t *) optlen);
 }
 
 
@@ -2737,47 +2947,55 @@ 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)
 {
-#if defined(HAVE_SETSOCKOPT)
-       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 setsockopt(fd, level, optname, optval, optlen);
-#else
-# error setsockopt not available
-#endif
+       return system_setsockopt(fd, level, optname, optval, optlen);
 }
 
 
 /* JVM_GetHostName */
 
-int JVM_GetHostName(charname, int namelen)
+int JVM_GetHostName(char *name, int namelen)
 {
-       TRACEJVMCALLS("JVM_GetHostName(name=%s, namelen=%d)", name, namelen);
+       int result;
+
+       TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
 
-       return gethostname(name, namelen);
+       result = system_gethostname(name, namelen);
+
+       TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
+
+       return result;
 }
 
 
 /* JVM_GetHostByAddr */
 
-struct hostentJVM_GetHostByAddr(const char* name, int len, int type)
+struct hostent *JVM_GetHostByAddr(const char* name, int len, int type)
 {
        log_println("JVM_GetHostByAddr: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetHostByName */
 
-struct hostentJVM_GetHostByName(char* name)
+struct hostent *JVM_GetHostByName(char* name)
 {
        log_println("JVM_GetHostByName: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetProtoByName */
 
-struct protoentJVM_GetProtoByName(char* name)
+struct protoent *JVM_GetProtoByName(char* name)
 {
        log_println("JVM_GetProtoByName: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2785,13 +3003,18 @@ struct protoent* JVM_GetProtoByName(char* name)
 
 void *JVM_LoadLibrary(const char *name)
 {
-       utf *u;
+       utf*  u;
+       void* handle;
 
-       TRACEJVMCALLS("JVM_LoadLibrary(name=%s)", name);
+       TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
 
        u = utf_new_char(name);
 
-       return native_library_open(u);
+       handle = native_library_open(u);
+
+       TRACEJVMCALLSEXIT(("->%p", handle));
+
+       return handle;
 }
 
 
@@ -2799,7 +3022,9 @@ void *JVM_LoadLibrary(const char *name)
 
 void JVM_UnloadLibrary(void* handle)
 {
-       log_println("JVM_UnloadLibrary: IMPLEMENT ME!");
+       TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
+
+       native_library_close(handle);
 }
 
 
@@ -2809,10 +3034,12 @@ void *JVM_FindLibraryEntry(void *handle, const char *name)
 {
        lt_ptr symbol;
 
-       TRACEJVMCALLS("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name);
+       TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
 
        symbol = lt_dlsym(handle, name);
 
+       TRACEJVMCALLSEXIT(("->%p", symbol));
+
        return symbol;
 }
 
@@ -2822,6 +3049,8 @@ void *JVM_FindLibraryEntry(void *handle, const char *name)
 jboolean JVM_IsNaN(jdouble a)
 {
        log_println("JVM_IsNaN: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2829,7 +3058,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);
 }
@@ -2839,7 +3068,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);
 }
@@ -2851,9 +3080,7 @@ JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 {
        java_object_t *o;
 
-#if PRINTJVM
-       log_println("JVM_RawMonitorCreate");
-#endif
+       TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
 
        o = NEW(java_object_t);
 
@@ -2867,9 +3094,8 @@ JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 
 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
 {
-#if PRINTJVM
-       log_println("JVM_RawMonitorDestroy: mon=%p", mon);
-#endif
+       TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
+
        FREE(mon, java_object_t);
 }
 
@@ -2878,9 +3104,8 @@ JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
 
 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 {
-#if PRINTJVM
-       log_println("JVM_RawMonitorEnter: mon=%p", mon);
-#endif
+       TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
+
        (void) lock_monitor_enter((java_object_t *) mon);
 
        return 0;
@@ -2891,9 +3116,8 @@ JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 
 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
 {
-#if PRINTJVM
-       log_println("JVM_RawMonitorExit: mon=%p", mon);
-#endif
+       TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
+
        (void) lock_monitor_exit((java_object_t *) mon);
 }
 
@@ -2919,6 +3143,8 @@ void JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj, jlongArray
 jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)
 {
        log_println("JVM_AccessVMBooleanFlag: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2927,6 +3153,8 @@ jboolean JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_
 jboolean JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)
 {
        log_println("JVM_AccessVMIntFlag: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -2943,6 +3171,8 @@ void JVM_VMBreakPoint(JNIEnv *env, jobject obj)
 jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
 {
        log_println("JVM_GetClassFields: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2951,6 +3181,8 @@ jobjectArray JVM_GetClassFields(JNIEnv *env, jclass cls, jint which)
 jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
 {
        log_println("JVM_GetClassMethods: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2959,6 +3191,8 @@ jobjectArray JVM_GetClassMethods(JNIEnv *env, jclass cls, jint which)
 jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
 {
        log_println("JVM_GetClassConstructors: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2967,6 +3201,8 @@ jobjectArray JVM_GetClassConstructors(JNIEnv *env, jclass cls, jint which)
 jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
 {
        log_println("JVM_GetClassField: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2975,6 +3211,8 @@ jobject JVM_GetClassField(JNIEnv *env, jclass cls, jstring name, jint which)
 jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray types, jint which)
 {
        log_println("JVM_GetClassMethod: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2983,6 +3221,8 @@ jobject JVM_GetClassMethod(JNIEnv *env, jclass cls, jstring name, jobjectArray t
 jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jint which)
 {
        log_println("JVM_GetClassConstructor: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2991,6 +3231,8 @@ jobject JVM_GetClassConstructor(JNIEnv *env, jclass cls, jobjectArray types, jin
 jobject JVM_NewInstance(JNIEnv *env, jclass cls)
 {
        log_println("JVM_NewInstance: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -2999,6 +3241,8 @@ jobject JVM_NewInstance(JNIEnv *env, jclass cls)
 jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
 {
        log_println("JVM_GetField: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -3006,7 +3250,13 @@ jobject JVM_GetField(JNIEnv *env, jobject field, jobject obj)
 
 jvalue JVM_GetPrimitiveField(JNIEnv *env, jobject field, jobject obj, unsigned char wCode)
 {
+       jvalue jv;
+
        log_println("JVM_GetPrimitiveField: IMPLEMENT ME!");
+
+       jv.l = NULL;
+
+       return jv;
 }
 
 
@@ -3030,21 +3280,53 @@ void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, un
 
 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
 {
-#if PRINTJVM
-       log_println("JVM_InvokeMethod: method=%p, obj=%p, args0=%p", method, obj, args0);
-#endif
-       return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
+       java_lang_reflect_Method *rm;
+       classinfo     *c;
+       int32_t        slot;
+       int32_t        override;
+       methodinfo    *m;
+       java_handle_t *ro;
+
+       TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
+
+       rm = (java_lang_reflect_Method *) method;
+
+       LLNI_field_get_cls(rm, clazz,    c);
+       LLNI_field_get_val(rm, slot,     slot);
+       LLNI_field_get_val(rm, override, override);
+
+       m = &(c->methods[slot]);
+
+       ro = reflect_method_invoke(m, (java_handle_t *) obj, (java_handle_objectarray_t *) args0, override);
+
+       return (jobject) ro;
 }
 
 
 /* JVM_NewInstanceFromConstructor */
 
-jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0)
+jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
 {
-#if PRINTJVM
-       log_println("JVM_NewInstanceFromConstructor: c=%p, args0=%p", c, args0);
-#endif
-       return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
+       java_lang_reflect_Constructor *rc;
+       classinfo                     *c;
+       int32_t                        slot;
+       int32_t                        override;
+       methodinfo                    *m;
+       java_handle_t                 *o;
+
+       TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
+
+       rc = (java_lang_reflect_Constructor *) con;
+
+       LLNI_field_get_cls(rc, clazz,    c);
+       LLNI_field_get_val(rc, slot,     slot);
+       LLNI_field_get_val(rc, override, override);
+
+       m = &(c->methods[slot]);
+
+       o = reflect_constructor_newinstance(m, (java_handle_objectarray_t *) args0, override);
+
+       return (jobject) o;
 }
 
 
@@ -3052,7 +3334,7 @@ jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args
 
 jboolean JVM_SupportsCX8()
 {
-       TRACEJVMCALLS("JVM_SupportsCX8()");
+       TRACEJVMCALLS(("JVM_SupportsCX8()"));
 
        /* IMPLEMENT ME */
 
@@ -3065,6 +3347,8 @@ jboolean JVM_SupportsCX8()
 jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal)
 {
        log_println("JVM_CX8Field: IMPLEMENT ME!");
+
+       return 0;
 }
 
 
@@ -3073,6 +3357,8 @@ jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlon
 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
 {
        log_println("JVM_GetAllThreads: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -3081,14 +3367,20 @@ jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
 {
        log_println("JVM_DumpThreads: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
 /* JVM_GetManagement */
 
-voidJVM_GetManagement(jint version)
+void *JVM_GetManagement(jint version)
 {
-       log_println("JVM_GetManagement: IMPLEMENT ME!");
+       TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
+
+       /* TODO We current don't support the management interface. */
+
+       return NULL;
 }
 
 
@@ -3097,6 +3389,8 @@ void* JVM_GetManagement(jint version)
 jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
 {
        log_println("JVM_InitAgentProperties: IMPLEMENT ME!");
+
+       return NULL;
 }
 
 
@@ -3104,7 +3398,32 @@ jobject JVM_InitAgentProperties(JNIEnv *env, jobject properties)
 
 jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
 {
-       log_println("JVM_GetEnclosingMethodInfo: IMPLEMENT ME!");
+       classinfo                 *c;
+       methodinfo                *m;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       if ((c == NULL) || class_is_primitive(c))
+               return NULL;
+
+       m = class_get_enclosingmethod_raw(c);
+
+       if (m == NULL)
+               return NULL;
+
+       oa = builtin_anewarray(3, class_java_lang_Object);
+
+       if (oa == NULL)
+               return NULL;
+
+       array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
+       array_objectarray_element_set(oa, 1, javastring_new(m->name));
+       array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
+
+       return (jobjectArray) oa;
 }
 
 
@@ -3114,8 +3433,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
@@ -3202,8 +3521,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;
 
@@ -3335,7 +3654,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;
@@ -3377,6 +3696,7 @@ void *JVM_RegisterSignal(jint sig, void *handler)
 jboolean JVM_RaiseSignal(jint sig)
 {
        log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
+
        return false;
 }
 
@@ -3385,7 +3705,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)