[pypy-commit] stmgc default: Optimize

arigo noreply at buildbot.pypy.org
Thu Jun 27 19:45:02 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r313:bf59a2c0e4eb
Date: 2013-06-27 19:44 +0200
http://bitbucket.org/pypy/stmgc/changeset/bf59a2c0e4eb/

Log:	Optimize

diff --git a/c4/et.h b/c4/et.h
--- a/c4/et.h
+++ b/c4/et.h
@@ -66,7 +66,7 @@
 static const revision_t GCFLAG_PUBLIC                 = STM_FIRST_GCFLAG << 2;
 static const revision_t GCFLAG_PREBUILT_ORIGINAL      = STM_FIRST_GCFLAG << 3;
 static const revision_t GCFLAG_PUBLIC_TO_PRIVATE      = STM_FIRST_GCFLAG << 4;
-static const revision_t GCFLAG_WRITE_BARRIER          = STM_FIRST_GCFLAG << 5;
+// in stmgc.h:          GCFLAG_WRITE_BARRIER          = STM_FIRST_GCFLAG << 5;
 static const revision_t GCFLAG_NURSERY_MOVED          = STM_FIRST_GCFLAG << 6;
 static const revision_t GCFLAG_BACKUP_COPY  /*debug*/ = STM_FIRST_GCFLAG << 7;
 static const revision_t GCFLAG_STUB         /*debug*/ = STM_FIRST_GCFLAG << 8;
diff --git a/c4/lists.h b/c4/lists.h
--- a/c4/lists.h
+++ b/c4/lists.h
@@ -185,7 +185,7 @@
    more.
 */
 
-#define FX_MASK      65535
+//#define FX_MASK      65535    in stmgc.h
 #define FX_ENTRIES   ((FX_MASK + 1) / sizeof(char *))
 #define FX_TOTAL     (FX_ENTRIES * 4 / 3)
 
@@ -206,8 +206,9 @@
     stm_read_barrier_cache = (char *)(fxcache->cache + fxcache->shift);
 }
 
-#define FXCACHE_AT(obj)  \
-    (*(gcptr *)(stm_read_barrier_cache + ((revision_t)(obj) & FX_MASK)))
+// moved to stmgc.h:
+//#define FXCACHE_AT(obj)
+//    (*(gcptr *)(stm_read_barrier_cache + ((revision_t)(obj) & FX_MASK)))
 
 static inline void fxcache_add(struct FXCache *fxcache, gcptr newobj)
 {
diff --git a/c4/stmgc.h b/c4/stmgc.h
--- a/c4/stmgc.h
+++ b/c4/stmgc.h
@@ -39,17 +39,20 @@
 _Bool stm_pointer_equal(gcptr, gcptr);
 
 /* to push/pop objects into the local shadowstack */
-/* (could be turned into macros or something later) */
+#if 0     // (optimized version below)
 void stm_push_root(gcptr);
 gcptr stm_pop_root(void);
+#endif
 
 /* initialize/deinitialize the stm framework in the current thread */
 void stm_initialize(void);
 void stm_finalize(void);
 
 /* read/write barriers (the most general versions only for now) */
+#if 0     // (optimized version below)
 gcptr stm_read_barrier(gcptr);
 gcptr stm_write_barrier(gcptr);
+#endif
 
 /* start a new transaction, calls callback(), and when it returns
    finish that transaction.  callback() is called with the 'arg'
@@ -81,4 +84,44 @@
    It is set to NULL by stm_initialize(). */
 extern __thread gcptr stm_thread_local_obj;
 
+
+
+/* macro-like functionality */
+
+extern __thread gcptr *stm_shadowstack;
+
+static inline void stm_push_root(gcptr obj) {
+    *stm_shadowstack++ = obj;
+}
+static inline gcptr stm_pop_root(void) {
+    return *--stm_shadowstack;
+}
+
+extern __thread revision_t stm_private_rev_num;
+gcptr stm_DirectReadBarrier(gcptr);
+gcptr stm_WriteBarrier(gcptr);
+static const revision_t GCFLAG_WRITE_BARRIER = STM_FIRST_GCFLAG << 5;
+extern __thread char *stm_read_barrier_cache;
+#define FX_MASK 65535
+#define FXCACHE_AT(obj)  \
+    (*(gcptr *)(stm_read_barrier_cache + ((revision_t)(obj) & FX_MASK)))
+
+#define UNLIKELY(test)  __builtin_expect(test, 0)
+static inline gcptr stm_read_barrier(gcptr obj) {
+    /* XXX optimize to get the smallest code */
+    if (UNLIKELY((obj->h_revision != stm_private_rev_num) &&
+                 (FXCACHE_AT(obj) != obj)))
+        obj = stm_DirectReadBarrier(obj);
+    return obj;
+}
+
+static inline gcptr stm_write_barrier(gcptr obj) {
+    if (UNLIKELY((obj->h_revision != stm_private_rev_num) |
+                 ((obj->h_tid & GCFLAG_WRITE_BARRIER) != 0)))
+        obj = stm_WriteBarrier(obj);
+    return obj;
+}
+#undef UNLIKELY
+
+
 #endif
diff --git a/c4/stmsync.c b/c4/stmsync.c
--- a/c4/stmsync.c
+++ b/c4/stmsync.c
@@ -4,7 +4,7 @@
 #define LENGTH_SHADOW_STACK   163840
 
 
-static __thread gcptr *stm_shadowstack;
+__thread gcptr *stm_shadowstack;
 static unsigned long stm_regular_length_limit = 10000;
 
 void stm_set_transaction_length(long length_max)
@@ -16,16 +16,6 @@
     stm_regular_length_limit = length_max;
 }
 
-void stm_push_root(gcptr obj)
-{
-    *stm_shadowstack++ = obj;
-}
-
-gcptr stm_pop_root(void)
-{
-    return *--stm_shadowstack;
-}
-
 static void init_shadowstack(void)
 {
     struct tx_descriptor *d = thread_descriptor;
@@ -75,27 +65,6 @@
     DescriptorDone();
 }
 
-gcptr stm_read_barrier(gcptr obj)
-{
-    //if (FXCACHE_AT(obj) == obj)
-    //    dprintf(("read_barrier: in cache: %p\n", obj));
-
-    /* XXX inline in the caller, optimize to get the smallest code */
-    if (UNLIKELY((obj->h_revision != stm_private_rev_num) &&
-                 (FXCACHE_AT(obj) != obj)))
-        obj = stm_DirectReadBarrier(obj);
-    return obj;
-}
-
-gcptr stm_write_barrier(gcptr obj)
-{
-    /* XXX inline in the caller */
-    if (UNLIKELY((obj->h_revision != stm_private_rev_num) |
-                 ((obj->h_tid & GCFLAG_WRITE_BARRIER) != 0)))
-        obj = stm_WriteBarrier(obj);
-    return obj;
-}
-
 /************************************************************/
 
 static revision_t sync_required = 0;


More information about the pypy-commit mailing list