Added standard includes, which are needed.
[cacao.git] / src / native / vm / VMObject.c
1 /* class: java/lang/Object */
2
3
4 #include <stdlib.h>
5 #include <string.h>
6 #include "jni.h"
7 #include "builtin.h"
8 #include "native.h"
9 #include "mm/boehm.h"
10 #include "threads/locks.h"
11 #include "toolbox/loging.h"
12 #include "toolbox/memory.h"
13 #include "java_lang_Cloneable.h"
14 #include "java_lang_Object.h"
15
16
17 /*
18  * Class:     java/lang/Object
19  * Method:    clone
20  * Signature: ()Ljava/lang/Object;
21  */
22 JNIEXPORT struct java_lang_Object* JNICALL Java_java_lang_VMObject_clone ( JNIEnv *env ,  jclass clazz, struct java_lang_Cloneable* this)
23 {
24 /*      log_text("Java_java_lang_VMObject_clone called");
25         log_utf(((java_objectheader*)this)->vftbl->class->name);
26         log_text("starting cloning");     */
27     classinfo *c;
28     java_lang_Object *new;
29     arraydescriptor *desc;
30     
31     if ((desc = this->header.vftbl->arraydesc) != NULL) {
32         /* We are cloning an array */
33         
34         u4 size = desc->dataoffset + desc->componentsize * ((java_arrayheader*)this)->size;
35         
36         new = (java_lang_Object*)heap_allocate(size, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
37         memcpy(new, this, size);
38         
39         return new;
40     }
41     
42     /* We are cloning a non-array */
43     if (! builtin_instanceof ((java_objectheader*) this, class_java_lang_Cloneable) ) {
44         exceptionptr = native_new_and_init (class_java_lang_CloneNotSupportedException);
45         return NULL;
46     }
47
48     /* XXX should use vftbl */
49     c = this -> header.vftbl -> class;
50     new = (java_lang_Object*) builtin_new (c);
51     if (!new) {
52         exceptionptr = proto_java_lang_OutOfMemoryError;
53         return NULL;
54     }
55     memcpy (new, this, c->instancesize);
56     return new;
57 }
58
59
60 /*
61  * Class:     java/lang/Object
62  * Method:    notify
63  * Signature: ()V
64  */
65 JNIEXPORT void JNICALL Java_java_lang_VMObject_notify ( JNIEnv *env ,  jclass clazz, struct java_lang_Object* this)
66 {
67         if (runverbose)
68                 log_text ("java_lang_Object_notify called");
69
70         #ifdef USE_THREADS
71                 signal_cond_for_object(&this->header);
72         #endif
73 }
74
75 /*
76  * Class:     java/lang/Object
77  * Method:    notifyAll
78  * Signature: ()V
79  */
80 JNIEXPORT void JNICALL Java_java_lang_VMObject_notifyAll ( JNIEnv *env ,  jclass clazz, struct java_lang_Object* this)
81 {
82         if (runverbose)
83                 log_text ("java_lang_Object_notifyAll called");
84
85         #ifdef USE_THREADS
86                 broadcast_cond_for_object(&this->header);
87         #endif
88 }
89
90
91 /*
92  * Class:     java/lang/Object
93  * Method:    wait
94  * Signature: (J)V
95  */
96 JNIEXPORT void JNICALL Java_java_lang_VMObject_wait ( JNIEnv *env , jclass clazz, struct java_lang_Object* this, s8 time,s4 par3)
97 {
98         if (runverbose)
99                 log_text ("java_lang_Object_wait called");
100
101         #ifdef USE_THREADS
102                 wait_cond_for_object(&this->header, time);
103         #endif
104 }
105
106
107 /*
108  * These are local overrides for various environment variables in Emacs.
109  * Please do not remove this and leave it at the end of the file, where
110  * Emacs will automagically detect them.
111  * ---------------------------------------------------------------------
112  * Local variables:
113  * mode: c
114  * indent-tabs-mode: t
115  * c-basic-offset: 4
116  * tab-width: 4
117  * End:
118  */