* Removed all Id tags.
[cacao.git] / src / native / vm / sun / jvm.c
index c7d43b3ce08fffac3a6ab31e4f0a6353019f0dfe..642826d53d94b5fb2543a94fcc8c0095a80051de 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_Class.c 8132 2007-06-22 11:15:47Z twisti $
-
 */
 
 
@@ -31,6 +29,7 @@
 
 #include "config.h"
 
+#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <ltdl.h>
@@ -51,6 +50,7 @@
 #include "mm/memory.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
 
 #include "native/include/java_lang_AssertionStatusDirectives.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_Object.h"
 #include "native/vm/java_lang_Runtime.h"
-#include "native/vm/java_lang_String.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/java_util_concurrent_atomic_AtomicLong.h"
+#include "native/vm/reflect.h"
 
 #include "threads/lock-common.h"
+#include "threads/threads-common.h"
 
 #include "toolbox/logging.h"
 
+#include "vm/array.h"
 #include "vm/builtin.h"
 #include "vm/exceptions.h"
+#include "vm/global.h"
 #include "vm/initialize.h"
+#include "vm/primitive.h"
 #include "vm/properties.h"
+#include "vm/resolve.h"
+#include "vm/signallocal.h"
 #include "vm/stringlocal.h"
 #include "vm/vm.h"
 
 #include "vm/jit/stacktrace.h"
 
 #include "vmcore/classcache.h"
-#include "vmcore/primitive.h"
+#include "vmcore/options.h"
 
 
-/* debugging macro ************************************************************/
+/* debugging macro***********************************************************/
 
 #if !defined(NDEBUG)
-# define DEBUG_JVM(x) \
+
+# define TRACEJVMCALLS(...) \
     do { \
-        if (opt_TraceJVM) { \
-            log_println("%s", (x)); \
+        if (opt_TraceJVMCalls) { \
+            log_println(__VA_ARGS__); \
         } \
     } while (0)
+
+# define PRINTJVMWARNINGS(...)
+/*     do { \ */
+/*         if (opt_PrintJVMWarnings) { \ */
+/*             log_println(__VA_ARGS__); \ */
+/*         } \ */
+/*     } while (0) */
+
 #else
-# define DEBUG_JVM(x)
+
+# define TRACEJVMCALLS(...)
+# define PRINTJVMWARNINGS(...)
+
 #endif
 
 
@@ -214,10 +244,17 @@ jlong JVM_NanoTime(JNIEnv *env, jclass ignored)
 
 void JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length)
 {
+       java_handle_t *s;
+       java_handle_t *d;
+
+       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
-       builtin_arraycopy(src, src_pos, dst, dst_pos, length);
+
+       (void) builtin_arraycopy(s, src_pos, d, dst_pos, length);
 }
 
 
@@ -228,7 +265,7 @@ jobject JVM_InitProperties(JNIEnv *env, jobject properties)
 #if PRINTJVM
        log_println("JVM_InitProperties: properties=%d", properties);
 #endif
-       properties_system_add_all((java_objectheader *) properties);
+       properties_system_add_all((java_handle_t *) properties);
 }
 
 
@@ -264,10 +301,9 @@ void JVM_OnExit(void (*func)(void))
 
 void JVM_GC(void)
 {
-#if PRINTJVM
-       log_println("JVM_GC");
-#endif
-       _Jv_java_lang_Runtime_gc();
+       TRACEJVMCALLS("JVM_GC()");
+
+       gc_call();
 }
 
 
@@ -299,10 +335,9 @@ void JVM_TraceMethodCalls(jboolean on)
 
 jlong JVM_TotalMemory(void)
 {
-#if PRINTJVM
-       log_println("JVM_TotalMemory");
-#endif
-       return _Jv_java_lang_Runtime_totalMemory();
+       TRACEJVMCALLS("JVM_TotalMemory()");
+
+       return gc_get_heap_size();
 }
 
 
@@ -310,10 +345,9 @@ jlong JVM_TotalMemory(void)
 
 jlong JVM_FreeMemory(void)
 {
-#if PRINTJVM
-       log_println("JVM_FreeMemory");
-#endif
-       return _Jv_java_lang_Runtime_freeMemory();
+       TRACEJVMCALLS("JVM_FreeMemory()");
+
+       return gc_get_free_bytes();
 }
 
 
@@ -321,7 +355,9 @@ jlong JVM_FreeMemory(void)
 
 jlong JVM_MaxMemory(void)
 {
-       log_println("JVM_MaxMemory: IMPLEMENT ME!");
+       TRACEJVMCALLS("JVM_MaxMemory()");
+
+       return gc_get_max_heap_size();
 }
 
 
@@ -443,7 +479,7 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
        /* get declaring class name */
 
        declaringclass =
-               _Jv_java_lang_Class_getName((java_lang_Class *) ste->method->class);
+               _Jv_java_lang_Class_getName(LLNI_classinfo_wrap(ste->method->class));
 
        /* fill the java.lang.StackTraceElement element */
 
@@ -452,7 +488,7 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
        o->fileName       = filename;
        o->lineNumber     = linenumber;
 
-       return o;
+       return (jobject) o;
 }
 
 
@@ -507,7 +543,7 @@ jobject JVM_Clone(JNIEnv* env, jobject handle)
 #if PRINTJVM
        log_println("JVM_Clone: handle=%p", handle);
 #endif
-       return (jobject) builtin_clone(env, (java_objectheader *) handle);
+       return (jobject) builtin_clone(env, (java_handle_t *) handle);
 }
 
 
@@ -555,7 +591,8 @@ jobject JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg)
 
 void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
 {
-       log_println("JVM_EnableCompiler: IMPLEMENT ME!");
+       TRACEJVMCALLS("JVM_EnableCompiler(env=%p, compCls=%p)", env, compCls);
+       PRINTJVMWARNINGS("JVM_EnableCompiler not supported");
 }
 
 
@@ -563,7 +600,8 @@ void JVM_EnableCompiler(JNIEnv *env, jclass compCls)
 
 void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
 {
-       log_println("JVM_DisableCompiler: IMPLEMENT ME!");
+       TRACEJVMCALLS("JVM_DisableCompiler(env=%p, compCls=%p)", env, compCls);
+       PRINTJVMWARNINGS("JVM_DisableCompiler not supported");
 }
 
 
@@ -595,11 +633,10 @@ jint JVM_GetLastErrorString(char *buf, int len)
 
 /* JVM_NativePath */
 
-char* JVM_NativePath(char* path)
+char *JVM_NativePath(char *path)
 {
-#if PRINTJVM
-       log_println("JVM_NativePath: path=%s", path);
-#endif
+       TRACEJVMCALLS("JVM_NativePath(path=%s)", path);
+
        /* XXX is this correct? */
 
        return path;
@@ -610,11 +647,9 @@ char* JVM_NativePath(char* path)
 
 jclass JVM_GetCallerClass(JNIEnv* env, int depth)
 {
-       java_objectarray *oa;
+       java_handle_objectarray_t *oa;
 
-#if PRINTJVM
-       log_println("JVM_GetCallerClass: depth=%d", depth);
-#endif
+       TRACEJVMCALLS("JVM_GetCallerClass(env=%p, depth=%d)", env, depth);
 
        oa = stacktrace_getClassContext();
 
@@ -631,12 +666,17 @@ jclass JVM_GetCallerClass(JNIEnv* env, int depth)
 
 /* JVM_FindPrimitiveClass */
 
-jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)
+jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* s)
 {
-#if PRINTVM
-       log_println("JVM_FindPrimitiveClass: utf=%s", utf);
-#endif
-       return (jclass) primitive_class_get_by_name(utf_new_char(utf));
+       classinfo *c;
+       utf       *u;
+
+       TRACEJVMCALLS("JVM_FindPrimitiveClass(env=%p, s=%s)", env, s);
+
+       u = utf_new_char(s);
+       c = primitive_class_get_by_name(u);
+
+       return (jclass) LLNI_classinfo_wrap(c);
 }
 
 
@@ -644,7 +684,8 @@ jclass JVM_FindPrimitiveClass(JNIEnv* env, const char* utf)
 
 void JVM_ResolveClass(JNIEnv* env, jclass cls)
 {
-       log_println("JVM_ResolveClass: IMPLEMENT ME!");
+       TRACEJVMCALLS("JVM_ResolveClass(env=%p, cls=%p)", env, cls);
+       PRINTJVMWARNINGS("JVM_ResolveClass not implemented");
 }
 
 
@@ -652,13 +693,16 @@ void JVM_ResolveClass(JNIEnv* env, jclass cls)
 
 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
 {
-       classinfo *c;
+       classinfo   *c;
+       utf         *u;
+       classloader *cl;
 
-#if PRINTJVM
-       log_println("JVM_FindClassFromClassLoader: name=%s, init=%d, loader=%p, throwError=%d", name, init, loader, throwError);
-#endif
+       TRACEJVMCALLS("JVM_FindClassFromClassLoader: name=%s, init=%d, loader=%p, throwError=%d", name, init, loader, throwError);
+
+       u  = utf_new_char(name);
+       cl = (classloader *) loader;
 
-       c = load_class_from_classloader(utf_new_char(name), (java_objectheader *) loader);
+       c = load_class_from_classloader(u, cl);
 
        if (c == NULL)
                return NULL;
@@ -668,7 +712,7 @@ jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init
                        if (!initialize_class(c))
                                return NULL;
 
-       return (jclass) c;
+       return (jclass) LLNI_classinfo_wrap(c);
 }
 
 
@@ -692,13 +736,20 @@ 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)
 {
-#if PRINTJVM
-       log_println("JVM_DefineClassWithSource: name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s", name, loader, buf, len, pd, source);
-#endif
-       /* XXX do something with pd and source */
+       classinfo   *c;
+       utf         *u;
+       classloader *cl;
+
+       TRACEJVMCALLS("JVM_DefineClassWithSource(env=%p, name=%s, loader=%p, buf=%p, len=%d, pd=%p, source=%s)", env, name, loader, buf, len, pd, source);
 
-       return (jclass) class_define(utf_new_char(name), (java_objectheader *) loader, len, (u1 *) buf);
+       u  = utf_new_char(name);
+       cl = (classloader *) loader;
 
+       /* XXX do something with source */
+
+       c = class_define(u, cl, len, (const uint8_t *) buf, (java_handle_t *) pd);
+
+       return (jclass) LLNI_classinfo_wrap(c);
 }
 
 
@@ -706,10 +757,18 @@ jclass JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader,
 
 jclass JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
 {
-#if PRINTJVM
-       log_println("JVM_FindLoadedClass: loader=%p, name=%p", loader, name);
-#endif
-       return (jclass) classcache_lookup((classloader *) loader, javastring_toutf(name, true));
+       classloader *cl;
+       utf         *u;
+       classinfo   *c;
+
+       TRACEJVMCALLS("JVM_FindLoadedClass(env=%p, loader=%p, name=%p)", env, loader, name);
+
+       cl = (classloader *) loader;
+
+       u = javastring_toutf((java_handle_t *) name, true);
+       c = classcache_lookup(cl, u);
+
+       return (jclass) LLNI_classinfo_wrap(c);
 }
 
 
@@ -728,10 +787,16 @@ jstring JVM_GetClassName(JNIEnv *env, jclass cls)
 
 jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassInterfaces: cls=%p", cls);
-#endif
-       return (jobjectArray) _Jv_java_lang_Class_getInterfaces((java_lang_Class *) cls);
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS("JVM_GetClassInterfaces(env=%p, cls=%p)", env, cls);
+
+       c = LLNI_classinfo_unwrap(cls);
+
+       oa = class_get_interfaces(c);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -739,9 +804,8 @@ jobjectArray JVM_GetClassInterfaces(JNIEnv *env, jclass cls)
 
 jobject JVM_GetClassLoader(JNIEnv *env, jclass cls)
 {
-#if PRINTJVM
-       log_println("JVM_GetClassLoader: cls=%p", cls);
-#endif
+       TRACEJVMCALLS("JVM_GetClassLoader(env=%p, cls=%p)", env, cls);
+
        return (jobject) _Jv_java_lang_Class_getClassLoader((java_lang_Class *) cls);
 }
 
@@ -756,7 +820,7 @@ jboolean JVM_IsInterface(JNIEnv *env, jclass cls)
        log_println("JVM_IsInterface: cls=%p", cls);
 #endif
 
-       c = (classinfo *) cls;
+       c = LLNI_classinfo_unwrap(cls);
 
        return class_is_interface(c);
 }
@@ -784,11 +848,9 @@ jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-#if PRINTJVM || 1
-       log_println("JVM_GetProtectionDomain: cls=%p");
-#endif
+       TRACEJVMCALLS("JVM_GetProtectionDomain(env=%p, cls=%p)", env, cls);
 
-       c = (classinfo *) cls;
+       c = LLNI_classinfo_unwrap(cls);
 
        if (c == NULL) {
                exceptions_throw_nullpointerexception();
@@ -799,6 +861,8 @@ jobject JVM_GetProtectionDomain(JNIEnv *env, jclass cls)
 
        if (class_is_primitive(c))
                return NULL;
+
+       return (jobject) c->protectiondomain;
 }
 
 
@@ -814,17 +878,17 @@ void JVM_SetProtectionDomain(JNIEnv *env, jclass cls, jobject protection_domain)
 
 jobject JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)
 {
-       java_objectheader *o;
-       classinfo         *c;
-       methodinfo        *m;
-       java_objectheader *result;
-       java_objectheader *e;
+       java_handle_t *o;
+       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
 
-       o = (java_objectheader *) action;
+       o = (java_handle_t *) action;
        c = o->vftbl->class;
 
        if (action == NULL) {
@@ -881,7 +945,7 @@ jboolean JVM_IsArrayClass(JNIEnv *env, jclass cls)
 #if PRINTJVM
        log_println("JVM_IsArrayClass: cls=%p", cls);
 #endif
-       return class_is_array((classinfo *) cls);
+       return class_is_array(LLNI_classinfo_unwrap(cls));
 }
 
 
@@ -891,7 +955,7 @@ jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
 {
        classinfo *c;
 
-       c = (classinfo *) cls;
+       c = LLNI_classinfo_unwrap(cls);
 
 #if PRINTJVM
        log_println("JVM_IsPrimitiveClass(cls=%p)", cls);
@@ -905,10 +969,16 @@ jboolean JVM_IsPrimitiveClass(JNIEnv *env, jclass cls)
 
 jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
 {
-#if PRINTJVM
-       log_println("JVM_GetComponentType: cls=%p", cls);
-#endif
-       return (jclass) _Jv_java_lang_Class_getComponentType((java_lang_Class *) cls);
+       classinfo *component;
+       classinfo *c;
+       
+       TRACEJVMCALLS("JVM_GetComponentType(env=%p, cls=%p)", env, cls);
+
+       c = LLNI_classinfo_unwrap(cls);
+       
+       component = class_get_componenttype(c);
+
+       return (jclass) LLNI_classinfo_wrap(component);
 }
 
 
@@ -922,7 +992,7 @@ jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
        log_println("JVM_GetClassModifiers: cls=%p", cls);
 #endif
 
-       c = (classinfo *) cls;
+       c = LLNI_classinfo_unwrap(cls);
 
        /* XXX is this correct? */
 
@@ -934,7 +1004,16 @@ jint JVM_GetClassModifiers(JNIEnv *env, jclass cls)
 
 jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
 {
-       log_println("JVM_GetDeclaredClasses: IMPLEMENT ME!");
+       classinfo                 *c;
+       java_handle_objectarray_t *oa;
+
+       TRACEJVMCALLS("JVM_GetDeclaredClasses(env=%p, ofClass=%p)", env, ofClass);
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       oa = class_get_declaredclasses(c, false);
+
+       return (jobjectArray) oa;
 }
 
 
@@ -942,7 +1021,16 @@ jobjectArray JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass)
 
 jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
 {
-       log_println("JVM_GetDeclaringClass: IMPLEMENT ME!");
+       classinfo *c;
+       classinfo *dc;
+
+       TRACEJVMCALLS("JVM_GetDeclaringClass(env=%p, ofClass=%p)", env, ofClass);
+
+       c = LLNI_classinfo_unwrap(ofClass);
+
+       dc = class_get_declaringclass(c);
+
+       return (jclass) LLNI_classinfo_wrap(dc);
 }
 
 
@@ -950,7 +1038,26 @@ jclass JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass)
 
 jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
 {
-       log_println("JVM_GetClassSignature: IMPLEMENT ME!");
+       classinfo     *c;
+       utf           *u;
+       java_object_t *s;
+
+       TRACEJVMCALLS("JVM_GetClassSignature(env=%p, cls=%p)", env, cls);
+
+       c = (classinfo *) cls;
+
+       /* Get the signature of the class. */
+
+       u = class_get_signature(c);
+
+       if (u == NULL)
+               return NULL;
+
+       /* Convert UTF-string to a Java-string. */
+
+       s = javastring_new(u);
+
+       return (jstring) s;
 }
 
 
@@ -958,7 +1065,22 @@ jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
 
 jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 {
-       log_println("JVM_GetClassAnnotations: IMPLEMENT ME!");
+       classinfo               *c           = NULL;
+       java_handle_bytearray_t *annotations = NULL;
+
+       TRACEJVMCALLS("JVM_GetClassAnnotations: cls=%p", cls);
+
+       if (cls == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+       
+       c = LLNI_classinfo_unwrap(cls);
+
+       /* get annotations: */
+       annotations = class_get_annotations(c);
+
+       return (jbyteArray)annotations;
 }
 
 
@@ -966,7 +1088,19 @@ jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 
 jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
 {
-       log_println("JVM_GetFieldAnnotations: IMPLEMENT ME!");
+       java_lang_reflect_Field *rf = (java_lang_reflect_Field*)field;
+       java_handle_bytearray_t *ba = NULL;
+
+       TRACEJVMCALLS("JVM_GetFieldAnnotations: field=%p", field);
+
+       if (field == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       LLNI_field_get_ref(rf, annotations, ba);
+
+       return (jbyteArray)ba;
 }
 
 
@@ -974,7 +1108,19 @@ jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
 
 jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
 {
-       log_println("JVM_GetMethodAnnotations: IMPLEMENT ME!");
+       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
+       java_handle_bytearray_t  *ba = NULL;
+
+       TRACEJVMCALLS("JVM_GetMethodAnnotations: method=%p", method);
+
+       if (method == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       LLNI_field_get_ref(rm, annotations, ba);
+
+       return (jbyteArray)ba;
 }
 
 
@@ -982,7 +1128,19 @@ jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
 
 jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
 {
-       log_println("JVM_GetMethodDefaultAnnotationValue: IMPLEMENT ME!");
+       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
+       java_handle_bytearray_t  *ba = NULL;
+
+       TRACEJVMCALLS("JVM_GetMethodDefaultAnnotationValue: method=%p", method);
+
+       if (method == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       LLNI_field_get_ref(rm, annotationDefault, ba);
+
+       return (jbyteArray)ba;
 }
 
 
@@ -990,7 +1148,19 @@ jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
 
 jbyteArray JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)
 {
-       log_println("JVM_GetMethodParameterAnnotations: IMPLEMENT ME!");
+       java_lang_reflect_Method *rm = (java_lang_reflect_Method*)method;
+       java_handle_bytearray_t  *ba = NULL;
+
+       TRACEJVMCALLS("JVM_GetMethodParameterAnnotations: method=%p", method);
+
+       if (method == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       LLNI_field_get_ref(rm, parameterAnnotations, ba);
+
+       return (jbyteArray)ba;
 }
 
 
@@ -1037,7 +1207,7 @@ jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
        log_println("JVM_GetClassAccessFlags: cls=%p", cls);
 #endif
 
-       c = (classinfo *) cls;
+       c = LLNI_classinfo_unwrap(cls);
 
        return c->flags & ACC_CLASS_REFLECT_MASK;
 }
@@ -1047,7 +1217,28 @@ jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
 
 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
 {
-       log_println("JVM_GetClassConstantPool: IMPLEMENT ME!");
+#if defined(ENABLE_ANNOTATIONS)
+       sun_reflect_ConstantPool *constantPool    = NULL;
+       java_lang_Object         *constantPoolOop = (java_lang_Object*)cls;
+       
+       TRACEJVMCALLS("JVM_GetClassConstantPool(env=%p, cls=%p)", env, cls);
+
+       constantPool = 
+               (sun_reflect_ConstantPool*)native_new_and_init(
+                       class_sun_reflect_ConstantPool);
+       
+       if (constantPool == NULL) {
+               /* out of memory */
+               return NULL;
+       }
+       
+       LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
+
+       return (jobject)constantPool;
+#else
+       log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
+       return NULL;
+#endif
 }
 
 
@@ -1055,7 +1246,13 @@ jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
 
 jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
 {
-       log_println("JVM_ConstantPoolGetSize: IMPLEMENT ME!");
+       classinfo *c;
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetSize(env=%p, unused=%p, jcpool=%p)", env, unused, jcpool);
+
+       c = LLNI_classinfo_unwrap(jcpool);
+
+       return c->cpcount;
 }
 
 
@@ -1063,7 +1260,22 @@ jint JVM_ConstantPoolGetSize(JNIEnv *env, jobject unused, jobject jcpool)
 
 jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetClassAt: IMPLEMENT ME!");
+       constant_classref *ref;
+       classinfo         *c;
+       classinfo         *result;
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetClassAt(env=%p, jcpool=%p, index=%d)", env, jcpool, index);
+
+       c = LLNI_classinfo_unwrap(jcpool);
+
+       ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
+
+       if (ref == NULL)
+               return NULL;
+
+       result = resolve_classref_eager(ref);
+
+       return (jclass) LLNI_classinfo_wrap(result);
 }
 
 
@@ -1071,7 +1283,27 @@ jclass JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject unused, jobject jcpool, j
 
 jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetClassAtIfLoaded: IMPLEMENT ME!");
+       constant_classref *ref;
+       classinfo         *c;
+       classinfo         *result;
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetClassAtIfLoaded(env=%p, unused=%p, jcpool=%p, index=%d)", env, unused, jcpool, index);
+
+       c = LLNI_classinfo_unwrap(jcpool);
+
+       ref = (constant_classref *) class_getconstant(c, index, CONSTANT_Class);
+
+       if (ref == NULL)
+               return NULL;
+       
+       if (!resolve_classref(NULL, ref, resolveLazy, true, true, &result))
+               return NULL;
+
+       if ((result == NULL) || !(result->state & CLASS_LOADED)) {
+               return NULL;
+       }
+       
+       return (jclass) LLNI_classinfo_wrap(result);
 }
 
 
@@ -1079,7 +1311,19 @@ jclass JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject unused, jobject j
 
 jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetMethodAt: IMPLEMENT ME!");
+       constant_FMIref *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       
+       TRACEJVMCALLS("JVM_ConstantPoolGetMethodAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
+       
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       /* XXX: is that right? or do I have to use resolve_method_*? */
+       return (jobject)reflect_method_new(ref->p.method);
 }
 
 
@@ -1087,7 +1331,27 @@ jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetMethodAtIfLoaded: IMPLEMENT ME!");
+       constant_FMIref *ref;
+       classinfo *c = NULL;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetMethodAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Methodref);
+
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
+               return NULL;
+       }
+
+       if (c == NULL || !(c->state & CLASS_LOADED)) {
+               return NULL;
+       }
+
+       return (jobject)reflect_method_new(ref->p.method);
 }
 
 
@@ -1095,7 +1359,18 @@ jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject
 
 jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetFieldAt: IMPLEMENT ME!");
+       constant_FMIref *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+       
+       TRACEJVMCALLS("JVM_ConstantPoolGetFieldAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
+
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       return (jobject)reflect_field_new(ref->p.field);
 }
 
 
@@ -1103,7 +1378,27 @@ jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetFieldAtIfLoaded: IMPLEMENT ME!");
+       constant_FMIref *ref;
+       classinfo *c;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetFieldAtIfLoaded: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_FMIref*)class_getconstant(cls, index, CONSTANT_Fieldref);
+
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       if (!resolve_classref(NULL, ref->p.classref, resolveLazy, true, true, &c)) {
+               return NULL;
+       }
+
+       if (c == NULL || !(c->state & CLASS_LOADED)) {
+               return NULL;
+       }
+
+       return (jobject)reflect_field_new(ref->p.field);
 }
 
 
@@ -1111,7 +1406,8 @@ jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject
 
 jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetMemberRefInfoAt: IMPLEMENT ME!");
+       log_println("JVM_ConstantPoolGetMemberRefInfoAt: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
+       return NULL;
 }
 
 
@@ -1119,7 +1415,18 @@ jobjectArray JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject unused, job
 
 jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetIntAt: IMPLEMENT ME!");
+       constant_integer *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetIntAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_integer*)class_getconstant(cls, index, CONSTANT_Integer);
+
+       if (ref == NULL) {
+               return 0;
+       }
+
+       return ref->value;
 }
 
 
@@ -1127,7 +1434,18 @@ jint JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject unused, jobject jcpool, jint
 
 jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetLongAt: IMPLEMENT ME!");
+       constant_long *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetLongAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_long*)class_getconstant(cls, index, CONSTANT_Long);
+
+       if (ref == NULL) {
+               return 0;
+       }
+
+       return ref->value;
 }
 
 
@@ -1135,7 +1453,18 @@ jlong JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject unused, jobject jcpool, jin
 
 jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetFloatAt: IMPLEMENT ME!");
+       constant_float *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetFloatAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_float*)class_getconstant(cls, index, CONSTANT_Float);
+
+       if (ref == NULL) {
+               return 0;
+       }
+
+       return ref->value;
 }
 
 
@@ -1143,7 +1472,18 @@ jfloat JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject unused, jobject jcpool, j
 
 jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetDoubleAt: IMPLEMENT ME!");
+       constant_double *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetDoubleAt: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (constant_double*)class_getconstant(cls, index, CONSTANT_Double);
+
+       if (ref == NULL) {
+               return 0;
+       }
+
+       return ref->value;
 }
 
 
@@ -1151,7 +1491,19 @@ jdouble JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetStringAt: IMPLEMENT ME!");
+       utf *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetStringAt: jcpool=%p, index=%d", jcpool, index);
+       
+       ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
+
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       /* XXX: I hope literalstring_new is the right Function. */
+       return (jstring)literalstring_new(ref);
 }
 
 
@@ -1159,7 +1511,19 @@ jstring JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject unused, jobject jcpool,
 
 jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, jint index)
 {
-       log_println("JVM_ConstantPoolGetUTF8At: IMPLEMENT ME!");
+       utf *ref;
+       classinfo *cls = LLNI_classinfo_unwrap(jcpool);
+
+       TRACEJVMCALLS("JVM_ConstantPoolGetUTF8At: jcpool=%p, index=%d", jcpool, index);
+
+       ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
+
+       if (ref == NULL) {
+               return NULL;
+       }
+
+       /* XXX: I hope literalstring_new is the right Function. */
+       return (jstring)literalstring_new(ref);
 }
 
 
@@ -1167,7 +1531,9 @@ jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, j
 
 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
 {
-       log_println("JVM_DesiredAssertionStatus: cls=%p, IMPLEMENT ME!", cls);
+       TRACEJVMCALLS("JVM_DesiredAssertionStatus(env=%p, unused=%p, cls=%p)", env, unused, cls);
+
+       /* TODO: Implement this one, but false should be OK. */
 
        return false;
 }
@@ -1177,10 +1543,10 @@ jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
 
 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
 {
-       classinfo         *c;
+       classinfo                           *c;
        java_lang_AssertionStatusDirectives *o;
-       java_objectarray  *classes;
-       java_objectarray  *packages;
+       java_handle_objectarray_t           *classes;
+       java_handle_objectarray_t           *packages;
 
 #if PRINTJVM || 1
        log_println("JVM_AssertionStatusDirectives");
@@ -1522,68 +1888,20 @@ jint JVM_Write(jint fd, char *buf, jint nbytes)
 jint JVM_Available(jint fd, jlong *pbytes)
 {
 #if defined(FIONREAD)
-       ssize_t n;
+       int bytes;
+
+       TRACEJVMCALLS("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes);
 
        *pbytes = 0;
 
-       if (ioctl(fd, FIONREAD, (char *) &n) != 0)
+       if (ioctl(fd, FIONREAD, &bytes) < 0)
                return 0;
 
-       *pbytes = n;
+       *pbytes = bytes;
 
        return 1;
-#elif defined(HAVE_FSTAT)
-       struct stat statBuffer;
-       off_t n;
-       int result;
-
-       *pbytes = 0;
-
-       if ((fstat(fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode)) {
-               n = lseek (fd, 0, SEEK_CUR);
-
-               if (n != -1) {
-                       *pbytes = statBuffer.st_size - n; 
-                       result = 1;
-               }
-               else {
-                       result = 0;
-               }
-       }
-       else {
-               result = 0;
-       }
-  
-       return result;
-#elif defined(HAVE_SELECT)
-       fd_set filedescriptset;
-       struct timeval tv;
-       int result;
-
-       *pbytes = 0;
-  
-       FD_ZERO(&filedescriptset);
-       FD_SET(fd, &filedescriptset);
-       memset(&tv, 0, sizeof(tv));
-
-       switch (select(fd+1, &filedescriptset, NULL, NULL, &tv))
-               {
-               case -1: 
-                       result = errno; 
-                       break;
-               case  0:
-                       *pbytes = 0;
-                       result = CPNATIVE_OK;
-                       break;      
-               default: 
-                       *pbytes = 1;
-                       result = CPNATIVE_OK;
-                       break;
-               }
-       return result;
 #else
-       *pbytes = 0;
-       return 0;
+# error FIONREAD not defined
 #endif
 }
 
@@ -1676,7 +1994,9 @@ void JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio)
 
 void JVM_Yield(JNIEnv *env, jclass threadClass)
 {
-       log_println("JVM_Yield: IMPLEMENT ME!");
+       TRACEJVMCALLS("JVM_Yield(env=%p, threadClass=%p)", env, threadClass);
+
+       threads_yield();
 }
 
 
@@ -1758,6 +2078,9 @@ jclass JVM_CurrentLoadedClass(JNIEnv *env)
 
 jobject JVM_CurrentClassLoader(JNIEnv *env)
 {
+    /* XXX if a method in a class in a trusted loader is in a
+          doPrivileged, return NULL */
+
        log_println("JVM_CurrentClassLoader: IMPLEMENT ME!");
 }
 
@@ -1793,7 +2116,11 @@ jint JVM_ClassLoaderDepth(JNIEnv *env)
 
 jstring JVM_GetSystemPackage(JNIEnv *env, jstring name)
 {
-       log_println("JVM_GetSystemPackage: IMPLEMENT ME!");
+       log_println("JVM_GetSystemPackage(env=%p, name=%p)");
+       javastring_print((java_handle_t *) name);
+       printf("\n");
+
+       return NULL;
 }
 
 
@@ -1841,7 +2168,13 @@ jclass JVM_LoadClass0(JNIEnv *env, jobject receiver, jclass currClass, jstring c
 
 jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
 {
-       log_println("JVM_GetArrayLength: IMPLEMENT ME!");
+       java_handle_t *a;
+
+       TRACEJVMCALLS("JVM_GetArrayLength(arr=%p)", arr);
+
+       a = (java_handle_t *) arr;
+
+       return array_length_get(a);
 }
 
 
@@ -1849,7 +2182,21 @@ jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
 
 jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
 {
-       log_println("JVM_GetArrayElement: IMPLEMENT ME!");
+       java_handle_t *a;
+       java_handle_t *o;
+
+       TRACEJVMCALLS("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index);
+
+       a = (java_handle_t *) arr;
+
+/*     if (!class_is_array(a->objheader.vftbl->class)) { */
+/*             exceptions_throw_illegalargumentexception(); */
+/*             return NULL; */
+/*     } */
+
+       o = array_element_get(a, index);
+
+       return (jobject) o;
 }
 
 
@@ -1865,7 +2212,15 @@ jvalue JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint w
 
 void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
 {
-       log_println("JVM_SetArrayElement: IMPLEMENT ME!");
+       java_handle_t *a;
+       java_handle_t *value;
+
+       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;
+
+       array_element_set(a, index, value);
 }
 
 
@@ -1881,16 +2236,14 @@ void JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v
 
 jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
 {
-       classinfo        *c;
-       classinfo        *pc;
-       java_arrayheader *a;
-       java_objectarray *oa;
+       classinfo                 *c;
+       classinfo                 *pc;
+       java_handle_t             *a;
+       java_handle_objectarray_t *oa;
 
-       c = (classinfo *) eltClass;
+       TRACEJVMCALLS("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length);
 
-#if PRINTJVM
-       log_println("JVM_NewArray(eltClass=%p, length=%d)", eltClass, length);
-#endif
+       c = LLNI_classinfo_unwrap(eltClass);
 
        /* create primitive or object array */
 
@@ -1928,9 +2281,8 @@ jint JVM_InitializeSocketLibrary()
 
 jint JVM_Socket(jint domain, jint type, jint protocol)
 {
-#if PRINTJVM || 1
-       log_println("JVM_Socket: domain=%d, type=%d, protocol=%d", domain, type, protocol);
-#endif
+       TRACEJVMCALLS("JVM_Socket(domain=%d, type=%d, protocol=%d)", domain, type, protocol);
+
        return socket(domain, type, protocol);
 }
 
@@ -1939,9 +2291,8 @@ jint JVM_Socket(jint domain, jint type, jint protocol)
 
 jint JVM_SocketClose(jint fd)
 {
-#if PRINTJVM || 1
-       log_println("JVM_SocketClose: fd=%d", fd);
-#endif
+       TRACEJVMCALLS("JVM_SocketClose(fd=%d)", fd);
+
        return close(fd);
 }
 
@@ -1950,9 +2301,8 @@ jint JVM_SocketClose(jint fd)
 
 jint JVM_SocketShutdown(jint fd, jint howto)
 {
-#if PRINTJVM || 1
-       log_println("JVM_SocketShutdown: fd=%d, howto=%d", fd, howto);
-#endif
+       TRACEJVMCALLS("JVM_SocketShutdown(fd=%d, howto=%d)", fd, howto);
+
        return shutdown(fd, howto);
 }
 
@@ -1985,9 +2335,8 @@ jint JVM_Timeout(int fd, long timeout)
 
 jint JVM_Listen(jint fd, jint count)
 {
-#if PRINTJVM || 1
-       log_println("JVM_Listen: fd=%d, count=%d", fd, count);
-#endif
+       TRACEJVMCALLS("JVM_Listen(fd=%d, count=%d)", fd, count);
+
        return listen(fd, count);
 }
 
@@ -1996,9 +2345,8 @@ jint JVM_Listen(jint fd, jint count)
 
 jint JVM_Connect(jint fd, struct sockaddr *him, jint len)
 {
-#if PRINTJVM || 1
-       log_println("JVM_Connect: fd=%d, him=%p, len=%d", fd, him, len);
-#endif
+       TRACEJVMCALLS("JVM_Connect(fd=%d, him=%p, len=%d)", fd, him, len);
+
        return connect(fd, him, len);
 }
 
@@ -2015,9 +2363,8 @@ jint JVM_Bind(jint fd, struct sockaddr *him, jint len)
 
 jint JVM_Accept(jint fd, struct sockaddr *him, jint *len)
 {
-#if PRINTJVM || 1
-       log_println("JVM_Accept: fd=%d, him=%p, len=%p", fd, him, len);
-#endif
+       TRACEJVMCALLS("JVM_Accept(fd=%d, him=%p, len=%p)", fd, him, len);
+
        return accept(fd, him, (socklen_t *) len);
 }
 
@@ -2034,9 +2381,8 @@ jint JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *fr
 
 jint JVM_GetSockName(jint fd, struct sockaddr *him, int *len)
 {
-#if PRINTJVM || 1
-       log_println("JVM_GetSockName: fd=%d, him=%p, len=%p", fd, him, len);
-#endif
+       TRACEJVMCALLS("JVM_GetSockName(fd=%d, him=%p, len=%p)", fd, him, len);
+
        return getsockname(fd, him, (socklen_t *) len);
 }
 
@@ -2069,9 +2415,8 @@ 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 PRINTJVM || 1
-       log_println("JVM_SetSockOpt: fd=%d, level=%d, optname=%d, optval=%s, optlen=%d", fd, level, optname, optval, optlen);
-#endif
+       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);
 }
 
@@ -2080,9 +2425,8 @@ jint JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int opt
 
 int JVM_GetHostName(char* name, int namelen)
 {
-#if PRINTJVM || 1
-       log_println("JVM_GetHostName: name=%s, namelen=%d", name, namelen);
-#endif
+       TRACEJVMCALLS("JVM_GetHostName(name=%s, namelen=%d)", name, namelen);
+
        return gethostname(name, namelen);
 }
 
@@ -2113,12 +2457,15 @@ struct protoent* JVM_GetProtoByName(char* name)
 
 /* JVM_LoadLibrary */
 
-void* JVM_LoadLibrary(const char* name)
+void *JVM_LoadLibrary(const char *name)
 {
-#if PRINTJVM
-       log_println("JVM_LoadLibrary: name=%s", name);
-#endif
-    return native_library_open(utf_new_char(name));
+       utf *u;
+
+       TRACEJVMCALLS("JVM_LoadLibrary(name=%s)", name);
+
+       u = utf_new_char(name);
+
+       return native_library_open(u);
 }
 
 
@@ -2132,13 +2479,11 @@ void JVM_UnloadLibrary(void* handle)
 
 /* JVM_FindLibraryEntry */
 
-void* JVM_FindLibraryEntry(void* handle, const char* name)
+void *JVM_FindLibraryEntry(void *handle, const char *name)
 {
        lt_ptr symbol;
 
-#if PRINTJVM
-       log_println("JVM_FindLibraryEntry: handle=%p, name=%s", handle, name);
-#endif
+       TRACEJVMCALLS("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name);
 
        symbol = lt_dlsym(handle, name);
 
@@ -2158,9 +2503,8 @@ jboolean JVM_IsNaN(jdouble a)
 
 jboolean JVM_IsSupportedJNIVersion(jint version)
 {
-#if PRINTJVM
-       log_println("JVM_IsSupportedJNIVersion: version=%d", version);
-#endif
+       TRACEJVMCALLS("JVM_IsSupportedJNIVersion(version=%d)", version);
+
        switch (version) {
        case JNI_VERSION_1_1:
        case JNI_VERSION_1_2:
@@ -2176,10 +2520,9 @@ jboolean JVM_IsSupportedJNIVersion(jint version)
 
 jstring JVM_InternString(JNIEnv *env, jstring str)
 {
-#if PRINTJVM
-       log_println("JVM_InternString: str=%p", str);
-#endif
-       return (jstring) _Jv_java_lang_String_intern((java_lang_String *) str);
+       TRACEJVMCALLS("JVM_InternString(env=%p, str=%p)", env, str);
+
+       return (jstring) javastring_intern((java_handle_t *) str);
 }
 
 
@@ -2187,13 +2530,13 @@ jstring JVM_InternString(JNIEnv *env, jstring str)
 
 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 {
-       java_objectheader *o;
+       java_object_t *o;
 
 #if PRINTJVM
        log_println("JVM_RawMonitorCreate");
 #endif
 
-       o = NEW(java_objectheader);
+       o = NEW(java_object_t);
 
        lock_init_object_lock(o);
 
@@ -2208,7 +2551,7 @@ JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
 #if PRINTJVM
        log_println("JVM_RawMonitorDestroy: mon=%p", mon);
 #endif
-       FREE(mon, java_objectheader);
+       FREE(mon, java_object_t);
 }
 
 
@@ -2219,7 +2562,7 @@ JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 #if PRINTJVM
        log_println("JVM_RawMonitorEnter: mon=%p", mon);
 #endif
-       (void) lock_monitor_enter((java_objectheader *) mon);
+       (void) lock_monitor_enter((java_object_t *) mon);
 
        return 0;
 }
@@ -2232,7 +2575,7 @@ JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
 #if PRINTJVM
        log_println("JVM_RawMonitorExit: mon=%p", mon);
 #endif
-       (void) lock_monitor_exit((java_objectheader *) mon);
+       (void) lock_monitor_exit((java_object_t *) mon);
 }
 
 
@@ -2371,7 +2714,7 @@ jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray
 #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_objectarray *) args0);
+       return (jobject) _Jv_java_lang_reflect_Method_invoke((java_lang_reflect_Method *) method, (java_lang_Object *) obj, (java_handle_objectarray_t *) args0);
 }
 
 
@@ -2382,7 +2725,7 @@ jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args
 #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_objectarray *) args0);
+       return (jobject) _Jv_java_lang_reflect_Constructor_newInstance(env, (java_lang_reflect_Constructor *) c, (java_handle_objectarray_t *) args0);
 }
 
 
@@ -2449,15 +2792,212 @@ jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
 
 jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
 {
-       log_println("JVM_GetThreadStateValues: IMPLEMENT ME!");
+       java_handle_intarray_t *ia;
+
+       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
+          states supported by the VM.  Return NULL if not compatible.
+       
+          This function must map the VM java_lang_Thread::ThreadStatus
+          to the Java thread state that the JDK supports. */
+
+       switch (javaThreadState) {
+    case THREAD_STATE_NEW:
+               ia = builtin_newarray_int(1);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
+               break; 
+
+    case THREAD_STATE_RUNNABLE:
+               ia = builtin_newarray_int(1);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
+               break; 
+
+    case THREAD_STATE_BLOCKED:
+               ia = builtin_newarray_int(1);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
+               break; 
+
+    case THREAD_STATE_WAITING:
+               ia = builtin_newarray_int(2);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
+               /* XXX Implement parked stuff. */
+/*             array_intarray_element_set(ia, 1, PARKED); */
+               break; 
+
+    case THREAD_STATE_TIMED_WAITING:
+               ia = builtin_newarray_int(3);
+
+               if (ia == NULL)
+                       return NULL;
+
+               /* XXX Not sure about that one. */
+/*             array_intarray_element_set(ia, 0, SLEEPING); */
+               array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
+               /* XXX Implement parked stuff. */
+/*             array_intarray_element_set(ia, 2, PARKED); */
+               break; 
+
+    case THREAD_STATE_TERMINATED:
+               ia = builtin_newarray_int(1);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
+               break; 
+
+    default:
+               /* Unknown state - probably incompatible JDK version */
+               return NULL;
+       }
+
+       return (jintArray) ia;
 }
 
 
-/* JVM_GetThreadStateValues */
+/* JVM_GetThreadStateNames */
 
 jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
 {
-       log_println("JVM_GetThreadStateValues: IMPLEMENT ME!");
+       java_handle_intarray_t    *ia;
+       java_handle_objectarray_t *oa;
+       java_object_t             *s;
+
+       TRACEJVMCALLS("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
+                                 env, javaThreadState, values);
+
+       ia = (java_handle_intarray_t *) values;
+
+       /* If new thread states are added in future JDK and VM versions,
+          this should check if the JDK version is compatible with thread
+          states supported by the VM.  Return NULL if not compatible.
+       
+          This function must map the VM java_lang_Thread::ThreadStatus
+          to the Java thread state that the JDK supports. */
+
+       if (values == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       switch (javaThreadState) {
+    case THREAD_STATE_NEW:
+               assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
+
+               oa = builtin_anewarray(1, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               s = javastring_new(utf_new_char("NEW"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 0, s);
+               break; 
+
+    case THREAD_STATE_RUNNABLE:
+               oa = builtin_anewarray(1, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               s = javastring_new(utf_new_char("RUNNABLE"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 0, s);
+               break; 
+
+    case THREAD_STATE_BLOCKED:
+               oa = builtin_anewarray(1, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               s = javastring_new(utf_new_char("BLOCKED"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 0, s);
+               break; 
+
+    case THREAD_STATE_WAITING:
+               oa = builtin_anewarray(2, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
+/*             s = javastring_new(utf_new_char("WAITING.PARKED")); */
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 0, s);
+/*             array_objectarray_element_set(oa, 1, s); */
+               break; 
+
+    case THREAD_STATE_TIMED_WAITING:
+               oa = builtin_anewarray(3, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+/*             s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
+               s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
+/*             s = javastring_new(utf_new_char("TIMED_WAITING.PARKED")); */
+
+               if (s == NULL)
+                       return NULL;
+
+/*             array_objectarray_element_set(oa, 0, s); */
+               array_objectarray_element_set(oa, 0, s);
+/*             array_objectarray_element_set(oa, 2, s); */
+               break; 
+
+    case THREAD_STATE_TERMINATED:
+               oa = builtin_anewarray(1, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               s = javastring_new(utf_new_char("TERMINATED"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 0, s);
+               break; 
+
+       default:
+               /* Unknown state - probably incompatible JDK version */
+               return NULL;
+       }
+
+       return (jobjectArray) oa;
 }
 
 
@@ -2471,10 +3011,53 @@ void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
 
 /* OS: JVM_RegisterSignal */
 
-void* JVM_RegisterSignal(jint sig, void* handler)
+void *JVM_RegisterSignal(jint sig, void *handler)
 {
-       log_println("JVM_RegisterSignal: sig=%d, handler=%p, IMPLEMENT ME!", sig, handler);
-       return NULL;
+       functionptr newHandler;
+
+       TRACEJVMCALLS("JVM_RegisterSignal(sig=%d, handler=%p)", sig, handler);
+
+       if (handler == (void *) 2)
+               newHandler = (functionptr) signal_thread_handler;
+       else
+               newHandler = (functionptr) (uintptr_t) handler;
+
+       switch (sig) {
+    case SIGILL:
+    case SIGFPE:
+    case SIGUSR1:
+    case SIGSEGV:
+               /* These signals are already used by the VM. */
+               return (void *) -1;
+
+    case SIGQUIT:
+               /* This signal is used by the VM to dump thread stacks unless
+                  ReduceSignalUsage is set, in which case the user is allowed
+                  to set his own _native_ handler for this signal; thus, in
+                  either case, we do not allow JVM_RegisterSignal to change
+                  the handler. */
+               return (void *) -1;
+
+       case SIGHUP:
+       case SIGINT:
+       case SIGTERM:
+               break;
+       }
+
+       signal_register_signal(sig, newHandler, 0);
+
+       /* XXX Should return old handler. */
+
+       return (void *) 2;
+}
+
+
+/* OS: JVM_RaiseSignal */
+
+jboolean JVM_RaiseSignal(jint sig)
+{
+       log_println("JVM_RaiseSignal: IMPLEMENT ME! sig=%s", sig);
+       return false;
 }
 
 
@@ -2482,8 +3065,22 @@ void* JVM_RegisterSignal(jint sig, void* handler)
 
 jint JVM_FindSignal(const char *name)
 {
-       log_println("JVM_FindSignal: name=%s", name);
-       return 0;
+       TRACEJVMCALLS("JVM_FindSignal(name=%s)", name);
+
+#if defined(__LINUX__)
+       if (strcmp(name, "HUP") == 0)
+               return SIGHUP;
+
+       if (strcmp(name, "INT") == 0)
+               return SIGINT;
+
+       if (strcmp(name, "TERM") == 0)
+               return SIGTERM;
+#else
+# error not implemented for this OS
+#endif
+
+       return -1;
 }