Commit 433fd6c0 authored by verwaest's avatar verwaest Committed by Commit bot

[runtime] Clean up symbol access in identity hash code

BUG=

Review URL: https://codereview.chromium.org/1768553002

Cr-Commit-Position: refs/heads/master@{#34497}
parent d5d4f0b8
...@@ -7110,11 +7110,12 @@ Handle<Smi> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object) { ...@@ -7110,11 +7110,12 @@ Handle<Smi> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object) {
: JSObject::GetOrCreateIdentityHash(Handle<JSObject>::cast(object)); : JSObject::GetOrCreateIdentityHash(Handle<JSObject>::cast(object));
} }
Handle<Object> JSReceiver::GetIdentityHash(Isolate* isolate,
Object* JSReceiver::GetIdentityHash() { Handle<JSReceiver> receiver) {
return IsJSProxy() return receiver->IsJSProxy() ? JSProxy::GetIdentityHash(
? JSProxy::cast(this)->GetIdentityHash() isolate, Handle<JSProxy>::cast(receiver))
: JSObject::cast(this)->GetIdentityHash(); : JSObject::GetIdentityHash(
isolate, Handle<JSObject>::cast(receiver));
} }
......
...@@ -1402,8 +1402,11 @@ Object* Object::GetHash() { ...@@ -1402,8 +1402,11 @@ Object* Object::GetHash() {
Object* hash = GetSimpleHash(); Object* hash = GetSimpleHash();
if (hash->IsSmi()) return hash; if (hash->IsSmi()) return hash;
DisallowHeapAllocation no_gc;
DCHECK(IsJSReceiver()); DCHECK(IsJSReceiver());
return JSReceiver::cast(this)->GetIdentityHash(); JSReceiver* receiver = JSReceiver::cast(this);
Isolate* isolate = receiver->GetIsolate();
return *JSReceiver::GetIdentityHash(isolate, handle(receiver, isolate));
} }
...@@ -5856,7 +5859,7 @@ static Smi* GenerateIdentityHash(Isolate* isolate) { ...@@ -5856,7 +5859,7 @@ static Smi* GenerateIdentityHash(Isolate* isolate) {
void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) { void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) {
DCHECK(!object->IsJSGlobalProxy()); DCHECK(!object->IsJSGlobalProxy());
Isolate* isolate = object->GetIsolate(); Isolate* isolate = object->GetIsolate();
Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol();
JSObject::AddProperty(object, hash_code_symbol, hash, NONE); JSObject::AddProperty(object, hash_code_symbol, hash, NONE);
} }
...@@ -5873,40 +5876,35 @@ static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) { ...@@ -5873,40 +5876,35 @@ static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
return hash; return hash;
} }
// static
Object* JSObject::GetIdentityHash() { Handle<Object> JSObject::GetIdentityHash(Isolate* isolate,
DisallowHeapAllocation no_gc; Handle<JSObject> object) {
Isolate* isolate = GetIsolate(); if (object->IsJSGlobalProxy()) {
if (IsJSGlobalProxy()) { return handle(JSGlobalProxy::cast(*object)->hash(), isolate);
return JSGlobalProxy::cast(this)->hash();
} }
Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol();
Handle<Object> stored_value = return JSReceiver::GetDataProperty(object, hash_code_symbol);
Object::GetPropertyOrElement(Handle<Object>(this, isolate),
hash_code_symbol).ToHandleChecked();
return stored_value->IsSmi() ? *stored_value
: isolate->heap()->undefined_value();
} }
// static
Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) { Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
if (object->IsJSGlobalProxy()) { if (object->IsJSGlobalProxy()) {
return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object)); return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object));
} }
Isolate* isolate = object->GetIsolate(); Isolate* isolate = object->GetIsolate();
Handle<Object> maybe_hash(object->GetIdentityHash(), isolate); Handle<Object> maybe_hash = JSObject::GetIdentityHash(isolate, object);
if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash); if (maybe_hash->IsSmi()) return Handle<Smi>::cast(maybe_hash);
Handle<Smi> hash(GenerateIdentityHash(isolate), isolate); Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol()); SetIdentityHash(object, hash);
JSObject::AddProperty(object, hash_code_symbol, hash, NONE);
return hash; return hash;
} }
// static
Object* JSProxy::GetIdentityHash() { Handle<Object> JSProxy::GetIdentityHash(Isolate* isolate,
return this->hash(); Handle<JSProxy> proxy) {
return handle(proxy->hash(), isolate);
} }
......
...@@ -1933,7 +1933,8 @@ class JSReceiver: public HeapObject { ...@@ -1933,7 +1933,8 @@ class JSReceiver: public HeapObject {
// Retrieves a permanent object identity hash code. The undefined value might // Retrieves a permanent object identity hash code. The undefined value might
// be returned in case no hash was created yet. // be returned in case no hash was created yet.
inline Object* GetIdentityHash(); static inline Handle<Object> GetIdentityHash(Isolate* isolate,
Handle<JSReceiver> object);
// Retrieves a permanent object identity hash code. May create and store a // Retrieves a permanent object identity hash code. May create and store a
// hash code if needed and none exists. // hash code if needed and none exists.
...@@ -2526,7 +2527,8 @@ class JSObject: public JSReceiver { ...@@ -2526,7 +2527,8 @@ class JSObject: public JSReceiver {
Handle<JSObject> object, Handle<JSObject> object,
Handle<Object> value); Handle<Object> value);
MUST_USE_RESULT Object* GetIdentityHash(); static Handle<Object> GetIdentityHash(Isolate* isolate,
Handle<JSObject> object);
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object); static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
...@@ -9801,7 +9803,8 @@ class JSProxy: public JSReceiver { ...@@ -9801,7 +9803,8 @@ class JSProxy: public JSReceiver {
typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize> typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize>
BodyDescriptor; BodyDescriptor;
MUST_USE_RESULT Object* GetIdentityHash(); static Handle<Object> GetIdentityHash(Isolate* isolate,
Handle<JSProxy> receiver);
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy); static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
......
...@@ -82,7 +82,7 @@ static void TestHashMap(Handle<HashMap> table) { ...@@ -82,7 +82,7 @@ static void TestHashMap(Handle<HashMap> table) {
CHECK_EQ(table->NumberOfElements(), i + 1); CHECK_EQ(table->NumberOfElements(), i + 1);
CHECK_NE(table->FindEntry(key), HashMap::kNotFound); CHECK_NE(table->FindEntry(key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(key), *value); CHECK_EQ(table->Lookup(key), *value);
CHECK(key->GetIdentityHash()->IsSmi()); CHECK(JSReceiver::GetIdentityHash(isolate, key)->IsSmi());
} }
// Keys never added to the map which already have an identity hash // Keys never added to the map which already have an identity hash
...@@ -92,7 +92,7 @@ static void TestHashMap(Handle<HashMap> table) { ...@@ -92,7 +92,7 @@ static void TestHashMap(Handle<HashMap> table) {
CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi()); CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
CHECK_EQ(table->FindEntry(key), HashMap::kNotFound); CHECK_EQ(table->FindEntry(key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value()); CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
CHECK(key->GetIdentityHash()->IsSmi()); CHECK(JSReceiver::GetIdentityHash(isolate, key)->IsSmi());
} }
// Keys that don't have an identity hash should not be found and also // Keys that don't have an identity hash should not be found and also
...@@ -100,8 +100,8 @@ static void TestHashMap(Handle<HashMap> table) { ...@@ -100,8 +100,8 @@ static void TestHashMap(Handle<HashMap> table) {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7); Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value()); CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
Object* identity_hash = key->GetIdentityHash(); Handle<Object> identity_hash = JSReceiver::GetIdentityHash(isolate, key);
CHECK_EQ(identity_hash, CcTest::heap()->undefined_value()); CHECK_EQ(CcTest::heap()->undefined_value(), *identity_hash);
} }
} }
......
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