* src/vm/os.hpp (os::send): New function.
[cacao.git] / src / native / vm / openjdk / jvm.cpp
index fca4b7a888d07fa4dd1f498aea09712517ebbd30..9b393d3bf53ab69f17260117462762223109a0e9 100644 (file)
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include "vm/types.h"
+// Include our JNI header before the JVM headers, because the JVM
+// headers include jni.h and we want to override the typedefs in
+// jni.h.
+#include "native/jni.hpp"
+
+// We include jvm_md.h before jvm.h as the latter includes the former.
+#include INCLUDE_JVM_MD_H
+#include INCLUDE_JVM_H
 
 #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_String.h"            /* required by j.l.CL */
-#include "native/include/java_nio_ByteBuffer.h"         /* required by j.l.CL */
-#include "native/include/java_lang_ClassLoader.h"        /* required by j.l.C */
-#include "native/include/java_lang_StackTraceElement.h"
-#include "native/include/java_lang_Throwable.h"
-#include "native/include/java_security_ProtectionDomain.h"
-
-#if defined(ENABLE_ANNOTATIONS)
-#include "native/include/sun_reflect_ConstantPool.h"
-#endif
+#include "native/native.hpp"
 
-#include "native/vm/reflect.h"
+#include "native/vm/reflection.hpp"
 
-#include "native/vm/openjdk/hpi.h"
+#include "native/vm/openjdk/hpi.hpp"
+#include "native/vm/openjdk/management.hpp"
 
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
 #include "threads/thread.hpp"
 
 #include "toolbox/logging.h"
-#include "toolbox/list.h"
+#include "toolbox/list.hpp"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 
 #if defined(ENABLE_ASSERTION)
-#include "vm/assertion.h"
+#include "vm/assertion.hpp"
 #endif
 
-#include "vm/builtin.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/classcache.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
-#include "vm/initialize.h"
+#include "vm/globals.hpp"
+#include "vm/initialize.hpp"
+#include "vm/javaobjects.hpp"
+#include "vm/options.h"
+#include "vm/os.hpp"
 #include "vm/package.hpp"
 #include "vm/primitive.hpp"
-#include "vm/properties.h"
-#include "vm/resolve.h"
+#include "vm/properties.hpp"
+#include "vm/resolve.hpp"
 #include "vm/signallocal.h"
 #include "vm/string.hpp"
 #include "vm/vm.hpp"
 
 #include "vm/jit/stacktrace.hpp"
 
-#include "vmcore/classcache.h"
-#include "vmcore/globals.hpp"
-#include "vmcore/options.h"
-#include "vmcore/os.hpp"
-
 
 /* debugging macros ***********************************************************/
 
 #endif
 
 
-typedef struct {
-    /* Naming convention of RE build version string: n.n.n[_uu[c]][-<identifier>]-bxx */
-    unsigned int jvm_version;   /* Consists of major, minor, micro (n.n.n) */
-                                /* and build number (xx) */
-    unsigned int update_version : 8;         /* Update release version (uu) */
-    unsigned int special_update_version : 8; /* Special update release version (c) */
-    unsigned int reserved1 : 16; 
-    unsigned int reserved2; 
-
-    /* The following bits represents JVM supports that JDK has dependency on.
-     * JDK can use these bits to determine which JVM version
-     * and support it has to maintain runtime compatibility.
-     *
-     * When a new bit is added in a minor or update release, make sure
-     * the new bit is also added in the main/baseline.
-     */
-    unsigned int is_attachable : 1;
-    unsigned int : 31;
-    unsigned int : 32;
-    unsigned int : 32;
-} jvm_version_info;
-
-
-/*
- * A structure used to a capture exception table entry in a Java method.
- */
-typedef struct {
-    jint start_pc;
-    jint end_pc;
-    jint handler_pc;
-    jint catchType;
-} JVM_ExceptionTableEntryType;
-
-
 // Interface functions are exported as C functions.
 extern "C" {
 
@@ -297,11 +258,10 @@ jobject JVM_InitProperties(JNIEnv *env, jobject properties)
           -D option, as requested. */
 
        jio_snprintf(buf, sizeof(buf), PRINTF_FORMAT_INT64_T, opt_MaxDirectMemorySize);
-       properties_add("sun.nio.MaxDirectMemorySize", buf);
-
-       /* Add all properties. */
+       VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
 
-       properties_system_add_all(h);
+       // Fill the java.util.Properties object.
+       VM::get_current()->get_properties().fill(h);
 
        return properties;
 }
@@ -414,19 +374,14 @@ jint JVM_ActiveProcessorCount(void)
 
 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));
 
-       o = (java_lang_Throwable *) receiver;
-
-       ba = stacktrace_get_current();
+       java_handle_bytearray_t* ba = stacktrace_get_current();
 
        if (ba == NULL)
                return;
 
-       LLNI_field_set_ref(o, backtrace, (java_lang_Object *) ba);
+       java_lang_Throwable jlt(receiver, ba);
 }
 
 
@@ -442,36 +397,28 @@ void JVM_PrintStackTrace(JNIEnv *env, jobject receiver, jobject printable)
 
 jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
 {
-       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));
 
-       if (throwable == NULL) {
+       java_lang_Throwable jlt(throwable);
+
+       if (jlt.is_null()) {
                exceptions_throw_nullpointerexception();
                return 0;
        }
 
-       to = (java_lang_Throwable *) throwable;
-
-       LLNI_field_get_ref(to, backtrace, o);
-
-       ba = (java_handle_bytearray_t *) o;
+       java_handle_bytearray_t* ba = jlt.get_backtrace();
 
        if (ba == NULL)
                return 0;
 
-       /* We need a critical section here as the stacktrace structure is
-          mapped onto a Java byte-array. */
+       // We need a critical section here as the stacktrace structure is
+       // mapped onto a Java byte-array.
 
        LLNI_CRITICAL_START;
 
-       st = (stacktrace_t *) LLNI_array_data(ba);
+       stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
 
-       depth = st->length;
+       int32_t depth = st->length;
 
        LLNI_CRITICAL_END;
 
@@ -483,95 +430,69 @@ jint JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable)
 
 jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
 {
-       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 *steo;
-       java_handle_t*               declaringclass;
-       java_lang_String            *filename;
-       int32_t                      linenumber;
-
        TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
 
-       to = (java_lang_Throwable *) throwable;
-
-       LLNI_field_get_ref(to, backtrace, o);
-
-       ba = (java_handle_bytearray_t *) o;
+       java_lang_Throwable jlt(throwable);
+       java_handle_bytearray_t* ba = jlt.get_backtrace();
 
-       /* FIXME critical section */
+       // We need a critical section here as the stacktrace structure is
+       // mapped onto a Java byte-array.
+       LLNI_CRITICAL_START;
 
-       st = (stacktrace_t *) LLNI_array_data(ba);
+       stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
 
        if ((index < 0) || (index >= st->length)) {
                /* XXX This should be an IndexOutOfBoundsException (check this
                   again). */
-
                exceptions_throw_arrayindexoutofboundsexception();
                return NULL;
        }
 
-       /* Get the stacktrace entry. */
-
-       ste = &(st->entries[index]);
-
-       /* Get the codeinfo, methodinfo and classinfo. */
+       // Get the stacktrace entry.
+       stacktrace_entry_t* ste = &(st->entries[index]);
 
-       code = ste->code;
-       m    = code->m;
-       c    = m->clazz;
+       // Get the codeinfo, methodinfo and classinfo.
+       codeinfo*   code = ste->code;
+       methodinfo* m    = code->m;
+       classinfo*  c    = m->clazz;
 
-       /* allocate a new StackTraceElement */
-
-       steo = (java_lang_StackTraceElement *)
-               builtin_new(class_java_lang_StackTraceElement);
-
-       if (steo == NULL)
-               return NULL;
-
-       /* get filename */
+       // Get filename.
+       java_handle_t* filename;
 
        if (!(m->flags & ACC_NATIVE)) {
                if (c->sourcefile != NULL)
-                       filename = (java_lang_String *) javastring_new(c->sourcefile);
+                       filename = javastring_new(c->sourcefile);
                else
                        filename = NULL;
        }
        else
                filename = NULL;
 
-       /* get line number */
+       // Get line number.
+       int32_t linenumber;
 
        if (m->flags & ACC_NATIVE) {
                linenumber = -2;
        }
        else {
-               /* FIXME The linenumbertable_linenumber_for_pc could change
-                  the methodinfo pointer when hitting an inlined method. */
-
-               linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
+               // FIXME linenumbertable->find could change the methodinfo
+               // pointer when hitting an inlined method.
+               linenumber = code->linenumbertable->find(&m, ste->pc);
                linenumber = (linenumber == 0) ? -1 : linenumber;
        }
 
-       /* get declaring class name */
-
-       declaringclass = class_get_classname(c);
+       LLNI_CRITICAL_END;
 
-       /* fill the java.lang.StackTraceElement element */
+       // Get declaring class name.
+       java_handle_t* declaringclass = class_get_classname(c);
 
-       /* FIXME critical section */
+       // Allocate a new StackTraceElement object.
+       java_lang_StackTraceElement jlste(declaringclass, javastring_new(m->name), filename, linenumber);
 
-       steo->declaringClass = (java_lang_String*) declaringclass;
-       steo->methodName     = (java_lang_String*) javastring_new(m->name);
-       steo->fileName       = filename;
-       steo->lineNumber     = linenumber;
+       if (jlste.is_null())
+               return NULL;
 
-       return (jobject) steo;
+       return (jobject) jlste.get_handle();
 }
 
 
@@ -581,7 +502,9 @@ jint JVM_IHashCode(JNIEnv* env, jobject handle)
 {
        TRACEJVMCALLS(("JVM_IHashCode(env=%p, jobject=%p)", env, handle));
 
-       return (jint) ((ptrint) handle);
+       java_lang_Object o(handle);
+
+       return o.get_hashcode();
 }
 
 
@@ -722,21 +645,23 @@ void JVM_DisableCompiler(JNIEnv *env, jclass compCls)
 
 /* JVM_GetLastErrorString */
 
-jint JVM_GetLastErrorString(char *buf, int len)
+jint JVM_GetLastErrorString(charbuf, int len)
 {
        TRACEJVMCALLS(("JVM_GetLastErrorString(buf=%p, len=%d", buf, len));
 
-       return hpi_system->GetLastErrorString(buf, len);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_system().GetLastErrorString(buf, len);
 }
 
 
 /* JVM_NativePath */
 
-char *JVM_NativePath(char *path)
+char *JVM_NativePath(charpath)
 {
        TRACEJVMCALLS(("JVM_NativePath(path=%s)", path));
 
-       return hpi_file->NativePath(path);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().NativePath(path);
 }
 
 
@@ -1207,22 +1132,19 @@ jstring JVM_GetClassSignature(JNIEnv *env, jclass cls)
 
 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(env=%p, cls=%p)", env, cls));
 
        if (cls == NULL) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
        
-       c = LLNI_classinfo_unwrap(cls);
+       classinfo* c = LLNI_classinfo_unwrap(cls);
 
        /* get annotations: */
-       annotations = class_get_annotations(c);
+       java_handle_bytearray_t* annotations = class_get_annotations(c);
 
-       return (jbyteArray)annotations;
+       return (jbyteArray) annotations;
 }
 
 
@@ -1230,21 +1152,16 @@ jbyteArray JVM_GetClassAnnotations(JNIEnv *env, jclass cls)
 
 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(env=%p, field=%p)", env, field));
 
-       TRACEJVMCALLS(("JVM_GetFieldAnnotations: field=%p", field));
+       java_lang_reflect_Field jlrf(field);
 
-       if (field == NULL) {
+       if (jlrf.is_null()) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
 
-       rf = (java_lang_reflect_Field*)field;
-
-       LLNI_field_get_ref(rf, annotations, ba);
-
-       return (jbyteArray)ba;
+       return (jbyteArray) jlrf.get_annotations();
 }
 
 
@@ -1252,21 +1169,16 @@ jbyteArray JVM_GetFieldAnnotations(JNIEnv *env, jobject field)
 
 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(env=%p, method=%p)", env, method));
 
-       TRACEJVMCALLS(("JVM_GetMethodAnnotations: method=%p", method));
+       java_lang_reflect_Method jlrm(method);
 
-       if (method == NULL) {
+       if (jlrm.is_null()) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
 
-       rm = (java_lang_reflect_Method*)method;
-
-       LLNI_field_get_ref(rm, annotations, ba);
-
-       return (jbyteArray)ba;
+       return (jbyteArray) jlrm.get_annotations();
 }
 
 
@@ -1274,21 +1186,16 @@ jbyteArray JVM_GetMethodAnnotations(JNIEnv *env, jobject method)
 
 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(env=%p, method=%p)", env, method));
 
-       TRACEJVMCALLS(("JVM_GetMethodDefaultAnnotationValue: method=%p", method));
+       java_lang_reflect_Method jlrm(method);
 
-       if (method == NULL) {
+       if (jlrm.is_null()) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
 
-       rm = (java_lang_reflect_Method*)method;
-
-       LLNI_field_get_ref(rm, annotationDefault, ba);
-
-       return (jbyteArray)ba;
+       return (jbyteArray) jlrm.get_annotationDefault();
 }
 
 
@@ -1296,21 +1203,16 @@ jbyteArray JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)
 
 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(env=%p, method=%p)", env, method));
 
-       TRACEJVMCALLS(("JVM_GetMethodParameterAnnotations: method=%p", method));
+       java_lang_reflect_Method jlrm(method);
 
-       if (method == NULL) {
+       if (jlrm.is_null()) {
                exceptions_throw_nullpointerexception();
                return NULL;
        }
 
-       rm = (java_lang_reflect_Method*)method;
-
-       LLNI_field_get_ref(rm, parameterAnnotations, ba);
-
-       return (jbyteArray)ba;
+       return (jbyteArray) jlrm.get_parameterAnnotations();
 }
 
 
@@ -1335,14 +1237,11 @@ jobjectArray JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean pu
 
 jobjectArray JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean 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);
+       classinfo* c = LLNI_classinfo_unwrap(ofClass);
 
-       oa = class_get_declaredmethods(c, publicOnly);
+       java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
 
        return (jobjectArray) oa;
 }
@@ -1386,25 +1285,16 @@ jint JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)
 jobject JVM_GetClassConstantPool(JNIEnv *env, jclass cls)
 {
 #if defined(ENABLE_ANNOTATIONS)
-       sun_reflect_ConstantPool *constantPool    = NULL;
-                     /* constant pool object for the class refered by '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));
 
-       constantPool = 
-               (sun_reflect_ConstantPool*)native_new_and_init(
-                       class_sun_reflect_ConstantPool);
+       java_handle_t* h = native_new_and_init(class_sun_reflect_ConstantPool);
+       sun_reflect_ConstantPool cp(h, cls);
        
-       if (constantPool == NULL) {
-               /* out of memory */
+       if (cp.is_null()) {
                return NULL;
        }
        
-       LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
-
-       return (jobject)constantPool;
+       return (jobject) cp.get_handle();
 #else
        log_println("JVM_GetClassConstantPool(env=%p, cls=%p): not implemented in this configuration!", env, cls);
        return NULL;
@@ -1499,8 +1389,11 @@ jobject JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject unused, jobject jcpool,
                return NULL;
        }
 
+       // Create a new java.lang.reflect.Method Java object.
        /* XXX: is that right? or do I have to use resolve_method_*? */
-       return (jobject)reflect_method_new(ref->p.method);
+       java_lang_reflect_Method jlrm(ref->p.method);
+
+       return (jobject) jlrm.get_handle();
 }
 
 
@@ -1530,7 +1423,10 @@ jobject JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject unused, jobject
                return NULL;
        }
 
-       return (jobject)reflect_method_new(ref->p.method);
+       // Create a new java.lang.reflect.Method Java object.
+       java_lang_reflect_Method jlrm(ref->p.method);
+
+       return (jobject) jlrm.get_handle();
 }
 
 
@@ -1551,7 +1447,10 @@ jobject JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject unused, jobject jcpool,
                return NULL;
        }
 
-       return (jobject)reflect_field_new(ref->p.field);
+       // Create a new java.lang.reflect.Field Java object.
+       java_lang_reflect_Field jlrf(ref->p.field);
+
+       return (jobject) jlrf.get_handle();
 }
 
 
@@ -1581,7 +1480,10 @@ jobject JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject unused, jobject
                return NULL;
        }
 
-       return (jobject)reflect_field_new(ref->p.field);
+       // Create a new java.lang.reflect.Field Java object.
+       java_lang_reflect_Field jlrf(ref->p.field);
+
+       return (jobject) jlrf.get_handle();
 }
 
 
@@ -1730,7 +1632,6 @@ jstring JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject unused, jobject jcpool, j
 jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
 {
 #if defined(ENABLE_ASSERTION)
-       assertion_name_t  *item;
        classinfo         *c;
        jboolean           status;
        utf               *name;
@@ -1747,8 +1648,10 @@ jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
        }
 
        if (list_assertion_names != NULL) {
-               item = (assertion_name_t *)list_first(list_assertion_names);
-               while (item != NULL) {
+               for (List<assertion_name_t*>::iterator it = list_assertion_names->begin();
+                        it != list_assertion_names->end(); it++) {
+                       assertion_name_t* item = *it;
+
                        name = utf_new_char(item->name);
                        if (name == c->packagename) {
                                status = (jboolean)item->enabled;
@@ -1756,8 +1659,6 @@ jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
                        else if (name == c->name) {
                                status = (jboolean)item->enabled;
                        }
-
-                       item = (assertion_name_t *)list_next(list_assertion_names, item);
                }
        }
 
@@ -1772,30 +1673,17 @@ jboolean JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls)
 
 jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
 {
-       classinfo                             *c;
-       java_lang_AssertionStatusDirectives   *o;
        java_handle_objectarray_t             *classes;
        java_handle_objectarray_t             *packages;
        java_booleanarray_t                   *classEnabled;
        java_booleanarray_t                   *packageEnabled;
 #if defined(ENABLE_ASSERTION)
-       assertion_name_t                      *item;
        java_handle_t                         *js;
        s4                                     i, j;
 #endif
 
        TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
 
-       c = load_class_bootstrap(utf_new_char("java/lang/AssertionStatusDirectives"));
-
-       if (c == NULL)
-               return NULL;
-
-       o = (java_lang_AssertionStatusDirectives *) builtin_new(c);
-
-       if (o == NULL)
-               return NULL;
-
 #if defined(ENABLE_ASSERTION)
        classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
 #else
@@ -1835,8 +1723,9 @@ jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
                i = 0;
                j = 0;
                
-               item = (assertion_name_t *)list_first(list_assertion_names);
-               while (item != NULL) {
+               for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
+                       assertion_name_t* item = *it;
+
                        js = javastring_new_from_ascii(item->name);
                        if (js == NULL) {
                                return NULL;
@@ -1852,20 +1741,15 @@ jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
                                packageEnabled->data[j] = (jboolean) item->enabled;
                                j += 1;
                        }
-
-                       item = (assertion_name_t *)list_next(list_assertion_names, item);
                }
        }
 #endif
 
        /* set instance fields */
 
-       o->classes  = classes;
-       o->packages = packages;
-       o->classEnabled = classEnabled;
-       o->packageEnabled = packageEnabled;
+       java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
 
-       return (jobject) o;
+       return (jobject) jlasd.get_handle();
 }
 
 
@@ -2168,13 +2052,14 @@ jboolean JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2)
  */
 #define JVM_EEXIST       -100
 
-jint JVM_Open(const char *fname, jint flags, jint mode)
+jint JVM_Open(const charfname, jint flags, jint mode)
 {
        int result;
 
        TRACEJVMCALLS(("JVM_Open(fname=%s, flags=%d, mode=%d)", fname, flags, mode));
 
-       result = hpi_file->Open(fname, flags, mode);
+       HPI& hpi = VM::get_current()->get_hpi();
+       result = hpi.get_file().Open(fname, flags, mode);
 
        if (result >= 0) {
                return result;
@@ -2196,37 +2081,41 @@ jint JVM_Close(jint fd)
 {
        TRACEJVMCALLS(("JVM_Close(fd=%d)", fd));
 
-       return hpi_file->Close(fd);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().Close(fd);
 }
 
 
 /* JVM_Read */
 
-jint JVM_Read(jint fd, char *buf, jint nbytes)
+jint JVM_Read(jint fd, charbuf, jint nbytes)
 {
        TRACEJVMCALLS(("JVM_Read(fd=%d, buf=%p, nbytes=%d)", fd, buf, nbytes));
 
-       return (jint) hpi_file->Read(fd, buf, nbytes);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return (jint) hpi.get_file().Read(fd, buf, nbytes);
 }
 
 
 /* JVM_Write */
 
-jint JVM_Write(jint fd, char *buf, jint nbytes)
+jint JVM_Write(jint fd, charbuf, jint nbytes)
 {
        TRACEJVMCALLS(("JVM_Write(fd=%d, buf=%s, nbytes=%d)", fd, buf, nbytes));
 
-       return (jint) hpi_file->Write(fd, buf, nbytes);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return (jint) hpi.get_file().Write(fd, buf, nbytes);
 }
 
 
 /* JVM_Available */
 
-jint JVM_Available(jint fd, jlong *pbytes)
+jint JVM_Available(jint fd, jlongpbytes)
 {
        TRACEJVMCALLS(("JVM_Available(fd=%d, pbytes=%p)", fd, pbytes));
 
-       return hpi_file->Available(fd, pbytes);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().Available(fd, pbytes);
 }
 
 
@@ -2236,7 +2125,8 @@ jlong JVM_Lseek(jint fd, jlong offset, jint whence)
 {
        TRACEJVMCALLS(("JVM_Lseek(fd=%d, offset=%ld, whence=%d)", fd, offset, whence));
 
-       return hpi_file->Seek(fd, (off_t) offset, whence);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().Seek(fd, (off_t) offset, whence);
 }
 
 
@@ -2246,7 +2136,8 @@ jint JVM_SetLength(jint fd, jlong length)
 {
        TRACEJVMCALLS(("JVM_SetLength(fd=%d, length=%ld)", length));
 
-       return hpi_file->SetLength(fd, length);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().SetLength(fd, length);
 }
 
 
@@ -2256,7 +2147,8 @@ jint JVM_Sync(jint fd)
 {
        TRACEJVMCALLS(("JVM_Sync(fd=%d)", fd));
 
-       return hpi_file->Sync(fd);
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.get_file().Sync(fd);
 }
 
 
@@ -2776,7 +2668,8 @@ jint JVM_InitializeSocketLibrary()
 {
        TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
 
-       return hpi_initialize_socket_library();
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.initialize_socket_library();
 }
 
 
@@ -2824,9 +2717,13 @@ jint JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)
 
 jint JVM_Send(jint fd, char *buf, jint nBytes, jint flags)
 {
-       log_println("JVM_Send: IMPLEMENT ME!");
+       TRACEJVMCALLSENTER(("JVM_Send(fd=%d, buf=%p, nBytes=%d, flags=%d", fd, buf, nBytes, flags));
 
-       return 0;
+       int result = os::send(fd, buf, nBytes, flags);
+
+       TRACEJVMCALLSEXIT(("->%d", result));
+
+       return result;
 }
 
 
@@ -3004,17 +2901,15 @@ struct protoent *JVM_GetProtoByName(char* name)
 
 /* JVM_LoadLibrary */
 
-void *JVM_LoadLibrary(const char *name)
+void* JVM_LoadLibrary(const char* name)
 {
-       utf*  u;
-       void* handle;
-
        TRACEJVMCALLSENTER(("JVM_LoadLibrary(name=%s)", name));
 
-       u = utf_new_char(name);
-
-       handle = native_library_open(u);
+       utf* u = utf_new_char(name);
 
+       NativeLibrary nl(u);
+       void* handle = nl.open();
+       
        TRACEJVMCALLSEXIT(("->%p", handle));
 
        return handle;
@@ -3027,19 +2922,21 @@ void JVM_UnloadLibrary(void* handle)
 {
        TRACEJVMCALLS(("JVM_UnloadLibrary(handle=%p)", handle));
 
-       native_library_close(handle);
+       NativeLibrary nl(handle);
+       nl.close();
 }
 
 
 /* JVM_FindLibraryEntry */
 
-void *JVM_FindLibraryEntry(void *handle, const char *name)
+void *JVM_FindLibraryEntry(void* handle, const char* name)
 {
        void* symbol;
 
        TRACEJVMCALLSENTER(("JVM_FindLibraryEntry(handle=%p, name=%s)", handle, name));
 
-       symbol = hpi_library->FindLibraryEntry(handle, name);
+       HPI& hpi = VM::get_current()->get_hpi();
+       symbol = hpi.get_library().FindLibraryEntry(handle, name);
 
        TRACEJVMCALLSEXIT(("->%p", symbol));
 
@@ -3081,35 +2978,31 @@ jstring JVM_InternString(JNIEnv *env, jstring str)
 
 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void)
 {
-       java_object_t *o;
-
        TRACEJVMCALLS(("JVM_RawMonitorCreate()"));
 
-       o = NEW(java_object_t);
+       Mutex* m = new Mutex();
 
-       lock_init_object_lock(o);
-
-       return o;
+       return m;
 }
 
 
 /* JVM_RawMonitorDestroy */
 
-JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon)
+JNIEXPORT void JNICALL JVM_RawMonitorDestroy(voidmon)
 {
        TRACEJVMCALLS(("JVM_RawMonitorDestroy(mon=%p)", mon));
 
-       FREE(mon, java_object_t);
+       delete ((Mutex*) mon);
 }
 
 
 /* JVM_RawMonitorEnter */
 
-JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
+JNIEXPORT jint JNICALL JVM_RawMonitorEnter(voidmon)
 {
        TRACEJVMCALLS(("JVM_RawMonitorEnter(mon=%p)", mon));
 
-       (void) lock_monitor_enter((java_object_t *) mon);
+       ((Mutex*) mon)->lock();
 
        return 0;
 }
@@ -3117,11 +3010,11 @@ JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon)
 
 /* JVM_RawMonitorExit */
 
-JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon)
+JNIEXPORT void JNICALL JVM_RawMonitorExit(voidmon)
 {
        TRACEJVMCALLS(("JVM_RawMonitorExit(mon=%p)", mon));
 
-       (void) lock_monitor_exit((java_object_t *) mon);
+       ((Mutex*) mon)->unlock();
 }
 
 
@@ -3283,26 +3176,13 @@ void JVM_SetPrimitiveField(JNIEnv *env, jobject field, jobject obj, jvalue v, un
 
 jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0)
 {
-       java_lang_reflect_Method *rm;
-       classinfo     *c;
-       int32_t        slot;
-       int32_t        override;
-       methodinfo    *m;
-       java_handle_t *ro;
-
        TRACEJVMCALLS(("JVM_InvokeMethod(env=%p, method=%p, obj=%p, args0=%p)", env, method, obj, args0));
 
-       rm = (java_lang_reflect_Method *) method;
-
-       LLNI_field_get_cls(rm, clazz,    c);
-       LLNI_field_get_val(rm, slot,     slot);
-       LLNI_field_get_val(rm, override, override);
-
-       m = &(c->methods[slot]);
-
-       ro = reflect_method_invoke(m, (java_handle_t *) obj, (java_handle_objectarray_t *) args0, override);
+       java_lang_reflect_Method jlrm(method);
+       
+       java_handle_t* result = jlrm.invoke((java_handle_t*) obj, (java_handle_objectarray_t*) args0);
 
-       return (jobject) ro;
+       return (jobject) result;
 }
 
 
@@ -3310,24 +3190,10 @@ jobject JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray
 
 jobject JVM_NewInstanceFromConstructor(JNIEnv *env, jobject con, jobjectArray args0)
 {
-       java_lang_reflect_Constructor *rc;
-       classinfo                     *c;
-       int32_t                        slot;
-       int32_t                        override;
-       methodinfo                    *m;
-       java_handle_t                 *o;
-
        TRACEJVMCALLS(("JVM_NewInstanceFromConstructor(env=%p, c=%p, args0=%p)", env, con, args0));
 
-       rc = (java_lang_reflect_Constructor *) con;
-
-       LLNI_field_get_cls(rc, clazz,    c);
-       LLNI_field_get_val(rc, slot,     slot);
-       LLNI_field_get_val(rc, override, override);
-
-       m = &(c->methods[slot]);
-
-       o = reflect_constructor_newinstance(m, (java_handle_objectarray_t *) args0, override);
+       java_lang_reflect_Constructor jlrc(con);
+       java_handle_t* o = jlrc.new_instance((java_handle_objectarray_t*) args0);
 
        return (jobject) o;
 }
@@ -3381,9 +3247,7 @@ void *JVM_GetManagement(jint version)
 {
        TRACEJVMCALLS(("JVM_GetManagement(version=%d)", version));
 
-       /* TODO We current don't support the management interface. */
-
-       return NULL;
+       return Management::get_jmm_interface(version);
 }
 
 
@@ -3498,6 +3362,24 @@ jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
 /*             array_intarray_element_set(ia, 2, PARKED); */
                break; 
 
+    case THREAD_STATE_PARKED:
+               ia = builtin_newarray_int(2);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_PARKED);
+               break; 
+
+    case THREAD_STATE_TIMED_PARKED:
+               ia = builtin_newarray_int(2);
+
+               if (ia == NULL)
+                       return NULL;
+
+               array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_PARKED);
+               break; 
+
     case THREAD_STATE_TERMINATED:
                ia = builtin_newarray_int(1);
 
@@ -3593,7 +3475,6 @@ jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArra
                        return NULL;
 
                s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
-/*             s = javastring_new(utf_new_char("WAITING.PARKED")); */
 
                if (s == NULL)
                        return NULL;
@@ -3610,7 +3491,6 @@ jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArra
 
 /*             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;
@@ -3620,6 +3500,36 @@ jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArra
 /*             array_objectarray_element_set(oa, 2, s); */
                break; 
 
+    case THREAD_STATE_PARKED:
+               oa = builtin_anewarray(2, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               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_PARKED:
+               oa = builtin_anewarray(3, class_java_lang_String);
+
+               if (oa == NULL)
+                       return NULL;
+
+               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, 1, s); */
+               break; 
+
     case THREAD_STATE_TERMINATED:
                oa = builtin_anewarray(1, class_java_lang_String);
 
@@ -3719,8 +3629,15 @@ jint JVM_FindSignal(const char *name)
 
        if (strcmp(name, "TERM") == 0)
                return SIGTERM;
+#elif defined(__SOLARIS__)
+       int signum;
+
+       if (os::str2sig(name, &signum) == -1)
+               return -1;
+
+       return signum;
 #else
-# error not implemented for this OS
+# error Not implemented for this OS.
 #endif
 
        return -1;
@@ -3740,4 +3657,5 @@ jint JVM_FindSignal(const char *name)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */