* src/native/vm/sun/jvm.c (JVM_GetEnclosingMethodInfo): Use
[cacao.git] / src / native / vm / sun / jvm.c
index 33621a875de618169409246b2aa86328db80d449..be21f58c99e757cc1bac5661886ff18fc717d2d6 100644 (file)
 #include "native/include/sun_reflect_ConstantPool.h"
 #endif
 
-#include "native/vm/java_lang_Class.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(...)                                            \
-    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 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)                               \
         }                                                                              \
     } 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 TRACEJVMCALLSENTER(x)
+# define TRACEJVMCALLSEXIT(x)
 # define TRACEJVMCALLSVERBOSE(x)
-# define PRINTJVMWARNINGS(...)
+# define PRINTJVMWARNINGS(x)
 
 #endif
 
@@ -230,7 +245,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();
 }
@@ -240,7 +255,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,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;
@@ -290,7 +316,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);
@@ -309,7 +335,7 @@ void JVM_OnExit(void (*func)(void))
 
 void JVM_GC(void)
 {
-       TRACEJVMCALLS("JVM_GC()");
+       TRACEJVMCALLS(("JVM_GC()"));
 
        gc_call();
 }
@@ -345,7 +371,7 @@ void JVM_TraceMethodCalls(jboolean on)
 
 jlong JVM_TotalMemory(void)
 {
-       TRACEJVMCALLS("JVM_TotalMemory()");
+       TRACEJVMCALLS(("JVM_TotalMemory()"));
 
        return gc_get_heap_size();
 }
@@ -355,7 +381,7 @@ jlong JVM_TotalMemory(void)
 
 jlong JVM_FreeMemory(void)
 {
-       TRACEJVMCALLS("JVM_FreeMemory()");
+       TRACEJVMCALLS(("JVM_FreeMemory()"));
 
        return gc_get_free_bytes();
 }
@@ -365,7 +391,7 @@ jlong JVM_FreeMemory(void)
 
 jlong JVM_MaxMemory(void)
 {
-       TRACEJVMCALLS("JVM_MaxMemory()");
+       TRACEJVMCALLS(("JVM_MaxMemory()"));
 
        return gc_get_max_heap_size();
 }
@@ -375,7 +401,7 @@ jlong JVM_MaxMemory(void)
 
 jint JVM_ActiveProcessorCount(void)
 {
-       TRACEJVMCALLS("JVM_ActiveProcessorCount()");
+       TRACEJVMCALLS(("JVM_ActiveProcessorCount()"));
 
        return system_processors_online();
 }
@@ -388,11 +414,11 @@ 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_get();
+       ba = stacktrace_get_current();
 
        if (ba == NULL)
                return;
@@ -413,21 +439,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;
@@ -451,23 +480,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_String            *declaringclass;
+       java_lang_StackTraceElement *steo;
+       java_handle_t*               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 */
 
@@ -489,14 +521,14 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
        code = ste->code;
        m    = code->m;
-       c    = m->class;
+       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 */
@@ -525,18 +557,18 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 
        /* get declaring class name */
 
-       declaringclass = _Jv_java_lang_Class_getName(LLNI_classinfo_wrap(c));
+       declaringclass = class_get_classname(c);
 
        /* fill the java.lang.StackTraceElement element */
 
        /* FIXME critical section */
 
-       o->declaringClass = declaringclass;
-       o->methodName     = (java_lang_String *) javastring_new(m->name);
-       o->fileName       = filename;
-       o->lineNumber     = linenumber;
+       steo->declaringClass = (java_lang_String*) declaringclass;
+       steo->methodName     = (java_lang_String*) javastring_new(m->name);
+       steo->fileName       = filename;
+       steo->lineNumber     = linenumber;
 
-       return (jobject) o;
+       return (jobject) steo;
 }
 
 
@@ -544,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);
 }
@@ -558,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();
@@ -581,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;
@@ -599,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;
@@ -613,7 +645,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);
 }
@@ -671,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"));
 }
 
 
@@ -680,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"));
 }
 
 
@@ -689,25 +721,9 @@ void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
 
 jint JVM_GetLastErrorString(char *buf, int len)
 {
-       const char *s;
-       int n;
-
-    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';
+       TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
 
-               return n;
-    }
+       return hpi_system->GetLastErrorString(buf, len);
 }
 
 
@@ -715,11 +731,9 @@ 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? */
-
-       return path;
+       return hpi_file->NativePath(path);
 }
 
 
@@ -727,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);
-
-       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;
 }
 
 
@@ -751,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);
@@ -764,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"));
 }
 
 
@@ -773,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));
+
+       /* As of now, OpenJDK does not call this function with throwError
+          is true. */
 
-       TRACEJVMCALLS("JVM_FindClassFromClassLoader(name=%s, init=%d, loader=%p, throwError=%d)", name, init, loader, throwError);
+       assert(throwError == false);
 
        u  = utf_new_char(name);
        cl = loader_hashtable_classloader_add((java_handle_t *) loader);
@@ -820,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);
@@ -845,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);
 
@@ -864,9 +876,13 @@ 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);
+       classinfo* c;
 
-       return (jstring) _Jv_java_lang_Class_getName((java_lang_Class *) cls);
+       TRACEJVMCALLS(("JVM_GetClassName(env=%p, cls=%p)", env, cls));
+
+       c = LLNI_classinfo_unwrap(cls);
+
+       return (jstring) class_get_classname(c);
 }
 
 
@@ -877,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);
 
@@ -891,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;
 }
 
@@ -909,7 +927,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);
 
@@ -934,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);
 
@@ -958,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);
 
@@ -988,16 +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;
 
-       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();
@@ -1017,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;
        }
 
@@ -1044,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
@@ -1060,7 +1083,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);
 
@@ -1074,7 +1097,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);
 
@@ -1089,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);
        
@@ -1106,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);
 
@@ -1123,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);
 
@@ -1140,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);
 
@@ -1158,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);
 
@@ -1184,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();
@@ -1207,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();
@@ -1229,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();
@@ -1251,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();
@@ -1273,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();
@@ -1292,9 +1315,16 @@ 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);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredFields(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
 
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredFields((java_lang_Class *) ofClass, publicOnly);
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredfields(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1302,9 +1332,16 @@ 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);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredMethods(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
+
+       c = LLNI_classinfo_unwrap(ofClass);
 
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredMethods((java_lang_Class *) ofClass, publicOnly);
+       oa = class_get_declaredmethods(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1312,9 +1349,16 @@ 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);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS(("JVM_GetClassDeclaredConstructors(env=%p, ofClass=%p, publicOnly=%d)", env, ofClass, publicOnly));
 
-       return (jobjectArray) _Jv_java_lang_Class_getDeclaredConstructors((java_lang_Class *) ofClass, publicOnly);
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredconstructors(c, publicOnly);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -1324,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);
 
@@ -1344,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(
@@ -1371,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);
 
@@ -1387,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);
 
@@ -1412,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);
 
@@ -1442,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);
@@ -1465,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);
@@ -1494,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);
@@ -1516,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);
@@ -1557,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);
@@ -1578,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);
@@ -1599,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);
@@ -1620,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);
@@ -1641,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);
@@ -1663,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);
@@ -1688,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);
 
@@ -1737,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"));
 
@@ -2125,9 +2169,9 @@ 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);
+       result = hpi_file->Open(fname, flags, mode);
 
        if (result >= 0) {
                return result;
@@ -2147,9 +2191,9 @@ 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);
+       return hpi_file->Close(fd);
 }
 
 
@@ -2157,9 +2201,9 @@ 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);
+       return (jint) hpi_file->Read(fd, buf, nbytes);
 }
 
 
@@ -2167,9 +2211,9 @@ 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);
+       return (jint) hpi_file->Write(fd, buf, nbytes);
 }
 
 
@@ -2177,25 +2221,9 @@ jint JVM_Write(jint fd, char *buf, jint nbytes)
 
 jint JVM_Available(jint fd, jlong *pbytes)
 {
-#if defined(FIONREAD)
-       int bytes;
-       int result;
+       TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
 
-       TRACEJVMCALLS("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes);
-
-       *pbytes = 0;
-
-       result = ioctl(fd, FIONREAD, &bytes);
-
-       if (result < 0)
-               return 0;
-
-       *pbytes = bytes;
-
-       return 1;
-#else
-# error FIONREAD not defined
-#endif
+       return hpi_file->Available(fd, pbytes);
 }
 
 
@@ -2203,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) system_lseek(fd, (off_t) offset, whence);
+       return hpi_file->Seek(fd, (off_t) offset, whence);
 }
 
 
@@ -2213,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 system_ftruncate(fd, length);
+       return hpi_file->SetLength(fd, length);
 }
 
 
@@ -2223,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 system_fsync(fd);
+       return hpi_file->Sync(fd);
 }
 
 
@@ -2233,9 +2261,9 @@ 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));
 
-       _Jv_java_lang_Thread_start((java_lang_Thread *) jthread, 0);
+       threads_thread_start((java_handle_t *) jthread);
 }
 
 
@@ -2251,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. */
@@ -2298,9 +2320,21 @@ void JVM_ResumeThread(JNIEnv* env, jobject jthread)
 
 void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
 {
-       TRACEJVMCALLS("JVM_SetThreadPriority(env=%p, jthread=%p, prio=%d)", env, 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. */
 
-       _Jv_java_lang_Thread_setPriority((java_lang_Thread *) jthread, prio);
+       if (t == NULL)
+               return;
+
+       threads_set_thread_priority(t->tid, prio);
 }
 
 
@@ -2308,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();
 }
@@ -2318,9 +2352,9 @@ 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));
 
-       _Jv_java_lang_Thread_sleep(millis);
+       threads_sleep(millis, 0);
 }
 
 
@@ -2328,9 +2362,13 @@ void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
 
 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
 {
+       java_object_t *o;
+
        TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
 
-       return (jobject) _Jv_java_lang_Thread_currentThread();
+       o = thread_get_current_object();
+
+       return (jobject) o;
 }
 
 
@@ -2348,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);
 }
 
 
@@ -2356,11 +2405,21 @@ void JVM_Interrupt(JNIEnv* env, jobject jthread)
 
 jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted)
 {
-       TRACEJVMCALLS("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted);
+       java_handle_t *h;
+       threadobject  *t;
+       jboolean       interrupted;
 
-       /* XXX do something with clear_interrupted */
+       TRACEJVMCALLS(("JVM_IsInterrupted(env=%p, jthread=%p, clear_interrupted=%d)", env, jthread, clear_interrupted));
 
-       return _Jv_java_lang_Thread_isInterrupted((java_lang_Thread *) jthread);
+       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;
 }
 
 
@@ -2371,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;
 
@@ -2421,7 +2480,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();
 }
@@ -2455,7 +2514,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);
@@ -2505,9 +2564,9 @@ jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint le
 
 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
 {
-       classloader *cl;
+       classloader_t *cl;
 
-       TRACEJVMCALLS("JVM_LatestUserDefinedLoader(env=%p)", env);
+       TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
 
        cl = stacktrace_first_nonnull_classloader();
 
@@ -2531,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;
 
@@ -2546,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;
 
@@ -2582,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;
@@ -2608,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();
@@ -2619,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;
@@ -2648,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();
@@ -2659,12 +2726,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++) {
@@ -2692,9 +2771,9 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
 
 jint JVM_InitializeSocketLibrary()
 {
-       log_println("JVM_InitializeSocketLibrary: IMPLEMENT ME!");
+       TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
 
-       return 0;
+       return hpi_initialize_socket_library();
 }
 
 
@@ -2702,7 +2781,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);
 }
@@ -2712,7 +2791,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);
 }
@@ -2722,7 +2801,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);
 }
@@ -2762,7 +2841,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);
 }
@@ -2772,7 +2851,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);
 }
@@ -2792,7 +2871,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);
 }
@@ -2812,7 +2891,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);
 }
@@ -2836,7 +2915,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;
 
@@ -2858,7 +2937,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);
 }
@@ -2868,7 +2947,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);
 }
@@ -2878,9 +2957,15 @@ 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);
+       int result;
+
+       TRACEJVMCALLSENTER(("JVM_GetHostName(name=%s, namelen=%d)", name, namelen));
+
+       result = system_gethostname(name, namelen);
 
-       return system_gethostname(name, namelen);
+       TRACEJVMCALLSEXIT(("->%d (name=%s)", result, name));
+
+       return result;
 }
 
 
@@ -2918,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;
 }
 
 
@@ -2932,7 +3022,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);
 }
@@ -2944,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;
 }
 
@@ -2966,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);
 }
@@ -2976,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);
 }
@@ -2988,7 +3080,7 @@ JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 {
        java_object_t *o;
 
-       TRACEJVMCALLS("JVM_RawMonitorCreate()");
+       TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
 
        o = NEW(java_object_t);
 
@@ -3002,7 +3094,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);
 }
@@ -3012,7 +3104,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);
 
@@ -3024,7 +3116,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);
 }
@@ -3188,19 +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)
 {
-       TRACEJVMCALLS("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, 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;
 
-       return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
+       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)
 {
-       TRACEJVMCALLS("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, c, 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;
 
-       return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
+       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;
 }
 
 
@@ -3208,7 +3334,7 @@ jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args
 
 jboolean JVM_SupportsCX8()
 {
-       TRACEJVMCALLS("JVM_SupportsCX8()");
+       TRACEJVMCALLS(("JVM_SupportsCX8()"));
 
        /* IMPLEMENT ME */
 
@@ -3250,7 +3376,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. */
 
@@ -3276,14 +3402,14 @@ 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);
 
        if ((c == NULL) || class_is_primitive(c))
                return NULL;
 
-       m = class_get_enclosingmethod(c);
+       m = class_get_enclosingmethod_raw(c);
 
        if (m == NULL)
                return NULL;
@@ -3293,7 +3419,7 @@ jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
        if (oa == NULL)
                return NULL;
 
-       array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->class));
+       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));
 
@@ -3307,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
@@ -3395,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;
 
@@ -3528,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;
@@ -3579,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)