#include "native/llni.h"
#include "native/native.h"
-#include "native/include/java_lang_Object.h"
-#include "native/include/java_lang_Class.h"
-#include "native/include/java_lang_String.h"
-#include "native/include/java_lang_StackTraceElement.h"
-#include "native/include/java_lang_Throwable.h"
-
// FIXME
-extern "C" {
-#include "native/include/java_lang_VMThrowable.h"
-}
+//#include "native/include/java_lang_VMThrowable.h"
#include "vm/array.h"
#include "vm/builtin.h"
#include "vm/jit/stacktrace.hpp"
#include "vmcore/globals.hpp"
+#include "vmcore/javaobjects.hpp"
#include "vmcore/loader.h"
-/* native methods implemented by this file ************************************/
-
-static JNINativeMethod methods[] = {
- { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace },
- { (char*) "getStackTrace", (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace },
-};
-
-
-/* _Jv_java_lang_VMThrowable_init **********************************************
-
- Register native functions.
-
-*******************************************************************************/
-
-extern "C" {
-void _Jv_java_lang_VMThrowable_init(void)
-{
- utf *u;
-
- u = utf_new_char("java/lang/VMThrowable");
-
- native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
-}
-
-
// Native functions are exported as C functions.
extern "C" {
* Method: fillInStackTrace
* Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
*/
-JNIEXPORT java_lang_VMThrowable* JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, java_lang_Throwable *t)
+JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, jobject t)
{
- java_lang_VMThrowable *vmto;
- java_handle_bytearray_t *ba;
- java_lang_Object *o;
+ java_handle_t* h;
+ java_handle_bytearray_t* ba;
- vmto = (java_lang_VMThrowable *)
- native_new_and_init(class_java_lang_VMThrowable);
+ h = native_new_and_init(class_java_lang_VMThrowable);
- if (vmto == NULL)
+ if (h == NULL)
return NULL;
+ java_lang_VMThrowable vmt(h);
+
ba = stacktrace_get_current();
if (ba == NULL)
return NULL;
- o = (java_lang_Object *) ba;
-
- LLNI_field_set_ref(vmto, vmdata, o);
+ vmt.set_vmdata(ba);
- return vmto;
+ return (jobject) vmt.get_handle();
}
* Method: getStackTrace
* Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
*/
-JNIEXPORT java_handle_objectarray_t* JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, java_lang_VMThrowable *_this, java_lang_Throwable *t)
+JNIEXPORT jobjectArray JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, jobject _this, jobject t)
{
- java_lang_Object *o;
- java_handle_bytearray_t *ba;
- stacktrace_t *st;
- stacktrace_entry_t *ste;
- java_handle_objectarray_t *oa;
- java_lang_StackTraceElement *steo;
- codeinfo *code;
- methodinfo *m;
- java_lang_String *filename;
- s4 linenumber;
- java_handle_t *declaringclass;
- int i;
+ java_lang_VMThrowable vmt(_this);
- /* Get the stacktrace from the VMThrowable object. */
+ // Get the stacktrace from the VMThrowable object.
- LLNI_field_get_ref(_this, vmdata, o);
+ java_handle_bytearray_t* ba = vmt.get_vmdata();
- ba = (java_handle_bytearray_t *) o;
-
- st = (stacktrace_t *) LLNI_array_data(ba);
+ // XXX Critical GC section?
+ stacktrace_t* st = (stacktrace_t*) LLNI_array_data(ba);
assert(st != NULL);
- ste = st->entries;
+ stacktrace_entry_t* ste = st->entries;
/* Create the stacktrace element array. */
- oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement);
+ java_handle_objectarray_t* oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement);
if (oa == NULL)
return NULL;
- for (i = 0; i < st->length; i++, ste++) {
- /* allocate a new stacktrace element */
-
- steo = (java_lang_StackTraceElement *)
- builtin_new(class_java_lang_StackTraceElement);
-
- if (steo == NULL)
- return NULL;
-
+ for (int i = 0; i < st->length; i++, ste++) {
/* Get the codeinfo and methodinfo. */
- code = ste->code;
- m = code->m;
+ codeinfo* code = ste->code;
+ methodinfo* m = code->m;
/* Get filename. */
+ java_handle_t* filename;
+
if (!(m->flags & ACC_NATIVE)) {
if (m->clazz->sourcefile)
- filename = (java_lang_String *) javastring_new(m->clazz->sourcefile);
+ filename = javastring_new(m->clazz->sourcefile);
else
filename = NULL;
}
/* get line number */
+ int32_t linenumber;
+
if (m->flags & ACC_NATIVE) {
linenumber = -1;
}
/* get declaring class name */
- declaringclass = class_get_classname(m->clazz);
+ java_handle_t* declaringclass = class_get_classname(m->clazz);
- /* Fill the java.lang.StackTraceElement object. */
+ /* allocate a new stacktrace element */
- LLNI_field_set_ref(steo, fileName , filename);
- LLNI_field_set_val(steo, lineNumber , linenumber);
- LLNI_field_set_ref(steo, declaringClass, (java_lang_String*) declaringclass);
- LLNI_field_set_ref(steo, methodName , (java_lang_String *) javastring_new(m->name));
- LLNI_field_set_val(steo, isNative , (m->flags & ACC_NATIVE) ? 1 : 0);
+ java_handle_t* h = builtin_new(class_java_lang_StackTraceElement);
- array_objectarray_element_set(oa, i, (java_handle_t *) steo);
+ if (h == NULL)
+ return NULL;
+
+ java_lang_StackTraceElement ste(h, filename, linenumber, declaringclass, javastring_new(m->name), ((m->flags & ACC_NATIVE) ? 1 : 0));
+
+ array_objectarray_element_set(oa, i, ste.get_handle());
}
- return oa;
+ return (jobjectArray) oa;
}
} // extern "C"
+/* native methods implemented by this file ************************************/
+
+static JNINativeMethod methods[] = {
+ { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace },
+ { (char*) "getStackTrace", (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace },
+};
+
+
+/* _Jv_java_lang_VMThrowable_init **********************************************
+
+ Register native functions.
+
+*******************************************************************************/
+
+extern "C" {
+void _Jv_java_lang_VMThrowable_init(void)
+{
+ utf *u;
+
+ u = utf_new_char("java/lang/VMThrowable");
+
+ native_method_register(u, methods, NATIVE_METHODS_COUNT);
+}
+}
+
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where