[pypy-svn] r65255 - in pypy/branch/pyjitpl5/pypy/jit: backend/x86 backend/x86/test metainterp

arigo at codespeak.net arigo at codespeak.net
Tue May 12 22:00:26 CEST 2009


Author: arigo
Date: Tue May 12 22:00:23 2009
New Revision: 65255

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/gc.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/gc.py
Log:
The first (and only) test passes, for what it's worth.  Still missing
some proper testing...  See comment in _rewrite_const_ptrs.


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	Tue May 12 22:00:23 2009
@@ -120,6 +120,8 @@
 
     def make_sure_mc_exists(self):
         if self.mc is None:
+            from pypy.jit.backend.x86.runner import ConstDescr3
+
             self.fail_boxes = lltype.malloc(rffi.CArray(lltype.Signed),
                                             MAX_FAIL_BOXES, flavor='raw')
             self.fail_box_addr = self.cpu.cast_ptr_to_int(self.fail_boxes)
@@ -150,6 +152,7 @@
             # that appear as ConstPtr.
             if self.cpu.gc_ll_descr.moving_gc:
                 self.gcrefs = self.cpu.gc_ll_descr.GcRefList()
+                self.single_gcref_descr = ConstDescr3(0, WORD, True)
             else:
                 self.gcrefs = None
 

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/gc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/gc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/gc.py	Tue May 12 22:00:23 2009
@@ -77,7 +77,9 @@
         self.hashtable = lltype.malloc(self.HASHTABLE,
                                        self.HASHTABLE_SIZE+1,
                                        flavor='raw')
-        dummy = llmemory.itemoffsetof(self.hashtable, self.HASHTABLE_SIZE)
+        dummy = lltype.direct_ptradd(lltype.direct_arrayitems(self.hashtable),
+                                     self.HASHTABLE_SIZE)
+        dummy = llmemory.cast_ptr_to_adr(dummy)
         for i in range(self.HASHTABLE_SIZE+1):
             self.hashtable[i] = dummy
 
@@ -110,7 +112,9 @@
         # add it
         index = self.nextindex
         self.list[index] = gcref
-        addr_ref = llmemory.itemoffsetof(self.GCREF_LIST, index)
+        addr_ref = lltype.direct_ptradd(lltype.direct_arrayitems(self.list),
+                                        index)
+        addr_ref = llmemory.cast_ptr_to_adr(addr_ref)
         self.nextindex = index + 1
         # record it in the hashtable
         self.hashtable[hash] = addr_ref

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/regalloc.py	Tue May 12 22:00:23 2009
@@ -3,11 +3,12 @@
 """
 
 from pypy.jit.metainterp.history import (Box, Const, ConstInt, ConstPtr,
-                                         ResOperation, ConstAddr)
+                                         ResOperation, ConstAddr, BoxPtr)
 from pypy.jit.backend.x86.ri386 import *
 from pypy.rpython.lltypesystem import lltype, ll2ctypes, rffi, rstr
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib import rgc
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.resoperation import rop
 
@@ -44,11 +45,15 @@
     if isinstance(c, ConstInt):
         return imm(c.value)
     elif isinstance(c, ConstPtr):
+        if we_are_translated() and rgc.can_move(c.value):
+            print "convert_to_imm: ConstPtr needs special care"
+            raise AssertionError
         return imm(rffi.cast(lltype.Signed, c.value))
     elif isinstance(c, ConstAddr):
         return imm(ll2ctypes.cast_adr_to_int(c.value))
     else:
-        raise ValueError("convert_to_imm: got a %s" % c)
+        print "convert_to_imm: got a %s" % c
+        raise AssertionError
 
 class RegAlloc(object):
     max_stack_depth = 0
@@ -60,6 +65,7 @@
         self.assembler = assembler
         self.translate_support_code = translate_support_code
         if regalloc is None:
+            self._rewrite_const_ptrs(tree.operations)
             self.tree = tree
             self.reg_bindings = newcheckdict()
             self.stack_bindings = newcheckdict()
@@ -76,6 +82,7 @@
             self.loop_consts = loop_consts
             self.current_stack_depth = sd
         else:
+            self._rewrite_const_ptrs(guard_op.suboperations)
             inp = guard_op.inputargs
             self.reg_bindings = {}
             self.stack_bindings = {}
@@ -313,6 +320,33 @@
         self.max_stack_depth = max(self.max_stack_depth,
                                    self.current_stack_depth + 1)
 
+    def _rewrite_const_ptrs(self, operations):
+        # Idea: when running on a moving GC, we can't (easily) encode
+        # the ConstPtrs in the assembler, because they can move at any
+        # point in time.  Instead, we store them in 'gcrefs.list', a GC
+        # but nonmovable list; and here, we modify 'operations' to
+        # replace direct usage of ConstPtr with a BoxPtr loaded by a
+        # GETFIELD_RAW from the array 'gcrefs.list'.
+        gcrefs = self.assembler.gcrefs
+        if gcrefs is None:
+            return
+        single_gcref_descr = self.assembler.single_gcref_descr
+        newops = []
+        for op in operations:
+            for i in range(len(op.args)):
+                v = op.args[i]
+                if isinstance(v, ConstPtr) and rgc.can_move(v.value):
+                    box = BoxPtr(v.value)
+                    addr = gcrefs.get_address_of_gcref(v.value)
+                    addr = rffi.cast(lltype.Signed, addr)
+                    newops.append(ResOperation(rop.GETFIELD_RAW,
+                                               [ConstInt(addr)], box,
+                                               single_gcref_descr))
+                    op.args[i] = box
+            newops.append(op)
+        del operations[:]
+        operations.extend(newops)
+
     def _compute_vars_longevity(self, inputargs, operations):
         # compute a dictionary that maps variables to index in
         # operations that is a "last-time-seen"

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/test/test_zrpy_gc.py	Tue May 12 22:00:23 2009
@@ -79,6 +79,5 @@
     compile_and_run("boehm")
 
 def test_compile_hybrid():
-    py.test.skip("in-progress")
     # a moving GC, with a write barrier.  Supports malloc_varsize_nonmovable.
     compile_and_run("hybrid", gcrootfinder="asmgcc")

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/gc.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/gc.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/gc.py	Tue May 12 22:00:23 2009
@@ -13,6 +13,12 @@
 class GC_semispace(GcDescription):
     malloc_zero_filled = True
 
+class GC_generation(GcDescription):
+    malloc_zero_filled = True
+
+class GC_hybrid(GcDescription):
+    malloc_zero_filled = True
+
 
 def get_description(config):
     name = config.translation.gc



More information about the Pypy-commit mailing list