[pypy-svn] r65867 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Mon Jun 22 18:17:29 CEST 2009


Author: arigo
Date: Mon Jun 22 18:17:28 2009
New Revision: 65867

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
Log:
Progress on virtualizables.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Mon Jun 22 18:17:28 2009
@@ -467,6 +467,8 @@
     @arguments("int", "box")
     def opimpl_setfield_vable(self, index, valuebox):
         self.metainterp.virtualizable_boxes[index] = valuebox
+        self.metainterp.synchronize_virtualizable()
+        # XXX only the index'th field needs to be synchronized, really
 
     def perform_call(self, jitcode, varargs):
         if (isinstance(self.metainterp.history, history.BlackHole) and
@@ -1135,7 +1137,9 @@
 
     def reached_can_enter_jit(self, live_arg_boxes):
         if self.staticdata.virtualizable_info is not None:
-            live_arg_boxes += self.virtualizable_boxes
+            # we use ':-1' to remove the last item, which is the virtualizable
+            # itself
+            live_arg_boxes += self.virtualizable_boxes[:-1]
         # Called whenever we reach the 'can_enter_jit' hint.
         # First, attempt to make a bridge:
         # - if self.resumekey is a ResumeGuardDescr, it starts from a guard
@@ -1363,6 +1367,7 @@
             self.virtualizable_boxes = vinfo.read_boxes(self.cpu,
                                                         virtualizable)
             original_boxes += self.virtualizable_boxes
+            self.virtualizable_boxes.append(virtualizable_box)
 
     def handle_exception(self):
         etype = self.cpu.get_exception()
@@ -1389,12 +1394,20 @@
         if self.staticdata.virtualizable_info is not None:
             self.virtualizable_boxes = _consume_nums(vable_nums,
                                                      newboxes, consts)
+            self.synchronize_virtualizable()
+            #
         self.framestack = []
         for jitcode, pc, nums, exception_target in resume_info:
             f = self.newframe(jitcode)
             f.setup_resume_at_op(pc, nums, consts, newboxes,
                                            exception_target)
 
+    def synchronize_virtualizable(self):
+        vinfo = self.staticdata.virtualizable_info
+        virtualizable_box = self.virtualizable_boxes[-1]
+        virtualizable = virtualizable_box.getptr(vinfo.VTYPEPTR)
+        vinfo.write_boxes(virtualizable, self.virtualizable_boxes)
+
 class GenerateMergePoint(Exception):
     def __init__(self, args, target_loop):
         assert target_loop is not None

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_virtualizable.py	Mon Jun 22 18:17:28 2009
@@ -61,7 +61,6 @@
         self.check_loops(getfield_gc=0, setfield_gc=0)
 
     def test_preexisting_access_2(self):
-        py.test.skip("bugs")
         myjitdriver = JitDriver(greens = [], reds = ['n', 'xy'],
                                 virtualizables = ['xy'])
         def f(n):
@@ -80,6 +79,7 @@
                     xy.inst_x = x + 10
                 n -= 1
             return xy.inst_x
+        assert f(5) == 185
         res = self.meta_interp(f, [5])
         assert res == 185
         self.check_loops(getfield_gc=0, setfield_gc=0)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/warmspot.py	Mon Jun 22 18:17:28 2009
@@ -473,6 +473,7 @@
         index = len(jitdriver.greens) + jitdriver.reds.index(vname)
         VTYPEPTR = warmrunnerdesc.JIT_ENTER_FUNCTYPE.ARGS[index]
         fields = VTYPEPTR.TO._adtmeths['access'].redirected_fields
+        FIELDTYPES = [getattr(VTYPEPTR.TO, name) for name in fields]
         self.VTYPEPTR = VTYPEPTR
         self.index_in_boxes = index
         self.num_extra_boxes = len(fields)
@@ -481,13 +482,23 @@
         #
         def read_boxes(cpu, virtualizable):
             boxes = []
-            for fieldname in unroll_fields:
+            for _, fieldname in unroll_fields:
                 x = getattr(virtualizable, fieldname)
                 boxes.append(wrap(cpu, x))
             return boxes
         #
-        unroll_fields = unrolling_iterable(fields)
+        def write_boxes(virtualizable, boxes):
+            assert len(boxes) >= field_count
+            i = 0
+            for FIELDTYPE, fieldname in unroll_fields:
+                x = unwrap(FIELDTYPE, boxes[i])
+                setattr(virtualizable, fieldname, x)
+                i = i + 1
+        #
+        field_count = len(fields)
+        unroll_fields = unrolling_iterable(zip(FIELDTYPES, fields))
         self.read_boxes = read_boxes
+        self.write_boxes = write_boxes
 
     def _freeze_(self):
         return True
@@ -635,7 +646,7 @@
             elif value > MAX_HASH_TABLE_BITS:
                 value = MAX_HASH_TABLE_BITS
             # the tables are initialized with the correct size only in
-            # attach_unoptimized_bridge_from_interp()
+            # create_tables_now()
             self.hashbits = value
             self.hashtablemask = 0
             self.mccounters = [0]



More information about the Pypy-commit mailing list