* src/vm/array.c: Moved to C++.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 3 Sep 2008 12:48:06 +0000 (14:48 +0200)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 3 Sep 2008 12:48:06 +0000 (14:48 +0200)
* src/vm/array.h: Likewise.
* src/vm/array.cpp: New file.
* src/vm/array.hpp: Likewise.
* src/mm/cacao-gc/heap.h,
src/native/jni.cpp,
src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp,
src/native/vm/openjdk/jvm.cpp,
src/vm/Makefile.am,
src/vm/annotation.c,
src/vm/class.c,
src/vm/field.cpp,
src/vm/jit/argument.cpp,
src/vm/jit/builtin.cpp,
src/vm/jit/stacktrace.cpp,
src/vm/jit/verify/typecheck-stackbased.c,
src/vm/jit/verify/typecheck-typeinferer.c,
src/vm/jit/verify/typecheck.c,
src/vm/jit/verify/typeinfo.c,
src/vm/linker.c,
src/vm/method.c,
src/vm/primitive.cpp,
src/vm/primitive.hpp,
src/vm/string.cpp,
src/vm/vm.cpp: Related changes.

--HG--
rename : src/vm/array.c => src/vm/array.cpp
rename : src/vm/array.h => src/vm/array.hpp

25 files changed:
src/mm/cacao-gc/heap.h
src/native/jni.cpp
src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp
src/native/vm/openjdk/jvm.cpp
src/vm/Makefile.am
src/vm/annotation.c
src/vm/array.c [deleted file]
src/vm/array.cpp [new file with mode: 0644]
src/vm/array.h [deleted file]
src/vm/array.hpp [new file with mode: 0644]
src/vm/class.c
src/vm/field.cpp
src/vm/jit/argument.cpp
src/vm/jit/builtin.cpp
src/vm/jit/stacktrace.cpp
src/vm/jit/verify/typecheck-stackbased.c
src/vm/jit/verify/typecheck-typeinferer.c
src/vm/jit/verify/typecheck.c
src/vm/jit/verify/typeinfo.c
src/vm/linker.c
src/vm/method.c
src/vm/primitive.cpp
src/vm/primitive.hpp
src/vm/string.cpp
src/vm/vm.cpp

index f53613a363098292e9a7702d3276b1b9004adf6b..7e76976c3ebf2ccab9403c5974df39dda4fa5952 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "gc.h"
 #include "region.h"
-#include "vm/array.h" /* needed for ARRAYTYPE_OBJECT */
+#include "vm/array.hpp" /* needed for ARRAYTYPE_OBJECT */
 
 
 #define GC_SIZE_DUMMY 0xff
index cf190db7226ff6c90037f256e06c7967c42e0f9b..a9761747888e20aabc350fd727a3310d78dbdc5e 100644 (file)
@@ -49,7 +49,7 @@
 
 #include "toolbox/logging.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
index 7513be2779ea30e82b189878434df39563f90fd3..12f75e5787fa09c3432505572fdc2a8952ef2223 100644 (file)
@@ -38,7 +38,7 @@
 # include "native/vm/include/java_lang_VMThrowable.h"
 #endif
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/globals.hpp"
index 31e70d0f64f81d7fba87c6d1cf877864966321cd..301d4f23ed2f0b2857abaf707df3e7f8599879ec 100644 (file)
@@ -59,7 +59,7 @@
 #include "toolbox/logging.h"
 #include "toolbox/list.hpp"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 
 #if defined(ENABLE_ASSERTION)
 #include "vm/assertion.hpp"
index b9c8451d16986e9658f84888c170cae308bac976..9867cc83625af1543a0d53a8a836ce61fb7ab2af 100644 (file)
@@ -80,8 +80,8 @@ libvm_la_SOURCES = \
        access.c \
        access.h \
        $(ANNOTATION_SOURCES) \
-       array.c \
-       array.h \
+       array.cpp \
+       array.hpp \
        $(ASSERTION_SOURCES) \
        class.c \
        class.h \
index f6b0b102d2f6e329e9b14db3c83b0712a63ab912..b85b352a4f5154816b0f1a4cd5bd2d790ff1ee77 100644 (file)
@@ -35,7 +35,7 @@
 #include "toolbox/logging.h"
 
 #include "vm/annotation.h"
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/loader.hpp"
diff --git a/src/vm/array.c b/src/vm/array.c
deleted file mode 100644 (file)
index 58fdff3..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-/* src/vm/array.c - Java array functions
-
-   Copyright (C) 2007
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-   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., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-*/
-
-
-#include "config.h"
-
-#include <stdint.h>
-
-#include "native/llni.h"
-
-#include "vm/array.h"
-#include "vm/exceptions.hpp"
-#include "vm/global.h"
-#include "vm/primitive.hpp"
-#include "vm/vm.hpp"
-
-
-/* array_element_get ***********************************************************
-
-   Returns a boxed element of the given Java array.
-
-*******************************************************************************/
-
-java_handle_t *array_element_get(java_handle_t *a, int32_t index)
-{
-       vftbl_t       *v;
-       int            type;
-       imm_union      value;
-       java_handle_t *o;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
-
-       v = LLNI_vftbl_direct(a);
-
-       type = v->arraydesc->arraytype;
-
-       value = array_element_primitive_get(a, index);
-
-       o = Primitive_box(type, value);
-
-       return o;
-}
-
-
-/* array_element_set ***********************************************************
-
-   Sets a boxed element in the given Java array.
-
-*******************************************************************************/
-
-void array_element_set(java_handle_t *a, int32_t index, java_handle_t *o)
-{
-       imm_union value;
-
-       value = Primitive_unbox(o);
-
-       array_element_primitive_set(a, index, value);
-}
-
-
-/* array_element_primitive_get *************************************************
-
-   Returns a primitive element of the given Java array.
-
-*******************************************************************************/
-
-imm_union array_element_primitive_get(java_handle_t *a, int32_t index)
-{
-       vftbl_t  *v;
-       int       type;
-       imm_union value;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               value.a = NULL;
-               return value;
-       }
-
-       v = LLNI_vftbl_direct(a);
-
-       type = v->arraydesc->arraytype;
-
-       switch (type) {
-       case ARRAYTYPE_BOOLEAN:
-               value.i = array_booleanarray_element_get((java_handle_booleanarray_t *) a, index);
-               break;
-       case ARRAYTYPE_BYTE:
-               value.i = array_bytearray_element_get((java_handle_bytearray_t *) a,
-                                                                                         index);
-               break;
-       case ARRAYTYPE_CHAR:
-               value.i = array_chararray_element_get((java_handle_chararray_t *) a,
-                                                                                         index);
-               break;
-       case ARRAYTYPE_SHORT:
-               value.i = array_shortarray_element_get((java_handle_shortarray_t *) a,
-                                                                                          index);
-               break;
-       case ARRAYTYPE_INT:
-               value.i = array_intarray_element_get((java_handle_intarray_t *) a,
-                                                                                        index);
-               break;
-       case ARRAYTYPE_LONG:
-               value.l = array_longarray_element_get((java_handle_longarray_t *) a,
-                                                                                         index);
-               break;
-       case ARRAYTYPE_FLOAT:
-               value.f = array_floatarray_element_get((java_handle_floatarray_t *) a,
-                                                                                          index);
-               break;
-       case ARRAYTYPE_DOUBLE:
-               value.d = array_doublearray_element_get((java_handle_doublearray_t *) a,
-                                                                                               index);
-               break;
-       case ARRAYTYPE_OBJECT:
-               value.a = array_objectarray_element_get((java_handle_objectarray_t *) a,
-                                                                                               index);
-               break;
-       default:
-               vm_abort("array_element_primitive_get: invalid array element type %d",
-                                type);
-       }
-
-       return value;
-}
-
-
-/* array_element_primitive_set *************************************************
-
-   Sets a primitive element in the given Java array.
-
-*******************************************************************************/
-
-void array_element_primitive_set(java_handle_t *a, int32_t index, imm_union value)
-{
-       vftbl_t *v;
-       int      type;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               return;
-       }
-
-       v = LLNI_vftbl_direct(a);
-
-       type = v->arraydesc->arraytype;
-
-       switch (type) {
-       case ARRAYTYPE_BOOLEAN:
-               array_booleanarray_element_set((java_handle_booleanarray_t *) a,
-                                                                          index, value.i);
-               break;
-       case ARRAYTYPE_BYTE:
-               array_bytearray_element_set((java_handle_bytearray_t *) a,
-                                                                       index, value.i);
-               break;
-       case ARRAYTYPE_CHAR:
-               array_chararray_element_set((java_handle_chararray_t *) a,
-                                                                       index, value.i);
-               break;
-       case ARRAYTYPE_SHORT:
-               array_shortarray_element_set((java_handle_shortarray_t *) a,
-                                                                        index, value.i);
-               break;
-       case ARRAYTYPE_INT:
-               array_intarray_element_set((java_handle_intarray_t *) a,
-                                                                  index, value.i);
-               break;
-       case ARRAYTYPE_LONG:
-               array_longarray_element_set((java_handle_longarray_t *) a,
-                                                                       index, value.l);
-               break;
-       case ARRAYTYPE_FLOAT:
-               array_floatarray_element_set((java_handle_floatarray_t *) a,
-                                                                        index, value.f);
-               break;
-       case ARRAYTYPE_DOUBLE:
-               array_doublearray_element_set((java_handle_doublearray_t *) a,
-                                                                         index, value.d);
-               break;
-       case ARRAYTYPE_OBJECT:
-               array_objectarray_element_set((java_handle_objectarray_t *) a,
-                                                                         index, value.a);
-               break;
-       default:
-               vm_abort("array_element_primitive_set: invalid array element type %d",
-                                type);
-       }
-}
-
-
-/* array_xxxarray_element_get **************************************************
-
-   Returns a primitive element of the given Java array.
-
-*******************************************************************************/
-
-#define ARRAY_TYPEARRAY_ELEMENT_GET(name, type)                                \
-type array_##name##array_element_get(java_handle_##name##array_t *a, int32_t index) \
-{                                                                              \
-       type    value;                                                             \
-       int32_t size;                                                              \
-                                                                               \
-       if (a == NULL) {                                                           \
-               exceptions_throw_nullpointerexception();                               \
-               return (type) 0;                                                       \
-       }                                                                          \
-                                                                               \
-       size = LLNI_array_size(a);                                                 \
-                                                                               \
-       if ((index < 0) || (index >= size)) {                                      \
-               exceptions_throw_arrayindexoutofboundsexception();                     \
-               return (type) 0;                                                       \
-       }                                                                          \
-                                                                               \
-       value = LLNI_array_direct(a, index);                                       \
-                                                                               \
-       return value;                                                              \
-}
-
-java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
-{
-       java_handle_t *value;
-       int32_t size;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               return NULL;
-       }
-
-       size = LLNI_array_size(a);
-
-       if ((index < 0) || (index >= size)) {
-               exceptions_throw_arrayindexoutofboundsexception();
-               return NULL;
-       }
-
-       LLNI_CRITICAL_START;
-       value = LLNI_WRAP(LLNI_array_direct(a, index));
-       LLNI_CRITICAL_END;
-
-       return value;
-}
-
-ARRAY_TYPEARRAY_ELEMENT_GET(boolean, uint8_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(byte,    int8_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(char,    uint16_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(short,   int16_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(int,     int32_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(long,    int64_t)
-ARRAY_TYPEARRAY_ELEMENT_GET(float,   float)
-ARRAY_TYPEARRAY_ELEMENT_GET(double,  double)
-
-
-/* array_xxxarray_element_set **************************************************
-
-   Sets a primitive element in the given Java array.
-
-*******************************************************************************/
-
-#define ARRAY_TYPEARRAY_ELEMENT_SET(name, type)                                \
-void array_##name##array_element_set(java_handle_##name##array_t *a, int32_t index, type value) \
-{                                                                              \
-       int32_t size;                                                              \
-                                                                               \
-       if (a == NULL) {                                                           \
-               exceptions_throw_nullpointerexception();                               \
-               return;                                                                \
-       }                                                                          \
-                                                                               \
-       size = LLNI_array_size(a);                                                 \
-                                                                               \
-       if ((index < 0) || (index >= size)) {                                      \
-               exceptions_throw_arrayindexoutofboundsexception();                     \
-               return;                                                                \
-       }                                                                          \
-                                                                               \
-       LLNI_array_direct(a, index) = value;                                       \
-}
-
-void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
-{
-       int32_t size;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               return;
-       }
-
-       /* Sanity check. */
-
-       assert(a->header.objheader.vftbl->arraydesc->arraytype == ARRAYTYPE_OBJECT);
-
-       if (value != NULL) {
-               if (builtin_canstore(a, value) == false) {
-                       exceptions_throw_illegalargumentexception();
-                       return;
-               }
-       }
-
-       size = LLNI_array_size(a);
-
-       if ((index < 0) || (index >= size)) {
-               exceptions_throw_arrayindexoutofboundsexception();
-               return;
-       }
-
-       LLNI_CRITICAL_START;
-       LLNI_array_direct(a, index) = LLNI_UNWRAP(value);
-       LLNI_CRITICAL_END;
-}
-
-ARRAY_TYPEARRAY_ELEMENT_SET(boolean, uint8_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(byte,    int8_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(char,    uint16_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(short,   int16_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(int,     int32_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(long,    int64_t)
-ARRAY_TYPEARRAY_ELEMENT_SET(float,   float)
-ARRAY_TYPEARRAY_ELEMENT_SET(double,  double)
-
-
-/* array_length_get ***********************************************************
-
-   Returns a the length of the given Java array.
-
-   ARGUMENTS:
-       a ... Java array
-
-   RETURN VALUE:
-         -1 ... exception thrown
-          >= 0 ... length of the Java array
-
-*******************************************************************************/
-
-int32_t array_length_get(java_handle_t *a)
-{
-       classinfo *c;
-       int32_t    size;
-
-       if (a == NULL) {
-               exceptions_throw_nullpointerexception();
-               return -1;
-       }
-
-       LLNI_class_get(a, c);
-
-       if (!class_is_array(c)) {
-/*             exceptions_throw_illegalargumentexception("Argument is not an array"); */
-               exceptions_throw_illegalargumentexception();
-               return -1;
-       }
-
-       size = LLNI_array_size(a);
-
-       return size;
-}
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
diff --git a/src/vm/array.cpp b/src/vm/array.cpp
new file mode 100644 (file)
index 0000000..de602db
--- /dev/null
@@ -0,0 +1,396 @@
+/* src/vm/array.cpp - Java array functions
+
+   Copyright (C) 2007
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/llni.h"
+
+#include "vm/array.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/global.h"
+#include "vm/primitive.hpp"
+#include "vm/vm.hpp"
+
+
+/* array_element_get ***********************************************************
+
+   Returns a boxed element of the given Java array.
+
+*******************************************************************************/
+
+java_handle_t *array_element_get(java_handle_t *a, int32_t index)
+{
+       vftbl_t       *v;
+       int            type;
+       imm_union      value;
+       java_handle_t *o;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       v = LLNI_vftbl_direct(a);
+
+       type = v->arraydesc->arraytype;
+
+       value = array_element_primitive_get(a, index);
+
+       o = Primitive::box(type, value);
+
+       return o;
+}
+
+
+/* array_element_set ***********************************************************
+
+   Sets a boxed element in the given Java array.
+
+*******************************************************************************/
+
+void array_element_set(java_handle_t *a, int32_t index, java_handle_t *o)
+{
+       imm_union value;
+
+       value = Primitive::unbox(o);
+
+       array_element_primitive_set(a, index, value);
+}
+
+
+/* array_element_primitive_get *************************************************
+
+   Returns a primitive element of the given Java array.
+
+*******************************************************************************/
+
+imm_union array_element_primitive_get(java_handle_t *a, int32_t index)
+{
+       vftbl_t  *v;
+       int       type;
+       imm_union value;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               value.a = NULL;
+               return value;
+       }
+
+       v = LLNI_vftbl_direct(a);
+
+       type = v->arraydesc->arraytype;
+
+       switch (type) {
+       case ARRAYTYPE_BOOLEAN:
+               value.i = array_booleanarray_element_get((java_handle_booleanarray_t *) a, index);
+               break;
+       case ARRAYTYPE_BYTE:
+               value.i = array_bytearray_element_get((java_handle_bytearray_t *) a,
+                                                                                         index);
+               break;
+       case ARRAYTYPE_CHAR:
+               value.i = array_chararray_element_get((java_handle_chararray_t *) a,
+                                                                                         index);
+               break;
+       case ARRAYTYPE_SHORT:
+               value.i = array_shortarray_element_get((java_handle_shortarray_t *) a,
+                                                                                          index);
+               break;
+       case ARRAYTYPE_INT:
+               value.i = array_intarray_element_get((java_handle_intarray_t *) a,
+                                                                                        index);
+               break;
+       case ARRAYTYPE_LONG:
+               value.l = array_longarray_element_get((java_handle_longarray_t *) a,
+                                                                                         index);
+               break;
+       case ARRAYTYPE_FLOAT:
+               value.f = array_floatarray_element_get((java_handle_floatarray_t *) a,
+                                                                                          index);
+               break;
+       case ARRAYTYPE_DOUBLE:
+               value.d = array_doublearray_element_get((java_handle_doublearray_t *) a,
+                                                                                               index);
+               break;
+       case ARRAYTYPE_OBJECT:
+               value.a = array_objectarray_element_get((java_handle_objectarray_t *) a,
+                                                                                               index);
+               break;
+       default:
+               vm_abort("array_element_primitive_get: invalid array element type %d",
+                                type);
+       }
+
+       return value;
+}
+
+
+/* array_element_primitive_set *************************************************
+
+   Sets a primitive element in the given Java array.
+
+*******************************************************************************/
+
+void array_element_primitive_set(java_handle_t *a, int32_t index, imm_union value)
+{
+       vftbl_t *v;
+       int      type;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return;
+       }
+
+       v = LLNI_vftbl_direct(a);
+
+       type = v->arraydesc->arraytype;
+
+       switch (type) {
+       case ARRAYTYPE_BOOLEAN:
+               array_booleanarray_element_set((java_handle_booleanarray_t *) a,
+                                                                          index, value.i);
+               break;
+       case ARRAYTYPE_BYTE:
+               array_bytearray_element_set((java_handle_bytearray_t *) a,
+                                                                       index, value.i);
+               break;
+       case ARRAYTYPE_CHAR:
+               array_chararray_element_set((java_handle_chararray_t *) a,
+                                                                       index, value.i);
+               break;
+       case ARRAYTYPE_SHORT:
+               array_shortarray_element_set((java_handle_shortarray_t *) a,
+                                                                        index, value.i);
+               break;
+       case ARRAYTYPE_INT:
+               array_intarray_element_set((java_handle_intarray_t *) a,
+                                                                  index, value.i);
+               break;
+       case ARRAYTYPE_LONG:
+               array_longarray_element_set((java_handle_longarray_t *) a,
+                                                                       index, value.l);
+               break;
+       case ARRAYTYPE_FLOAT:
+               array_floatarray_element_set((java_handle_floatarray_t *) a,
+                                                                        index, value.f);
+               break;
+       case ARRAYTYPE_DOUBLE:
+               array_doublearray_element_set((java_handle_doublearray_t *) a,
+                                                                         index, value.d);
+               break;
+       case ARRAYTYPE_OBJECT:
+               array_objectarray_element_set((java_handle_objectarray_t *) a,
+                                                                         index, static_cast<java_handle_t*>(value.a));
+               break;
+       default:
+               vm_abort("array_element_primitive_set: invalid array element type %d",
+                                type);
+       }
+}
+
+
+/* array_xxxarray_element_get **************************************************
+
+   Returns a primitive element of the given Java array.
+
+*******************************************************************************/
+
+#define ARRAY_TYPEARRAY_ELEMENT_GET(name, type)                                \
+type array_##name##array_element_get(java_handle_##name##array_t *a, int32_t index) \
+{                                                                              \
+       type    value;                                                             \
+       int32_t size;                                                              \
+                                                                               \
+       if (a == NULL) {                                                           \
+               exceptions_throw_nullpointerexception();                               \
+               return (type) 0;                                                       \
+       }                                                                          \
+                                                                               \
+       size = LLNI_array_size(a);                                                 \
+                                                                               \
+       if ((index < 0) || (index >= size)) {                                      \
+               exceptions_throw_arrayindexoutofboundsexception();                     \
+               return (type) 0;                                                       \
+       }                                                                          \
+                                                                               \
+       value = LLNI_array_direct(a, index);                                       \
+                                                                               \
+       return value;                                                              \
+}
+
+java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index)
+{
+       java_handle_t *value;
+       int32_t size;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return NULL;
+       }
+
+       size = LLNI_array_size(a);
+
+       if ((index < 0) || (index >= size)) {
+               exceptions_throw_arrayindexoutofboundsexception();
+               return NULL;
+       }
+
+       LLNI_CRITICAL_START;
+       value = LLNI_WRAP(LLNI_array_direct(a, index));
+       LLNI_CRITICAL_END;
+
+       return value;
+}
+
+ARRAY_TYPEARRAY_ELEMENT_GET(boolean, uint8_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(byte,    int8_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(char,    uint16_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(short,   int16_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(int,     int32_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(long,    int64_t)
+ARRAY_TYPEARRAY_ELEMENT_GET(float,   float)
+ARRAY_TYPEARRAY_ELEMENT_GET(double,  double)
+
+
+/* array_xxxarray_element_set **************************************************
+
+   Sets a primitive element in the given Java array.
+
+*******************************************************************************/
+
+#define ARRAY_TYPEARRAY_ELEMENT_SET(name, type)                                \
+void array_##name##array_element_set(java_handle_##name##array_t *a, int32_t index, type value) \
+{                                                                              \
+       int32_t size;                                                              \
+                                                                               \
+       if (a == NULL) {                                                           \
+               exceptions_throw_nullpointerexception();                               \
+               return;                                                                \
+       }                                                                          \
+                                                                               \
+       size = LLNI_array_size(a);                                                 \
+                                                                               \
+       if ((index < 0) || (index >= size)) {                                      \
+               exceptions_throw_arrayindexoutofboundsexception();                     \
+               return;                                                                \
+       }                                                                          \
+                                                                               \
+       LLNI_array_direct(a, index) = value;                                       \
+}
+
+void array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value)
+{
+       int32_t size;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return;
+       }
+
+       /* Sanity check. */
+
+       assert(a->header.objheader.vftbl->arraydesc->arraytype == ARRAYTYPE_OBJECT);
+
+       if (value != NULL) {
+               if (builtin_canstore(a, value) == false) {
+                       exceptions_throw_illegalargumentexception();
+                       return;
+               }
+       }
+
+       size = LLNI_array_size(a);
+
+       if ((index < 0) || (index >= size)) {
+               exceptions_throw_arrayindexoutofboundsexception();
+               return;
+       }
+
+       LLNI_CRITICAL_START;
+       LLNI_array_direct(a, index) = LLNI_UNWRAP(value);
+       LLNI_CRITICAL_END;
+}
+
+ARRAY_TYPEARRAY_ELEMENT_SET(boolean, uint8_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(byte,    int8_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(char,    uint16_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(short,   int16_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(int,     int32_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(long,    int64_t)
+ARRAY_TYPEARRAY_ELEMENT_SET(float,   float)
+ARRAY_TYPEARRAY_ELEMENT_SET(double,  double)
+
+
+/* array_length_get ***********************************************************
+
+   Returns a the length of the given Java array.
+
+   ARGUMENTS:
+       a ... Java array
+
+   RETURN VALUE:
+         -1 ... exception thrown
+          >= 0 ... length of the Java array
+
+*******************************************************************************/
+
+int32_t array_length_get(java_handle_t *a)
+{
+       classinfo *c;
+       int32_t    size;
+
+       if (a == NULL) {
+               exceptions_throw_nullpointerexception();
+               return -1;
+       }
+
+       LLNI_class_get(a, c);
+
+       if (!class_is_array(c)) {
+/*             exceptions_throw_illegalargumentexception("Argument is not an array"); */
+               exceptions_throw_illegalargumentexception();
+               return -1;
+       }
+
+       size = LLNI_array_size(a);
+
+       return size;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
diff --git a/src/vm/array.h b/src/vm/array.h
deleted file mode 100644 (file)
index 132855c..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/* src/vm/array.h - Java array functions
-
-   Copyright (C) 2007
-   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
-
-   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.
-
-   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., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-*/
-
-
-#ifndef _VM_ARRAY_H
-#define _VM_ARRAY_H
-
-#include "config.h"
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "vm/global.h"
-#include "vm/primitive.hpp"
-
-
-/* array types ****************************************************************/
-
-/* CAUTION: Don't change the numerical values! These constants (with
-   the exception of ARRAYTYPE_OBJECT) are used as indices in the
-   primitive type table. */
-
-#define ARRAYTYPE_INT         PRIMITIVETYPE_INT
-#define ARRAYTYPE_LONG        PRIMITIVETYPE_LONG
-#define ARRAYTYPE_FLOAT       PRIMITIVETYPE_FLOAT
-#define ARRAYTYPE_DOUBLE      PRIMITIVETYPE_DOUBLE
-#define ARRAYTYPE_BYTE        PRIMITIVETYPE_BYTE
-#define ARRAYTYPE_CHAR        PRIMITIVETYPE_CHAR
-#define ARRAYTYPE_SHORT       PRIMITIVETYPE_SHORT
-#define ARRAYTYPE_BOOLEAN     PRIMITIVETYPE_BOOLEAN
-#define ARRAYTYPE_OBJECT      PRIMITIVETYPE_VOID     /* don't use as index! */
-
-
-/* function prototypes ********************************************************/
-
-java_handle_t *array_element_get(java_handle_t *a, int32_t index);
-void           array_element_set(java_handle_t *a, int32_t index, java_handle_t *o);
-
-imm_union      array_element_primitive_get(java_handle_t *a, int32_t index);
-void           array_element_primitive_set(java_handle_t *a, int32_t index, imm_union value);
-
-uint8_t        array_booleanarray_element_get(java_handle_booleanarray_t *a, int32_t index);
-int8_t         array_bytearray_element_get(java_handle_bytearray_t *a, int32_t index);
-uint16_t       array_chararray_element_get(java_handle_chararray_t *a, int32_t index);
-int16_t        array_shortarray_element_get(java_handle_shortarray_t *a, int32_t index);
-int32_t        array_intarray_element_get(java_handle_intarray_t *a, int32_t index);
-int64_t        array_longarray_element_get(java_handle_longarray_t *a, int32_t index);
-float          array_floatarray_element_get(java_handle_floatarray_t *a, int32_t index);
-double         array_doublearray_element_get(java_handle_doublearray_t *a, int32_t index);
-java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index);
-
-void           array_booleanarray_element_set(java_handle_booleanarray_t *a, int32_t index, uint8_t value);
-void           array_bytearray_element_set(java_handle_bytearray_t *a, int32_t index, int8_t value);
-void           array_chararray_element_set(java_handle_chararray_t *a, int32_t index, uint16_t value);
-void           array_shortarray_element_set(java_handle_shortarray_t *a, int32_t index, int16_t value);
-void           array_intarray_element_set(java_handle_intarray_t *a, int32_t index, int32_t value);
-void           array_longarray_element_set(java_handle_longarray_t *a, int32_t index, int64_t value);
-void           array_floatarray_element_set(java_handle_floatarray_t *a, int32_t index, float value);
-void           array_doublearray_element_set(java_handle_doublearray_t *a, int32_t index, double value);
-void           array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value);
-
-int32_t        array_length_get(java_handle_t *a);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _VM_ARRAY_H */
-
-
-/*
- * These are local overrides for various environment variables in Emacs.
- * Please do not remove this and leave it at the end of the file, where
- * Emacs will automagically detect them.
- * ---------------------------------------------------------------------
- * Local variables:
- * mode: c
- * indent-tabs-mode: t
- * c-basic-offset: 4
- * tab-width: 4
- * End:
- * vim:noexpandtab:sw=4:ts=4:
- */
diff --git a/src/vm/array.hpp b/src/vm/array.hpp
new file mode 100644 (file)
index 0000000..86f1084
--- /dev/null
@@ -0,0 +1,107 @@
+/* src/vm/array.hpp - Java array functions
+
+   Copyright (C) 2007
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+
+   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.
+
+   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., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+*/
+
+
+#ifndef _VM_ARRAY_HPP
+#define _VM_ARRAY_HPP
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "vm/global.h"
+#include "vm/primitive.hpp"
+
+
+/* array types ****************************************************************/
+
+/* CAUTION: Don't change the numerical values! These constants (with
+   the exception of ARRAYTYPE_OBJECT) are used as indices in the
+   primitive type table. */
+
+#define ARRAYTYPE_INT         PRIMITIVETYPE_INT
+#define ARRAYTYPE_LONG        PRIMITIVETYPE_LONG
+#define ARRAYTYPE_FLOAT       PRIMITIVETYPE_FLOAT
+#define ARRAYTYPE_DOUBLE      PRIMITIVETYPE_DOUBLE
+#define ARRAYTYPE_BYTE        PRIMITIVETYPE_BYTE
+#define ARRAYTYPE_CHAR        PRIMITIVETYPE_CHAR
+#define ARRAYTYPE_SHORT       PRIMITIVETYPE_SHORT
+#define ARRAYTYPE_BOOLEAN     PRIMITIVETYPE_BOOLEAN
+#define ARRAYTYPE_OBJECT      PRIMITIVETYPE_VOID     /* don't use as index! */
+
+
+/* function prototypes ********************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+java_handle_t *array_element_get(java_handle_t *a, int32_t index);
+void           array_element_set(java_handle_t *a, int32_t index, java_handle_t *o);
+
+imm_union      array_element_primitive_get(java_handle_t *a, int32_t index);
+void           array_element_primitive_set(java_handle_t *a, int32_t index, imm_union value);
+
+uint8_t        array_booleanarray_element_get(java_handle_booleanarray_t *a, int32_t index);
+int8_t         array_bytearray_element_get(java_handle_bytearray_t *a, int32_t index);
+uint16_t       array_chararray_element_get(java_handle_chararray_t *a, int32_t index);
+int16_t        array_shortarray_element_get(java_handle_shortarray_t *a, int32_t index);
+int32_t        array_intarray_element_get(java_handle_intarray_t *a, int32_t index);
+int64_t        array_longarray_element_get(java_handle_longarray_t *a, int32_t index);
+float          array_floatarray_element_get(java_handle_floatarray_t *a, int32_t index);
+double         array_doublearray_element_get(java_handle_doublearray_t *a, int32_t index);
+java_handle_t *array_objectarray_element_get(java_handle_objectarray_t *a, int32_t index);
+
+void           array_booleanarray_element_set(java_handle_booleanarray_t *a, int32_t index, uint8_t value);
+void           array_bytearray_element_set(java_handle_bytearray_t *a, int32_t index, int8_t value);
+void           array_chararray_element_set(java_handle_chararray_t *a, int32_t index, uint16_t value);
+void           array_shortarray_element_set(java_handle_shortarray_t *a, int32_t index, int16_t value);
+void           array_intarray_element_set(java_handle_intarray_t *a, int32_t index, int32_t value);
+void           array_longarray_element_set(java_handle_longarray_t *a, int32_t index, int64_t value);
+void           array_floatarray_element_set(java_handle_floatarray_t *a, int32_t index, float value);
+void           array_doublearray_element_set(java_handle_doublearray_t *a, int32_t index, double value);
+void           array_objectarray_element_set(java_handle_objectarray_t *a, int32_t index, java_handle_t *value);
+
+int32_t        array_length_get(java_handle_t *a);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _VM_ARRAY_HPP
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c++
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */
index be41aa832cf77148de9e09549534e75e1dd658b9..dee0de8313d1f98aaa7cdaf4c8956fad260f67b0 100644 (file)
@@ -43,7 +43,7 @@
 
 #include "toolbox/logging.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/classcache.h"
index 881cd148b9b2b9b8423701636e321ef80f305fd3..2cd114fc73cea7bd7e3f30aaa1791469a5fe6324 100644 (file)
@@ -36,7 +36,7 @@
 #include "vm/types.h"
 
 #include "vm/annotation.h"
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/descriptor.h"
index 73ed9e271f4db5fa42fb7bc0bcf2793acbd3fd5c..60ddfaf7e115a2528c9282b86f07b5ec9ec23342 100644 (file)
@@ -34,7 +34,7 @@
 
 #include "native/llni.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/descriptor.h"
 #include "vm/global.h"
 #include "vm/method.h"
index 47a7dcc3ae5f1da012057d41685a80f74c954a1c..bf9b656611d6b07949c4f765af8c85c1ed31fb66 100644 (file)
@@ -59,7 +59,7 @@
 #include "toolbox/logging.h"
 #include "toolbox/util.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/cycles-stats.h"
index 37c72d05d2bf3f56fe3561e1e72c743ab4213029..54ec365dc43ccb5226d975451b2c6a0061ee0bcb 100644 (file)
@@ -45,7 +45,7 @@
 
 #include "toolbox/logging.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/cycles-stats.h"
index 042f0806067f9796514a263269d7a3139413e889..b978516b5f6a33422dbcbfab09b5c6b62908d07b 100644 (file)
@@ -32,7 +32,7 @@
 #include "vm/jit/builtin.hpp"
 #include "mm/memory.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
index 67ca099ab08d7db09cb40bae81fb898f6391259b..f63d37fd808ca00a37345f385b167e573b5f092b 100644 (file)
@@ -36,7 +36,7 @@
 #include "toolbox/logging.h"
 
 #include "vm/access.h"
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/globals.hpp"
index 6d85fb6641c0635018c39b2b21e6a439341ae910..51b789fdedd5caec7d7bafb9beb5589454bdf9df 100644 (file)
@@ -148,7 +148,7 @@ error reporting.
 #include "toolbox/logging.h"
 
 #include "vm/access.h"
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/global.h"
index 258dec8e9eed1cd4225f24898be856285050ae98..6cf7f6556fc678324481529421d80a62c1e123ee 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "toolbox/logging.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/class.h"
 #include "vm/descriptor.h"
 #include "vm/exceptions.hpp"
index 64bbc0a12ad56d370973e5782e2d1e0992aa673d..cda34a0d183c535256622f0f85e7691375eb2237 100644 (file)
@@ -40,7 +40,7 @@
 #include "toolbox/logging.h"
 
 #include "vm/access.h"
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/class.h"
 #include "vm/classcache.h"
 #include "vm/exceptions.hpp"
index 814240698ca6d5c56601cdba07e91955f267b2a2..15b808a9992cc3d93fb8f92bfbdf246622aab0ab 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "threads/mutex.hpp"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/class.h"
 #include "vm/exceptions.hpp"
index 880f3851ff227b070e77aee954fe7335a587d661..0a2d42212365b0fa394904783ca18266edd835aa 100644 (file)
@@ -412,7 +412,7 @@ java_handle_t* Primitive::box(int type, imm_union value)
                break;
        default:
                o = NULL;
-               os::abort("primitive_box: invalid primitive type %d", type);
+               os::abort("Primitive::box: Invalid primitive type %d", type);
        }
 
        return o;
@@ -473,7 +473,7 @@ imm_union Primitive::unbox(java_handle_t *h)
                value.a = h;
                break;
        default:
-               os::abort("Primitive::unbox: invalid primitive type %d", type);
+               os::abort("Primitive::unbox: Invalid primitive type %d", type);
        }
 
        return value;
@@ -652,11 +652,9 @@ inline double Primitive::unbox_double(java_handle_t *h)
 
 extern "C" {
 
-       classinfo* Primitive_get_class_by_name(utf *name) { return Primitive::get_class_by_name(name); }
+classinfo* Primitive_get_class_by_name(utf *name) { return Primitive::get_class_by_name(name); }
 classinfo* Primitive_get_class_by_type(int type) { return Primitive::get_class_by_type(type); }
 classinfo* Primitive_get_arrayclass_by_type(int type) { return Primitive::get_arrayclass_by_type(type); }
-java_handle_t* Primitive_box(int type, imm_union value) { return Primitive::box(type, value); }
-imm_union Primitive_unbox(java_handle_t *h) { return Primitive::unbox(h); }
 }
 
 
index 19700c18f66f980bb00892cf3521526451791637..3697b321ccbdbd0135e9bb23454c76a2ec020523 100644 (file)
@@ -129,11 +129,7 @@ void       primitive_postinit(void);
 // Legacy C interface.
 classinfo *Primitive_get_class_by_name(utf *name);
 classinfo *Primitive_get_class_by_type(int type);
-
 classinfo *Primitive_get_arrayclass_by_type(int type);
-
-java_handle_t *Primitive_box(int type, imm_union value);
-imm_union      Primitive_unbox(java_handle_t *h);
 #endif
 
 #endif // _PRIMITIVE_HPP
index 6d2c42dc38abaa07a687b838766b5f9575e901c7..6ea526d158822ffa6d8cc7195e9ea87b0466660e 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "threads/lock.hpp"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/globals.hpp"
index 1bc3e5d64ba0fc733e2781443bd7e5b9f64172e9..7f8d65c4514556efc9a0ada34856ba61c3979137 100644 (file)
@@ -57,7 +57,7 @@
 
 #include "toolbox/logging.h"
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 
 #if defined(ENABLE_ASSERTION)
 #include "vm/assertion.hpp"