* src/threads/thread.hpp (thread_set_object, thread_get_object): Removed.
[cacao.git] / src / native / vm / openjdk / jvm.cpp
index f356686358642efa01c9008f83f1dfed5fb1628d..0d365146f0e398fb44aa2bdfa738b5a9b414d024 100644 (file)
@@ -1,7 +1,8 @@
 /* src/native/vm/openjdk/jvm.cpp - HotSpot VM interface functions
 
-   Copyright (C) 2007, 2008
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2009 Theobroma Systems Ltd.
 
    This file is part of CACAO.
 
@@ -37,8 +38,6 @@
 #include <sys/ioctl.h>
 #endif
 
-#include <sys/socket.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 
 // Include our JNI header before the JVM headers, because the JVM
         }                                                                              \
     } while (0)
 
-# define PRINTJVMWARNINGS(x)
-/*     do { \ */
-/*         if (opt_PrintJVMWarnings) { \ */
-/*             log_println x; \ */
-/*         } \ */
-/*     } while (0) */
+# define PRINTJVMWARNINGS(x)                                   \
+    do {                                                                               \
+        if (opt_PrintWarnings) {                               \
+            log_println x;                                             \
+        }                                                                              \
+    } while (0)
 
 #else
 
@@ -654,6 +653,25 @@ void JVM_ResolveClass(JNIEnv* env, jclass cls)
 }
 
 
+/* JVM_FindClassFromBootLoader */
+
+jclass JVM_FindClassFromBootLoader(JNIEnv* env, const char* name)
+{
+       classinfo     *c;
+       utf           *u;
+
+       TRACEJVMCALLS(("JVM_FindClassFromBootLoader(name=%s)", name));
+
+       u  = utf_new_char(name);
+       c = load_class_from_classloader(u, NULL);
+
+       if (c == NULL)
+               return NULL;
+
+       return (jclass) LLNI_classinfo_wrap(c);
+}
+
+
 /* JVM_FindClassFromClassLoader */
 
 jclass JVM_FindClassFromClassLoader(JNIEnv* env, const char* name, jboolean init, jobject loader, jboolean throwError)
@@ -2146,7 +2164,23 @@ jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
 
 void JVM_SuspendThread(JNIEnv* env, jobject jthread)
 {
-       log_println("JVM_SuspendThread: Deprecated.  Not implemented.");
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_SuspendThread(env=%p, jthread=%p)", env, jthread));
+
+       if (opt_PrintWarnings)
+               log_println("JVM_SuspendThread: Deprecated, do not use!");
+
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
+
+       /* The threadobject is null when a thread is created in Java. */
+
+       if (t == NULL)
+               return;
+
+       threads_suspend_thread(t, SUSPEND_REASON_JAVA);
 }
 
 
@@ -2154,7 +2188,23 @@ void JVM_SuspendThread(JNIEnv* env, jobject jthread)
 
 void JVM_ResumeThread(JNIEnv* env, jobject jthread)
 {
-       log_println("JVM_ResumeThread: Deprecated.  Not implemented.");
+       java_handle_t *h;
+       threadobject  *t;
+
+       TRACEJVMCALLS(("JVM_ResumeThread(env=%p, jthread=%p)", env, jthread));
+
+       if (opt_PrintWarnings)
+               log_println("JVM_ResumeThread: Deprecated, do not use!");
+
+       h = (java_handle_t *) jthread;
+       t = thread_get_thread(h);
+
+       /* The threadobject is null when a thread is created in Java. */
+
+       if (t == NULL)
+               return;
+
+       threads_resume_thread(t, SUSPEND_REASON_JAVA);
 }
 
 
@@ -2316,12 +2366,10 @@ 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!");
+       TRACEJVMCALLS(("JVM_CurrentClassLoader(env=%p)", env));
+       PRINTJVMWARNINGS(("JVM_CurrentClassLoader is deprecated, do not use it."));
 
-       return NULL;
+       return stacktrace_first_nonsystem_classloader();
 }
 
 
@@ -2413,13 +2461,9 @@ jobject JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint le
 
 jobject JVM_LatestUserDefinedLoader(JNIEnv *env)
 {
-       classloader_t *cl;
-
        TRACEJVMCALLS(("JVM_LatestUserDefinedLoader(env=%p)", env));
 
-       cl = stacktrace_first_nonnull_classloader();
-
-       return (jobject) cl;
+       return stacktrace_first_nonnull_classloader();
 }
 
 
@@ -3191,8 +3235,8 @@ jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlon
 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
 {
        // Get a list of all active threads.
-       list<threadobject*> active_threads;
-       ThreadList::get_active_threads(active_threads);
+       List<threadobject*> active_threads;
+       ThreadList::get_active_java_threads(active_threads);
 
        // Allocate array to hold the java.lang.Thread objects.
        int32_t length = active_threads.size();
@@ -3206,7 +3250,7 @@ jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
        for (List<threadobject*>::iterator it = active_threads.begin(); it != active_threads.end(); it++) {
                threadobject* t = *it;
 
-               java_handle_t* h = thread_get_object(t);
+               java_handle_t* h = LLNI_WRAP(t->object);
                assert(h != NULL);
 
                oa.set_element(index, h);
@@ -3565,7 +3609,15 @@ jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArra
 
 void JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size)
 {
-       log_println("JVM_GetVersionInfo: IMPLEMENT ME!");
+       TRACEJVMCALLS(("JVM_GetVersionInfo(env=%p, info=%p, info_size=%zd)", env, info, info_size));
+
+       memset(info, 0, info_size);
+
+       info->jvm_version = ((VERSION_MAJOR & 0xff) << 24) | ((VERSION_MINOR & 0xff) << 16) | (VERSION_MICRO & 0xff);
+       info->update_version = 0;
+       info->special_update_version = 0;
+       info->is_attach_supported = 0;
+       info->is_kernel_jvm = 0;
 }