Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r87394:a6e7414f79c7
Date: 2016-09-26 17:52 +0200
http://bitbucket.org/pypy/pypy/changeset/a6e7414f79c7/

Log:    Fix what occurs near the limit MAX_STACK_DEPTH: I *think* it would
        appear to skip some frames then, in the JIT case

diff --git a/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h 
b/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
--- a/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
+++ b/rpython/rlib/rvmprof/src/vmprof_get_custom_offset.h
@@ -4,17 +4,18 @@
                                 long *current_pos_addr);
 
 
+#define MAX_INLINE_DEPTH  384
+
+
 static long vmprof_write_header_for_jit_addr(intptr_t *result, long n,
-                                             intptr_t ip, int max_depth)
+                                             intptr_t addr, int max_depth)
 {
 #ifdef PYPY_JIT_CODEMAP
     void *codemap;
     long current_pos = 0;
-    intptr_t ident;
+    intptr_t ident, local_stack[MAX_INLINE_DEPTH];
+    long m;
     long start_addr = 0;
-    intptr_t addr = (intptr_t)ip;
-    int start, k;
-    intptr_t tmp;
 
     codemap = pypy_find_codemap_at_addr(addr, &start_addr);
     if (codemap == NULL || n >= max_depth - 2)
@@ -25,24 +26,29 @@
     // in the middle
     result[n++] = VMPROF_ASSEMBLER_TAG;
     result[n++] = start_addr;
-    start = n;
-    while (n < max_depth) {
+
+    // build the list of code idents corresponding to the current
+    // position inside this particular piece of assembler.  If (very
+    // unlikely) we get more than MAX_INLINE_DEPTH recursion levels
+    // all inlined inside this single piece of assembler, then stop:
+    // there will be some missing frames then.  Otherwise, we need to
+    // first collect 'local_stack' and then write it to 'result' in the
+    // opposite order, stopping at 'max_depth'.  Previous versions of
+    // the code would write the oldest calls and then stop---whereas
+    // what we really need it to write the newest calls and then stop.
+    m = 0;
+    while (m < MAX_INLINE_DEPTH) {
         ident = pypy_yield_codemap_at_addr(codemap, addr, &current_pos);
         if (ident == -1)
             // finish
             break;
         if (ident == 0)
             continue; // not main codemap
+        local_stack[m++] = ident;
+    }
+    while (m > 0 && n < max_depth) {
         result[n++] = VMPROF_JITTED_TAG;
-        result[n++] = ident;
-    }
-    k = 1;
-
-    while (k < (n - start) / 2) {
-        tmp = result[start + k];
-        result[start + k] = result[n - k];
-        result[n - k] = tmp;
-        k += 2;
+        result[n++] = local_stack[--m];
     }
 #endif
     return n;
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to