GNU header update.
[cacao.git] / src / native / vm / VMSystem.c
index 1de9a01743612116c0ef524213b03a84d53e42a5..aead797c191892bd173479430b4627a163d38ecf 100644 (file)
-/* class: java/lang/System */
+/* native/vm/VMSystem.c - java/lang/VMSystem
 
+   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+   Institut f. Computersprachen - TU Wien
 
-#include "jni.h"
-#include "builtin.h"
-#include "native.h"
-#include "java_lang_Object.h"
+   This file is part of CACAO.
 
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
 
-#if 0
-/*
- * Class:     java/lang/System
- * Method:    currentTimeMillis
- * Signature: ()J
- */
-JNIEXPORT s8 JNICALL Java_java_lang_VMSystem_currentTimeMillis ( JNIEnv *env )
-{
-       struct timeval tv;
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.
+
+   Contact: cacao@complang.tuwien.ac.at
+
+   Authors: Roman Obermaiser
+
+   Changes: Joseph Wenninger
+
+   $Id: VMSystem.c 1735 2004-12-07 14:33:27Z twisti $
+
+*/
+
+
+#include <string.h>
+#include <time.h>
+
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_Object.h"
+#include "toolbox/logging.h"
+#include "vm/exceptions.h"
+#include "vm/builtin.h"
 
-       (void) gettimeofday(&tv, NULL);
-       return ((s8) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
-}
-#endif
 
 /*
  * Class:     java/lang/System
  * Method:    arraycopy
  * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
  */
-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)
+JNIEXPORT void JNICALL Java_java_lang_VMSystem_arraycopy(JNIEnv *env, jclass clazz, java_lang_Object *source, s4 sp, java_lang_Object *dest, s4 dp, s4 len)
 {
        s4 i;
-       java_arrayheader *s = (java_arrayheader*) source;
-       java_arrayheader *d = (java_arrayheader*) dest;
-        arraydescriptor *sdesc;
-        arraydescriptor *ddesc;
+       java_arrayheader *s = (java_arrayheader *) source;
+       java_arrayheader *d = (java_arrayheader *) dest;
+       arraydescriptor *sdesc;
+       arraydescriptor *ddesc;
 
-/*     printf("arraycopy: %p:%x->%p:%x\n",source,sp,dest,dp);
-       fflush(stdout);*/
+       /*      printf("arraycopy: %p:%x->%p:%x\n",source,sp,dest,dp);
+               fflush(stdout);*/
 
        if (!s || !d) { 
-            exceptionptr = proto_java_lang_NullPointerException; 
-            return; 
-        }
-
-        sdesc = s->objheader.vftbl->arraydesc;
-        ddesc = d->objheader.vftbl->arraydesc;
-
-        if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
-            exceptionptr = proto_java_lang_ArrayStoreException; 
-            return; 
-        }
-
-       if ((len<0) || (sp<0) || (sp+len > s->size) || (dp<0) || (dp+len > d->size)) {
-            exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException; 
-            return; 
-        }
-
-        if (sdesc->componentvftbl == ddesc->componentvftbl) {
-            /* We copy primitive values or references of exactly the same type */
-            s4 dataoffset = sdesc->dataoffset;
-            s4 componentsize = sdesc->componentsize;
-            memmove(((u1*)d) + dataoffset + componentsize * dp,
-                    ((u1*)s) + dataoffset + componentsize * sp,
-                    (size_t) len * componentsize);
-        }
-        else {
-            /* We copy references of different type */
-            java_objectarray *oas = (java_objectarray*) s;
-            java_objectarray *oad = (java_objectarray*) d;
+               *exceptionptr = new_exception(string_java_lang_NullPointerException);
+               return; 
+       }
+
+       sdesc = s->objheader.vftbl->arraydesc;
+       ddesc = d->objheader.vftbl->arraydesc;
+
+       if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
+               *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
+               return; 
+       }
+
+       if ((len < 0) || (sp < 0) || (sp + len > s->size) || (dp < 0) || (dp + len > d->size)) {
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+               return; 
+       }
+
+       if (sdesc->componentvftbl == ddesc->componentvftbl) {
+               /* We copy primitive values or references of exactly the same type */
+               s4 dataoffset = sdesc->dataoffset;
+               s4 componentsize = sdesc->componentsize;
+               memmove(((u1 *) d) + dataoffset + componentsize * dp,
+                               ((u1 *) s) + dataoffset + componentsize * sp,
+                               (size_t) len * componentsize);
+
+       } else {
+               /* We copy references of different type */
+               java_objectarray *oas = (java_objectarray *) s;
+               java_objectarray *oad = (java_objectarray *) d;
                 
-            if (dp<=sp) 
-                for (i=0; i<len; i++) {
-                    java_objectheader *o = oas->data[sp+i];
-                    if (!builtin_canstore(oad, o)) {
-                        exceptionptr = proto_java_lang_ArrayStoreException;
-                        return;
-                    }
-                    oad->data[dp+i] = o;
-                }
-            else
-                /* XXX this does not completely obey the specification!
-                 * If an exception is thrown only the elements above
-                 * the current index have been copied. The
-                 * specification requires that only the elements
-                 * *below* the current index have been copied before
-                 * the throw.
-                 */
-                for (i=len-1; i>=0; i--) {
-                    java_objectheader *o = oas->data[sp+i];
-                    if (!builtin_canstore(oad, o)) {
-                        exceptionptr = proto_java_lang_ArrayStoreException;
-                        return;
-                    }
-                    oad->data[dp+i] = o;
-                }
-        }
+               if (dp <= sp) {
+                       for (i = 0; i < len; i++) {
+                               java_objectheader *o = oas->data[sp + i];
+                               if (!builtin_canstore(oad, o)) {
+                                       *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
+                                       return;
+                               }
+                               oad->data[dp + i] = o;
+                       }
+
+               } else {
+                       /* XXX this does not completely obey the specification!
+                        * If an exception is thrown only the elements above
+                        * the current index have been copied. The
+                        * specification requires that only the elements
+                        * *below* the current index have been copied before
+                        * the throw.
+                        */
+                       for (i = len - 1; i >= 0; i--) {
+                               java_objectheader *o = oas->data[sp + i];
+                               if (!builtin_canstore(oad, o)) {
+                                       *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
+                                       return;
+                               }
+                               oad->data[dp + i] = o;
+                       }
+               }
+       }
 }
 
-void attach_property (char *name, char *value)
-{
-       log_text("attach_property not supported");
-#if 0
-       if (activeprops >= MAXPROPS) panic ("Too many properties defined");
-       proplist[activeprops][0] = name;
-       proplist[activeprops][1] = value;
-       activeprops++;
-#endif
-}
 
 /*
  * Class:     java/lang/System
  * Method:    identityHashCode
  * Signature: (Ljava/lang/Object;)I
  */
-JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode (JNIEnv *env , jclass clazz, struct java_lang_Object* par1)
+JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, java_lang_Object *par1)
 {
-       return ((char*) par1) - ((char*) 0);    
+       return ((char *) par1) - ((char *) 0);
 }