PR149: Used wrong class loader.
[cacao.git] / src / vm / jit / stacktrace.cpp
index b51154ed2578fdb94b3068f88660ece7eb2bffa1..c59d05ac1bf7299add8422432dbd1cc7041da8ba 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/stacktrace.cpp - machine independent stacktrace system
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2011
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
    Copyright (C) 2009 Theobroma Systems Ltd.
 
@@ -33,6 +33,7 @@
 
 #include "vm/types.h"
 
+#include "arch.h"
 #include "md.h"
 
 #include "mm/gc.hpp"
@@ -138,7 +139,7 @@ void stacktrace_stackframeinfo_add(stackframeinfo_t* sfi, void* pv, void* sp, vo
                /* On S390 we use REG_RA as REG_ITMP3, so we have always to get
                   the RA from stack. */
 
-               framesize = *((u4 *) (((uintptr_t) pv) + FrameSize));
+               framesize = md_stacktrace_get_framesize(code);
 
                ra = md_stacktrace_get_returnaddress(sp, framesize);
 # else
@@ -149,7 +150,7 @@ void stacktrace_stackframeinfo_add(stackframeinfo_t* sfi, void* pv, void* sp, vo
                   the asm_vm_call_method special case. */
 
                if ((code == NULL) || !code_is_leafmethod(code)) {
-                       framesize = *((u4 *) (((uintptr_t) pv) + FrameSize));
+                       framesize = md_stacktrace_get_framesize(code);
 
                        ra = md_stacktrace_get_returnaddress(sp, framesize);
                }
@@ -306,7 +307,7 @@ static inline void stacktrace_stackframeinfo_next(stackframeinfo_t *tmpsfi)
  
        /* Get the current stack frame size. */
 
-       framesize = *((uint32_t *) (((intptr_t) pv) + FrameSize));
+       framesize = md_stacktrace_get_framesize(code);
 
        /* Get the RA of the current stack frame (RA to the parent Java
           method) if the current method is a non-leaf method.  Otherwise
@@ -357,7 +358,7 @@ static inline void stacktrace_stackframeinfo_next(stackframeinfo_t *tmpsfi)
        else
 #endif
                {
-#if defined(__I386__) || defined (__X86_64__) || defined (__M68K__)
+#if STACKFRMAE_RA_BETWEEN_FRAMES
                        sp = (void *) (((intptr_t) sp) + framesize + SIZEOF_VOID_P);
 #elif defined(__SPARC_64__)
                        /* already has the new sp */
@@ -903,6 +904,14 @@ classloader_t* stacktrace_first_nonnull_classloader(void)
                m  = tmpsfi.code->m;
                cl = class_get_classloader(m->clazz);
 
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+               /* NOTE: See hotspot/src/share/vm/runtime/vframe.cpp
+                  (vframeStreamCommon::skip_reflection_related_frames). */
+               if (class_issubclass(m->clazz, class_sun_reflect_MethodAccessorImpl) ||
+                       class_issubclass(m->clazz, class_sun_reflect_ConstructorAccessorImpl))
+                       continue;
+#endif
+
                if (cl != NULL)
                        return cl;
        }
@@ -1401,7 +1410,8 @@ stacktrace_t* stacktrace_get_of_thread(threadobject* t)
 
 /* stacktrace_print_of_thread **************************************************
 
-   Print the current stacktrace of the given thread.
+   Print the current stacktrace of the given thread. It will only work
+   for suspended threads.
 
    ARGUMENTS:
        t ... thread
@@ -1421,7 +1431,7 @@ void stacktrace_print_of_thread(threadobject *t)
 
        sfi = t->_stackframeinfo;
        
-       if (sfi == NULL) {
+       if (!t->suspended || sfi == NULL) {
                puts("\t<<No stacktrace available>>");
                fflush(stdout);
                return;