{
TRACEJNICALLS(("_Jv_JNI_GetVersion(env=%p)", env));
- /* We support JNI 1.6. */
-
- return JNI_VERSION_1_6;
+ return JNI_VERSION_SUPPORTED;
}
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';
}
/* GNU classpath currently supports JNI 1.2 */
switch (_vm_args->version) {
- case JNI_VERSION_1_1:
+ case JNI_VERSION_1_1:
_vm_args->version = JNI_VERSION_1_1;
break;
- case JNI_VERSION_1_2:
- case JNI_VERSION_1_4:
+ case JNI_VERSION_1_2:
+ case JNI_VERSION_1_4:
_vm_args->ignoreUnrecognized = JNI_FALSE;
_vm_args->options = NULL;
_vm_args->nOptions = 0;
break;
- default:
- return -1;
+ case JNI_VERSION_CACAO:
+ // We reveal ourselves by accepting this version number,
+ // this actually means we are using the supported JNI version.
+ _vm_args->version = JNI_VERSION_SUPPORTED;
+ break;
+
+ default:
+ return JNI_ERR;
}
-
- return 0;
+
+ return JNI_OK;
}
#include "mm/memory.hpp"
#include "native/jni.hpp"
- #include "native/llni.h"
#include "native/native.hpp"
#if defined(ENABLE_JNI_HEADERS)
char *path;
utf *uname;
java_handle_t* descriptor;
-
+
+ // Get current list of classpath entries.
+ SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
+
/* get the classname as char string (do it here for the warning at
the end of the function) */
filenamelen = utf_bytes(uname) + strlen("0");
filename = MNEW(char, filenamelen);
utf_copy(filename, uname);
-
+
/* walk through all classpath entries */
- for (List<list_classpath_entry*>::iterator it = list_classpath_entries->begin(); it != list_classpath_entries->end(); it++) {
+ for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
list_classpath_entry* lce = *it;
#if defined(ENABLE_ZLIB)
{
/* 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)
#endif
#include "vm/global.h"
+#include "vm/os.hpp"
#include "vm/vm.hpp" /* REMOVE ME: temporarily */
// 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);
return -1;
}
else if (result < 0) {
- vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf: recv failed");
+ os::abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readBuf: recv failed");
}
return result;
}
else if (result < 0) {
// TODO Should throw an IOException.
- vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readByte: recv failed");
+ os::abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_readByte: recv failed");
}
return byte;
{
// 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);
if (result < 0) {
// TODO Should throw an IOException.
- vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf: send failed");
+ os::abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeBuf: send failed");
}
return result;
ssize_t result = send(handle, &byte, 1, 0);
if (result < 0)
- vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte: send failed");
+ os::abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_writeByte: send failed");
return result;
}
int result = close(handle);
if (result < 0)
- vm_abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_close0: close failed");
+ os::abort_errno("Java_com_sun_cldc_io_j2me_socket_Protocol_close0: close failed");
}
} // extern "C"
#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);
}
struct stat buf; /* buffer for stat */
jboolean ret; /* return value of "add" */
+ // Get current list of classpath entries.
+ SuckClasspath& suckclasspath = VM::get_current()->get_suckclasspath();
+
/* get the resource name as utf string */
utfname = javastring_toutf((java_handle_t *) name, false);
/* iterate over all classpath entries */
- for (List<list_classpath_entry*>::iterator it = list_classpath_entries->begin(); it != list_classpath_entries->end(); it++) {
+ for (SuckClasspath::iterator it = suckclasspath.begin(); it != suckclasspath.end(); it++) {
list_classpath_entry* lce = *it;
/* clear path pointer */
# 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)
*/
JNIEXPORT jboolean JNICALL Java_sun_misc_Unsafe_compareAndSwapObject(JNIEnv *env, jobject _this, jobject o, jlong offset, jobject expected, jobject x)
{
- volatile void **p;
+ void **p;
void *result;
/* XXX Use LLNI */
- p = (volatile void **) (((uint8_t *) o) + offset);
+ p = (void **) (((uint8_t *) o) + offset);
- result = Atomic::compare_and_swap(p, expected, x);
+ result = Atomic::compare_and_swap(p, (void *) expected, (void *) x);
if (result == expected)
return true;
p = (uint32_t *) (((uint8_t *) o) + offset);
- result = Atomic::compare_and_swap(p, expected, x);
+ result = Atomic::compare_and_swap(p, (uint32_t) expected, (uint32_t) x);
if (result == (uint32_t) expected)
return true;
p = (uint64_t *) (((uint8_t *) o) + offset);
- result = Atomic::compare_and_swap(p, expected, x);
+ result = Atomic::compare_and_swap(p, (uint64_t) expected, (uint64_t) x);
if (result == (uint64_t) expected)
return true;
bool class_isanysubclass(classinfo *sub, classinfo *super)
{
- uint32_t diffval;
- bool result;
+ bool result;
/* This is the trivial case. */
#else
LOCK_CLASSRENUMBER_LOCK;
- diffval = sub->vftbl->baseval - super->vftbl->baseval;
- result = diffval <= (uint32_t) super->vftbl->diffval;
+ uint32_t diffval = sub->vftbl->baseval - super->vftbl->baseval;
+ result = diffval <= (uint32_t) super->vftbl->diffval;
UNLOCK_CLASSRENUMBER_LOCK;
#endif
}
+/* class_is_arraycompatible ****************************************************
+
+ Checks if two array type descriptors are assignment compatible.
+
+ RETURN VALUE:
+ true .... target = desc is possible
+ false ... otherwise
+
+*******************************************************************************/
+
+bool class_is_arraycompatible(arraydescriptor *desc, arraydescriptor *target)
+{
+ if (desc == target)
+ return true;
+
+ if (desc->arraytype != target->arraytype)
+ return false;
+
+ if (desc->arraytype != ARRAYTYPE_OBJECT)
+ return true;
+
+ /* {both arrays are arrays of references} */
+
+ if (desc->dimension == target->dimension) {
+ if (!desc->elementvftbl)
+ return false;
+
+ /* an array which contains elements of interface types is
+ allowed to be casted to array of Object (JOWENN) */
+
+ if ((desc->elementvftbl->baseval < 0) &&
+ (target->elementvftbl->baseval == 1))
+ return true;
+
+ return class_isanysubclass(desc->elementvftbl->clazz,
+ target->elementvftbl->clazz);
+ }
+
+ if (desc->dimension < target->dimension)
+ return false;
+
+ /* {desc has higher dimension than target} */
+
+ return class_isanysubclass(pseudo_class_Arraystub,
+ target->elementvftbl->clazz);
+}
+
+
/* class_is_assignable_from ****************************************************
Return whether an instance of the "from" class parameter would be
if (!link_class(from))
return false;
- return class_isanysubclass(from, to);
+ /* Decide whether we are dealing with array types or object types. */
+
+ if (class_is_array(to) && class_is_array(from))
+ return class_is_arraycompatible(from->vftbl->arraydesc, to->vftbl->arraydesc);
+ else
+ return class_isanysubclass(from, to);
}
if (!link_class(c))
return false;
- return builtin_instanceof(h, c);
+ /* Decide whether we are dealing with array types or object types. */
+
+ if (class_is_array(c))
+ return builtin_arrayinstanceof(h, c);
+ else
+ return builtin_instanceof(h, c);
}
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
}
-/* builtin_descriptorscompatible ***********************************************
-
- Checks if two array type descriptors are assignment compatible.
-
- RETURN VALUE:
- 1......target = desc is possible
- 0......otherwise
-
-*******************************************************************************/
-
-static bool builtin_descriptorscompatible(arraydescriptor *desc, arraydescriptor *target)
-{
- if (desc == target)
- return 1;
-
- if (desc->arraytype != target->arraytype)
- return 0;
-
- if (desc->arraytype != ARRAYTYPE_OBJECT)
- return 1;
-
- /* {both arrays are arrays of references} */
-
- if (desc->dimension == target->dimension) {
- if (!desc->elementvftbl)
- return 0;
- /* an array which contains elements of interface types is
- allowed to be casted to Object (JOWENN)*/
-
- if ((desc->elementvftbl->baseval < 0) &&
- (target->elementvftbl->baseval == 1))
- return 1;
-
- return class_isanysubclass(desc->elementvftbl->clazz,
- target->elementvftbl->clazz);
- }
-
- if (desc->dimension < target->dimension)
- return 0;
-
- /* {desc has higher dimension than target} */
-
- return class_isanysubclass(pseudo_class_Arraystub,
- target->elementvftbl->clazz);
-}
-
-
/* builtin_arraycheckcast ******************************************************
Checks if an object is really a subtype of the requested array
if (desc == NULL)
return 0;
- return builtin_descriptorscompatible(desc, targetclass->vftbl->arraydesc);
+ return class_is_arraycompatible(desc, targetclass->vftbl->arraydesc);
}
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;
vftbl_t *componentvftbl;
vftbl_t *valuevftbl;
int32_t baseval;
- uint32_t diffval;
bool result;
if (o == NULL)
#if USES_NEW_SUBTYPE
result = fast_subtype_check(valuevftbl, componentvftbl);
#else
- diffval = valuevftbl->baseval - componentvftbl->baseval;
- result = diffval <= (uint32_t) componentvftbl->diffval;
+ uint32_t diffval = valuevftbl->baseval - componentvftbl->baseval;
+ result = diffval <= (uint32_t) componentvftbl->diffval;
#endif
}
else {
/* {o is an array} */
- result = builtin_descriptorscompatible(valuedesc, componentvftbl->arraydesc);
+ result = class_is_arraycompatible(valuedesc, componentvftbl->arraydesc);
}
/* return result */
vftbl_t *elementvftbl;
vftbl_t *valuevftbl;
int32_t baseval;
- uint32_t diffval;
bool result;
if (o == NULL)
#if USES_NEW_SUBTYPE
result = fast_subtype_check(valuevftbl, elementvftbl);
#else
- diffval = valuevftbl->baseval - elementvftbl->baseval;
- result = diffval <= (uint32_t) elementvftbl->diffval;
+ uint32_t diffval = valuevftbl->baseval - elementvftbl->baseval;
+ result = diffval <= (uint32_t) elementvftbl->diffval;
#endif
}
* one-dimensional array of a class type */
bool builtin_fast_canstore_onedim_class(java_objectarray_t *a, java_object_t *o)
{
- vftbl_t *elementvftbl;
- vftbl_t *valuevftbl;
- uint32_t diffval;
- bool result;
+ vftbl_t *elementvftbl;
+ vftbl_t *valuevftbl;
+ bool result;
if (o == NULL)
return 1;
#if USES_NEW_SUBTYPE
result = fast_subtype_check(valuevftbl, elementvftbl);
#else
- diffval = valuevftbl->baseval - elementvftbl->baseval;
- result = diffval <= (uint32_t) elementvftbl->diffval;
+ uint32_t diffval = valuevftbl->baseval - elementvftbl->baseval;
+ result = diffval <= (uint32_t) elementvftbl->diffval;
#endif
UNLOCK_CLASSRENUMBER_LOCK;
}
- /* 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);
# include "vm/jit/python.h"
#endif
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
#if defined(ENABLE_JVMTI)
# include "native/jvmti/cacaodbg.h"
OPT_SHOW,
OPT_DEBUGCOLOR,
-#if !defined(NDEBUG)
- OPT_ALL,
- OPT_METHOD,
- OPT_SIGNATURE,
-#endif
-
#if defined(ENABLE_VERIFIER)
OPT_NOVERIFY,
OPT_XVERIFY_ALL,
{ "c", true, OPT_CHECK },
{ "l", false, OPT_LOAD },
-#if !defined(NDEBUG)
- { "all", false, OPT_ALL },
- { "sig", true, OPT_SIGNATURE },
-#endif
-
#if defined(ENABLE_LOOP)
{ "oloop", false, OPT_OLOOP },
#endif
/* keep these at the end of the list */
-#if !defined(NDEBUG)
- { "m", true, OPT_METHOD },
-#endif
-
{ "s", true, OPT_SHOW },
{ "debug-color", false, OPT_DEBUGCOLOR },
puts(" -oloop optimize array accesses in loops");
#endif
puts(" -l don't start the class after loading");
-#if !defined(NDEBUG)
- puts(" -all compile all methods, no execution");
- puts(" -m compile only a specific method");
- puts(" -sig specify signature for a specific method");
-#endif
puts(" -s... show...");
puts(" (c)onstants the constant pool");
makeinitializations = false;
break;
-#if !defined(NDEBUG)
- case OPT_ALL:
- compileall = true;
- opt_run = false;
- makeinitializations = false;
- break;
-
- case OPT_METHOD:
- opt_run = false;
- opt_method = opt_arg;
- makeinitializations = false;
- break;
-
- case OPT_SIGNATURE:
- opt_signature = opt_arg;
- break;
-#endif
-
case OPT_SHOW: /* Display options */
for (unsigned int i = 0; i < strlen(opt_arg); i++) {
switch (opt_arg[i]) {
/* AFTER: thread_preinit */
- if (!suck_init())
- os::abort("vm_create: suck_init failed");
-
- suck_add_from_property("java.endorsed.dirs");
+ _suckclasspath.add_from_property("java.endorsed.dirs");
/* Now we have all options handled and we can print the version
information.
// FIXME Make boot_class_path const char*.
boot_class_path = (char*) _properties.get("sun.boot.class.path");
- suck_add(boot_class_path);
+ _suckclasspath.add(boot_class_path);
/* initialize the classcache hashtable stuff: lock, hashtable
(must be done _after_ threads_preinit) */
/* Initialize the native VM subsystem. */
/* AFTER: threads_init (at least for SUN's classes) */
- nativevm_init();
+ if (!nativevm_init())
+ os::abort("vm_create: nativevm_init failed");
#if defined(ENABLE_PROFILING)
/* initialize profiling */
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) {
+ if (opt_CompileAll) {
vm_compile_all();
return;
}
#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? */
usage();
#if !defined(NDEBUG)
- if (opt_method != NULL) {
+ if (opt_CompileMethod != NULL) {
vm_compile_method(mainname);
return;
}
#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? */
if (!link_class(mainclass))
exceptions_print_stacktrace();
- if (opt_signature != NULL) {
+ if (opt_CompileSignature != NULL) {
m = class_resolveclassmethod(mainclass,
- utf_new_char(opt_method),
- utf_new_char(opt_signature),
+ utf_new_char(opt_CompileMethod),
+ utf_new_char(opt_CompileSignature),
mainclass,
false);
}
else {
m = class_resolveclassmethod(mainclass,
- utf_new_char(opt_method),
+ utf_new_char(opt_CompileMethod),
NULL,
mainclass,
false);
if (m == NULL)
os::abort("vm_compile_method: java.lang.NoSuchMethodException: %s.%s",
- opt_method, opt_signature ? opt_signature : "");
+ opt_CompileMethod, opt_CompileSignature ? opt_CompileSignature : "");
jit_compile(m);
}
{
va_list ap;
- va_start(ap, text);
- os::abort(text, ap);
- va_end(ap);
-}
+ log_println("vm_abort: WARNING, port me to C++ and use os::abort() instead.");
-void vm_abort_errnum(int errnum, const char* text, ...)
-{
- va_list ap;
+ // Print the log message.
+ log_start();
va_start(ap, text);
- os::abort_errnum(errnum, text, ap);
+ log_vprint(text, ap);
va_end(ap);
-}
-void vm_abort_errno(const char* text, ...)
-{
- va_list ap;
+ log_finish();
- va_start(ap, text);
- os::abort_errno(text, ap);
- va_end(ap);
+ // Print a backtrace.
+ os::print_backtrace();
+
+ // Now abort the VM.
+ os::abort();
}
}