* src/native/vm/openjdk/jvm.cpp (JVM_IsInterrupted): Fixed for threads which
[cacao.git] / src / native / vm / openjdk / jvm.cpp
index 8a7a1d768d8a80b3124c725e1dfe34eebd1303fe..cc431263185f5366f223875e3ac581068eef4c7a 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"
 
-#include "mm/memory.h"
+// We include jvm_md.h before jvm.h as the latter includes the former.
+#include INCLUDE_JVM_MD_H
+#include INCLUDE_JVM_H
+
+#include "fdlibm/fdlibm.h"
+
+#include "mm/memory.hpp"
 
-#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/hpi.hpp"
+#include "native/vm/openjdk/management.hpp"
 
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
 #include "threads/thread.hpp"
+#include "threads/threadlist.hpp"
 
-#include "toolbox/logging.h"
-#include "toolbox/list.h"
+#include "toolbox/logging.hpp"
+#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/classcache.h"
+#include "vm/jit/builtin.hpp"
+#include "vm/classcache.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
-#include "vm/initialize.h"
+#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/signallocal.h"
+#include "vm/properties.hpp"
+#include "vm/resolve.hpp"
+#include "vm/signallocal.hpp"
 #include "vm/string.hpp"
 #include "vm/vm.hpp"
 
 #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" {
 
@@ -285,11 +261,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);
+       VM::get_current()->get_properties().put("sun.nio.MaxDirectMemorySize", buf);
 
-       /* Add all properties. */
-
-       properties_system_add_all(h);
+       // Fill the java.util.Properties object.
+       VM::get_current()->get_properties().fill(h);
 
        return properties;
 }
@@ -463,65 +438,11 @@ jobject JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index)
        java_lang_Throwable jlt(throwable);
        java_handle_bytearray_t* ba = jlt.get_backtrace();
 
-       // We need a critical section here as the stacktrace structure is
+       // XXX We need a critical section here as the stacktrace structure is
        // mapped onto a Java byte-array.
-       LLNI_CRITICAL_START;
-
        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.
-       stacktrace_entry_t* ste = &(st->entries[index]);
-
-       // Get the codeinfo, methodinfo and classinfo.
-       codeinfo*   code = ste->code;
-       methodinfo* m    = code->m;
-       classinfo*  c    = m->clazz;
-
-       // Get filename.
-       java_handle_t* filename;
-
-       if (!(m->flags & ACC_NATIVE)) {
-               if (c->sourcefile != NULL)
-                       filename = javastring_new(c->sourcefile);
-               else
-                       filename = NULL;
-       }
-       else
-               filename = NULL;
-
-       // 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);
-               linenumber = (linenumber == 0) ? -1 : linenumber;
-       }
-
-       LLNI_CRITICAL_END;
-
-       // Get declaring class name.
-       java_handle_t* declaringclass = class_get_classname(c);
-
-       // Allocate a new StackTraceElement object.
-       java_lang_StackTraceElement jlste(declaringclass, javastring_new(m->name), filename, linenumber);
-
-       if (jlste.is_null())
-               return NULL;
-
-       return (jobject) jlste.get_handle();
+       return stacktrace_get_StackTraceElement(st, index);
 }
 
 
@@ -531,7 +452,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();
 }
 
 
@@ -672,21 +595,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);
 }
 
 
@@ -1657,7 +1582,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;
@@ -1674,8 +1598,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;
@@ -1683,8 +1609,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);
                }
        }
 
@@ -1704,7 +1628,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
@@ -1750,8 +1673,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;
@@ -1767,8 +1691,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
@@ -2080,13 +2002,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;
@@ -2108,37 +2031,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);
 }
 
 
@@ -2148,7 +2075,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);
 }
 
 
@@ -2158,7 +2086,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);
 }
 
 
@@ -2168,7 +2097,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);
 }
 
 
@@ -2203,8 +2133,7 @@ jboolean JVM_IsThreadAlive(JNIEnv* env, jobject jthread)
        h = (java_handle_t *) jthread;
        t = thread_get_thread(h);
 
-       /* The threadobject is null when a thread is created in Java. The
-          priority is set later during startup. */
+       /* The threadobject is null when a thread is created in Java. */
 
        if (t == NULL)
                return 0;
@@ -2309,6 +2238,8 @@ void JVM_Interrupt(JNIEnv* env, jobject jthread)
        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;
 
@@ -2329,6 +2260,11 @@ jboolean JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrup
        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 JNI_FALSE;
+
        interrupted = thread_is_interrupted(t);
 
        if (interrupted && clear_interrupted)
@@ -2668,14 +2604,26 @@ jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
 
        /* Create an array-class if necessary. */
 
-       if (class_is_primitive(c))
+       if (class_is_primitive(c)) {
                ac = Primitive::get_arrayclass_by_name(c->name);
+
+               // Arrays of void are not allowed.
+               if (ac == NULL) {
+                       exceptions_throw_illegalargumentexception();
+                       return NULL;
+               }
+
+               if (length > 1)
+                       ac = class_multiarray_of((length - 1), ac, true);
+       }
        else
-               ac = class_array_of(c, true);
+               ac = class_multiarray_of(length, c, true);
 
        if (ac == NULL)
                return NULL;
 
+       /* Allocate a new array on the heap. */
+
        a = builtin_multianewarray(length, (java_handle_t *) ac, dims);
 
        return (jobject) a;
@@ -2688,7 +2636,8 @@ jint JVM_InitializeSocketLibrary()
 {
        TRACEJVMCALLS(("JVM_InitializeSocketLibrary()"));
 
-       return hpi_initialize_socket_library();
+       HPI& hpi = VM::get_current()->get_hpi();
+       return hpi.initialize_socket_library();
 }
 
 
@@ -2736,9 +2685,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;
 }
 
 
@@ -2916,17 +2869,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;
@@ -2939,19 +2890,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));
 
@@ -2961,11 +2914,17 @@ void *JVM_FindLibraryEntry(void *handle, const char *name)
 
 /* JVM_IsNaN */
 
-jboolean JVM_IsNaN(jdouble a)
+jboolean JVM_IsNaN(jdouble d)
 {
-       log_println("JVM_IsNaN: IMPLEMENT ME!");
+       bool result;
 
-       return 0;
+       TRACEJVMCALLSENTER(("JVM_IsNaN(d=%f)", d));
+
+       result = isnan(d);
+
+       TRACEJVMCALLSEXIT(("->%d", result));
+
+       return result;
 }
 
 
@@ -2993,35 +2952,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;
 }
@@ -3029,11 +2984,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();
 }
 
 
@@ -3244,9 +3199,31 @@ jboolean JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlon
 
 jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
 {
-       log_println("JVM_GetAllThreads: IMPLEMENT ME!");
+       // Get a list of all active threads.
+       list<threadobject*> active_threads;
+       ThreadList::get_active_threads(active_threads);
 
-       return NULL;
+       // Allocate array to hold the java.lang.Thread objects.
+       int32_t length = active_threads.size();
+       java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_Thread);
+
+       if (oa == NULL)
+               return NULL;
+
+       // Iterate over all threads (which were active just a second ago).
+       int32_t index = 0;
+       for (List<threadobject*>::iterator it = active_threads.begin(); it != active_threads.end(); it++) {
+               threadobject* t = *it;
+
+               java_handle_t* h = thread_get_object(t);
+               assert(h != NULL);
+
+               array_objectarray_element_set(oa, index, h);
+
+               index++;
+       }
+
+       return oa;
 }
 
 
@@ -3254,9 +3231,55 @@ jobjectArray JVM_GetAllThreads(JNIEnv *env, jclass dummy)
 
 jobjectArray JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads)
 {
-       log_println("JVM_DumpThreads: IMPLEMENT ME!");
+       int32_t i;
 
-       return NULL;
+       TRACEJVMCALLS(("JVM_DumpThreads((env=%p, threadClass=%p, threads=%p)", env, threadClass, threads));
+
+       if (threads == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       // Get length of the threads array.
+       int32_t length = array_length_get((java_handle_t*) threads);
+
+       if (length <= 0) {
+               exceptions_throw_illegalargumentexception();
+               return NULL;
+       }
+
+       // Allocate array to hold stacktraces.
+       classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
+       java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
+
+       if (oas == NULL) {
+               return NULL;
+       }
+
+       // Iterate over all passed thread objects.
+       for (i = 0; i < length; i++) {
+               java_handle_t* thread = array_objectarray_element_get(threads, i);
+
+               // Get thread for the given thread object.
+               threadobject* t = thread_get_thread(thread);
+
+               // The threadobject is null when a thread is created in Java.
+               if (t == NULL)
+                       continue;
+
+               // Get stacktrace for given thread.
+               stacktrace_t* st = stacktrace_get_of_thread(t);
+
+               // Convert stacktrace into array of StackTraceElements.
+               java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
+
+               if (oa == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oas, i, (java_handle_t*) oa);
+       }
+
+       return oas;
 }
 
 
@@ -3266,9 +3289,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);
 }
 
 
@@ -3366,12 +3387,11 @@ jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
                        return NULL;
 
                array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
-               /* XXX Implement parked stuff. */
-/*             array_intarray_element_set(ia, 1, PARKED); */
+               array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
                break; 
 
     case THREAD_STATE_TIMED_WAITING:
-               ia = builtin_newarray_int(3);
+               ia = builtin_newarray_int(2);
 
                if (ia == NULL)
                        return NULL;
@@ -3379,8 +3399,7 @@ jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
                /* 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); */
+               array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
                break; 
 
     case THREAD_STATE_TERMINATED:
@@ -3478,31 +3497,40 @@ 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;
 
                array_objectarray_element_set(oa, 0, s);
-/*             array_objectarray_element_set(oa, 1, s); */
+
+               s = javastring_new(utf_new_char("WAITING.PARKED"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 1, s);
                break; 
 
     case THREAD_STATE_TIMED_WAITING:
-               oa = builtin_anewarray(3, class_java_lang_String);
+               oa = builtin_anewarray(2, 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); */
+
+               s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
+
+               if (s == NULL)
+                       return NULL;
+
+               array_objectarray_element_set(oa, 1, s);
                break; 
 
     case THREAD_STATE_TERMINATED:
@@ -3632,4 +3660,5 @@ jint JVM_FindSignal(const char *name)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */