* changed src/native/vm/sun/jvm.c: Throw IllegalArgumentException in all
[cacao.git] / src / native / vm / gnu / java_lang_VMThread.c
index 765960d92c233ae5be0d9dacbf1c96d46005a7e9..d3d84482d6b25e36ce4f5bcafd6a4c8fbff3c734 100644 (file)
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_VMThread.c 7246 2007-01-29 18:49:05Z twisti $
-
 */
 
 
 #include "config.h"
-#include "vm/types.h"
+
+#include <stdint.h>
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
+
 #include "native/include/java_lang_ThreadGroup.h"
 #include "native/include/java_lang_Object.h"            /* java_lang_Thread.h */
 #include "native/include/java_lang_Throwable.h"         /* java_lang_Thread.h */
 #include "native/include/java_lang_VMThread.h"
 #include "native/include/java_lang_Thread.h"
+
+#include "native/include/java_lang_VMThread.h"
+
 #include "native/vm/java_lang_Thread.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
+#include "threads/threads-common.h"
+
+#include "vmcore/utf8.h"
+
+
+/* native methods implemented by this file ************************************/
+
+static JNINativeMethod methods[] = {
+       { "countStackFrames",  "()I",                      (void *) (intptr_t) &Java_java_lang_VMThread_countStackFrames  },
+       { "start",             "(J)V",                     (void *) (intptr_t) &Java_java_lang_VMThread_start             },
+       { "interrupt",         "()V",                      (void *) (intptr_t) &Java_java_lang_VMThread_interrupt         },
+       { "isInterrupted",     "()Z",                      (void *) (intptr_t) &Java_java_lang_VMThread_isInterrupted     },
+       { "suspend",           "()V",                      (void *) (intptr_t) &Java_java_lang_VMThread_suspend           },
+       { "resume",            "()V",                      (void *) (intptr_t) &Java_java_lang_VMThread_resume            },
+       { "nativeSetPriority", "(I)V",                     (void *) (intptr_t) &Java_java_lang_VMThread_nativeSetPriority },
+       { "nativeStop",        "(Ljava/lang/Throwable;)V", (void *) (intptr_t) &Java_java_lang_VMThread_nativeStop        },
+       { "currentThread",     "()Ljava/lang/Thread;",     (void *) (intptr_t) &Java_java_lang_VMThread_currentThread     },
+       { "yield",             "()V",                      (void *) (intptr_t) &Java_java_lang_VMThread_yield             },
+       { "interrupted",       "()Z",                      (void *) (intptr_t) &Java_java_lang_VMThread_interrupted       },
+       { "holdsLock",         "(Ljava/lang/Object;)Z",    (void *) (intptr_t) &Java_java_lang_VMThread_holdsLock         },
+       { "getState",          "()Ljava/lang/String;",     (void *) (intptr_t) &Java_java_lang_VMThread_getState          },
+};
+
+
+/* _Jv_java_lang_VMThread_init *************************************************
+
+   Register native functions.
+
+*******************************************************************************/
+
+void _Jv_java_lang_VMThread_init(void)
+{
+       utf *u;
+
+       u = utf_new_char("java/lang/VMThread");
+
+       native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
 
 
 /*
  * Method:    countStackFrames
  * Signature: ()I
  */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
 {
-    return _Jv_java_lang_Thread_countStackFrames(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       return _Jv_java_lang_Thread_countStackFrames(thread);
 }
 
 
@@ -60,9 +103,13 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_
  * Method:    start
  * Signature: (J)V
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 stacksize)
+JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, int64_t stacksize)
 {
-       _Jv_java_lang_Thread_start(this->thread, stacksize);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_start(thread, stacksize);
 }
 
 
@@ -73,7 +120,11 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
 {
-       _Jv_java_lang_Thread_interrupt(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_interrupt(thread);
 }
 
 
@@ -82,9 +133,13 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_
  * Method:    isInterrupted
  * Signature: ()Z
  */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
 {
-       return _Jv_java_lang_Thread_isInterrupted(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       return _Jv_java_lang_Thread_isInterrupted(thread);
 }
 
 
@@ -95,7 +150,11 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lan
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
 {
-       _Jv_java_lang_Thread_suspend(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_suspend(thread);
 }
 
 
@@ -106,7 +165,11 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VM
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
 {
-       _Jv_java_lang_Thread_resume(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_resume(thread);
 }
 
 
@@ -115,20 +178,28 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMT
  * Method:    nativeSetPriority
  * Signature: (I)V
  */
-JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
+JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, int32_t priority)
 {
-       _Jv_java_lang_Thread_setPriority(this->thread, priority);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_setPriority(thread, priority);
 }
 
 
 /*
  * Class:     java/lang/VMThread
  * Method:    nativeStop
- * Signature: (Ljava/lang/Object;)V
+ * Signature: (Ljava/lang/Throwable;)V
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
 {
-       _Jv_java_lang_Thread_stop(this->thread, t);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       _Jv_java_lang_Thread_stop(thread, t);
 }
 
 
@@ -159,7 +230,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
  * Method:    interrupted
  * Signature: ()Z
  */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
 {
        return _Jv_java_lang_Thread_interrupted();
 }
@@ -170,7 +241,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass cla
  * Method:    holdsLock
  * Signature: (Ljava/lang/Object;)Z
  */
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
+JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
 {
        return _Jv_java_lang_Thread_holdsLock(o);
 }
@@ -183,7 +254,11 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz
  */
 JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *this)
 {
-       return _Jv_java_lang_Thread_getState(this->thread);
+       java_lang_Thread *thread;
+
+       LLNI_field_get_ref(this, thread, thread);
+
+       return _Jv_java_lang_Thread_getState(thread);
 }