This can reduce performance, so should be used for debugging only. js::CollectNurseryBeforeDump() promotes any live objects in the nursery to the tenured heap. This is slow, but this way, we are certain to get an accurate picture of the heap.
| 109 | // the tenured heap. This is slow, but this way, we are certain to get an |
| 110 | // accurate picture of the heap. |
| 111 | static bool gjs_dump_heap(JSContext* cx, unsigned argc, JS::Value* vp) { |
| 112 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 113 | Gjs::AutoChar filename; |
| 114 | |
| 115 | if (!gjs_parse_call_args(cx, "dumpHeap", args, "|F", "filename", &filename)) |
| 116 | return false; |
| 117 | |
| 118 | LogFile file(filename); |
| 119 | if (file.has_error()) { |
| 120 | gjs_throw(cx, "Cannot dump heap to %s: %s", filename.get(), |
| 121 | file.errmsg()); |
| 122 | return false; |
| 123 | } |
| 124 | js::DumpHeap(cx, file.fp(), js::CollectNurseryBeforeDump); |
| 125 | |
| 126 | gjs_debug(GJS_DEBUG_CONTEXT, "Heap dumped to %s", |
| 127 | filename ? filename.get() : "stdout"); |
| 128 | |
| 129 | args.rval().setUndefined(); |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | static bool gjs_gc(JSContext* cx, unsigned argc, JS::Value* vp) { |
| 134 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |