Improve the newSpark dud test by using the pointer tag bits
authorDuncan Coutts <duncan@well-typed.com>
Wed, 1 Jun 2011 16:16:29 +0000 (17:16 +0100)
committerDuncan Coutts <duncan@well-typed.com>
Mon, 18 Jul 2011 15:31:13 +0000 (16:31 +0100)
newSpark() checks if the spark is a dud, and if so does not add it to
the spark pool. Previously, newSpark would discard the pointer tag bits
and just check closure_SHOULD_SPARK(p). We can take advantage of the
tag bits which can tell us if the pointer points to a value. If it is,
it's a dud spark and we don't need to add it to the spark pool.

rts/Sparks.c
rts/Sparks.h

index a826190..18d9597 100644 (file)
@@ -63,13 +63,7 @@ newSpark (StgRegTable *reg, StgClosure *p)
     Capability *cap = regTableToCapability(reg);
     SparkPool *pool = cap->sparks;
 
-    /* I am not sure whether this is the right thing to do.
-     * Maybe it is better to exploit the tag information
-     * instead of throwing it away?
-     */
-    p = UNTAG_CLOSURE(p);
-
-    if (closure_SHOULD_SPARK(p)) {
+    if (!fizzledSpark(p)) {
         pushWSDeque(pool,p);
         cap->sparks_created++;
     } else {
index cffe99d..d714cb5 100644 (file)
@@ -31,6 +31,8 @@ INLINE_HEADER StgClosure* reclaimSpark(SparkPool *pool);
 INLINE_HEADER rtsBool looksEmpty(SparkPool* deque);
 
 StgClosure * tryStealSpark     (Capability *cap);
+INLINE_HEADER rtsBool      fizzledSpark  (StgClosure *);
+
 void         freeSparkPool     (SparkPool *pool);
 void         createSparkThread (Capability *cap);
 void         traverseSparkQueue(evac_fn evac, void *user, Capability *cap);
@@ -63,6 +65,11 @@ INLINE_HEADER void discardSparks (SparkPool *pool)
     discardElements(pool);
 }
 
+INLINE_HEADER rtsBool fizzledSpark (StgClosure *spark)
+{
+    return (GET_CLOSURE_TAG(spark) != 0 || !closure_SHOULD_SPARK(spark));
+}
+
 #endif // THREADED_RTS
 
 #include "EndPrivate.h"