new array classes cleanup + made tests (except fp*) work
[cacao.git] / src / native / vm / VMSystem.c
1 /* class: java/lang/System */
2
3 #if 0
4 /*
5  * Class:     java/lang/System
6  * Method:    currentTimeMillis
7  * Signature: ()J
8  */
9 JNIEXPORT s8 JNICALL Java_java_lang_VMSystem_currentTimeMillis ( JNIEnv *env )
10 {
11         struct timeval tv;
12
13         (void) gettimeofday(&tv, NULL);
14         return ((s8) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
15 }
16 #endif
17
18 /*
19  * Class:     java/lang/System
20  * Method:    arraycopy
21  * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
22  */
23 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)
24 {
25         s4 i;
26         java_arrayheader *s = (java_arrayheader*) source;
27         java_arrayheader *d = (java_arrayheader*) dest;
28         arraydescriptor *sdesc;
29         arraydescriptor *ddesc;
30
31 /*      printf("arraycopy: %p:%x->%p:%x\n",source,sp,dest,dp);
32         fflush(stdout);*/
33
34         if (!s || !d) { 
35             exceptionptr = proto_java_lang_NullPointerException; 
36             return; 
37         }
38
39         sdesc = s->objheader.vftbl->arraydesc;
40         ddesc = d->objheader.vftbl->arraydesc;
41
42         if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
43             exceptionptr = proto_java_lang_ArrayStoreException; 
44             return; 
45         }
46
47         if ((len<0) || (sp<0) || (sp+len > s->size) || (dp<0) || (dp+len > d->size)) {
48             exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException; 
49             return; 
50         }
51
52         if (sdesc->componentvftbl == ddesc->componentvftbl) {
53             /* We copy primitive values or references of exactly the same type */
54             s4 dataoffset = sdesc->dataoffset;
55             s4 componentsize = sdesc->componentsize;
56             memmove(((u1*)d) + dataoffset + componentsize * dp,
57                     ((u1*)s) + dataoffset + componentsize * sp,
58                     (size_t) len * componentsize);
59         }
60         else {
61             /* We copy references of different type */
62             java_objectarray *oas = (java_objectarray*) s;
63             java_objectarray *oad = (java_objectarray*) d;
64                 
65             if (dp<=sp) 
66                 for (i=0; i<len; i++) {
67                     java_objectheader *o = oas->data[sp+i];
68                     if (!builtin_canstore(oad, o)) {
69                         exceptionptr = proto_java_lang_ArrayStoreException;
70                         return;
71                     }
72                     oad->data[dp+i] = o;
73                 }
74             else
75                 /* XXX this does not completely obey the specification!
76                  * If an exception is thrown only the elements above
77                  * the current index have been copied. The
78                  * specification requires that only the elements
79                  * *below* the current index have been copied before
80                  * the throw.
81                  */
82                 for (i=len-1; i>=0; i--) {
83                     java_objectheader *o = oas->data[sp+i];
84                     if (!builtin_canstore(oad, o)) {
85                         exceptionptr = proto_java_lang_ArrayStoreException;
86                         return;
87                     }
88                     oad->data[dp+i] = o;
89                 }
90         }
91 }
92
93 void attach_property (char *name, char *value)
94 {
95         log_text("attach_property not supported");
96 #if 0
97         if (activeprops >= MAXPROPS) panic ("Too many properties defined");
98         proplist[activeprops][0] = name;
99         proplist[activeprops][1] = value;
100         activeprops++;
101 #endif
102 }
103
104 /*
105  * Class:     java/lang/System
106  * Method:    identityHashCode
107  * Signature: (Ljava/lang/Object;)I
108  */
109 JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode (JNIEnv *env , jclass clazz, struct java_lang_Object* par1)
110 {
111         return ((char*) par1) - ((char*) 0);    
112 }
113
114
115
116