Commit f38c92a9 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[Collections] Replace GenericHash runtime call with fast C call

Bug: v8:5717
Change-Id: I3775001a6148e25f15b11410449a6f8b7693f122
Reviewed-on: https://chromium-review.googlesource.com/625276
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47589}
parent 734d1734
......@@ -1409,6 +1409,12 @@ ExternalReference ExternalReference::orderedhashmap_gethash_raw(
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
}
ExternalReference ExternalReference::get_or_create_hash_raw(Isolate* isolate) {
typedef Smi* (*GetOrCreateHash)(Isolate * isolate, Object * key);
GetOrCreateHash f = Object::GetOrCreateHash;
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
}
ExternalReference ExternalReference::try_internalize_string_function(
Isolate* isolate) {
return ExternalReference(Redirect(
......
......@@ -989,6 +989,8 @@ class ExternalReference BASE_EMBEDDED {
static ExternalReference orderedhashmap_gethash_raw(Isolate* isolate);
static ExternalReference get_or_create_hash_raw(Isolate* isolate);
static ExternalReference page_flags(Page* page);
static ExternalReference ForDeoptEntry(Address entry);
......
......@@ -30,6 +30,7 @@ class CollectionsBuiltinsAssembler : public CodeStubAssembler {
Node* GetHash(Node* const key);
Node* CallGetHashRaw(Node* const key);
Node* CallGetOrCreateHashRaw(Node* const key);
// Transitions the iterator to the non obsolete backing store.
// This is a NOP if the [table] is not obsolete.
......@@ -429,6 +430,21 @@ TF_BUILTIN(SetConstructor, CollectionsBuiltinsAssembler) {
args.PopAndReturn(var_result.value());
}
Node* CollectionsBuiltinsAssembler::CallGetOrCreateHashRaw(Node* const key) {
Node* const function_addr =
ExternalConstant(ExternalReference::get_or_create_hash_raw(isolate()));
Node* const isolate_ptr =
ExternalConstant(ExternalReference::isolate_address(isolate()));
MachineType type_ptr = MachineType::Pointer();
MachineType type_tagged = MachineType::AnyTagged();
Node* const result = CallCFunction2(type_tagged, type_ptr, type_tagged,
function_addr, isolate_ptr, key);
return result;
}
Node* CollectionsBuiltinsAssembler::CallGetHashRaw(Node* const key) {
Node* const function_addr = ExternalConstant(
ExternalReference::orderedhashmap_gethash_raw(isolate()));
......@@ -916,8 +932,7 @@ TF_BUILTIN(MapSet, CollectionsBuiltinsAssembler) {
&add_entry);
// Otherwise, go to runtime to compute the hash code.
entry_start_position_or_hash.Bind(
SmiUntag(CAST(CallRuntime(Runtime::kGenericHash, context, key))));
entry_start_position_or_hash.Bind(SmiUntag(CallGetOrCreateHashRaw(key)));
Goto(&add_entry);
}
......@@ -1083,8 +1098,7 @@ TF_BUILTIN(SetAdd, CollectionsBuiltinsAssembler) {
&add_entry);
// Otherwise, go to runtime to compute the hash code.
entry_start_position_or_hash.Bind(
SmiUntag(CAST(CallRuntime(Runtime::kGenericHash, context, key))));
entry_start_position_or_hash.Bind(SmiUntag((CallGetOrCreateHashRaw(key))));
Goto(&add_entry);
}
......
......@@ -266,6 +266,8 @@ void ExternalReferenceTable::AddReferences(Isolate* isolate) {
"search_string_raw<1-byte, 2-byte>");
Add(ExternalReference::orderedhashmap_gethash_raw(isolate).address(),
"orderedhashmap_gethash_raw");
Add(ExternalReference::get_or_create_hash_raw(isolate).address(),
"get_or_create_hash_raw");
Add(ExternalReference::log_enter_external_function(isolate).address(),
"Logger::EnterExternal");
Add(ExternalReference::log_leave_external_function(isolate).address(),
......
......@@ -2343,6 +2343,11 @@ Object* Object::GetHash() {
return receiver->GetIdentityHash(isolate);
}
// static
Smi* Object::GetOrCreateHash(Isolate* isolate, Object* key) {
return key->GetOrCreateHash(isolate);
}
Smi* Object::GetOrCreateHash(Isolate* isolate) {
Object* hash = GetSimpleHash(this);
if (hash->IsSmi()) return Smi::cast(hash);
......
......@@ -1447,6 +1447,7 @@ class Object {
// the actual object type. May create and store a hash code if needed and none
// exists.
Smi* GetOrCreateHash(Isolate* isolate);
static Smi* GetOrCreateHash(Isolate* isolate, Object* key);
// Checks whether this object has the same value as the given one. This
// function is implemented according to ES5, section 9.12 and can be used
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment