[pypy-svn] r76798 - in pypy/branch/markcompact/pypy: rpython/memory/gc translator/c/test

arigo at codespeak.net arigo at codespeak.net
Mon Aug 30 09:49:23 CEST 2010


Author: arigo
Date: Mon Aug 30 09:49:21 2010
New Revision: 76798

Modified:
   pypy/branch/markcompact/pypy/rpython/memory/gc/markcompact.py
   pypy/branch/markcompact/pypy/translator/c/test/test_newgc.py
Log:
A direct test for the bug, and a fix.  Argh.


Modified: pypy/branch/markcompact/pypy/rpython/memory/gc/markcompact.py
==============================================================================
--- pypy/branch/markcompact/pypy/rpython/memory/gc/markcompact.py	(original)
+++ pypy/branch/markcompact/pypy/rpython/memory/gc/markcompact.py	Mon Aug 30 09:49:21 2010
@@ -583,12 +583,12 @@
         if grow_hash_field:
             gcflags |= GCFLAG_SAVED_HASHFIELD
             hashvalue = self.get_identityhash_from_addr(obj)
-            (toaddr + basesize).signed[0] = hashvalue
         elif gcflags & GCFLAG_SAVED_HASHFIELD:
             fromaddr = llarena.getfakearenaaddress(obj)
             fromaddr -= self.gcheaderbuilder.size_gc_header
             hashvalue = (fromaddr + basesize).signed[0]
-            (toaddr + basesize).signed[0] = hashvalue
+        else:
+            hashvalue = 0     # not used
         #
         hdr.tid = self.combine(typeid, gcflags << first_gcflag_bit)
         #
@@ -597,6 +597,9 @@
             llmemory.raw_memmove(fromaddr, toaddr, basesize)
         else:
             llmemory.raw_memcopy(fromaddr, toaddr, basesize)
+        #
+        if gcflags & GCFLAG_SAVED_HASHFIELD:
+            (toaddr + basesize).signed[0] = hashvalue
 
     def debug_check_object(self, obj):
         tid = self.header(obj).tid

Modified: pypy/branch/markcompact/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/markcompact/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/markcompact/pypy/translator/c/test/test_newgc.py	Mon Aug 30 09:49:21 2010
@@ -1080,6 +1080,52 @@
     def test_finalizer_order(self):
         py.test.skip("not implemented")
 
+    def define_adding_a_hash(cls):
+        from pypy.rlib.objectmodel import compute_identity_hash
+        S1 = lltype.GcStruct('S1', ('x', lltype.Signed))
+        S2 = lltype.GcStruct('S2', ('p1', lltype.Ptr(S1)),
+                                   ('p2', lltype.Ptr(S1)),
+                                   ('p3', lltype.Ptr(S1)),
+                                   ('p4', lltype.Ptr(S1)),
+                                   ('p5', lltype.Ptr(S1)),
+                                   ('p6', lltype.Ptr(S1)),
+                                   ('p7', lltype.Ptr(S1)),
+                                   ('p8', lltype.Ptr(S1)),
+                                   ('p9', lltype.Ptr(S1)))
+        def g():
+            lltype.malloc(S1)   # forgotten, will be shifted over
+            s2 = lltype.malloc(S2)   # a big object, overlaps its old position
+            s2.p1 = lltype.malloc(S1); s2.p1.x = 1010
+            s2.p2 = lltype.malloc(S1); s2.p2.x = 1020
+            s2.p3 = lltype.malloc(S1); s2.p3.x = 1030
+            s2.p4 = lltype.malloc(S1); s2.p4.x = 1040
+            s2.p5 = lltype.malloc(S1); s2.p5.x = 1050
+            s2.p6 = lltype.malloc(S1); s2.p6.x = 1060
+            s2.p7 = lltype.malloc(S1); s2.p7.x = 1070
+            s2.p8 = lltype.malloc(S1); s2.p8.x = 1080
+            s2.p9 = lltype.malloc(S1); s2.p9.x = 1090
+            return s2
+        def f():
+            rgc.collect()
+            s2 = g()
+            h2 = compute_identity_hash(s2)
+            rgc.collect()    # shift s2 to the left, but add a hash field
+            assert s2.p1.x == 1010
+            assert s2.p2.x == 1020
+            assert s2.p3.x == 1030
+            assert s2.p4.x == 1040
+            assert s2.p5.x == 1050
+            assert s2.p6.x == 1060
+            assert s2.p7.x == 1070
+            assert s2.p8.x == 1080
+            assert s2.p9.x == 1090
+            return h2 - compute_identity_hash(s2)
+        return f
+
+    def test_adding_a_hash(self):
+        res = self.run("adding_a_hash")
+        assert res == 0
+
 # ____________________________________________________________________
 
 class TaggedPointersTest(object):



More information about the Pypy-commit mailing list