Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: runtime/vm/object.cc

Issue 2941643002: Check for a passed-in type argument vector in the prolog of generic functions. (Closed)
Patch Set: Fix lookup in dart:_internal Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/become.h" 10 #include "vm/become.h"
(...skipping 2655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 Function& invocation = Function::Handle( 2666 Function& invocation = Function::Handle(
2667 zone, Function::New( 2667 zone, Function::New(
2668 String::Handle(zone, Symbols::New(thread, target_name)), kind, 2668 String::Handle(zone, Symbols::New(thread, target_name)), kind,
2669 false, // Not static. 2669 false, // Not static.
2670 false, // Not const. 2670 false, // Not const.
2671 false, // Not abstract. 2671 false, // Not abstract.
2672 false, // Not external. 2672 false, // Not external.
2673 false, // Not native. 2673 false, // Not native.
2674 *this, TokenPosition::kMinSource)); 2674 *this, TokenPosition::kMinSource));
2675 ArgumentsDescriptor desc(args_desc); 2675 ArgumentsDescriptor desc(args_desc);
2676 if (desc.TypeArgsLen() > 0) {
2677 // Make dispatcher function generic, since type arguments are passed.
2678 const TypeArguments& type_params =
2679 TypeArguments::Handle(zone, TypeArguments::New(desc.TypeArgsLen()));
2680 // TODO(regis): Can we leave the array uninitialized to save memory?
2681 invocation.set_type_parameters(type_params);
2682 }
2683
2676 invocation.set_num_fixed_parameters(desc.PositionalCount()); 2684 invocation.set_num_fixed_parameters(desc.PositionalCount());
2677 invocation.SetNumOptionalParameters(desc.NamedCount(), 2685 invocation.SetNumOptionalParameters(desc.NamedCount(),
2678 false); // Not positional. 2686 false); // Not positional.
2679 invocation.set_parameter_types( 2687 invocation.set_parameter_types(
2680 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld))); 2688 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld)));
2681 invocation.set_parameter_names( 2689 invocation.set_parameter_names(
2682 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld))); 2690 Array::Handle(zone, Array::New(desc.Count(), Heap::kOld)));
2683 // Receiver. 2691 // Receiver.
2684 invocation.SetParameterTypeAt(0, Object::dynamic_type()); 2692 invocation.SetParameterTypeAt(0, Object::dynamic_type());
2685 invocation.SetParameterNameAt(0, Symbols::This()); 2693 invocation.SetParameterNameAt(0, Symbols::This());
(...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4828 } 4836 }
4829 4837
4830 4838
4831 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { 4839 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const {
4832 ASSERT(!IsCanonical()); 4840 ASSERT(!IsCanonical());
4833 StorePointer(TypeAddr(index), value.raw()); 4841 StorePointer(TypeAddr(index), value.raw());
4834 } 4842 }
4835 4843
4836 4844
4837 bool TypeArguments::IsResolved() const { 4845 bool TypeArguments::IsResolved() const {
4846 if (IsCanonical()) {
4847 return true;
4848 }
4838 AbstractType& type = AbstractType::Handle(); 4849 AbstractType& type = AbstractType::Handle();
4839 const intptr_t num_types = Length(); 4850 const intptr_t num_types = Length();
4840 for (intptr_t i = 0; i < num_types; i++) { 4851 for (intptr_t i = 0; i < num_types; i++) {
4841 type = TypeAt(i); 4852 type = TypeAt(i);
4842 if (!type.IsResolved()) { 4853 if (!type.IsResolved()) {
4843 return false; 4854 return false;
4844 } 4855 }
4845 } 4856 }
4846 return true; 4857 return true;
4847 } 4858 }
(...skipping 8238 matching lines...) Expand 10 before | Expand all | Expand 10 after
13086 void ICData::ResetSwitchable(Zone* zone) const { 13097 void ICData::ResetSwitchable(Zone* zone) const {
13087 ASSERT(NumArgsTested() == 1); 13098 ASSERT(NumArgsTested() == 1);
13088 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1))); 13099 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1)));
13089 } 13100 }
13090 13101
13091 13102
13092 const char* ICData::ToCString() const { 13103 const char* ICData::ToCString() const {
13093 const String& name = String::Handle(target_name()); 13104 const String& name = String::Handle(target_name());
13094 const intptr_t num_args = NumArgsTested(); 13105 const intptr_t num_args = NumArgsTested();
13095 const intptr_t num_checks = NumberOfChecks(); 13106 const intptr_t num_checks = NumberOfChecks();
13107 const intptr_t type_args_len = TypeArgsLen();
13096 return OS::SCreate(Thread::Current()->zone(), 13108 return OS::SCreate(Thread::Current()->zone(),
13097 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd "", 13109 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd
13098 name.ToCString(), num_args, num_checks); 13110 " "
Vyacheslav Egorov (Google) 2017/06/20 15:21:41 maybe: " type-args-len: " ... to remove this str
regis 2017/06/21 04:39:04 Done.
13111 "type-args-len: %" Pd "",
13112 name.ToCString(), num_args, num_checks, type_args_len);
13099 } 13113 }
13100 13114
13101 13115
13102 RawFunction* ICData::Owner() const { 13116 RawFunction* ICData::Owner() const {
13103 Object& obj = Object::Handle(raw_ptr()->owner_); 13117 Object& obj = Object::Handle(raw_ptr()->owner_);
13104 if (obj.IsNull()) { 13118 if (obj.IsNull()) {
13105 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); 13119 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT);
13106 return Function::null(); 13120 return Function::null();
13107 } else if (obj.IsFunction()) { 13121 } else if (obj.IsFunction()) {
13108 return Function::Cast(obj).raw(); 13122 return Function::Cast(obj).raw();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
13171 void ICData::set_tag(intptr_t value) const { 13185 void ICData::set_tag(intptr_t value) const {
13172 StoreNonPointer(&raw_ptr()->tag_, value); 13186 StoreNonPointer(&raw_ptr()->tag_, value);
13173 } 13187 }
13174 #endif 13188 #endif
13175 13189
13176 intptr_t ICData::NumArgsTested() const { 13190 intptr_t ICData::NumArgsTested() const {
13177 return NumArgsTestedBits::decode(raw_ptr()->state_bits_); 13191 return NumArgsTestedBits::decode(raw_ptr()->state_bits_);
13178 } 13192 }
13179 13193
13180 13194
13195 intptr_t ICData::TypeArgsLen() const {
13196 ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
13197 return args_desc.TypeArgsLen();
13198 }
13199
13200
13181 void ICData::SetNumArgsTested(intptr_t value) const { 13201 void ICData::SetNumArgsTested(intptr_t value) const {
13182 ASSERT(Utils::IsUint(2, value)); 13202 ASSERT(Utils::IsUint(2, value));
13183 StoreNonPointer(&raw_ptr()->state_bits_, 13203 StoreNonPointer(&raw_ptr()->state_bits_,
13184 NumArgsTestedBits::update(value, raw_ptr()->state_bits_)); 13204 NumArgsTestedBits::update(value, raw_ptr()->state_bits_));
13185 } 13205 }
13186 13206
13187 13207
13188 uint32_t ICData::DeoptReasons() const { 13208 uint32_t ICData::DeoptReasons() const {
13189 return DeoptReasonBits::decode(raw_ptr()->state_bits_); 13209 return DeoptReasonBits::decode(raw_ptr()->state_bits_);
13190 } 13210 }
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
14710 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName()); 14730 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName());
14711 } 14731 }
14712 14732
14713 14733
14714 const char* Code::Name() const { 14734 const char* Code::Name() const {
14715 Zone* zone = Thread::Current()->zone(); 14735 Zone* zone = Thread::Current()->zone();
14716 const Object& obj = Object::Handle(zone, owner()); 14736 const Object& obj = Object::Handle(zone, owner());
14717 if (obj.IsNull()) { 14737 if (obj.IsNull()) {
14718 // Regular stub. 14738 // Regular stub.
14719 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); 14739 const char* name = StubCode::NameOfStub(UncheckedEntryPoint());
14720 ASSERT(name != NULL); 14740 if (name == NULL) {
14741 ASSERT(!StubCode::HasBeenInitialized());
14742 return zone->PrintToString("[this stub]"); // Not yet recorded.
14743 }
14721 return zone->PrintToString("[Stub] %s", name); 14744 return zone->PrintToString("[Stub] %s", name);
14722 } else if (obj.IsClass()) { 14745 } else if (obj.IsClass()) {
14723 // Allocation stub. 14746 // Allocation stub.
14724 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName()); 14747 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName());
14725 ASSERT(!cls_name.IsNull()); 14748 ASSERT(!cls_name.IsNull());
14726 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString()); 14749 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString());
14727 } else { 14750 } else {
14728 ASSERT(obj.IsFunction()); 14751 ASSERT(obj.IsFunction());
14729 // Dart function. 14752 // Dart function.
14730 const char* opt = is_optimized() ? "*" : ""; 14753 const char* opt = is_optimized() ? "*" : "";
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
15994 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); 16017 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15995 if (other_is_dart_function || instantiated_other.IsFunctionType()) { 16018 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15996 // Check if this instance understands a call() method of a compatible type. 16019 // Check if this instance understands a call() method of a compatible type.
15997 Function& sig_fun = 16020 Function& sig_fun =
15998 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); 16021 Function::Handle(zone, cls.LookupCallFunctionForTypeTest());
15999 if (!sig_fun.IsNull()) { 16022 if (!sig_fun.IsNull()) {
16000 if (other_is_dart_function) { 16023 if (other_is_dart_function) {
16001 return true; 16024 return true;
16002 } 16025 }
16003 if (!sig_fun.HasInstantiatedSignature()) { 16026 if (!sig_fun.HasInstantiatedSignature()) {
16027 // The following signature instantiation of sig_fun with its own type
16028 // parameters only works if sig_fun has no generic parent, which is
16029 // guaranteed to be the case, since the looked up call() function
16030 // cannot be nested. It is most probably not even generic.
16031 ASSERT(!sig_fun.HasGenericParent());
16004 const TypeArguments& function_type_arguments = 16032 const TypeArguments& function_type_arguments =
16005 TypeArguments::Handle(zone, sig_fun.type_parameters()); 16033 TypeArguments::Handle(zone, sig_fun.type_parameters());
16006 // No bound error possible, since the instance exists. 16034 // No bound error possible, since the instance exists.
16007 sig_fun = sig_fun.InstantiateSignatureFrom( 16035 sig_fun = sig_fun.InstantiateSignatureFrom(
16008 type_arguments, function_type_arguments, Heap::kOld); 16036 type_arguments, function_type_arguments, Heap::kOld);
16009 } 16037 }
16010 const Function& other_signature = 16038 const Function& other_signature =
16011 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 16039 Function::Handle(zone, Type::Cast(instantiated_other).signature());
16012 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) { 16040 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) {
16013 return true; 16041 return true;
(...skipping 7405 matching lines...) Expand 10 before | Expand all | Expand 10 after
23419 return UserTag::null(); 23447 return UserTag::null();
23420 } 23448 }
23421 23449
23422 23450
23423 const char* UserTag::ToCString() const { 23451 const char* UserTag::ToCString() const {
23424 const String& tag_label = String::Handle(label()); 23452 const String& tag_label = String::Handle(label());
23425 return tag_label.ToCString(); 23453 return tag_label.ToCString();
23426 } 23454 }
23427 23455
23428 } // namespace dart 23456 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698