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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/source_report.h" 5 #include "vm/source_report.h"
6 6
7 #include "vm/compiler.h" 7 #include "vm/compiler.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 12 matching lines...) Expand all
23 compile_mode_(compile_mode), 23 compile_mode_(compile_mode),
24 thread_(NULL), 24 thread_(NULL),
25 script_(NULL), 25 script_(NULL),
26 start_pos_(TokenPosition::kNoSource), 26 start_pos_(TokenPosition::kNoSource),
27 end_pos_(TokenPosition::kNoSource), 27 end_pos_(TokenPosition::kNoSource),
28 profile_(Isolate::Current()), 28 profile_(Isolate::Current()),
29 next_script_index_(0) { 29 next_script_index_(0) {
30 } 30 }
31 31
32 32
33 SourceReport::~SourceReport() {
34 ClearScriptTable();
35 }
36
37
38 void SourceReport::ClearScriptTable() {
39 for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
40 delete script_table_entries_[i];
41 script_table_entries_[i] = NULL;
42 }
43 script_table_entries_.Clear();
44 script_table_.Clear();
45 next_script_index_ = 0;
46 }
47
48
33 void SourceReport::Init(Thread* thread, 49 void SourceReport::Init(Thread* thread,
34 const Script* script, 50 const Script* script,
35 TokenPosition start_pos, 51 TokenPosition start_pos,
36 TokenPosition end_pos) { 52 TokenPosition end_pos) {
37 thread_ = thread; 53 thread_ = thread;
38 script_ = script; 54 script_ = script;
39 start_pos_ = start_pos; 55 start_pos_ = start_pos;
40 end_pos_ = end_pos; 56 end_pos_ = end_pos;
41 script_table_entries_.Clear(); 57 ClearScriptTable();
42 script_table_.Clear();
43 next_script_index_ = 0;
44 if (IsReportRequested(kProfile)) { 58 if (IsReportRequested(kProfile)) {
45 // Build the profile. 59 // Build the profile.
46 SampleFilter samplesForIsolate(thread_->isolate(), 60 SampleFilter samplesForIsolate(thread_->isolate(),
47 Thread::kMutatorTask, 61 Thread::kMutatorTask,
48 -1, -1); 62 -1, -1);
49 profile_.Build(thread, &samplesForIsolate, Profile::kNoTags); 63 profile_.Build(thread, &samplesForIsolate, Profile::kNoTags);
50 } 64 }
51 } 65 }
52 66
53 67
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return false; 110 return false;
97 } 111 }
98 112
99 113
100 intptr_t SourceReport::GetScriptIndex(const Script& script) { 114 intptr_t SourceReport::GetScriptIndex(const Script& script) {
101 const String& url = String::Handle(zone(), script.url()); 115 const String& url = String::Handle(zone(), script.url());
102 ScriptTableEntry* pair = script_table_.Lookup(&url); 116 ScriptTableEntry* pair = script_table_.Lookup(&url);
103 if (pair != NULL) { 117 if (pair != NULL) {
104 return pair->index; 118 return pair->index;
105 } 119 }
120 ScriptTableEntry* tmp = new ScriptTableEntry();
121 tmp->key = &url;
122 tmp->index = next_script_index_++;
123 tmp->script = &Script::Handle(zone(), script.raw());
124 script_table_entries_.Add(tmp);
125 script_table_.Insert(tmp);
126 ASSERT(script_table_entries_.length() == next_script_index_);
127 #if defined(DEBUG)
128 VerifyScriptTable();
129 #endif
130 return tmp->index;
131 }
106 132
107 ScriptTableEntry tmp; 133
108 tmp.key = &url; 134 #if defined(DEBUG)
109 tmp.index = next_script_index_++; 135 void SourceReport::VerifyScriptTable() {
110 tmp.script = &script; 136 for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
111 script_table_entries_.Add(tmp); 137 const String* url = script_table_entries_[i]->key;
112 script_table_.Insert(&(script_table_entries_.Last())); 138 const Script* script = script_table_entries_[i]->script;
113 return tmp.index; 139 intptr_t index = script_table_entries_[i]->index;
140 ASSERT(i == index);
141 const String& url2 = String::Handle(zone(), script->url());
142 ASSERT(url2.Equals(*url));
143 ScriptTableEntry* pair = script_table_.Lookup(&url2);
144 ASSERT(i == pair->index);
145 }
114 } 146 }
147 #endif
115 148
116 149
117 bool SourceReport::ScriptIsLoadedByLibrary(const Script& script, 150 bool SourceReport::ScriptIsLoadedByLibrary(const Script& script,
118 const Library& lib) { 151 const Library& lib) {
119 const Array& scripts = Array::Handle(zone(), lib.LoadedScripts()); 152 const Array& scripts = Array::Handle(zone(), lib.LoadedScripts());
120 for (intptr_t j = 0; j < scripts.Length(); j++) { 153 for (intptr_t j = 0; j < scripts.Length(); j++) {
121 if (scripts.At(j) == script.raw()) { 154 if (scripts.At(j) == script.raw()) {
122 return true; 155 return true;
123 } 156 }
124 } 157 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 const ProfileFunctionSourcePosition& position = 363 const ProfileFunctionSourcePosition& position =
331 profile_function->GetSourcePosition(i); 364 profile_function->GetSourcePosition(i);
332 inclusiveTicks.AddValue(position.inclusive_ticks()); 365 inclusiveTicks.AddValue(position.inclusive_ticks());
333 } 366 }
334 } 367 }
335 } 368 }
336 } 369 }
337 370
338 371
339 void SourceReport::PrintScriptTable(JSONArray* scripts) { 372 void SourceReport::PrintScriptTable(JSONArray* scripts) {
340 for (int i = 0; i < script_table_entries_.length(); i++) { 373 for (intptr_t i = 0; i < script_table_entries_.length(); i++) {
341 const Script* script = script_table_entries_[i].script; 374 const Script* script = script_table_entries_[i]->script;
342 scripts->AddValue(*script); 375 scripts->AddValue(*script);
343 } 376 }
344 } 377 }
345 378
346 379
347 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) { 380 void SourceReport::VisitFunction(JSONArray* jsarr, const Function& func) {
348 if (ShouldSkipFunction(func)) { 381 if (ShouldSkipFunction(func)) {
349 return; 382 return;
350 } 383 }
351 384
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // Visit all closures for this isolate. 531 // Visit all closures for this isolate.
499 VisitClosures(&ranges); 532 VisitClosures(&ranges);
500 } 533 }
501 534
502 // Print the script table. 535 // Print the script table.
503 JSONArray scripts(&report, "scripts"); 536 JSONArray scripts(&report, "scripts");
504 PrintScriptTable(&scripts); 537 PrintScriptTable(&scripts);
505 } 538 }
506 539
507 } // namespace dart 540 } // namespace dart
OLDNEW
« 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