[runtime] Unhandlify GetOrCreateHash

This no longer causes allocation, so it's safe to unhandlify.

This will allow us to use directly call into C++ (via CallCFunction)
to calculate the hash instead of going through the runtime (via
%GenericHash).

Bug: v8:5717
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Ia561efb4d89d7a3d10c28913537b45b3ce477bb3
Reviewed-on: https://chromium-review.googlesource.com/624519
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47489}
This commit is contained in:
Sathya Gunasekaran 2017-08-21 15:26:03 -07:00 committed by Commit Bot
parent 784ac3ae39
commit f3d43c80bb
9 changed files with 39 additions and 52 deletions

View File

@ -3105,7 +3105,7 @@ void NativeWeakMap::Set(Local<Value> v8_key, Local<Value> v8_value) {
DCHECK(false);
return;
}
int32_t hash = i::Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = i::Object::GetOrCreateHash(isolate, *key)->value();
i::JSWeakCollection::Set(weak_collection, key, value, hash);
}
@ -3168,7 +3168,7 @@ bool NativeWeakMap::Delete(Local<Value> v8_key) {
DCHECK(false);
return false;
}
int32_t hash = i::Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = i::Object::GetOrCreateHash(isolate, *key)->value();
return i::JSWeakCollection::Delete(weak_collection, key, hash);
}
@ -5184,7 +5184,7 @@ int v8::Object::GetIdentityHash() {
auto isolate = Utils::OpenHandle(this)->GetIsolate();
i::HandleScope scope(isolate);
auto self = Utils::OpenHandle(this);
return i::JSReceiver::GetOrCreateIdentityHash(isolate, self)->value();
return i::JSReceiver::GetOrCreateIdentityHash(isolate, *self)->value();
}

View File

@ -5712,12 +5712,11 @@ inline int JSGlobalProxy::SizeWithEmbedderFields(int embedder_field_count) {
return kSize + embedder_field_count * kPointerSize;
}
Smi* JSReceiver::GetOrCreateIdentityHash(Isolate* isolate,
Handle<JSReceiver> object) {
return object->IsJSProxy() ? JSProxy::GetOrCreateIdentityHash(
isolate, Handle<JSProxy>::cast(object))
: JSObject::GetOrCreateIdentityHash(
isolate, Handle<JSObject>::cast(object));
Smi* JSReceiver::GetOrCreateIdentityHash(Isolate* isolate, JSReceiver* object) {
return object->IsJSProxy()
? JSProxy::GetOrCreateIdentityHash(isolate, JSProxy::cast(object))
: JSObject::GetOrCreateIdentityHash(isolate,
JSObject::cast(object));
}
Object* JSReceiver::GetIdentityHash(Isolate* isolate, JSReceiver* receiver) {

View File

@ -2341,13 +2341,12 @@ Object* Object::GetHash() {
return JSReceiver::GetIdentityHash(isolate, receiver);
}
Smi* Object::GetOrCreateHash(Isolate* isolate, Handle<Object> object) {
Object* hash = GetSimpleHash(*object);
Smi* Object::GetOrCreateHash(Isolate* isolate, Object* object) {
Object* hash = GetSimpleHash(object);
if (hash->IsSmi()) return Smi::cast(hash);
DCHECK(object->IsJSReceiver());
return JSReceiver::GetOrCreateIdentityHash(isolate,
Handle<JSReceiver>::cast(object));
return JSReceiver::GetOrCreateIdentityHash(isolate, JSReceiver::cast(object));
}
@ -6318,8 +6317,7 @@ void JSReceiver::SetProperties(HeapObject* properties) {
}
template <typename ProxyType>
static Smi* GetOrCreateIdentityHashHelper(Isolate* isolate,
Handle<ProxyType> proxy) {
static Smi* GetOrCreateIdentityHashHelper(Isolate* isolate, ProxyType* proxy) {
Object* maybe_hash = proxy->hash();
if (maybe_hash->IsSmi()) return Smi::cast(maybe_hash);
@ -6343,14 +6341,12 @@ Object* JSObject::GetIdentityHash(Isolate* isolate, JSObject* object) {
}
// static
Smi* JSObject::GetOrCreateIdentityHash(Isolate* isolate,
Handle<JSObject> object) {
Smi* JSObject::GetOrCreateIdentityHash(Isolate* isolate, JSObject* object) {
if (object->IsJSGlobalProxy()) {
return GetOrCreateIdentityHashHelper(isolate,
Handle<JSGlobalProxy>::cast(object));
return GetOrCreateIdentityHashHelper(isolate, JSGlobalProxy::cast(object));
}
Object* hash_obj = JSObject::GetIdentityHash(isolate, *object);
Object* hash_obj = JSObject::GetIdentityHash(isolate, object);
if (!hash_obj->IsUndefined(isolate)) {
return Smi::cast(hash_obj);
}
@ -6368,7 +6364,7 @@ Smi* JSObject::GetOrCreateIdentityHash(Isolate* isolate,
// static
Object* JSProxy::GetIdentityHash(JSProxy* proxy) { return proxy->hash(); }
Smi* JSProxy::GetOrCreateIdentityHash(Isolate* isolate, Handle<JSProxy> proxy) {
Smi* JSProxy::GetOrCreateIdentityHash(Isolate* isolate, JSProxy* proxy) {
return GetOrCreateIdentityHashHelper(isolate, proxy);
}
@ -17355,7 +17351,7 @@ bool StringSet::Has(Handle<String> name) {
Handle<ObjectHashSet> ObjectHashSet::Add(Handle<ObjectHashSet> set,
Handle<Object> key) {
Isolate* isolate = set->GetIsolate();
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
if (!set->Has(isolate, key, hash)) {
set = EnsureCapacity(set, 1);
int entry = set->FindInsertionEntry(hash);
@ -18071,7 +18067,7 @@ Handle<ObjectHashTable> ObjectHashTable::Put(Handle<ObjectHashTable> table,
DCHECK(!value->IsTheHole(isolate));
// Make sure the key object has an identity hash code.
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
return Put(table, key, value, hash);
}
@ -18289,7 +18285,7 @@ bool OrderedHashTable<Derived, entrysize>::HasKey(Isolate* isolate,
Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
Handle<Object> key) {
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
int hash = Object::GetOrCreateHash(table->GetIsolate(), *key)->value();
int entry = table->HashToEntry(hash);
// Walk the chain of the bucket and try finding the key.
while (entry != kNotFound) {
@ -18411,12 +18407,6 @@ bool OrderedHashTable<Derived, entrysize>::Delete(Isolate* isolate,
Object* OrderedHashMap::GetHash(Isolate* isolate, Object* key) {
DisallowHeapAllocation no_gc;
// This special cases for Smi, so that we avoid the HandleScope
// creation below.
if (key->IsSmi()) {
return Smi::FromInt(ComputeIntegerHash(Smi::cast(key)->value()));
}
HandleScope scope(isolate);
Object* hash = key->GetHash();
// If the object does not have an identity hash, it was never used as a key
if (hash->IsUndefined(isolate)) return Smi::FromInt(-1);
@ -18428,7 +18418,7 @@ Object* OrderedHashMap::GetHash(Isolate* isolate, Object* key) {
Handle<OrderedHashMap> OrderedHashMap::Add(Handle<OrderedHashMap> table,
Handle<Object> key,
Handle<Object> value) {
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
int hash = Object::GetOrCreateHash(table->GetIsolate(), *key)->value();
int entry = table->HashToEntry(hash);
// Walk the chain of the bucket and try finding the key.
{
@ -18561,7 +18551,7 @@ Handle<SmallOrderedHashSet> SmallOrderedHashSet::Add(
table = SmallOrderedHashSet::Grow(table);
}
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
int hash = Object::GetOrCreateHash(table->GetIsolate(), *key)->value();
int nof = table->NumberOfElements();
// Read the existing bucket values.
@ -18591,7 +18581,7 @@ Handle<SmallOrderedHashMap> SmallOrderedHashMap::Add(
table = SmallOrderedHashMap::Grow(table);
}
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
int hash = Object::GetOrCreateHash(table->GetIsolate(), *key)->value();
int nof = table->NumberOfElements();
// Read the existing bucket values.

View File

@ -1448,8 +1448,7 @@ class Object {
// Returns the permanent hash code associated with this object depending on
// the actual object type. May create and store a hash code if needed and none
// exists.
// TODO(gsathya): Remove Handle usage, just use Object*.
static Smi* GetOrCreateHash(Isolate* isolate, Handle<Object> object);
static Smi* GetOrCreateHash(Isolate* isolate, Object* object);
// 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
@ -2174,7 +2173,7 @@ class JSReceiver: public HeapObject {
// Retrieves a permanent object identity hash code. May create and store a
// hash code if needed and none exists.
inline static Smi* GetOrCreateIdentityHash(Isolate* isolate,
Handle<JSReceiver> object);
JSReceiver* object);
// Stores the hash code. The hash passed in must be masked with
// JSReceiver::kHashMask.
@ -2699,8 +2698,7 @@ class JSObject: public JSReceiver {
static Object* GetIdentityHash(Isolate* isolate, JSObject* object);
static Smi* GetOrCreateIdentityHash(Isolate* isolate,
Handle<JSObject> object);
static Smi* GetOrCreateIdentityHash(Isolate* isolate, JSObject* object);
// Helper for fast versions of preventExtensions, seal, and freeze.
// attrs is one of NONE, SEALED, or FROZEN (depending on the operation).
@ -6337,7 +6335,7 @@ class JSProxy: public JSReceiver {
static Object* GetIdentityHash(JSProxy* receiver);
static Smi* GetOrCreateIdentityHash(Isolate* isolate, Handle<JSProxy> proxy);
static Smi* GetOrCreateIdentityHash(Isolate* isolate, JSProxy* proxy);
static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
Handle<Symbol> private_name,

View File

@ -28,7 +28,7 @@ RUNTIME_FUNCTION(Runtime_GenericHash) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
Smi* hash = Object::GetOrCreateHash(isolate, object);
Smi* hash = Object::GetOrCreateHash(isolate, *object);
return hash;
}

View File

@ -2918,7 +2918,7 @@ void GlobalProxyIdentityHash(bool set_in_js) {
CHECK(original_hash->IsSmi());
hash1 = i::Smi::ToInt(original_hash);
} else {
hash1 = i::Object::GetOrCreateHash(i_isolate, i_global_proxy)->value();
hash1 = i::Object::GetOrCreateHash(i_isolate, *i_global_proxy)->value();
}
// Hash should be retained after being detached.
env->DetachGlobal();

View File

@ -92,7 +92,7 @@ static void TestHashMap(Handle<HashMap> table) {
// code should not be found.
for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK(JSReceiver::GetOrCreateIdentityHash(isolate, key)->IsSmi());
CHECK(JSReceiver::GetOrCreateIdentityHash(isolate, *key)->IsSmi());
CHECK_EQ(table->FindEntry(key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
CHECK(JSReceiver::GetIdentityHash(isolate, *key)->IsSmi());
@ -163,7 +163,7 @@ static void TestHashSet(Handle<HashSet> table) {
// code should not be found.
for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK(JSReceiver::GetOrCreateIdentityHash(isolate, key)->IsSmi());
CHECK(JSReceiver::GetOrCreateIdentityHash(isolate, *key)->IsSmi());
CHECK(!table->Has(isolate, key));
CHECK(JSReceiver::GetIdentityHash(isolate, *key)->IsSmi());
}

View File

@ -97,9 +97,9 @@ TEST(Weakness) {
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
Handle<Smi> smi(Smi::FromInt(23), isolate);
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
JSWeakCollection::Set(weakmap, key, object, hash);
int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
int32_t object_hash = Object::GetOrCreateHash(isolate, *object)->value();
JSWeakCollection::Set(weakmap, object, smi, object_hash);
}
CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
@ -143,7 +143,7 @@ TEST(Shrinking) {
for (int i = 0; i < 32; i++) {
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
Handle<Smi> smi(Smi::FromInt(i), isolate);
int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
int32_t object_hash = Object::GetOrCreateHash(isolate, *object)->value();
JSWeakCollection::Set(weakmap, object, smi, object_hash);
}
}
@ -191,7 +191,7 @@ TEST(Regress2060a) {
Handle<JSObject> object = factory->NewJSObject(function, TENURED);
CHECK(!heap->InNewSpace(*object));
CHECK(!first_page->Contains(object->address()));
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
JSWeakCollection::Set(weakmap, key, object, hash);
}
}
@ -233,7 +233,7 @@ TEST(Regress2060b) {
Handle<JSWeakMap> weakmap = AllocateJSWeakMap(isolate);
for (int i = 0; i < 32; i++) {
Handle<Smi> smi(Smi::FromInt(i), isolate);
int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
int32_t hash = Object::GetOrCreateHash(isolate, *keys[i])->value();
JSWeakCollection::Set(weakmap, keys[i], smi, hash);
}

View File

@ -98,7 +98,7 @@ TEST(WeakSet_Weakness) {
{
HandleScope scope(isolate);
Handle<Smi> smi(Smi::FromInt(23), isolate);
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
JSWeakCollection::Set(weakset, key, smi, hash);
}
CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
@ -142,7 +142,7 @@ TEST(WeakSet_Shrinking) {
for (int i = 0; i < 32; i++) {
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
Handle<Smi> smi(Smi::FromInt(i), isolate);
int32_t hash = Object::GetOrCreateHash(isolate, object)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *object)->value();
JSWeakCollection::Set(weakset, object, smi, hash);
}
}
@ -190,7 +190,7 @@ TEST(WeakSet_Regress2060a) {
Handle<JSObject> object = factory->NewJSObject(function, TENURED);
CHECK(!heap->InNewSpace(*object));
CHECK(!first_page->Contains(object->address()));
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
int32_t hash = Object::GetOrCreateHash(isolate, *key)->value();
JSWeakCollection::Set(weakset, key, object, hash);
}
}
@ -232,7 +232,7 @@ TEST(WeakSet_Regress2060b) {
Handle<JSWeakSet> weakset = AllocateJSWeakSet(isolate);
for (int i = 0; i < 32; i++) {
Handle<Smi> smi(Smi::FromInt(i), isolate);
int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
int32_t hash = Object::GetOrCreateHash(isolate, *keys[i])->value();
JSWeakCollection::Set(weakset, keys[i], smi, hash);
}