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 4957 2006-05-26 11:48:10Z edwin $
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 c = this->header.vftbl->class;
123 new = (java_lang_Object *) builtin_new(c);
128 MCOPY(new, this, u1, c->instancesize);
130 #if defined(ENABLE_THREADS)
131 lock_init_object_lock((java_objectheader *) new);
139 * Class: java/lang/VMObject
143 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
145 #if defined(ENABLE_THREADS)
146 lock_notify_object(&this->header);
152 * Class: java/lang/VMObject
156 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
158 #if defined(ENABLE_THREADS)
159 lock_notify_all_object(&this->header);
165 * Class: java/lang/VMObject
167 * Signature: (Ljava/lang/Object;JI)V
169 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *o, s8 ms, s4 ns)
171 #if defined(ENABLE_THREADS)
172 lock_wait_for_object(&o->header, ms, ns);
178 * These are local overrides for various environment variables in Emacs.
179 * Please do not remove this and leave it at the end of the file, where
180 * Emacs will automagically detect them.
181 * ---------------------------------------------------------------------
184 * indent-tabs-mode: t