| 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 12974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12985 result.AddReceiverCheck(class_id, | 12985 result.AddReceiverCheck(class_id, |
| 12986 Function::Handle(GetTargetAt(i)), | 12986 Function::Handle(GetTargetAt(i)), |
| 12987 count); | 12987 count); |
| 12988 } | 12988 } |
| 12989 } | 12989 } |
| 12990 | 12990 |
| 12991 return result.raw(); | 12991 return result.raw(); |
| 12992 } | 12992 } |
| 12993 | 12993 |
| 12994 | 12994 |
| 12995 // (cid, count) tuple used to sort ICData by count. |
| 12996 struct CidCount { |
| 12997 CidCount(intptr_t cid_, intptr_t count_, Function* f_) |
| 12998 : cid(cid_), count(count_), function(f_) {} |
| 12999 |
| 13000 static int HighestCountFirst(const CidCount* a, const CidCount* b); |
| 13001 |
| 13002 intptr_t cid; |
| 13003 intptr_t count; |
| 13004 Function* function; |
| 13005 }; |
| 13006 |
| 13007 |
| 13008 int CidCount::HighestCountFirst(const CidCount* a, const CidCount* b) { |
| 13009 if (a->count > b->count) { |
| 13010 return -1; |
| 13011 } |
| 13012 return (a->count < b->count) ? 1 : 0; |
| 13013 } |
| 13014 |
| 13015 |
| 13016 RawICData* ICData::AsUnaryClassChecksSortedByCount() const { |
| 13017 ASSERT(!IsNull()); |
| 13018 const intptr_t kNumArgsTested = 1; |
| 13019 const intptr_t len = NumberOfChecks(); |
| 13020 if (len <= 1) { |
| 13021 // No sorting needed. |
| 13022 return AsUnaryClassChecks(); |
| 13023 } |
| 13024 GrowableArray<CidCount> aggregate; |
| 13025 for (intptr_t i = 0; i < len; i++) { |
| 13026 const intptr_t class_id = GetClassIdAt(i, 0); |
| 13027 const intptr_t count = GetCountAt(i); |
| 13028 if (count == 0) { |
| 13029 continue; |
| 13030 } |
| 13031 bool found = false; |
| 13032 for (intptr_t r = 0; r < aggregate.length(); r++) { |
| 13033 if (aggregate[r].cid == class_id) { |
| 13034 aggregate[r].count += count; |
| 13035 found = true; |
| 13036 break; |
| 13037 } |
| 13038 } |
| 13039 if (!found) { |
| 13040 aggregate.Add(CidCount(class_id, count, |
| 13041 &Function::ZoneHandle(GetTargetAt(i)))); |
| 13042 } |
| 13043 } |
| 13044 aggregate.Sort(CidCount::HighestCountFirst); |
| 13045 |
| 13046 ICData& result = ICData::Handle(ICData::NewFrom(*this, kNumArgsTested)); |
| 13047 ASSERT(result.NumberOfChecks() == 0); |
| 13048 // Room for all entries and the sentinel. |
| 13049 const intptr_t data_len = |
| 13050 result.TestEntryLength() * (aggregate.length() + 1); |
| 13051 const Array& data = Array::Handle(Array::New(data_len, Heap::kOld)); |
| 13052 result.set_ic_data_array(data); |
| 13053 ASSERT(result.NumberOfChecks() == aggregate.length()); |
| 13054 |
| 13055 intptr_t pos = 0; |
| 13056 for (intptr_t i = 0; i < aggregate.length(); i++) { |
| 13057 data.SetAt(pos + 0, Smi::Handle(Smi::New(aggregate[i].cid))); |
| 13058 data.SetAt(pos + TargetIndexFor(1), *aggregate[i].function); |
| 13059 data.SetAt(pos + CountIndexFor(1), |
| 13060 Smi::Handle(Smi::New(aggregate[i].count))); |
| 13061 |
| 13062 pos += result.TestEntryLength(); |
| 13063 } |
| 13064 WriteSentinel(data, result.TestEntryLength()); |
| 13065 result.set_ic_data_array(data); |
| 13066 return result.raw(); |
| 13067 } |
| 13068 |
| 13069 |
| 12995 bool ICData::AllTargetsHaveSameOwner(intptr_t owner_cid) const { | 13070 bool ICData::AllTargetsHaveSameOwner(intptr_t owner_cid) const { |
| 12996 if (NumberOfChecks() == 0) return false; | 13071 if (NumberOfChecks() == 0) return false; |
| 12997 Class& cls = Class::Handle(); | 13072 Class& cls = Class::Handle(); |
| 12998 const intptr_t len = NumberOfChecks(); | 13073 const intptr_t len = NumberOfChecks(); |
| 12999 for (intptr_t i = 0; i < len; i++) { | 13074 for (intptr_t i = 0; i < len; i++) { |
| 13000 if (IsUsedAt(i)) { | 13075 if (IsUsedAt(i)) { |
| 13001 cls = Function::Handle(GetTargetAt(i)).Owner(); | 13076 cls = Function::Handle(GetTargetAt(i)).Owner(); |
| 13002 if (cls.id() != owner_cid) { | 13077 if (cls.id() != owner_cid) { |
| 13003 return false; | 13078 return false; |
| 13004 } | 13079 } |
| (...skipping 9282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 22287 return UserTag::null(); | 22362 return UserTag::null(); |
| 22288 } | 22363 } |
| 22289 | 22364 |
| 22290 | 22365 |
| 22291 const char* UserTag::ToCString() const { | 22366 const char* UserTag::ToCString() const { |
| 22292 const String& tag_label = String::Handle(label()); | 22367 const String& tag_label = String::Handle(label()); |
| 22293 return tag_label.ToCString(); | 22368 return tag_label.ToCString(); |
| 22294 } | 22369 } |
| 22295 | 22370 |
| 22296 } // namespace dart | 22371 } // namespace dart |
| OLD | NEW |