CACAO
java_lang_VMThrowable.cpp
Go to the documentation of this file.
1 /* src/native/vm/gnuclasspath/java_lang_VMThrowable.cpp
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdint.h>
29 #include <assert.h>
30 
31 #include "vm/types.hpp"
32 
33 #include "native/jni.hpp"
34 #include "native/llni.hpp"
35 #include "native/native.hpp"
36 
37 #if defined(ENABLE_JNI_HEADERS)
38 # include "native/vm/include/java_lang_VMThrowable.h"
39 #endif
40 
41 #include "vm/array.hpp"
42 #include "vm/jit/builtin.hpp"
43 #include "vm/exceptions.hpp"
44 #include "vm/globals.hpp"
45 #include "vm/javaobjects.hpp"
46 #include "vm/loader.hpp"
47 #include "vm/string.hpp"
48 #include "vm/vm.hpp"
49 
50 #include "vm/jit/code.hpp"
52 #include "vm/jit/stacktrace.hpp"
53 
54 
55 
56 // Native functions are exported as C functions.
57 extern "C" {
58 
59 /*
60  * Class: java/lang/VMThrowable
61  * Method: fillInStackTrace
62  * Signature: (Ljava/lang/Throwable;)Ljava/lang/VMThrowable;
63  */
65 {
66  java_handle_t* h;
68 
70 
71  if (h == NULL)
72  return NULL;
73 
74  java_lang_VMThrowable vmt(h);
75 
77 
78  if (ba == NULL)
79  return NULL;
80 
81  vmt.set_vmdata(ba);
82 
83  return (jobject) vmt.get_handle();
84 }
85 
86 
87 /*
88  * Class: java/lang/VMThrowable
89  * Method: getStackTrace
90  * Signature: (Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;
91  */
93 {
94  java_lang_VMThrowable vmt(_this);
95 
96  // Get the stacktrace from the VMThrowable object.
97 
98  ByteArray ba(vmt.get_vmdata());
99 
100  // XXX Critical GC section?
101  stacktrace_t* st = (stacktrace_t*) ba.get_raw_data_ptr();
102 
103  assert(st != NULL);
104 
106 }
107 
108 } // extern "C"
109 
110 
111 /* native methods implemented by this file ************************************/
112 
113 static JNINativeMethod methods[] = {
114  { (char*) "fillInStackTrace", (char*) "(Ljava/lang/Throwable;)Ljava/lang/VMThrowable;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_fillInStackTrace },
115  { (char*) "getStackTrace", (char*) "(Ljava/lang/Throwable;)[Ljava/lang/StackTraceElement;", (void*) (uintptr_t) &Java_java_lang_VMThrowable_getStackTrace },
116 };
117 
118 
119 /* _Jv_java_lang_VMThrowable_init **********************************************
120 
121  Register native functions.
122 
123 *******************************************************************************/
124 
126 {
127  Utf8String u = Utf8String::from_utf8("java/lang/VMThrowable");
128 
131 }
132 
133 
134 /*
135  * These are local overrides for various environment variables in Emacs.
136  * Please do not remove this and leave it at the end of the file, where
137  * Emacs will automagically detect them.
138  * ---------------------------------------------------------------------
139  * Local variables:
140  * mode: c++
141  * indent-tabs-mode: t
142  * c-basic-offset: 4
143  * tab-width: 4
144  * End:
145  */
virtual java_handle_t * get_handle() const
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
JNIEXPORT jobjectArray JNICALL Java_java_lang_VMThrowable_getStackTrace(JNIEnv *env, jobject _this, jobject t)
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
classinfo * class_java_lang_VMThrowable
Definition: globals.cpp:49
static JNINativeMethod methods[]
void set_vmdata(java_handle_bytearray_t *value)
JNIEXPORT jobject JNICALL Java_java_lang_VMThrowable_fillInStackTrace(JNIEnv *env, jclass clazz, jobject t)
GNU Classpath java/lang/VMThrowable.
java_handle_objectarray_t * stacktrace_get_StackTraceElements(stacktrace_t *st)
Creates a complete array of java.lang.StackTraceElement objects for the given stacktrace.
Definition: stacktrace.cpp:740
java_handle_bytearray_t * get_vmdata() const
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
void _Jv_java_lang_VMThrowable_init(void)
java_handle_t * native_new_and_init(classinfo *c)
Registers a new native agent by specified by it&#39;s library name and with an optional options string...
Definition: native.cpp:729
java_handle_bytearray_t * stacktrace_get_current(void)
Definition: stacktrace.cpp:635
static VM * get_current()
Definition: vm.hpp:99