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/compiler.h" | 8 #include "vm/compiler.h" |
8 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
9 #include "vm/log.h" | 10 #include "vm/log.h" |
10 #include "vm/longjump.h" | 11 #include "vm/longjump.h" |
11 #include "vm/object.h" | 12 #include "vm/object.h" |
12 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
13 #include "vm/resolver.h" | 14 #include "vm/resolver.h" |
14 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
15 | 16 |
16 namespace dart { | 17 namespace dart { |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 | 325 |
325 void Precompiler::CleanUp() { | 326 void Precompiler::CleanUp() { |
326 I->set_collected_closures(GrowableObjectArray::Handle(Z)); | 327 I->set_collected_closures(GrowableObjectArray::Handle(Z)); |
327 | 328 |
328 DropUncompiledFunctions(); | 329 DropUncompiledFunctions(); |
329 | 330 |
330 // TODO(rmacnak): DropEmptyClasses(); | 331 // TODO(rmacnak): DropEmptyClasses(); |
332 | |
333 BindStaticCalls(); | |
331 } | 334 } |
332 | 335 |
333 | 336 |
334 void Precompiler::ProcessFunction(const Function& function) { | 337 void Precompiler::ProcessFunction(const Function& function) { |
335 if (!function.HasCode()) { | 338 if (!function.HasCode()) { |
336 function_count_++; | 339 function_count_++; |
337 | 340 |
338 if (FLAG_trace_precompiler) { | 341 if (FLAG_trace_precompiler) { |
339 THR_Print("Precompiling %" Pd " %s (%" Pd ", %s)\n", | 342 THR_Print("Precompiling %" Pd " %s (%" Pd ", %s)\n", |
340 function_count_, | 343 function_count_, |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 if (!closures.IsNull()) { | 687 if (!closures.IsNull()) { |
685 for (intptr_t j = 0; j < closures.Length(); j++) { | 688 for (intptr_t j = 0; j < closures.Length(); j++) { |
686 function ^= closures.At(j); | 689 function ^= closures.At(j); |
687 ASSERT(function.HasCode()); | 690 ASSERT(function.HasCode()); |
688 } | 691 } |
689 } | 692 } |
690 } | 693 } |
691 } | 694 } |
692 } | 695 } |
693 | 696 |
697 | |
698 void Precompiler::BindStaticCalls() { | |
699 Library& lib = Library::Handle(Z); | |
700 Class& cls = Class::Handle(Z); | |
701 Array& functions = Array::Handle(Z); | |
702 Function& function = Function::Handle(Z); | |
703 GrowableObjectArray& retained_functions = GrowableObjectArray::Handle(Z); | |
704 GrowableObjectArray& closures = GrowableObjectArray::Handle(Z); | |
705 | |
706 for (intptr_t i = 0; i < libraries_.Length(); i++) { | |
707 lib ^= libraries_.At(i); | |
708 ClassDictionaryIterator it(lib, ClassDictionaryIterator::kIteratePrivate); | |
709 while (it.HasNext()) { | |
710 cls = it.GetNextClass(); | |
711 if (cls.IsDynamicClass()) { | |
712 continue; // class 'dynamic' is in the read-only VM isolate. | |
713 } | |
714 | |
715 functions = cls.functions(); | |
716 retained_functions = GrowableObjectArray::New(); | |
Ivan Posva
2015/10/03 00:07:31
What purpose does this allocation serve?
rmacnak
2015/10/05 17:54:03
From copied iteration code. Removed.
| |
717 for (intptr_t j = 0; j < functions.Length(); j++) { | |
718 function ^= functions.At(j); | |
719 BindStaticCalls(function); | |
720 } | |
721 | |
722 closures = cls.closures(); | |
723 if (!closures.IsNull()) { | |
724 for (intptr_t j = 0; j < closures.Length(); j++) { | |
725 function ^= closures.At(j); | |
726 BindStaticCalls(function); | |
727 } | |
728 } | |
729 } | |
730 } | |
731 } | |
732 | |
733 | |
734 void Precompiler::BindStaticCalls(const Function& function) { | |
735 ASSERT(function.HasCode()); | |
736 | |
737 const Code& code = Code::Handle(Z, function.CurrentCode()); | |
738 | |
739 const Array& table = Array::Handle(Z, code.static_calls_target_table()); | |
740 Smi& pc_offset = Smi::Handle(Z); | |
741 Function& target = Function::Handle(Z); | |
742 Code& target_code = Code::Handle(Z); | |
743 | |
744 for (intptr_t i = 0; i < table.Length(); i += Code::kSCallTableEntryLength) { | |
745 pc_offset ^= table.At(i + Code::kSCallTableOffsetEntry); | |
746 target ^= table.At(i + Code::kSCallTableFunctionEntry); | |
747 if (target.IsNull()) { | |
748 target_code ^= table.At(i + Code::kSCallTableCodeEntry); | |
749 ASSERT(!target_code.IsNull()); | |
750 ASSERT(!target_code.IsFunctionCode()); | |
751 // Allocation stub or AllocateContext or AllocateArray or ... | |
752 } else { | |
753 ASSERT(target.HasCode()); | |
754 target_code ^= target.CurrentCode(); | |
755 CodePatcher::PatchStaticCallAt(pc_offset.Value() + code.EntryPoint(), | |
Ivan Posva
2015/10/03 00:07:31
Can you please explain why only patching of the fu
rmacnak
2015/10/05 17:54:03
Allocation stubs are generated eagerly, so their u
Ivan Posva
2015/10/05 18:30:06
Put differently: You are using the stub as a handl
| |
756 code, target_code); | |
757 } | |
758 } | |
759 code.set_static_calls_target_table(Object::empty_array()); | |
760 } | |
761 | |
694 } // namespace dart | 762 } // namespace dart |
OLD | NEW |