diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index a230c6db85777622eee1c6e3baf73d011bdd2197..93e72251f3beeb2b3ab26bfa2bffcd9eece9be61 100755 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -1145,14 +1145,11 @@ void HeapSnapshot::FillEdges(bool isSimplify) { LOG_ECMA(INFO) << "HeapSnapshot::FillEdges begin, nodeCount: " << nodeCount_; ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "HeapSnapshot::FillEdges", ""); - auto iter = nodes_.begin(); - size_t count = 0; - while (count++ < nodes_.size()) { - ASSERT(*iter != nullptr); - auto entryFrom = *iter; + for (size_t i = 0; i < nodeCount_; ++i) { + Node *entryFrom = nodes_[i]; + ASSERT(entryFrom != nullptr); JSTaggedValue value(entryFrom->GetAddress()); if (!value.IsHeapObject()) { - iter++; continue; } std::vector referenceResources; @@ -1163,7 +1160,7 @@ void HeapSnapshot::FillEdges(bool isSimplify) continue; } Node *entryTo = nullptr; - EdgeType type = toValue.IsWeak() ? EdgeType::WEAK : (EdgeType)it.type_; + EdgeType type = toValue.IsWeak() ? EdgeType::WEAK : it.type_; if (toValue.IsWeak()) { toValue.RemoveWeakTag(); } @@ -1175,15 +1172,14 @@ void HeapSnapshot::FillEdges(bool isSimplify) entryTo = GenerateNode(toValue, 0, true, isSimplify); } if (entryTo != nullptr) { - Edge *edge = (it.type_ == Reference::ReferenceType::ELEMENT) ? + Edge *edge = (it.type_ == EdgeType::ELEMENT) ? Edge::NewEdge(chunk_, type, entryFrom, entryTo, it.index_) : Edge::NewEdge(chunk_, type, entryFrom, entryTo, GetString(it.name_)); RenameFunction(it.name_, entryFrom, entryTo); InsertEdgeUnique(edge); - (*iter)->IncEdgeCount(); // Update Node's edgeCount_ here + entryFrom->IncEdgeCount(); // Update Node's edgeCount_ here } } - iter++; } LOG_ECMA(INFO) << "HeapSnapshot::FillEdges exit, nodeCount: " << nodeCount_ << ", edgeCount: " << edgeCount_; } diff --git a/ecmascript/dfx/hprof/heap_snapshot.h b/ecmascript/dfx/hprof/heap_snapshot.h index b41dfda43d30172cf392b5bf9cd2154104d800b3..69e3f0d490c7fcf4c0dbdc19b10bf3a2be154777 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.h +++ b/ecmascript/dfx/hprof/heap_snapshot.h @@ -384,16 +384,14 @@ private: }; struct Reference { - enum class ReferenceType { CONTEXT, ELEMENT, PROPERTY, INTERNAL, HIDDEN, SHORTCUT, WEAK, DEFAULT = PROPERTY }; - Reference(const CString &name, JSTaggedValue value) : name_(name), value_(value) {} - Reference(const CString &name, JSTaggedValue value, ReferenceType type) : name_(name), value_(value), type_(type) {} - Reference(uint32_t index, JSTaggedValue value, ReferenceType type) : index_(index), value_(value), type_(type) {} + Reference(const CString &name, JSTaggedValue value, EdgeType type) : name_(name), value_(value), type_(type) {} + Reference(uint32_t index, JSTaggedValue value, EdgeType type) : index_(index), value_(value), type_(type) {} CString name_; uint32_t index_ {-1U}; JSTaggedValue value_; - ReferenceType type_ {ReferenceType::DEFAULT}; + EdgeType type_ {EdgeType::DEFAULT}; }; class EntryVisitor { @@ -458,11 +456,11 @@ public: } CString *GenerateNodeName(TaggedObject *entry); NodeType GenerateNodeType(TaggedObject *entry); - const CList *GetNodes() const + const CVector *GetNodes() const { return &nodes_; } - const CList *GetEdges() const + const CVector *GetEdges() const { return &edges_; } @@ -551,14 +549,14 @@ private: void LogLeakedLocalHandleBackTrace(ObjectSlot slot); void LogLeakedLocalHandleBackTrace(common::RefField<> &refField); - CList nodes_ {}; - CList edges_ {}; + CVector nodes_ {}; + CVector edges_ {}; CVector timeStamps_ {}; uint32_t nodeCount_ {0}; uint32_t edgeCount_ {0}; size_t totalNodesSize_ {0}; HeapEntryMap entryMap_; - panda::ecmascript::HeapRootVisitor rootVisitor_; + HeapRootVisitor rootVisitor_; const EcmaVM *vm_; StringHashMap *stringTable_ {nullptr}; bool isVmMode_ {true}; @@ -567,7 +565,7 @@ private: Node* privateStringNode_ {nullptr}; bool trackAllocations_ {false}; CVector traceInfoStack_ {}; - CMap stackInfo_; + CMap stackInfo_; CMap scriptIdMap_; TraceTree traceTree_; CMap methodToTraceNodeId_; diff --git a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp index 9e486bc8de0d7bc4162552abacce4a13405727f9..cb8c9353b88fabae726c263b768e601cc9cb7090 100644 --- a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp @@ -89,7 +89,7 @@ void HeapSnapshotJSONSerializer::SerializeNodes(HeapSnapshot *snapshot, StreamWr { LOG_ECMA(INFO) << "HeapSnapshotJSONSerializer::SerializeNodes"; ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "HeapSnapshotJSONSerializer::SerializeNodes", ""); - const CList *nodes = snapshot->GetNodes(); + const CVector *nodes = snapshot->GetNodes(); const StringHashMap *stringTable = snapshot->GetEcmaStringTable(); ASSERT(nodes != nullptr); writer->WriteString("\"nodes\":["); // Section Header @@ -126,7 +126,7 @@ void HeapSnapshotJSONSerializer::SerializeEdges(HeapSnapshot *snapshot, StreamWr { LOG_ECMA(INFO) << "HeapSnapshotJSONSerializer::SerializeEdges"; ECMA_BYTRACE_NAME(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_ARK, "HeapSnapshotJSONSerializer::SerializeEdges", ""); - const CList *edges = snapshot->GetEdges(); + const CVector *edges = snapshot->GetEdges(); const StringHashMap *stringTable = snapshot->GetEcmaStringTable(); ASSERT(edges != nullptr); writer->WriteString("\"edges\":["); diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 7f7a8dea633f9c9535967a01aec061045377a1ec..0311a88d97c7f1430f4a750d5faa6c72f45756b2 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -4013,7 +4013,7 @@ static void DumpElementClass(const JSThread *thread, const TaggedArray *arr, std vec.reserve(vec.size() + len); for (uint32_t i = 0; i < len; i++) { JSTaggedValue val(arr->Get(thread, i)); - vec.emplace_back(i, val, Reference::ReferenceType::ELEMENT); + vec.emplace_back(i, val, EdgeType::ELEMENT); } } @@ -4647,7 +4647,7 @@ void NumberDictionary::DumpForSnapshot(const JSThread *thread, std::vector(JSTaggedNumber(key).GetNumber()), val, Reference::ReferenceType::ELEMENT); + static_cast(JSTaggedNumber(key).GetNumber()), val, EdgeType::ELEMENT); } } }