[pypy-commit] pypy stmgc-c7: Use stm_call_on_commit() to delay the raw free().

arigo noreply at buildbot.pypy.org
Tue Aug 19 19:05:57 CEST 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r72913:0febb0d1b4e7
Date: 2014-08-19 19:05 +0200
http://bitbucket.org/pypy/pypy/changeset/0febb0d1b4e7/

Log:	Use stm_call_on_commit() to delay the raw free().

diff --git a/rpython/translator/c/src/mem.c b/rpython/translator/c/src/mem.c
--- a/rpython/translator/c/src/mem.c
+++ b/rpython/translator/c/src/mem.c
@@ -12,7 +12,7 @@
 # else
 #  define try_pypy_debug_alloc_stop(p)  /* nothing */
 # endif
-void _pypy_stm_free(void *ptr)
+void _pypy_stm_cb_free(void *ptr)
 {
     /* This is called by src_stm/et.c when the transaction is aborted
        and the 'ptr' was malloced but not freed.  We have first to
@@ -24,6 +24,22 @@
     PyObject_Free(ptr);
     COUNT_FREE;
 }
+void _pypy_stm_op_free(void *ptr)
+{
+    /* Called when RPython code contains OP_FREE or OP_RAW_FREE.
+     */
+    if (stm_call_on_abort(&stm_thread_local, ptr, NULL) == 0) {
+        /* There is a running non-inevitable transaction, but the object
+           was not registered during it, which means that it was created
+           before.  In this case, we cannot immediately free it, but
+           only when a commit follows. */
+        stm_call_on_commit(&stm_thread_local, ptr, _pypy_stm_cb_free);
+    }
+    else {
+        /* In all other cases, free the object immediately. */
+        _pypy_stm_cb_free(ptr);
+    }
+}
 #endif
 
 
diff --git a/rpython/translator/c/src/mem.h b/rpython/translator/c/src/mem.h
--- a/rpython/translator/c/src/mem.h
+++ b/rpython/translator/c/src/mem.h
@@ -16,13 +16,14 @@
 
 
 #ifdef RPY_STM
-void _pypy_stm_free(void *);
+void _pypy_stm_cb_free(void *);
+void _pypy_stm_op_free(void *);
 #define _OP_RAW_MALLOCED(r)       stm_call_on_abort(&stm_thread_local, r,   \
-                                                                _pypy_stm_free)
-#define _OP_RAW_STM_UNREGISTER(r) stm_call_on_abort(&stm_thread_local, r, NULL)
+                                                             _pypy_stm_cb_free)
+#define OP_FREE(p)                _pypy_stm_op_free(p)
 #else
-#define _OP_RAW_MALLOCED(r)         /* nothing */
-#define _OP_RAW_STM_UNREGISTER(r)   /* nothing */
+#define _OP_RAW_MALLOCED(r)       /* nothing */
+#define OP_FREE(p)                PyObject_Free(p); COUNT_FREE
 #endif
 
 
@@ -34,8 +35,7 @@
 	}								\
     }
 
-#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE; \
-                          _OP_RAW_STM_UNREGISTER(p);
+#define OP_RAW_FREE(p, r) OP_FREE(p)
 
 #define OP_RAW_MEMCLEAR(p, size, r) memset((void*)p, 0, size)
 
@@ -54,8 +54,6 @@
 
 /************************************************************/
 
-#define OP_FREE(p)	OP_RAW_FREE(p, do_not_use)
-
 #ifndef COUNT_OP_MALLOCS
 
 #define COUNT_MALLOC	/* nothing */
@@ -87,7 +85,11 @@
 
 #  define OP_TRACK_ALLOC_START(addr, r)  pypy_debug_alloc_start(addr, \
                                                                 __FUNCTION__)
-#  define OP_TRACK_ALLOC_STOP(addr, r)   pypy_debug_alloc_stop(addr)
+#  ifdef RPY_STM
+#    define OP_TRACK_ALLOC_STOP(addr, r)   /* nothing */
+#  else
+#    define OP_TRACK_ALLOC_STOP(addr, r)   pypy_debug_alloc_stop(addr)
+#  endif
 
 void pypy_debug_alloc_start(void*, const char*);
 void pypy_debug_alloc_stop(void*);
diff --git a/rpython/translator/stm/inevitable.py b/rpython/translator/stm/inevitable.py
--- a/rpython/translator/stm/inevitable.py
+++ b/rpython/translator/stm/inevitable.py
@@ -96,7 +96,7 @@
     if op.opname in MALLOCS:
         return False
     if op.opname in FREES:
-        return True
+        return False
     #
     # Function calls
     if op.opname == 'direct_call' or op.opname == 'indirect_call':


More information about the pypy-commit mailing list