Include options.h
[cacao.git] / nat / VMObject.c
1 /* nat/VMObject.c - java/lang/Object
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30
31    $Id: VMObject.c 1227 2004-06-30 19:29:35Z twisti $
32
33 */
34
35
36 #include <stdlib.h>
37 #include <string.h>
38 #include "jni.h"
39 #include "builtin.h"
40 #include "loader.h"
41 #include "native.h"
42 #include "options.h"
43 #include "mm/boehm.h"
44 #include "threads/locks.h"
45 #include "toolbox/logging.h"
46 #include "toolbox/memory.h"
47 #include "java_lang_Cloneable.h"
48 #include "java_lang_Object.h"
49
50
51 /*
52  * Class:     java/lang/Object
53  * Method:    clone
54  * Signature: ()Ljava/lang/Object;
55  */
56 JNIEXPORT java_lang_Object* JNICALL Java_java_lang_VMObject_clone(JNIEnv *env, jclass clazz, java_lang_Cloneable *this)
57 {
58         classinfo *c;
59         java_lang_Object *new;
60         arraydescriptor *desc;
61     
62         if ((desc = this->header.vftbl->arraydesc) != NULL) {
63                 /* We are cloning an array */
64         
65                 u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader *) this)->size;
66         
67                 new = (java_lang_Object *) heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
68                 memcpy(new, this, size);
69 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
70                 new->header.monitorBits = 0;
71 #endif
72         
73                 return new;
74         }
75     
76     /* We are cloning a non-array */
77     if (!builtin_instanceof((java_objectheader *) this, class_java_lang_Cloneable)) {
78         *exceptionptr =
79                         new_exception(string_java_lang_CloneNotSupportedException);
80         return NULL;
81     }
82
83     /* XXX should use vftbl */
84     c = this->header.vftbl->class;
85     new = (java_lang_Object *) builtin_new(c);
86
87     if (!new)
88         return NULL;
89
90     memcpy(new, this, c->instancesize);
91 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
92         new->header.monitorBits = 0;
93 #endif
94
95     return new;
96 }
97
98
99 /*
100  * Class:     java/lang/Object
101  * Method:    notify
102  * Signature: ()V
103  */
104 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify(JNIEnv *env, jclass clazz, java_lang_Object *this)
105 {
106         if (runverbose)
107                 log_text("java_lang_Object_notify called");
108
109 #if defined(USE_THREADS)
110         signal_cond_for_object(&this->header);
111 #endif
112 }
113
114
115 /*
116  * Class:     java/lang/Object
117  * Method:    notifyAll
118  * Signature: ()V
119  */
120 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll(JNIEnv *env, jclass clazz, java_lang_Object *this)
121 {
122         if (runverbose)
123                 log_text("java_lang_Object_notifyAll called");
124
125 #if defined(USE_THREADS)
126         broadcast_cond_for_object(&this->header);
127 #endif
128 }
129
130
131 /*
132  * Class:     java/lang/Object
133  * Method:    wait
134  * Signature: (J)V
135  */
136 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait(JNIEnv *env, jclass clazz, java_lang_Object *this, s8 time, s4 par3)
137 {
138         if (runverbose)
139                 log_text("java_lang_VMObject_wait called");
140
141 #if defined(USE_THREADS)
142         wait_cond_for_object(&this->header, time);
143 #endif
144 }
145
146
147 /*
148  * These are local overrides for various environment variables in Emacs.
149  * Please do not remove this and leave it at the end of the file, where
150  * Emacs will automagically detect them.
151  * ---------------------------------------------------------------------
152  * Local variables:
153  * mode: c
154  * indent-tabs-mode: t
155  * c-basic-offset: 4
156  * tab-width: 4
157  * End:
158  */