Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/code_generator.h" | 5 #include "vm/code_generator.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 "Trace IC miss in optimized code"); | 54 "Trace IC miss in optimized code"); |
| 55 DEFINE_FLAG(bool, trace_optimized_ic_calls, false, | 55 DEFINE_FLAG(bool, trace_optimized_ic_calls, false, |
| 56 "Trace IC calls in optimized code."); | 56 "Trace IC calls in optimized code."); |
| 57 DEFINE_FLAG(bool, trace_patching, false, "Trace patching of code."); | 57 DEFINE_FLAG(bool, trace_patching, false, "Trace patching of code."); |
| 58 DEFINE_FLAG(bool, trace_runtime_calls, false, "Trace runtime calls"); | 58 DEFINE_FLAG(bool, trace_runtime_calls, false, "Trace runtime calls"); |
| 59 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); | 59 DEFINE_FLAG(bool, trace_type_checks, false, "Trace runtime type checks."); |
| 60 | 60 |
| 61 DECLARE_FLAG(int, deoptimization_counter_threshold); | 61 DECLARE_FLAG(int, deoptimization_counter_threshold); |
| 62 DECLARE_FLAG(bool, trace_compiler); | 62 DECLARE_FLAG(bool, trace_compiler); |
| 63 DECLARE_FLAG(bool, warn_on_javascript_compatibility); | 63 DECLARE_FLAG(bool, warn_on_javascript_compatibility); |
| 64 DECLARE_FLAG(int, max_polymorphic_checks); | |
| 64 | 65 |
| 65 DEFINE_FLAG(bool, use_osr, true, "Use on-stack replacement."); | 66 DEFINE_FLAG(bool, use_osr, true, "Use on-stack replacement."); |
| 66 DEFINE_FLAG(bool, trace_osr, false, "Trace attempts at on-stack replacement."); | 67 DEFINE_FLAG(bool, trace_osr, false, "Trace attempts at on-stack replacement."); |
| 67 | 68 |
| 68 DEFINE_FLAG(int, stacktrace_every, 0, | 69 DEFINE_FLAG(int, stacktrace_every, 0, |
| 69 "Compute debugger stacktrace on every N stack overflow checks"); | 70 "Compute debugger stacktrace on every N stack overflow checks"); |
| 70 DEFINE_FLAG(charp, stacktrace_filter, NULL, | 71 DEFINE_FLAG(charp, stacktrace_filter, NULL, |
| 71 "Compute stacktrace in named function on stack overflow checks"); | 72 "Compute stacktrace in named function on stack overflow checks"); |
| 72 DEFINE_FLAG(int, deoptimize_every, 0, | 73 DEFINE_FLAG(int, deoptimize_every, 0, |
| 73 "Deoptimize on every N stack overflow checks"); | 74 "Deoptimize on every N stack overflow checks"); |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 target_function.IsNull() ? "null" : target_function.ToCString()); | 773 target_function.IsNull() ? "null" : target_function.ToCString()); |
| 773 } | 774 } |
| 774 *result = target_function.raw(); | 775 *result = target_function.raw(); |
| 775 return true; | 776 return true; |
| 776 } | 777 } |
| 777 | 778 |
| 778 | 779 |
| 779 // Handle other invocations (implicit closures, noSuchMethod). | 780 // Handle other invocations (implicit closures, noSuchMethod). |
| 780 RawFunction* InlineCacheMissHelper( | 781 RawFunction* InlineCacheMissHelper( |
| 781 const Instance& receiver, | 782 const Instance& receiver, |
| 782 const ICData& ic_data) { | 783 const Array& args_descriptor, |
| 783 const Array& args_descriptor = Array::Handle(ic_data.arguments_descriptor()); | 784 const String& target_name) { |
| 784 | |
| 785 const Class& receiver_class = Class::Handle(receiver.clazz()); | 785 const Class& receiver_class = Class::Handle(receiver.clazz()); |
| 786 const String& target_name = String::Handle(ic_data.target_name()); | |
| 787 | 786 |
| 788 Function& result = Function::Handle(); | 787 Function& result = Function::Handle(); |
| 789 if (!ResolveCallThroughGetter(receiver, | 788 if (!ResolveCallThroughGetter(receiver, |
| 790 receiver_class, | 789 receiver_class, |
| 791 target_name, | 790 target_name, |
| 792 args_descriptor, | 791 args_descriptor, |
| 793 &result)) { | 792 &result)) { |
| 794 ArgumentsDescriptor desc(args_descriptor); | 793 ArgumentsDescriptor desc(args_descriptor); |
| 795 const Function& target_function = | 794 const Function& target_function = |
| 796 Function::Handle(receiver_class.GetInvocationDispatcher( | 795 Function::Handle(receiver_class.GetInvocationDispatcher( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 821 String& function_name = String::Handle(ic_data.target_name()); | 820 String& function_name = String::Handle(ic_data.target_name()); |
| 822 ASSERT(function_name.IsSymbol()); | 821 ASSERT(function_name.IsSymbol()); |
| 823 Function& target_function = Function::Handle( | 822 Function& target_function = Function::Handle( |
| 824 Resolver::ResolveDynamic(receiver, function_name, arguments_descriptor)); | 823 Resolver::ResolveDynamic(receiver, function_name, arguments_descriptor)); |
| 825 if (target_function.IsNull()) { | 824 if (target_function.IsNull()) { |
| 826 if (FLAG_trace_ic) { | 825 if (FLAG_trace_ic) { |
| 827 OS::PrintErr("InlineCacheMissHandler NULL function for %s receiver: %s\n", | 826 OS::PrintErr("InlineCacheMissHandler NULL function for %s receiver: %s\n", |
| 828 String::Handle(ic_data.target_name()).ToCString(), | 827 String::Handle(ic_data.target_name()).ToCString(), |
| 829 receiver.ToCString()); | 828 receiver.ToCString()); |
| 830 } | 829 } |
| 831 target_function = InlineCacheMissHelper(receiver, ic_data); | 830 const Array& args_descriptor = |
| 831 Array::Handle(ic_data.arguments_descriptor()); | |
| 832 const String& target_name = String::Handle(ic_data.target_name()); | |
| 833 target_function = InlineCacheMissHelper(receiver, | |
| 834 args_descriptor, | |
| 835 target_name); | |
| 832 } | 836 } |
| 833 if (target_function.IsNull()) { | 837 if (target_function.IsNull()) { |
| 834 ASSERT(!FLAG_lazy_dispatchers); | 838 ASSERT(!FLAG_lazy_dispatchers); |
| 835 return target_function.raw(); | 839 return target_function.raw(); |
| 836 } | 840 } |
| 837 if (args.length() == 1) { | 841 if (args.length() == 1) { |
| 838 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); | 842 ic_data.AddReceiverCheck(args[0]->GetClassId(), target_function); |
| 839 } else { | 843 } else { |
| 840 GrowableArray<intptr_t> class_ids(args.length()); | 844 GrowableArray<intptr_t> class_ids(args.length()); |
| 841 ASSERT(ic_data.NumArgsTested() == args.length()); | 845 ASSERT(ic_data.NumArgsTested() == args.length()); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 OS::PrintErr("StaticCallMissHandler at %#" Px | 1005 OS::PrintErr("StaticCallMissHandler at %#" Px |
| 1002 " target %s (%" Pd ", %" Pd ")\n", | 1006 " target %s (%" Pd ", %" Pd ")\n", |
| 1003 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); | 1007 caller_frame->pc(), target.ToCString(), cids[0], cids[1]); |
| 1004 } | 1008 } |
| 1005 arguments.SetReturn(target); | 1009 arguments.SetReturn(target); |
| 1006 } | 1010 } |
| 1007 | 1011 |
| 1008 | 1012 |
| 1009 // Handle a miss of a megamorphic cache. | 1013 // Handle a miss of a megamorphic cache. |
| 1010 // Arg0: Receiver. | 1014 // Arg0: Receiver. |
| 1011 // Arg1: ICData object. | 1015 // Arg1: ICData object. |
|
srdjan
2015/11/03 22:30:49
or cache
rmacnak
2015/11/03 23:54:29
Done.
| |
| 1012 // Arg2: Arguments descriptor array. | 1016 // Arg2: Arguments descriptor array. |
| 1013 | 1017 |
| 1014 // Returns: target function to call. | 1018 // Returns: target function to call. |
| 1015 DEFINE_RUNTIME_ENTRY(MegamorphicCacheMissHandler, 3) { | 1019 DEFINE_RUNTIME_ENTRY(MegamorphicCacheMissHandler, 3) { |
| 1016 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); | 1020 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); |
| 1017 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); | 1021 const Object& ic_data_or_cache = Object::Handle(arguments.ArgAt(1)); |
| 1018 const Array& descriptor = Array::CheckedHandle(arguments.ArgAt(2)); | 1022 const Array& descriptor = Array::CheckedHandle(arguments.ArgAt(2)); |
| 1019 const String& name = String::Handle(ic_data.target_name()); | 1023 String& name = String::Handle(); |
|
srdjan
2015/11/03 22:30:49
zone is already defined here, please use it for ha
rmacnak
2015/11/03 23:54:29
Done
| |
| 1020 const MegamorphicCache& cache = MegamorphicCache::Handle( | 1024 if (ic_data_or_cache.IsICData()) { |
| 1021 MegamorphicCacheTable::Lookup(isolate, name, descriptor)); | 1025 name = ICData::Cast(ic_data_or_cache).target_name(); |
| 1026 } else { | |
| 1027 ASSERT(ic_data_or_cache.IsMegamorphicCache()); | |
| 1028 name = MegamorphicCache::Cast(ic_data_or_cache).target_name(); | |
| 1029 } | |
| 1022 Class& cls = Class::Handle(receiver.clazz()); | 1030 Class& cls = Class::Handle(receiver.clazz()); |
| 1023 ASSERT(!cls.IsNull()); | 1031 ASSERT(!cls.IsNull()); |
| 1024 if (FLAG_trace_ic || FLAG_trace_ic_miss_in_optimized) { | 1032 if (FLAG_trace_ic || FLAG_trace_ic_miss_in_optimized) { |
| 1025 OS::PrintErr("Megamorphic IC miss, class=%s, function=%s\n", | 1033 OS::PrintErr("Megamorphic IC miss, class=%s, function=%s\n", |
| 1026 cls.ToCString(), name.ToCString()); | 1034 cls.ToCString(), name.ToCString()); |
| 1027 } | 1035 } |
| 1028 | 1036 |
| 1029 ArgumentsDescriptor args_desc(descriptor); | 1037 ArgumentsDescriptor args_desc(descriptor); |
| 1030 Function& target_function = Function::Handle( | 1038 Function& target_function = Function::Handle( |
| 1031 Resolver::ResolveDynamicForReceiverClass(cls, | 1039 Resolver::ResolveDynamicForReceiverClass(cls, |
| 1032 name, | 1040 name, |
| 1033 args_desc)); | 1041 args_desc)); |
| 1034 if (target_function.IsNull()) { | 1042 if (target_function.IsNull()) { |
| 1035 target_function = InlineCacheMissHelper(receiver, ic_data); | 1043 target_function = InlineCacheMissHelper(receiver, descriptor, name); |
| 1036 } | 1044 } |
| 1037 if (target_function.IsNull()) { | 1045 if (target_function.IsNull()) { |
| 1038 ASSERT(!FLAG_lazy_dispatchers); | 1046 ASSERT(!FLAG_lazy_dispatchers); |
| 1047 // TODO(rmacnak): Consider inserting null into the cache. | |
| 1039 arguments.SetReturn(target_function); | 1048 arguments.SetReturn(target_function); |
| 1040 return; | 1049 return; |
| 1041 } | 1050 } |
| 1042 // Insert function found into cache and return it. | 1051 |
| 1043 cache.EnsureCapacity(); | 1052 if (ic_data_or_cache.IsICData()) { |
| 1044 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); | 1053 const ICData& ic_data = ICData::Cast(ic_data_or_cache); |
| 1045 cache.Insert(class_id, target_function); | 1054 if (ic_data.NumberOfChecks() == FLAG_max_polymorphic_checks) { |
|
srdjan
2015/11/03 22:30:49
Use '>=', it is more reliable than '=='
rmacnak
2015/11/03 23:54:29
Done.
| |
| 1055 // Switch | |
| 1056 const MegamorphicCache& cache = MegamorphicCache::Handle( | |
| 1057 MegamorphicCacheTable::Lookup(isolate, name, descriptor)); | |
| 1058 DartFrameIterator iterator; | |
| 1059 StackFrame* miss_function_frame = iterator.NextFrame(); | |
| 1060 ASSERT(miss_function_frame->IsDartFrame()); | |
| 1061 StackFrame* caller_frame = iterator.NextFrame(); | |
| 1062 ASSERT(caller_frame->IsDartFrame()); | |
| 1063 const Code& code = Code::Handle(caller_frame->LookupDartCode()); | |
| 1064 const Code& stub = | |
| 1065 Code::Handle(StubCode::MegamorphicLookup_entry()->code()); | |
| 1066 CodePatcher::PatchSwitchableCallAt(caller_frame->pc(), | |
| 1067 code, ic_data, cache, stub); | |
| 1068 } else { | |
| 1069 ic_data.AddReceiverCheck(receiver.GetClassId(), target_function); | |
| 1070 } | |
| 1071 } else { | |
| 1072 const MegamorphicCache& cache = MegamorphicCache::Cast(ic_data_or_cache); | |
| 1073 // Insert function found into cache and return it. | |
| 1074 cache.EnsureCapacity(); | |
| 1075 const Smi& class_id = Smi::Handle(Smi::New(cls.id())); | |
| 1076 cache.Insert(class_id, target_function); | |
| 1077 } | |
| 1046 arguments.SetReturn(target_function); | 1078 arguments.SetReturn(target_function); |
| 1047 } | 1079 } |
| 1048 | 1080 |
| 1049 | 1081 |
| 1050 // Invoke appropriate noSuchMethod or closure from getter. | 1082 // Invoke appropriate noSuchMethod or closure from getter. |
| 1051 // Arg0: receiver | 1083 // Arg0: receiver |
| 1052 // Arg1: IC data | 1084 // Arg1: IC data |
|
srdjan
2015/11/03 22:30:49
or cache
rmacnak
2015/11/03 23:54:29
Done.
| |
| 1053 // Arg2: arguments descriptor array | 1085 // Arg2: arguments descriptor array |
| 1054 // Arg3: arguments array | 1086 // Arg3: arguments array |
| 1055 DEFINE_RUNTIME_ENTRY(InvokeNoSuchMethodDispatcher, 4) { | 1087 DEFINE_RUNTIME_ENTRY(InvokeNoSuchMethodDispatcher, 4) { |
| 1056 ASSERT(!FLAG_lazy_dispatchers); | 1088 ASSERT(!FLAG_lazy_dispatchers); |
| 1057 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); | 1089 const Instance& receiver = Instance::CheckedHandle(arguments.ArgAt(0)); |
| 1058 const ICData& ic_data = ICData::CheckedHandle(arguments.ArgAt(1)); | 1090 const Object& ic_data_or_cache = Object::Handle(arguments.ArgAt(1)); |
| 1059 const Array& orig_arguments_desc = Array::CheckedHandle(arguments.ArgAt(2)); | 1091 const Array& orig_arguments_desc = Array::CheckedHandle(arguments.ArgAt(2)); |
| 1060 const Array& orig_arguments = Array::CheckedHandle(arguments.ArgAt(3)); | 1092 const Array& orig_arguments = Array::CheckedHandle(arguments.ArgAt(3)); |
| 1061 const String& target_name = String::Handle(ic_data.target_name()); | 1093 String& target_name = String::Handle(); |
| 1094 if (ic_data_or_cache.IsICData()) { | |
| 1095 target_name = ICData::Cast(ic_data_or_cache).target_name(); | |
| 1096 } else { | |
| 1097 ASSERT(ic_data_or_cache.IsMegamorphicCache()); | |
| 1098 target_name = MegamorphicCache::Cast(ic_data_or_cache).target_name(); | |
| 1099 } | |
| 1062 | 1100 |
| 1063 Class& cls = Class::Handle(receiver.clazz()); | 1101 Class& cls = Class::Handle(receiver.clazz()); |
| 1064 Function& function = Function::Handle(); | 1102 Function& function = Function::Handle(); |
| 1065 | 1103 |
| 1066 // Dart distinguishes getters and regular methods and allows their calls | 1104 // Dart distinguishes getters and regular methods and allows their calls |
| 1067 // to mix with conversions, and its selectors are independent of arity. So do | 1105 // to mix with conversions, and its selectors are independent of arity. So do |
| 1068 // a zigzagged lookup to see if this call failed because of an arity mismatch, | 1106 // a zigzagged lookup to see if this call failed because of an arity mismatch, |
| 1069 // need for conversion, or there really is no such method. | 1107 // need for conversion, or there really is no such method. |
| 1070 | 1108 |
| 1071 #define NO_SUCH_METHOD() \ | 1109 #define NO_SUCH_METHOD() \ |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1844 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1882 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
| 1845 const TypedData& new_data = | 1883 const TypedData& new_data = |
| 1846 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1884 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
| 1847 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1885 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
| 1848 typed_data_cell.SetAt(0, new_data); | 1886 typed_data_cell.SetAt(0, new_data); |
| 1849 arguments.SetReturn(new_data); | 1887 arguments.SetReturn(new_data); |
| 1850 } | 1888 } |
| 1851 | 1889 |
| 1852 | 1890 |
| 1853 } // namespace dart | 1891 } // namespace dart |
| OLD | NEW |