* src/vm/jit/x86_64/asmpart.S (asm_abstractmethoderror): Keep stack aligned.
[cacao.git] / src / vm / jit / methodtree.c
index 2e586d173ee76eb73a53e0289fe9ca92adee8867..e8dd331aaf95d2673900f8fcd9809908e2c90561 100644 (file)
 
 #include <stdint.h>
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
 #include "toolbox/avl.h"
 
 #include "vm/jit/asmpart.h"
 #include "vm/jit/methodtree.h"
+#include "vm/jit/stacktrace.hpp"
 
 
 /* methodtree_element *********************************************************/
@@ -174,6 +175,10 @@ void *methodtree_find(void *pc)
 {
        void *pv;
 
+       // This flag indicates whether a methodtree lookup is failing. We need
+       // to keep track of this to avoid endless loops during stacktrace creation.
+       static bool methodtree_find_failing = false;
+
        /* Try to find a method. */
 
        pv = methodtree_find_nocheck(pc);
@@ -194,13 +199,16 @@ void *methodtree_find(void *pc)
                log_println("PC=0x%08x", pc);
 #endif
                log_println("");
-               assert(0);
-               log_println("Dumping the current stacktrace:");
 
-#if defined(ENABLE_THREADS)
-               /* XXX michi: This should be available even without threads! */
-               threads_print_stacktrace();
-#endif
+               // Detect and avoid endless loops.
+               if (methodtree_find_failing)
+                       vm_abort("Exiting without stacktrace...");
+               else
+                       methodtree_find_failing = true;
+
+               // Actually try to dump a stacktrace.
+               log_println("Dumping the current stacktrace:");
+               stacktrace_print_current();
 
                vm_abort("Exiting...");
        }