| 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 440 |
| 439 void Precompiler::AddField(const Field& field) { | 441 void Precompiler::AddField(const Field& field) { |
| 440 if (field.is_static()) { | 442 if (field.is_static()) { |
| 441 // Potential const object. Uninitialized field will harmlessly do a | 443 // Potential const object. Uninitialized field will harmlessly do a |
| 442 // redundant add of the Null class. | 444 // redundant add of the Null class. |
| 443 const Object& value = Object::Handle(Z, field.StaticValue()); | 445 const Object& value = Object::Handle(Z, field.StaticValue()); |
| 444 const Class& cls = Class::Handle(Z, value.clazz()); | 446 const Class& cls = Class::Handle(Z, value.clazz()); |
| 445 AddClass(cls); | 447 AddClass(cls); |
| 446 | 448 |
| 447 if (field.has_initializer()) { | 449 if (field.has_initializer()) { |
| 450 // Should not be in the middle of initialization while precompiling. |
| 451 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 452 |
| 453 const bool is_initialized = value.raw() != Object::sentinel().raw(); |
| 454 if (is_initialized && !reset_fields_) return; |
| 455 |
| 448 if (field.HasPrecompiledInitializer()) return; | 456 if (field.HasPrecompiledInitializer()) return; |
| 449 | 457 |
| 450 if (FLAG_trace_precompiler) { | 458 if (FLAG_trace_precompiler) { |
| 451 THR_Print("Precompiling initializer for %s\n", field.ToCString()); | 459 THR_Print("Precompiling initializer for %s\n", field.ToCString()); |
| 452 } | 460 } |
| 453 ASSERT(!Dart::IsRunningPrecompiledCode()); | 461 ASSERT(!Dart::IsRunningPrecompiledCode()); |
| 454 field.SetStaticValue(Instance::Handle(field.SavedInitialStaticValue())); | 462 field.SetStaticValue(Instance::Handle(field.SavedInitialStaticValue())); |
| 455 Compiler::CompileStaticInitializer(field); | 463 Compiler::CompileStaticInitializer(field); |
| 456 | 464 |
| 457 const Function& function = | 465 const Function& function = |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 for (intptr_t j = 0; j < closures.Length(); j++) { | 648 for (intptr_t j = 0; j < closures.Length(); j++) { |
| 641 function ^= closures.At(j); | 649 function ^= closures.At(j); |
| 642 ASSERT(function.HasCode()); | 650 ASSERT(function.HasCode()); |
| 643 } | 651 } |
| 644 } | 652 } |
| 645 } | 653 } |
| 646 } | 654 } |
| 647 } | 655 } |
| 648 | 656 |
| 649 } // namespace dart | 657 } // namespace dart |
| OLD | NEW |