summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2019-07-16 17:08:39 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-02-17 11:21:11 -0500
commitc0907fef5dbd35e7ac22ecc24be4180c4b6bd9be (patch)
tree294e485335603c100e439ce62d657056f27e55a8
parent937feda39e0cc79cd5d23d36f5a81155d992b9f9 (diff)
downloadhaskell-c0907fef5dbd35e7ac22ecc24be4180c4b6bd9be.tar.gz
rts: TraverseHeap: Move stackElement to header
The point of this is to let user code call traversePushClosure directly instead of going through traversePushRoot. This in turn allows specifying a stackElement to be used when the traversal returns from a top-level (root) closure.
-rw-r--r--rts/TraverseHeap.c68
-rw-r--r--rts/TraverseHeap.h65
2 files changed, 64 insertions, 69 deletions
diff --git a/rts/TraverseHeap.c b/rts/TraverseHeap.c
index 7f5278d878..8f8b62b2d0 100644
--- a/rts/TraverseHeap.c
+++ b/rts/TraverseHeap.c
@@ -32,72 +32,6 @@ bool isTravDataValid(const traverseState *ts, const StgClosure *c)
return (c->header.prof.hp.trav & 1) == ts->flip;
}
-typedef enum {
- // Object with fixed layout. Keeps an information about that
- // element was processed. (stackPos.next.step)
- posTypeStep,
- // Description of the pointers-first heap object. Keeps information
- // about layout. (stackPos.next.ptrs)
- posTypePtrs,
- // Keeps SRT bitmap (stackPos.next.srt)
- posTypeSRT,
- // Keeps a new object that was not inspected yet. Keeps a parent
- // element (stackPos.next.parent)
- posTypeFresh,
- // This stackElement is empty
- posTypeEmpty
-} nextPosType;
-
-typedef union {
- // fixed layout or layout specified by a field in the closure
- StgWord step;
-
- // layout.payload
- struct {
- // See StgClosureInfo in InfoTables.h
- StgHalfWord pos;
- StgHalfWord ptrs;
- StgPtr payload;
- } ptrs;
-
- // SRT
- struct {
- StgClosure *srt;
- } srt;
-
- // parent of the current closure, used only when posTypeFresh is set
- StgClosure *cp;
-} nextPos;
-
-/**
- * Position pointer into a closure. Determines what the next element to return
- * for a stackElement is.
- */
-typedef struct {
- nextPosType type;
- nextPos next;
-} stackPos;
-
-/**
- * An element of the traversal work-stack. Besides the closure itself this also
- * stores it's parent, associated data and an accumulator.
- *
- * When 'info.type == posTypeFresh' a 'stackElement' represents just one
- * closure, namely 'c' and 'cp' being it's parent. Otherwise 'info' specifies an
- * offset into the children of 'c'. This is to support returning a closure's
- * children one-by-one without pushing one element per child onto the stack. See
- * traverseGetChildren() and traversePop().
- *
- */
-typedef struct stackElement_ {
- stackPos info;
- StgClosure *c;
- stackElement *sep; // stackElement of parent closure
- stackData data;
- stackAccum accum;
-} stackElement;
-
-
#if defined(DEBUG)
unsigned int g_traversalDebugLevel = 0;
static inline void debug(const char *s, ...)
@@ -333,7 +267,7 @@ pushStackElement(traverseState *ts, const stackElement se)
* c - closure
* data - data associated with closure.
*/
-STATIC_INLINE void
+inline void
traversePushClosure(traverseState *ts, StgClosure *c, StgClosure *cp, stackElement *sep, stackData data) {
stackElement se;
diff --git a/rts/TraverseHeap.h b/rts/TraverseHeap.h
index e24b0aae87..8ea04dee32 100644
--- a/rts/TraverseHeap.h
+++ b/rts/TraverseHeap.h
@@ -16,8 +16,51 @@
#include "BeginPrivate.h"
+typedef enum {
+ // Object with fixed layout. Keeps an information about that
+ // element was processed. (stackPos.next.step)
+ posTypeStep,
+ // Description of the pointers-first heap object. Keeps information
+ // about layout. (stackPos.next.ptrs)
+ posTypePtrs,
+ // Keeps SRT bitmap (stackPos.next.srt)
+ posTypeSRT,
+ // Keeps a new object that was not inspected yet. Keeps a parent
+ // element (stackPos.next.parent)
+ posTypeFresh,
+ // This stackElement is empty
+ posTypeEmpty
+} nextPosType;
+
+typedef union {
+ // fixed layout or layout specified by a field in the closure
+ StgWord step;
+
+ // layout.payload
+ struct {
+ // See StgClosureInfo in InfoTables.h
+ StgHalfWord pos;
+ StgHalfWord ptrs;
+ StgPtr payload;
+ } ptrs;
+
+ // SRT
+ struct {
+ StgClosure *srt;
+ } srt;
+
+ // parent of the current closure, used only when posTypeFresh is set
+ StgClosure *cp;
+} nextPos;
-typedef struct traverseState_ traverseState;
+/**
+ * Position pointer into a closure. Determines what the next element to return
+ * for a stackElement is.
+ */
+typedef struct stackPos_ {
+ nextPosType type;
+ nextPos next;
+} stackPos;
typedef union stackData_ {
/**
@@ -30,7 +73,24 @@ typedef union stackAccum_ {
StgWord subtree_sizeW;
} stackAccum;
-typedef struct stackElement_ stackElement;
+/**
+ * An element of the traversal work-stack. Besides the closure itself this also
+ * stores it's parent, associated data and an accumulator.
+ *
+ * When 'info.type == posTypeFresh' a 'stackElement' represents just one
+ * closure, namely 'c' and 'cp' being it's parent. Otherwise 'info' specifies an
+ * offset into the children of 'c'. This is to support returning a closure's
+ * children one-by-one without pushing one element per child onto the stack. See
+ * traverseGetChildren() and traversePop().
+ *
+ */
+typedef struct stackElement_ {
+ stackPos info;
+ StgClosure *c;
+ struct stackElement_ *sep; // stackElement of parent closure
+ stackData data;
+ stackAccum accum;
+} stackElement;
typedef struct traverseState_ {
/** Note [Profiling heap traversal visited bit]
@@ -163,6 +223,7 @@ bool isTravDataValid(const traverseState *ts, const StgClosure *c);
void traverseWorkStack(traverseState *ts, visitClosure_cb visit_cb);
void traversePushRoot(traverseState *ts, StgClosure *c, StgClosure *cp, stackData data);
+void traversePushClosure(traverseState *ts, StgClosure *c, StgClosure *cp, stackElement *sep, stackData data);
bool traverseMaybeInitClosureData(const traverseState* ts, StgClosure *c);
void traverseInvalidateClosureData(traverseState* ts);