* src/vm/array.h: Likewise.
* src/vm/Makefile.am (libvm_la_SOURCES): Added array.[ch].
* src/vm/builtin.c,
src/vm/string.c,
src/vm/jit/verify/typecheck-typeinferer.c,
src/vm/jit/verify/typecheck.c,
src/vm/jit/verify/typecheck-stackbased.c,
src/vm/jit/verify/typeinfo.c,
src/vmcore/linker.c (vm/array.h): Added.
* src/vm/primitive.h (ARRAYTYPE_*): Moved to vm/array.h
* src/vmcore/class.c (class_get_componenttype): New function.
* src/vmcore/class.h: Likewise.
* src/native/vm/java_lang_Class.c (getComponentType): Removed.
* src/native/vm/java_lang_Class.h: Likewise.
* src/native/vm/gnu/java_lang_VMClass.c (getComponentType): Call
class_get_componenttype.
* src/native/vm/sun/jvm.c (JVM_GetComponentType): Likewise.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_VMClass.c 8318 2007-08-16 10:05:34Z michi $
+ $Id: java_lang_VMClass.c 8330 2007-08-16 18:15:51Z twisti $
*/
*/
JNIEXPORT java_lang_Class* JNICALL Java_java_lang_VMClass_getComponentType(JNIEnv *env, jclass clazz, java_lang_Class *klass)
{
- return _Jv_java_lang_Class_getComponentType(klass);
+ classinfo *c;
+ classinfo *component;
+
+ c = (classinfo *) klass;
+
+ component = class_get_componenttype(c);
+
+ return (java_lang_Class *) component;
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_Class.c 8319 2007-08-16 10:43:43Z michi $
+ $Id: java_lang_Class.c 8330 2007-08-16 18:15:51Z twisti $
*/
}
-/*
- * Class: java/lang/Class
- * Method: getComponentType
- * Signature: ()Ljava/lang/Class;
- */
-java_lang_Class *_Jv_java_lang_Class_getComponentType(java_lang_Class *klass)
-{
- classinfo *c;
- classinfo *comp;
- arraydescriptor *desc;
-
- c = (classinfo *) klass;
-
- /* XXX maybe we could find a way to do this without linking. */
- /* This way should be safe and easy, however. */
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return NULL;
-
- desc = c->vftbl->arraydesc;
-
- if (desc == NULL)
- return NULL;
-
- if (desc->arraytype == ARRAYTYPE_OBJECT)
- comp = desc->componentvftbl->class;
- else
- comp = primitive_class_get_by_type(desc->arraytype);
-
- return (java_lang_Class *) comp;
-}
-
-
/*
* Class: java/lang/Class
* Method: getModifiers
s4 _Jv_java_lang_Class_isPrimitive(java_lang_Class *klass);
java_lang_Class *_Jv_java_lang_Class_getSuperclass(java_lang_Class *klass);
java_handle_objectarray_t *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass);
-java_lang_Class *_Jv_java_lang_Class_getComponentType(java_lang_Class *klass);
s4 _Jv_java_lang_Class_getModifiers(java_lang_Class *klass, s4 ignoreInnerClassesAttrib);
java_lang_Class *_Jv_java_lang_Class_getDeclaringClass(java_lang_Class *klass);
java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass, s4 publicOnly);
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: jvm.c 8323 2007-08-16 16:01:05Z twisti $
+ $Id: jvm.c 8330 2007-08-16 18:15:51Z twisti $
*/
jclass JVM_GetComponentType(JNIEnv *env, jclass cls)
{
-#if PRINTJVM
- log_println("JVM_GetComponentType: cls=%p", cls);
-#endif
- return (jclass) _Jv_java_lang_Class_getComponentType((java_lang_Class *) cls);
+ classinfo *component;
+
+ TRACEJVMCALLS("JVM_GetComponentType(env=%p, cls=%p)", env, cls);
+
+ c = (classinfo *) cls;
+
+ component = class_get_componenttype(c);
+
+ return (jclass) component;
}
jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
{
-/* log_println("JVM_GetArrayElement: IMPLEMENT ME!"); */
-
- java_arrayheader *a = NULL;
- int32_t elementtype = 0;
+ java_arrayheader *a;
+ int type;
- TRACEJVMCALLS("JVM_GetArrayElement: arr=%p, index=%d", arr, index);
+ TRACEJVMCALLS("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index);
a = (java_arrayheader *) arr;
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
##
-## $Id: Makefile.am 8288 2007-08-10 15:12:00Z twisti $
+## $Id: Makefile.am 8330 2007-08-16 18:15:51Z twisti $
## Process this file with automake to produce Makefile.in
libvm_la_SOURCES = \
access.c \
access.h \
+ array.c \
+ array.h \
builtin.c \
builtin.h \
builtintable.inc \
--- /dev/null
+/* src/vm/array.c - array functions
+
+ Copyright (C) 2007 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
+
+ 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.
+
+ $Id: access.c 8318 2007-08-16 10:05:34Z michi $
+
+*/
+
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "native/llni.h"
+
+#include "vm/array.h"
+#include "vm/global.h"
+#include "vm/vm.h"
+
+
+/* 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 elementtype;
+ imm_union value;
+
+ v = LLNI_vftbl_direct(a);
+
+ elementtype = v->arraydesc->elementtype;
+
+ switch (elementtype) {
+ case ARRAYTYPE_BOOLEAN:
+ value.i = array_booleanarray_element_get(a, index);
+ break;
+ case ARRAYTYPE_BYTE:
+ value.i = array_bytearray_element_get(a, index);
+ break;
+ case ARRAYTYPE_CHAR:
+ value.i = array_chararray_element_get(a, index);
+ break;
+ case ARRAYTYPE_SHORT:
+ value.i = array_shortarray_element_get(a, index);
+ break;
+ case ARRAYTYPE_INT:
+ value.i = array_intarray_element_get(a, index);
+ break;
+ case ARRAYTYPE_LONG:
+ value.l = array_longarray_element_get(a, index);
+ break;
+ case ARRAYTYPE_FLOAT:
+ value.f = array_floatarray_element_get(a, index);
+ break;
+ case ARRAYTYPE_DOUBLE:
+ value.d = array_doublearray_element_get(a, index);
+ break;
+ case ARRAYTYPE_OBJECT:
+ value.a = array_objectarray_element_get(a, index);
+ break;
+
+ default:
+ vm_abort("array_element_primitive_get: invalid array element type %d",
+ elementtype);
+ }
+
+ return value;
+}
+
+
+/* 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_t *a, int32_t index) \
+{ \
+ java_handle_##name##array_t *ja; \
+ type value; \
+ \
+ ja = (java_handle_##name##array_t *) a; \
+ \
+ value = LLNI_array_direct(ja, index); \
+ \
+ 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_TYPEARRAY_ELEMENT_GET(object, java_handle_t*)
+
+
+/*
+ * 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:
+ */
--- /dev/null
+/* src/vm/array.h - array functions
+
+ Copyright (C) 2007 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
+
+ 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.
+
+ $Id: access.c 8318 2007-08-16 10:05:34Z michi $
+
+*/
+
+
+#ifndef _VM_ARRAY_H
+#define _VM_ARRAY_H
+
+#include "config.h"
+
+#include <stdint.h>
+
+#include "vm/global.h"
+#include "vm/primitive.h"
+
+
+/* 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 ********************************************************/
+
+imm_union array_element_primitive_get(java_handle_t *a, int32_t index);
+
+uint8_t array_booleanarray_element_get(java_handle_t *a, int32_t index);
+int8_t array_bytearray_element_get(java_handle_t *a, int32_t index);
+uint16_t array_chararray_element_get(java_handle_t *a, int32_t index);
+int16_t array_shortarray_element_get(java_handle_t *a, int32_t index);
+int32_t array_intarray_element_get(java_handle_t *a, int32_t index);
+int64_t array_longarray_element_get(java_handle_t *a, int32_t index);
+float array_floatarray_element_get(java_handle_t *a, int32_t index);
+double array_doublearray_element_get(java_handle_t *a, int32_t index);
+java_handle_t *array_objectarray_element_get(java_handle_t *a, int32_t index);
+
+#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:
+ */
calls instead of machine instructions, using the C calling
convention.
- $Id: builtin.c 8318 2007-08-16 10:05:34Z michi $
+ $Id: builtin.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include "toolbox/logging.h"
#include "toolbox/util.h"
+#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/cycles-stats.h"
#include "vm/exceptions.h"
#include "vm/builtin.h"
#include "mm/memory.h"
+#include "vm/array.h"
#include "vm/global.h"
#include "vm/primitive.h"
#include "toolbox/logging.h"
+#include "vm/array.h"
#include "vm/access.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: typecheck.c 8288 2007-08-10 15:12:00Z twisti $
+ $Id: typecheck.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include "toolbox/logging.h"
#include "vm/access.h"
+#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: typeinfo.c 8288 2007-08-10 15:12:00Z twisti $
+ $Id: typeinfo.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include <string.h>
#include "mm/memory.h"
+
#include "toolbox/logging.h"
+#include "vm/array.h"
#include "vm/exceptions.h"
#include "vm/primitive.h"
#include "vm/resolve.h"
#define PRIMITIVETYPE_VOID TYPE_VOID
-/* 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! */
-
-
/* primitivetypeinfo **********************************************************/
struct primitivetypeinfo {
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: string.c 8318 2007-08-16 10:05:34Z michi $
+ $Id: string.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include "threads/lock-common.h"
+#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/primitive.h"
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: class.c 8318 2007-08-16 10:05:34Z michi $
+ $Id: class.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include "toolbox/logging.h"
+#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
}
+/* class_get_componenttype *****************************************************
+
+ Return the component class of the given class. If the given class
+ is not an array, return NULL.
+
+*******************************************************************************/
+
+classinfo *class_get_componenttype(classinfo *c)
+{
+ classinfo *component;
+ arraydescriptor *ad;
+
+ /* XXX maybe we could find a way to do this without linking. */
+ /* This way should be safe and easy, however. */
+
+ if (!(c->state & CLASS_LINKED))
+ if (!link_class(c))
+ return NULL;
+
+ ad = c->vftbl->arraydesc;
+
+ if (ad == NULL)
+ return NULL;
+
+ if (ad->arraytype == ARRAYTYPE_OBJECT)
+ component = ad->componentvftbl->class;
+ else
+ component = primitive_class_get_by_type(ad->arraytype);
+
+ return component;
+}
+
+
/* class_get_declaredclasses ***************************************************
Return an array of declared classes of the given class.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: class.h 8318 2007-08-16 10:05:34Z michi $
+ $Id: class.h 8330 2007-08-16 18:15:51Z twisti $
*/
bool class_is_interface(classinfo *c);
classinfo *class_get_superclass(classinfo *c);
+classinfo *class_get_componenttype(classinfo *c);
java_handle_objectarray_t *class_get_declaredclasses(classinfo *c, bool publicOnly);
classinfo *class_get_declaringclass(classinfo *c);
java_handle_objectarray_t *class_get_interfaces(classinfo *c);
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: linker.c 8318 2007-08-16 10:05:34Z michi $
+ $Id: linker.c 8330 2007-08-16 18:15:51Z twisti $
*/
#include "toolbox/logging.h"
#include "vm/access.h"
+#include "vm/array.h"
#include "vm/exceptions.h"
#include "vm/primitive.h"
#include "vm/stringlocal.h"