[pypy-commit] pypy vmprof: - Fix rbisect to match the expectations of asmmmemmgr.

arigo noreply at buildbot.pypy.org
Tue Feb 10 13:45:47 CET 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: vmprof
Changeset: r75797:700eed63ab38
Date: 2015-02-10 13:44 +0100
http://bitbucket.org/pypy/pypy/changeset/700eed63ab38/

Log:	- Fix rbisect to match the expectations of asmmmemmgr.

	- Fix asmmemmgr to not kill a random jit_codemap entry every time
	free() is called on a block that does not contain code.

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
@@ -62,9 +62,12 @@
         self.jit_frame_depth_map = (self.jit_frame_depth_map[:jit_adr_start] +
                                     self.jit_frame_depth_map[jit_adr_stop:])
         # fix up codemap
-        codemap_adr = bisect_tuple(self.jit_codemap, start)
-        self.jit_codemap = (self.jit_codemap[:codemap_adr] +
-                            self.jit_codemap[codemap_adr + 1:])
+        # (there should only be zero or one codemap entry in that range,
+        # but still we use a range to distinguish between zero and one)
+        codemap_adr_start = bisect_tuple(self.jit_codemap, start)
+        codemap_adr_stop = bisect_tuple(self.jit_codemap, stop)
+        self.jit_codemap = (self.jit_codemap[:codemap_adr_start] +
+                            self.jit_codemap[codemap_adr_stop:])
 
     def open_malloc(self, minsize):
         """Allocate at least minsize bytes.  Returns (start, stop)."""
diff --git a/rpython/rlib/rbisect.py b/rpython/rlib/rbisect.py
--- a/rpython/rlib/rbisect.py
+++ b/rpython/rlib/rbisect.py
@@ -1,10 +1,12 @@
 
 def bisect(a, x):
+    """Return the index in the sorted list 'a' of 'x'.  If 'x' is not in 'a',
+    return the index where it can be inserted."""
     lo = 0
     hi = len(a)
     while lo < hi:
         mid = (lo+hi)//2
-        if x < a[mid]: hi = mid
+        if x <= a[mid]: hi = mid
         else: lo = mid+1
     return lo
 
@@ -14,6 +16,6 @@
     hi = len(a)
     while lo < hi:
         mid = (lo+hi)//2
-        if x < a[mid][0]: hi = mid
+        if x <= a[mid][0]: hi = mid
         else: lo = mid+1
     return lo
diff --git a/rpython/rlib/test/test_rbisect.py b/rpython/rlib/test/test_rbisect.py
--- a/rpython/rlib/test/test_rbisect.py
+++ b/rpython/rlib/test/test_rbisect.py
@@ -5,42 +5,42 @@
     cases = [
             ([], 1, 0),
             ([1], 0, 0),
-            ([1], 1, 1),
+            ([1], 1, 0),
             ([1], 2, 1),
             ([1, 1], 0, 0),
-            ([1, 1], 1, 2),
+            ([1, 1], 1, 0),
             ([1, 1], 2, 2),
             ([1, 1, 1], 0, 0),
-            ([1, 1, 1], 1, 3),
+            ([1, 1, 1], 1, 0),
             ([1, 1, 1], 2, 3),
             ([1, 1, 1, 1], 0, 0),
-            ([1, 1, 1, 1], 1, 4),
+            ([1, 1, 1, 1], 1, 0),
             ([1, 1, 1, 1], 2, 4),
             ([1, 2], 0, 0),
-            ([1, 2], 1, 1),
+            ([1, 2], 1, 0),
             ([1, 2], 1.5, 1),
-            ([1, 2], 2, 2),
+            ([1, 2], 2, 1),
             ([1, 2], 3, 2),
             ([1, 1, 2, 2], 0, 0),
-            ([1, 1, 2, 2], 1, 2),
+            ([1, 1, 2, 2], 1, 0),
             ([1, 1, 2, 2], 1.5, 2),
-            ([1, 1, 2, 2], 2, 4),
+            ([1, 1, 2, 2], 2, 2),
             ([1, 1, 2, 2], 3, 4),
             ([1, 2, 3], 0, 0),
-            ([1, 2, 3], 1, 1),
+            ([1, 2, 3], 1, 0),
             ([1, 2, 3], 1.5, 1),
-            ([1, 2, 3], 2, 2),
+            ([1, 2, 3], 2, 1),
             ([1, 2, 3], 2.5, 2),
-            ([1, 2, 3], 3, 3),
+            ([1, 2, 3], 3, 2),
             ([1, 2, 3], 4, 3),
             ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
-            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1),
+            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0),
             ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
-            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3),
+            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1),
             ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
-            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6),
+            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3),
             ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
-            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10),
+            ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6),
             ([1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10),
         ]
     for lst, elem, exp in cases:


More information about the pypy-commit mailing list