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

Unified Diff: runtime/vm/megamorphic_cache_table.cc

Issue 1339363002: Reapply "Move megamorphic cache table into the Dart heap." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/megamorphic_cache_table.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/megamorphic_cache_table.cc
diff --git a/runtime/vm/megamorphic_cache_table.cc b/runtime/vm/megamorphic_cache_table.cc
index 3bbc5291fc9fcd925c96c623c6cba1e8adac1b44..c87be9696bae2a6ecf2325a28541a7262542d469 100644
--- a/runtime/vm/megamorphic_cache_table.cc
+++ b/runtime/vm/megamorphic_cache_table.cc
@@ -6,50 +6,52 @@
#include <stdlib.h>
#include "vm/object.h"
+#include "vm/object_store.h"
#include "vm/stub_code.h"
#include "vm/symbols.h"
namespace dart {
-MegamorphicCacheTable::MegamorphicCacheTable()
- : miss_handler_function_(NULL),
- miss_handler_code_(NULL),
- capacity_(0),
- length_(0),
- table_(NULL) {
-}
-
-
-MegamorphicCacheTable::~MegamorphicCacheTable() {
- free(table_);
-}
-
-
-RawMegamorphicCache* MegamorphicCacheTable::Lookup(const String& name,
+RawMegamorphicCache* MegamorphicCacheTable::Lookup(Isolate* isolate,
+ const String& name,
const Array& descriptor) {
- for (intptr_t i = 0; i < length_; ++i) {
- if ((table_[i].name == name.raw()) &&
- (table_[i].descriptor == descriptor.raw())) {
- return table_[i].cache;
+ ASSERT(name.IsSymbol());
+ // TODO(rmacnak): ASSERT(descriptor.IsCanonical());
+
+ // TODO(rmacnak): Make a proper hashtable a la symbol table.
+ GrowableObjectArray& table = GrowableObjectArray::Handle(
+ isolate->object_store()->megamorphic_cache_table());
+ if (table.IsNull()) {
+ table = GrowableObjectArray::New();
+ ASSERT((table.Length() % kEntrySize) == 0);
+ isolate->object_store()->set_megamorphic_cache_table(table);
+ } else {
+ for (intptr_t i = 0; i < table.Length(); i += kEntrySize) {
+ if ((table.At(i + kEntryNameOffset) == name.raw()) &&
+ (table.At(i + kEntryDescriptorOffset) == descriptor.raw())) {
+ return MegamorphicCache::RawCast(table.At(i + kEntryCacheOffset));
+ }
}
}
- if (length_ == capacity_) {
- capacity_ += kCapacityIncrement;
- table_ =
- reinterpret_cast<Entry*>(realloc(table_, capacity_ * sizeof(*table_)));
- }
-
- ASSERT(length_ < capacity_);
const MegamorphicCache& cache =
MegamorphicCache::Handle(MegamorphicCache::New());
- Entry entry = { name.raw(), descriptor.raw(), cache.raw() };
- table_[length_++] = entry;
+ table.Add(name);
+ table.Add(descriptor);
+ table.Add(cache);
+ ASSERT((table.Length() % kEntrySize) == 0);
return cache.raw();
}
-void MegamorphicCacheTable::InitMissHandler() {
+RawFunction* MegamorphicCacheTable::miss_handler(Isolate* isolate) {
+ ASSERT(isolate->object_store()->megamorphic_miss_function() !=
+ Function::null());
+ return isolate->object_store()->megamorphic_miss_function();
+}
+
+
+void MegamorphicCacheTable::InitMissHandler(Isolate* isolate) {
// The miss handler for a class ID not found in the table is invoked as a
// normal Dart function.
const Code& code =
@@ -69,37 +71,27 @@ void MegamorphicCacheTable::InitMissHandler() {
0)); // No token position.
function.set_is_debuggable(false);
function.set_is_visible(false);
- miss_handler_code_ = code.raw();
- miss_handler_function_ = function.raw();
function.AttachCode(code);
-}
-
-void MegamorphicCacheTable::VisitObjectPointers(ObjectPointerVisitor* v) {
- ASSERT(v != NULL);
- v->VisitPointer(reinterpret_cast<RawObject**>(&miss_handler_code_));
- v->VisitPointer(reinterpret_cast<RawObject**>(&miss_handler_function_));
- for (intptr_t i = 0; i < length_; ++i) {
- v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].name));
- v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].descriptor));
- v->VisitPointer(reinterpret_cast<RawObject**>(&table_[i].cache));
- }
+ isolate->object_store()->SetMegamorphicMissHandler(code, function);
}
-void MegamorphicCacheTable::PrintSizes() {
+void MegamorphicCacheTable::PrintSizes(Isolate* isolate) {
StackZone zone(Thread::Current());
intptr_t size = 0;
MegamorphicCache& cache = MegamorphicCache::Handle();
Array& buckets = Array::Handle();
- for (intptr_t i = 0; i < length_; ++i) {
- cache = table_[i].cache;
+ const GrowableObjectArray& table = GrowableObjectArray::Handle(
+ isolate->object_store()->megamorphic_cache_table());
+ for (intptr_t i = 0; i < table.Length(); i += kEntrySize) {
+ cache ^= table.At(i + kEntryCacheOffset);
buckets = cache.buckets();
size += MegamorphicCache::InstanceSize();
size += Array::InstanceSize(buckets.Length());
}
OS::Print("%" Pd " megamorphic caches using %" Pd "KB.\n",
- length_, size / 1024);
+ table.Length() / kEntrySize, size / 1024);
}
} // namespace dart
« no previous file with comments | « runtime/vm/megamorphic_cache_table.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698