OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/isolate_reload.h" | 5 #include "vm/isolate_reload.h" |
6 | 6 |
7 #include "vm/become.h" | 7 #include "vm/become.h" |
8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 THR_Print("Morphing from "); | 160 THR_Print("Morphing from "); |
161 DumpFormatFor(from_); | 161 DumpFormatFor(from_); |
162 THR_Print("To "); | 162 THR_Print("To "); |
163 DumpFormatFor(to_); | 163 DumpFormatFor(to_); |
164 THR_Print("\n"); | 164 THR_Print("\n"); |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 void InstanceMorpher::AppendTo(JSONArray* array) { | 168 void InstanceMorpher::AppendTo(JSONArray* array) { |
169 JSONObject jsobj(array); | 169 JSONObject jsobj(array); |
170 jsobj.AddProperty("type", "Morpher"); | 170 jsobj.AddProperty("type", "ShapeChangeMapping"); |
171 jsobj.AddProperty("class", to_); | 171 jsobj.AddProperty("class", to_); |
172 jsobj.AddProperty("instances", before()->length()); | 172 jsobj.AddProperty("instanceCount", before()->length()); |
173 JSONArray map(&jsobj, "mapping"); | 173 JSONArray map(&jsobj, "fieldOffsetMappings"); |
174 for (int i = 0; i < mapping_.length(); i += 2) { | 174 for (int i = 0; i < mapping_.length(); i += 2) { |
175 JSONArray pair(&map); | 175 JSONArray pair(&map); |
176 pair.AddValue(mapping_.At(i)); | 176 pair.AddValue(mapping_.At(i)); |
177 pair.AddValue(mapping_.At(i+1)); | 177 pair.AddValue(mapping_.At(i+1)); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 void ReasonForCancelling::Report(IsolateReloadContext* context) { | 182 void ReasonForCancelling::Report(IsolateReloadContext* context) { |
183 const Error& error = Error::Handle(ToError()); | 183 const Error& error = Error::Handle(ToError()); |
(...skipping 23 matching lines...) Expand all Loading... |
207 | 207 |
208 | 208 |
209 void ClassReasonForCancelling::AppendTo(JSONArray* array) { | 209 void ClassReasonForCancelling::AppendTo(JSONArray* array) { |
210 JSONObject jsobj(array); | 210 JSONObject jsobj(array); |
211 jsobj.AddProperty("type", "ReasonForCancelling"); | 211 jsobj.AddProperty("type", "ReasonForCancelling"); |
212 jsobj.AddProperty("class", from_); | 212 jsobj.AddProperty("class", from_); |
213 const String& message = String::Handle(ToString()); | 213 const String& message = String::Handle(ToString()); |
214 jsobj.AddProperty("message", message); | 214 jsobj.AddProperty("message", message); |
215 } | 215 } |
216 | 216 |
| 217 |
217 RawError* IsolateReloadContext::error() const { | 218 RawError* IsolateReloadContext::error() const { |
218 ASSERT(has_error()); | 219 ASSERT(has_error()); |
219 // Report the first error to the surroundings. | 220 // Report the first error to the surroundings. |
220 const Error& error = | 221 const Error& error = |
221 Error::Handle(reasons_to_cancel_reload_.At(0)->ToError()); | 222 Error::Handle(reasons_to_cancel_reload_.At(0)->ToError()); |
222 OS::Print("[[%s]]\n", error.ToCString()); | |
223 return error.raw(); | 223 return error.raw(); |
224 } | 224 } |
225 | 225 |
226 | 226 |
227 class ScriptUrlSetTraits { | 227 class ScriptUrlSetTraits { |
228 public: | 228 public: |
229 static bool ReportStats() { return false; } | 229 static bool ReportStats() { return false; } |
230 static const char* Name() { return "ScriptUrlSetTraits"; } | 230 static const char* Name() { return "ScriptUrlSetTraits"; } |
231 | 231 |
232 static bool IsMatch(const Object& a, const Object& b) { | 232 static bool IsMatch(const Object& a, const Object& b) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 bool IsolateReloadContext::IsSameLibrary( | 350 bool IsolateReloadContext::IsSameLibrary( |
351 const Library& a_lib, const Library& b_lib) { | 351 const Library& a_lib, const Library& b_lib) { |
352 const String& a_lib_url = | 352 const String& a_lib_url = |
353 String::Handle(a_lib.IsNull() ? String::null() : a_lib.url()); | 353 String::Handle(a_lib.IsNull() ? String::null() : a_lib.url()); |
354 const String& b_lib_url = | 354 const String& b_lib_url = |
355 String::Handle(b_lib.IsNull() ? String::null() : b_lib.url()); | 355 String::Handle(b_lib.IsNull() ? String::null() : b_lib.url()); |
356 return a_lib_url.Equals(b_lib_url); | 356 return a_lib_url.Equals(b_lib_url); |
357 } | 357 } |
358 | 358 |
359 | 359 |
360 IsolateReloadContext::IsolateReloadContext(Isolate* isolate) | 360 IsolateReloadContext::IsolateReloadContext(Isolate* isolate, |
| 361 JSONStream* js) |
361 : start_time_micros_(OS::GetCurrentMonotonicMicros()), | 362 : start_time_micros_(OS::GetCurrentMonotonicMicros()), |
362 reload_timestamp_(OS::GetCurrentTimeMillis()), | 363 reload_timestamp_(OS::GetCurrentTimeMillis()), |
363 isolate_(isolate), | 364 isolate_(isolate), |
364 reload_skipped_(false), | 365 reload_skipped_(false), |
| 366 js_(js), |
365 saved_num_cids_(-1), | 367 saved_num_cids_(-1), |
366 saved_class_table_(NULL), | 368 saved_class_table_(NULL), |
367 num_saved_libs_(-1), | 369 num_saved_libs_(-1), |
368 instance_morphers_(), | 370 instance_morphers_(), |
369 reasons_to_cancel_reload_(), | 371 reasons_to_cancel_reload_(), |
370 cid_mapper_(), | 372 cid_mapper_(), |
371 modified_libs_(NULL), | 373 modified_libs_(NULL), |
372 script_uri_(String::null()), | 374 script_uri_(String::null()), |
373 error_(Error::null()), | 375 error_(Error::null()), |
374 old_classes_set_storage_(Array::null()), | 376 old_classes_set_storage_(Array::null()), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // information from scratch. | 536 // information from scratch. |
535 RebuildDirectSubclasses(); | 537 RebuildDirectSubclasses(); |
536 | 538 |
537 if (FLAG_write_protect_code) { | 539 if (FLAG_write_protect_code) { |
538 // Re-enable code page write protection. | 540 // Re-enable code page write protection. |
539 I->heap()->WriteProtectCode(true); | 541 I->heap()->WriteProtectCode(true); |
540 } | 542 } |
541 | 543 |
542 BackgroundCompiler::Enable(); | 544 BackgroundCompiler::Enable(); |
543 | 545 |
544 if (FLAG_trace_reload) { | 546 ReportOnJSON(js_); |
545 JSONStream stream; | |
546 ReportOnJSON(&stream); | |
547 OS::Print("\nJSON report:\n %s\n", stream.ToCString()); | |
548 } | |
549 } | 547 } |
550 | 548 |
551 | 549 |
552 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) { | 550 void IsolateReloadContext::ReportOnJSON(JSONStream* stream) { |
553 JSONObject jsobj(stream); | 551 JSONObject jsobj(stream); |
554 jsobj.AddProperty("type", "Reload"); | 552 jsobj.AddProperty("type", "ReloadReport"); |
555 jsobj.AddProperty("succeeded", !HasReasonsForCancelling()); | 553 jsobj.AddProperty("success", !HasReasonsForCancelling()); |
556 if (HasReasonsForCancelling()) { | 554 { |
557 JSONArray array(&jsobj, "reasons"); | 555 JSONObject details(&jsobj, "details"); |
558 for (intptr_t i = 0; i < reasons_to_cancel_reload_.length(); i++) { | 556 if (HasReasonsForCancelling()) { |
559 ReasonForCancelling* reason = reasons_to_cancel_reload_.At(i); | 557 // Reload was rejected. |
560 reason->AppendTo(&array); | 558 JSONArray array(&jsobj, "notices"); |
561 } | 559 for (intptr_t i = 0; i < reasons_to_cancel_reload_.length(); i++) { |
562 } else { | 560 ReasonForCancelling* reason = reasons_to_cancel_reload_.At(i); |
563 JSONArray array(&jsobj, "changes"); | 561 reason->AppendTo(&array); |
564 for (intptr_t i = 0; i < instance_morphers_.length(); i++) { | 562 } |
565 instance_morphers_.At(i)->AppendTo(&array); | 563 } else { |
| 564 // Reload was successful. |
| 565 const GrowableObjectArray& libs = |
| 566 GrowableObjectArray::Handle(object_store()->libraries()); |
| 567 const intptr_t final_library_count = libs.Length(); |
| 568 const intptr_t loaded_library_count = |
| 569 final_library_count - num_saved_libs_; |
| 570 details.AddProperty("savedLibraryCount", num_saved_libs_); |
| 571 details.AddProperty("loadedLibraryCount", loaded_library_count); |
| 572 details.AddProperty("finalLibraryCount", final_library_count); |
| 573 JSONArray array(&jsobj, "shapeChangeMappings"); |
| 574 for (intptr_t i = 0; i < instance_morphers_.length(); i++) { |
| 575 instance_morphers_.At(i)->AppendTo(&array); |
| 576 } |
566 } | 577 } |
567 } | 578 } |
568 } | 579 } |
569 | 580 |
570 | 581 |
571 void IsolateReloadContext::AbortReload(const Error& error) { | 582 void IsolateReloadContext::AbortReload(const Error& error) { |
572 AddReasonForCancelling(new Aborted(error)); | 583 AddReasonForCancelling(new Aborted(error)); |
573 ReportReasonsForCancelling(); | 584 ReportReasonsForCancelling(); |
574 Rollback(); | 585 Rollback(); |
575 } | 586 } |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 ASSERT(!super_cls.IsNull()); | 1586 ASSERT(!super_cls.IsNull()); |
1576 super_cls.AddDirectSubclass(cls); | 1587 super_cls.AddDirectSubclass(cls); |
1577 } | 1588 } |
1578 } | 1589 } |
1579 } | 1590 } |
1580 } | 1591 } |
1581 | 1592 |
1582 #endif // !PRODUCT | 1593 #endif // !PRODUCT |
1583 | 1594 |
1584 } // namespace dart | 1595 } // namespace dart |
OLD | NEW |