src/native/vm/gnuclasspath/java_lang_VMObject.cpp
author Stefan Ring <stefan@complang.tuwien.ac.at>
Mon Mar 04 19:20:45 2013 +0100 (2 months ago)
changeset 9534 15f8bbb64b07
parent 877644b1dcf512af
permissions -rw-r--r--
* tests/regression/base/All.java: Adjust copyright header (file path).
* tests/regression/base/Makefile.am: Likewise.
* tests/regression/base/TestExceptionInStaticClassInitializer.java: Likewise.
* tests/regression/base/TestPatcher.java: Likewise.
     1 /* src/native/vm/gnuclasspath/java_lang_VMObject.cpp - java/lang/VMObject
     2 
     3    Copyright (C) 1996-2005, 2006, 2007, 2008
     4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
     5 
     6    This file is part of CACAO.
     7 
     8    This program is free software; you can redistribute it and/or
     9    modify it under the terms of the GNU General Public License as
    10    published by the Free Software Foundation; either version 2, or (at
    11    your option) any later version.
    12 
    13    This program is distributed in the hope that it will be useful, but
    14    WITHOUT ANY WARRANTY; without even the implied warranty of
    15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16    General Public License for more details.
    17 
    18    You should have received a copy of the GNU General Public License
    19    along with this program; if not, write to the Free Software
    20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    21    02110-1301, USA.
    22 
    23 */
    24 
    25 
    26 #include "config.h"
    27 
    28 #include <stdint.h>
    29 
    30 #include "native/jni.hpp"
    31 #include "native/llni.h"
    32 #include "native/native.hpp"
    33 
    34 #if defined(ENABLE_JNI_HEADERS)
    35 # include "native/vm/include/java_lang_VMObject.h"
    36 #endif
    37 
    38 #include "threads/lock.hpp"
    39 
    40 #include "vm/jit/builtin.hpp"
    41 #include "vm/exceptions.hpp"
    42 #include "vm/javaobjects.hpp"
    43 #include "vm/utf8.h"
    44 
    45 
    46 // Native functions are exported as C functions.
    47 extern "C" {
    48 
    49 /*
    50  * Class:     java/lang/VMObject
    51  * Method:    getClass
    52  * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
    53  */
    54 JNIEXPORT jclass JNICALL Java_java_lang_VMObject_getClass(JNIEnv* env, jclass clazz, jobject obj)
    55 {
    56 	if (obj == NULL) {
    57 		exceptions_throw_nullpointerexception();
    58 		return NULL;
    59 	}
    60 
    61 	java_lang_Object o(obj);
    62 
    63 	return (jclass) LLNI_classinfo_wrap(o.get_Class());
    64 }
    65 
    66 
    67 /*
    68  * Class:     java/lang/VMObject
    69  * Method:    clone
    70  * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
    71  */
    72 JNIEXPORT jobject JNICALL Java_java_lang_VMObject_clone(JNIEnv* env, jclass clazz, jobject _this)
    73 {
    74 	return builtin_clone(NULL, _this);
    75 }
    76 
    77 
    78 /*
    79  * Class:     java/lang/VMObject
    80  * Method:    notify
    81  * Signature: (Ljava/lang/Object;)V
    82  */
    83 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv* env, jclass clazz, jobject _this)
    84 {
    85 #if defined(ENABLE_THREADS)
    86 	lock_notify_object(_this);
    87 #endif
    88 }
    89 
    90 
    91 /*
    92  * Class:     java/lang/VMObject
    93  * Method:    notifyAll
    94  * Signature: (Ljava/lang/Object;)V
    95  */
    96 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv* env, jclass clazz, jobject _this)
    97 {
    98 #if defined(ENABLE_THREADS)
    99 	lock_notify_all_object(_this);
   100 #endif
   101 }
   102 
   103 
   104 /*
   105  * Class:     java/lang/VMObject
   106  * Method:    wait
   107  * Signature: (Ljava/lang/Object;JI)V
   108  */
   109 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv* env, jclass clazz, jobject o, jlong ms, jint ns)
   110 {
   111 #if defined(ENABLE_THREADS)
   112 	lock_wait_for_object(o, ms, ns);
   113 #endif
   114 }
   115 
   116 } // extern "C"
   117 
   118 
   119 /* native methods implemented by this file ************************************/
   120 
   121 static JNINativeMethod methods[] = {
   122 	{ (char*) "getClass",  (char*) "(Ljava/lang/Object;)Ljava/lang/Class;",     (void*) (uintptr_t) &Java_java_lang_VMObject_getClass  },
   123 	{ (char*) "clone",     (char*) "(Ljava/lang/Cloneable;)Ljava/lang/Object;", (void*) (uintptr_t) &Java_java_lang_VMObject_clone     },
   124 	{ (char*) "notify",    (char*) "(Ljava/lang/Object;)V",                     (void*) (uintptr_t) &Java_java_lang_VMObject_notify    },
   125 	{ (char*) "notifyAll", (char*) "(Ljava/lang/Object;)V",                     (void*) (uintptr_t) &Java_java_lang_VMObject_notifyAll },
   126 	{ (char*) "wait",      (char*) "(Ljava/lang/Object;JI)V",                   (void*) (uintptr_t) &Java_java_lang_VMObject_wait      },
   127 };
   128 
   129 
   130 /* _Jv_java_lang_VMObject_init *************************************************
   131 
   132    Register native functions.
   133 
   134 *******************************************************************************/
   135 
   136 void _Jv_java_lang_VMObject_init(void)
   137 {
   138 	utf* u = utf_new_char("java/lang/VMObject");
   139 
   140 	NativeMethods& nm = VM::get_current()->get_nativemethods();
   141 	nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
   142 }
   143 
   144 
   145 /*
   146  * These are local overrides for various environment variables in Emacs.
   147  * Please do not remove this and leave it at the end of the file, where
   148  * Emacs will automagically detect them.
   149  * ---------------------------------------------------------------------
   150  * Local variables:
   151  * mode: c++
   152  * indent-tabs-mode: t
   153  * c-basic-offset: 4
   154  * tab-width: 4
   155  * End:
   156  */