[pypy-commit] stmgc copy-over-original2: I *think* that by now stm_pointer_equal() can be done more simply,

arigo noreply at buildbot.pypy.org
Sat Jul 27 10:08:31 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: copy-over-original2
Changeset: r462:d4e3aac8c458
Date: 2013-07-27 10:08 +0200
http://bitbucket.org/pypy/stmgc/changeset/d4e3aac8c458/

Log:	I *think* that by now stm_pointer_equal() can be done more simply,
	without needing to get the stm_id().

diff --git a/c4/extra.c b/c4/extra.c
--- a/c4/extra.c
+++ b/c4/extra.c
@@ -131,17 +131,16 @@
 
 _Bool stm_pointer_equal(gcptr p1, gcptr p2)
 {
-    /* fast path for two equal pointers */
-    if (p1 == p2)
-        return 1;
-    /* if p1 or p2 is NULL (but not both, because they are different
-       pointers), then return 0 */
-    if (p1 == NULL || p2 == NULL)
-        return 0;
-    /* types must be the same */
-    if ((p1->h_tid & STM_USER_TID_MASK) != (p2->h_tid & STM_USER_TID_MASK))
-        return 0;
-    return stm_id(p1) == stm_id(p2);
+    if (p1 != NULL && p2 != NULL) {
+        /* resolve h_original, but only if !PREBUILT_ORIGINAL */
+        if (p1->h_original && !(p1->h_tid & GCFLAG_PREBUILT_ORIGINAL)) {
+            p1 = (gcptr)p1->h_original;
+        }
+        if (p2->h_original && !(p2->h_tid & GCFLAG_PREBUILT_ORIGINAL)) {
+            p2 = (gcptr)p2->h_original;
+        }
+    }
+    return (p1 == p2);
 }
 
 /************************************************************/
diff --git a/c4/test/test_extra.py b/c4/test/test_extra.py
--- a/c4/test/test_extra.py
+++ b/c4/test/test_extra.py
@@ -104,13 +104,28 @@
             assert ffi.string(c).endswith("ei424242ee")
 
 def test_pointer_equal():
-    p = palloc(HDR + WORD)
-    assert lib.stm_pointer_equal(p, p)
-    assert not lib.stm_pointer_equal(p, ffi.NULL)
-    assert not lib.stm_pointer_equal(ffi.NULL, p)
-    assert lib.stm_pointer_equal(ffi.NULL, ffi.NULL)
-    q = lib.stm_write_barrier(p)
-    assert q != p
-    assert lib.stm_pointer_equal(p, q)
-    assert lib.stm_pointer_equal(q, q)
-    assert lib.stm_pointer_equal(q, p)
+    p1 = palloc(HDR + WORD)
+    p2 = palloc(HDR + WORD)
+    p3 = oalloc(HDR + WORD)
+    p4 = nalloc(HDR + WORD)
+    lib.stm_commit_transaction()
+    lib.stm_begin_inevitable_transaction()
+    p1b = lib.stm_write_barrier(p1)
+    p2b = lib.stm_write_barrier(p2)
+    p3b = lib.stm_write_barrier(p3)
+    p4b = lib.stm_write_barrier(p4)
+    #
+    got = []
+    for qa in [ffi.NULL, p1, p1b, p2, p2b, p3, p3b, p4, p4b]:
+        for qb in [ffi.NULL, p1, p1b, p2, p2b, p3, p3b, p4, p4b]:
+            got.append(lib.stm_pointer_equal(qa, qb))
+    #
+    assert got == [1, 0, 0, 0, 0, 0, 0, 0, 0,
+                   0, 1, 1, 0, 0, 0, 0, 0, 0,
+                   0, 1, 1, 0, 0, 0, 0, 0, 0,
+                   0, 0, 0, 1, 1, 0, 0, 0, 0,
+                   0, 0, 0, 1, 1, 0, 0, 0, 0,
+                   0, 0, 0, 0, 0, 1, 1, 0, 0,
+                   0, 0, 0, 0, 0, 1, 1, 0, 0,
+                   0, 0, 0, 0, 0, 0, 0, 1, 1,
+                   0, 0, 0, 0, 0, 0, 0, 1, 1]


More information about the pypy-commit mailing list