bug 683862 - Using JSGCTraceKind in the public API. r=luke

This commit is contained in:
Igor Bukanov 2011-09-01 20:43:46 +02:00
parent 46c2f6aa69
commit 4e89b5ccc4
11 changed files with 58 additions and 63 deletions

View File

@ -447,7 +447,7 @@ DumpHeap(JSContext *cx,
{
JSAutoByteString fileName;
void* startThing = NULL;
uint32 startTraceKind = 0;
JSGCTraceKind startTraceKind = JSTRACE_OBJECT;
void *thingToFind = NULL;
size_t maxDepth = (size_t)-1;
void *thingToIgnore = NULL;

View File

@ -2860,7 +2860,7 @@ jsdService::DumpHeap(const nsACString &fileName)
rv = NS_ERROR_FAILURE;
} else {
JSContext *cx = JSD_GetDefaultJSContext (mCx);
if (!JS_DumpHeap(cx, file, NULL, 0, NULL, (size_t)-1, NULL))
if (!JS_DumpHeap(cx, file, NULL, JSTRACE_OBJECT, NULL, (size_t)-1, NULL))
rv = NS_ERROR_FAILURE;
if (file != stdout)
fclose(file);

View File

@ -2192,11 +2192,10 @@ JS_TraceRuntime(JSTracer *trc)
}
JS_PUBLIC_API(void)
JS_CallTracer(JSTracer *trc, void *thing, uint32 kind)
JS_CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
JS_ASSERT(thing);
JS_ASSERT(kind <= JSTRACE_LAST);
MarkKind(trc, thing, JSGCTraceKind(kind));
MarkKind(trc, thing, kind);
}
#ifdef DEBUG
@ -2206,12 +2205,10 @@ JS_CallTracer(JSTracer *trc, void *thing, uint32 kind)
#endif
JS_PUBLIC_API(void)
JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing, uint32 kindIndex,
JSBool details)
JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc, void *thing,
JSGCTraceKind kind, JSBool details)
{
JS_ASSERT(kindIndex <= JSTRACE_LAST);
JSGCTraceKind kind = JSGCTraceKind(kindIndex);
const char *name;
const char *name = NULL; /* silence uninitialized warning */
size_t n;
if (bufsize == 0)
@ -2336,7 +2333,7 @@ typedef struct JSHeapDumpNode JSHeapDumpNode;
struct JSHeapDumpNode {
void *thing;
uint32 kind;
JSGCTraceKind kind;
JSHeapDumpNode *next; /* next sibling */
JSHeapDumpNode *parent; /* node with the thing that refer to thing
from this node */
@ -2357,7 +2354,7 @@ typedef struct JSDumpingTracer {
} JSDumpingTracer;
static void
DumpNotify(JSTracer *trc, void *thing, uint32 kind)
DumpNotify(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
JSDumpingTracer *dtrc;
JSContext *cx;
@ -2501,7 +2498,7 @@ DumpNode(JSDumpingTracer *dtrc, FILE* fp, JSHeapDumpNode *node)
}
JS_PUBLIC_API(JSBool)
JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, JSGCTraceKind startKind,
void *thingToFind, size_t maxDepth, void *thingToIgnore)
{
JSDumpingTracer dtrc;
@ -2527,7 +2524,7 @@ JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
node = NULL;
dtrc.lastNodep = &node;
if (!startThing) {
JS_ASSERT(startKind == 0);
JS_ASSERT(startKind == JSTRACE_OBJECT);
TraceRuntime(&dtrc.base);
} else {
JS_TraceChildren(&dtrc.base, startThing, startKind);

View File

@ -1610,8 +1610,8 @@ typedef enum {
JSTRACE_SCRIPT,
/*
* Trace kinds internal to the engine. JSTraceCallback implementation can
* only call JS_TraceChildren on them.
* Trace kinds internal to the engine. The embedding can only them if it
* implements JSTraceCallback.
*/
#if JS_HAS_XML_SUPPORT
JSTRACE_XML,
@ -1639,15 +1639,30 @@ JSVAL_TO_TRACEABLE(jsval v)
return JSVAL_TO_GCTHING(v);
}
static JS_ALWAYS_INLINE uint32
static JS_ALWAYS_INLINE JSGCTraceKind
JSVAL_TRACE_KIND(jsval v)
{
jsval_layout l;
JS_ASSERT(JSVAL_IS_GCTHING(v));
l.asBits = JSVAL_BITS(v);
return JSVAL_TRACE_KIND_IMPL(l);
return (JSGCTraceKind) JSVAL_TRACE_KIND_IMPL(l);
}
/*
* Tracer callback, called for each traceable thing directly referenced by a
* particular object or runtime structure. It is the callback responsibility
* to ensure the traversal of the full object graph via calling eventually
* JS_TraceChildren on the passed thing. In this case the callback must be
* prepared to deal with cycles in the traversal graph.
*
* kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting
* internal implementation-specific traversal kind. In the latter case the only
* operations on thing that the callback can do is to call JS_TraceChildren or
* DEBUG-only JS_PrintTraceThingInfo.
*/
typedef void
(* JSTraceCallback)(JSTracer *trc, void *thing, JSGCTraceKind kind);
struct JSTracer {
JSContext *context;
JSTraceCallback callback;
@ -1663,7 +1678,7 @@ struct JSTracer {
* describing the reference using the macros below.
*/
extern JS_PUBLIC_API(void)
JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
JS_CallTracer(JSTracer *trc, void *thing, JSGCTraceKind kind);
/*
* Set debugging information about a reference to a traceable thing to prepare
@ -1756,7 +1771,7 @@ JS_CallTracer(JSTracer *trc, void *thing, uint32 kind);
JS_END_MACRO
extern JS_PUBLIC_API(void)
JS_TraceChildren(JSTracer *trc, void *thing, uint32 kind);
JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind);
extern JS_PUBLIC_API(void)
JS_TraceRuntime(JSTracer *trc);
@ -1765,7 +1780,7 @@ JS_TraceRuntime(JSTracer *trc);
extern JS_PUBLIC_API(void)
JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
void *thing, uint32 kind, JSBool includeDetails);
void *thing, JSGCTraceKind kind, JSBool includeDetails);
/*
* DEBUG-only method to dump the object graph of heap-allocated things.
@ -1774,8 +1789,8 @@ JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
* start: when non-null, dump only things reachable from start
* thing. Otherwise dump all things reachable from the
* runtime roots.
* startKind: trace kind of start if start is not null. Must be 0 when
* start is null.
* startKind: trace kind of start if start is not null. Must be
* JSTRACE_OBJECT when start is null.
* thingToFind: dump only paths in the object graph leading to thingToFind
* when non-null.
* maxDepth: the upper bound on the number of edges to descend from the
@ -1783,7 +1798,7 @@ JS_PrintTraceThingInfo(char *buf, size_t bufsize, JSTracer *trc,
* thingToIgnore: thing to ignore during the graph traversal when non-null.
*/
extern JS_PUBLIC_API(JSBool)
JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, uint32 startKind,
JS_DumpHeap(JSContext *cx, FILE *fp, void* startThing, JSGCTraceKind kind,
void *thingToFind, size_t maxDepth, void *thingToIgnore);
#endif

View File

@ -1620,7 +1620,7 @@ GCMarker::markDelayedChildren()
#ifdef DEBUG
static void
EmptyMarkCallback(JSTracer *trc, void *thing, uint32 kind)
EmptyMarkCallback(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
}
#endif

View File

@ -1011,13 +1011,10 @@ GCMarker::drainMarkStack()
} /* namespace js */
JS_PUBLIC_API(void)
JS_TraceChildren(JSTracer *trc, void *thing, uint32 kindIndex)
JS_TraceChildren(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
JS_ASSERT(kindIndex <= JSTRACE_LAST);
JSGCTraceKind kind = JSGCTraceKind(kindIndex);
switch (kind) {
default:
JS_ASSERT(kind == JSTRACE_OBJECT);
case JSTRACE_OBJECT:
MarkChildren(trc, static_cast<JSObject *>(thing));
break;

View File

@ -359,21 +359,6 @@ typedef JSBool
typedef void
(* JSTraceOp)(JSTracer *trc, JSObject *obj);
/*
* Tracer callback, called for each traceable thing directly referenced by a
* particular object or runtime structure. It is the callback responsibility
* to ensure the traversal of the full object graph via calling eventually
* JS_TraceChildren on the passed thing. In this case the callback must be
* prepared to deal with cycles in the traversal graph.
*
* kind argument is one of JSTRACE_OBJECT, JSTRACE_STRING or a tag denoting
* internal implementation-specific traversal kind. In the latter case the only
* operations on thing that the callback can do is to call JS_TraceChildren or
* DEBUG-only JS_PrintTraceThingInfo.
*/
typedef void
(* JSTraceCallback)(JSTracer *trc, void *thing, uint32 kind);
/*
* DEBUG only callback that JSTraceOp implementation can provide to return
* a string describing the reference traced with JS_CallTracer.

View File

@ -1364,7 +1364,7 @@ typedef struct JSCountHeapNode JSCountHeapNode;
struct JSCountHeapNode {
void *thing;
int32 kind;
JSGCTraceKind kind;
JSCountHeapNode *next;
};
@ -1377,7 +1377,7 @@ typedef struct JSCountHeapTracer {
} JSCountHeapTracer;
static void
CountHeapNotify(JSTracer *trc, void *thing, uint32 kind)
CountHeapNotify(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
JSCountHeapTracer *countTracer;
JSDHashEntryStub *entry;
@ -1419,7 +1419,7 @@ static JSBool
CountHeap(JSContext *cx, uintN argc, jsval *vp)
{
void* startThing;
int32 startTraceKind;
JSGCTraceKind startTraceKind;
jsval v;
int32 traceKind, i;
JSString *str;
@ -1440,7 +1440,7 @@ CountHeap(JSContext *cx, uintN argc, jsval *vp)
};
startThing = NULL;
startTraceKind = 0;
startTraceKind = JSTRACE_OBJECT;
if (argc > 0) {
v = JS_ARGV(cx, vp)[0];
if (JSVAL_IS_TRACEABLE(v)) {
@ -2370,7 +2370,7 @@ DumpHeap(JSContext *cx, uintN argc, jsval *vp)
{
jsval v;
void* startThing;
uint32 startTraceKind;
JSGCTraceKind startTraceKind;
const char *badTraceArg;
void *thingToFind;
size_t maxDepth;
@ -2396,7 +2396,7 @@ DumpHeap(JSContext *cx, uintN argc, jsval *vp)
}
startThing = NULL;
startTraceKind = 0;
startTraceKind = JSTRACE_OBJECT;
if (argc > 1) {
v = JS_ARGV(cx, vp)[1];
if (JSVAL_IS_TRACEABLE(v)) {

View File

@ -87,7 +87,8 @@ class HeapReverser : public JSTracer {
class Node {
public:
Node() { }
Node(uint32 kind) : kind(kind), incoming(), marked(false) { }
Node(JSGCTraceKind kind)
: kind(kind), incoming(), marked(false) { }
/*
* Move constructor and move assignment. These allow us to store our
@ -103,7 +104,7 @@ class HeapReverser : public JSTracer {
}
/* What kind of Cell this is. */
uint32 kind;
JSGCTraceKind kind;
/*
* A vector of this Cell's incoming edges.
@ -199,9 +200,9 @@ class HeapReverser : public JSTracer {
/* A work item in the stack of nodes whose children we need to traverse. */
struct Child {
Child(void *cell, uint32 kind) : cell(cell), kind(kind) { }
Child(void *cell, JSGCTraceKind kind) : cell(cell), kind(kind) { }
void *cell;
uint32 kind;
JSGCTraceKind kind;
};
/*
@ -214,7 +215,7 @@ class HeapReverser : public JSTracer {
void *parent;
/* Traverse an edge. */
bool traverseEdge(void *cell, uint32 kind);
bool traverseEdge(void *cell, JSGCTraceKind kind);
/*
* JS_TraceRuntime and JS_TraceChildren don't propagate error returns,
@ -225,14 +226,14 @@ class HeapReverser : public JSTracer {
bool traversalStatus;
/* Static member function wrapping 'traverseEdge'. */
static void traverseEdgeWithThis(JSTracer *tracer, void *cell, uint32 kind) {
static void traverseEdgeWithThis(JSTracer *tracer, void *cell, JSGCTraceKind kind) {
HeapReverser *reverser = static_cast<HeapReverser *>(tracer);
reverser->traversalStatus = reverser->traverseEdge(cell, kind);
}
};
bool
HeapReverser::traverseEdge(void *cell, uint32 kind) {
HeapReverser::traverseEdge(void *cell, JSGCTraceKind kind) {
/* Capture this edge before the JSTracer members get overwritten. */
char *edgeDescription = getEdgeDescription();
if (!edgeDescription)

View File

@ -576,7 +576,7 @@ static JSBool
DumpHeap(JSContext *cx, uintN argc, jsval *vp)
{
void* startThing = NULL;
uint32 startTraceKind = 0;
JSGCTraceKind startTraceKind = JSTRACE_OBJECT;
void *thingToFind = NULL;
size_t maxDepth = (size_t)-1;
void *thingToIgnore = NULL;

View File

@ -223,7 +223,7 @@ nsXPConnect::ReleaseXPConnectSingleton()
: fopen(dumpName, "w");
if(dumpFile)
{
JS_DumpHeap(ccx, dumpFile, nsnull, 0, nsnull,
JS_DumpHeap(ccx, dumpFile, nsnull, JSTRACE_OBJECT, nsnull,
static_cast<size_t>(-1), nsnull);
if(dumpFile != stdout)
fclose(dumpFile);
@ -619,7 +619,7 @@ xpc_GCThingIsGrayCCThing(void *thing)
* re-coloring.
*/
static void
UnmarkGrayChildren(JSTracer *trc, void *thing, uint32 kind)
UnmarkGrayChildren(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
int stackDummy;
if (!JS_CHECK_STACK_SIZE(trc->context->stackLimit, &stackDummy)) {
@ -675,7 +675,7 @@ struct TraversalTracer : public JSTracer
};
static void
NoteJSChild(JSTracer *trc, void *thing, uint32 kind)
NoteJSChild(JSTracer *trc, void *thing, JSGCTraceKind kind)
{
if(AddToCCKind(kind))
{
@ -732,7 +732,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb)
{
JSContext *cx = mCycleCollectionContext->GetJSContext();
uint32 traceKind = js_GetGCThingTraceKind(p);
JSGCTraceKind traceKind = js_GetGCThingTraceKind(p);
JSObject *obj;
js::Class *clazz;