#include "vm/types.h"
-#include "native/jni.h"
+#include "native/jni.hpp"
#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 "vm/array.h"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
-
-#include "vm/jit/code.h"
-#include "vm/jit/linenumbertable.h"
+#include "native/native.hpp"
+
+#if defined(ENABLE_JNI_HEADERS)
+# include "native/vm/include/java_lang_VMThrowable.h"
+#endif
+
+#include "vm/array.hpp"
+#include "vm/jit/builtin.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/globals.hpp"
+#include "vm/javaobjects.hpp"
+#include "vm/loader.hpp"
+#include "vm/string.hpp"
+
+#include "vm/jit/code.hpp"
+#include "vm/jit/linenumbertable.hpp"
#include "vm/jit/stacktrace.hpp"
-#include "vmcore/class.h"
-#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.
* 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;
+ vmt.set_vmdata(ba);
- LLNI_field_set_ref(vmto, vmdata, o);
-
- 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;
-
- /* Get the stacktrace from the VMThrowable object. */
+ java_lang_VMThrowable vmt(_this);
- LLNI_field_get_ref(_this, vmdata, o);
+ // Get the stacktrace from the VMThrowable object.
- ba = (java_handle_bytearray_t *) o;
+ ByteArray ba(vmt.get_vmdata());
- st = (stacktrace_t *) LLNI_array_data(ba);
+ // XXX Critical GC section?
+ stacktrace_t* st = (stacktrace_t*) ba.get_raw_data_ptr();
assert(st != NULL);
- ste = st->entries;
-
- /* Create the stacktrace element array. */
-
- 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;
-
- /* Get the codeinfo and methodinfo. */
-
- code = ste->code;
- m = code->m;
-
- /* Get filename. */
+ return stacktrace_get_StackTraceElements(st);
+}
- if (!(m->flags & ACC_NATIVE)) {
- if (m->clazz->sourcefile)
- filename = (java_lang_String *) javastring_new(m->clazz->sourcefile);
- else
- filename = NULL;
- }
- else
- filename = NULL;
+} // extern "C"
- /* get line number */
- if (m->flags & ACC_NATIVE) {
- linenumber = -1;
- }
- else {
- /* FIXME The linenumbertable_linenumber_for_pc could
- change the methodinfo pointer when hitting an inlined
- method. */
+/* native methods implemented by this file ************************************/
- linenumber = linenumbertable_linenumber_for_pc(&m, code, ste->pc);
- linenumber = (linenumber == 0) ? -1 : linenumber;
- }
+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 },
+};
- /* get declaring class name */
- declaringclass = class_get_classname(m->clazz);
+/* _Jv_java_lang_VMThrowable_init **********************************************
- /* Fill the java.lang.StackTraceElement object. */
+ Register native functions.
- 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);
+*******************************************************************************/
- array_objectarray_element_set(oa, i, (java_handle_t *) steo);
- }
+void _Jv_java_lang_VMThrowable_init(void)
+{
+ utf* u = utf_new_char("java/lang/VMThrowable");
- return oa;
+ NativeMethods& nm = VM::get_current()->get_nativemethods();
+ nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
}
-} // extern "C"
-
/*
* These are local overrides for various environment variables in Emacs.