Revert "[vm] Cache method resolution."
This reverts commit 2f0dfd6124e080d0a90175898087c5f300012c30.
Reason for revert:
Need to revert this CL in order to revert [0] which had performance regressions.
[0] https://dart-review.googlesource.com/c/sdk/+/98428
Original change's description:
> [vm] Cache method resolution.
>
> Change-Id: I5b3a9764b6932548ee25823b7dc42011ac292427
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98640
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: RĂ©gis Crelier <regis@google.com>
TBR=rmacnak@google.com,alexmarkov@google.com,regis@google.com
Change-Id: I2b3367e38103437a74124d129ff0b357058a5a57
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99160
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/interpreter.cc b/runtime/vm/interpreter.cc
index 1f5ac08..b9247b6 100644
--- a/runtime/vm/interpreter.cc
+++ b/runtime/vm/interpreter.cc
@@ -263,7 +263,6 @@
bool LookupCache::Lookup(intptr_t receiver_cid,
RawString* function_name,
- RawArray* arguments_descriptor,
RawFunction** target) const {
ASSERT(receiver_cid != kIllegalCid); // Sentinel value.
@@ -271,16 +270,14 @@
receiver_cid ^ reinterpret_cast<intptr_t>(function_name);
const intptr_t probe1 = hash & kTableMask;
if (entries_[probe1].receiver_cid == receiver_cid &&
- entries_[probe1].function_name == function_name &&
- entries_[probe1].arguments_descriptor == arguments_descriptor) {
+ entries_[probe1].function_name == function_name) {
*target = entries_[probe1].target;
return true;
}
intptr_t probe2 = (hash >> 3) & kTableMask;
if (entries_[probe2].receiver_cid == receiver_cid &&
- entries_[probe2].function_name == function_name &&
- entries_[probe2].arguments_descriptor == arguments_descriptor) {
+ entries_[probe2].function_name == function_name) {
*target = entries_[probe2].target;
return true;
}
@@ -290,26 +287,32 @@
void LookupCache::Insert(intptr_t receiver_cid,
RawString* function_name,
- RawArray* arguments_descriptor,
RawFunction* target) {
// Otherwise we have to clear the cache or rehash on scavenges too.
ASSERT(function_name->IsOldObject());
- ASSERT(arguments_descriptor->IsOldObject());
ASSERT(target->IsOldObject());
const intptr_t hash =
receiver_cid ^ reinterpret_cast<intptr_t>(function_name);
const intptr_t probe1 = hash & kTableMask;
- entries_[probe1].receiver_cid = receiver_cid;
- entries_[probe1].function_name = function_name;
- entries_[probe1].arguments_descriptor = arguments_descriptor;
- entries_[probe1].target = target;
+ if (entries_[probe1].receiver_cid == kIllegalCid) {
+ entries_[probe1].receiver_cid = receiver_cid;
+ entries_[probe1].function_name = function_name;
+ entries_[probe1].target = target;
+ return;
+ }
const intptr_t probe2 = (hash >> 3) & kTableMask;
- entries_[probe2].receiver_cid = receiver_cid;
- entries_[probe2].function_name = function_name;
- entries_[probe2].arguments_descriptor = arguments_descriptor;
- entries_[probe2].target = target;
+ if (entries_[probe2].receiver_cid == kIllegalCid) {
+ entries_[probe2].receiver_cid = receiver_cid;
+ entries_[probe2].function_name = function_name;
+ entries_[probe2].target = target;
+ return;
+ }
+
+ entries_[probe1].receiver_cid = receiver_cid;
+ entries_[probe1].function_name = function_name;
+ entries_[probe1].target = target;
}
Interpreter::Interpreter()
@@ -906,8 +909,7 @@
InterpreterHelpers::GetClassId(call_base[receiver_idx]);
RawFunction* target;
- if (UNLIKELY(!lookup_cache_.Lookup(receiver_cid, target_name, argdesc_,
- &target))) {
+ if (UNLIKELY(!lookup_cache_.Lookup(receiver_cid, target_name, &target))) {
// Table lookup miss.
top[1] = call_base[receiver_idx];
top[2] = target_name;
@@ -923,8 +925,10 @@
}
target = static_cast<RawFunction*>(top[4]);
+ target_name = static_cast<RawString*>(top[2]);
argdesc_ = static_cast<RawArray*>(top[3]);
ASSERT(target->IsFunction());
+ lookup_cache_.Insert(receiver_cid, target_name, target);
}
top[0] = target;
diff --git a/runtime/vm/interpreter.h b/runtime/vm/interpreter.h
index d4c95e6..e8fe9db 100644
--- a/runtime/vm/interpreter.h
+++ b/runtime/vm/interpreter.h
@@ -40,19 +40,17 @@
void Clear();
bool Lookup(intptr_t receiver_cid,
RawString* function_name,
- RawArray* arguments_descriptor,
RawFunction** target) const;
void Insert(intptr_t receiver_cid,
RawString* function_name,
- RawArray* arguments_descriptor,
RawFunction* target);
private:
struct Entry {
intptr_t receiver_cid;
RawString* function_name;
- RawArray* arguments_descriptor;
RawFunction* target;
+ intptr_t padding;
};
static const intptr_t kNumEntries = 1024;
@@ -124,8 +122,6 @@
void VisitObjectPointers(ObjectPointerVisitor* visitor);
void MajorGC() { lookup_cache_.Clear(); }
- LookupCache& lookup_cache() { return lookup_cache_; }
-
private:
uintptr_t* stack_;
uword stack_base_;
diff --git a/runtime/vm/resolver.cc b/runtime/vm/resolver.cc
index 84e76d9..b50e120 100644
--- a/runtime/vm/resolver.cc
+++ b/runtime/vm/resolver.cc
@@ -6,7 +6,6 @@
#include "vm/dart_entry.h"
#include "vm/flags.h"
-#include "vm/interpreter.h"
#include "vm/isolate.h"
#include "vm/log.h"
#include "vm/object.h"
@@ -48,18 +47,6 @@
String::Handle(zone, receiver_class.Name()).ToCString());
}
-#if !defined(DART_PRECOMPILED_RUNTIME)
- Interpreter* interpreter = thread->interpreter();
- if (interpreter != NULL) {
- RawFunction* result;
- if (interpreter->lookup_cache().Lookup(receiver_class.id(),
- function_name.raw(),
- args_desc.array().raw(), &result)) {
- return result;
- }
- }
-#endif
-
Function& function = Function::Handle(
zone, ResolveDynamicAnyArgs(zone, receiver_class, function_name,
args_desc, allow_add));
@@ -91,13 +78,6 @@
THR_Print("ResolveDynamic result: %s\n", function.ToCString());
}
-#if !defined(DART_PRECOMPILED_RUNTIME)
- if ((interpreter != NULL) && !function.IsNull()) {
- interpreter->lookup_cache().Insert(receiver_class.id(), function_name.raw(),
- args_desc.array().raw(), function.raw());
- }
-#endif
-
return function.raw();
}
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index 4c17020..47eadaf 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -1012,17 +1012,15 @@
}
static RawFunction* InlineCacheMissHandler(
- Zone* zone,
const GrowableArray<const Instance*>& args, // Checked arguments only.
const ICData& ic_data) {
const Instance& receiver = *args[0];
ArgumentsDescriptor arguments_descriptor(
- Array::Handle(zone, ic_data.arguments_descriptor()));
- String& function_name = String::Handle(zone, ic_data.target_name());
+ Array::Handle(ic_data.arguments_descriptor()));
+ String& function_name = String::Handle(ic_data.target_name());
ASSERT(function_name.IsSymbol());
Function& target_function = Function::Handle(
- zone,
Resolver::ResolveDynamic(receiver, function_name, arguments_descriptor));
ObjectStore* store = Isolate::Current()->object_store();
@@ -1107,7 +1105,7 @@
GrowableArray<const Instance*> args(1);
args.Add(&receiver);
const Function& result =
- Function::Handle(zone, InlineCacheMissHandler(zone, args, ic_data));
+ Function::Handle(InlineCacheMissHandler(args, ic_data));
arguments.SetReturn(result);
}
@@ -1125,7 +1123,7 @@
args.Add(&receiver);
args.Add(&other);
const Function& result =
- Function::Handle(zone, InlineCacheMissHandler(zone, args, ic_data));
+ Function::Handle(InlineCacheMissHandler(args, ic_data));
arguments.SetReturn(result);
}
@@ -1138,7 +1136,7 @@
const ICData& ic_data = ICData::CheckedHandle(zone, arguments.ArgAt(1));
// IC data for static call is prepopulated with the statically known target.
ASSERT(ic_data.NumberOfChecksIs(1));
- const Function& target = Function::Handle(zone, ic_data.GetTargetAt(0));
+ const Function& target = Function::Handle(ic_data.GetTargetAt(0));
target.EnsureHasCode();
ASSERT(!target.IsNull() && target.HasCode());
ic_data.AddReceiverCheck(arg.GetClassId(), target, 1);
@@ -1164,7 +1162,7 @@
const ICData& ic_data = ICData::CheckedHandle(zone, arguments.ArgAt(2));
// IC data for static call is prepopulated with the statically known target.
ASSERT(!ic_data.NumberOfChecksIs(0));
- const Function& target = Function::Handle(zone, ic_data.GetTargetAt(0));
+ const Function& target = Function::Handle(ic_data.GetTargetAt(0));
target.EnsureHasCode();
GrowableArray<intptr_t> cids(2);
cids.Add(arg0.GetClassId());