Author: Armin Rigo <[email protected]>
Branch: vlen-resume
Changeset: r82372:d18f72a15f77
Date: 2016-02-21 17:54 +0100
http://bitbucket.org/pypy/pypy/changeset/d18f72a15f77/

Log:    (fijal, cfbolz, arigo)

        in-progress

diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py
--- a/rpython/jit/metainterp/resume.py
+++ b/rpython/jit/metainterp/resume.py
@@ -27,6 +27,13 @@
         self.prev = prev
         self.boxes = boxes
 
+class TopSnapshot(Snapshot):
+    __slots__ = ('vable_boxes',)
+
+    def __init__(self, prev, boxes, vable_boxes):
+        Snapshot.__init__(self, prev, boxes)
+        self.vable_boxes = vable_boxes
+
 def combine_uint(index1, index2):
     assert 0 <= index1 < 65536
     assert 0 <= index2 < 65536
@@ -127,9 +134,8 @@
                        snapshot_storage):
     n = len(framestack) - 1
     if virtualizable_boxes is not None:
-        boxes = virtualref_boxes + virtualizable_boxes
-    else:
-        boxes = virtualref_boxes[:]
+        virtualizable_boxes = virtualizable_boxes[:]
+    virtualref_boxes = virtualref_boxes[:]
     if n >= 0:
         top = framestack[n]
         _ensure_parent_resumedata(framestack, n)
@@ -138,11 +144,12 @@
         snapshot_storage.rd_frame_info_list = frame_info_list
         snapshot = Snapshot(top.parent_resumedata_snapshot,
                             top.get_list_of_active_boxes(False))
-        snapshot = Snapshot(snapshot, boxes)
+        snapshot = TopSnapshot(snapshot, virtualref_boxes, virtualizable_boxes)
         snapshot_storage.rd_snapshot = snapshot
     else:
         snapshot_storage.rd_frame_info_list = None
-        snapshot_storage.rd_snapshot = Snapshot(None, boxes)
+        snapshot_storage.rd_snapshot = TopSnapshot(None, virtualref_boxes,
+                                                   virtualizable_boxes)
 
 PENDINGFIELDSTRUCT = lltype.Struct('PendingField',
                                    ('lldescr', OBJECTPTR),
@@ -200,10 +207,12 @@
         self.v = 0
 
     def count_boxes(self, lst):
-        c = 0
+        snapshot = lst[0]
+        assert isinstance(snapshot, TopSnapshot)
+        c = len(snapshot.vable_boxes)
         for snapshot in lst:
             c += len(snapshot.boxes)
-        c += 2 * (len(lst) - 1)
+        c += 2 * (len(lst) - 1) + 1
         return c
 
     def append(self, item):
@@ -294,13 +303,11 @@
             state.append(tagged)
         state.n = n
         state.v = v
-        state.position -= length + 2
 
-    def number(self, optimizer, snapshot, frameinfo):
+    def number(self, optimizer, topsnapshot, frameinfo):
         # flatten the list
-        vref_snapshot = snapshot
-        cur = snapshot.prev
-        snapshot_list = [vref_snapshot]
+        cur = topsnapshot.prev
+        snapshot_list = [topsnapshot]
         framestack_list = []
         while cur:
             framestack_list.append(frameinfo)
@@ -311,19 +318,29 @@
 
         # we want to number snapshots starting from the back, but ending
         # with a forward list
-        for i in range(len(snapshot_list) - 1, -1, -1):
-            state.position -= len(snapshot_list[i].boxes)
-            if i != 0:
-                frameinfo = framestack_list[i - 1]
-                jitcode_pos, pc = unpack_uint(frameinfo.packed_jitcode_pc)
-                state.position -= 2
-                state.append(rffi.cast(rffi.SHORT, jitcode_pos))
-                state.append(rffi.cast(rffi.SHORT, pc))
+        for i in range(len(snapshot_list) - 1, 0, -1):
+            state.position -= len(snapshot_list[i].boxes) + 2
+            frameinfo = framestack_list[i - 1]
+            jitcode_pos, pc = unpack_uint(frameinfo.packed_jitcode_pc)
+            state.append(rffi.cast(rffi.SHORT, jitcode_pos))
+            state.append(rffi.cast(rffi.SHORT, pc))
             self._number_boxes(snapshot_list[i].boxes, optimizer, state)
+            state.position -= len(snapshot_list[i].boxes) + 2
 
-        numb = resumecode.create_numbering(state.current,
-                                           len(vref_snapshot.boxes))
+        assert isinstance(topsnapshot, TopSnapshot)
+        special_boxes_size = (len(topsnapshot.vable_boxes) +
+                              1 + len(topsnapshot.boxes))
+        assert state.position == special_boxes_size
 
+        state.position = 0
+        self._number_boxes(topsnapshot.vable_boxes, optimizer, state)
+        n = len(topsnapshot.boxes)
+        assert not (n & 1)
+        state.append(rffi.cast(rffi.SHORT, n >> 1))
+        self._number_boxes(topsnapshot.boxes, optimizer, state)
+        assert state.position == special_boxes_size
+
+        numb = resumecode.create_numbering(state.current)
         return numb, state.liveboxes, state.v
         
     def forget_numberings(self):
@@ -1146,8 +1163,9 @@
             virtualizable_boxes = self.consume_virtualizable_boxes(vinfo)
             end = first_snapshot_size - len(virtualizable_boxes)
         elif ginfo is not None:
+            xxxxxx
             item, self.cur_index = resumecode.numb_next_item(self.numb,
-                first_snapshot_size - 1)xxxxxxxxxxxxx
+                first_snapshot_size - 1)
             virtualizable_boxes = [self.decode_ref(item)]
             end = first_snapshot_size - 1
         else:
@@ -1483,7 +1501,8 @@
             if vinfo is not None:
                 end_vref = self.consume_vable_info(vinfo)
             if ginfo is not None:
-                end_vref -= 1         xxxxxxxxxxxxxxx
+                end_vref -= 1
+                xxxxxxxxxxxxxxx
             self.consume_virtualref_info(vrefinfo, end_vref) 
         self.cur_index = rffi.cast(lltype.Signed, 
self.numb.first_snapshot_size)
 
diff --git a/rpython/jit/metainterp/resumecode.py 
b/rpython/jit/metainterp/resumecode.py
--- a/rpython/jit/metainterp/resumecode.py
+++ b/rpython/jit/metainterp/resumecode.py
@@ -1,44 +1,30 @@
 
 """ Resume bytecode. It goes as following:
 
-<numb> <numb> <pc> <jitcode> <numb> <numb> <numb> <pc> <jitcode>
+  [<virtualizable object> <numb> <numb> <numb>]    if vinfo is not None
+   -OR-
+  [<ginfo object>]                                 if ginfo is not None
+   -OR-
+  []                                               if both are None
 
-until the length of the array.
+  [<length> <virtual> <vref> <virtual> <vref>]     for virtualrefs
 
-The interface is only create_numbering/numb_next_item, but! there is a trick
-that uses first_snapshot_size + some knowledge about inside to decode
-virtualref/virtualizable_fields/virtualizable in that order in resume.py.
+  [<pc> <jitcode> <numb> <numb> <numb>]            the frames
+  [<pc> <jitcode> <numb> <numb>]
+  ...
 
-If the algorithm changes, the part about how to find where virtualizable
-and virtualrefs are to be found
+  until the length of the array.
 """
 
 from rpython.rtyper.lltypesystem import rffi, lltype
 
 NUMBERINGP = lltype.Ptr(lltype.GcForwardReference())
 NUMBERING = lltype.GcStruct('Numbering',
-#                            ('prev', NUMBERINGP),
-#                            ('prev_index', rffi.USHORT),
-                            ('first_snapshot_size', rffi.USHORT), # ugh, ugly
                             ('code', lltype.Array(rffi.UCHAR)))
 NUMBERINGP.TO.become(NUMBERING)
 NULL_NUMBER = lltype.nullptr(NUMBERING)
 
-# this is the actually used version
-
-## def create_numbering(lst, first_snapshot_size):
-##     numb = lltype.malloc(NUMBERING, len(lst))
-##     for i in range(len(lst)):
-##         numb.code[i] = rffi.cast(rffi.SHORT, lst[i])
-##     numb.first_snapshot_size = rffi.cast(rffi.USHORT, first_snapshot_size)
-##     return numb
-
-## def numb_next_item(numb, index):
-##     return rffi.cast(lltype.Signed, numb.code[index]), index + 1
-
-# this is the version that can be potentially used
-
-def create_numbering(lst, first_snapshot_size):
+def create_numbering(lst):
     result = []
     for item in lst:
         item *= 2
@@ -58,7 +44,6 @@
             result.append(rffi.cast(rffi.UCHAR, item >> 14))
 
     numb = lltype.malloc(NUMBERING, len(result))
-    numb.first_snapshot_size = rffi.cast(rffi.USHORT, first_snapshot_size)
     for i in range(len(result)):
         numb.code[i] = result[i]
     return numb
diff --git a/rpython/jit/metainterp/test/test_resume.py 
b/rpython/jit/metainterp/test/test_resume.py
--- a/rpython/jit/metainterp/test/test_resume.py
+++ b/rpython/jit/metainterp/test/test_resume.py
@@ -10,7 +10,7 @@
      VArrayInfoNotClear, VStrPlainInfo, VStrConcatInfo, VStrSliceInfo,\
      VUniPlainInfo, VUniConcatInfo, VUniSliceInfo, Snapshot, FrameInfo,\
      capture_resumedata, ResumeDataLoopMemo, UNASSIGNEDVIRTUAL, INT,\
-     annlowlevel, PENDINGFIELDSP, unpack_uint, TAG_CONST_OFFSET
+     annlowlevel, PENDINGFIELDSP, unpack_uint, TAG_CONST_OFFSET, TopSnapshot
 from rpython.jit.metainterp.resumecode import unpack_numbering,\
      create_numbering, NULL_NUMBER
 
@@ -278,9 +278,7 @@
     assert bh.written_f == expected_f
 
 
-def Numbering(nums):
-    numb = create_numbering(nums, 0)
-    return numb
+Numbering = create_numbering
 
 def tagconst(i):
     return tag(i + TAG_CONST_OFFSET, TAGCONST)
@@ -610,7 +608,8 @@
     assert unpack_uint(frame_info_list.packed_jitcode_pc) == (2, 15)
     
     snapshot = storage.rd_snapshot
-    assert snapshot.boxes == vrs + vbs      # in the same list
+    assert snapshot.boxes == vrs
+    assert snapshot.vable_boxes == vbs
 
     snapshot = snapshot.prev
     assert snapshot.prev is fs[2].parent_resumedata_snapshot
@@ -904,9 +903,9 @@
     env = [b1, c1, b2, b1, c2]
     snap = Snapshot(None, env)
     env1 = [c3, b3, b1, c1]
-    snap1 = Snapshot(snap, env1)
+    snap1 = TopSnapshot(snap, env1, [])
     env2 = [c3, b3, b1, c3]
-    snap2 = Snapshot(snap, env2)
+    snap2 = TopSnapshot(snap, env2, [])
 
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
     frameinfo = FrameInfo(None, FakeJitCode("jitcode", 0), 0)
@@ -916,10 +915,11 @@
 
     assert liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
                          b3: tag(2, TAGBOX)}
-    base = [tag(0, TAGBOX), tag(1, TAGINT), tag(1, TAGBOX), tag(0, TAGBOX), 
tag(2, TAGINT)]
+    base = [0, 0, tag(0, TAGBOX), tag(1, TAGINT),
+            tag(1, TAGBOX), tag(0, TAGBOX), tag(2, TAGINT)]
 
-    assert unpack_numbering(numb) == [
-          tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(1, TAGINT), 0, 
0] + base
+    assert unpack_numbering(numb) == [2, tag(3, TAGINT), tag(2, TAGBOX),
+                                      tag(0, TAGBOX), tag(1, TAGINT)] + base
 
     numb2, liveboxes2, v = memo.number(FakeOptimizer(), snap2, frameinfo)
     assert v == 0
@@ -927,11 +927,11 @@
     assert liveboxes2 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
                          b3: tag(2, TAGBOX)}
     assert liveboxes2 is not liveboxes
-    assert unpack_numbering(numb2) == [
-         tag(3, TAGINT), tag(2, TAGBOX), tag(0, TAGBOX), tag(3, TAGINT), 0, 0] 
+ base
+    assert unpack_numbering(numb2) == [2, tag(3, TAGINT), tag(2, TAGBOX),
+                                       tag(0, TAGBOX), tag(3, TAGINT)] + base
 
     env3 = [c3, b3, b1, c3]
-    snap3 = Snapshot(snap, env3)
+    snap3 = TopSnapshot(snap, env3, [])
 
     class FakeVirtualInfo(info.AbstractInfo):
         def __init__(self, virt):
@@ -946,13 +946,12 @@
     assert v == 0
     
     assert liveboxes3 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX)}
-    assert unpack_numbering(numb3) == [tag(3, TAGINT), tag(4, TAGINT),
-                                       tag(0, TAGBOX),
-                                       tag(3, TAGINT), 0, 0] + base
+    assert unpack_numbering(numb3) == [2, tag(3, TAGINT), tag(4, TAGINT),
+                                       tag(0, TAGBOX), tag(3, TAGINT)] + base
 
     # virtual
     env4 = [c3, b4, b1, c3]
-    snap4 = Snapshot(snap, env4)
+    snap4 = TopSnapshot(snap, env4, [])
 
     b4.set_forwarded(FakeVirtualInfo(True))
     numb4, liveboxes4, v = memo.number(FakeOptimizer(), snap4, frameinfo)
@@ -960,11 +959,11 @@
     
     assert liveboxes4 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
                           b4: tag(0, TAGVIRTUAL)}
-    assert unpack_numbering(numb4) == [tag(3, TAGINT), tag(0, TAGVIRTUAL),
-                                tag(0, TAGBOX), tag(3, TAGINT), 0, 0] + base
+    assert unpack_numbering(numb4) == [2, tag(3, TAGINT), tag(0, TAGVIRTUAL),
+                                       tag(0, TAGBOX), tag(3, TAGINT)] + base
 
     env5 = [b1, b4, b5]
-    snap5 = Snapshot(snap4, env5)
+    snap5 = TopSnapshot(snap4, [], env5)
 
     b4.set_forwarded(FakeVirtualInfo(True))
     b5.set_forwarded(FakeVirtualInfo(True))
@@ -974,8 +973,11 @@
     
     assert liveboxes5 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
                           b4: tag(0, TAGVIRTUAL), b5: tag(1, TAGVIRTUAL)}
-    assert unpack_numbering(numb5) == [tag(0, TAGBOX), tag(0, TAGVIRTUAL),
-                           tag(1, TAGVIRTUAL), 2, 1] + unpack_numbering(numb4)
+    assert unpack_numbering(numb5) == [
+        tag(0, TAGBOX), tag(0, TAGVIRTUAL), tag(1, TAGVIRTUAL),
+        0,
+        2, 1, tag(3, TAGINT), tag(0, TAGVIRTUAL), tag(0, TAGBOX), tag(3, 
TAGINT)
+        ] + base
 
 def test_ResumeDataLoopMemo_number_boxes():
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
diff --git a/rpython/jit/metainterp/test/test_resumecode.py 
b/rpython/jit/metainterp/test/test_resumecode.py
--- a/rpython/jit/metainterp/test/test_resumecode.py
+++ b/rpython/jit/metainterp/test/test_resumecode.py
@@ -15,15 +15,15 @@
         [13000, 12000, 10000, 256, 255, 254, 257, -3, -1000]
     ]
     for l in examples:
-        n = create_numbering(l, 0)
+        n = create_numbering(l)
         assert unpack_numbering(n) == l
 
 @given(strategies.lists(strategies.integers(-2**15, 2**15-1)))
 def test_roundtrip(l):
-    n = create_numbering(l, 0)
+    n = create_numbering(l)
     assert unpack_numbering(n) == l
 
 @given(strategies.lists(strategies.integers(-2**15, 2**15-1)))
 def test_compressing(l):
-    n = create_numbering(l, 0)
+    n = create_numbering(l)
     assert len(n.code) <= len(l) * 3
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to