[runtime] Clean up symbol access in identity hash code

BUG=

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

Cr-Commit-Position: refs/heads/master@{#34497}
This commit is contained in:
verwaest 2016-03-04 06:38:36 -08:00 committed by Commit bot
parent d5d4f0b80f
commit 433fd6c078
4 changed files with 35 additions and 33 deletions

View File

@ -7110,11 +7110,12 @@ Handle<Smi> JSReceiver::GetOrCreateIdentityHash(Handle<JSReceiver> object) {
: JSObject::GetOrCreateIdentityHash(Handle<JSObject>::cast(object));
}
Object* JSReceiver::GetIdentityHash() {
return IsJSProxy()
? JSProxy::cast(this)->GetIdentityHash()
: JSObject::cast(this)->GetIdentityHash();
Handle<Object> JSReceiver::GetIdentityHash(Isolate* isolate,
Handle<JSReceiver> receiver) {
return receiver->IsJSProxy() ? JSProxy::GetIdentityHash(
isolate, Handle<JSProxy>::cast(receiver))
: JSObject::GetIdentityHash(
isolate, Handle<JSObject>::cast(receiver));
}

View File

@ -1402,8 +1402,11 @@ Object* Object::GetHash() {
Object* hash = GetSimpleHash();
if (hash->IsSmi()) return hash;
DisallowHeapAllocation no_gc;
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) {
void JSObject::SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash) {
DCHECK(!object->IsJSGlobalProxy());
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);
}
@ -5873,40 +5876,35 @@ static Handle<Smi> GetOrCreateIdentityHashHelper(Handle<ProxyType> proxy) {
return hash;
}
Object* JSObject::GetIdentityHash() {
DisallowHeapAllocation no_gc;
Isolate* isolate = GetIsolate();
if (IsJSGlobalProxy()) {
return JSGlobalProxy::cast(this)->hash();
// static
Handle<Object> JSObject::GetIdentityHash(Isolate* isolate,
Handle<JSObject> object) {
if (object->IsJSGlobalProxy()) {
return handle(JSGlobalProxy::cast(*object)->hash(), isolate);
}
Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol());
Handle<Object> stored_value =
Object::GetPropertyOrElement(Handle<Object>(this, isolate),
hash_code_symbol).ToHandleChecked();
return stored_value->IsSmi() ? *stored_value
: isolate->heap()->undefined_value();
Handle<Name> hash_code_symbol = isolate->factory()->hash_code_symbol();
return JSReceiver::GetDataProperty(object, hash_code_symbol);
}
// static
Handle<Smi> JSObject::GetOrCreateIdentityHash(Handle<JSObject> object) {
if (object->IsJSGlobalProxy()) {
return GetOrCreateIdentityHashHelper(Handle<JSGlobalProxy>::cast(object));
}
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);
Handle<Smi> hash(GenerateIdentityHash(isolate), isolate);
Handle<Name> hash_code_symbol(isolate->heap()->hash_code_symbol());
JSObject::AddProperty(object, hash_code_symbol, hash, NONE);
SetIdentityHash(object, hash);
return hash;
}
Object* JSProxy::GetIdentityHash() {
return this->hash();
// static
Handle<Object> JSProxy::GetIdentityHash(Isolate* isolate,
Handle<JSProxy> proxy) {
return handle(proxy->hash(), isolate);
}

View File

@ -1933,7 +1933,8 @@ class JSReceiver: public HeapObject {
// Retrieves a permanent object identity hash code. The undefined value might
// 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
// hash code if needed and none exists.
@ -2526,7 +2527,8 @@ class JSObject: public JSReceiver {
Handle<JSObject> object,
Handle<Object> value);
MUST_USE_RESULT Object* GetIdentityHash();
static Handle<Object> GetIdentityHash(Isolate* isolate,
Handle<JSObject> object);
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
@ -9801,7 +9803,8 @@ class JSProxy: public JSReceiver {
typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize>
BodyDescriptor;
MUST_USE_RESULT Object* GetIdentityHash();
static Handle<Object> GetIdentityHash(Isolate* isolate,
Handle<JSProxy> receiver);
static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);

View File

@ -82,7 +82,7 @@ static void TestHashMap(Handle<HashMap> table) {
CHECK_EQ(table->NumberOfElements(), i + 1);
CHECK_NE(table->FindEntry(key), HashMap::kNotFound);
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
@ -92,7 +92,7 @@ static void TestHashMap(Handle<HashMap> table) {
CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
CHECK_EQ(table->FindEntry(key), HashMap::kNotFound);
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
@ -100,8 +100,8 @@ static void TestHashMap(Handle<HashMap> table) {
for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
Object* identity_hash = key->GetIdentityHash();
CHECK_EQ(identity_hash, CcTest::heap()->undefined_value());
Handle<Object> identity_hash = JSReceiver::GetIdentityHash(isolate, key);
CHECK_EQ(CcTest::heap()->undefined_value(), *identity_hash);
}
}