Chromium Code Reviews| 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/code_patcher.h" | 7 #include "vm/code_patcher.h" |
| 8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
| 9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
| 10 #include "vm/log.h" | 10 #include "vm/log.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 changed_(false), | 54 changed_(false), |
| 55 function_count_(0), | 55 function_count_(0), |
| 56 class_count_(0), | 56 class_count_(0), |
| 57 selector_count_(0), | 57 selector_count_(0), |
| 58 dropped_function_count_(0), | 58 dropped_function_count_(0), |
| 59 libraries_(GrowableObjectArray::Handle(Z, I->object_store()->libraries())), | 59 libraries_(GrowableObjectArray::Handle(Z, I->object_store()->libraries())), |
| 60 pending_functions_(GrowableObjectArray::Handle(Z, | 60 pending_functions_(GrowableObjectArray::Handle(Z, |
| 61 GrowableObjectArray::New())), | 61 GrowableObjectArray::New())), |
| 62 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())), | 62 collected_closures_(GrowableObjectArray::Handle(Z, I->collected_closures())), |
| 63 sent_selectors_(Z), | 63 sent_selectors_(Z), |
| 64 stackmaps_(Z), | |
| 64 error_(Error::Handle(Z)) { | 65 error_(Error::Handle(Z)) { |
| 65 } | 66 } |
| 66 | 67 |
| 67 | 68 |
| 68 void Precompiler::DoCompileAll( | 69 void Precompiler::DoCompileAll( |
| 69 Dart_QualifiedFunctionName embedder_entry_points[]) { | 70 Dart_QualifiedFunctionName embedder_entry_points[]) { |
| 70 // Drop all existing code so we can use the presence of code as an indicator | 71 // Drop all existing code so we can use the presence of code as an indicator |
| 71 // that we have already looked for the function's callees. | 72 // that we have already looked for the function's callees. |
| 72 ClearAllCode(); | 73 ClearAllCode(); |
| 73 | 74 |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 | 325 |
| 325 | 326 |
| 326 void Precompiler::CleanUp() { | 327 void Precompiler::CleanUp() { |
| 327 I->set_collected_closures(GrowableObjectArray::Handle(Z)); | 328 I->set_collected_closures(GrowableObjectArray::Handle(Z)); |
| 328 | 329 |
| 329 DropUncompiledFunctions(); | 330 DropUncompiledFunctions(); |
| 330 | 331 |
| 331 // TODO(rmacnak): DropEmptyClasses(); | 332 // TODO(rmacnak): DropEmptyClasses(); |
| 332 | 333 |
| 333 BindStaticCalls(); | 334 BindStaticCalls(); |
| 335 | |
| 336 DedupStackmaps(); | |
| 334 } | 337 } |
| 335 | 338 |
| 336 | 339 |
| 337 void Precompiler::ProcessFunction(const Function& function) { | 340 void Precompiler::ProcessFunction(const Function& function) { |
| 338 if (!function.HasCode()) { | 341 if (!function.HasCode()) { |
| 339 function_count_++; | 342 function_count_++; |
| 340 | 343 |
| 341 if (FLAG_trace_precompiler) { | 344 if (FLAG_trace_precompiler) { |
| 342 THR_Print("Precompiling %" Pd " %s (%" Pd ", %s)\n", | 345 THR_Print("Precompiling %" Pd " %s (%" Pd ", %s)\n", |
| 343 function_count_, | 346 function_count_, |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 CodePatcher::PatchStaticCallAt(pc_offset.Value() + code.EntryPoint(), | 760 CodePatcher::PatchStaticCallAt(pc_offset.Value() + code.EntryPoint(), |
| 758 code, target_code); | 761 code, target_code); |
| 759 } | 762 } |
| 760 } | 763 } |
| 761 | 764 |
| 762 // We won't patch static calls anymore, so drop the static call table to save | 765 // We won't patch static calls anymore, so drop the static call table to save |
| 763 // space. | 766 // space. |
| 764 code.set_static_calls_target_table(Object::empty_array()); | 767 code.set_static_calls_target_table(Object::empty_array()); |
| 765 } | 768 } |
| 766 | 769 |
| 770 | |
| 771 void Precompiler::DedupStackmaps() { | |
| 772 Library& lib = Library::Handle(Z); | |
|
Florian Schneider
2015/10/07 10:40:07
This code for iterating over all functions seems t
rmacnak
2015/10/07 22:19:06
Recast as visitor. Covers clear code, bind static
| |
| 773 Class& cls = Class::Handle(Z); | |
| 774 Array& functions = Array::Handle(Z); | |
| 775 Function& function = Function::Handle(Z); | |
| 776 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z); | |
| 777 | |
| 778 for (intptr_t i = 0; i < libraries_.Length(); i++) { | |
| 779 lib ^= libraries_.At(i); | |
| 780 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | |
| 781 while (it.HasNext()) { | |
| 782 cls = it.GetNextClass(); | |
| 783 if (cls.IsDynamicClass()) { | |
| 784 continue; // class 'dynamic' is in the read-only VM isolate. | |
| 785 } | |
| 786 | |
| 787 functions = cls.functions(); | |
| 788 for (intptr_t j = 0; j < functions.Length(); j++) { | |
| 789 function ^= functions.At(j); | |
| 790 DedupStackmaps(function); | |
| 791 } | |
| 792 | |
| 793 closures = cls.closures(); | |
| 794 if (!closures.IsNull()) { | |
| 795 for (intptr_t j = 0; j < closures.Length(); j++) { | |
| 796 function ^= closures.At(j); | |
| 797 DedupStackmaps(function); | |
| 798 } | |
| 799 } | |
| 800 } | |
| 801 } | |
| 802 } | |
| 803 | |
| 804 | |
| 805 void Precompiler::DedupStackmaps(const Function& function) { | |
| 806 Code& code = Code::Handle(Z, function.CurrentCode()); | |
| 807 Array& stackmaps = Array::Handle(Z, code.stackmaps()); | |
| 808 if (stackmaps.IsNull()) return; | |
| 809 Stackmap& stackmap = Stackmap::Handle(Z); | |
| 810 for (intptr_t i = 0; i < stackmaps.Length(); i++) { | |
| 811 stackmap ^= stackmaps.At(i); | |
| 812 stackmap = DedupStackmap(stackmap); | |
| 813 stackmaps.SetAt(i, stackmap); | |
| 814 } | |
| 815 } | |
| 816 | |
| 817 | |
| 818 RawStackmap* Precompiler::DedupStackmap(const Stackmap& stackmap) { | |
| 819 const Stackmap* canonical_stackmap = stackmaps_.Lookup(stackmap); | |
| 820 if (canonical_stackmap == NULL) { | |
| 821 stackmaps_.Add(Stackmap::ZoneHandle(Z, stackmap.raw())); | |
| 822 return stackmap.raw(); | |
| 823 } else { | |
| 824 return canonical_stackmap->raw(); | |
| 825 } | |
| 826 } | |
| 827 | |
| 767 } // namespace dart | 828 } // namespace dart |
| OLD | NEW |