1 /* src/native/vm/VMObject.c - java/lang/VMObject
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: VMObject.c 4357 2006-01-22 23:33:38Z twisti $
41 #include "mm/memory.h"
42 #include "toolbox/logging.h"
43 #include "native/jni.h"
44 #include "native/native.h"
45 #include "native/include/java_lang_Class.h"
46 #include "native/include/java_lang_Cloneable.h"
47 #include "native/include/java_lang_Object.h"
49 #if defined(USE_THREADS)
50 # if defined(NATIVE_THREADS)
51 # include "threads/native/threads.h"
53 # include "threads/green/threads.h"
54 # include "threads/green/locks.h"
58 #include "vm/builtin.h"
59 #include "vm/exceptions.h"
60 #include "vm/loader.h"
61 #include "vm/options.h"
62 #include "vm/stringlocal.h"
66 * Class: java/lang/VMObject
68 * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
70 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, java_lang_Object *obj)
77 c = ((java_objectheader *) obj)->vftbl->class;
79 return (java_lang_Class *) c;
84 * Class: java/lang/VMObject
86 * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
88 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
91 java_lang_Object *new;
92 arraydescriptor *desc;
94 /* we are cloning an array */
96 if ((desc = this->header.vftbl->arraydesc) != NULL) {
98 u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
100 new = (java_lang_Object *)
101 heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
106 MCOPY(new, this, u1, size);
108 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
109 initObjectLock((java_objectheader *) new);
115 /* we are cloning a non-array */
117 if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
119 new_exception(string_java_lang_CloneNotSupportedException);
123 /* XXX should use vftbl */
124 c = this->header.vftbl->class;
125 new = (java_lang_Object *) builtin_new(c);
130 MCOPY(new, this, u1, c->instancesize);
132 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
133 initObjectLock((java_objectheader *) new);
141 * Class: java/lang/VMObject
145 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
148 log_text("java_lang_Object_notify called");
150 #if defined(USE_THREADS)
151 signal_cond_for_object(&this->header);
157 * Class: java/lang/VMObject
161 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
164 log_text("java_lang_Object_notifyAll called");
166 #if defined(USE_THREADS)
167 broadcast_cond_for_object(&this->header);
173 * Class: java/lang/VMObject
175 * Signature: (Ljava/lang/Object;JI)V
177 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, s8 ms, s4 ns)
180 log_text("java_lang_VMObject_wait called");
182 #if defined(USE_THREADS)
183 wait_cond_for_object(&o->header, ms, ns);
189 * These are local overrides for various environment variables in Emacs.
190 * Please do not remove this and leave it at the end of the file, where
191 * Emacs will automagically detect them.
192 * ---------------------------------------------------------------------
195 * indent-tabs-mode: t