[pypy-svn] r65133 - in pypy/branch/tagged-pointers-framework/pypy/rpython/memory: gctransform test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu May 7 14:00:26 CEST 2009


Author: cfbolz
Date: Thu May  7 14:00:26 2009
New Revision: 65133

Modified:
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_gc.py
   pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_transformed_gc.py
Log:
tests with prebuilt data structures. This finds a bug. The tests still fails on
mark-n-sweep, no clue why yet.


Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/gctransform/framework.py	Thu May  7 14:00:26 2009
@@ -843,7 +843,7 @@
             end = gcdata.static_root_nongcend
             while addr != end:
                 result = addr.address[0]
-                if result.address[0] != llmemory.NULL:
+                if self.gc.points_to_valid_gc_object(result):
                     collect_static_in_prebuilt_nongc(gc, result)
                 addr += sizeofaddr
         if collect_static_in_prebuilt_gc:
@@ -851,7 +851,7 @@
             end = gcdata.static_root_end
             while addr != end:
                 result = addr.address[0]
-                if result.address[0] != llmemory.NULL:
+                if self.gc.points_to_valid_gc_object(result):
                     collect_static_in_prebuilt_gc(gc, result)
                 addr += sizeofaddr
         if collect_stack_root:

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_gc.py	Thu May  7 14:00:26 2009
@@ -472,36 +472,20 @@
 
         assert self.interpret(f, []) == 2
 
-    def test_tagged(self):
+    def test_tagged_simple(self):
         from pypy.rlib.objectmodel import UnboxedValue
-        class A(object):
-            __slots__ = ()
-            def meth(self, x):
-                raise NotImplementedError
-
-        class B(A):
-            attrvalue = 66
-            def __init__(self, normalint):
-                self.normalint = normalint
-            def meth(self, x):
-                return self.normalint + x + 2
-
-        class C(A, UnboxedValue):
-            __slots__ = 'smallint'
-            def meth(self, x):
-                return self.smallint + x + 3
 
         class Unrelated(object):
             pass
 
         u = Unrelated()
-        u.x = C(47)
+        u.x = UnboxedObject(47)
         def fn(n):
             rgc.collect() # check that a prebuilt tagged pointer doesn't explode
             if n > 0:
-                x = B(n)
+                x = BoxedObject(n)
             else:
-                x = C(n)
+                x = UnboxedObject(n)
             u.x = x # invoke write barrier
             rgc.collect()
             return x.meth(100)
@@ -510,6 +494,46 @@
         res = self.interpret(fn, [-1000])
         assert res == -897
 
+    def test_tagged_prebuilt(self):
+
+        class F:
+            pass
+
+        f = F()
+        f.l = [UnboxedObject(10)]
+        def fn(n):
+            if n > 0:
+                x = BoxedObject(n)
+            else:
+                x = UnboxedObject(n)
+            f.l.append(x)
+            rgc.collect()
+            return f.l[-1].meth(100)
+        res = self.interpret(fn, [1000])
+        assert res == 1102
+        res = self.interpret(fn, [-1000])
+        assert res == -897
+
+from pypy.rlib.objectmodel import UnboxedValue
+
+class TaggedBase(object):
+    __slots__ = ()
+    def meth(self, x):
+        raise NotImplementedError
+
+class BoxedObject(TaggedBase):
+    attrvalue = 66
+    def __init__(self, normalint):
+        self.normalint = normalint
+    def meth(self, x):
+        return self.normalint + x + 2
+
+class UnboxedObject(TaggedBase, UnboxedValue):
+    __slots__ = 'smallint'
+    def meth(self, x):
+        return self.smallint + x + 3
+
+
 class TestMarkSweepGC(GCTest):
     from pypy.rpython.memory.gc.marksweep import MarkSweepGC as GCClass
 

Modified: pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_transformed_gc.py	(original)
+++ pypy/branch/tagged-pointers-framework/pypy/rpython/memory/test/test_transformed_gc.py	Thu May  7 14:00:26 2009
@@ -526,28 +526,18 @@
         assert res == 'y'
 
     def test_tagged(self):
-        from pypy.rlib.objectmodel import UnboxedValue
-        class A(object):
-            __slots__ = ()
-            def meth(self, x):
-                raise NotImplementedError
+        class Unrelated(object):
+            pass
 
-        class B(A):
-            attrvalue = 66
-            def __init__(self, normalint):
-                self.normalint = normalint
-            def meth(self, x):
-                return self.normalint + x + 2
-
-        class C(A, UnboxedValue):
-            __slots__ = 'smallint'
-            def meth(self, x):
-                return self.smallint + x + 3
+        u = Unrelated()
+        u.x = UnboxedObject(47)
         def fn(n):
+            rgc.collect() # check that a prebuilt tagged pointer doesn't explode
             if n > 0:
-                x = B(n)
+                x = BoxedObject(n)
             else:
-                x = C(n)
+                x = UnboxedObject(n)
+            u.x = x # invoke write barrier
             rgc.collect()
             return x.meth(100)
         def func():
@@ -556,6 +546,26 @@
         res = func([])
         assert res == fn(1000) + fn(-1000)
 
+from pypy.rlib.objectmodel import UnboxedValue
+
+class TaggedBase(object):
+    __slots__ = ()
+    def meth(self, x):
+        raise NotImplementedError
+
+class BoxedObject(TaggedBase):
+    attrvalue = 66
+    def __init__(self, normalint):
+        self.normalint = normalint
+    def meth(self, x):
+        return self.normalint + x + 2
+
+class UnboxedObject(TaggedBase, UnboxedValue):
+    __slots__ = 'smallint'
+    def meth(self, x):
+        return self.smallint + x + 3
+
+
 class GenericMovingGCTests(GenericGCTests):
     GC_CAN_MOVE = True
     GC_CANNOT_MALLOC_NONMOVABLE = True



More information about the Pypy-commit mailing list