Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Unified Diff: runtime/vm/source_report.cc

Issue 2038203002: Fix various nefarious problems with the script table used in source reports. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/source_report.h ('k') | runtime/vm/source_report_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/source_report.cc
diff --git a/runtime/vm/source_report.cc b/runtime/vm/source_report.cc
index ee8858d64ff0fcbfa7719b8fba2712e70af8aca8..7fa1573af42cd13ebc1233c14c2fce0388552225 100644
--- a/runtime/vm/source_report.cc
+++ b/runtime/vm/source_report.cc
@@ -30,6 +30,22 @@ SourceReport::SourceReport(intptr_t report_set, CompileMode compile_mode)
}
+SourceReport::~SourceReport() {
+ ClearScriptTable();
+}
+
+
+void SourceReport::ClearScriptTable() {
+ for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
+ delete script_table_entries_[i];
+ script_table_entries_[i] = NULL;
+ }
+ script_table_entries_.Clear();
+ script_table_.Clear();
+ next_script_index_ = 0;
+}
+
+
void SourceReport::Init(Thread* thread,
const Script* script,
TokenPosition start_pos,
@@ -38,9 +54,7 @@ void SourceReport::Init(Thread* thread,
script_ = script;
start_pos_ = start_pos;
end_pos_ = end_pos;
- script_table_entries_.Clear();
- script_table_.Clear();
- next_script_index_ = 0;
+ ClearScriptTable();
if (IsReportRequested(kProfile)) {
// Build the profile.
SampleFilter samplesForIsolate(thread_->isolate(),
@@ -103,17 +117,36 @@ intptr_t SourceReport::GetScriptIndex(const Script& script) {
if (pair != NULL) {
return pair->index;
}
-
- ScriptTableEntry tmp;
- tmp.key = &url;
- tmp.index = next_script_index_++;
- tmp.script = &script;
+ ScriptTableEntry* tmp = new ScriptTableEntry();
+ tmp->key = &url;
+ tmp->index = next_script_index_++;
+ tmp->script = &Script::Handle(zone(), script.raw());
script_table_entries_.Add(tmp);
- script_table_.Insert(&(script_table_entries_.Last()));
- return tmp.index;
+ script_table_.Insert(tmp);
+ ASSERT(script_table_entries_.length() == next_script_index_);
+#if defined(DEBUG)
+ VerifyScriptTable();
+#endif
+ return tmp->index;
}
+#if defined(DEBUG)
+void SourceReport::VerifyScriptTable() {
+ for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
+ const String* url = script_table_entries_[i]->key;
+ const Script* script = script_table_entries_[i]->script;
+ intptr_t index = script_table_entries_[i]->index;
+ ASSERT(i == index);
+ const String& url2 = String::Handle(zone(), script->url());
+ ASSERT(url2.Equals(*url));
+ ScriptTableEntry* pair = script_table_.Lookup(&url2);
+ ASSERT(i == pair->index);
+ }
+}
+#endif
+
+
bool SourceReport::ScriptIsLoadedByLibrary(const Script& script,
const Library& lib) {
const Array& scripts = Array::Handle(zone(), lib.LoadedScripts());
@@ -337,8 +370,8 @@ void SourceReport::PrintProfileData(JSONObject* jsobj,
void SourceReport::PrintScriptTable(JSONArray* scripts) {
- for (int i = 0; i < script_table_entries_.length(); i++) {
- const Script* script = script_table_entries_[i].script;
+ for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
+ const Script* script = script_table_entries_[i]->script;
scripts->AddValue(*script);
}
}
« no previous file with comments | « runtime/vm/source_report.h ('k') | runtime/vm/source_report_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698