[pypy-svn] r74830 - in pypy/branch/blackhole-improvement/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Fri May 28 02:24:12 CEST 2010


Author: arigo
Date: Fri May 28 02:24:10 2010
New Revision: 74830

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py
Log:
In-progress: virtualrefs.


Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Fri May 28 02:24:10 2010
@@ -1279,6 +1279,7 @@
         curbh._copy_data_from_miframe(frame)
         curbh.nextblackholeinterp = nextbh
         nextbh = curbh
+    XXX   # virtualrefs
     firstbh = nextbh
     #
     try:

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	Fri May 28 02:24:10 2010
@@ -1864,9 +1864,7 @@
         expect_virtualizable = vinfo is not None
         boxlists = resume.rebuild_from_resumedata(self, resumedescr,
                                                   expect_virtualizable)
-        #inputargs_and_holes, virtualizable_boxes, virtualref_boxes = boxlists
-        inputargs_and_holes = boxlists    # XXX
-        virtualref_boxes = []             # XXX
+        inputargs_and_holes, virtualizable_boxes, virtualref_boxes = boxlists
         #
         # virtual refs: make the vrefs point to the freshly allocated virtuals
         self.virtualref_boxes = virtualref_boxes

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	Fri May 28 02:24:10 2010
@@ -57,7 +57,7 @@
     storage.rd_frame_info_list = frame_info_list
     snapshot = Snapshot(top.parent_resumedata_snapshot,
                         top.get_list_of_active_boxes(False))
-    #snapshot = Snapshot(snapshot, virtualref_boxes[:]) # xxx for now
+    snapshot = Snapshot(snapshot, virtualref_boxes[:]) # xxx for now
     if virtualizable_boxes is not None:
         snapshot = Snapshot(snapshot, virtualizable_boxes[:]) # xxx for now
     storage.rd_snapshot = snapshot
@@ -552,7 +552,7 @@
     virtualizable_boxes = None
     if expects_virtualizables:
         XXX # virtualizable_boxes = resumereader.consume_boxes()
-    #resumereader.consume_boxes([], [], [])     # XXX virtualref
+    virtualref_boxes = resumereader.consume_virtualref_boxes()
     frameinfo = storage.rd_frame_info_list
     while True:
         f = metainterp.newframe(frameinfo.jitcode)
@@ -564,7 +564,7 @@
             break
     metainterp.framestack.reverse()
     resumereader.done()
-    return resumereader.liveboxes
+    return resumereader.liveboxes, None, virtualref_boxes
 
 def force_from_resumedata(metainterp, newboxes, storage,
                           expects_virtualizables):
@@ -572,8 +572,7 @@
     virtualizable_boxes = None
     if expects_virtualizables:
         virtualizable_boxes = resumereader.consume_boxes()
-    #virtualref_boxes = resumereader.consume_boxes()
-    virtualref_boxes = []     # XXX virtualrefs
+    virtualref_boxes = resumereader.consume_boxes()
     return virtualizable_boxes, virtualref_boxes, resumereader.virtuals
 
 class ResumeDataBoxReader(AbstractResumeDataReader):
@@ -589,6 +588,13 @@
         self.boxes_f = boxes_f
         self._prepare_next_section(info)
 
+    def consume_virtualref_boxes(self):
+        # Returns a list of boxes, assumed to be all BoxPtrs.
+        # We leave up to the caller to call vrefinfo.continue_tracing().
+        nums = self.cur_numb.nums
+        self.cur_numb = self.cur_numb.prev
+        return [self.decode_ref(num) for num in nums]
+
     def allocate_with_vtable(self, known_class):
         return self.metainterp.execute_and_record(rop.NEW_WITH_VTABLE,
                                                   None, known_class)
@@ -683,7 +689,8 @@
     resumereader = ResumeDataDirectReader(blackholeinterpbuilder.cpu, storage)
     if expects_virtualizables:
         XXX
-    #virtualref_boxes = resumereader.consume_boxes()     # virtualref XXX
+    vrefinfo = blackholeinterpbuilder.metainterp_sd.virtualref_info
+    resumereader.consume_virtualref_info(vrefinfo)
     #
     # First get a chain of blackhole interpreters whose length is given
     # by the depth of rd_frame_info_list.  The first one we get must be
@@ -723,6 +730,17 @@
         info = blackholeinterp.get_current_position_info()
         self._prepare_next_section(info)
 
+    def consume_virtualref_info(self, vrefinfo):
+        # we have to decode a list of references containing pairs
+        # [..., virtual, vref, ...]
+        nums = self.cur_numb.nums
+        self.cur_numb = self.cur_numb.prev
+        for i in range(0, len(nums), 2):
+            virtual = self.decode_ref(nums[i])
+            vref = self.decode_ref(nums[i+1])
+            # For each pair, we store the virtual inside the vref.
+            vrefinfo.continue_tracing(vref, virtual)
+
     def allocate_with_vtable(self, known_class):
         from pypy.jit.metainterp.executor import exec_new_with_vtable
         return exec_new_with_vtable(self.cpu, known_class)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py	Fri May 28 02:24:10 2010
@@ -81,8 +81,26 @@
         JIT_VIRTUAL_REF = self.vrefinfo.JIT_VIRTUAL_REF
         bxs2[0].getref(lltype.Ptr(JIT_VIRTUAL_REF)).virtual_token = 1234567
         #
-        self.metainterp.rebuild_state_after_failure(guard_op.descr,
-                                                    guard_op.fail_args[:])
+        # try reloading from blackhole.py's point of view
+        from pypy.jit.metainterp.resume import ResumeDataDirectReader
+        cpu = self.metainterp.cpu
+        cpu.get_latest_value_count = lambda : len(guard_op.fail_args)
+        cpu.get_latest_value_int = lambda i:guard_op.fail_args[i].getint()
+        cpu.get_latest_value_ref = lambda i:guard_op.fail_args[i].getref_base()
+        cpu.clear_latest_values = lambda : None
+        resumereader = ResumeDataDirectReader(cpu, guard_op.descr)
+        vrefinfo = self.metainterp.staticdata.virtualref_info
+        lst = []
+        vrefinfo.continue_tracing = lambda vref, virtual: \
+                                        lst.append((vref, virtual))
+        resumereader.consume_virtualref_info(vrefinfo)
+        del vrefinfo.continue_tracing
+        assert len(lst) == 1
+        lltype.cast_opaque_ptr(lltype.Ptr(JIT_VIRTUAL_REF),
+                               lst[0][0])  # assert correct type
+        #
+        # try reloading from pyjitpl's point of view
+        self.metainterp.rebuild_state_after_failure(guard_op.descr)
         assert len(self.metainterp.framestack) == 1
         assert len(self.metainterp.virtualref_boxes) == 2
         assert self.metainterp.virtualref_boxes[0].value == bxs1[0].value



More information about the Pypy-commit mailing list