- we now build a libnat.a
[cacao.git] / src / native / vm / VMSystem.c
1 /* class: java/lang/System */
2
3
4 #include "jni.h"
5 #include "builtin.h"
6 #include "native.h"
7 #include "java_lang_Object.h"
8
9
10 #if 0
11 /*
12  * Class:     java/lang/System
13  * Method:    currentTimeMillis
14  * Signature: ()J
15  */
16 JNIEXPORT s8 JNICALL Java_java_lang_VMSystem_currentTimeMillis ( JNIEnv *env )
17 {
18         struct timeval tv;
19
20         (void) gettimeofday(&tv, NULL);
21         return ((s8) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
22 }
23 #endif
24
25 /*
26  * Class:     java/lang/System
27  * Method:    arraycopy
28  * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
29  */
30 JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy (JNIEnv *env, jclass clazz,struct java_lang_Object* source, s4 sp, struct java_lang_Object* dest, s4 dp, s4 len)
31 {
32         s4 i;
33         java_arrayheader *s = (java_arrayheader*) source;
34         java_arrayheader *d = (java_arrayheader*) dest;
35         arraydescriptor *sdesc;
36         arraydescriptor *ddesc;
37
38 /*      printf("arraycopy: %p:%x->%p:%x\n",source,sp,dest,dp);
39         fflush(stdout);*/
40
41         if (!s || !d) { 
42             exceptionptr = proto_java_lang_NullPointerException; 
43             return; 
44         }
45
46         sdesc = s->objheader.vftbl->arraydesc;
47         ddesc = d->objheader.vftbl->arraydesc;
48
49         if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
50             exceptionptr = proto_java_lang_ArrayStoreException; 
51             return; 
52         }
53
54         if ((len<0) || (sp<0) || (sp+len > s->size) || (dp<0) || (dp+len > d->size)) {
55             exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException; 
56             return; 
57         }
58
59         if (sdesc->componentvftbl == ddesc->componentvftbl) {
60             /* We copy primitive values or references of exactly the same type */
61             s4 dataoffset = sdesc->dataoffset;
62             s4 componentsize = sdesc->componentsize;
63             memmove(((u1*)d) + dataoffset + componentsize * dp,
64                     ((u1*)s) + dataoffset + componentsize * sp,
65                     (size_t) len * componentsize);
66         }
67         else {
68             /* We copy references of different type */
69             java_objectarray *oas = (java_objectarray*) s;
70             java_objectarray *oad = (java_objectarray*) d;
71                 
72             if (dp<=sp) 
73                 for (i=0; i<len; i++) {
74                     java_objectheader *o = oas->data[sp+i];
75                     if (!builtin_canstore(oad, o)) {
76                         exceptionptr = proto_java_lang_ArrayStoreException;
77                         return;
78                     }
79                     oad->data[dp+i] = o;
80                 }
81             else
82                 /* XXX this does not completely obey the specification!
83                  * If an exception is thrown only the elements above
84                  * the current index have been copied. The
85                  * specification requires that only the elements
86                  * *below* the current index have been copied before
87                  * the throw.
88                  */
89                 for (i=len-1; i>=0; i--) {
90                     java_objectheader *o = oas->data[sp+i];
91                     if (!builtin_canstore(oad, o)) {
92                         exceptionptr = proto_java_lang_ArrayStoreException;
93                         return;
94                     }
95                     oad->data[dp+i] = o;
96                 }
97         }
98 }
99
100 void attach_property (char *name, char *value)
101 {
102         log_text("attach_property not supported");
103 #if 0
104         if (activeprops >= MAXPROPS) panic ("Too many properties defined");
105         proplist[activeprops][0] = name;
106         proplist[activeprops][1] = value;
107         activeprops++;
108 #endif
109 }
110
111 /*
112  * Class:     java/lang/System
113  * Method:    identityHashCode
114  * Signature: (Ljava/lang/Object;)I
115  */
116 JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode (JNIEnv *env , jclass clazz, struct java_lang_Object* par1)
117 {
118         return ((char*) par1) - ((char*) 0);    
119 }
120
121
122 /*
123  * These are local overrides for various environment variables in Emacs.
124  * Please do not remove this and leave it at the end of the file, where
125  * Emacs will automagically detect them.
126  * ---------------------------------------------------------------------
127  * Local variables:
128  * mode: c
129  * indent-tabs-mode: t
130  * c-basic-offset: 4
131  * tab-width: 4
132  * End:
133  */