| 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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 11714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11725 const intptr_t len = NumberOfChecks(); | 11725 const intptr_t len = NumberOfChecks(); |
| 11726 for (intptr_t i = 0; i < len; i++) { | 11726 for (intptr_t i = 0; i < len; i++) { |
| 11727 if (GetReceiverClassIdAt(i) == class_id) { | 11727 if (GetReceiverClassIdAt(i) == class_id) { |
| 11728 return GetTargetAt(i); | 11728 return GetTargetAt(i); |
| 11729 } | 11729 } |
| 11730 } | 11730 } |
| 11731 return Function::null(); | 11731 return Function::null(); |
| 11732 } | 11732 } |
| 11733 | 11733 |
| 11734 | 11734 |
| 11735 RawICData* ICData::AsUnaryClassChecksForCid( |
| 11736 intptr_t cid, const Function& target) const { |
| 11737 ASSERT(!IsNull()); |
| 11738 const intptr_t kNumArgsTested = 1; |
| 11739 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); |
| 11740 |
| 11741 // Copy count so that we copy the state "count == 0" vs "count > 0". |
| 11742 result.AddReceiverCheck(cid, target, GetCountAt(0)); |
| 11743 return result.raw(); |
| 11744 } |
| 11745 |
| 11746 |
| 11735 RawICData* ICData::AsUnaryClassChecksForArgNr(intptr_t arg_nr) const { | 11747 RawICData* ICData::AsUnaryClassChecksForArgNr(intptr_t arg_nr) const { |
| 11736 ASSERT(!IsNull()); | 11748 ASSERT(!IsNull()); |
| 11737 ASSERT(NumArgsTested() > arg_nr); | 11749 ASSERT(NumArgsTested() > arg_nr); |
| 11738 if ((arg_nr == 0) && (NumArgsTested() == 1)) { | 11750 if ((arg_nr == 0) && (NumArgsTested() == 1)) { |
| 11739 // Frequent case. | 11751 // Frequent case. |
| 11740 return raw(); | 11752 return raw(); |
| 11741 } | 11753 } |
| 11742 const intptr_t kNumArgsTested = 1; | 11754 const intptr_t kNumArgsTested = 1; |
| 11743 ICData& result = ICData::Handle(ICData::New( | 11755 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); |
| 11744 Function::Handle(owner()), | |
| 11745 String::Handle(target_name()), | |
| 11746 Array::Handle(arguments_descriptor()), | |
| 11747 deopt_id(), | |
| 11748 kNumArgsTested)); | |
| 11749 const intptr_t len = NumberOfChecks(); | 11756 const intptr_t len = NumberOfChecks(); |
| 11750 for (intptr_t i = 0; i < len; i++) { | 11757 for (intptr_t i = 0; i < len; i++) { |
| 11751 const intptr_t class_id = GetClassIdAt(i, arg_nr); | 11758 const intptr_t class_id = GetClassIdAt(i, arg_nr); |
| 11752 const intptr_t count = GetCountAt(i); | 11759 const intptr_t count = GetCountAt(i); |
| 11753 if (count == 0) { | 11760 if (count == 0) { |
| 11754 continue; | 11761 continue; |
| 11755 } | 11762 } |
| 11756 intptr_t duplicate_class_id = -1; | 11763 intptr_t duplicate_class_id = -1; |
| 11757 const intptr_t result_len = result.NumberOfChecks(); | 11764 const intptr_t result_len = result.NumberOfChecks(); |
| 11758 for (intptr_t k = 0; k < result_len; k++) { | 11765 for (intptr_t k = 0; k < result_len; k++) { |
| 11759 if (class_id == result.GetReceiverClassIdAt(k)) { | 11766 if (class_id == result.GetReceiverClassIdAt(k)) { |
| 11760 duplicate_class_id = k; | 11767 duplicate_class_id = k; |
| 11761 break; | 11768 break; |
| 11762 } | 11769 } |
| 11763 } | 11770 } |
| 11764 if (duplicate_class_id >= 0) { | 11771 if (duplicate_class_id >= 0) { |
| 11765 // This check is valid only when checking the receiver. | 11772 // This check is valid only when checking the receiver. |
| 11766 ASSERT((arg_nr != 0) || | 11773 ASSERT((arg_nr != 0) || |
| 11767 (result.GetTargetAt(duplicate_class_id) == GetTargetAt(i))); | 11774 (result.GetTargetAt(duplicate_class_id) == GetTargetAt(i))); |
| 11768 result.IncrementCountAt(duplicate_class_id, count); | 11775 result.IncrementCountAt(duplicate_class_id, count); |
| 11769 } else { | 11776 } else { |
| 11770 // This will make sure that Smi is first if it exists. | 11777 // This will make sure that Smi is first if it exists. |
| 11771 result.AddReceiverCheck(class_id, | 11778 result.AddReceiverCheck(class_id, |
| 11772 Function::Handle(GetTargetAt(i)), | 11779 Function::Handle(GetTargetAt(i)), |
| 11773 count); | 11780 count); |
| 11774 } | 11781 } |
| 11775 } | 11782 } |
| 11776 // Copy deoptimization reasons. | |
| 11777 result.SetDeoptReasons(DeoptReasons()); | |
| 11778 | 11783 |
| 11779 return result.raw(); | 11784 return result.raw(); |
| 11780 } | 11785 } |
| 11781 | 11786 |
| 11782 | 11787 |
| 11783 bool ICData::AllTargetsHaveSameOwner(intptr_t owner_cid) const { | 11788 bool ICData::AllTargetsHaveSameOwner(intptr_t owner_cid) const { |
| 11784 if (NumberOfChecks() == 0) return false; | 11789 if (NumberOfChecks() == 0) return false; |
| 11785 Class& cls = Class::Handle(); | 11790 Class& cls = Class::Handle(); |
| 11786 const intptr_t len = NumberOfChecks(); | 11791 const intptr_t len = NumberOfChecks(); |
| 11787 for (intptr_t i = 0; i < len; i++) { | 11792 for (intptr_t i = 0; i < len; i++) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11890 // Number of array elements in one test entry. | 11895 // Number of array elements in one test entry. |
| 11891 intptr_t len = result.TestEntryLength(); | 11896 intptr_t len = result.TestEntryLength(); |
| 11892 // IC data array must be null terminated (sentinel entry). | 11897 // IC data array must be null terminated (sentinel entry). |
| 11893 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); | 11898 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); |
| 11894 result.set_ic_data(ic_data); | 11899 result.set_ic_data(ic_data); |
| 11895 result.WriteSentinel(ic_data); | 11900 result.WriteSentinel(ic_data); |
| 11896 return result.raw(); | 11901 return result.raw(); |
| 11897 } | 11902 } |
| 11898 | 11903 |
| 11899 | 11904 |
| 11905 RawICData* ICData::NewFrom(const ICData& from, intptr_t num_args_tested) { |
| 11906 const ICData& result = ICData::Handle(ICData::New( |
| 11907 Function::Handle(from.owner()), |
| 11908 String::Handle(from.target_name()), |
| 11909 Array::Handle(from.arguments_descriptor()), |
| 11910 from.deopt_id(), |
| 11911 num_args_tested)); |
| 11912 // Copy deoptimization reasons. |
| 11913 result.SetDeoptReasons(from.DeoptReasons()); |
| 11914 return result.raw(); |
| 11915 } |
| 11916 |
| 11917 |
| 11900 void ICData::PrintJSONImpl(JSONStream* stream, bool ref) const { | 11918 void ICData::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 11901 Object::PrintJSONImpl(stream, ref); | 11919 Object::PrintJSONImpl(stream, ref); |
| 11902 } | 11920 } |
| 11903 | 11921 |
| 11904 | 11922 |
| 11905 void ICData::PrintToJSONArray(const JSONArray& jsarray, | 11923 void ICData::PrintToJSONArray(const JSONArray& jsarray, |
| 11906 intptr_t token_pos, | 11924 intptr_t token_pos, |
| 11907 bool is_static_call) const { | 11925 bool is_static_call) const { |
| 11908 Isolate* isolate = Isolate::Current(); | 11926 Isolate* isolate = Isolate::Current(); |
| 11909 Class& cls = Class::Handle(); | 11927 Class& cls = Class::Handle(); |
| (...skipping 8891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20801 return tag_label.ToCString(); | 20819 return tag_label.ToCString(); |
| 20802 } | 20820 } |
| 20803 | 20821 |
| 20804 | 20822 |
| 20805 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20823 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20806 Instance::PrintJSONImpl(stream, ref); | 20824 Instance::PrintJSONImpl(stream, ref); |
| 20807 } | 20825 } |
| 20808 | 20826 |
| 20809 | 20827 |
| 20810 } // namespace dart | 20828 } // namespace dart |
| OLD | NEW |