Author: Remi Meier <[email protected]>
Branch: stmgc-c4
Changeset: r66144:d2096ca14852
Date: 2013-08-14 09:09 +0200
http://bitbucket.org/pypy/pypy/changeset/d2096ca14852/

Log:    test gc.py's stm barrier fastpaths

diff --git a/rpython/jit/backend/llsupport/gc.py 
b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -448,13 +448,13 @@
     @specialize.arg(2)
     def _do_barrier(self, gcref_struct, returns_modified_object):
         assert returns_modified_object
-        from rpython.memory.gc.stmgc import get_hdr_revision
+        from rpython.memory.gc.stmgc import StmGC
         objadr = llmemory.cast_ptr_to_adr(gcref_struct)
+        objhdr = rffi.cast(StmGC.GCHDRP, gcref_struct)
 
         # if h_revision == privat_rev of transaction
-        rev = get_hdr_revision(objadr)
         priv_rev = self.llop1.stm_get_adr_of_private_rev_num(rffi.SIGNEDP)
-        if rev[0] == priv_rev[0]:
+        if objhdr.h_revision == priv_rev[0]:
             return gcref_struct
 
         # XXX: readcache!
@@ -472,17 +472,15 @@
     @specialize.arg(2)
     def _do_barrier(self, gcref_struct, returns_modified_object):
         assert returns_modified_object
-        from rpython.memory.gc.stmgc import (StmGC, get_hdr_revision,
-                                             get_hdr_tid)
+        from rpython.memory.gc.stmgc import StmGC
         objadr = llmemory.cast_ptr_to_adr(gcref_struct)
-
+        objhdr = rffi.cast(StmGC.GCHDRP, gcref_struct)
+        
         # if h_revision == privat_rev of transaction
-        rev = get_hdr_revision(objadr)
         priv_rev = self.llop1.stm_get_adr_of_private_rev_num(rffi.SIGNEDP)
-        if rev[0] == priv_rev[0]:
+        if objhdr.h_revision == priv_rev[0]:
             # also WRITE_BARRIER not set?
-            tid = get_hdr_tid(objadr)[0]
-            if not (tid & StmGC.GCFLAG_WRITE_BARRIER):
+            if not (objhdr.h_tid & StmGC.GCFLAG_WRITE_BARRIER):
                 return gcref_struct
         
         funcptr = self.get_barrier_funcptr(returns_modified_object)
diff --git a/rpython/jit/backend/x86/test/test_stm_integration.py 
b/rpython/jit/backend/x86/test/test_stm_integration.py
--- a/rpython/jit/backend/x86/test/test_stm_integration.py
+++ b/rpython/jit/backend/x86/test/test_stm_integration.py
@@ -102,11 +102,14 @@
 class FakeGCHeaderBuilder:
     size_gc_header = WORD
 
-GCPTR = lltype.Ptr(lltype.GcStruct(
-            'GCPTR', ('h_tid', lltype.Unsigned),
-            ('h_revision', lltype.Signed),
-            ('h_original', lltype.Unsigned)))
-HDRSIZE = 3 * WORD
+class fakellop:
+    PRIV_REV = 66
+    def stm_get_adr_of_private_rev_num(self, _):
+        TP = rffi.CArray(lltype.Signed)
+        p = lltype.malloc(TP, n=1, flavor='raw', 
+                          track_allocation=False, zero=True)
+        p[0] = fakellop.PRIV_REV
+        return p
 
 class GCDescrStm(GCDescrShadowstackDirect):
     def __init__(self):
@@ -154,11 +157,11 @@
                                RESULT=lltype.Bool)
 
         def malloc_big_fixedsize(size, tid):
-            entries = size + HDRSIZE
+            entries = size + StmGC.GCHDRSIZE
             TP = rffi.CArray(lltype.Char)
             obj = lltype.malloc(TP, n=entries, flavor='raw',
                                             track_allocation=False, zero=True)
-            objptr = rffi.cast(GCPTR, obj)
+            objptr = rffi.cast(StmGC.GCHDRP, obj)
             objptr.h_tid = rffi.cast(lltype.Unsigned,
                                   StmGC.GCFLAG_OLD|StmGC.GCFLAG_WRITE_BARRIER
                                   | tid)
@@ -259,6 +262,8 @@
         s.h_revision = rffi.cast(lltype.Signed, StmGC.PREBUILT_REVISION)
         return s
 
+    
+        
     def test_gc_read_barrier_fastpath(self):
         from rpython.jit.backend.llsupport.gc import STMReadBarrierDescr
         descr = STMReadBarrierDescr(self.cpu.gc_ll_descr, 'P2R')
@@ -268,15 +273,6 @@
             called.append(obj)
             return obj
 
-        PRIV_REV = 66
-        class fakellop:
-            def stm_get_adr_of_private_rev_num(self, _):
-                TP = rffi.SIGNEDP
-                p = lltype.malloc(TP, n=1, flavor='raw', 
-                                  track_allocation=False, zero=True)
-                p[0] = PRIV_REV
-                return rffi.cast(llmemory.Address, p)
-        
         functype = lltype.Ptr(lltype.FuncType(
             [llmemory.Address], llmemory.Address))
         funcptr = llhelper(functype, read)
@@ -284,28 +280,68 @@
         descr.llop1 = fakellop()
 
         # -------- TEST --------
-        for rev in [PRIV_REV+4, PRIV_REV]:
+        for rev in [fakellop.PRIV_REV+4, fakellop.PRIV_REV]:
             called[:] = []
             
             s = self.allocate_prebuilt_s()
             sgcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
             s.h_revision = rev
 
-            descr._do_barrier(llmemory.AddressAsInt(sgcref),
+            descr._do_barrier(sgcref,
                               returns_modified_object=True)
                         
             # check if rev-fastpath worked
-            if rev == PRIV_REV:
+            if rev == fakellop.PRIV_REV:
                 # fastpath
-                assert sgcref not in called
+                self.assert_not_in(called, [sgcref])
             else:
-                assert sgcref in called
+                self.assert_in(called, [sgcref])
                 
             # XXX: read_cache test!
             # # now add it to the read-cache and check
             # # that it will never call the read_barrier
             # assert not called_on
 
+    def test_gc_write_barrier_fastpath(self):
+        from rpython.jit.backend.llsupport.gc import STMWriteBarrierDescr
+        descr = STMWriteBarrierDescr(self.cpu.gc_ll_descr, 'P2W')
+
+        called = []
+        def write(obj):
+            called.append(obj)
+            return obj
+
+        functype = lltype.Ptr(lltype.FuncType(
+            [llmemory.Address], llmemory.Address))
+        funcptr = llhelper(functype, write)
+        descr.b_failing_case_ptr = funcptr
+        descr.llop1 = fakellop()
+
+        # -------- TEST --------
+        for rev in [fakellop.PRIV_REV+4, fakellop.PRIV_REV]:
+            called[:] = []
+            
+            s = self.allocate_prebuilt_s()
+            sgcref = lltype.cast_opaque_ptr(llmemory.GCREF, s)
+            s.h_revision = rev
+
+            descr._do_barrier(sgcref,
+                              returns_modified_object=True)
+                        
+            # check if rev-fastpath worked
+            if rev == fakellop.PRIV_REV:
+                # fastpath
+                self.assert_not_in(called, [sgcref])
+            else:
+                self.assert_in(called, [sgcref])
+                
+            # now set WRITE_BARRIER -> always call slowpath
+            called[:] = []
+            s.h_tid |= StmGC.GCFLAG_WRITE_BARRIER
+            descr._do_barrier(sgcref, 
+                              returns_modified_object=True)
+            self.assert_in(called, [sgcref])
+
         
         
         
diff --git a/rpython/memory/gc/stmgc.py b/rpython/memory/gc/stmgc.py
--- a/rpython/memory/gc/stmgc.py
+++ b/rpython/memory/gc/stmgc.py
@@ -36,10 +36,19 @@
     malloc_zero_filled = True
     #gcflag_extra = GCFLAG_EXTRA
 
+
+    GCHDR = lltype.GcStruct(
+        'GCPTR',
+        ('h_tid', lltype.Unsigned),
+        ('h_revision', lltype.Signed),
+        ('h_original', lltype.Unsigned))
+    GCHDRP = lltype.Ptr(GCHDR)
+    GCHDRSIZE = 3 * WORD
+
     HDR = rffi.COpaque('struct stm_object_s')
     H_TID = 0
     H_REVISION = WORD
-    H_ORIGINAL = WORD + WORD
+    H_ORIGINAL = WORD * 2
     typeid_is_in_field = None
 
     VISIT_FPTR = lltype.Ptr(lltype.FuncType([llmemory.Address], lltype.Void))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to