This also renames ->jni_interface_frame field of struct
jni_stack_entry to ->vm_frame VM can be entered from JNI not only
through JNI interface function but also through JNI trampoline
(jit_native_trampoline).

Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 include/vm/stack-trace.h |   19 +++++++++----------
 jit/trampoline.c         |    3 +++
 vm/jni-interface.c       |   36 ++++++++++++++++++------------------
 vm/stack-trace.c         |    2 +-
 4 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/include/vm/stack-trace.h b/include/vm/stack-trace.h
index 925cdce..4bde292 100644
--- a/include/vm/stack-trace.h
+++ b/include/vm/stack-trace.h
@@ -23,14 +23,13 @@ struct jni_stack_entry {
         * when stack is traversed. */
        struct vm_method *method;
 
-       /* This field is filled in on entry to any JNI interface
-        * function. Having this field filled in allows the
-        * stackwalker to skip whole JNI call. When JNI interface
-        * fuction returns to JNI caller nothing is done because this
-        * structure can be accessed only when we're in VM which can
-        * happen only after some JNI interface function was
-        * called. */
-       void *jni_interface_frame;
+       /* This field is filled in on VM entry from JNI method which
+        * is not return from that method. Having this field filled in
+        * allows the stackwalker to skip whole JNI call. When VM
+        * returns to JNI nothing is done because this entry can be
+        * accessed only from VM.
+        */
+       void *vm_frame;
 } __attribute__((packed));
 
 struct vm_native_stack_entry {
@@ -83,8 +82,8 @@ static inline void *vm_native_stack_get_frame(void)
  * optimizations might optimize some function calls so that the target
  * function runs in the caller's frame. We want to avoid this situation.
  */
-#define vm_enter_jni_interface() {                                     \
-       jni_stack[jni_stack_index() - 1].jni_interface_frame = \
+#define enter_vm_from_jni() {                                          \
+               jni_stack[jni_stack_index() - 1].vm_frame =             \
                        __builtin_frame_address(0);                     \
        }
 
diff --git a/jit/trampoline.c b/jit/trampoline.c
index 794b431..415d4d5 100644
--- a/jit/trampoline.c
+++ b/jit/trampoline.c
@@ -39,6 +39,7 @@
 #include "vm/die.h"
 #include "vm/vm.h"
 #include "vm/jni.h"
+#include "vm/stack-trace.h"
 
 #include <stdio.h>
 
@@ -48,6 +49,8 @@ static void *jit_native_trampoline(struct compilation_unit 
*cu)
        struct vm_method *method;
        void *ret;
 
+       enter_vm_from_jni();
+
        method = cu->method;
 
        class_name  = method->class->name;
diff --git a/vm/jni-interface.c b/vm/jni-interface.c
index a09fe34..6a5488c 100644
--- a/vm/jni-interface.c
+++ b/vm/jni-interface.c
@@ -57,7 +57,7 @@ vm_jni_find_class(struct vm_jni_env *env, const char *name)
 {
        struct vm_class *class;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        class = classloader_load(name);
        if (!class) {
@@ -80,7 +80,7 @@ vm_jni_get_method_id(struct vm_jni_env *env, jclass clazz, 
const char *name,
        struct vm_method *mb;
        struct vm_class *class;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        check_null(clazz);
        check_class_object(clazz);
@@ -109,7 +109,7 @@ vm_jni_get_field_id(struct vm_jni_env *env, jclass clazz, 
const char *name,
        struct vm_field *fb;
        struct vm_class *class;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        check_null(clazz);
        check_class_object(clazz);
@@ -138,7 +138,7 @@ vm_jni_get_static_method_id(struct vm_jni_env *env, jclass 
clazz,
        struct vm_method *mb;
        struct vm_class *class;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        check_null(clazz);
 
@@ -165,7 +165,7 @@ vm_jni_get_string_utf_chars(struct vm_jni_env *env, jobject 
string,
 {
        jbyte *array;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        if (!string)
                return NULL;
@@ -184,7 +184,7 @@ static void
 vm_release_string_utf_chars(struct vm_jni_env *env, jobject string,
                            const char *utf)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        free((char *)utf);
 }
@@ -192,7 +192,7 @@ vm_release_string_utf_chars(struct vm_jni_env *env, jobject 
string,
 static jint
 vm_jni_throw(struct vm_jni_env *env, jthrowable exception)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        if (!vm_object_is_instance_of(exception, vm_java_lang_Throwable))
                return -1;
@@ -206,7 +206,7 @@ vm_jni_throw_new(struct vm_jni_env *env, jclass clazz, 
const char *message)
 {
        struct vm_class *class;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        if (!clazz)
                return -1;
@@ -221,14 +221,14 @@ vm_jni_throw_new(struct vm_jni_env *env, jclass clazz, 
const char *message)
 
 static jthrowable vm_jni_exception_occurred(struct vm_jni_env *env)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        return exception_occurred();
 }
 
 static void vm_jni_exception_describe(struct vm_jni_env *env)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        if (exception_occurred())
                vm_print_exception(exception_occurred());
@@ -236,7 +236,7 @@ static void vm_jni_exception_describe(struct vm_jni_env 
*env)
 
 static void vm_jni_exception_clear(struct vm_jni_env *env)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        clear_exception();
 }
@@ -244,7 +244,7 @@ static void vm_jni_exception_clear(struct vm_jni_env *env)
 static void
 vm_jni_fatal_error(struct vm_jni_env *env, const char *msg)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        die("%s", msg);
 }
@@ -255,7 +255,7 @@ vm_jni_call_static_void_method(struct vm_jni_env *env, 
jclass clazz,
 {
        va_list args;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        va_start(args, methodID);
        vm_call_method_v(methodID, args);
@@ -268,7 +268,7 @@ static void
 vm_jni_call_static_void_method_v(struct vm_jni_env *env, jclass clazz,
                                 jmethodID methodID, va_list args)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
        vm_call_method_v(methodID, args);
 }
 
@@ -279,7 +279,7 @@ vm_jni_call_static_object_method(struct vm_jni_env *env, 
jclass clazz,
        jobject result;
        va_list args;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        va_start(args, methodID);
        result = (jobject) vm_call_method_v(methodID, args);
@@ -292,7 +292,7 @@ static jobject
 vm_jni_call_static_object_method_v(struct vm_jni_env *env, jclass clazz,
                                   jmethodID methodID, va_list args)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        return (jobject) vm_call_method_v(methodID, args);
 }
@@ -304,7 +304,7 @@ vm_jni_call_static_byte_method(struct vm_jni_env *env, 
jclass clazz,
        jbyte result;
        va_list args;
 
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        va_start(args, methodID);
        result = (jbyte) vm_call_method_v(methodID, args);
@@ -317,7 +317,7 @@ static jbyte
 vm_jni_call_static_byte_method_v(struct vm_jni_env *env, jclass clazz,
                                 jmethodID methodID, va_list args)
 {
-       vm_enter_jni_interface();
+       enter_vm_from_jni();
 
        return (jbyte) vm_call_method_v(methodID, args);
 }
diff --git a/vm/stack-trace.c b/vm/stack-trace.c
index 3aba177..45ad794 100644
--- a/vm/stack-trace.c
+++ b/vm/stack-trace.c
@@ -217,7 +217,7 @@ static int get_caller_stack_trace_elem(struct 
stack_trace_elem *elem)
                struct jni_stack_entry *tr =
                        &jni_stack[elem->jni_stack_index];
 
-               if (tr->jni_interface_frame == elem->frame) {
+               if (tr->vm_frame == elem->frame) {
                        elem->type = STACK_TRACE_ELEM_TYPE_JNI;
                        elem->is_native = false;
 
-- 
1.6.0.6


------------------------------------------------------------------------------
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to