* m4/jvm.m4: New file.
[cacao.git] / src / native / vm / openjdk / jvm.cpp
index a22bd39f1950afe39e0f601f49f832298d5d5459..1b9780fafffc3cd6a3cb4437f3bc324408ad16e6 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/native.hpp"
 
 #include "native/vm/reflection.hpp"
 
 #include "native/vm/openjdk/hpi.h"
+#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.h"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
+#include "vm/globals.hpp"
 #include "vm/initialize.h"
+#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/properties.hpp"
 #include "vm/resolve.h"
 #include "vm/signallocal.h"
 #include "vm/string.hpp"
 
 #include "vm/jit/stacktrace.hpp"
 
-#include "vmcore/classcache.h"
-#include "vmcore/globals.hpp"
-#include "vmcore/javaobjects.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" {
 
@@ -286,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;
 }
@@ -504,10 +475,9 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
                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;
        }
 
@@ -532,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();
 }
 
 
@@ -1658,7 +1630,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;
@@ -1675,8 +1646,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;
@@ -1684,8 +1657,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);
                }
        }
 
@@ -1705,7 +1676,6 @@ jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
        java_booleanarray_t                   *classEnabled;
        java_booleanarray_t                   *packageEnabled;
 #if defined(ENABLE_ASSERTION)
-       assertion_name_t                      *item;
        java_handle_t                         *js;
        s4                                     i, j;
 #endif
@@ -1751,8 +1721,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;
@@ -1768,8 +1739,6 @@ 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
@@ -2994,35 +2963,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);
-
-       lock_init_object_lock(o);
+       Mutex* m = new Mutex();
 
-       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;
 }
@@ -3030,11 +2995,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();
 }
 
 
@@ -3267,9 +3232,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);
 }
 
 
@@ -3605,8 +3568,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;
@@ -3626,4 +3596,5 @@ jint JVM_FindSignal(const char *name)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */