1 /* nat/VMSystem.c - java/lang/System
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
31 $Id: VMSystem.c 1344 2004-07-21 17:12:53Z twisti $
38 #include "exceptions.h"
42 #include "toolbox/logging.h"
43 #include "java_lang_Object.h"
47 * Class: java/lang/System
49 * Signature: (Ljava/lang/Object;ILjava/lang/Object;II)V
51 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)
54 java_arrayheader *s = (java_arrayheader *) source;
55 java_arrayheader *d = (java_arrayheader *) dest;
56 arraydescriptor *sdesc;
57 arraydescriptor *ddesc;
59 /* printf("arraycopy: %p:%x->%p:%x\n",source,sp,dest,dp);
63 *exceptionptr = new_exception(string_java_lang_NullPointerException);
67 sdesc = s->objheader.vftbl->arraydesc;
68 ddesc = d->objheader.vftbl->arraydesc;
70 if (!sdesc || !ddesc || (sdesc->arraytype != ddesc->arraytype)) {
71 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
75 if ((len < 0) || (sp < 0) || (sp + len > s->size) || (dp < 0) || (dp + len > d->size)) {
76 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
80 if (sdesc->componentvftbl == ddesc->componentvftbl) {
81 /* We copy primitive values or references of exactly the same type */
82 s4 dataoffset = sdesc->dataoffset;
83 s4 componentsize = sdesc->componentsize;
84 memmove(((u1 *) d) + dataoffset + componentsize * dp,
85 ((u1 *) s) + dataoffset + componentsize * sp,
86 (size_t) len * componentsize);
89 /* We copy references of different type */
90 java_objectarray *oas = (java_objectarray *) s;
91 java_objectarray *oad = (java_objectarray *) d;
94 for (i = 0; i < len; i++) {
95 java_objectheader *o = oas->data[sp + i];
96 if (!builtin_canstore(oad, o)) {
97 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
100 oad->data[dp + i] = o;
104 /* XXX this does not completely obey the specification!
105 * If an exception is thrown only the elements above
106 * the current index have been copied. The
107 * specification requires that only the elements
108 * *below* the current index have been copied before
111 for (i = len - 1; i >= 0; i--) {
112 java_objectheader *o = oas->data[sp + i];
113 if (!builtin_canstore(oad, o)) {
114 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
117 oad->data[dp + i] = o;
125 * Class: java/lang/System
126 * Method: identityHashCode
127 * Signature: (Ljava/lang/Object;)I
129 JNIEXPORT s4 JNICALL Java_java_lang_VMSystem_identityHashCode(JNIEnv *env, jclass clazz, java_lang_Object *par1)
131 return ((char *) par1) - ((char *) 0);
136 * These are local overrides for various environment variables in Emacs.
137 * Please do not remove this and leave it at the end of the file, where
138 * Emacs will automagically detect them.
139 * ---------------------------------------------------------------------
142 * indent-tabs-mode: t