[pypy-commit] stmgc default: Merge non-zero-nursery

Raemi noreply at buildbot.pypy.org
Thu Mar 12 15:42:48 CET 2015


Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: 
Changeset: r1725:787577b281d6
Date: 2015-03-12 15:43 +0100
http://bitbucket.org/pypy/stmgc/changeset/787577b281d6/

Log:	Merge non-zero-nursery

diff --git a/c8/demo/demo_random.c b/c8/demo/demo_random.c
--- a/c8/demo/demo_random.c
+++ b/c8/demo/demo_random.c
@@ -231,10 +231,14 @@
                            sizeof(struct node_s) + 4096*70};
         size_t size = sizes[get_rand(4)];
         p = stm_allocate(size);
-        ((nodeptr_t)p)->sig = SIGNATURE;
-        ((nodeptr_t)p)->my_size = size;
-        ((nodeptr_t)p)->my_id = 0;
-        ((nodeptr_t)p)->my_hash = 0;
+        nodeptr_t n = (nodeptr_t)p;
+        n->sig = SIGNATURE;
+        n->my_size = size;
+        n->my_id = 0;
+        n->my_hash = 0;
+        nodeptr_t TLPREFIX *last_next = (nodeptr_t TLPREFIX *)((stm_char*)n + n->my_size - sizeof(void*));
+        n->next = NULL;
+        *last_next = NULL;
         pop_roots();
         /* reload_roots not necessary, all are old after start_transaction */
         break;
diff --git a/c8/demo/demo_random2.c b/c8/demo/demo_random2.c
--- a/c8/demo/demo_random2.c
+++ b/c8/demo/demo_random2.c
@@ -240,10 +240,14 @@
             sizeof(struct node_s) + (get_rand(100000) & ~15)};
         size_t size = sizes[get_rand(sizeof(sizes) / sizeof(size_t))];
         p = stm_allocate(size);
-        ((nodeptr_t)p)->sig = SIGNATURE;
-        ((nodeptr_t)p)->my_size = size;
-        ((nodeptr_t)p)->my_id = 0;
-        ((nodeptr_t)p)->my_hash = 0;
+        nodeptr_t n = (nodeptr_t)p;
+        n->sig = SIGNATURE;
+        n->my_size = size;
+        n->my_id = 0;
+        n->my_hash = 0;
+        nodeptr_t TLPREFIX *last_next = (nodeptr_t TLPREFIX *)((stm_char*)n + n->my_size - sizeof(void*));
+        n->next = NULL;
+        *last_next = NULL;
         pop_roots(pushed);
         break;
     case 4:  // read and validate 'p'
diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -862,6 +862,31 @@
 }
 
 
+static void touch_all_pages_of_obj(object_t *obj, size_t obj_size)
+{
+    int my_segnum = STM_SEGMENT->segment_num;
+    uintptr_t end_page, first_page = ((uintptr_t)obj) / 4096UL;
+
+    /* get the last page containing data from the object */
+    if (LIKELY(is_small_uniform(obj))) {
+        end_page = first_page;
+    } else {
+        end_page = (((uintptr_t)obj) + obj_size - 1) / 4096UL;
+    }
+
+    acquire_privatization_lock(STM_SEGMENT->segment_num);
+    uintptr_t page;
+    for (page = first_page; page <= end_page; page++) {
+        if (get_page_status_in(my_segnum, page) == PAGE_NO_ACCESS) {
+            release_privatization_lock(STM_SEGMENT->segment_num);
+            volatile char *dummy = REAL_ADDRESS(STM_SEGMENT->segment_base, page * 4096UL);
+            *dummy;            /* force segfault */
+            acquire_privatization_lock(STM_SEGMENT->segment_num);
+        }
+    }
+    release_privatization_lock(STM_SEGMENT->segment_num);
+}
+
 __attribute__((always_inline))
 static void write_slowpath_common(object_t *obj, bool mark_card)
 {
@@ -888,29 +913,10 @@
            the full obj in this segment (XXX) */
         char *realobj;
         size_t obj_size;
-        int my_segnum = STM_SEGMENT->segment_num;
-        uintptr_t end_page, first_page = ((uintptr_t)obj) / 4096UL;
-
         realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
         obj_size = stmcb_size_rounded_up((struct object_s *)realobj);
-        /* get the last page containing data from the object */
-        if (LIKELY(is_small_uniform(obj))) {
-            end_page = first_page;
-        } else {
-            end_page = (((uintptr_t)obj) + obj_size - 1) / 4096UL;
-        }
 
-        acquire_privatization_lock(STM_SEGMENT->segment_num);
-        uintptr_t page;
-        for (page = first_page; page <= end_page; page++) {
-            if (get_page_status_in(my_segnum, page) == PAGE_NO_ACCESS) {
-                release_privatization_lock(STM_SEGMENT->segment_num);
-                volatile char *dummy = REAL_ADDRESS(STM_SEGMENT->segment_base, page * 4096UL);
-                *dummy;            /* force segfault */
-                acquire_privatization_lock(STM_SEGMENT->segment_num);
-            }
-        }
-        release_privatization_lock(STM_SEGMENT->segment_num);
+        touch_all_pages_of_obj(obj, obj_size);
     }
 
     if (mark_card) {
diff --git a/c8/stm/core.h b/c8/stm/core.h
--- a/c8/stm/core.h
+++ b/c8/stm/core.h
@@ -278,6 +278,8 @@
 static stm_thread_local_t *abort_with_mutex_no_longjmp(void);
 static void abort_data_structures_from_segment_num(int segment_num);
 
+static void touch_all_pages_of_obj(object_t *obj, size_t obj_size);
+
 static void synchronize_object_enqueue(object_t *obj);
 static void synchronize_objects_flush(void);
 
diff --git a/c8/stm/nursery.c b/c8/stm/nursery.c
--- a/c8/stm/nursery.c
+++ b/c8/stm/nursery.c
@@ -451,11 +451,8 @@
 #undef STM_PSEGMENT
 #undef STM_SEGMENT
     dprintf(("throw_away_nursery\n"));
-    /* reset the nursery by zeroing it */
+
     size_t nursery_used;
-    char *realnursery;
-
-    realnursery = REAL_ADDRESS(pseg->pub.segment_base, _stm_nursery_start);
     nursery_used = pseg->pub.nursery_current - (stm_char *)_stm_nursery_start;
     if (nursery_used > NB_NURSERY_PAGES * 4096) {
         /* possible in rare cases when the program artificially advances
@@ -463,11 +460,18 @@
         nursery_used = NB_NURSERY_PAGES * 4096;
     }
     OPT_ASSERT((nursery_used & 7) == 0);
+
+
+#if _STM_NURSERY_ZEROED
+    /* reset the nursery by zeroing it */
+    char *realnursery;
+    realnursery = REAL_ADDRESS(pseg->pub.segment_base, _stm_nursery_start);
     memset(realnursery, 0, nursery_used);
 
     /* assert that the rest of the nursery still contains only zeroes */
     assert_memset_zero(realnursery + nursery_used,
                        (NURSERY_END - _stm_nursery_start) - nursery_used);
+#endif
 
     pseg->pub.nursery_current = (stm_char *)_stm_nursery_start;
 
@@ -601,6 +605,9 @@
     stm_char *end = p + size_rounded_up;
     if ((uintptr_t)end <= NURSERY_END) {
         STM_SEGMENT->nursery_current = end;
+#if !_STM_NURSERY_ZEROED
+        ((object_t *)p)->stm_flags = 0;
+#endif
         return (object_t *)p;
     }
 
@@ -626,7 +633,14 @@
 
     tree_insert(STM_PSEGMENT->young_outside_nursery, (uintptr_t)o, 0);
 
+#if _STM_NURSERY_ZEROED
     memset(REAL_ADDRESS(STM_SEGMENT->segment_base, o), 0, size_rounded_up);
+#else
+    o->stm_flags = 0;
+    /* make all pages of 'o' accessible as synchronize_obj_flush() in minor
+       collections assumes all young objs are fully accessible. */
+    touch_all_pages_of_obj(o, size_rounded_up);
+#endif
     return o;
 }
 
@@ -646,6 +660,7 @@
 }
 #endif
 
+__attribute__((unused))
 static void assert_memset_zero(void *s, size_t n)
 {
 #ifndef NDEBUG
@@ -662,9 +677,12 @@
 static void check_nursery_at_transaction_start(void)
 {
     assert((uintptr_t)STM_SEGMENT->nursery_current == _stm_nursery_start);
+
+#if _STM_NURSERY_ZEROED
     assert_memset_zero(REAL_ADDRESS(STM_SEGMENT->segment_base,
                                     STM_SEGMENT->nursery_current),
                        NURSERY_END - _stm_nursery_start);
+#endif
 }
 
 
diff --git a/c8/stmgc.h b/c8/stmgc.h
--- a/c8/stmgc.h
+++ b/c8/stmgc.h
@@ -73,6 +73,10 @@
     void *creating_pthread[2];
 } stm_thread_local_t;
 
+#ifndef _STM_NURSERY_ZEROED
+#define _STM_NURSERY_ZEROED               0
+#endif
+
 #define _STM_GCFLAG_WRITE_BARRIER      0x01
 #define _STM_FAST_ALLOC           (66*1024)
 #define _STM_NSE_SIGNAL_ABORT             1
@@ -254,6 +258,9 @@
     if (UNLIKELY((uintptr_t)end > STM_SEGMENT->nursery_end))
         return _stm_allocate_slowpath(size_rounded_up);
 
+#if !_STM_NURSERY_ZEROED
+    ((object_t *)p)->stm_flags = 0;
+#endif
     return (object_t *)p;
 }
 
diff --git a/c8/test/support.py b/c8/test/support.py
--- a/c8/test/support.py
+++ b/c8/test/support.py
@@ -448,6 +448,7 @@
                     ('STM_LARGEMALLOC_TEST', '1'),
                     ('STM_NO_COND_WAIT', '1'),
                     ('STM_DEBUGPRINT', '1'),
+                    ('_STM_NURSERY_ZEROED', '1'),
                     ('GC_N_SMALL_REQUESTS', str(GC_N_SMALL_REQUESTS)), #check
                     ],
      undef_macros=['NDEBUG'],
diff --git a/duhton-c8/Makefile b/duhton-c8/Makefile
--- a/duhton-c8/Makefile
+++ b/duhton-c8/Makefile
@@ -3,7 +3,7 @@
 
 C8HEADERS = ../c8/stmgc.h ../c8/stm/*.h
 
-COMMON = -pthread -lrt -g -Wall
+COMMON = -pthread -lrt -g -Wall -D_STM_NURSERY_ZEROED=1
 
 
 all: duhton_debug duhton duhton_release


More information about the pypy-commit mailing list