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

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: 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 8202 matching lines...) Expand 10 before | Expand all | Expand 10 after
13050 void ICData::ResetSwitchable(Zone* zone) const { 13061 void ICData::ResetSwitchable(Zone* zone) const {
13051 ASSERT(NumArgsTested() == 1); 13062 ASSERT(NumArgsTested() == 1);
13052 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1))); 13063 set_ic_data_array(Array::Handle(zone, CachedEmptyICDataArray(1)));
13053 } 13064 }
13054 13065
13055 13066
13056 const char* ICData::ToCString() const { 13067 const char* ICData::ToCString() const {
13057 const String& name = String::Handle(target_name()); 13068 const String& name = String::Handle(target_name());
13058 const intptr_t num_args = NumArgsTested(); 13069 const intptr_t num_args = NumArgsTested();
13059 const intptr_t num_checks = NumberOfChecks(); 13070 const intptr_t num_checks = NumberOfChecks();
13071 const intptr_t type_args_len = TypeArgsLen();
13060 return OS::SCreate(Thread::Current()->zone(), 13072 return OS::SCreate(Thread::Current()->zone(),
13061 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd "", 13073 "ICData target:'%s' num-args: %" Pd " num-checks: %" Pd
13062 name.ToCString(), num_args, num_checks); 13074 " "
13075 "type-args-len: %" Pd "",
13076 name.ToCString(), num_args, num_checks, type_args_len);
13063 } 13077 }
13064 13078
13065 13079
13066 RawFunction* ICData::Owner() const { 13080 RawFunction* ICData::Owner() const {
13067 Object& obj = Object::Handle(raw_ptr()->owner_); 13081 Object& obj = Object::Handle(raw_ptr()->owner_);
13068 if (obj.IsNull()) { 13082 if (obj.IsNull()) {
13069 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); 13083 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT);
13070 return Function::null(); 13084 return Function::null();
13071 } else if (obj.IsFunction()) { 13085 } else if (obj.IsFunction()) {
13072 return Function::Cast(obj).raw(); 13086 return Function::Cast(obj).raw();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
13135 void ICData::set_tag(intptr_t value) const { 13149 void ICData::set_tag(intptr_t value) const {
13136 StoreNonPointer(&raw_ptr()->tag_, value); 13150 StoreNonPointer(&raw_ptr()->tag_, value);
13137 } 13151 }
13138 #endif 13152 #endif
13139 13153
13140 intptr_t ICData::NumArgsTested() const { 13154 intptr_t ICData::NumArgsTested() const {
13141 return NumArgsTestedBits::decode(raw_ptr()->state_bits_); 13155 return NumArgsTestedBits::decode(raw_ptr()->state_bits_);
13142 } 13156 }
13143 13157
13144 13158
13159 intptr_t ICData::TypeArgsLen() const {
13160 ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor()));
13161 return args_desc.TypeArgsLen();
13162 }
13163
13164
13145 void ICData::SetNumArgsTested(intptr_t value) const { 13165 void ICData::SetNumArgsTested(intptr_t value) const {
13146 ASSERT(Utils::IsUint(2, value)); 13166 ASSERT(Utils::IsUint(2, value));
13147 StoreNonPointer(&raw_ptr()->state_bits_, 13167 StoreNonPointer(&raw_ptr()->state_bits_,
13148 NumArgsTestedBits::update(value, raw_ptr()->state_bits_)); 13168 NumArgsTestedBits::update(value, raw_ptr()->state_bits_));
13149 } 13169 }
13150 13170
13151 13171
13152 uint32_t ICData::DeoptReasons() const { 13172 uint32_t ICData::DeoptReasons() const {
13153 return DeoptReasonBits::decode(raw_ptr()->state_bits_); 13173 return DeoptReasonBits::decode(raw_ptr()->state_bits_);
13154 } 13174 }
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after
14674 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName()); 14694 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName());
14675 } 14695 }
14676 14696
14677 14697
14678 const char* Code::Name() const { 14698 const char* Code::Name() const {
14679 Zone* zone = Thread::Current()->zone(); 14699 Zone* zone = Thread::Current()->zone();
14680 const Object& obj = Object::Handle(zone, owner()); 14700 const Object& obj = Object::Handle(zone, owner());
14681 if (obj.IsNull()) { 14701 if (obj.IsNull()) {
14682 // Regular stub. 14702 // Regular stub.
14683 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); 14703 const char* name = StubCode::NameOfStub(UncheckedEntryPoint());
14684 ASSERT(name != NULL); 14704 if (name == NULL) {
14705 return zone->PrintToString("[this stub]"); // Not yet recorded.
rmacnak 2017/06/14 00:14:20 ASSERT stub code not initialized? I think there's
regis 2017/06/14 21:02:04 I found this in the profiler: StubCode::HasBeenIni
14706 }
14685 return zone->PrintToString("[Stub] %s", name); 14707 return zone->PrintToString("[Stub] %s", name);
14686 } else if (obj.IsClass()) { 14708 } else if (obj.IsClass()) {
14687 // Allocation stub. 14709 // Allocation stub.
14688 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName()); 14710 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName());
14689 ASSERT(!cls_name.IsNull()); 14711 ASSERT(!cls_name.IsNull());
14690 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString()); 14712 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString());
14691 } else { 14713 } else {
14692 ASSERT(obj.IsFunction()); 14714 ASSERT(obj.IsFunction());
14693 // Dart function. 14715 // Dart function.
14694 const char* opt = is_optimized() ? "*" : ""; 14716 const char* opt = is_optimized() ? "*" : "";
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
15958 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); 15980 const bool other_is_dart_function = instantiated_other.IsDartFunctionType();
15959 if (other_is_dart_function || instantiated_other.IsFunctionType()) { 15981 if (other_is_dart_function || instantiated_other.IsFunctionType()) {
15960 // Check if this instance understands a call() method of a compatible type. 15982 // Check if this instance understands a call() method of a compatible type.
15961 Function& sig_fun = 15983 Function& sig_fun =
15962 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); 15984 Function::Handle(zone, cls.LookupCallFunctionForTypeTest());
15963 if (!sig_fun.IsNull()) { 15985 if (!sig_fun.IsNull()) {
15964 if (other_is_dart_function) { 15986 if (other_is_dart_function) {
15965 return true; 15987 return true;
15966 } 15988 }
15967 if (!sig_fun.HasInstantiatedSignature()) { 15989 if (!sig_fun.HasInstantiatedSignature()) {
15990 // The following signature instantiation of sig_fun with its own type
15991 // parameters only works if sig_fun has no generic parent, which is
15992 // guaranteed to be the case, since the looked up call() function
15993 // cannot be nested. It is most probably not even generic.
15994 ASSERT(!sig_fun.HasGenericParent());
15968 const TypeArguments& function_type_arguments = 15995 const TypeArguments& function_type_arguments =
15969 TypeArguments::Handle(zone, sig_fun.type_parameters()); 15996 TypeArguments::Handle(zone, sig_fun.type_parameters());
15970 // No bound error possible, since the instance exists. 15997 // No bound error possible, since the instance exists.
15971 sig_fun = sig_fun.InstantiateSignatureFrom( 15998 sig_fun = sig_fun.InstantiateSignatureFrom(
15972 type_arguments, function_type_arguments, Heap::kOld); 15999 type_arguments, function_type_arguments, Heap::kOld);
15973 } 16000 }
15974 const Function& other_signature = 16001 const Function& other_signature =
15975 Function::Handle(zone, Type::Cast(instantiated_other).signature()); 16002 Function::Handle(zone, Type::Cast(instantiated_other).signature());
15976 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) { 16003 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) {
15977 return true; 16004 return true;
(...skipping 7398 matching lines...) Expand 10 before | Expand all | Expand 10 after
23376 return UserTag::null(); 23403 return UserTag::null();
23377 } 23404 }
23378 23405
23379 23406
23380 const char* UserTag::ToCString() const { 23407 const char* UserTag::ToCString() const {
23381 const String& tag_label = String::Handle(label()); 23408 const String& tag_label = String::Handle(label());
23382 return tag_label.ToCString(); 23409 return tag_label.ToCString();
23383 } 23410 }
23384 23411
23385 } // namespace dart 23412 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698