Author: Armin Rigo <[email protected]>
Branch: c7-refactor
Changeset: r746:d288b4fdb72b
Date: 2014-02-16 09:29 +0100
http://bitbucket.org/pypy/stmgc/changeset/d288b4fdb72b/

Log:    creation_markers need to distinguish between current-transaction
        objects *inside* or *outside* the nursery, otherwise
        _stm_write_slowpath() is never going to be called for the latter

diff --git a/c7/stm/core.h b/c7/stm/core.h
--- a/c7/stm/core.h
+++ b/c7/stm/core.h
@@ -74,6 +74,11 @@
     TS_INEVITABLE,
     TS_MUST_ABORT,
 };
+enum {   /* for stm_creation_marker_t */
+    CM_NOT_CURRENT_TRANSACTION             = 0x00,
+    CM_CURRENT_TRANSACTION_OUTSIDE_NURSERY = 0x01,
+    CM_CURRENT_TRANSACTION_IN_NURSERY      = 0xff,
+};
 
 static char *stm_object_pages;
 static stm_thread_local_t *stm_thread_locals = NULL;
@@ -105,7 +110,8 @@
 static bool _running_transaction(void);
 
 static inline bool obj_from_same_transaction(object_t *obj) {
-    return ((stm_creation_marker_t *)(((uintptr_t)obj) >> 8))->cm != 0;
+    return ((stm_creation_marker_t *)(((uintptr_t)obj) >> 8))->cm !=
+        CM_NOT_CURRENT_TRANSACTION;
 }
 
 static void teardown_core(void);
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -21,8 +21,7 @@
 
 /* size in bytes of the "line".  Should be equal to the line used by
    stm_creation_marker_t. */
-#define NURSERY_LINE_SHIFT    8
-#define NURSERY_LINE          (1 << NURSERY_LINE_SHIFT)
+#define NURSERY_LINE          256
 
 /************************************************************/
 
@@ -37,6 +36,7 @@
 
 static void setup_nursery(void)
 {
+    assert(NURSERY_LINE == (1 << 8));  /* from stm_creation_marker_t */
     assert((NURSERY_SECTION_SIZE % NURSERY_LINE) == 0);
     assert(MEDIUM_OBJECT < LARGE_OBJECT);
     assert(LARGE_OBJECT < NURSERY_SECTION_SIZE);
@@ -49,40 +49,6 @@
     return (uintptr_t)obj < NURSERY_START + NURSERY_SIZE;
 }
 
-static void set_creation_markers(stm_char *p, uint64_t size)
-{
-    /* Set the creation markers to 0xff for all lines from p to p+size.
-       Both p and size should be aligned to NURSERY_LINE. */
-
-    assert((((uintptr_t)p) & (NURSERY_LINE - 1)) == 0);
-    assert((size & (NURSERY_LINE - 1)) == 0);
-
-    char *addr = REAL_ADDRESS(STM_SEGMENT->segment_base,
-                              ((uintptr_t)p) >> NURSERY_LINE_SHIFT);
-    memset(addr, 0xff, size >> NURSERY_LINE_SHIFT);
-
-    LIST_APPEND(STM_PSEGMENT->creation_markers, addr);
-}
-
-static void reset_all_creation_markers(void)
-{
-    /* Note that the page 'NB_PAGES - 1' is not actually used.  This
-       ensures that the creation markers always end with some zeroes.
-       We reset the markers 8 at a time, by writing null integers
-       until we reach a place that is already null.
-    */
-    LIST_FOREACH_R(
-        STM_PSEGMENT->creation_markers,
-        uintptr_t /*item*/,
-        ({
-            uint64_t *p = (uint64_t *)(item & ~7);
-            while (*p != 0)
-                *p++ = 0;
-        }));
-
-    list_clear(STM_PSEGMENT->creation_markers);
-}
-
 
 #define NURSERY_ALIGN(bytes)  \
     (((bytes) + NURSERY_LINE - 1) & ~(NURSERY_LINE - 1))
@@ -112,8 +78,8 @@
         STM_SEGMENT->nursery_section_end = (uintptr_t)p + NURSERY_SECTION_SIZE;
 
         /* Also fill the corresponding creation markers with 0xff. */
-        set_creation_markers(p, NURSERY_SECTION_SIZE);
-
+        set_creation_markers(p, NURSERY_SECTION_SIZE,
+                             CM_CURRENT_TRANSACTION_IN_NURSERY);
         return p;
     }
     abort();
diff --git a/c7/stm/nursery.h b/c7/stm/nursery.h
--- a/c7/stm/nursery.h
+++ b/c7/stm/nursery.h
@@ -1,2 +1,2 @@
 
-static void reset_all_creation_markers(void);
+/* empty */
diff --git a/c7/stm/pages.c b/c7/stm/pages.c
--- a/c7/stm/pages.c
+++ b/c7/stm/pages.c
@@ -77,3 +77,36 @@
     assert(flag_page_private[pagenum] == REMAPPING_PAGE);
     flag_page_private[pagenum] = PRIVATE_PAGE;
 }
+
+static void set_creation_markers(stm_char *p, uint64_t size, int newvalue)
+{
+    /* Set the creation markers to 'newvalue' for all lines from 'p' to
+       'p+size'.  Both p and size should be aligned to the line size: 256. */
+
+    assert((((uintptr_t)p) & 255) == 0);
+    assert((size & 255) == 0);
+
+    char *addr = REAL_ADDRESS(STM_SEGMENT->segment_base, ((uintptr_t)p) >> 8);
+    memset(addr, newvalue, size >> 8);
+
+    LIST_APPEND(STM_PSEGMENT->creation_markers, addr);
+}
+
+static void reset_all_creation_markers(void)
+{
+    /* Note that the page 'NB_PAGES - 1' is not actually used.  This
+       ensures that the creation markers always end with some zeroes.
+       We reset the markers 8 at a time, by writing null integers
+       until we reach a place that is already null.
+    */
+    LIST_FOREACH_R(
+        STM_PSEGMENT->creation_markers,
+        uintptr_t /*item*/,
+        ({
+            uint64_t *p = (uint64_t *)(item & ~7);
+            while (*p != 0)
+                *p++ = 0;
+        }));
+
+    list_clear(STM_PSEGMENT->creation_markers);
+}
diff --git a/c7/stm/pages.h b/c7/stm/pages.h
--- a/c7/stm/pages.h
+++ b/c7/stm/pages.h
@@ -28,3 +28,6 @@
     }
     _pages_privatize(pagenum, count);
 }
+
+static void set_creation_markers(stm_char *p, uint64_t size, int newvalue);
+static void reset_all_creation_markers(void);
diff --git a/c7/stmgc.h b/c7/stmgc.h
--- a/c7/stmgc.h
+++ b/c7/stmgc.h
@@ -49,10 +49,11 @@
 struct stm_creation_marker_s {
     /* In addition to read markers, every "line" of 256 bytes has one
        extra byte, the creation marker, located at the address divided
-       by 256.  The creation marker is either 0xff if all objects in
+       by 256.  The creation marker is either non-zero if all objects in
        this line come have been allocated by the current transaction,
        or 0x00 if none of them have been.  Lines cannot contain a
-       mixture of both. */
+       mixture of both.  Non-zero values are 0xff if in the nursery,
+       and 0x01 if outside the nursery. */
     uint8_t cm;
 };
 
@@ -152,9 +153,10 @@
 static inline void stm_write(object_t *obj)
 {
     /* this is:
-           'if (cm == 0 && (stm_flags & WRITE_BARRIER_CALLED) == 0)'
-         assuming that 'cm' is either 0 (not created in current transaction)
-                                or 0xff (created in current transaction) */
+           'if (cm < 0x80 && (stm_flags & WRITE_BARRIER_CALLED) == 0)'
+         where 'cm' can be 0 (not created in current transaction)
+                     or 0xff (created in current transaction)
+                     or 0x01 (same, but outside the nursery) */
     if (UNLIKELY(!((((stm_creation_marker_t *)(((uintptr_t)obj) >> 8))->cm |
                     obj->stm_flags) & _STM_GCFLAG_WRITE_BARRIER_CALLED)))
         _stm_write_slowpath(obj);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to