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 4921 2006-05-15 14:24:36Z twisti $
45 #include "mm/memory.h"
46 #include "toolbox/logging.h"
47 #include "native/jni.h"
48 #include "native/native.h"
49 #include "native/include/java_lang_Class.h"
50 #include "native/include/java_lang_Cloneable.h"
51 #include "native/include/java_lang_Object.h"
53 #if defined(ENABLE_THREADS)
54 # include "threads/native/threads.h"
57 #include "vm/builtin.h"
58 #include "vm/exceptions.h"
59 #include "vm/loader.h"
60 #include "vm/options.h"
61 #include "vm/stringlocal.h"
65 * Class: java/lang/VMObject
67 * Signature: (Ljava/lang/Object;)Ljava/lang/Class;
69 JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMObject_getClass(JNIEnv *env, jclass clazz, java_lang_Object *obj)
76 c = ((java_objectheader *) obj)->vftbl->class;
78 return (java_lang_Class *) c;
83 * Class: java/lang/VMObject
85 * Signature: (Ljava/lang/Cloneable;)Ljava/lang/Object;
87 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
90 java_lang_Object *new;
91 arraydescriptor *desc;
93 /* we are cloning an array */
95 if ((desc = this->header.vftbl->arraydesc) != NULL) {
97 u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
99 new = (java_lang_Object *)
100 heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
105 MCOPY(new, this, u1, size);
107 #if defined(ENABLE_THREADS)
108 lock_init_object_lock((java_objectheader *) new);
114 /* we are cloning a non-array */
116 if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
118 new_exception(string_java_lang_CloneNotSupportedException);
122 /* XXX should use vftbl */
123 c = this->header.vftbl->class;
124 new = (java_lang_Object *) builtin_new(c);
129 MCOPY(new, this, u1, c->instancesize);
131 #if defined(ENABLE_THREADS)
132 lock_init_object_lock((java_objectheader *) new);
140 * Class: java/lang/VMObject
144 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
146 #if defined(ENABLE_THREADS)
147 lock_notify_object(&this->header);
153 * Class: java/lang/VMObject
157 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
159 #if defined(ENABLE_THREADS)
160 lock_notify_all_object(&this->header);
166 * Class: java/lang/VMObject
168 * Signature: (Ljava/lang/Object;JI)V
170 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, s8 ms, s4 ns)
172 #if defined(ENABLE_THREADS)
173 lock_wait_for_object(&o->header, ms, ns);
179 * These are local overrides for various environment variables in Emacs.
180 * Please do not remove this and leave it at the end of the file, where
181 * Emacs will automagically detect them.
182 * ---------------------------------------------------------------------
185 * indent-tabs-mode: t