* src/vm/array.hpp: Implemented array access classes in C++.
[cacao.git] / src / native / vm / gnuclasspath / java_lang_VMThrowable.cpp
index 6eedf4b4cfe04de795e6aa4e4c0bb74244a00492..2e2bae3664cf9e9ef49f944af0d3fa5719ec7894 100644 (file)
 
 #include "native/jni.hpp"
 #include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
 
 #if defined(ENABLE_JNI_HEADERS)
 # include "native/vm/include/java_lang_VMThrowable.h"
 #endif
 
-#include "vm/array.h"
+#include "vm/array.hpp"
 #include "vm/jit/builtin.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/globals.hpp"
@@ -94,73 +94,14 @@ JNIEXPORT jobjectArray JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *
 
        // 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);
 
-       stacktrace_entry_t* ste = st->entries;
-
-       /* Create the stacktrace element array. */
-
-       java_handle_objectarray_t* oa = builtin_anewarray(st->length, class_java_lang_StackTraceElement);
-
-       if (oa == NULL)
-               return NULL;
-
-       for (int i = 0; i < st->length; i++, ste++) {
-               /* Get the codeinfo and methodinfo. */
-
-               codeinfo*   code = ste->code;
-               methodinfo* m    = code->m;
-
-               /* Get filename. */
-
-               java_handle_t* filename;
-
-               if (!(m->flags & ACC_NATIVE)) {
-                       if (m->clazz->sourcefile)
-                               filename = javastring_new(m->clazz->sourcefile);
-                       else
-                               filename = NULL;
-               }
-               else
-                       filename = NULL;
-
-               /* get line number */
-
-               int32_t linenumber;
-
-               if (m->flags & ACC_NATIVE) {
-                       linenumber = -1;
-               }
-               else {
-                       /* FIXME linenumbertable->find could change the methodinfo
-                          pointer when hitting an inlined method. */
-
-                       linenumber = code->linenumbertable->find(&m, ste->pc);
-                       linenumber = (linenumber == 0) ? -1 : linenumber;
-               }
-
-               /* get declaring class name */
-
-               java_handle_t* declaringclass = class_get_classname(m->clazz);
-
-               /* allocate a new stacktrace element */
-
-               java_handle_t* h = builtin_new(class_java_lang_StackTraceElement);
-
-               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 (jobjectArray) oa;
+       return stacktrace_get_StackTraceElements(st);
 }
 
 } // extern "C"
@@ -180,15 +121,12 @@ static JNINativeMethod methods[] = {
 
 *******************************************************************************/
 
-extern "C" {
 void _Jv_java_lang_VMThrowable_init(void)
 {
-       utf *u;
-
-       u = utf_new_char("java/lang/VMThrowable");
+       utf* u = utf_new_char("java/lang/VMThrowable");
 
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }