Chromium Code Reviews| 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/megamorphic_cache_table.h" | 5 #include "vm/megamorphic_cache_table.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/stub_code.h" | 10 #include "vm/stub_code.h" |
| 11 #include "vm/symbols.h" | 11 #include "vm/symbols.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 RawMegamorphicCache* MegamorphicCacheTable::Lookup(Isolate* isolate, | 15 RawMegamorphicCache* MegamorphicCacheTable::Lookup(Isolate* isolate, |
| 16 const String& name, | 16 const String& name, |
| 17 const Array& descriptor) { | 17 const Array& descriptor) { |
| 18 ASSERT(name.IsSymbol()); | 18 ASSERT(name.IsSymbol()); |
| 19 // TODO(rmacnak): ASSERT(descriptor.IsCanonical()); | 19 // TODO(rmacnak): ASSERT(descriptor.IsCanonical()); |
| 20 | 20 |
| 21 // TODO(rmacnak): Make a proper hashtable a la symbol table. | 21 // TODO(rmacnak): Make a proper hashtable a la symbol table. |
| 22 GrowableObjectArray& table = GrowableObjectArray::Handle( | 22 GrowableObjectArray& table = GrowableObjectArray::Handle( |
| 23 isolate->object_store()->megamorphic_cache_table()); | 23 isolate->object_store()->megamorphic_cache_table()); |
| 24 MegamorphicCache& cache = MegamorphicCache::Handle(); | |
| 24 if (table.IsNull()) { | 25 if (table.IsNull()) { |
| 25 table = GrowableObjectArray::New(Heap::kOld); | 26 table = GrowableObjectArray::New(Heap::kOld); |
| 26 ASSERT((table.Length() % kEntrySize) == 0); | |
| 27 isolate->object_store()->set_megamorphic_cache_table(table); | 27 isolate->object_store()->set_megamorphic_cache_table(table); |
| 28 } else { | 28 } else { |
| 29 for (intptr_t i = 0; i < table.Length(); i += kEntrySize) { | 29 for (intptr_t i = 0; i < table.Length(); i++) { |
| 30 if ((table.At(i + kEntryNameOffset) == name.raw()) && | 30 cache ^= table.At(i); |
| 31 (table.At(i + kEntryDescriptorOffset) == descriptor.raw())) { | 31 if (cache.target_name() == name.raw() && |
| 32 return MegamorphicCache::RawCast(table.At(i + kEntryCacheOffset)); | 32 cache.arguments_descriptor() == descriptor.raw()) { |
|
srdjan
2015/10/20 20:17:07
Add parens
rmacnak
2015/10/20 20:44:06
Done.
| |
| 33 return cache.raw(); | |
| 33 } | 34 } |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 37 const MegamorphicCache& cache = | 38 cache = MegamorphicCache::New(name, descriptor); |
| 38 MegamorphicCache::Handle(MegamorphicCache::New()); | |
| 39 table.Add(name, Heap::kOld); | |
| 40 table.Add(descriptor, Heap::kOld); | |
| 41 table.Add(cache, Heap::kOld); | 39 table.Add(cache, Heap::kOld); |
| 42 ASSERT((table.Length() % kEntrySize) == 0); | |
| 43 return cache.raw(); | 40 return cache.raw(); |
| 44 } | 41 } |
| 45 | 42 |
| 46 | 43 |
| 47 RawFunction* MegamorphicCacheTable::miss_handler(Isolate* isolate) { | 44 RawFunction* MegamorphicCacheTable::miss_handler(Isolate* isolate) { |
| 48 ASSERT(isolate->object_store()->megamorphic_miss_function() != | 45 ASSERT(isolate->object_store()->megamorphic_miss_function() != |
| 49 Function::null()); | 46 Function::null()); |
| 50 return isolate->object_store()->megamorphic_miss_function(); | 47 return isolate->object_store()->megamorphic_miss_function(); |
| 51 } | 48 } |
| 52 | 49 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 82 | 79 |
| 83 | 80 |
| 84 void MegamorphicCacheTable::PrintSizes(Isolate* isolate) { | 81 void MegamorphicCacheTable::PrintSizes(Isolate* isolate) { |
| 85 StackZone zone(Thread::Current()); | 82 StackZone zone(Thread::Current()); |
| 86 intptr_t size = 0; | 83 intptr_t size = 0; |
| 87 MegamorphicCache& cache = MegamorphicCache::Handle(); | 84 MegamorphicCache& cache = MegamorphicCache::Handle(); |
| 88 Array& buckets = Array::Handle(); | 85 Array& buckets = Array::Handle(); |
| 89 const GrowableObjectArray& table = GrowableObjectArray::Handle( | 86 const GrowableObjectArray& table = GrowableObjectArray::Handle( |
| 90 isolate->object_store()->megamorphic_cache_table()); | 87 isolate->object_store()->megamorphic_cache_table()); |
| 91 if (table.IsNull()) return; | 88 if (table.IsNull()) return; |
| 92 for (intptr_t i = 0; i < table.Length(); i += kEntrySize) { | 89 for (intptr_t i = 0; i < table.Length(); i++) { |
| 93 cache ^= table.At(i + kEntryCacheOffset); | 90 cache ^= table.At(i); |
| 94 buckets = cache.buckets(); | 91 buckets = cache.buckets(); |
| 95 size += MegamorphicCache::InstanceSize(); | 92 size += MegamorphicCache::InstanceSize(); |
| 96 size += Array::InstanceSize(buckets.Length()); | 93 size += Array::InstanceSize(buckets.Length()); |
| 97 } | 94 } |
| 98 OS::Print("%" Pd " megamorphic caches using %" Pd "KB.\n", | 95 OS::Print("%" Pd " megamorphic caches using %" Pd "KB.\n", |
| 99 table.Length() / kEntrySize, size / 1024); | 96 table.Length(), size / 1024); |
| 100 } | 97 } |
| 101 | 98 |
| 102 } // namespace dart | 99 } // namespace dart |
| OLD | NEW |