void xpc_PrintAllReferencesTo(void *p) { /* p must be a JS object */ XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); JS_DumpHeap(rt->GetJSRuntime(), stdout, nullptr, JSTRACE_OBJECT, p, 0x7fffffff, nullptr); }
void ScriptInterface::DumpHeap() { #if MOZJS_DEBUG_ABI JS_DumpHeap(GetJSRuntime(), stderr, NULL, JSTRACE_OBJECT, NULL, (size_t)-1, NULL); #endif fprintf(stderr, "# Bytes allocated: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES)); JS_GC(GetJSRuntime()); fprintf(stderr, "# Bytes allocated after GC: %u\n", JS_GetGCParameter(GetJSRuntime(), JSGC_BYTES)); }
void DumpHeap(const char* basename, int idx, JSContext* cx) { char filename[64]; sprintf_s(filename, ARRAY_SIZE(filename), "%s.%03d.txt", basename, idx); OsPath pathname = psLogDir() / filename; FILE* f = sys_OpenFile(pathname, "w"); ENSURE(f); JS_DumpHeap(cx, f, NULL, 0, NULL, (size_t)-1, NULL); fclose(f); }
/** * Dump the JS heap. * * arguments: start, find, maxDepth, ignore, filename * default: all, null, 1000, null, /dev/stdout */ static JSBool vm_dumpHeap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { #if defined(DEBUG) JSObject *start = NULL, *find = NULL, *ignore = NULL; int32 maxDepth = 1000; char *filename = (char *)"/dev/stdout"; FILE *file; JSBool b; if (JS_ConvertArguments(cx, argc, argv, "ooios", &start, &find, &maxDepth, &ignore, &filename) == JS_FALSE) return JS_FALSE; file = fopen(filename, "r"); if (!file) return gpsee_throw(cx, MODULE_ID ".dumpHeap.fopen: %m"); b = JS_DumpHeap(cx, file, start, 0, find, maxDepth, ignore); fclose(file); return b; #else return gpsee_throw(cx, MODULE_ID ".dumpHeap.undefined: requires a debug JSAPI build"); #endif }
static JSBool DumpHeap(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { char *fileName = NULL; void* startThing = NULL; uint32 startTraceKind = 0; void *thingToFind = NULL; size_t maxDepth = (size_t)-1; void *thingToIgnore = NULL; jsval *vp; FILE *dumpFile; JSBool ok; vp = &argv[0]; if (*vp != JSVAL_NULL && *vp != JSVAL_VOID) { JSString *str; str = JS_ValueToString(cx, *vp); if (!str) return JS_FALSE; *vp = STRING_TO_JSVAL(str); fileName = JS_GetStringBytes(str); } vp = &argv[1]; if (*vp != JSVAL_NULL && *vp != JSVAL_VOID) { if (!JSVAL_IS_TRACEABLE(*vp)) goto not_traceable_arg; startThing = JSVAL_TO_TRACEABLE(*vp); startTraceKind = JSVAL_TRACE_KIND(*vp); } vp = &argv[2]; if (*vp != JSVAL_NULL && *vp != JSVAL_VOID) { if (!JSVAL_IS_TRACEABLE(*vp)) goto not_traceable_arg; thingToFind = JSVAL_TO_TRACEABLE(*vp); } vp = &argv[3]; if (*vp != JSVAL_NULL && *vp != JSVAL_VOID) { uint32 depth; if (!JS_ValueToECMAUint32(cx, *vp, &depth)) return JS_FALSE; maxDepth = depth; } vp = &argv[4]; if (*vp != JSVAL_NULL && *vp != JSVAL_VOID) { if (!JSVAL_IS_TRACEABLE(*vp)) goto not_traceable_arg; thingToIgnore = JSVAL_TO_TRACEABLE(*vp); } if (!fileName) { dumpFile = gOutFile; } else { dumpFile = fopen(fileName, "w"); if (!dumpFile) { fprintf(gErrFile, "dumpHeap: can't open %s: %s\n", fileName, strerror(errno)); return JS_FALSE; } } ok = JS_DumpHeap(cx, dumpFile, startThing, startTraceKind, thingToFind, maxDepth, thingToIgnore); if (dumpFile != gOutFile) fclose(dumpFile); return ok; not_traceable_arg: fprintf(gErrFile, "dumpHeap: argument %u is not null or a heap-allocated thing\n", (unsigned)(vp - argv)); return JS_FALSE; }