1 /* native/vm/VMObject.c - java/lang/Object
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
31 $Id: VMObject.c 1735 2004-12-07 14:33:27Z twisti $
40 #include "mm/memory.h"
41 #include "toolbox/logging.h"
42 #include "native/jni.h"
43 #include "native/native.h"
44 #include "native/include/java_lang_Cloneable.h"
45 #include "native/include/java_lang_Object.h"
46 #include "vm/builtin.h"
47 #include "vm/exceptions.h"
48 #include "vm/loader.h"
49 #include "vm/options.h"
51 #if defined(USE_THREADS)
52 # if defined(NATIVE_THREADS)
53 # include "threads/native/threads.h"
55 # include "threads/green/threads.h"
56 # include "threads/green/locks.h"
62 * Class: java/lang/Object
64 * Signature: ()Ljava/lang/Object;
66 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
69 java_lang_Object *new;
70 arraydescriptor *desc;
72 if ((desc = this->header.vftbl->arraydesc) != NULL) {
73 /* We are cloning an array */
75 u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
77 new = (java_lang_Object *) heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
78 memcpy(new, this, size);
79 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
80 initObjectLock((java_objectheader *) new);
86 /* We are cloning a non-array */
87 if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
89 new_exception(string_java_lang_CloneNotSupportedException);
93 /* XXX should use vftbl */
94 c = this->header.vftbl->class;
95 new = (java_lang_Object *) builtin_new(c);
100 memcpy(new, this, c->instancesize);
101 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
102 initObjectLock((java_objectheader *) new);
110 * Class: java/lang/Object
114 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
117 log_text("java_lang_Object_notify called");
119 #if defined(USE_THREADS)
120 signal_cond_for_object(&this->header);
126 * Class: java/lang/Object
130 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
133 log_text("java_lang_Object_notifyAll called");
135 #if defined(USE_THREADS)
136 broadcast_cond_for_object(&this->header);
142 * Class: java/lang/Object
146 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *this, s8 time, s4 par3)
149 log_text("java_lang_VMObject_wait called");
151 #if defined(USE_THREADS)
152 wait_cond_for_object(&this->header, time, par3);
158 * These are local overrides for various environment variables in Emacs.
159 * Please do not remove this and leave it at the end of the file, where
160 * Emacs will automagically detect them.
161 * ---------------------------------------------------------------------
164 * indent-tabs-mode: t