[Bug]: 录制allocationtracker出现应用崩溃

desc:
在录制allocation过程中,一旦new新的function对象,会去生成node节点,该节点会解析该函数的名称。但是在刚开始new
function时method还未设置,此时去method中解析函数名就会出错导致崩溃。

solu: 只在最后生成node节点时对函数名解析,中间过程不解析。

issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I8FPKT

Signed-off-by: wanghuan2022 <wanghuan80@huawei.com>
Change-Id: I2e6298b24a00c2ce5f1d9de93be6753c93698c62
This commit is contained in:
wanghuan2022 2023-11-11 17:36:10 +08:00
parent 39842db0db
commit e98b342f04
2 changed files with 37 additions and 2 deletions

View File

@ -276,7 +276,7 @@ CString *HeapSnapshot::GenerateNodeName(TaggedObject *entry)
case JSType::JS_FUNCTION_BASE:
return GetString("JSFunctionBase");
case JSType::JS_FUNCTION:
return GetString(CString(ParseFunctionName(entry)));
return GetString(CString("JSFunction"));
case JSType::JS_ERROR:
return GetString("Error");
case JSType::JS_EVAL_ERROR:
@ -648,7 +648,14 @@ Node *HeapSnapshot::GenerateNode(JSTaggedValue entry, size_t size, bool isInFini
node = GenerateStringNode(entry, size, isInFinish);
}
if (node == nullptr) {
LOG_ECMA(DEBUG) << "string node nullptr";
LOG_ECMA(ERROR) << "string node nullptr";
}
return node;
}
if (entry.IsJSFunction()) {
node = GenerateFunctionNode(entry, size, isInFinish);
if (node == nullptr) {
LOG_ECMA(ERROR) << "function node nullptr";
}
return node;
}
@ -945,6 +952,33 @@ Node *HeapSnapshot::GeneratePrivateStringNode(size_t size)
return node;
}
Node *HeapSnapshot::GenerateFunctionNode(JSTaggedValue entry, size_t size, bool isInFinish)
{
TaggedObject *obj = entry.GetTaggedObject();
Address addr = reinterpret_cast<Address>(obj);
Node *existNode = entryMap_.FindEntry(addr);
auto [idExist, sequenceId] = entryIdMap_->FindId(addr);
if (existNode != nullptr) {
if (isInFinish) {
existNode->SetName(GetString(CString(ParseFunctionName(obj))));
}
existNode->SetLive(true);
return existNode;
}
size_t selfsize = (size != 0) ? size : obj->GetClass()->SizeFromJSHClass(obj);
Node *node = Node::NewNode(chunk_, sequenceId, nodeCount_, GetString("JSFunction"), NodeType::CLOSURE, selfsize,
obj);
if (isInFinish) {
node->SetName(GetString(CString(ParseFunctionName(obj))));
}
if (!idExist) {
entryIdMap_->InsertId(addr, sequenceId);
}
entryMap_.InsertEntry(node);
InsertNodeUnique(node);
return node;
}
void HeapSnapshot::FillEdges()
{
size_t length = nodes_.size();

View File

@ -500,6 +500,7 @@ private:
Node *GenerateNode(JSTaggedValue entry, size_t size = 0, bool isInFinish = false);
Node *GeneratePrivateStringNode(size_t size);
Node *GenerateStringNode(JSTaggedValue entry, size_t size, bool isInFinish = false);
Node *GenerateFunctionNode(JSTaggedValue entry, size_t size, bool isInFinish = false);
void FillEdges();
void RenameFunction(const CString &edgeName, Node *entryFrom, Node *entryTo);
void BridgeAllReferences();