Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: 
Changeset: r87724:b9ac5226fa5c
Date: 2016-10-12 17:45 +0200
http://bitbucket.org/pypy/pypy/changeset/b9ac5226fa5c/

Log:    merge default

diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -734,7 +734,7 @@
         modifier = resume.ResumeDataVirtualAdder(self, descr, op, self.trace,
                                                  self.resumedata_memo)
         try:
-            newboxes = modifier.finish(self, pendingfields)
+            newboxes = modifier.finish(pendingfields)
             if (newboxes is not None and
                 len(newboxes) > self.metainterp_sd.options.failargs_limit):
                 raise resume.TagOverflow
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
@@ -165,7 +165,7 @@
 class NumberingState(object):
     def __init__(self, size):
         self.liveboxes = {}
-        self.current = [0] * size
+        self.current = [rffi.cast(rffi.SHORT, 0)] * size
         self._pos = 0
         self.num_boxes = 0
         self.num_virtuals = 0
@@ -179,6 +179,9 @@
         assert rffi.cast(lltype.Signed, short) == item
         return self.append_short(short)
 
+    def create_numbering(self):
+        return resumecode.create_numbering(self.current)
+
 class ResumeDataLoopMemo(object):
 
     def __init__(self, metainterp_sd):
@@ -229,12 +232,12 @@
 
     # env numbering
 
-    def _number_boxes(self, iter, arr, optimizer, state):
+    def _number_boxes(self, iter, arr, optimizer, numb_state):
         """ Number boxes from one snapshot
         """
-        num_boxes = state.num_boxes
-        num_virtuals = state.num_virtuals
-        liveboxes = state.liveboxes
+        num_boxes = numb_state.num_boxes
+        num_virtuals = numb_state.num_virtuals
+        liveboxes = numb_state.liveboxes
         for item in arr:
             box = iter.get(rffi.cast(lltype.Signed, item))
             box = optimizer.get_box_replacement(box)
@@ -258,34 +261,34 @@
                     tagged = tag(num_boxes, TAGBOX)
                     num_boxes += 1
                 liveboxes[box] = tagged
-            state.append_short(tagged)
-        state.num_boxes = num_boxes
-        state.num_virtuals = num_virtuals
+            numb_state.append_short(tagged)
+        numb_state.num_boxes = num_boxes
+        numb_state.num_virtuals = num_virtuals
 
     def number(self, optimizer, position, trace):
         snapshot_iter = trace.get_snapshot_iter(position)
-        state = NumberingState(snapshot_iter.size)
+        numb_state = NumberingState(snapshot_iter.size)
 
         arr = snapshot_iter.vable_array
 
-        state.append_int(len(arr))
-        self._number_boxes(snapshot_iter, arr, optimizer, state)
+        numb_state.append_int(len(arr))
+        self._number_boxes(snapshot_iter, arr, optimizer, numb_state)
 
         arr = snapshot_iter.vref_array
         n = len(arr)
         assert not (n & 1)
-        state.append_int(n >> 1)
+        numb_state.append_int(n >> 1)
 
-        self._number_boxes(snapshot_iter, arr, optimizer, state)
+        self._number_boxes(snapshot_iter, arr, optimizer, numb_state)
 
         for snapshot in snapshot_iter.framestack:
             jitcode_index, pc = snapshot_iter.unpack_jitcode_pc(snapshot)
-            state.append_int(jitcode_index)
-            state.append_int(pc)
-            self._number_boxes(snapshot_iter, snapshot.box_array, optimizer, 
state)
+            numb_state.append_int(jitcode_index)
+            numb_state.append_int(pc)
+            self._number_boxes(
+                    snapshot_iter, snapshot.box_array, optimizer, numb_state)
 
-        numb = resumecode.create_numbering(state.current)
-        return numb, state.liveboxes, state.num_virtuals
+        return numb_state
 
 
     # caching for virtuals and boxes inside them
@@ -418,7 +421,8 @@
         _, tagbits = untag(tagged)
         return tagbits == TAGVIRTUAL
 
-    def finish(self, optimizer, pending_setfields=[]):
+    def finish(self, pending_setfields=[]):
+        optimizer = self.optimizer
         # compute the numbering
         storage = self.storage
         # make sure that nobody attached resume data to this guard yet
@@ -426,12 +430,12 @@
         resume_position = self.guard_op.rd_resume_position
         assert resume_position >= 0
         # count stack depth
-        numb, liveboxes_from_env, num_virtuals = self.memo.number(optimizer,
-            resume_position, self.optimizer.trace)
-        self.liveboxes_from_env = liveboxes_from_env
+        numb_state = self.memo.number(optimizer,
+            resume_position, optimizer.trace)
+        self.liveboxes_from_env = liveboxes_from_env = numb_state.liveboxes
+        num_virtuals = numb_state.num_virtuals
         self.liveboxes = {}
-        storage.rd_numb = numb
-        
+
         # collect liveboxes and virtuals
         n = len(liveboxes_from_env) - num_virtuals
         liveboxes = [None] * n
@@ -467,6 +471,7 @@
         self._number_virtuals(liveboxes, optimizer, num_virtuals)
         self._add_pending_fields(optimizer, pending_setfields)
 
+        storage.rd_numb = numb_state.create_numbering()
         storage.rd_consts = self.memo.consts
         return liveboxes[:]
 
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
@@ -551,8 +551,8 @@
           FakeFrame("code2", 9, c3, b2)]
     capture_resumedata(fs, None, [], storage)
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
-    modifier = ResumeDataVirtualAdder(None, storage, storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer())
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(), storage, storage, memo)
+    liveboxes = modifier.finish()
     metainterp = MyMetaInterp()
 
     b1t, b2t, b3t = [BoxInt(), InputArgRef(), BoxInt()]
@@ -575,8 +575,8 @@
           FakeFrame("code2", 9, c3, b2)]
     capture_resumedata(fs, [b4], [], storage)
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
-    modifier = ResumeDataVirtualAdder(None, storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer({}))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer({}), storage, memo)
+    liveboxes = modifier.finish()
     metainterp = MyMetaInterp()
 
     b1t, b2t, b3t, b4t = [BoxInt(), InputArgRef(), BoxInt(), InputArgRef()]
@@ -604,11 +604,11 @@
     capture_resumedata(fs, None, [], storage2)
     
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
-    modifier = ResumeDataVirtualAdder(None, storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer({}))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer({}), storage, memo)
+    liveboxes = modifier.finish()
 
-    modifier = ResumeDataVirtualAdder(None, storage2, memo)
-    liveboxes2 = modifier.finish(FakeOptimizer({}))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer({}), storage2, memo)
+    liveboxes2 = modifier.finish()
 
     metainterp = MyMetaInterp()
 
@@ -668,8 +668,8 @@
     
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
     values = {b2: virtual_value(b2, b5, c4)}
-    modifier = ResumeDataVirtualAdder(storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer(values))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(values), storage, memo)
+    liveboxes = modifier.finish()
     assert len(storage.rd_virtuals) == 1
     assert storage.rd_virtuals[0].fieldnums == [tag(-1, TAGBOX),
                                                 tag(0, TAGCONST)]
@@ -679,8 +679,8 @@
     v6.setfield(LLtypeMixin.nextdescr, v6)    
     values = {b2: virtual_value(b2, b4, v6), b6: v6}
     memo.clear_box_virtual_numbers()
-    modifier = ResumeDataVirtualAdder(storage2, memo)
-    liveboxes2 = modifier.finish(FakeOptimizer(values))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(values), storage2, memo)
+    liveboxes2 = modifier.finish()
     assert len(storage2.rd_virtuals) == 2    
     assert storage2.rd_virtuals[0].fieldnums == [tag(len(liveboxes2)-1, 
TAGBOX),
                                                  tag(-1, TAGVIRTUAL)]
@@ -725,8 +725,8 @@
     
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())
     values = {b2: virtual_value(b2, b5, c4)}
-    modifier = ResumeDataVirtualAdder(storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer(values))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(values), storage, memo)
+    liveboxes = modifier.finish()
     assert len(storage.rd_virtuals) == 1
     assert storage.rd_virtuals[0].fieldnums == [tag(-1, TAGBOX),
                                                 tag(0, TAGCONST)]
@@ -735,8 +735,8 @@
     fs = [FakeFrame("code0", 0, b1, b4, b2)]
     capture_resumedata(fs, None, [], storage2)
     values[b4] = virtual_value(b4, b6, c4)
-    modifier = ResumeDataVirtualAdder(storage2, memo)
-    liveboxes = modifier.finish(FakeOptimizer(values))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(values), storage2, memo)
+    liveboxes = modifier.finish()
     assert len(storage2.rd_virtuals) == 2
     assert storage2.rd_virtuals[1].fieldnums == 
storage.rd_virtuals[0].fieldnums
     assert storage2.rd_virtuals[1] is storage.rd_virtuals[0]
@@ -754,8 +754,8 @@
     v2 = virtual_value(b2, b3, v1)
     v1.setfield(LLtypeMixin.nextdescr, v2)
     values = {b1: v1, b2: v2}
-    modifier = ResumeDataVirtualAdder(storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer(values))
+    modifier = ResumeDataVirtualAdder(FakeOptimizer(values), storage, memo)
+    liveboxes = modifier.finish()
     assert liveboxes == [b3]
     assert len(storage.rd_virtuals) == 2
     assert storage.rd_virtuals[0].fieldnums == [tag(-1, TAGBOX),
@@ -849,11 +849,12 @@
 
     iter = t.get_iter()
     b1, b2, b3, b4, b5 = iter.inputargs
-    numb, liveboxes, v = memo.number(FakeOptimizer(), 0, iter)
-    assert v == 0
+    numb_state = memo.number(FakeOptimizer(), 0, iter)
+    numb = numb_state.create_numbering()
+    assert numb_state.num_virtuals == 0
 
-    assert liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
-                         b3: tag(2, TAGBOX)}
+    assert numb_state.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
+                                    b3: tag(2, TAGBOX)}
     base = [0, 0, tag(0, TAGBOX), tag(1, TAGINT),
             tag(1, TAGBOX), tag(0, TAGBOX), tag(2, TAGINT)]
 
@@ -864,12 +865,13 @@
                                   False, [], [])
     snap2.prev = snap
 
-    numb2, liveboxes2, v = memo.number(FakeOptimizer(), 1, iter)
-    assert v == 0
-    
-    assert liveboxes2 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
-                         b3: tag(2, TAGBOX)}
-    assert liveboxes2 is not liveboxes
+    numb_state2 = memo.number(FakeOptimizer(), 1, iter)
+    numb2 = numb_state2.create_numbering()
+    assert numb_state2.num_virtuals == 0
+
+    assert numb_state2.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
+                                     b3: tag(2, TAGBOX)}
+    assert numb_state2.liveboxes is not numb_state.liveboxes
     assert unpack_numbering(numb2) == [0, 0] + base + [0, 2, tag(3, TAGINT), 
tag(2, TAGBOX),
                                        tag(0, TAGBOX), tag(3, TAGINT)]
 
@@ -887,10 +889,11 @@
 
     # renamed
     b3.set_forwarded(c4)
-    numb3, liveboxes3, v = memo.number(FakeOptimizer(), 2, iter)
-    assert v == 0
+    numb_state3 = memo.number(FakeOptimizer(), 2, iter)
+    numb3 = numb_state3.create_numbering()
+    assert numb_state3.num_virtuals == 0
     
-    assert liveboxes3 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX)}
+    assert numb_state3.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX)}
     assert unpack_numbering(numb3) == ([0, 2, tag(3, TAGINT), tag(4, TAGINT),
                                        tag(0, TAGBOX), tag(3, TAGINT)] +
                                        base + [0, 2])
@@ -902,11 +905,12 @@
     snap4.prev = snap
 
     b4.set_forwarded(FakeVirtualInfo(True))
-    numb4, liveboxes4, v = memo.number(FakeOptimizer(), 3, iter)
-    assert v == 1
+    numb_state4 = memo.number(FakeOptimizer(), 3, iter)
+    numb4 = numb_state4.create_numbering()
+    assert numb_state4.num_virtuals == 1
     
-    assert liveboxes4 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
-                          b4: tag(0, TAGVIRTUAL)}
+    assert numb_state4.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
+                                     b4: tag(0, TAGVIRTUAL)}
     assert unpack_numbering(numb4) == [0, 2, tag(3, TAGINT), tag(0, 
TAGVIRTUAL),
                                        tag(0, TAGBOX), tag(3, TAGINT)] + base 
+ [0, 2]
 
@@ -920,11 +924,12 @@
 
     b4.set_forwarded(FakeVirtualInfo(True))
     b5.set_forwarded(FakeVirtualInfo(True))
-    numb5, liveboxes5, v = memo.number(FakeOptimizer(), 4, iter)
-    assert v == 2
-    
-    assert liveboxes5 == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
-                          b4: tag(0, TAGVIRTUAL), b5: tag(1, TAGVIRTUAL)}
+    numb_state5 = memo.number(FakeOptimizer(), 4, iter)
+    numb5 = numb_state5.create_numbering()
+    assert numb_state5.num_virtuals == 2
+
+    assert numb_state5.liveboxes == {b1: tag(0, TAGBOX), b2: tag(1, TAGBOX),
+                                     b4: tag(0, TAGVIRTUAL), b5: tag(1, 
TAGVIRTUAL)}
     assert unpack_numbering(numb5) == [
         3, tag(0, TAGBOX), tag(0, TAGVIRTUAL), tag(1, TAGVIRTUAL),
         0] + base + [
@@ -941,8 +946,9 @@
     i = t.get_iter()
     t.create_top_snapshot(FakeJitCode("", 0), 0, Frame(lst), False, [], [])
     memo = ResumeDataLoopMemo(metainterp_sd)
-    num, liveboxes, v = memo.number(FakeOptimizer(), 0, i)
-    l = unpack_numbering(num)
+    numb_state = memo.number(FakeOptimizer(), 0, i)
+    numb = numb_state.create_numbering()
+    l = unpack_numbering(numb)
     assert l[0] == 0
     assert l[1] == 0
     assert l[2] == 0
@@ -951,7 +957,7 @@
     for i, item in enumerate(lst):
         v, tag = untag(l[i + 4])
         if tag == TAGBOX:
-            assert l[i + 4] == liveboxes[mapping[item]]
+            assert l[i + 4] == numb_state.liveboxes[mapping[item]]
         elif tag == TAGCONST:
             assert memo.consts[v].getint() == item.getint()
         elif tag == TAGINT:
@@ -1059,7 +1065,7 @@
     memo = ResumeDataLoopMemo(metainterp_sd)  
     i = t.get_iter()
     modifier = ResumeDataVirtualAdder(FakeOptimizer(i), storage, storage, i, 
memo)
-    liveboxes = modifier.finish(FakeOptimizer(i))
+    liveboxes = modifier.finish()
     cpu = MyCPU([])
     reader = ResumeDataDirectReader(MyMetaInterp(cpu), storage, "deadframe")
     reader.consume_vref_and_vable(None, None, None)
@@ -1077,7 +1083,7 @@
     memo = ResumeDataLoopMemo(metainterp_sd)
     i = t.get_iter()
     modifier = ResumeDataVirtualAdder(FakeOptimizer(i), storage, storage, i, 
memo)
-    modifier.finish(FakeOptimizer(i))
+    modifier.finish()
     assert len(memo.consts) == 2
     assert storage.rd_consts is memo.consts
 
@@ -1086,7 +1092,7 @@
     i = t.get_iter()
     modifier2 = ResumeDataVirtualAdder(FakeOptimizer(i), storage2, storage2,
                                        i, memo)
-    modifier2.finish(FakeOptimizer(i))
+    modifier2.finish()
     assert len(memo.consts) == 3    
     assert storage2.rd_consts is memo.consts
 
@@ -1155,7 +1161,7 @@
 
     b1s.set_forwarded(b1_2)
     b2s.set_forwarded(b1_2)
-    liveboxes = modifier.finish(FakeOptimizer())
+    liveboxes = modifier.finish()
     assert storage.rd_snapshot is None
     b1t, b3t = [InputArgInt(11), InputArgInt(33)]
     newboxes = _resume_remap(liveboxes, [b1_2, b3s], b1t, b3t)
@@ -1177,7 +1183,7 @@
     storage = make_storage(b1s, b2s, b3s)
     memo = ResumeDataLoopMemo(FakeMetaInterpStaticData())        
     modifier = ResumeDataVirtualAdder(FakeOptimizer(), storage, storage, memo)
-    liveboxes = modifier.finish(FakeOptimizer())
+    liveboxes = modifier.finish()
     b2t, b3t = [InputArgRef(demo55o), InputArgInt(33)]
     newboxes = _resume_remap(liveboxes, [b2s, b3s], b2t, b3t)
     metainterp = MyMetaInterp()
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to