* src/vm/array.cpp: Likewise.
* src/vm/jit/builtin.hpp (builtin_newarray, builtin_anewarray): Removed.
* src/vm/jit/builtin.cpp: Likewise.
* src/vm/vm.cpp (vm_run): Minor rework of argument handling.
* src/vm/string.cpp: This code is messed up and needs to be cleaned up soon.
The rest of the files were just updated to the new array access classes, so I
simply list them below:
* src/native/jni.cpp
* src/native/llni.h
* src/native/vm/cldc1.1/com_sun_cldc_io_ResourceInputStream.cpp
* src/native/vm/cldc1.1/com_sun_cldc_io_j2me_socket_Protocol.cpp
* src/native/vm/cldc1.1/java_lang_String.cpp
* src/native/vm/gnuclasspath/gnu_java_lang_VMCPStringBuilder.cpp
* src/native/vm/gnuclasspath/gnu_java_lang_management_VMRuntimeMXBeanImpl.cpp
* src/native/vm/gnuclasspath/java_lang_VMClassLoader.cpp
* src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp
* src/native/vm/gnuclasspath/java_lang_management_VMManagementFactory.cpp
* src/native/vm/openjdk/jvm.cpp
* src/native/vm/reflection.cpp
* src/native/vm/sun_misc_Unsafe.cpp
* src/vm/annotation.cpp
* src/vm/class.cpp
* src/vm/field.cpp
* src/vm/global.h
* src/vm/jit/argument.cpp
* src/vm/jit/stacktrace.cpp
* src/vm/jit/trace.cpp
* src/vm/method.cpp
--HG--
branch : michi
jstring jni_NewString(JNIEnv *env, const jchar *buf, jsize len)
{
TRACEJNICALLS(("jni_NewString(env=%p, buf=%p, len=%d)", env, buf, len));
-
- java_handle_chararray_t* a = builtin_newarray_char(len);
- if (a == NULL)
+ CharArray ca(len);
+
+ if (ca.is_null())
return NULL;
/* copy text */
+
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
for (jsize i = 0; i < len; i++)
- LLNI_array_direct(a, i) = buf[i];
+ ptr[i] = buf[i];
java_handle_t* h = builtin_new(class_java_lang_String);
if (h == NULL)
return NULL;
- java_lang_String s(h, a, len, 0);
+ java_lang_String s(h, ca.get_handle(), len, 0);
return (jstring) jni_NewLocalRef(env, (jobject) s.get_handle());
}
java_lang_String s(str);
- java_handle_chararray_t* ca = s.get_value();
- int32_t count = s.get_count();
- int32_t offset = s.get_offset();
+ CharArray ca(s.get_value());
+
+ int32_t count = s.get_count();
+ int32_t offset = s.get_offset();
- if (ca == NULL)
+ if (ca.is_null())
return NULL;
/* allocate memory */
/* copy text */
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
for (i = 0; i < count; i++)
- stringbuffer[i] = LLNI_array_direct(ca, offset + i);
+ stringbuffer[i] = ptr[offset + i];
/* terminate string */
TRACEJNICALLS(("jni_GetStringUTFLength(env=%p, string=%p)", env, string));
java_lang_String s(string);
- java_handle_chararray_t* ca = s.get_value();
- int32_t count = s.get_count();
+ CharArray ca(s.get_value());
+ int32_t count = s.get_count();
// FIXME GC critical section!
- int32_t length = u2_utflength(ca->data, count);
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+ int32_t length = u2_utflength(ptr, count);
return length;
}
jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
{
- java_handle_t *a;
- jsize size;
-
TRACEJNICALLS(("_Jv_JNI_GetArrayLength(env=%p, array=%p)", env, array));
- a = (java_handle_t *) array;
+ Array a(array);
- size = LLNI_array_size(a);
+ jsize size = a.get_length();
return size;
}
jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
jclass elementClass, jobject initialElement)
{
- classinfo *c;
- java_handle_t *o;
- java_handle_objectarray_t *oa;
- s4 i;
+ classinfo* c;
+ java_handle_t* o;
+ s4 i;
STATISTICS(jniinvokation());
return NULL;
}
- oa = builtin_anewarray(length, c);
+ ObjectArray oa(length, c);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
/* set all elements to initialElement */
for (i = 0; i < length; i++)
- array_objectarray_element_set(oa, i, o);
+ oa.set_element(i, o);
- return (jobjectArray) jni_NewLocalRef(env, (jobject) oa);
+ return (jobjectArray) jni_NewLocalRef(env, (jobject) oa.get_handle());
}
jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
jsize index)
{
- java_handle_objectarray_t *oa;
- java_handle_t *o;
-
STATISTICS(jniinvokation());
- oa = (java_handle_objectarray_t *) array;
+ ObjectArray oa(array);
- if (index >= LLNI_array_size(oa)) {
+ if (index >= oa.get_length()) {
exceptions_throw_arrayindexoutofboundsexception();
return NULL;
}
- o = array_objectarray_element_get(oa, index);
+ java_handle_t* o = oa.get_element(index);
return jni_NewLocalRef(env, (jobject) o);
}
void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
jsize index, jobject val)
{
- java_handle_objectarray_t *oa;
- java_handle_t *o;
-
STATISTICS(jniinvokation());
- oa = (java_handle_objectarray_t *) array;
- o = (java_handle_t *) val;
+ ObjectArray oa(array);
- if (index >= LLNI_array_size(oa)) {
+ if (index >= oa.get_length()) {
exceptions_throw_arrayindexoutofboundsexception();
return;
}
/* check if the class of value is a subclass of the element class
of the array */
- if (!builtin_canstore(oa, o))
+ java_handle_t* o = (java_handle_t *) val;
+
+ if (!builtin_canstore(oa.get_handle(), o))
return;
- array_objectarray_element_set(oa, index, o);
+ oa.set_element(index, o);
}
-#define JNI_NEW_ARRAY(name, type, intern) \
+#define JNI_NEW_ARRAY(name, type) \
type _Jv_JNI_New##name##Array(JNIEnv *env, jsize len) \
{ \
- java_handle_##intern##array_t *a; \
- \
STATISTICS(jniinvokation()); \
\
if (len < 0) { \
return NULL; \
} \
\
- a = builtin_newarray_##intern(len); \
+ name##Array a(len); \
\
- return (type) jni_NewLocalRef(env, (jobject) a); \
+ return (type) jni_NewLocalRef(env, \
+ (jobject) a.get_handle()); \
}
-JNI_NEW_ARRAY(Boolean, jbooleanArray, boolean)
-JNI_NEW_ARRAY(Byte, jbyteArray, byte)
-JNI_NEW_ARRAY(Char, jcharArray, char)
-JNI_NEW_ARRAY(Short, jshortArray, short)
-JNI_NEW_ARRAY(Int, jintArray, int)
-JNI_NEW_ARRAY(Long, jlongArray, long)
-JNI_NEW_ARRAY(Float, jfloatArray, float)
-JNI_NEW_ARRAY(Double, jdoubleArray, double)
+JNI_NEW_ARRAY(Boolean, jbooleanArray)
+JNI_NEW_ARRAY(Byte, jbyteArray)
+JNI_NEW_ARRAY(Char, jcharArray)
+JNI_NEW_ARRAY(Short, jshortArray)
+JNI_NEW_ARRAY(Int, jintArray)
+JNI_NEW_ARRAY(Long, jlongArray)
+JNI_NEW_ARRAY(Float, jfloatArray)
+JNI_NEW_ARRAY(Double, jdoubleArray)
/* Get<PrimitiveType>ArrayElements *********************************************
type *_Jv_JNI_Get##name##ArrayElements(JNIEnv *env, type##Array array, \
jboolean *isCopy) \
{ \
- java_handle_##intern##array_t *a; \
- \
TRACEJNICALLS(("_Jv_JNI_Get" STR(name) "ArrayElements(env=%p, array=%p, isCopy=%d)", env, array, isCopy)); \
\
- a = (java_handle_##intern##array_t *) array; \
+ name##Array a(array); \
\
if (isCopy) \
*isCopy = JNI_FALSE; \
\
- return (type *) LLNI_array_data(a); \
+ return (type *) a.get_raw_data_ptr(); \
}
JNI_GET_ARRAY_ELEMENTS(Boolean, jboolean, boolean)
void _Jv_JNI_Release##name##ArrayElements(JNIEnv *env, type##Array array, \
type *elems, jint mode) \
{ \
- java_handle_##intern##array_t *a; \
- \
STATISTICS(jniinvokation()); \
\
- a = (java_handle_##intern##array_t *) array; \
+ name##Array a(array); \
\
- if (elems != (type *) LLNI_array_data(a)) { \
+ if (elems != (type *) a.get_raw_data_ptr()) { \
switch (mode) { \
case JNI_COMMIT: \
- MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
+ a.set_region(0, a.get_length(), (intern2 *) elems); \
break; \
case 0: \
- MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
+ a.set_region(0, a.get_length(), (intern2 *) elems); \
/* XXX TWISTI how should it be freed? */ \
break; \
case JNI_ABORT: \
void _Jv_JNI_Get##name##ArrayRegion(JNIEnv *env, type##Array array, \
jsize start, jsize len, type *buf) \
{ \
- java_handle_##intern##array_t *a; \
- \
TRACEJNICALLS(("_Jv_JNI_Get" STR(name) "ArrayRegion(env=%p, array=%p, start=%d, len=%d, buf=%p)", env, array, start, len, buf)); \
\
- a = (java_handle_##intern##array_t *) array; \
+ name##Array a(array); \
\
- if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
+ if ((start < 0) || (len < 0) || (start + len > a.get_length())) \
exceptions_throw_arrayindexoutofboundsexception(); \
else \
- MCOPY(buf, &LLNI_array_direct(a, start), intern2, len); \
+ a.get_region(start, len, (intern2 *) buf); \
}
JNI_GET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
void _Jv_JNI_Set##name##ArrayRegion(JNIEnv *env, type##Array array, \
jsize start, jsize len, const type *buf) \
{ \
- java_handle_##intern##array_t *a; \
- \
STATISTICS(jniinvokation()); \
\
- a = (java_handle_##intern##array_t *) array; \
+ name##Array a(array); \
\
- if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
+ if ((start < 0) || (len < 0) || (start + len > a.get_length())) \
exceptions_throw_arrayindexoutofboundsexception(); \
else \
- MCOPY(&LLNI_array_direct(a, start), buf, intern2, len); \
+ a.set_region(start, len, (intern2 *) buf); \
}
JNI_SET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
void jni_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
{
java_lang_String s(str);
- java_handle_chararray_t* ca = s.get_value();
- int32_t count = s.get_count();
+ CharArray ca(s.get_value());
+ int32_t count = s.get_count();
if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) {
exceptions_throw_stringindexoutofboundsexception();
return;
}
- MCOPY(buf, &LLNI_array_direct(ca, start), u2, len);
+ ca.get_region(start, len, buf);
}
TRACEJNICALLS(("jni_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf));
java_lang_String s(str);
- java_handle_chararray_t* ca = s.get_value();
- int32_t count = s.get_count();
- int32_t offset = s.get_offset();
+
+ CharArray ca(s.get_value());
+
+ int32_t count = s.get_count();
+ int32_t offset = s.get_offset();
if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) {
exceptions_throw_stringindexoutofboundsexception();
int32_t i;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
for (i = 0; i < len; i++)
- buf[i] = LLNI_array_direct(ca, offset + start + i);
+ buf[i] = ptr[offset + start + i];
buf[i] = '\0';
}
#define LLNI_field_direct(obj, field) (LLNI_DIRECT(obj)->field)
#define LLNI_vftbl_direct(obj) (LLNI_DIRECT((java_handle_t *) (obj))->vftbl)
-#define LLNI_array_direct(arr, index) (LLNI_DIRECT(arr)->data[(index)])
-#define LLNI_array_data(arr) (LLNI_DIRECT(arr)->data)
-#define LLNI_array_size(arr) (LLNI_DIRECT((java_handle_objectarray_t *) (arr))->header.size)
/* LLNI critical sections ******************************************************
#include "mm/memory.hpp"
#include "native/jni.hpp"
-#include "native/llni.h"
#include "native/native.hpp"
#if defined(ENABLE_JNI_HEADERS)
{
/* get pointer to the buffer */
// XXX Not GC safe.
- void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) byteArray, off));
-
+ ByteArray ba(byteArray);
+ void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
+
com_sun_cldchi_jvm_FileDescriptor fd(jobj);
int64_t filep = fd.get_pointer();
#include "mm/memory.hpp"
#include "native/jni.hpp"
-#include "native/llni.h"
#include "native/native.hpp"
#if defined(ENABLE_JNI_HEADERS)
// The hostname byte-array is a NULL terminated C-string.
// XXX Not GC safe.
- char* name = (char*) &(LLNI_array_data((java_handle_bytearray_t*) hostname));
+ ByteArray ba(hostname);
+ char* name = (char*) ba.get_raw_data_ptr();
/* get the host */
{
// Get pointer to the buffer.
// XXX Not GC safe.
- void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) b, off));
+ ByteArray ba(b);
+ void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
// Receive from the socket.
ssize_t result = recv(handle, buf, len, 0);
{
// Get pointer to the buffer.
// XXX Not GC safe.
- void* buf = &(LLNI_array_direct((java_handle_bytearray_t*) b, off));
+ ByteArray ba(b);
+ void* buf = (void*) (((int8_t*) ba.get_raw_data_ptr()) + off);
// Send the given byte to the socket.
ssize_t result = send(handle, buf, len, 0);
#include <string.h>
#include "native/jni.hpp"
-#include "native/llni.h"
#include "native/native.hpp"
#if defined(ENABLE_JNI_HEADERS)
{
java_lang_String jls(_this);
- java_handle_chararray_t* value = jls.get_value();
+ CharArray value(jls.get_value());
+
int32_t offset = jls.get_offset();
int32_t count = jls.get_count();
int32_t hash = 0;
for (int32_t i = 0; i < count; i++) {
- hash = (31 * hash) + LLNI_array_direct(value, offset + i);
+ hash = (31 * hash) + value.get_element(offset + i);
}
return hash;
{
java_lang_String jls(_this);
- java_handle_chararray_t* value = jls.get_value();
+ CharArray value(jls.get_value());
+
int32_t offset = jls.get_offset();
int32_t count = jls.get_count();
for (int32_t i = 0; i < count; i++) {
- if (LLNI_array_direct(value, offset + i) == ch) {
+ if (value.get_element(offset + i) == ch) {
return i;
}
}
{
java_lang_String jls(_this);
- java_handle_chararray_t* value = jls.get_value();
+ CharArray value(jls.get_value());
+
int32_t offset = jls.get_offset();
int32_t count = jls.get_count();
}
for (int32_t i = fromIndex ; i < count ; i++) {
- if (LLNI_array_direct(value, offset + i) == ch) {
+ if (value.get_element(offset + i) == ch) {
return i;
}
}
{
java_lang_String jls(_this);
- java_handle_chararray_t* value = jls.get_value();
+ CharArray value(jls.get_value());
+
int32_t offset = jls.get_offset();
int32_t count = jls.get_count();
int32_t start = ((fromIndex >= count) ? count - 1 : fromIndex);
for (int32_t i = start; i >= 0; i--) {
- if (LLNI_array_direct(value, offset + i) == ch) {
+ if (value.get_element(offset + i) == ch) {
return i;
}
}
# include "native/vm/include/gnu_java_lang_VMCPStringBuilder.h"
#endif
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/exceptions.hpp"
#include "vm/globals.hpp"
/* This is a native version of
java.lang.String.<init>([CIIZ)Ljava/lang/String; */
- if (startIndex < 0) {
+ if (startIndex < 0) {
/* exceptions_throw_stringindexoutofboundsexception("offset: " + offset); */
exceptions_throw_stringindexoutofboundsexception();
return NULL;
}
- if (count < 0) {
+ if (count < 0) {
/* exceptions_throw_stringindexoutofboundsexception("count: " + count); */
exceptions_throw_stringindexoutofboundsexception();
return NULL;
/* equivalent to: offset + count < 0 || offset + count > data.length */
- java_handle_chararray_t* ca = (java_handle_chararray_t*) value;
+ CharArray ca(value);
- LLNI_CRITICAL_START;
- int32_t length = LLNI_array_size(ca);
- LLNI_CRITICAL_END;
-
- if (length - startIndex < count) {
+ if (ca.get_length() - startIndex < count) {
/* exceptions_throw_stringindexoutofboundsexception("offset + count: " + (offset + count)); */
exceptions_throw_stringindexoutofboundsexception();
return NULL;
if (h == NULL)
return NULL;
- java_lang_String s(h, ca, (int32_t) count, (int32_t) startIndex);
+ java_lang_String s(h, ca.get_handle(), (int32_t) count, (int32_t) startIndex);
return (jstring) s.get_handle();
}
# include "native/vm/include/gnu_java_lang_management_VMRuntimeMXBeanImpl.h"
#endif
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
{
log_println("Java_gnu_java_lang_management_VMRuntimeMXBeanImpl_getInputArguments: IMPLEMENT ME!");
- return builtin_anewarray(0, class_java_lang_String);
+ ObjectArray oa(0, class_java_lang_String);
+
+ return oa.get_handle();
}
#include "vm/assertion.hpp"
#endif
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/class.hpp"
#include "vm/classcache.hpp"
*/
JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, jobject cl, jstring name, jbyteArray data, jint offset, jint len, jobject pd)
{
- utf *utfname;
- classinfo *c;
- classloader_t *loader;
- java_handle_bytearray_t* ba;
- uint8_t* stream;
+ utf* utfname;
+ classinfo* c;
+ classloader_t* loader;
+ uint8_t* stream;
#if defined(ENABLE_JVMTI)
jint new_class_data_len = 0;
/* check the indexes passed */
- if ((offset < 0) || (len < 0) || ((offset + len) > LLNI_array_size(data))) {
+ ByteArray ba(data);
+
+ if ((offset < 0) || (len < 0) || ((offset + len) > ba.get_length())) {
exceptions_throw_arrayindexoutofboundsexception();
return NULL;
}
else
#endif
{
- ba = (java_handle_bytearray_t*) data;
- stream = (uint8_t *) &LLNI_array_direct(ba, offset);
+ stream = ((uint8_t *) ba.get_raw_data_ptr()) + offset;
c = class_define(utfname, loader, len, stream, (java_handle_t *) pd);
}
// Get the stacktrace from the VMThrowable object.
- java_handle_bytearray_t* ba = vmt.get_vmdata();
+ ByteArray ba(vmt.get_vmdata());
// XXX Critical GC section?
- stacktrace_t* st = (stacktrace_t*) LLNI_array_data(ba);
+ stacktrace_t* st = (stacktrace_t*) ba.get_raw_data_ptr();
assert(st != NULL);
#include "toolbox/logging.hpp"
+#include "vm/array.hpp"
#include "vm/globals.hpp"
#include "vm/vm.hpp"
*/
JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getMemoryPoolNames(JNIEnv *env, jclass clazz)
{
- java_handle_objectarray_t *oa;
-
log_println("Java_java_lang_management_VMManagementFactory_getMemoryPoolNames: IMPLEMENT ME!");
- oa = builtin_anewarray(0, class_java_lang_String);
+ ObjectArray oa(0, class_java_lang_String);
- return oa;
+ return oa.get_handle();
}
*/
JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getMemoryManagerNames(JNIEnv *env, jclass clazz)
{
- java_handle_objectarray_t *oa;
-
log_println("Java_java_lang_management_VMManagementFactory_getMemoryManagerNames: IMPLEMENT ME!");
- oa = builtin_anewarray(0, class_java_lang_String);
+ ObjectArray oa(0, class_java_lang_String);
- return oa;
+ return oa.get_handle();
}
*/
JNIEXPORT jobjectArray JNICALL Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames(JNIEnv *env, jclass clazz)
{
- java_handle_objectarray_t *oa;
-
log_println("Java_java_lang_management_VMManagementFactory_getGarbageCollectorNames: IMPLEMENT ME!");
- oa = builtin_anewarray(0, class_java_lang_String);
+ ObjectArray oa(0, class_java_lang_String);
- return oa;
+ return oa.get_handle();
}
} // extern "C"
return 0;
}
- java_handle_bytearray_t* ba = jlt.get_backtrace();
+ ByteArray ba(jlt.get_backtrace());
- if (ba == NULL)
+ if (ba.is_null())
return 0;
// We need a critical section here as the stacktrace structure is
LLNI_CRITICAL_START;
- stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
+ stacktrace_t* st = (stacktrace_t *) ba.get_raw_data_ptr();
int32_t depth = st->length;
TRACEJVMCALLS(("JVM_GetStackTraceElement(env=%p, throwable=%p, index=%d)", env, throwable, index));
java_lang_Throwable jlt(throwable);
- java_handle_bytearray_t* ba = jlt.get_backtrace();
+ ByteArray ba(jlt.get_backtrace());
// XXX We need a critical section here as the stacktrace structure is
// mapped onto a Java byte-array.
- stacktrace_t* st = (stacktrace_t *) LLNI_array_data(ba);
+ stacktrace_t* st = (stacktrace_t *) ba.get_raw_data_ptr();
return stacktrace_get_StackTraceElement(st, index);
}
oa = class_get_interfaces(c);
- return (jobjectArray) oa;
+ return oa;
}
void JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers)
{
- classinfo *c;
- java_handle_objectarray_t *hoa;
-
TRACEJVMCALLS(("JVM_SetClassSigners(env=%p, cls=%p, signers=%p)", env, cls, signers));
- c = LLNI_classinfo_unwrap(cls);
+ classinfo* c = LLNI_classinfo_unwrap(cls);
- hoa = (java_handle_objectarray_t *) signers;
+ ObjectArray oa(signers);
/* This call is ignored for primitive types and arrays. Signers
are only set once, ClassLoader.java, and thus shouldn't be
if (class_is_primitive(c) || class_is_array(c))
return;
- LLNI_classinfo_field_set(c, signers, hoa);
+ // XXX: Fix this!
+ LLNI_classinfo_field_set(c, signers, (java_objectarray_t*) oa.get_handle());
}
oa = class_get_declaredclasses(c, false);
- return (jobjectArray) oa;
+ return oa;
}
oa = class_get_declaredfields(c, publicOnly);
- return (jobjectArray) oa;
+ return oa;
}
java_handle_objectarray_t* oa = class_get_declaredmethods(c, publicOnly);
- return (jobjectArray) oa;
+ return oa;
}
oa = class_get_declaredconstructors(c, publicOnly);
- return (jobjectArray) oa;
+ return oa;
}
jobject JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused)
{
- java_handle_objectarray_t *classes;
- java_handle_objectarray_t *packages;
- java_booleanarray_t *classEnabled;
- java_booleanarray_t *packageEnabled;
#if defined(ENABLE_ASSERTION)
- java_handle_t *js;
- s4 i, j;
+ java_handle_t* js;
+ s4 i, j;
#endif
TRACEJVMCALLS(("JVM_AssertionStatusDirectives(env=%p, unused=%p)", env, unused));
#if defined(ENABLE_ASSERTION)
- classes = builtin_anewarray(assertion_class_count, class_java_lang_Object);
+ ObjectArray classes(assertion_class_count, class_java_lang_Object);
#else
- classes = builtin_anewarray(0, class_java_lang_Object);
+ ObjectArray classes(0, class_java_lang_Object);
#endif
- if (classes == NULL)
+ if (classes.is_null())
return NULL;
#if defined(ENABLE_ASSERTION)
- packages = builtin_anewarray(assertion_package_count, class_java_lang_Object);
+ ObjectArray packages(assertion_package_count, class_java_lang_Object);
#else
- packages = builtin_anewarray(0, class_java_lang_Object);
+ ObjectArray packages(0, class_java_lang_Object);
#endif
- if (packages == NULL)
+ if (packages.is_null())
return NULL;
#if defined(ENABLE_ASSERTION)
- classEnabled = builtin_newarray_boolean(assertion_class_count);
+ BooleanArray classEnabled(assertion_class_count);
#else
- classEnabled = builtin_newarray_boolean(0);
+ BooleanArray classEnabled(0);
#endif
- if (classEnabled == NULL)
+ if (classEnabled.is_null())
return NULL;
#if defined(ENABLE_ASSERTION)
- packageEnabled = builtin_newarray_boolean(assertion_package_count);
+ BooleanArray packageEnabled(assertion_package_count);
#else
- packageEnabled = builtin_newarray_boolean(0);
+ BooleanArray packageEnabled(0);
#endif
- if (packageEnabled == NULL)
+ if (packageEnabled.is_null())
return NULL;
#if defined(ENABLE_ASSERTION)
}
if (item->package == false) {
- classes->data[i] = js;
- classEnabled->data[i] = (jboolean) item->enabled;
+ classes.set_element(i, js);
+ classEnabled.set_element(i, (jboolean) item->enabled);
i += 1;
}
else {
- packages->data[j] = js;
- packageEnabled->data[j] = (jboolean) item->enabled;
+ packages.set_element(j, js);
+ packageEnabled.set_element(j, (jboolean) item->enabled);
j += 1;
}
}
/* set instance fields */
- java_lang_AssertionStatusDirectives jlasd(classes, classEnabled, packages, packageEnabled);
+ java_lang_AssertionStatusDirectives jlasd(
+ classes.get_handle(),
+ classEnabled.get_handle(),
+ packages.get_handle(),
+ packageEnabled.get_handle());
return (jobject) jlasd.get_handle();
}
{
TRACEJVMCALLS(("JVM_GetClassContext(env=%p)", env));
- return (jobjectArray) stacktrace_getClassContext();
+ return stacktrace_getClassContext();
}
jint JVM_GetArrayLength(JNIEnv *env, jobject arr)
{
- java_handle_t *a;
-
TRACEJVMCALLS(("JVM_GetArrayLength(arr=%p)", arr));
- a = (java_handle_t *) arr;
+ if (arr == NULL) {
+ exceptions_throw_nullpointerexception();
+ return -1;
+ }
+
+ Array a(arr);
+
+ // Check for exception in constructor.
+ if (a.is_null()) {
+ return -1;
+ }
- return array_length_get(a);
+ return a.get_length();
}
jobject JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index)
{
- java_handle_t *a;
- java_handle_t *o;
-
TRACEJVMCALLS(("JVM_GetArrayElement(env=%p, arr=%p, index=%d)", env, arr, index));
- a = (java_handle_t *) arr;
+ Array a(arr);
/* if (!class_is_array(a->objheader.vftbl->class)) { */
/* exceptions_throw_illegalargumentexception(); */
/* return NULL; */
/* } */
- o = array_element_get(a, index);
-
- return (jobject) o;
+ return a.get_boxed_element(index);
}
void JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val)
{
- java_handle_t *a;
- java_handle_t *value;
-
TRACEJVMCALLS(("JVM_SetArrayElement(env=%p, arr=%p, index=%d, val=%p)", env, arr, index, val));
- a = (java_handle_t *) arr;
- value = (java_handle_t *) val;
+ Array a(arr);
- array_element_set(a, index, value);
+ a.set_boxed_element(index, val);
}
jobject JVM_NewArray(JNIEnv *env, jclass eltClass, jint length)
{
- classinfo *c;
- classinfo *pc;
- java_handle_t *a;
- java_handle_objectarray_t *oa;
-
TRACEJVMCALLS(("JVM_NewArray(env=%p, eltClass=%p, length=%d)", env, eltClass, length));
if (eltClass == NULL) {
return NULL;
}
- /* NegativeArraySizeException is checked in builtin_newarray. */
+ /* NegativeArraySizeException is checked by array constructor. */
- c = LLNI_classinfo_unwrap(eltClass);
+ classinfo* c = LLNI_classinfo_unwrap(eltClass);
/* Create primitive or object array. */
if (class_is_primitive(c)) {
- pc = Primitive::get_arrayclass_by_name(c->name);
+ classinfo* pc = Primitive::get_arrayclass_by_name(c->name);
/* void arrays are not allowed. */
return NULL;
}
- a = builtin_newarray(length, pc);
+ Array a(length, pc);
- return (jobject) a;
+ return (jobject) a.get_handle();
}
else {
- oa = builtin_anewarray(length, c);
+ ObjectArray oa(length, c);
- return (jobject) oa;
+ return (jobject) oa.get_handle();
}
}
jobject JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim)
{
classinfo *c;
- java_handle_intarray_t *ia;
int32_t length;
long *dims;
int32_t value;
c = LLNI_classinfo_unwrap(eltClass);
- ia = (java_handle_intarray_t *) dim;
-
- length = array_length_get((java_handle_t *) ia);
+ IntArray ia(dim);
/* We check here for exceptions thrown in array_length_get,
otherwise these exceptions get overwritten by the following
IllegalArgumentException. */
- if (length < 0)
+ if (ia.is_null())
return NULL;
+ length = ia.get_length();
+
if ((length <= 0) || (length > /* MAX_DIM */ 255)) {
exceptions_throw_illegalargumentexception();
return NULL;
dims = MNEW(long, length);
for (i = 0; i < length; i++) {
- value = LLNI_array_direct(ia, i);
+ value = ia.get_element(i);
dims[i] = (long) value;
}
// Allocate array to hold the java.lang.Thread objects.
int32_t length = active_threads.size();
- java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_Thread);
+ ObjectArray oa(length, class_java_lang_Thread);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
// Iterate over all threads (which were active just a second ago).
java_handle_t* h = thread_get_object(t);
assert(h != NULL);
- array_objectarray_element_set(oa, index, h);
+ oa.set_element(index, h);
index++;
}
- return oa;
+ return oa.get_handle();
}
return NULL;
}
+ ObjectArray oa(threads);
+
// Get length of the threads array.
- int32_t length = array_length_get((java_handle_t*) threads);
+ int32_t length = oa.get_length();
if (length <= 0) {
exceptions_throw_illegalargumentexception();
// Allocate array to hold stacktraces.
classinfo* arrayclass = class_array_of(class_java_lang_StackTraceElement, true);
- java_handle_objectarray_t* oas = builtin_anewarray(length, arrayclass);
+ ObjectArray oaresult(length, arrayclass);
- if (oas == NULL) {
+ if (oaresult.is_null()) {
return NULL;
}
// Iterate over all passed thread objects.
for (i = 0; i < length; i++) {
- java_handle_t* thread = array_objectarray_element_get(threads, i);
+ java_handle_t* thread = oa.get_element(i);
// Get thread for the given thread object.
threadobject* t = thread_get_thread(thread);
stacktrace_t* st = stacktrace_get_of_thread(t);
// Convert stacktrace into array of StackTraceElements.
- java_handle_objectarray_t* oa = stacktrace_get_StackTraceElements(st);
+ java_handle_objectarray_t* oaste = stacktrace_get_StackTraceElements(st);
- if (oa == NULL)
+ if (oaste == NULL)
return NULL;
- array_objectarray_element_set(oas, i, (java_handle_t*) oa);
+ oaresult.set_element(i, oaste);
}
- return oas;
+ return oaresult.get_handle();
}
jobjectArray JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass)
{
- classinfo *c;
- methodinfo *m;
- java_handle_objectarray_t *oa;
-
TRACEJVMCALLS(("JVM_GetEnclosingMethodInfo(env=%p, ofClass=%p)", env, ofClass));
- c = LLNI_classinfo_unwrap(ofClass);
+ classinfo* c = LLNI_classinfo_unwrap(ofClass);
if ((c == NULL) || class_is_primitive(c))
return NULL;
- m = class_get_enclosingmethod_raw(c);
+ methodinfo* m = class_get_enclosingmethod_raw(c);
if (m == NULL)
return NULL;
- oa = builtin_anewarray(3, class_java_lang_Object);
+ ObjectArray oa(3, class_java_lang_Object);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
- array_objectarray_element_set(oa, 0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
- array_objectarray_element_set(oa, 1, javastring_new(m->name));
- array_objectarray_element_set(oa, 2, javastring_new(m->descriptor));
+ oa.set_element(0, (java_handle_t *) LLNI_classinfo_wrap(m->clazz));
+ oa.set_element(1, javastring_new(m->name));
+ oa.set_element(2, javastring_new(m->descriptor));
- return (jobjectArray) oa;
+ return oa.get_handle();
}
jintArray JVM_GetThreadStateValues(JNIEnv* env, jint javaThreadState)
{
- java_handle_intarray_t *ia;
-
TRACEJVMCALLS(("JVM_GetThreadStateValues(env=%p, javaThreadState=%d)",
env, javaThreadState));
switch (javaThreadState) {
case THREAD_STATE_NEW:
- ia = builtin_newarray_int(1);
+ {
+ IntArray ia(1);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- array_intarray_element_set(ia, 0, THREAD_STATE_NEW);
- break;
+ ia.set_element(0, THREAD_STATE_NEW);
+ return ia.get_handle();
+ }
case THREAD_STATE_RUNNABLE:
- ia = builtin_newarray_int(1);
+ {
+ IntArray ia(1);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- array_intarray_element_set(ia, 0, THREAD_STATE_RUNNABLE);
- break;
+ ia.set_element(0, THREAD_STATE_RUNNABLE);
+ return ia.get_handle();
+ }
case THREAD_STATE_BLOCKED:
- ia = builtin_newarray_int(1);
+ {
+ IntArray ia(1);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- array_intarray_element_set(ia, 0, THREAD_STATE_BLOCKED);
- break;
+ ia.set_element(0, THREAD_STATE_BLOCKED);
+ return ia.get_handle();
+ }
case THREAD_STATE_WAITING:
- ia = builtin_newarray_int(2);
+ {
+ IntArray ia(2);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- array_intarray_element_set(ia, 0, THREAD_STATE_WAITING);
- array_intarray_element_set(ia, 1, THREAD_STATE_PARKED);
- break;
+ ia.set_element(0, THREAD_STATE_WAITING);
+ ia.set_element(1, THREAD_STATE_PARKED);
+ return ia.get_handle();
+ }
case THREAD_STATE_TIMED_WAITING:
- ia = builtin_newarray_int(2);
+ {
+ IntArray ia(2);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- /* XXX Not sure about that one. */
-/* array_intarray_element_set(ia, 0, SLEEPING); */
- array_intarray_element_set(ia, 0, THREAD_STATE_TIMED_WAITING);
- array_intarray_element_set(ia, 1, THREAD_STATE_TIMED_PARKED);
- break;
+ /* XXX Not sure about that one. */
+/* ia.set_element(0, SLEEPING); */
+ ia.set_element(0, THREAD_STATE_TIMED_WAITING);
+ ia.set_element(1, THREAD_STATE_TIMED_PARKED);
+ return ia.get_handle();
+ }
case THREAD_STATE_TERMINATED:
- ia = builtin_newarray_int(1);
+ {
+ IntArray ia(1);
- if (ia == NULL)
- return NULL;
+ if (ia.is_null())
+ return NULL;
- array_intarray_element_set(ia, 0, THREAD_STATE_TERMINATED);
- break;
+ ia.set_element(0, THREAD_STATE_TERMINATED);
+ return ia.get_handle();
+ }
default:
/* Unknown state - probably incompatible JDK version */
return NULL;
}
-
- return (jintArray) ia;
}
jobjectArray JVM_GetThreadStateNames(JNIEnv* env, jint javaThreadState, jintArray values)
{
- java_handle_intarray_t *ia;
- java_handle_objectarray_t *oa;
- java_object_t *s;
+ java_object_t* s;
TRACEJVMCALLS(("JVM_GetThreadStateNames(env=%p, javaThreadState=%d, values=%p)",
env, javaThreadState, values));
- ia = (java_handle_intarray_t *) values;
+ IntArray ia(values);
/* If new thread states are added in future JDK and VM versions,
this should check if the JDK version is compatible with thread
switch (javaThreadState) {
case THREAD_STATE_NEW:
- assert(ia->header.size == 1 && ia->data[0] == THREAD_STATE_NEW);
+ {
+ assert(ia.get_length() == 1 && ia.get_element(0) == THREAD_STATE_NEW);
- oa = builtin_anewarray(1, class_java_lang_String);
+ ObjectArray oa(1, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
- s = javastring_new(utf_new_char("NEW"));
+ s = javastring_new(utf_new_char("NEW"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
- break;
+ oa.set_element(0, s);
+ return oa.get_handle();
+ }
case THREAD_STATE_RUNNABLE:
- oa = builtin_anewarray(1, class_java_lang_String);
+ {
+ ObjectArray oa(1, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
- s = javastring_new(utf_new_char("RUNNABLE"));
+ s = javastring_new(utf_new_char("RUNNABLE"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
- break;
+ oa.set_element(0, s);
+ return oa.get_handle();
+ }
case THREAD_STATE_BLOCKED:
- oa = builtin_anewarray(1, class_java_lang_String);
+ {
+ ObjectArray oa(1, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
- s = javastring_new(utf_new_char("BLOCKED"));
+ s = javastring_new(utf_new_char("BLOCKED"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
- break;
+ oa.set_element(0, s);
+ return oa.get_handle();
+ }
case THREAD_STATE_WAITING:
- oa = builtin_anewarray(2, class_java_lang_String);
+ {
+ ObjectArray oa(2, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
- s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
+ s = javastring_new(utf_new_char("WAITING.OBJECT_WAIT"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
+ oa.set_element(0, s);
- s = javastring_new(utf_new_char("WAITING.PARKED"));
+ s = javastring_new(utf_new_char("WAITING.PARKED"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 1, s);
- break;
+ oa.set_element(1, s);
+ return oa.get_handle();
+ }
case THREAD_STATE_TIMED_WAITING:
- oa = builtin_anewarray(2, class_java_lang_String);
+ {
+ ObjectArray oa(2, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
-/* s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
- s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
+/* s = javastring_new(utf_new_char("TIMED_WAITING.SLEEPING")); */
+ s = javastring_new(utf_new_char("TIMED_WAITING.OBJECT_WAIT"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
+ oa.set_element(0, s);
- s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
+ s = javastring_new(utf_new_char("TIMED_WAITING.PARKED"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 1, s);
- break;
+ oa.set_element(1, s);
+ return oa.get_handle();
+ }
case THREAD_STATE_TERMINATED:
- oa = builtin_anewarray(1, class_java_lang_String);
+ {
+ ObjectArray oa(1, class_java_lang_String);
- if (oa == NULL)
- return NULL;
+ if (oa.is_null())
+ return NULL;
- s = javastring_new(utf_new_char("TERMINATED"));
+ s = javastring_new(utf_new_char("TERMINATED"));
- if (s == NULL)
- return NULL;
+ if (s == NULL)
+ return NULL;
- array_objectarray_element_set(oa, 0, s);
- break;
+ oa.set_element(0, s);
+ return oa.get_handle();
+ }
default:
/* Unknown state - probably incompatible JDK version */
return NULL;
}
-
- return (jobjectArray) oa;
}
#include "native/vm/reflection.hpp"
#include "vm/access.hpp"
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/exceptions.hpp"
#include "vm/global.h"
/* check if we got the right number of arguments */
+ ObjectArray oa(params);
+
if (((params == NULL) && (paramcount != 0)) ||
- (params && (LLNI_array_size(params) != paramcount)))
+ (params && (oa.get_length() != paramcount)))
{
exceptions_throw_illegalargumentexception();
return NULL;
# include "native/include/sun_misc_Unsafe.h"
#endif
+#include "vm/array.hpp"
#include "vm/jit/builtin.hpp"
#include "vm/exceptions.hpp"
#include "vm/initialize.hpp"
/* check the indexes passed */
- if ((off < 0) || (len < 0) || ((off + len) > LLNI_array_size(b))) {
+ ByteArray ba(b);
+
+ if ((off < 0) || (len < 0) || ((off + len) > ba.get_length())) {
exceptions_throw_arrayindexoutofboundsexception();
return NULL;
}
/* define the class */
- c = class_define(utfname, cl, len, (uint8_t *) &(LLNI_array_direct((java_handle_bytearray_t*) b, off)),
+ uint8_t* ptr = ((uint8_t*) ba.get_raw_data_ptr()) + off;
+ c = class_define(utfname, cl, len, ptr,
(java_handle_t *) protectionDomain);
if (c == NULL)
static java_handle_objectarray_t *annotation_bytearrays_resize(
java_handle_objectarray_t *bytearrays, uint32_t size)
{
- java_handle_objectarray_t *newbas = NULL; /* new array */
uint32_t minsize = 0; /* count of object refs to copy */
uint32_t oldsize = 0; /* size of old array */
+ ObjectArray bas(bytearrays);
+
if (bytearrays != NULL) {
- oldsize = array_length_get((java_handle_t*)bytearrays);
+ oldsize = bas.get_length();
/* if the size already fits do nothing */
if (size == oldsize) {
return bytearrays;
}
}
-
- newbas = builtin_anewarray(size,
+
+ // Allocate new array on the heap.
+
+ ObjectArray newbas(size,
Primitive::get_arrayclass_by_type(PRIMITIVETYPE_BYTE));
-
+
/* is there a old byte array array? */
- if (newbas != NULL && bytearrays != NULL) {
+ if (newbas.is_non_null() && bytearrays != NULL) {
minsize = size < oldsize ? size : oldsize;
LLNI_CRITICAL_START;
MCOPY(
- LLNI_array_data(newbas), LLNI_array_data(bytearrays),
+ newbas.get_raw_data_ptr(), bas.get_raw_data_ptr(),
java_object_t*, minsize);
LLNI_CRITICAL_END;
}
- return newbas;
+ return newbas.get_handle();
}
java_handle_t *bytearrays, uint32_t index,
java_handle_bytearray_t *bytearray)
{
- java_handle_objectarray_t *bas; /* bytearrays */
uint32_t size = 0; /* current size of the array */
/* do nothing if NULL is inserted but no array exists */
return NULL;
}
+ ObjectArray bas(bytearrays);
+
/* get lengths if array exists */
if (bytearrays != NULL) {
- size = array_length_get(bytearrays);
+ size = bas.get_length();
}
- bas = (java_handle_objectarray_t*)bytearrays;
-
if (bytearray == NULL) {
/* insert NULL only if array is big enough */
if (size > index) {
- array_objectarray_element_set(bas, index, NULL);
+ bas.set_element(index, NULL);
}
}
else {
+ // XXX: We should use a clone function here!!!
/* resize array if it's not enough for inserted value */
if (size <= index) {
- bas = annotation_bytearrays_resize(bas, index + 1);
+ bas = annotation_bytearrays_resize(bas.get_handle(), index + 1);
- if (bas == NULL) {
+ if (bas.is_null()) {
/* out of memory */
return NULL;
}
}
- array_objectarray_element_set(bas, index, (java_handle_t*)bytearray);
+ bas.set_element(index, (java_handle_t*) bytearray);
}
- return (java_handle_t*)bas;
+ return bas.get_handle();
}
java_handle_bytearray_t **attribute, const char *errormsg_prefix)
{
uint32_t size = 0; /* size of the attribute */
- java_handle_bytearray_t *ba = NULL; /* the raw attributes' bytes */
assert(cb != NULL);
assert(attribute != NULL);
/* if attribute_length == 0 then NULL is
* the right value for this attribute */
if (size > 0) {
- ba = builtin_newarray_byte(size);
+ ByteArray ba(size);
- if (ba == NULL) {
+ if (ba.is_null()) {
/* out of memory */
return false;
}
/* load data */
LLNI_CRITICAL_START;
- suck_nbytes((uint8_t*)LLNI_array_data(ba), cb, size);
+ uint8_t* ptr = (uint8_t*) ba.get_raw_data_ptr();
+ suck_nbytes(ptr, cb, size);
LLNI_CRITICAL_END;
/* return data */
- *attribute = ba;
+ *attribute = ba.get_handle();
}
return true;
Copyright (C) 2007
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+ Copyright (C) 2008 Theobroma Systems Ltd.
This file is part of CACAO.
#include "vm/array.hpp"
#include "vm/exceptions.hpp"
#include "vm/global.h"
+#include "vm/globals.hpp"
#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)
+/**
+ * Returns a boxed element of the given Java array.
+ */
+java_handle_t* Array::get_boxed_element(int32_t index)
{
vftbl_t *v;
int type;
imm_union value;
java_handle_t *o;
- if (a == NULL) {
+ if (is_null()) {
exceptions_throw_nullpointerexception();
return NULL;
}
- v = LLNI_vftbl_direct(a);
+ v = LLNI_vftbl_direct(_handle);
type = v->arraydesc->arraytype;
- value = array_element_primitive_get(a, index);
+ value = get_primitive_element(index);
o = Primitive::box(type, value);
}
-/* 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)
+/**
+ * Sets a boxed element in the given Java array.
+ */
+void Array::set_boxed_element(int32_t index, java_handle_t *o)
{
imm_union value;
value = Primitive::unbox(o);
- array_element_primitive_set(a, index, value);
+ set_primitive_element(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)
+/**
+ * Returns a primitive element of the given Java array.
+ */
+imm_union Array::get_primitive_element(int32_t index)
{
vftbl_t *v;
int type;
imm_union value;
- if (a == NULL) {
+ if (is_null()) {
exceptions_throw_nullpointerexception();
value.a = NULL;
return value;
}
+ java_handle_array_t* a = _handle;
+
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);
+ {
+ BooleanArray array(a);
+ value.i = array.get_element(index);
+ }
break;
case ARRAYTYPE_BYTE:
- value.i = array_bytearray_element_get((java_handle_bytearray_t *) a,
- index);
+ {
+ ByteArray array(a);
+ value.i = array.get_element(index);
+ }
break;
case ARRAYTYPE_CHAR:
- value.i = array_chararray_element_get((java_handle_chararray_t *) a,
- index);
+ {
+ CharArray array(a);
+ value.i = array.get_element(index);
+ }
break;
case ARRAYTYPE_SHORT:
- value.i = array_shortarray_element_get((java_handle_shortarray_t *) a,
- index);
+ {
+ ShortArray array(a);
+ value.i = array.get_element(index);
+ }
break;
case ARRAYTYPE_INT:
- value.i = array_intarray_element_get((java_handle_intarray_t *) a,
- index);
+ {
+ IntArray array(a);
+ value.i = array.get_element(index);
+ }
break;
case ARRAYTYPE_LONG:
- value.l = array_longarray_element_get((java_handle_longarray_t *) a,
- index);
+ {
+ LongArray array(a);
+ value.l = array.get_element(index);
+ }
break;
case ARRAYTYPE_FLOAT:
- value.f = array_floatarray_element_get((java_handle_floatarray_t *) a,
- index);
+ {
+ FloatArray array(a);
+ value.f = array.get_element(index);
+ }
break;
case ARRAYTYPE_DOUBLE:
- value.d = array_doublearray_element_get((java_handle_doublearray_t *) a,
- index);
+ {
+ DoubleArray array(a);
+ value.d = array.get_element(index);
+ }
break;
case ARRAYTYPE_OBJECT:
- value.a = array_objectarray_element_get((java_handle_objectarray_t *) a,
- index);
+ {
+ ObjectArray array(a);
+ value.a = array.get_element(index);
+ }
break;
default:
- vm_abort("array_element_primitive_get: invalid array element type %d",
+ vm_abort("Array::primitive_element_get: invalid array element type %d",
type);
}
}
-/* 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)
+/**
+ * Sets a primitive element in the given Java array.
+ */
+void Array::set_primitive_element(int32_t index, imm_union value)
{
vftbl_t *v;
int type;
- if (a == NULL) {
+ if (is_null()) {
exceptions_throw_nullpointerexception();
return;
}
+ java_handle_array_t* a = _handle;
+
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);
+ {
+ BooleanArray array(a);
+ array.set_element(index, value.i);
+ }
break;
case ARRAYTYPE_BYTE:
- array_bytearray_element_set((java_handle_bytearray_t *) a,
- index, value.i);
+ {
+ ByteArray array(a);
+ array.set_element(index, value.i);
+ }
break;
case ARRAYTYPE_CHAR:
- array_chararray_element_set((java_handle_chararray_t *) a,
- index, value.i);
+ {
+ CharArray array(a);
+ array.set_element(index, value.i);
+ }
break;
case ARRAYTYPE_SHORT:
- array_shortarray_element_set((java_handle_shortarray_t *) a,
- index, value.i);
+ {
+ ShortArray array(a);
+ array.set_element(index, value.i);
+ }
break;
case ARRAYTYPE_INT:
- array_intarray_element_set((java_handle_intarray_t *) a,
- index, value.i);
+ {
+ IntArray array(a);
+ array.set_element(index, value.i);
+ }
break;
case ARRAYTYPE_LONG:
- array_longarray_element_set((java_handle_longarray_t *) a,
- index, value.l);
+ {
+ LongArray array(a);
+ array.set_element(index, value.l);
+ }
break;
case ARRAYTYPE_FLOAT:
- array_floatarray_element_set((java_handle_floatarray_t *) a,
- index, value.f);
+ {
+ FloatArray array(a);
+ array.set_element(index, value.f);
+ }
break;
case ARRAYTYPE_DOUBLE:
- array_doublearray_element_set((java_handle_doublearray_t *) a,
- index, value.d);
+ {
+ DoubleArray array(a);
+ array.set_element(index, value.d);
+ }
break;
case ARRAYTYPE_OBJECT:
- array_objectarray_element_set((java_handle_objectarray_t *) a,
- index, static_cast<java_handle_t*>(value.a));
+ {
+ ObjectArray array(a);
+ array.set_element(index, static_cast<java_handle_t*>(value.a));
+ }
break;
default:
vm_abort("array_element_primitive_set: invalid array element type %d",
}
-/* 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)
+/**
+ * Creates an array of references to the given class type on the heap.
+ * The handle pointer to the array can be NULL in case of an exception.
+ */
+ObjectArray::ObjectArray(int32_t length, classinfo* componentclass)
+ : ArrayTemplate<java_handle_t*>(NULL)
{
- int32_t size;
+ // Is class loaded?
+ assert(componentclass->state & CLASS_LOADED);
- 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();
+ // Is class linked?
+ if (!(componentclass->state & CLASS_LINKED))
+ if (!link_class(componentclass)) {
+ _handle = NULL;
return;
}
- }
- size = LLNI_array_size(a);
+ classinfo* arrayclass = class_array_of(componentclass, true);
- if ((index < 0) || (index >= size)) {
- exceptions_throw_arrayindexoutofboundsexception();
+ if (arrayclass == NULL) {
+ _handle = NULL;
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
+ // Delegate allocation to generic array class
+ Array a(length, arrayclass);
- RETURN VALUE:
- -1 ... exception thrown
- >= 0 ... length of the Java array
+ _handle = a.get_handle();
+}
-*******************************************************************************/
-int32_t array_length_get(java_handle_t *a)
+/**
+ * Creates an array of references to classinfos on the heap.
+ * The handle pointer to the array can be NULL in case of an exception.
+ */
+ClassArray::ClassArray(int32_t length)
+ : ArrayTemplate<classinfo*>(NULL)
{
- 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);
+ // Delegate allocation to object array class
+ ObjectArray oa(length, class_java_lang_Class);
- return size;
+ _handle = oa.get_handle();
}
Copyright (C) 2007
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+ Copyright (C) 2008 Theobroma Systems Ltd.
This file is part of CACAO.
#include <stdint.h>
+#include "mm/gc.hpp" // XXX Remove me!
+
+#include "native/llni.h" // XXX Remove me!
+
+#include "vm/class.hpp"
+#include "vm/exceptions.hpp"
#include "vm/global.h"
#include "vm/primitive.hpp"
#define ARRAYTYPE_OBJECT PRIMITIVETYPE_VOID /* don't use as index! */
-/* function prototypes ********************************************************/
-
#ifdef __cplusplus
-extern "C" {
+
+/**
+ * This is a generic accessor class for Java arrays (of unspecified type),
+ * which can be used to safely operate on Java arrays in native code.
+ */
+class Array {
+protected:
+ // Handle of Java array.
+ java_handle_array_t* _handle;
+
+private:
+ // We don't want a Java arrays to be copied.
+ Array(Array* a) {}
+ Array(Array& a) {}
+
+public:
+ inline Array(java_handle_t* h);
+ inline Array(int32_t length, classinfo* arrayclass);
+ virtual ~Array() {}
+
+ // Getters.
+ virtual inline java_handle_array_t* get_handle() const { return _handle; }
+ inline int32_t get_length() const;
+
+ inline bool is_null () const;
+ inline bool is_non_null() const;
+
+ // Safe element modification functions for primitive values
+ imm_union get_primitive_element(int32_t index);
+ void set_primitive_element(int32_t index, imm_union value);
+
+ // Safe element modification functions for boxed values
+ java_handle_t* get_boxed_element(int32_t index);
+ void set_boxed_element(int32_t index, java_handle_t *o);
+
+ // XXX REMOVE ME!
+ inline void* get_raw_data_ptr() { return ((java_objectarray_t*) _handle)->data; }
+};
+
+
+/**
+ * Constructor checks if passed handle really is a Java array.
+ */
+inline Array::Array(java_handle_t* h)
+{
+ if (h == NULL) {
+ _handle = NULL;
+ return;
+ }
+
+#if 0
+ classinfo* c;
+ LLNI_class_get(h, c);
+ if (!class_is_array(c)) {
+ printf("Array::Array(): WARNING, passed handle is not an array\n");
+ //exceptions_throw_illegalargumentexception("Argument is not an array");
+ exceptions_throw_illegalargumentexception();
+ _handle = NULL;
+ return;
+ }
#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);
+ _handle = h;
+}
-#ifdef __cplusplus
-} // extern "C"
+/**
+ * Creates an array of the given array type on the heap.
+ * The handle pointer to the array can be NULL in case of an exception.
+ */
+inline Array::Array(int32_t size, classinfo* arrayclass)
+{
+ // Sanity check.
+ assert(class_is_array(arrayclass));
+
+ if (size < 0) {
+ exceptions_throw_negativearraysizeexception();
+ _handle = NULL;
+ return;
+ }
+
+ arraydescriptor* desc = arrayclass->vftbl->arraydesc;
+ int32_t dataoffset = desc->dataoffset;
+ int32_t componentsize = desc->componentsize;
+ int32_t actualsize = dataoffset + size * componentsize;
+
+ // Check for overflow.
+
+ if (((u4) actualsize) < ((u4) size)) {
+ exceptions_throw_outofmemoryerror();
+ _handle = NULL;
+ return;
+ }
+
+ java_array_t* a = (java_array_t*) heap_alloc(actualsize, (desc->arraytype == ARRAYTYPE_OBJECT), NULL, true);
+
+ if (a == NULL) {
+ _handle = NULL;
+ return;
+ }
+
+ LLNI_vftbl_direct(a) = arrayclass->vftbl;
+
+#if defined(ENABLE_THREADS)
+ a->objheader.lockword.init();
+#endif
+
+ a->size = size;
+
+ _handle = (java_handle_array_t*) a;
+}
+
+inline int32_t Array::get_length() const
+{
+ if (is_null()) {
+ printf("Array::get_length(): WARNING, got null-pointer\n");
+ exceptions_throw_nullpointerexception();
+ return -1;
+ }
+
+ // XXX Fix me!
+ int32_t length = ((java_array_t*) _handle)->size;
+
+ return length;
+}
+
+inline bool Array::is_null() const
+{
+ return (_handle == NULL);
+}
+
+inline bool Array::is_non_null() const
+{
+ return (_handle != NULL);
+}
+
+
+/**
+ * This is a template of an accessor class for Java arrays
+ * of a specific type.
+ */
+template<class T> class ArrayTemplate : public Array {
+protected:
+ ArrayTemplate(int32_t length, classinfo* arrayclass) : Array(length, arrayclass) {}
+
+public:
+ inline ArrayTemplate(java_handle_array_t* h) : Array(h) {}
+
+ // Safe element modification functions
+ inline T get_element(int32_t index);
+ inline void set_element(int32_t index, T value);
+
+ // Region copy functions
+ inline void get_region(int32_t offset, int32_t count, T* buffer);
+ inline void set_region(int32_t offset, int32_t count, const T* buffer);
+};
+
+
+template<class T> inline T ArrayTemplate<T>::get_element(int32_t index)
+{
+ if (is_null()) {
+ exceptions_throw_nullpointerexception();
+ return 0;
+ }
+
+ if ((index < 0) || (index >= get_length())) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return 0;
+ }
+
+ // XXX Fix me!
+ T* ptr = (T*) get_raw_data_ptr();
+
+ return ptr[index];
+}
+
+template<class T> inline void ArrayTemplate<T>::set_element(int32_t index, T value)
+{
+ if (is_null()) {
+ exceptions_throw_nullpointerexception();
+ return;
+ }
+
+ if ((index < 0) || (index >= get_length())) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return;
+ }
+
+ // XXX Fix me!
+ T* ptr = (T*) get_raw_data_ptr();
+
+ ptr[index] = value;
+}
+
+template<> inline void ArrayTemplate<java_handle_t*>::set_element(int32_t index, java_handle_t* value)
+{
+ if (is_null()) {
+ exceptions_throw_nullpointerexception();
+ return;
+ }
+
+ // Sanity check.
+ assert(((java_array_t*) _handle)->objheader.vftbl->arraydesc->arraytype == ARRAYTYPE_OBJECT);
+
+ // Check if value can be stored
+ if (value != NULL) {
+ if (builtin_canstore(get_handle(), value) == false) {
+ exceptions_throw_illegalargumentexception();
+ return;
+ }
+ }
+
+ if ((index < 0) || (index >= get_length())) {
+ exceptions_throw_arrayindexoutofboundsexception();
+ return;
+ }
+
+ // XXX Fix me!
+ java_handle_t** ptr = (java_handle_t**) get_raw_data_ptr();
+
+ ptr[index] = value;
+}
+
+template<class T> inline void ArrayTemplate<T>::get_region(int32_t offset, int32_t count, T* buffer)
+{
+ // Copy the array region inside a GC critical section.
+ GCCriticalSection cs;
+
+ // XXX Fix me!
+ const T* ptr = (T*) get_raw_data_ptr();
+
+ os::memcpy(buffer, ptr + offset, sizeof(T) * count);
+}
+
+template<class T> inline void ArrayTemplate<T>::set_region(int32_t offset, int32_t count, const T* buffer)
+{
+ // Copy the array region inside a GC critical section.
+ GCCriticalSection cs;
+
+ // XXX Fix me!
+ T* ptr = (T*) get_raw_data_ptr();
+
+ os::memcpy(ptr + offset, buffer, sizeof(T) * count);
+}
+
+
+/**
+ * Actual implementations of common Java array access classes.
+ */
+class BooleanArray : public ArrayTemplate<uint8_t> {
+public:
+ inline BooleanArray(java_handle_booleanarray_t* h) : ArrayTemplate<uint8_t>(h) {}
+ inline BooleanArray(int32_t length) : ArrayTemplate<uint8_t>(length, primitivetype_table[ARRAYTYPE_BOOLEAN].arrayclass) {}
+};
+
+class ByteArray : public ArrayTemplate<int8_t> {
+public:
+ inline ByteArray(java_handle_bytearray_t* h) : ArrayTemplate<int8_t>(h) {}
+ inline ByteArray(int32_t length) : ArrayTemplate<int8_t>(length, primitivetype_table[ARRAYTYPE_BYTE].arrayclass) {}
+};
+
+class CharArray : public ArrayTemplate<uint16_t> {
+public:
+ inline CharArray(java_handle_chararray_t* h) : ArrayTemplate<uint16_t>(h) {}
+ inline CharArray(int32_t length) : ArrayTemplate<uint16_t>(length, primitivetype_table[ARRAYTYPE_CHAR].arrayclass) {}
+};
+
+class ShortArray : public ArrayTemplate<int16_t> {
+public:
+ inline ShortArray(java_handle_shortarray_t* h) : ArrayTemplate<int16_t>(h) {}
+ inline ShortArray(int32_t length) : ArrayTemplate<int16_t>(length, primitivetype_table[ARRAYTYPE_SHORT].arrayclass) {}
+};
+
+class IntArray : public ArrayTemplate<int32_t> {
+public:
+ inline IntArray(java_handle_intarray_t* h) : ArrayTemplate<int32_t>(h) {}
+ inline IntArray(int32_t length) : ArrayTemplate<int32_t>(length, primitivetype_table[ARRAYTYPE_INT].arrayclass) {}
+};
+
+class LongArray : public ArrayTemplate<int64_t> {
+public:
+ inline LongArray(java_handle_longarray_t* h) : ArrayTemplate<int64_t>(h) {}
+ inline LongArray(int32_t length) : ArrayTemplate<int64_t>(length, primitivetype_table[ARRAYTYPE_LONG].arrayclass) {}
+};
+
+class FloatArray : public ArrayTemplate<float> {
+public:
+ inline FloatArray(java_handle_floatarray_t* h) : ArrayTemplate<float>(h) {}
+ inline FloatArray(int32_t length) : ArrayTemplate<float>(length, primitivetype_table[ARRAYTYPE_FLOAT].arrayclass) {}
+};
+
+class DoubleArray : public ArrayTemplate<double> {
+public:
+ inline DoubleArray(java_handle_doublearray_t* h) : ArrayTemplate<double>(h) {}
+ inline DoubleArray(int32_t length) : ArrayTemplate<double>(length, primitivetype_table[ARRAYTYPE_DOUBLE].arrayclass) {}
+};
+
+/**
+ * Actual implementation of access class for Java Object arrays.
+ */
+class ObjectArray : public ArrayTemplate<java_handle_t*> {
+public:
+ inline ObjectArray(java_handle_objectarray_t* h) : ArrayTemplate<java_handle_t*>(h) {}
+ ObjectArray(int32_t length, classinfo* componentclass);
+};
+
+/**
+ * Actual implementation of access class for java.lang.Class arrays.
+ */
+class ClassArray : public ArrayTemplate<classinfo*> {
+public:
+ ClassArray(int32_t length);
+};
+
+
+#else
+# warning No legacy C functions for array access classes.
#endif
#endif // _VM_ARRAY_HPP
utf *outername;
int declaredclasscount; /* number of declared classes */
int pos; /* current declared class */
- java_handle_objectarray_t *oa; /* array of declared classes */
int i;
classinfo *ic;
/* Allocate Class[] and check for OOM. */
- oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
+ ClassArray declaredclasses(declaredclasscount);
- if (oa == NULL)
+ if (declaredclasses.is_null())
return NULL;
for (i = 0, pos = 0; i < c->innerclasscount; i++) {
if (!link_class(ic))
return NULL;
- LLNI_array_direct(oa, pos++) = (java_object_t *) ic;
+ declaredclasses.set_element(pos++, ic);
}
}
- return oa;
+ return declaredclasses.get_handle();
}
#if defined(ENABLE_JAVASE)
java_handle_objectarray_t *class_get_declaredconstructors(classinfo *c, bool publicOnly)
{
- methodinfo* m;
- java_handle_objectarray_t* oa;
- int count;
- int index;
- int i;
+ methodinfo* m;
+ int count;
+ int index;
+ int i;
/* Determine number of constructors. */
/* Create array of constructors. */
- oa = builtin_anewarray(count, class_java_lang_reflect_Constructor);
+ ObjectArray oa(count, class_java_lang_reflect_Constructor);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
/* Get the constructors and store them in the array. */
/* Store object into array. */
- array_objectarray_element_set(oa, index, rc.get_handle());
+ oa.set_element(index, rc.get_handle());
index++;
}
}
- return oa;
+ return oa.get_handle();
}
#endif
#if defined(ENABLE_JAVASE)
java_handle_objectarray_t *class_get_declaredfields(classinfo *c, bool publicOnly)
{
- java_handle_objectarray_t *oa;
- fieldinfo *f;
- int count;
- int index;
- int i;
+ fieldinfo* f;
+ int count;
+ int index;
+ int i;
/* Determine number of fields. */
/* Create array of fields. */
- oa = builtin_anewarray(count, class_java_lang_reflect_Field);
+ ObjectArray oa(count, class_java_lang_reflect_Field);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
/* Get the fields and store them in the array. */
/* Store object into array. */
- array_objectarray_element_set(oa, index, rf.get_handle());
+ oa.set_element(index, rf.get_handle());
index++;
}
}
- return oa;
+ return oa.get_handle();
}
#endif
#if defined(ENABLE_JAVASE)
java_handle_objectarray_t *class_get_declaredmethods(classinfo *c, bool publicOnly)
{
- java_handle_objectarray_t *oa; /* result: array of Method-objects */
- methodinfo *m; /* the current method to be represented */
- int count;
- int index;
- int i;
+ methodinfo* m; /* the current method to be represented */
+ int count;
+ int index;
+ int i;
/* JOWENN: array classes do not declare methods according to mauve
test. It should be considered, if we should return to my old
clone method overriding instead of declaring it as a member
function. */
- if (class_is_array(c))
- return builtin_anewarray(0, class_java_lang_reflect_Method);
+ if (class_is_array(c)) {
+ ObjectArray oa(0, class_java_lang_reflect_Method);
+ return oa.get_handle();
+ }
/* Determine number of methods. */
/* Create array of methods. */
- oa = builtin_anewarray(count, class_java_lang_reflect_Method);
+ ObjectArray oa(count, class_java_lang_reflect_Method);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
/* Get the methods and store them in the array. */
/* Store object into array. */
- array_objectarray_element_set(oa, index, rm.get_handle());
+ oa.set_element(index, rm.get_handle());
index++;
}
}
- return oa;
+ return oa.get_handle();
}
#endif
*******************************************************************************/
-java_handle_objectarray_t *class_get_interfaces(classinfo *c)
+java_handle_objectarray_t* class_get_interfaces(classinfo *c)
{
- classinfo *ic;
- java_handle_objectarray_t *oa;
- u4 i;
+ classinfo* ic;
+ u4 i;
if (!(c->state & CLASS_LINKED))
if (!link_class(c))
return NULL;
- oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
+ ClassArray interfaces(c->interfacescount);
- if (oa == NULL)
+ if (interfaces.is_null())
return NULL;
for (i = 0; i < c->interfacescount; i++) {
ic = c->interfaces[i];
- LLNI_array_direct(oa, i) = (java_object_t *) ic;
+ interfaces.set_element(i, ic);
}
- return oa;
+ return interfaces.get_handle();
}
LLNI_classinfo_field_get(c, annotations, annotations);
- return (java_handle_bytearray_t*)annotations;
+ return (java_handle_bytearray_t*) annotations;
#else
return NULL;
#endif
#if defined(ENABLE_ANNOTATIONS)
classinfo *c; /* declaring class */
int slot; /* slot of this field */
- java_handle_bytearray_t *annotations; /* unparsed annotations */
java_handle_t *field_annotations; /* array of unparsed */
/* annotations of all fields of the declaring class */
- c = f->clazz;
- slot = f - c->fields;
- annotations = NULL;
+ c = f->clazz;
+ slot = f - c->fields;
LLNI_classinfo_field_get(c, field_annotations, field_annotations);
+ ObjectArray oa(field_annotations);
+
/* the field_annotations array might be shorter then the field
* count if the fields above a certain index have no annotations.
*/
- if (field_annotations != NULL &&
- array_length_get(field_annotations) > slot) {
- annotations = (java_handle_bytearray_t*)array_objectarray_element_get(
- (java_handle_objectarray_t*)field_annotations, slot);
+ if (field_annotations != NULL && oa.get_length() > slot) {
+ return (java_handle_bytearray_t*) oa.get_element(slot);
+ } else {
+ return NULL;
}
-
- return annotations;
#else
return NULL;
#endif
*******************************************************************************/
-#if defined(ENABLE_HANDLES)
-typedef struct java_handle_t {
- java_object_t *heap_object;
-} java_handle_t;
-
-typedef struct java_handle_array_t { java_array_t *heap_object; } java_handle_array_t;
-typedef struct java_handle_objectarray_t { java_objectarray_t *heap_object; } java_handle_objectarray_t;
-typedef struct java_handle_booleanarray_t { java_booleanarray_t *heap_object; } java_handle_booleanarray_t;
-typedef struct java_handle_bytearray_t { java_bytearray_t *heap_object; } java_handle_bytearray_t;
-typedef struct java_handle_chararray_t { java_chararray_t *heap_object; } java_handle_chararray_t;
-typedef struct java_handle_shortarray_t { java_shortarray_t *heap_object; } java_handle_shortarray_t;
-typedef struct java_handle_intarray_t { java_intarray_t *heap_object; } java_handle_intarray_t;
-typedef struct java_handle_longarray_t { java_longarray_t *heap_object; } java_handle_longarray_t;
-typedef struct java_handle_floatarray_t { java_floatarray_t *heap_object; } java_handle_floatarray_t;
-typedef struct java_handle_doublearray_t { java_doublearray_t *heap_object; } java_handle_doublearray_t;
-#else
typedef java_object_t java_handle_t;
-typedef java_array_t java_handle_array_t;
-typedef java_objectarray_t java_handle_objectarray_t;
-typedef java_booleanarray_t java_handle_booleanarray_t;
-typedef java_bytearray_t java_handle_bytearray_t;
-typedef java_chararray_t java_handle_chararray_t;
-typedef java_shortarray_t java_handle_shortarray_t;
-typedef java_intarray_t java_handle_intarray_t;
-typedef java_longarray_t java_handle_longarray_t;
-typedef java_floatarray_t java_handle_floatarray_t;
-typedef java_doublearray_t java_handle_doublearray_t;
-#endif
+typedef java_handle_t java_handle_array_t;
+typedef java_handle_array_t java_handle_objectarray_t;
+typedef java_handle_array_t java_handle_booleanarray_t;
+typedef java_handle_array_t java_handle_bytearray_t;
+typedef java_handle_array_t java_handle_chararray_t;
+typedef java_handle_array_t java_handle_shortarray_t;
+typedef java_handle_array_t java_handle_intarray_t;
+typedef java_handle_array_t java_handle_longarray_t;
+typedef java_handle_array_t java_handle_floatarray_t;
+typedef java_handle_array_t java_handle_doublearray_t;
/* global constants related to the verifier ***********************************/
i++;
}
+ ObjectArray oa(params);
+
for (j = 0; i < md->paramcount; i++, j++, pd++, td++) {
/* XXX This function can throw an exception, which should not happend
here, since we are outside the nativeworld. */
- param = array_objectarray_element_get(params, j);
+ param = oa.get_element(j);
switch (td->type) {
case TYPE_INT:
LLNI_CRITICAL_START;
- result = builtin_fast_canstore(LLNI_DIRECT(oa), LLNI_UNWRAP(o));
+ result = builtin_fast_canstore((java_objectarray_t*) LLNI_DIRECT(oa), LLNI_UNWRAP(o));
LLNI_CRITICAL_END;
}
-/* builtin_newarray ************************************************************
+/* builtin_java_newarray *******************************************************
Creates an array with the given vftbl on the heap. This function
takes as class argument an array class.
RETURN VALUE:
pointer to the array or NULL if no memory is available
- NOTE: This builtin can be called from NATIVE code only.
+ NOTE: This is a SLOW builtin and can be called from JIT code only.
*******************************************************************************/
-java_handle_t *builtin_newarray(int32_t size, classinfo *arrayclass)
+java_handle_array_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclazz)
{
- arraydescriptor *desc;
- s4 dataoffset;
- s4 componentsize;
- s4 actualsize;
- java_handle_t *a;
#if defined(ENABLE_RT_TIMING)
struct timespec time_start, time_end;
#endif
RT_TIMING_GET_TIME(time_start);
- desc = arrayclass->vftbl->arraydesc;
- dataoffset = desc->dataoffset;
- componentsize = desc->componentsize;
-
- if (size < 0) {
- exceptions_throw_negativearraysizeexception();
- return NULL;
- }
-
- actualsize = dataoffset + size * componentsize;
+ classinfo* arrayclass = LLNI_classinfo_unwrap(arrayclazz);
- /* check for overflow */
-
- if (((u4) actualsize) < ((u4) size)) {
- exceptions_throw_outofmemoryerror();
- return NULL;
- }
-
- a = (java_handle_t*) heap_alloc(actualsize, (desc->arraytype == ARRAYTYPE_OBJECT), NULL, true);
-
- if (a == NULL)
- return NULL;
-
-#if !defined(ENABLE_GC_CACAO) && defined(ENABLE_HANDLES)
- /* XXX this is only a dirty hack to make Boehm work with handles */
-
- a = LLNI_WRAP((java_object_t *) a);
-#endif
-
- LLNI_vftbl_direct(a) = arrayclass->vftbl;
-
-#if defined(ENABLE_THREADS)
- LLNI_DIRECT(a)->lockword.init();
-#endif
-
- LLNI_array_size(a) = size;
+ // Allocate a new array with given size and class on the heap
+ Array a(size, arrayclass);
RT_TIMING_GET_TIME(time_end);
RT_TIMING_TIME_DIFF(time_start, time_end, RT_TIMING_NEW_ARRAY);
- return a;
-}
-
-
-/* builtin_java_newarray *******************************************************
-
- NOTE: This is a SLOW builtin and can be called from JIT code only.
-
-*******************************************************************************/
-
-java_handle_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclazz)
-{
- return builtin_newarray(size, LLNI_classinfo_unwrap(arrayclazz));
-}
-
-
-/* builtin_anewarray ***********************************************************
-
- Creates an array of references to the given class type on the heap.
-
- RETURN VALUE:
- pointer to the array or NULL if no memory is
- available
-
- NOTE: This builtin can be called from NATIVE code only.
-
-*******************************************************************************/
-
-java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass)
-{
- classinfo *arrayclass;
-
- /* is class loaded */
-
- assert(componentclass->state & CLASS_LOADED);
-
- /* is class linked */
-
- if (!(componentclass->state & CLASS_LINKED))
- if (!link_class(componentclass))
- return NULL;
-
- arrayclass = class_array_of(componentclass, true);
-
- if (!arrayclass)
- return NULL;
-
- return (java_handle_objectarray_t *) builtin_newarray(size, arrayclass);
+ return a.get_handle();
}
*******************************************************************************/
-#define BUILTIN_NEWARRAY_TYPE(type, arraytype) \
-java_handle_##type##array_t *builtin_newarray_##type(int32_t size) \
-{ \
- return (java_handle_##type##array_t *) \
- builtin_newarray(size, primitivetype_table[arraytype].arrayclass); \
+#define BUILTIN_NEWARRAY_TYPE(type, name) \
+java_handle_##type##array_t *builtin_newarray_##type(int32_t size) \
+{ \
+ name##Array a(size); \
+ return a.get_handle(); \
}
-BUILTIN_NEWARRAY_TYPE(boolean, ARRAYTYPE_BOOLEAN)
-BUILTIN_NEWARRAY_TYPE(byte, ARRAYTYPE_BYTE)
-BUILTIN_NEWARRAY_TYPE(char, ARRAYTYPE_CHAR)
-BUILTIN_NEWARRAY_TYPE(short, ARRAYTYPE_SHORT)
-BUILTIN_NEWARRAY_TYPE(int, ARRAYTYPE_INT)
-BUILTIN_NEWARRAY_TYPE(long, ARRAYTYPE_LONG)
-BUILTIN_NEWARRAY_TYPE(float, ARRAYTYPE_FLOAT)
-BUILTIN_NEWARRAY_TYPE(double, ARRAYTYPE_DOUBLE)
+BUILTIN_NEWARRAY_TYPE(boolean, Boolean)
+BUILTIN_NEWARRAY_TYPE(byte, Byte)
+BUILTIN_NEWARRAY_TYPE(char, Char)
+BUILTIN_NEWARRAY_TYPE(short, Short)
+BUILTIN_NEWARRAY_TYPE(int, Int)
+BUILTIN_NEWARRAY_TYPE(long, Long)
+BUILTIN_NEWARRAY_TYPE(float, Float)
+BUILTIN_NEWARRAY_TYPE(double, Double)
/* builtin_multianewarray_intern ***********************************************
******************************************************************************/
-static java_handle_t *builtin_multianewarray_intern(int n,
+static java_handle_array_t *builtin_multianewarray_intern(int n,
classinfo *arrayclass,
long *dims)
{
- s4 size;
- java_handle_t *a;
- classinfo *componentclass;
- s4 i;
+ int32_t i;
/* create this dimension */
- size = (s4) dims[0];
- a = builtin_newarray(size, arrayclass);
+ int32_t size = (int32_t) dims[0];
+ Array a(size, arrayclass);
- if (!a)
+ if (a.is_null())
return NULL;
/* if this is the last dimension return */
if (!--n)
- return a;
+ return a.get_handle();
/* get the class of the components to create */
- componentclass = arrayclass->vftbl->arraydesc->componentvftbl->clazz;
+ classinfo* componentclass = arrayclass->vftbl->arraydesc->componentvftbl->clazz;
/* The verifier guarantees that the dimension count is in the range. */
/* create the component arrays */
+ ObjectArray oa(a.get_handle());
+
for (i = 0; i < size; i++) {
- java_handle_t *ea =
+ java_handle_array_t *ea =
#if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
/* we save an s4 to a s8 slot, 8-byte aligned */
if (!ea)
return NULL;
- array_objectarray_element_set((java_handle_objectarray_t *) a, i, ea);
+ oa.set_element(i, (java_handle_t*) ea);
}
- return a;
+ return a.get_handle();
}
return;
}
+ Array sa(src);
+ Array da(dest);
+
sdesc = LLNI_vftbl_direct(src)->arraydesc;
ddesc = LLNI_vftbl_direct(dest)->arraydesc;
}
// Check if ranges are valid.
- if ((((uint32_t) srcStart + (uint32_t) len) > (uint32_t) LLNI_array_size(src)) ||
- (((uint32_t) destStart + (uint32_t) len) > (uint32_t) LLNI_array_size(dest))) {
+ if ((((uint32_t) srcStart + (uint32_t) len) > (uint32_t) sa.get_length()) ||
+ (((uint32_t) destStart + (uint32_t) len) > (uint32_t) da.get_length())) {
exceptions_throw_arrayindexoutofboundsexception();
return;
}
else {
/* We copy references of different type */
- java_handle_objectarray_t *oas = (java_handle_objectarray_t *) src;
- java_handle_objectarray_t *oad = (java_handle_objectarray_t *) dest;
+ ObjectArray oas((java_handle_objectarray_t*) src);
+ ObjectArray oad((java_handle_objectarray_t*) dest);
if (destStart <= srcStart) {
for (i = 0; i < len; i++) {
- java_handle_t *o;
+ java_handle_t* o = oas.get_element(srcStart + i);
- o = array_objectarray_element_get(oas, srcStart + i);
-
- if (!builtin_canstore(oad, o))
+ if (!builtin_canstore(oad.get_handle(), o))
return;
- array_objectarray_element_set(oad, destStart + i, o);
+ oad.set_element(destStart + i, o);
}
}
else {
index have been copied before the throw. */
for (i = len - 1; i >= 0; i--) {
- java_handle_t *o;
-
- o = array_objectarray_element_get(oas, srcStart + i);
+ java_handle_t* o = oas.get_element(srcStart + i);
- if (!builtin_canstore(oad, o))
+ if (!builtin_canstore(oad.get_handle(), o))
return;
- array_objectarray_element_set(oad, destStart + i, o);
+ oad.set_element(destStart + i, o);
}
}
}
/* we are cloning an array */
if (ad != NULL) {
- size = ad->dataoffset + ad->componentsize * LLNI_array_size(o);
+ Array a(o);
+
+ size = ad->dataoffset + ad->componentsize * a.get_length();
co = (java_handle_t*) heap_alloc(size, (ad->arraytype == ARRAYTYPE_OBJECT), NULL, true);
java_object_t *builtin_fast_new(classinfo *c);
#define BUILTIN_FAST_new (functionptr) builtin_fast_new
-java_handle_t *builtin_newarray(int32_t size, classinfo *arrayclass);
-/* NOT AN OP */
-java_handle_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclass);
+java_handle_array_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclass);
#define BUILTIN_newarray (functionptr) builtin_java_newarray
-java_handle_objectarray_t *builtin_anewarray(int32_t size, classinfo *componentclass);
-/* NOT AN OP */
-
java_handle_booleanarray_t *builtin_newarray_boolean(int32_t size);
#define BUILTIN_newarray_boolean (functionptr) builtin_newarray_boolean
java_handle_chararray_t *builtin_newarray_char(int32_t size);
java_handle_bytearray_t *stacktrace_get(stackframeinfo_t *sfi)
{
- stackframeinfo_t tmpsfi;
- int depth;
- java_handle_bytearray_t *ba;
- int32_t ba_size;
- stacktrace_t *st;
- stacktrace_entry_t *ste;
- methodinfo *m;
- bool skip_fillInStackTrace;
- bool skip_init;
+ stackframeinfo_t tmpsfi;
+ int depth;
+ int32_t ba_size;
+ stacktrace_t *st;
+ stacktrace_entry_t *ste;
+ methodinfo *m;
+ bool skip_fillInStackTrace;
+ bool skip_init;
CYCLES_STATS_DECLARE_AND_START_WITH_OVERHEAD
ba_size = sizeof(stacktrace_t) + sizeof(stacktrace_entry_t) * depth;
- ba = builtin_newarray_byte(ba_size);
+ ByteArray ba(ba_size);
- if (ba == NULL)
+ if (ba.is_null())
goto return_NULL;
/* Get a stacktrace entry pointer. */
LLNI_CRITICAL_START;
- st = (stacktrace_t *) LLNI_array_data(ba);
+ st = (stacktrace_t *) ba.get_raw_data_ptr();
ste = st->entries;
CYCLES_STATS_END_WITH_OVERHEAD(stacktrace_fillInStackTrace,
stacktrace_overhead)
- return ba;
+ return ba.get_handle();
return_NULL:
/* dump_release(dumpsize); */
int32_t length = (st != NULL) ? st->length : 0;
// Create the stacktrace element array.
- java_handle_objectarray_t* oa = builtin_anewarray(length, class_java_lang_StackTraceElement);
+ ObjectArray oa(length, class_java_lang_StackTraceElement);
- if (oa == NULL)
+ if (oa.is_null())
return NULL;
// Iterate over all stacktrace elements.
return NULL;
// Store stacktrace element in array.
- array_objectarray_element_set(oa, i, h);
+ oa.set_element(i, h);
}
- return oa;
+ return oa.get_handle();
}
#endif
stackframeinfo_t *sfi;
stackframeinfo_t tmpsfi;
int depth;
- java_handle_objectarray_t *oa;
- java_object_t **data;
int i;
methodinfo *m;
/* Allocate the Class array. */
- oa = builtin_anewarray(depth, class_java_lang_Class);
+ ClassArray ca(depth);
- if (oa == NULL) {
+ if (ca.is_null()) {
CYCLES_STATS_END(stacktrace_getClassContext);
return NULL;
}
/* Fill the Class array from the stacktrace list. */
-
- LLNI_CRITICAL_START;
-
- data = LLNI_array_data(oa);
-
/* Iterate over the whole stack. */
i = 0;
/* Store the class in the array. */
- data[i] = (java_object_t *) m->clazz;
+ ca.set_element(i, m->clazz);
i++;
}
CYCLES_STATS_END(stacktrace_getClassContext)
- return oa;
+ return ca.get_handle();
}
#if defined(ENABLE_JAVASE) && defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
java_handle_objectarray_t *stacktrace_get_stack(void)
{
- stackframeinfo_t *sfi;
- stackframeinfo_t tmpsfi;
- int depth;
- java_handle_objectarray_t *oa;
- java_handle_objectarray_t *classes;
- java_handle_objectarray_t *methodnames;
- methodinfo *m;
- java_handle_t *string;
- int i;
+ stackframeinfo_t *sfi;
+ stackframeinfo_t tmpsfi;
+ int depth;
+ methodinfo *m;
+ java_handle_t *string;
+ int i;
CYCLES_STATS_DECLARE_AND_START
/* Allocate the required arrays. */
- oa = builtin_anewarray(2, arrayclass_java_lang_Object);
+ ObjectArray oa(2, arrayclass_java_lang_Object);
+ ClassArray classes(depth);
+ ObjectArray methodnames(depth, class_java_lang_String);
- if (oa == NULL)
+ if (oa.is_null())
goto return_NULL;
- classes = builtin_anewarray(depth, class_java_lang_Class);
-
- if (classes == NULL)
+ if (classes.is_null())
goto return_NULL;
- methodnames = builtin_anewarray(depth, class_java_lang_String);
-
- if (methodnames == NULL)
+ if (methodnames.is_null())
goto return_NULL;
/* Set up the 2-dimensional array. */
- array_objectarray_element_set(oa, 0, (java_handle_t *) classes);
- array_objectarray_element_set(oa, 1, (java_handle_t *) methodnames);
+ oa.set_element(0, (java_handle_t *) classes.get_handle());
+ oa.set_element(1, (java_handle_t *) methodnames.get_handle());
/* Iterate over the whole stack. */
/* TODO We should use a critical section here to speed things
continue;
/* Store the class in the array. */
- /* NOTE: We use a LLNI-macro here, because a classinfo is not
- a handle. */
- LLNI_array_direct(classes, i) = (java_object_t *) m->clazz;
+ classes.set_element(i, m->clazz);
/* Store the name in the array. */
if (string == NULL)
goto return_NULL;
- array_objectarray_element_set(methodnames, i, string);
+ methodnames.set_element(i, string);
i++;
}
CYCLES_STATS_END(stacktrace_get_stack)
- return oa;
+ return oa.get_handle();
return_NULL:
CYCLES_STATS_END(stacktrace_get_stack)
stacktrace_t* stacktrace_get_of_thread(threadobject* t)
{
stackframeinfo_t* sfi;
- java_handle_bytearray_t* ba;
+ java_handle_bytearray_t* stba;
stacktrace_t* st;
- sfi = t->_stackframeinfo;
- ba = stacktrace_get(sfi);
+ sfi = t->_stackframeinfo;
+ stba = stacktrace_get(sfi);
+
+ ByteArray ba(stba);
- if (ba == NULL)
+ if (ba.is_null())
return NULL;
- st = (stacktrace_t*) LLNI_array_data(ba);
+ st = (stacktrace_t*) ba.get_raw_data_ptr();
return st;
}
#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
java_lang_VMThrowable vmt(t.get_vmState());
- java_handle_bytearray_t* backtrace = vmt.get_vmdata();
+ ByteArray backtrace(vmt.get_vmdata());
#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK) || defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
- java_handle_bytearray_t* backtrace = t.get_backtrace();
+ ByteArray backtrace(t.get_backtrace());
#else
# error unknown classpath configuration
// Sanity check.
- assert(backtrace != NULL);
+ assert(backtrace.is_non_null());
/* We need a critical section here as we use the byte-array data
pointer directly. */
LLNI_CRITICAL_START;
- stacktrace_t* st = (stacktrace_t*) LLNI_array_data(backtrace);
+ stacktrace_t* st = (stacktrace_t*) backtrace.get_raw_data_ptr();
stacktrace_print(st);
#include "toolbox/logging.hpp"
+#include "vm/array.hpp"
#include "vm/global.h"
#include "vm/globals.hpp"
#include "vm/javaobjects.hpp"
logtextlen += utf_bytes(jlt.get_vftbl()->clazz->name);
if (jls.get_handle()) {
+ CharArray ca(jls.get_value());
// FIXME This is not handle capable!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
logtextlen += strlen(": ") +
- u2_utflength(jls.get_value()->data + jls.get_offset(), jls.get_count());
+ u2_utflength(ptr + jls.get_offset(), jls.get_count());
}
}
else {
java_handle_objectarray_t *method_get_parametertypearray(methodinfo *m)
{
- methoddesc *md;
- typedesc *paramtypes;
- int32_t paramcount;
- java_handle_objectarray_t *oa;
- int32_t i;
- classinfo *c;
+ methoddesc* md;
+ typedesc* paramtypes;
+ int32_t paramcount;
+ int32_t i;
+ classinfo* c;
md = m->parseddesc;
/* create class-array */
- oa = builtin_anewarray(paramcount, class_java_lang_Class);
+ ClassArray ca(paramcount);
- if (oa == NULL)
+ if (ca.is_null())
return NULL;
/* get classes */
if (!resolve_class_from_typedesc(¶mtypes[i], true, false, &c))
return NULL;
- LLNI_array_direct(oa, i) = (java_object_t *) c;
+ ca.set_element(i, c);
}
- return oa;
+ return ca.get_handle();
}
java_handle_objectarray_t *method_get_exceptionarray(methodinfo *m)
{
- java_handle_objectarray_t *oa;
- classinfo *c;
- s4 i;
+ classinfo* c;
+ s4 i;
/* create class-array */
- oa = builtin_anewarray(m->thrownexceptionscount, class_java_lang_Class);
+ ClassArray ca(m->thrownexceptionscount);
- if (oa == NULL)
+ if (ca.is_null())
return NULL;
/* iterate over all exceptions and store the class in the array */
if (c == NULL)
return NULL;
- LLNI_array_direct(oa, i) = (java_object_t *) c;
+ ca.set_element(i, c);
}
- return oa;
+ return ca.get_handle();
}
#if defined(ENABLE_ANNOTATIONS)
classinfo *c; /* methods' declaring class */
int slot; /* methods' slot */
- java_handle_t *annotations; /* methods' unparsed annotations */
java_handle_t *method_annotations; /* all methods' unparsed annotations */
/* of the declaring class */
- c = m->clazz;
- slot = m - c->methods;
- annotations = NULL;
+ c = m->clazz;
+ slot = m - c->methods;
LLNI_classinfo_field_get(c, method_annotations, method_annotations);
+ ObjectArray oa((java_handle_objectarray_t*) method_annotations);
+
/* the method_annotations array might be shorter then the method
* count if the methods above a certain index have no annotations.
*/
- if (method_annotations != NULL &&
- array_length_get(method_annotations) > slot) {
- annotations = array_objectarray_element_get(
- (java_handle_objectarray_t*)method_annotations, slot);
+ if (method_annotations != NULL && oa.get_length() > slot) {
+ return (java_handle_bytearray_t*) oa.get_element(slot);
+ } else {
+ return NULL;
}
-
- return (java_handle_bytearray_t*)annotations;
#else
return NULL;
#endif
#if defined(ENABLE_ANNOTATIONS)
classinfo *c; /* methods' declaring class */
int slot; /* methods' slot */
- java_handle_t *parameterAnnotations; /* methods' unparsed */
- /* parameter annotations */
java_handle_t *method_parameterannotations; /* all methods' unparsed */
/* parameter annotations of */
/* the declaring class */
- c = m->clazz;
- slot = m - c->methods;
- parameterAnnotations = NULL;
+ c = m->clazz;
+ slot = m - c->methods;
LLNI_classinfo_field_get(
c, method_parameterannotations, method_parameterannotations);
+ ObjectArray oa((java_handle_objectarray_t*) method_parameterannotations);
+
/* the method_annotations array might be shorter then the method
* count if the methods above a certain index have no annotations.
*/
- if (method_parameterannotations != NULL &&
- array_length_get(method_parameterannotations) > slot) {
- parameterAnnotations = array_objectarray_element_get(
- (java_handle_objectarray_t*)method_parameterannotations,
- slot);
+ if (method_parameterannotations != NULL && oa.get_length() > slot) {
+ return (java_handle_bytearray_t*) oa.get_element(slot);
+ } else {
+ return NULL;
}
-
- return (java_handle_bytearray_t*)parameterAnnotations;
#else
return NULL;
#endif
#if defined(ENABLE_ANNOTATIONS)
classinfo *c; /* methods' declaring class */
int slot; /* methods' slot */
- java_handle_t *annotationDefault; /* methods' unparsed */
- /* annotation default value */
java_handle_t *method_annotationdefaults; /* all methods' unparsed */
/* annotation default values of */
/* the declaring class */
- c = m->clazz;
- slot = m - c->methods;
- annotationDefault = NULL;
+ c = m->clazz;
+ slot = m - c->methods;
LLNI_classinfo_field_get(
c, method_annotationdefaults, method_annotationdefaults);
+ ObjectArray oa((java_handle_objectarray_t*) method_annotationdefaults);
+
/* the method_annotations array might be shorter then the method
* count if the methods above a certain index have no annotations.
- */
- if (method_annotationdefaults != NULL &&
- array_length_get(method_annotationdefaults) > slot) {
- annotationDefault = array_objectarray_element_get(
- (java_handle_objectarray_t*)method_annotationdefaults, slot);
+ */
+ if (method_annotationdefaults != NULL && oa.get_length() > slot) {
+ return (java_handle_bytearray_t*) oa.get_element(slot);
+ } else {
+ return NULL;
}
-
- return (java_handle_bytearray_t*)annotationDefault;
#else
return NULL;
#endif
void stringtable_update(void)
{
- java_chararray_t *a;
literalstring *s; /* hashtable entry */
for (unsigned int i = 0; i < hashtable_string.size; i++) {
os::abort("stringtable_update: invalid literalstring in hashtable");
}
- a = LLNI_UNWRAP(js.get_value());
+ java_chararray_t* a = (java_chararray_t*) js.get_value();
if (js.get_vftbl() == NULL)
// FIXME
int32_t utflength = utf_get_number_of_u2s_for_buffer(buffer, blength);
java_handle_t* h = builtin_new(class_java_lang_String);
- java_handle_chararray_t* ca = builtin_newarray_char(utflength);
+ CharArray ca(utflength);
/* javastring or character-array could not be created */
- if ((h == NULL) || (ca == NULL))
+ if ((h == NULL) || ca.is_null())
return NULL;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
/* decompress utf-string */
utf_ptr = buffer;
for (int32_t i = 0; i < utflength; i++)
- LLNI_array_direct(ca, i) = utf_nextu2((char **) &utf_ptr);
+ ptr[i] = utf_nextu2((char **) &utf_ptr);
/* set fields of the javastring-object */
- java_lang_String jls(h, ca, utflength);
+ java_lang_String jls(h, ca.get_handle(), utflength);
return jls.get_handle();
}
/* allocate the String object and the char array */
java_handle_t* h = builtin_new(class_java_lang_String);
- java_handle_chararray_t* ca = builtin_newarray_char(len);
+ CharArray ca(len);
/* javastring or character-array could not be created? */
- if ((h == NULL) || (ca == NULL))
+ if ((h == NULL) || ca.is_null())
return NULL;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
/* decompress UTF-8 string */
- utf8_safe_convert_to_u2s(text, nbytes, LLNI_array_data(ca));
+ utf8_safe_convert_to_u2s(text, nbytes, ptr);
/* set fields of the String object */
- java_lang_String jls(h, ca, len);
+ java_lang_String jls(h, ca.get_handle(), len);
return jls.get_handle();
}
int32_t utflength = utf_get_number_of_u2s(u);
java_handle_t* h = builtin_new(class_java_lang_String);
- java_handle_chararray_t* ca = builtin_newarray_char(utflength);
+ CharArray ca(utflength);
/* javastring or character-array could not be created */
- if ((h == NULL) || (ca == NULL))
+ if ((h == NULL) || ca.is_null())
return NULL;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
/* decompress utf-string */
for (int32_t i = 0; i < utflength; i++)
- LLNI_array_direct(ca, i) = utf_nextu2(&utf_ptr);
+ ptr[i] = utf_nextu2(&utf_ptr);
/* set fields of the javastring-object */
- java_lang_String jls(h, ca, utflength);
+ java_lang_String jls(h, ca.get_handle(), utflength);
return jls.get_handle();
}
int32_t utflength = utf_get_number_of_u2s(u);
java_handle_t* h = builtin_new(class_java_lang_String);
- java_handle_chararray_t* ca = builtin_newarray_char(utflength);
+ CharArray ca(utflength);
/* javastring or character-array could not be created */
- if ((h == NULL) || (ca == NULL))
+ if ((h == NULL) || ca.is_null())
return NULL;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
/* decompress utf-string */
for (int32_t i = 0; i < utflength; i++) {
if (ch == '/')
ch = '.';
- LLNI_array_direct(ca, i) = ch;
+ ptr[i] = ch;
}
/* set fields of the javastring-object */
- java_lang_String jls(h, ca, utflength);
+ java_lang_String jls(h, ca.get_handle(), utflength);
return jls.get_handle();
}
int32_t len = strlen(text);
java_handle_t* h = builtin_new(class_java_lang_String);
- java_handle_chararray_t* ca = builtin_newarray_char(len);
+ CharArray ca(len);
/* javastring or character-array could not be created */
- if ((h == NULL) || (ca == NULL))
+ if ((h == NULL) || ca.is_null())
return NULL;
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
/* copy text */
for (int32_t i = 0; i < len; i++)
- LLNI_array_direct(ca, i) = text[i];
+ ptr[i] = text[i];
/* set fields of the javastring-object */
- java_lang_String jls(h, ca, len);
+ java_lang_String jls(h, ca.get_handle(), len);
return jls.get_handle();
}
if (jls.is_null())
return (char*) "";
- java_handle_chararray_t* ca = jls.get_value();
+ CharArray ca(jls.get_value());
- if (ca == NULL)
+ if (ca.is_null())
return (char*) "";
int32_t count = jls.get_count();
char* buf = MNEW(char, count + 1);
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
int32_t i;
for (i = 0; i < count; i++)
- buf[i] = LLNI_array_direct(ca, offset + i);
+ buf[i] = ptr[offset + i];
buf[i] = '\0';
if (jls.is_null())
return utf_null;
- java_handle_chararray_t* value = jls.get_value();
+ CharArray ca(jls.get_value());
- if (jls.get_value() == NULL)
+ if (ca.is_null())
return utf_null;
int32_t count = jls.get_count();
int32_t offset = jls.get_offset();
- return utf_new_u2(LLNI_array_data(value) + offset, count, isclassname);
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
+ return utf_new_u2(ptr + offset, count, isclassname);
}
*******************************************************************************/
-static java_object_t *literalstring_u2(java_chararray_t *a, int32_t length,
+static java_handle_t *literalstring_u2(java_handle_chararray_t *a, int32_t length,
u4 offset, bool copymode)
{
- literalstring *s; /* hashtable element */
- java_chararray_t *ca; /* copy of u2-array */
- u4 key;
- u4 slot;
- u2 i;
+ literalstring *s; /* hashtable element */
+ u4 key;
+ u4 slot;
+ u2 i;
mutex->lock();
- /* find location in hashtable */
+ // XXX: Fix me!
+ CharArray ca(a);
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
+ /* find location in hashtable */
- key = unicode_hashkey(a->data + offset, length);
- slot = key & (hashtable_string.size - 1);
- s = (literalstring*) hashtable_string.ptr[slot];
+ key = unicode_hashkey(ptr + offset, length);
+ slot = key & (hashtable_string.size - 1);
+ s = (literalstring*) hashtable_string.ptr[slot];
- while (s) {
+ while (s) {
// FIXME
java_lang_String js(LLNI_WRAP(s->string));
if (length == js.get_count()) {
/* compare text */
- for (i = 0; i < length; i++)
+ for (i = 0; i < length; i++) {
// FIXME This is not handle capable!
+ CharArray jsca(js.get_value());
+ uint16_t* sptr = (uint16_t*) jsca.get_raw_data_ptr();
- if (a->data[offset + i] != ((java_chararray_t*) LLNI_UNWRAP(js.get_value()))->data[i])
+ if (ptr[offset + i] != sptr[i])
goto nomatch;
+ }
/* string already in hashtable, free memory */
mutex->unlock();
- return (java_object_t*) LLNI_UNWRAP(js.get_handle());
+ return js.get_handle();
}
nomatch:
/* follow link in external hash chain */
s = s->hashlink;
- }
+ }
- if (copymode) {
+ java_chararray_t* acopy;
+ if (copymode) {
/* create copy of u2-array for new javastring */
u4 arraysize = sizeof(java_chararray_t) + sizeof(u2) * (length - 1) + 10;
- ca = (java_chararray_t*) mem_alloc(arraysize);
+ acopy = (java_chararray_t*) mem_alloc(arraysize);
/* memcpy(ca, a, arraysize); */
- memcpy(&(ca->header), &(a->header), sizeof(java_array_t));
- memcpy(&(ca->data), &(a->data) + offset, sizeof(u2) * (length - 1) + 10);
- }
+ memcpy(&(acopy->header), &(((java_chararray_t*) a)->header), sizeof(java_array_t));
+ memcpy(&(acopy->data), &(((java_chararray_t*) a)->data) + offset, sizeof(u2) * (length - 1) + 10);
+ }
else {
- ca = a;
+ acopy = (java_chararray_t*) a;
}
- /* location in hashtable found, complete arrayheader */
+ /* location in hashtable found, complete arrayheader */
- ca->header.objheader.vftbl = Primitive::get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl;
- ca->header.size = length;
+ acopy->header.objheader.vftbl = Primitive::get_arrayclass_by_type(ARRAYTYPE_CHAR)->vftbl;
+ acopy->header.size = length;
assert(class_java_lang_String);
assert(class_java_lang_String->state & CLASS_LOADED);
// Create a new java.lang.String object on the system heap.
java_object_t* o = (java_object_t*) MNEW(uint8_t, class_java_lang_String->instancesize);
- // FIXME
- java_handle_t* h = LLNI_WRAP(o);
#if defined(ENABLE_STATISTICS)
if (opt_stat)
o->vftbl = class_java_lang_String->vftbl;
- // FIXME
- java_lang_String jls(h, LLNI_WRAP(ca), length);
+ CharArray cacopy((java_handle_chararray_t*) acopy);
+ java_lang_String jls(o, cacopy.get_handle(), length);
/* create new literalstring */
java_object_t *literalstring_new(utf *u)
{
- char *utf_ptr; /* pointer to current unicode character */
+ char *utf_ptr; /* pointer to current unicode character */
/* utf string */
- u4 utflength; /* length of utf-string if uncompressed */
- java_chararray_t *a; /* u2-array constructed from utf string */
- u4 i;
+ u4 utflength; /* length of utf-string if uncompressed */
+ java_chararray_t *a; /* u2-array constructed from utf string */
+ u4 i;
utf_ptr = u->text;
utflength = utf_get_number_of_u2s(u);
- /* allocate memory */
- a = (java_chararray_t*) mem_alloc(sizeof(java_chararray_t) + sizeof(u2) * (utflength - 1) + 10);
+ /* allocate memory */
+ a = (java_chararray_t*) mem_alloc(sizeof(java_chararray_t) + sizeof(u2) * (utflength - 1) + 10);
- /* convert utf-string to u2-array */
- for (i = 0; i < utflength; i++)
+ /* convert utf-string to u2-array */
+ for (i = 0; i < utflength; i++)
a->data[i] = utf_nextu2(&utf_ptr);
- return literalstring_u2(a, utflength, 0, false);
+ return literalstring_u2((java_handle_chararray_t*) a, utflength, 0, false);
}
Intern the given Java string.
- XXX NOTE: Literal Strings are direct references since they are not placed
- onto the GC-Heap. That's why this function looks so "different".
-
*******************************************************************************/
java_handle_t *javastring_intern(java_handle_t *string)
{
java_lang_String jls(string);
- java_handle_chararray_t* value = jls.get_value();
- // FIXME
- java_chararray_t* ca = LLNI_UNWRAP(value); /* XXX see note above */
+ CharArray ca(jls.get_value());
int32_t count = jls.get_count();
int32_t offset = jls.get_offset();
- java_object_t* o = literalstring_u2(ca, count, offset, true); /* XXX see note above */
+ java_handle_t* o = literalstring_u2(ca.get_handle(), count, offset, true);
- return LLNI_WRAP(o); /* XXX see note above */
+ return o;
}
{
java_lang_String jls(s);
- java_handle_chararray_t* value = jls.get_value();
+ CharArray ca(jls.get_value());
int32_t count = jls.get_count();
int32_t offset = jls.get_offset();
+ // XXX: Fix me!
+ uint16_t* ptr = (uint16_t*) ca.get_raw_data_ptr();
+
for (int32_t i = offset; i < offset + count; i++) {
- uint16_t c = LLNI_array_direct(value, i);
+ uint16_t c = ptr[i];
fputc(c, stream);
}
}
void vm_run(JavaVM *vm, JavaVMInitArgs *vm_args)
{
- char* option;
- char* mainname;
- char* p;
- utf *mainutf;
- classinfo *mainclass;
- java_handle_t *e;
- methodinfo *m;
- java_handle_objectarray_t *oa;
- s4 oalength;
- utf *u;
- java_handle_t *s;
- int status;
-
- // Prevent compiler warnings.
- oa = NULL;
+ methodinfo* m;
+ int status;
#if !defined(NDEBUG)
if (compileall) {
}
#endif
- /* Get the main class plus it's arguments. */
+ /* Get the main class or jar file argument. */
- mainname = NULL;
+ char* mainname = NULL;
if (opt_index < vm_args->nOptions) {
/* Get main-class argument. */
classpath. */
if (opt_jar == true) {
- p = MNEW(char, strlen(mainname) + strlen("0"));
+ char* p = MNEW(char, strlen(mainname) + strlen("0"));
strcpy(p, mainname);
mainname[i] = '/';
}
- /* Build argument array. Move index to first argument. */
+ /* Move index to first argument. */
opt_index++;
-
- oalength = vm_args->nOptions - opt_index;
-
- oa = builtin_anewarray(oalength, class_java_lang_String);
-
- for (int i = 0; i < oalength; i++) {
- option = vm_args->options[opt_index + i].optionString;
-
- u = utf_new_char(option);
- s = javastring_new(u);
-
- array_objectarray_element_set(oa, i, s);
- }
}
/* Do we have a main-class argument? */
}
#endif
+ /* Build argument array. */
+
+ int32_t oalength = vm_args->nOptions - opt_index;
+
+ ObjectArray oa(oalength, class_java_lang_String);
+
+ if (oa.is_null())
+ vm_exit(1);
+
+ for (int i = 0; i < oalength; i++) {
+ char* option = vm_args->options[opt_index + i].optionString;
+
+ utf* u = utf_new_char(option);
+ java_handle_t* s = javastring_new(u);
+
+ oa.set_element(i, s);
+ }
+
/* set return value to OK */
status = 0;
/* load the main class */
- mainutf = utf_new_char(mainname);
+ utf* mainutf = utf_new_char(mainname);
#if defined(ENABLE_JAVAME_CLDC1_1)
- mainclass = load_class_bootstrap(mainutf);
+ classinfo* mainclass = load_class_bootstrap(mainutf);
#else
- mainclass = load_class_from_sysloader(mainutf);
+ classinfo* mainclass = load_class_from_sysloader(mainutf);
#endif
/* error loading class */
- e = exceptions_get_and_clear_exception();
+ java_handle_t* e = exceptions_get_and_clear_exception();
if ((e != NULL) || (mainclass == NULL)) {
exceptions_throw_noclassdeffounderror_cause(e);
/* start the main thread */
- (void) vm_call_method(m, NULL, oa);
+ (void) vm_call_method(m, NULL, oa.get_handle());
/* exception occurred? */