| 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/aot_optimizer.h" | 7 #include "vm/aot_optimizer.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/ast_printer.h" | 9 #include "vm/ast_printer.h" |
| 10 #include "vm/branch_optimizer.h" | 10 #include "vm/branch_optimizer.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 return true; | 339 return true; |
| 340 } | 340 } |
| 341 | 341 |
| 342 | 342 |
| 343 Precompiler::Precompiler(Thread* thread) | 343 Precompiler::Precompiler(Thread* thread) |
| 344 : thread_(thread), | 344 : thread_(thread), |
| 345 zone_(NULL), | 345 zone_(NULL), |
| 346 isolate_(thread->isolate()), | 346 isolate_(thread->isolate()), |
| 347 jit_feedback_(NULL), | 347 jit_feedback_(NULL), |
| 348 changed_(false), | 348 changed_(false), |
| 349 retain_root_library_caches_(false), |
| 349 function_count_(0), | 350 function_count_(0), |
| 350 class_count_(0), | 351 class_count_(0), |
| 351 selector_count_(0), | 352 selector_count_(0), |
| 352 dropped_function_count_(0), | 353 dropped_function_count_(0), |
| 353 dropped_field_count_(0), | 354 dropped_field_count_(0), |
| 354 dropped_class_count_(0), | 355 dropped_class_count_(0), |
| 355 dropped_typearg_count_(0), | 356 dropped_typearg_count_(0), |
| 356 dropped_type_count_(0), | 357 dropped_type_count_(0), |
| 357 dropped_library_count_(0), | 358 dropped_library_count_(0), |
| 358 libraries_(GrowableObjectArray::Handle(I->object_store()->libraries())), | 359 libraries_(GrowableObjectArray::Handle(I->object_store()->libraries())), |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 {"dart:isolate", "::", "_runPendingImmediateCallback"}, | 683 {"dart:isolate", "::", "_runPendingImmediateCallback"}, |
| 683 #endif // !PRODUCT | 684 #endif // !PRODUCT |
| 684 // Fields | 685 // Fields |
| 685 {"dart:core", "Error", "_stackTrace"}, | 686 {"dart:core", "Error", "_stackTrace"}, |
| 686 {"dart:math", "_Random", "_state"}, | 687 {"dart:math", "_Random", "_state"}, |
| 687 {NULL, NULL, NULL} // Must be terminated with NULL entries. | 688 {NULL, NULL, NULL} // Must be terminated with NULL entries. |
| 688 }; | 689 }; |
| 689 | 690 |
| 690 AddEntryPoints(vm_entry_points); | 691 AddEntryPoints(vm_entry_points); |
| 691 AddEntryPoints(embedder_entry_points); | 692 AddEntryPoints(embedder_entry_points); |
| 693 const Library& lib = Library::Handle(I->object_store()->root_library()); |
| 694 const String& name = String::Handle(String::New("main")); |
| 695 const Object& main_closure = Object::Handle(lib.GetFunctionClosure(name)); |
| 696 if (main_closure.IsClosure()) { |
| 697 if (lib.LookupLocalFunction(name) == Function::null()) { |
| 698 // Check whether the function is in exported namespace of library, in |
| 699 // this case we have to retain the root library caches. |
| 700 if (lib.LookupFunctionAllowPrivate(name) != Function::null() || |
| 701 lib.LookupReExport(name) != Object::null()) { |
| 702 retain_root_library_caches_ = true; |
| 703 } |
| 704 } |
| 705 AddConstObject(Closure::Cast(main_closure)); |
| 706 } else if (main_closure.IsError()) { |
| 707 const Error& error = Error::Cast(main_closure); |
| 708 String& msg = |
| 709 String::Handle(Z, String::NewFormatted("Cannot find main closure %s\n", |
| 710 error.ToErrorCString())); |
| 711 Jump(Error::Handle(Z, ApiError::New(msg))); |
| 712 UNREACHABLE(); |
| 713 } |
| 692 } | 714 } |
| 693 | 715 |
| 694 | 716 |
| 695 void Precompiler::AddEntryPoints(Dart_QualifiedFunctionName entry_points[]) { | 717 void Precompiler::AddEntryPoints(Dart_QualifiedFunctionName entry_points[]) { |
| 696 Library& lib = Library::Handle(Z); | 718 Library& lib = Library::Handle(Z); |
| 697 Class& cls = Class::Handle(Z); | 719 Class& cls = Class::Handle(Z); |
| 698 Function& func = Function::Handle(Z); | 720 Function& func = Function::Handle(Z); |
| 699 Field& field = Field::Handle(Z); | 721 Field& field = Field::Handle(Z); |
| 700 String& library_uri = String::Handle(Z); | 722 String& library_uri = String::Handle(Z); |
| 701 String& class_name = String::Handle(Z); | 723 String& class_name = String::Handle(Z); |
| (...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 continue; | 2043 continue; |
| 2022 } | 2044 } |
| 2023 } else if (entry.IsLibraryPrefix()) { | 2045 } else if (entry.IsLibraryPrefix()) { |
| 2024 // Always drop. | 2046 // Always drop. |
| 2025 } else { | 2047 } else { |
| 2026 FATAL1("Unexpected library entry: %s", entry.ToCString()); | 2048 FATAL1("Unexpected library entry: %s", entry.ToCString()); |
| 2027 } | 2049 } |
| 2028 dict.SetAt(j, Object::null_object()); | 2050 dict.SetAt(j, Object::null_object()); |
| 2029 } | 2051 } |
| 2030 lib.RehashDictionary(dict, used * 4 / 3 + 1); | 2052 lib.RehashDictionary(dict, used * 4 / 3 + 1); |
| 2031 lib.DropDependenciesAndCaches(); | 2053 if (!(retain_root_library_caches_ && |
| 2054 (lib.raw() == I->object_store()->root_library()))) { |
| 2055 lib.DropDependenciesAndCaches(); |
| 2056 } |
| 2032 } | 2057 } |
| 2033 } | 2058 } |
| 2034 | 2059 |
| 2035 | 2060 |
| 2036 void Precompiler::DropClasses() { | 2061 void Precompiler::DropClasses() { |
| 2037 Class& cls = Class::Handle(Z); | 2062 Class& cls = Class::Handle(Z); |
| 2038 Array& constants = Array::Handle(Z); | 2063 Array& constants = Array::Handle(Z); |
| 2039 | 2064 |
| 2040 #if defined(DEBUG) | 2065 #if defined(DEBUG) |
| 2041 // We are about to remove classes from the class table. For this to be safe, | 2066 // We are about to remove classes from the class table. For this to be safe, |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3364 | 3389 |
| 3365 ASSERT(FLAG_precompiled_mode); | 3390 ASSERT(FLAG_precompiled_mode); |
| 3366 const bool optimized = function.IsOptimizable(); // False for natives. | 3391 const bool optimized = function.IsOptimizable(); // False for natives. |
| 3367 DartPrecompilationPipeline pipeline(zone, field_type_map); | 3392 DartPrecompilationPipeline pipeline(zone, field_type_map); |
| 3368 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); | 3393 return PrecompileFunctionHelper(precompiler, &pipeline, function, optimized); |
| 3369 } | 3394 } |
| 3370 | 3395 |
| 3371 #endif // DART_PRECOMPILER | 3396 #endif // DART_PRECOMPILER |
| 3372 | 3397 |
| 3373 } // namespace dart | 3398 } // namespace dart |
| OLD | NEW |