[pypy-commit] pypy stmgc-c4: Update to stmgc/6184784a65a0

arigo noreply at buildbot.pypy.org
Thu Sep 26 11:17:39 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c4
Changeset: r67106:dedb55addb8d
Date: 2013-09-26 08:20 +0200
http://bitbucket.org/pypy/pypy/changeset/dedb55addb8d/

Log:	Update to stmgc/6184784a65a0

diff --git a/rpython/translator/stm/src_stm/dbgmem.c b/rpython/translator/stm/src_stm/dbgmem.c
--- a/rpython/translator/stm/src_stm/dbgmem.c
+++ b/rpython/translator/stm/src_stm/dbgmem.c
@@ -15,6 +15,7 @@
 static char *zone_start, *zone_current = NULL, *zone_end = NULL;
 static signed char accessible_pages[MMAP_TOTAL / PAGE_SIZE] = {0};
 
+int stm_use_mprotect = 1;
 
 static void _stm_dbgmem(void *p, size_t sz, int prot)
 {
@@ -25,9 +26,11 @@
     intptr_t align = ((intptr_t)p) & (PAGE_SIZE-1);
     p = ((char *)p) - align;
     sz += align;
-    dprintf(("dbgmem: %p, %ld, %d\n", p, (long)sz, prot));
-    int err = mprotect(p, sz, prot);
-    assert(err == 0);
+    if (stm_use_mprotect) {
+        dprintf(("dbgmem: %p, %ld, %d\n", p, (long)sz, prot));
+        int err = mprotect(p, sz, prot);
+        assert(err == 0);
+    }
 }
 
 void *stm_malloc(size_t sz)
@@ -37,7 +40,7 @@
 #ifdef _GC_MEMPROTECT
     pthread_mutex_lock(&malloc_mutex);
     if (zone_current == NULL) {
-        zone_start = mmap(NULL, MMAP_TOTAL, PROT_NONE,
+        zone_start = mmap(NULL, MMAP_TOTAL, PROT_READ | PROT_WRITE,
                           MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
         if (zone_start == NULL || zone_start == MAP_FAILED) {
             stm_fatalerror("not enough memory: mmap() failed\n");
diff --git a/rpython/translator/stm/src_stm/et.c b/rpython/translator/stm/src_stm/et.c
--- a/rpython/translator/stm/src_stm/et.c
+++ b/rpython/translator/stm/src_stm/et.c
@@ -1017,7 +1017,12 @@
 
   // jump back to the setjmp_buf (this call does not return)
   stm_stop_sharedlock();
-  longjmp(*d->setjmp_buf, 1);
+  if (d->longjmp_callback != NULL)
+    d->longjmp_callback(d->setjmp_buf);
+  else
+    longjmp(*(jmp_buf *)d->setjmp_buf, 1);
+
+  stm_fatalerror("longjmp() call should not return");
 }
 
 void AbortTransactionAfterCollect(struct tx_descriptor *d, int reason)
@@ -1084,12 +1089,13 @@
   gcptrlist_clear(&d->abortinfo);
 }
 
-void BeginTransaction(jmp_buf* buf)
+void stm_begin_transaction(void *buf, void (*longjmp_callback)(void *))
 {
   struct tx_descriptor *d = thread_descriptor;
   init_transaction(d);
   d->active = 1;
   d->setjmp_buf = buf;
+  d->longjmp_callback = longjmp_callback;
   d->old_thread_local_obj = stm_thread_local_obj;
   d->start_time = GetGlobalCurTime(d);
   update_reads_size_limit(d);
diff --git a/rpython/translator/stm/src_stm/et.h b/rpython/translator/stm/src_stm/et.h
--- a/rpython/translator/stm/src_stm/et.h
+++ b/rpython/translator/stm/src_stm/et.h
@@ -160,7 +160,8 @@
 struct tx_descriptor {
   struct tx_public_descriptor *public_descriptor;
   revision_t public_descriptor_index;
-  jmp_buf *setjmp_buf;
+  void *setjmp_buf;
+  void(*longjmp_callback)(void *);
   revision_t start_time;
   revision_t my_lock;
   gcptr *shadowstack;
@@ -206,7 +207,6 @@
 /************************************************************/
 
 
-void BeginTransaction(jmp_buf *);
 void BeginInevitableTransaction(void);  /* must save roots around this call */
 void CommitTransaction(void);           /* must save roots around this call */
 void BecomeInevitable(const char *why); /* must save roots around this call */
diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-111c09337109
+6184784a65a0
diff --git a/rpython/translator/stm/src_stm/stmgc.h b/rpython/translator/stm/src_stm/stmgc.h
--- a/rpython/translator/stm/src_stm/stmgc.h
+++ b/rpython/translator/stm/src_stm/stmgc.h
@@ -122,6 +122,12 @@
 void stm_begin_inevitable_transaction(void);
 void stm_become_inevitable(const char *reason);
 
+/* specialized usage: for custom setjmp/longjmp implementation.
+   Must save roots around calls. */
+void stm_begin_transaction(void *buf, void (*longjmp_callback)(void *));
+void stm_transaction_break(void *buf, void (*longjmp_callback)(void *));
+void stm_invalidate_jmp_buf(void *buf);
+
 /* debugging: check if we're currently running a transaction or not. */
 int stm_in_transaction(void);
 
diff --git a/rpython/translator/stm/src_stm/stmsync.c b/rpython/translator/stm/src_stm/stmsync.c
--- a/rpython/translator/stm/src_stm/stmsync.c
+++ b/rpython/translator/stm/src_stm/stmsync.c
@@ -177,7 +177,7 @@
             d->reads_size_limit_nonatomic = limit;
         }
         if (!d->atomic) {
-            BeginTransaction(&_jmpbuf);
+            stm_begin_transaction(&_jmpbuf, NULL);
         }
         else {
             /* atomic transaction: a common case is that callback() returned
@@ -214,6 +214,35 @@
     assert(stm_shadowstack == v_saved_value);
 }
 
+void stm_transaction_break(void *buf, void (*longjmp_callback)(void *))
+{   /* must save roots around this call */
+    struct tx_descriptor *d = thread_descriptor;
+    if (d->atomic) {
+        assert(d->active >= 1);
+        stm_possible_safe_point();
+    }
+    else {
+        CommitTransaction();
+        if (d->active != 2) {
+            unsigned long limit = d->reads_size_limit_nonatomic;
+            if (limit != 0 && limit < (stm_regular_length_limit >> 1))
+                limit = (limit << 1) | 1;
+            else
+                limit = stm_regular_length_limit;
+            d->reads_size_limit_nonatomic = limit;
+        }
+        stm_begin_transaction(buf, longjmp_callback);
+    }
+}
+
+void stm_invalidate_jmp_buf(void *buf)
+{   /* must save roots around this call */
+    struct tx_descriptor *d = thread_descriptor;
+    if (d->setjmp_buf == buf) {
+        BecomeInevitable("stm_invalidate_jmp_buf with atomic");
+    }
+}
+
 void stm_commit_transaction(void)
 {   /* must save roots around this call */
     struct tx_descriptor *d = thread_descriptor;


More information about the pypy-commit mailing list