OLD | NEW |
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/precompiler.h" | 5 #include "vm/precompiler.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/log.h" | 9 #include "vm/log.h" |
10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 DEFINE_FLAG(bool, trace_precompiler, false, "Trace precompiler."); | 23 DEFINE_FLAG(bool, trace_precompiler, false, "Trace precompiler."); |
24 | 24 |
25 | 25 |
26 static void Jump(const Error& error) { | 26 static void Jump(const Error& error) { |
27 Thread::Current()->long_jump_base()->Jump(1, error); | 27 Thread::Current()->long_jump_base()->Jump(1, error); |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 RawError* Precompiler::CompileAll( | 31 RawError* Precompiler::CompileAll( |
32 Dart_QualifiedFunctionName embedder_entry_points[]) { | 32 Dart_QualifiedFunctionName embedder_entry_points[], |
| 33 bool reset_fields) { |
33 LongJumpScope jump; | 34 LongJumpScope jump; |
34 if (setjmp(*jump.Set()) == 0) { | 35 if (setjmp(*jump.Set()) == 0) { |
35 Precompiler precompiler(Thread::Current()); | 36 Precompiler precompiler(Thread::Current(), reset_fields); |
36 precompiler.DoCompileAll(embedder_entry_points); | 37 precompiler.DoCompileAll(embedder_entry_points); |
37 return Error::null(); | 38 return Error::null(); |
38 } else { | 39 } else { |
39 Isolate* isolate = Isolate::Current(); | 40 Isolate* isolate = Isolate::Current(); |
40 const Error& error = Error::Handle(isolate->object_store()->sticky_error()); | 41 const Error& error = Error::Handle(isolate->object_store()->sticky_error()); |
41 isolate->object_store()->clear_sticky_error(); | 42 isolate->object_store()->clear_sticky_error(); |
42 return error.raw(); | 43 return error.raw(); |
43 } | 44 } |
44 } | 45 } |
45 | 46 |
46 | 47 |
47 Precompiler::Precompiler(Thread* thread) : | 48 Precompiler::Precompiler(Thread* thread, bool reset_fields) : |
48 thread_(thread), | 49 thread_(thread), |
49 zone_(thread->zone()), | 50 zone_(thread->zone()), |
50 isolate_(thread->isolate()), | 51 isolate_(thread->isolate()), |
| 52 reset_fields_(reset_fields), |
51 changed_(false), | 53 changed_(false), |
52 function_count_(0), | 54 function_count_(0), |
53 class_count_(0), | 55 class_count_(0), |
54 selector_count_(0), | 56 selector_count_(0), |
55 dropped_function_count_(0), | 57 dropped_function_count_(0), |
56 libraries_(GrowableObjectArray::Handle(Z, I->object_store()->libraries())), | 58 libraries_(GrowableObjectArray::Handle(Z, I->object_store()->libraries())), |
57 pending_functions_(GrowableObjectArray::Handle(Z, | 59 pending_functions_(GrowableObjectArray::Handle(Z, |
58 GrowableObjectArray::New())), | 60 GrowableObjectArray::New())), |
59 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())), | 61 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())), |
60 sent_selectors_(Z), | 62 sent_selectors_(Z), |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 438 |
437 void Precompiler::AddField(const Field& field) { | 439 void Precompiler::AddField(const Field& field) { |
438 if (field.is_static()) { | 440 if (field.is_static()) { |
439 // Potential const object. Uninitialized field will harmlessly do a | 441 // Potential const object. Uninitialized field will harmlessly do a |
440 // redundant add of the Null class. | 442 // redundant add of the Null class. |
441 const Object& value = Object::Handle(Z, field.StaticValue()); | 443 const Object& value = Object::Handle(Z, field.StaticValue()); |
442 const Class& cls = Class::Handle(Z, value.clazz()); | 444 const Class& cls = Class::Handle(Z, value.clazz()); |
443 AddClass(cls); | 445 AddClass(cls); |
444 | 446 |
445 if (field.has_initializer()) { | 447 if (field.has_initializer()) { |
| 448 // Should not be in the middle of initialization while precompiling. |
| 449 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 450 |
| 451 const bool is_initialized = value.raw() != Object::sentinel().raw(); |
| 452 if (is_initialized && !reset_fields_) return; |
| 453 |
446 if (field.HasPrecompiledInitializer()) return; | 454 if (field.HasPrecompiledInitializer()) return; |
447 | 455 |
448 if (FLAG_trace_precompiler) { | 456 if (FLAG_trace_precompiler) { |
449 THR_Print("Precompiling initializer for %s\n", field.ToCString()); | 457 THR_Print("Precompiling initializer for %s\n", field.ToCString()); |
450 } | 458 } |
451 ASSERT(!Dart::IsRunningPrecompiledCode()); | 459 ASSERT(!Dart::IsRunningPrecompiledCode()); |
452 field.SetStaticValue(Instance::Handle(field.SavedInitialStaticValue())); | 460 field.SetStaticValue(Instance::Handle(field.SavedInitialStaticValue())); |
453 Compiler::CompileStaticInitializer(field); | 461 Compiler::CompileStaticInitializer(field); |
454 | 462 |
455 const Function& function = | 463 const Function& function = |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 for (intptr_t j = 0; j < closures.Length(); j++) { | 685 for (intptr_t j = 0; j < closures.Length(); j++) { |
678 function ^= closures.At(j); | 686 function ^= closures.At(j); |
679 ASSERT(function.HasCode()); | 687 ASSERT(function.HasCode()); |
680 } | 688 } |
681 } | 689 } |
682 } | 690 } |
683 } | 691 } |
684 } | 692 } |
685 | 693 |
686 } // namespace dart | 694 } // namespace dart |
OLD | NEW |