Gracefully handle unloaded scripts
If a script is unloaded between the collection of an allocation and the tranlation of an allocation profile, the profiler will segfault. With this change, we report unloaded scripts as having no line number,column number, or name. R=ofrobots@google.com BUG= Review URL: https://codereview.chromium.org/1846723002 Cr-Commit-Position: refs/heads/master@{#35147}
This commit is contained in:
parent
25fe0e01ef
commit
607143d460
@ -200,7 +200,8 @@ v8::AllocationProfile::Node* SamplingHeapProfiler::TranslateAllocationNode(
|
||||
int column = v8::AllocationProfile::kNoColumnNumberInfo;
|
||||
std::vector<v8::AllocationProfile::Allocation> allocations;
|
||||
allocations.reserve(node->allocations_.size());
|
||||
if (node->script_id_ != v8::UnboundScript::kNoScriptId) {
|
||||
if (node->script_id_ != v8::UnboundScript::kNoScriptId &&
|
||||
scripts.find(node->script_id_) != scripts.end()) {
|
||||
// Cannot use std::map<T>::at because it is not available on android.
|
||||
auto non_const_scripts = const_cast<std::map<int, Script*>&>(scripts);
|
||||
Script* script = non_const_scripts[node->script_id_];
|
||||
|
@ -2875,7 +2875,6 @@ static const v8::AllocationProfile::Node* FindAllocationProfileNode(
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
TEST(SamplingHeapProfiler) {
|
||||
v8::HandleScope scope(v8::Isolate::GetCurrent());
|
||||
LocalContext env;
|
||||
@ -2988,6 +2987,23 @@ TEST(SamplingHeapProfiler) {
|
||||
|
||||
heap_profiler->StopSamplingHeapProfiler();
|
||||
}
|
||||
|
||||
// A test case with scripts unloaded before profile gathered
|
||||
{
|
||||
heap_profiler->StartSamplingHeapProfiler(64);
|
||||
CompileRun(
|
||||
"for (var i = 0; i < 1024; i++) {\n"
|
||||
" eval(\"new Array(100)\");\n"
|
||||
"}\n");
|
||||
|
||||
CcTest::heap()->CollectAllGarbage();
|
||||
|
||||
v8::base::SmartPointer<v8::AllocationProfile> profile(
|
||||
heap_profiler->GetAllocationProfile());
|
||||
CHECK(!profile.is_empty());
|
||||
|
||||
heap_profiler->StopSamplingHeapProfiler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user