Author: Maciej Fijalkowski <[email protected]>
Branch: vmprof
Changeset: r75342:8e42a00ec79f
Date: 2015-01-15 14:35 +0200
http://bitbucket.org/pypy/pypy/changeset/8e42a00ec79f/
Log: try to improve _vmprof by using the jit address correctly from the
jit
diff --git a/pypy/module/_vmprof/src/get_custom_offset.c
b/pypy/module/_vmprof/src/get_custom_offset.c
new file mode 100644
--- /dev/null
+++ b/pypy/module/_vmprof/src/get_custom_offset.c
@@ -0,0 +1,13 @@
+
+long pypy_jit_start_addr();
+long pypy_jit_end_addr();
+long pypy_jit_stack_depth_at_loc(long);
+
+static ptrdiff_t vmprof_unw_get_custom_offset(void* ip) {
+ long ip_l = (long)ip;
+
+ if (ip < pypy_jit_start_addr() or ip > pypy_jit_end_addr()) {
+ return -1;
+ }
+ return pypy_jit_stack_depth_at_loc(ip);
+}
diff --git a/pypy/module/_vmprof/src/vmprof.c b/pypy/module/_vmprof/src/vmprof.c
--- a/pypy/module/_vmprof/src/vmprof.c
+++ b/pypy/module/_vmprof/src/vmprof.c
@@ -77,21 +77,7 @@
* ******************************************************
*/
-static void* jit_start = NULL;
-static void* jit_end = NULL;
-void vmprof_set_jit_range(void* start, void* end) {
- jit_start = start;
- jit_end = end;
-}
-
-static ptrdiff_t vmprof_unw_get_custom_offset(void* ip) {
- /* temporary hack to determine is this particular frame is JITted or not */
- if (ip >= jit_start && ip <= jit_end) {
- // it's probably a JIT frame
- return 19*8; // XXX
- }
- return -1; // not JITted code
-}
+#include "get_custom_offset.c"
typedef struct {
@@ -119,9 +105,9 @@
// setting the IP and SP in the cursor
vmprof_hacked_unw_cursor_t *cp2 = (vmprof_hacked_unw_cursor_t*)cp;
void* bp = (void*)sp + sp_offset;
- cp2->sp = bp+8; // the ret will pop a word, so the SP of the caller is
- // 8 bytes away from us
- cp2->ip = ((void**)bp)[0]; // the ret is on the top of the stack
+ cp2->sp = bp;
+ cp2->ip = ((void**)(bp - sizeof(void*))[0];
+ // the ret is on the top of the stack
return 1;
}
}
diff --git a/rpython/jit/backend/llsupport/asmmemmgr.py
b/rpython/jit/backend/llsupport/asmmemmgr.py
--- a/rpython/jit/backend/llsupport/asmmemmgr.py
+++ b/rpython/jit/backend/llsupport/asmmemmgr.py
@@ -5,6 +5,34 @@
from rpython.rlib.debug import debug_start, debug_print, debug_stop
from rpython.rlib.debug import have_debug_prints
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rlib.rbisect import bisect
+from rpython.rlib import rgc
+from rpython.rlib.entrypoint import entrypoint_lowlevel
+
+_memmngr = None # global reference so we can use @entrypoint :/
+
+@entrypoint_lowlevel('main', [lltype.Signed],
+ c_name='pypy_jit_stack_depth_at_loc')
[email protected]_collect
+def stack_depth_at_loc(loc):
+ global _memmngr
+
+ pos = bisect(_memmngr.jit_addr_map, loc)
+ if pos == 0 or pos == len(_memmngr.jit_addr_map):
+ return -1
+ return _memmngr.jit_frame_depth_map[pos-1]
+
+@entrypoint_lowlevel('main', [], c_name='pypy_jit_start_addr')
+def jit_start_addr(loc):
+ global _memmngr
+
+ return _memmngr.jit_addr_map[0]
+
+@entrypoint_lowlevel('main', [], c_name='pypy_jit_end_addr')
+def jit_end_addr(loc):
+ global _memmngr
+
+ return _memmngr.jit_addr_map[-1]
class AsmMemoryManager(object):
@@ -49,6 +77,13 @@
if r_uint is not None:
self.total_mallocs -= r_uint(stop - start)
self._add_free_block(start, stop)
+ # fix up jit_addr_map
+ jit_adr_start = bisect(self.jit_addr_map, start)
+ jit_adr_stop = bisect(self.jit_addr_map, stop)
+ self.jit_addr_map = (self.jit_addr_map[:jit_adr_start] +
+ self.jit_addr_map[jit_adr_stop:])
+ self.jit_frame_depth_map = (self.jit_frame_depth_map[:jit_adr_start] +
+ self.jit_frame_depth_map[jit_adr_stop:])
def open_malloc(self, minsize):
"""Allocate at least minsize bytes. Returns (start, stop)."""
@@ -157,15 +192,23 @@
def register_frame_depth_map(self, rawstart, frame_positions,
frame_assignments):
+ if not frame_positions:
+ return
if not self.jit_addr_map or rawstart > self.jit_addr_map[-1]:
start = len(self.jit_addr_map)
self.jit_addr_map += [0] * len(frame_positions)
self.jit_frame_depth_map += [0] * len(frame_positions)
- for i, pos in enumerate(frame_positions):
- self.jit_addr_map[i + start] = pos + rawstart
- self.jit_frame_depth_map[i + start] = frame_assignments[i]
else:
- xxx
+ start = bisect(self.jit_addr_map, rawstart)
+ self.jit_addr_map = (self.jit_addr_map[:start] +
+ [0] * len(frame_positions) +
+ self.jit_addr_map[start:])
+ self.jit_frame_depth_map = (self.jit_frame_depth_map[:start] +
+ [0] * len(frame_positions) +
+ self.jit_frame_depth_map[start:])
+ for i, pos in enumerate(frame_positions):
+ self.jit_addr_map[i + start] = pos + rawstart
+ self.jit_frame_depth_map[i + start] = frame_assignments[i]
def _delete(self):
"NOT_RPYTHON"
@@ -226,6 +269,9 @@
gcroot_markers = None
+ frame_positions = None
+ frame_assignments = None
+
def __init__(self, translated=None):
if translated is None:
translated = we_are_translated()
diff --git a/rpython/jit/backend/llsupport/test/test_asmmemmgr.py
b/rpython/jit/backend/llsupport/test/test_asmmemmgr.py
--- a/rpython/jit/backend/llsupport/test/test_asmmemmgr.py
+++ b/rpython/jit/backend/llsupport/test/test_asmmemmgr.py
@@ -2,6 +2,7 @@
from rpython.jit.backend.llsupport.asmmemmgr import AsmMemoryManager
from rpython.jit.backend.llsupport.asmmemmgr import MachineDataBlockWrapper
from rpython.jit.backend.llsupport.asmmemmgr import BlockBuilderMixin
+from rpython.jit.backend.llsupport import asmmemmgr
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib import debug
@@ -157,6 +158,7 @@
class FakeGcRootMap:
def register_asm_addr(self, retaddr, mark):
puts.append((retaddr, mark))
+
#
mc = BlockBuilderMixin()
mc.writechar('X')
@@ -262,3 +264,16 @@
md.done()
assert allblocks == [(1597, 1697), (1797, 1835)]
assert ops == [('free', 1835, 1897)]
+
+def test_find_jit_frame_depth():
+ mgr = AsmMemoryManager()
+ mgr.register_frame_depth_map(11, [0, 5, 10], [1, 2, 3])
+ mgr.register_frame_depth_map(30, [0, 5, 10], [4, 5, 6])
+ mgr.register_frame_depth_map(0, [0, 5, 10], [7, 8, 9])
+ asmmemmgr._memmngr = mgr
+ assert asmmemmgr.stack_depth_at_loc(13) == 1
+ assert asmmemmgr.stack_depth_at_loc(-3) == -1
+ assert asmmemmgr.stack_depth_at_loc(41) == -1
+ assert asmmemmgr.stack_depth_at_loc(5) == 8
+ assert asmmemmgr.stack_depth_at_loc(17) == 2
+ assert asmmemmgr.stack_depth_at_loc(38) == 5
diff --git a/rpython/jit/backend/x86/test/test_regloc.py
b/rpython/jit/backend/x86/test/test_regloc.py
--- a/rpython/jit/backend/x86/test/test_regloc.py
+++ b/rpython/jit/backend/x86/test/test_regloc.py
@@ -8,10 +8,18 @@
import py.test
class LocationCodeBuilder32(CodeBuilder32, LocationCodeBuilder):
- pass
+ def force_frame_size(self, frame_size):
+ pass
+
+ def stack_frame_size_delta(self, delta):
+ pass
class LocationCodeBuilder64(CodeBuilder64, LocationCodeBuilder):
- pass
+ def force_frame_size(self, frame_size):
+ pass
+
+ def stack_frame_size_delta(self, delta):
+ pass
cb32 = LocationCodeBuilder32
cb64 = LocationCodeBuilder64
diff --git a/rpython/jit/backend/x86/test/test_rx86.py
b/rpython/jit/backend/x86/test/test_rx86.py
--- a/rpython/jit/backend/x86/test/test_rx86.py
+++ b/rpython/jit/backend/x86/test/test_rx86.py
@@ -14,6 +14,12 @@
def getvalue(self):
return ''.join(self.buffer)
+ def force_frame_size(self, frame_size):
+ pass
+
+ def stack_frame_size_delta(self, delta):
+ pass
+
def assert_encodes_as(code_builder_cls, insn_name, args, expected_encoding):
s = code_builder_cls()
getattr(s, insn_name)(*args)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit