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

Side by Side Diff: runtime/vm/megamorphic_cache_table.cc

Issue 11299298: Cache lookups at megamorphic call sites in optimized code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/megamorphic_cache_table.h"
6
7 #include "vm/object.h"
8 #include "vm/stub_code.h"
9 #include "vm/symbols.h"
10
11 namespace dart {
12
13 MegamorphicCacheTable::MegamorphicCacheTable()
14 : capacity_(kInitialCapacity),
srdjan 2012/12/03 19:10:46 initialize miss_handler to null.
Kevin Millikin (Google) 2012/12/06 14:03:11 Done.
15 length_(0),
16 table_(new Entry[kInitialCapacity]) {
Vyacheslav Egorov (Google) 2012/12/03 14:55:22 I think you can allocate this on the first use of
Kevin Millikin (Google) 2012/12/06 14:03:11 Done.
17 }
18
19
20 MegamorphicCacheTable::~MegamorphicCacheTable() {
21 delete[] table_;
22 }
23
24
25 RawMegamorphicCache* MegamorphicCacheTable::Lookup(const String& name,
26 const Array& descriptor) {
27 for (intptr_t i = 0; i < length_; ++i) {
28 if ((table_[i].name == name.raw()) &&
29 (table_[i].descriptor == descriptor.raw())) {
30 return table_[i].cache;
31 }
32 }
33
34 if (length_ == capacity_) {
35 Entry* old_table = table_;
Vyacheslav Egorov (Google) 2012/12/03 14:55:22 I suggest using realloc/free instead of new[]/dele
Kevin Millikin (Google) 2012/12/06 14:03:11 OK, but I originally did it this way to avoid unsi
36 capacity_ += kCapacityIncrement;
37 table_ = new Entry[capacity_];
38 for (intptr_t i = 0; i < length_; ++i) {
39 table_[i] = old_table[i];
40 }
41 delete[] old_table;
42 }
43
44 ASSERT(length_ < capacity_);
45 const MegamorphicCache& cache =
46 MegamorphicCache::Handle(MegamorphicCache::New());
47 Entry entry = { name.raw(), descriptor.raw(), cache.raw() };
48 table_[length_++] = entry;
49 return cache.raw();
50 }
51
52
53 void MegamorphicCacheTable::InitMissHandler() {
54 const Code& code =
Vyacheslav Egorov (Google) 2012/12/03 14:55:22 I suggest adding a comment why do we need a fake f
Kevin Millikin (Google) 2012/12/06 14:03:11 OK.
55 Code::Handle(StubCode::Generate("_stub_MegamorphicMiss",
56 StubCode::GenerateMegamorphicMissStub));
57 const String& name = String::Handle(Symbols::New("megamorphic_miss"));
58 const Class& cls =
59 Class::Handle(Type::Handle(Type::Function()).type_class());
60 const Function& function =
61 Function::Handle(Function::New(name,
62 RawFunction::kRegularFunction,
63 false, // Not static.
64 false, // Not const.
65 false, // Not abstract.
66 false, // Not external.
67 cls,
68 0)); // No token position.
69 function.SetCode(code);
70 miss_handler_ = function.raw();
71 }
72
73
74 void MegamorphicCacheTable::VisitObjectPointers(ObjectPointerVisitor* v) {
75 ASSERT(v != NULL);
76 v->VisitPointer(reinterpret_cast<RawObject**>(&miss_handler_));
77 for (intptr_t i = 0; i < length_; ++i) {
78 v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].name));
79 v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].descriptor));
80 v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].cache));
81 }
82 }
83
84
85 void MegamorphicCacheTable::PrintSizes() {
86 StackZone zone(Isolate::Current());
87 intptr_t size = 0;
88 MegamorphicCache& cache = MegamorphicCache::Handle();
89 Array& buckets = Array::Handle();
90 for (intptr_t i = 0; i < length_; ++i) {
91 cache = table_[i].cache;
92 buckets = cache.buckets();
93 size += MegamorphicCache::InstanceSize();
94 size += Array::InstanceSize(buckets.Length());
95 }
96 OS::Print("%"Pd" megamorphic caches using %"Pd"KB.\n", length_, size / 1024);
97 }
98
99 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698