OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 " type-args-len: %" Pd "", |
| 13111 name.ToCString(), num_args, num_checks, type_args_len); |
13099 } | 13112 } |
13100 | 13113 |
13101 | 13114 |
13102 RawFunction* ICData::Owner() const { | 13115 RawFunction* ICData::Owner() const { |
13103 Object& obj = Object::Handle(raw_ptr()->owner_); | 13116 Object& obj = Object::Handle(raw_ptr()->owner_); |
13104 if (obj.IsNull()) { | 13117 if (obj.IsNull()) { |
13105 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); | 13118 ASSERT(Dart::vm_snapshot_kind() == Snapshot::kFullAOT); |
13106 return Function::null(); | 13119 return Function::null(); |
13107 } else if (obj.IsFunction()) { | 13120 } else if (obj.IsFunction()) { |
13108 return Function::Cast(obj).raw(); | 13121 return Function::Cast(obj).raw(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13171 void ICData::set_tag(intptr_t value) const { | 13184 void ICData::set_tag(intptr_t value) const { |
13172 StoreNonPointer(&raw_ptr()->tag_, value); | 13185 StoreNonPointer(&raw_ptr()->tag_, value); |
13173 } | 13186 } |
13174 #endif | 13187 #endif |
13175 | 13188 |
13176 intptr_t ICData::NumArgsTested() const { | 13189 intptr_t ICData::NumArgsTested() const { |
13177 return NumArgsTestedBits::decode(raw_ptr()->state_bits_); | 13190 return NumArgsTestedBits::decode(raw_ptr()->state_bits_); |
13178 } | 13191 } |
13179 | 13192 |
13180 | 13193 |
| 13194 intptr_t ICData::TypeArgsLen() const { |
| 13195 ArgumentsDescriptor args_desc(Array::Handle(arguments_descriptor())); |
| 13196 return args_desc.TypeArgsLen(); |
| 13197 } |
| 13198 |
| 13199 |
13181 void ICData::SetNumArgsTested(intptr_t value) const { | 13200 void ICData::SetNumArgsTested(intptr_t value) const { |
13182 ASSERT(Utils::IsUint(2, value)); | 13201 ASSERT(Utils::IsUint(2, value)); |
13183 StoreNonPointer(&raw_ptr()->state_bits_, | 13202 StoreNonPointer(&raw_ptr()->state_bits_, |
13184 NumArgsTestedBits::update(value, raw_ptr()->state_bits_)); | 13203 NumArgsTestedBits::update(value, raw_ptr()->state_bits_)); |
13185 } | 13204 } |
13186 | 13205 |
13187 | 13206 |
13188 uint32_t ICData::DeoptReasons() const { | 13207 uint32_t ICData::DeoptReasons() const { |
13189 return DeoptReasonBits::decode(raw_ptr()->state_bits_); | 13208 return DeoptReasonBits::decode(raw_ptr()->state_bits_); |
13190 } | 13209 } |
(...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14710 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName()); | 14729 return Thread::Current()->zone()->PrintToString("Code(%s)", QualifiedName()); |
14711 } | 14730 } |
14712 | 14731 |
14713 | 14732 |
14714 const char* Code::Name() const { | 14733 const char* Code::Name() const { |
14715 Zone* zone = Thread::Current()->zone(); | 14734 Zone* zone = Thread::Current()->zone(); |
14716 const Object& obj = Object::Handle(zone, owner()); | 14735 const Object& obj = Object::Handle(zone, owner()); |
14717 if (obj.IsNull()) { | 14736 if (obj.IsNull()) { |
14718 // Regular stub. | 14737 // Regular stub. |
14719 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); | 14738 const char* name = StubCode::NameOfStub(UncheckedEntryPoint()); |
14720 ASSERT(name != NULL); | 14739 if (name == NULL) { |
| 14740 ASSERT(!StubCode::HasBeenInitialized()); |
| 14741 return zone->PrintToString("[this stub]"); // Not yet recorded. |
| 14742 } |
14721 return zone->PrintToString("[Stub] %s", name); | 14743 return zone->PrintToString("[Stub] %s", name); |
14722 } else if (obj.IsClass()) { | 14744 } else if (obj.IsClass()) { |
14723 // Allocation stub. | 14745 // Allocation stub. |
14724 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName()); | 14746 String& cls_name = String::Handle(zone, Class::Cast(obj).ScrubbedName()); |
14725 ASSERT(!cls_name.IsNull()); | 14747 ASSERT(!cls_name.IsNull()); |
14726 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString()); | 14748 return zone->PrintToString("[Stub] Allocate %s", cls_name.ToCString()); |
14727 } else { | 14749 } else { |
14728 ASSERT(obj.IsFunction()); | 14750 ASSERT(obj.IsFunction()); |
14729 // Dart function. | 14751 // Dart function. |
14730 const char* opt = is_optimized() ? "*" : ""; | 14752 const char* opt = is_optimized() ? "*" : ""; |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15994 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); | 16016 const bool other_is_dart_function = instantiated_other.IsDartFunctionType(); |
15995 if (other_is_dart_function || instantiated_other.IsFunctionType()) { | 16017 if (other_is_dart_function || instantiated_other.IsFunctionType()) { |
15996 // Check if this instance understands a call() method of a compatible type. | 16018 // Check if this instance understands a call() method of a compatible type. |
15997 Function& sig_fun = | 16019 Function& sig_fun = |
15998 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); | 16020 Function::Handle(zone, cls.LookupCallFunctionForTypeTest()); |
15999 if (!sig_fun.IsNull()) { | 16021 if (!sig_fun.IsNull()) { |
16000 if (other_is_dart_function) { | 16022 if (other_is_dart_function) { |
16001 return true; | 16023 return true; |
16002 } | 16024 } |
16003 if (!sig_fun.HasInstantiatedSignature()) { | 16025 if (!sig_fun.HasInstantiatedSignature()) { |
| 16026 // The following signature instantiation of sig_fun with its own type |
| 16027 // parameters only works if sig_fun has no generic parent, which is |
| 16028 // guaranteed to be the case, since the looked up call() function |
| 16029 // cannot be nested. It is most probably not even generic. |
| 16030 ASSERT(!sig_fun.HasGenericParent()); |
16004 const TypeArguments& function_type_arguments = | 16031 const TypeArguments& function_type_arguments = |
16005 TypeArguments::Handle(zone, sig_fun.type_parameters()); | 16032 TypeArguments::Handle(zone, sig_fun.type_parameters()); |
16006 // No bound error possible, since the instance exists. | 16033 // No bound error possible, since the instance exists. |
16007 sig_fun = sig_fun.InstantiateSignatureFrom( | 16034 sig_fun = sig_fun.InstantiateSignatureFrom( |
16008 type_arguments, function_type_arguments, Heap::kOld); | 16035 type_arguments, function_type_arguments, Heap::kOld); |
16009 } | 16036 } |
16010 const Function& other_signature = | 16037 const Function& other_signature = |
16011 Function::Handle(zone, Type::Cast(instantiated_other).signature()); | 16038 Function::Handle(zone, Type::Cast(instantiated_other).signature()); |
16012 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) { | 16039 if (sig_fun.IsSubtypeOf(other_signature, bound_error, NULL, Heap::kOld)) { |
16013 return true; | 16040 return true; |
(...skipping 7405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23419 return UserTag::null(); | 23446 return UserTag::null(); |
23420 } | 23447 } |
23421 | 23448 |
23422 | 23449 |
23423 const char* UserTag::ToCString() const { | 23450 const char* UserTag::ToCString() const { |
23424 const String& tag_label = String::Handle(label()); | 23451 const String& tag_label = String::Handle(label()); |
23425 return tag_label.ToCString(); | 23452 return tag_label.ToCString(); |
23426 } | 23453 } |
23427 | 23454 |
23428 } // namespace dart | 23455 } // namespace dart |
OLD | NEW |