Signed-off-by: Tomek Grabiec <tgrab...@gmail.com>
---
 vm/jato.c |   50 +++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/vm/jato.c b/vm/jato.c
index 0f13dc6..4d959cd 100644
--- a/vm/jato.c
+++ b/vm/jato.c
@@ -100,24 +100,56 @@ static struct vm_object 
*native_vmstackwalker_getclasscontext(void)
 {
        struct stack_trace_elem st_elem;
        struct compilation_unit *cu;
-       struct vm_class *class;
        struct vm_object *res;
+       int nr_to_skip;
+       int depth;
+       int idx;
+       int i;
 
        init_stack_trace_elem_current(&st_elem);
+       depth = get_java_stack_trace_depth(&st_elem);
 
-       if (stack_trace_elem_next_java(&st_elem))
-               return NULL;
+       /* Skip call to VMStackWalker.getClassContext() */
+       depth -= 2;
+       stack_trace_elem_next_java(&st_elem);
+       stack_trace_elem_next_java(&st_elem);
 
-       cu = jit_lookup_cu(st_elem.addr);
-       if (!cu) {
-               NOT_IMPLEMENTED;
+       res = vm_object_alloc_array(vm_array_of_java_lang_Class, depth);
+       if (!res) {
+               signal_new_exception(vm_java_lang_OutOfMemoryError, NULL);
                return NULL;
        }
 
-       class = cu->method->class;
+       nr_to_skip = 0;
+       idx = 0;
+
+       for (i = 0; i < depth; i++, stack_trace_elem_next_java(&st_elem)) {
+               cu = jit_lookup_cu(st_elem.addr);
+               if (!cu)
+                       error("no compilation_unit mapping for %lx", 
st_elem.addr);
+
+               struct vm_class *vmc = cu->method->class;
+
+               if (vmc == vm_java_lang_reflect_Method &&
+                   !strcmp(cu->method->name, "invoke")) {
+                       /*
+                        * We should skip all Method.invoke() frames
+                        * here as stated in comment for
+                        * VMStackWalker.getClassContext().
+                        */
+                       nr_to_skip++;
+                       continue;
+               }
+
+               if (vm_class_ensure_init(vmc))
+                       return NULL;
+
+               printf("%d: %s.%s\n", idx, vmc->name, cu->method->name);
+
+               array_set_field_object(res, idx++, vmc->object);
+       }
 
-       res = vm_object_alloc_array(vm_java_lang_Class, 1);
-       array_set_field_object(res, 0, class->object);
+       res->array_length -= nr_to_skip;
 
        return res;
 }
-- 
1.6.0.6


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to