diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index 10d87c4bf1a08506443d834a23566ef534eae104..a230c6db85777622eee1c6e3baf73d011bdd2197 100755 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -723,17 +723,8 @@ void HeapSnapshot::FillNodes(bool isInFinish, bool isSimplify) LOG_ECMA(INFO) << "HeapSnapshot::FillNodes"; ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "HeapSnapshot::FillNodes", ""); // Iterate Heap Object - if (g_isEnableCMCGC) { - GenerateNodeRootVisitor visitor(*this, isInFinish, isSimplify); - rootVisitor_.VisitHeapRoots(vm_->GetJSThread(), visitor); - } else { - auto heap = vm_->GetHeap(); - if (heap != nullptr) { - heap->IterateOverObjects([this, isInFinish, isSimplify](TaggedObject *obj) { - GenerateNode(JSTaggedValue(obj), 0, isInFinish, isSimplify); - }, isSimplify); - } - } + GenerateNodeRootVisitor visitor(*this, isInFinish, isSimplify); + rootVisitor_.VisitHeapRoots(vm_->GetJSThread(), visitor); } Node *HeapSnapshot::HandleStringNode(JSTaggedValue &entry, size_t &size, bool &isInFinish, bool isBinMod) diff --git a/ecmascript/dfx/hprof/tests/heap_snapshot_test.cpp b/ecmascript/dfx/hprof/tests/heap_snapshot_test.cpp index 92212c42f5d206a9fcf98e69ffd8c89e4a691473..4235e6c1368b254c56c0bb6e87bd49eaac7a5c2a 100644 --- a/ecmascript/dfx/hprof/tests/heap_snapshot_test.cpp +++ b/ecmascript/dfx/hprof/tests/heap_snapshot_test.cpp @@ -65,10 +65,12 @@ private: class HeapProfilerFriendTest { public: - explicit HeapProfilerFriendTest(const EcmaVM *vm) : heapProfiler(vm) {} + explicit HeapProfilerFriendTest(const EcmaVM *vm) : heapProfiler(vm), vm_(vm) {} HeapSnapshot *MakeHeapSnapshotTest(HeapProfiler::SampleType type, DumpSnapShotOption dumpOption) { + heapProfiler.ForceFullGC(vm_); + heapProfiler.ForceSharedGC(); return heapProfiler.MakeHeapSnapshot(type, dumpOption); } @@ -83,6 +85,7 @@ public: } private: HeapProfiler heapProfiler; + const EcmaVM *vm_; }; } diff --git a/ecmascript/dfx/hprof/tests/js_files/heap_snapshot.js b/ecmascript/dfx/hprof/tests/js_files/heap_snapshot.js index 298427287ff1acfa38dfa6a9c3717e081e728b55..d3507bfd997d9dfb8daf48829deb9cdc8acc5e6e 100644 --- a/ecmascript/dfx/hprof/tests/js_files/heap_snapshot.js +++ b/ecmascript/dfx/hprof/tests/js_files/heap_snapshot.js @@ -21,17 +21,20 @@ let str5 = 'string5'; let str6 = 'string6'; let str7 = 'string7'; let str8 = 'string8'; -let treeStr1 = str1 + str2; -let treeStr2 = str3 + str4; -let treeStr3 = str5 + str6; -let treeStr4 = str7 + str8; -let treeStr5 = str1 + str2 + str3 + str4; -let treeStr6 = str5 + str6 + str7 + str8; -let treeStr7 = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8; -globalThis.save1 = treeStr1; -globalThis.save2 = treeStr2; -globalThis.save3 = treeStr3; -globalThis.save4 = treeStr4; -globalThis.save5 = treeStr5; -globalThis.save6 = treeStr6; -globalThis.save7 = treeStr7; \ No newline at end of file + +globalThis.treeStr1 = str1 + str2; +globalThis.treeStr2 = str3 + str4; +globalThis.treeStr3 = str5 + str6; +globalThis.treeStr4 = str7 + str8; +globalThis.treeStr5 = str1 + str2 + str3 + str4; +globalThis.treeStr6 = str5 + str6 + str7 + str8; +globalThis.treeStr7 = str1 + str2 + str3 + str4 + str5 + str6 + str7 + str8; + +globalThis.save1 = str1; +globalThis.save2 = str2; +globalThis.save3 = str3; +globalThis.save4 = str4; +globalThis.save5 = str5; +globalThis.save6 = str6; +globalThis.save7 = str7; +globalThis.save8 = str8; \ No newline at end of file