Move runtime helper for JSWeakCollection onto objects.
R=rossberg@chromium.org Review URL: https://codereview.chromium.org/1314053003 Cr-Commit-Position: refs/heads/master@{#30385}
This commit is contained in:
parent
68dfaf78d8
commit
3a8099c750
@ -2525,7 +2525,7 @@ Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) {
|
||||
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
|
||||
ENTER_V8(isolate);
|
||||
i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
|
||||
i::Runtime::WeakCollectionInitialize(isolate, weakmap);
|
||||
i::JSWeakCollection::Initialize(weakmap, isolate);
|
||||
return Utils::NativeWeakMapToLocal(weakmap);
|
||||
}
|
||||
|
||||
@ -2548,7 +2548,7 @@ void NativeWeakMap::Set(Local<Value> v8_key, Local<Value> v8_value) {
|
||||
return;
|
||||
}
|
||||
int32_t hash = i::Object::GetOrCreateHash(isolate, key)->value();
|
||||
i::Runtime::WeakCollectionSet(weak_collection, key, value, hash);
|
||||
i::JSWeakCollection::Set(weak_collection, key, value, hash);
|
||||
}
|
||||
|
||||
|
||||
@ -2611,7 +2611,8 @@ bool NativeWeakMap::Delete(Local<Value> v8_key) {
|
||||
DCHECK(false);
|
||||
return false;
|
||||
}
|
||||
return i::Runtime::WeakCollectionDelete(weak_collection, key);
|
||||
int32_t hash = i::Object::GetOrCreateHash(isolate, key)->value();
|
||||
return i::JSWeakCollection::Delete(weak_collection, key, hash);
|
||||
}
|
||||
|
||||
|
||||
|
@ -15153,6 +15153,49 @@ void JSMap::Clear(Handle<JSMap> map) {
|
||||
}
|
||||
|
||||
|
||||
void JSWeakCollection::Initialize(Handle<JSWeakCollection> weak_collection,
|
||||
Isolate* isolate) {
|
||||
DCHECK_EQ(0, weak_collection->map()->GetInObjectProperties());
|
||||
Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 0);
|
||||
weak_collection->set_table(*table);
|
||||
}
|
||||
|
||||
|
||||
void JSWeakCollection::Set(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, Handle<Object> value,
|
||||
int32_t hash) {
|
||||
DCHECK(key->IsJSReceiver() || key->IsSymbol());
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
DCHECK(table->IsKey(*key));
|
||||
Handle<ObjectHashTable> new_table =
|
||||
ObjectHashTable::Put(table, key, value, hash);
|
||||
weak_collection->set_table(*new_table);
|
||||
if (*table != *new_table) {
|
||||
// Zap the old table since we didn't record slots for its elements.
|
||||
table->FillWithHoles(0, table->length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool JSWeakCollection::Delete(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, int32_t hash) {
|
||||
DCHECK(key->IsJSReceiver() || key->IsSymbol());
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
DCHECK(table->IsKey(*key));
|
||||
bool was_present = false;
|
||||
Handle<ObjectHashTable> new_table =
|
||||
ObjectHashTable::Remove(table, key, &was_present, hash);
|
||||
weak_collection->set_table(*new_table);
|
||||
if (*table != *new_table) {
|
||||
// Zap the old table since we didn't record slots for its elements.
|
||||
table->FillWithHoles(0, table->length());
|
||||
}
|
||||
return was_present;
|
||||
}
|
||||
|
||||
|
||||
// Check if there is a break point at this code position.
|
||||
bool DebugInfo::HasBreakPoint(int code_position) {
|
||||
// Get the break point info object for this code position.
|
||||
|
@ -9445,6 +9445,12 @@ class JSWeakCollection: public JSObject {
|
||||
// [next]: linked list of encountered weak maps during GC.
|
||||
DECL_ACCESSORS(next, Object)
|
||||
|
||||
static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
|
||||
static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
|
||||
Handle<Object> value, int32_t hash);
|
||||
static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
|
||||
int32_t hash);
|
||||
|
||||
static const int kTableOffset = JSObject::kHeaderSize;
|
||||
static const int kNextOffset = kTableOffset + kPointerSize;
|
||||
static const int kSize = kNextOffset + kPointerSize;
|
||||
|
@ -271,19 +271,11 @@ RUNTIME_FUNCTION(Runtime_MapIteratorNext) {
|
||||
}
|
||||
|
||||
|
||||
void Runtime::WeakCollectionInitialize(
|
||||
Isolate* isolate, Handle<JSWeakCollection> weak_collection) {
|
||||
DCHECK_EQ(0, weak_collection->map()->GetInObjectProperties());
|
||||
Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 0);
|
||||
weak_collection->set_table(*table);
|
||||
}
|
||||
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_WeakCollectionInitialize) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 1);
|
||||
CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
|
||||
Runtime::WeakCollectionInitialize(isolate, weak_collection);
|
||||
JSWeakCollection::Initialize(weak_collection, isolate);
|
||||
return *weak_collection;
|
||||
}
|
||||
|
||||
@ -318,32 +310,6 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionHas) {
|
||||
}
|
||||
|
||||
|
||||
bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key) {
|
||||
int32_t hash =
|
||||
Object::GetOrCreateHash(weak_collection->GetIsolate(), key)->value();
|
||||
return WeakCollectionDelete(weak_collection, key, hash);
|
||||
}
|
||||
|
||||
|
||||
bool Runtime::WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, int32_t hash) {
|
||||
DCHECK(key->IsJSReceiver() || key->IsSymbol());
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
DCHECK(table->IsKey(*key));
|
||||
bool was_present = false;
|
||||
Handle<ObjectHashTable> new_table =
|
||||
ObjectHashTable::Remove(table, key, &was_present, hash);
|
||||
weak_collection->set_table(*new_table);
|
||||
if (*table != *new_table) {
|
||||
// Zap the old table since we didn't record slots for its elements.
|
||||
table->FillWithHoles(0, table->length());
|
||||
}
|
||||
return was_present;
|
||||
}
|
||||
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 3);
|
||||
@ -354,28 +320,11 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
RUNTIME_ASSERT(table->IsKey(*key));
|
||||
bool was_present = Runtime::WeakCollectionDelete(weak_collection, key, hash);
|
||||
bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
|
||||
return isolate->heap()->ToBoolean(was_present);
|
||||
}
|
||||
|
||||
|
||||
void Runtime::WeakCollectionSet(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, Handle<Object> value,
|
||||
int32_t hash) {
|
||||
DCHECK(key->IsJSReceiver() || key->IsSymbol());
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
DCHECK(table->IsKey(*key));
|
||||
Handle<ObjectHashTable> new_table =
|
||||
ObjectHashTable::Put(table, key, value, hash);
|
||||
weak_collection->set_table(*new_table);
|
||||
if (*table != *new_table) {
|
||||
// Zap the old table since we didn't record slots for its elements.
|
||||
table->FillWithHoles(0, table->length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 4);
|
||||
@ -387,7 +336,7 @@ RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
|
||||
Handle<ObjectHashTable> table(
|
||||
ObjectHashTable::cast(weak_collection->table()));
|
||||
RUNTIME_ASSERT(table->IsKey(*key));
|
||||
Runtime::WeakCollectionSet(weak_collection, key, value, hash);
|
||||
JSWeakCollection::Set(weak_collection, key, value, hash);
|
||||
return *weak_collection;
|
||||
}
|
||||
|
||||
@ -425,7 +374,7 @@ RUNTIME_FUNCTION(Runtime_ObservationWeakMapCreate) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 0);
|
||||
Handle<JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap();
|
||||
Runtime::WeakCollectionInitialize(isolate, weakmap);
|
||||
JSWeakCollection::Initialize(weakmap, isolate);
|
||||
return *weakmap;
|
||||
}
|
||||
} // namespace internal
|
||||
|
@ -1168,7 +1168,7 @@ class Runtime : public AllStatic {
|
||||
SharedFlag shared = SharedFlag::kNotShared);
|
||||
|
||||
enum TypedArrayId {
|
||||
// arrayIds below should be synchromized with typedarray.js natives.
|
||||
// arrayIds below should be synchronized with typedarray.js natives.
|
||||
ARRAY_ID_UINT8 = 1,
|
||||
ARRAY_ID_INT8 = 2,
|
||||
ARRAY_ID_UINT16 = 3,
|
||||
@ -1191,16 +1191,6 @@ class Runtime : public AllStatic {
|
||||
Isolate* isolate, Handle<FixedArray> literals,
|
||||
Handle<FixedArray> elements, bool is_strong);
|
||||
|
||||
static void WeakCollectionInitialize(
|
||||
Isolate* isolate, Handle<JSWeakCollection> weak_collection);
|
||||
static void WeakCollectionSet(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, Handle<Object> value,
|
||||
int32_t hash);
|
||||
static bool WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key);
|
||||
static bool WeakCollectionDelete(Handle<JSWeakCollection> weak_collection,
|
||||
Handle<Object> key, int32_t hash);
|
||||
|
||||
static MaybeHandle<JSArray> GetInternalProperties(Isolate* isolate,
|
||||
Handle<Object>);
|
||||
|
||||
|
@ -89,9 +89,9 @@ TEST(Weakness) {
|
||||
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
|
||||
Handle<Smi> smi(Smi::FromInt(23), isolate);
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
|
||||
Runtime::WeakCollectionSet(weakmap, key, object, hash);
|
||||
JSWeakCollection::Set(weakmap, key, object, hash);
|
||||
int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
|
||||
Runtime::WeakCollectionSet(weakmap, object, smi, object_hash);
|
||||
JSWeakCollection::Set(weakmap, object, smi, object_hash);
|
||||
}
|
||||
CHECK_EQ(2, ObjectHashTable::cast(weakmap->table())->NumberOfElements());
|
||||
|
||||
@ -147,7 +147,7 @@ TEST(Shrinking) {
|
||||
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
|
||||
Handle<Smi> smi(Smi::FromInt(i), isolate);
|
||||
int32_t object_hash = Object::GetOrCreateHash(isolate, object)->value();
|
||||
Runtime::WeakCollectionSet(weakmap, object, smi, object_hash);
|
||||
JSWeakCollection::Set(weakmap, object, smi, object_hash);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ TEST(Regress2060a) {
|
||||
CHECK(!heap->InNewSpace(object->address()));
|
||||
CHECK(!first_page->Contains(object->address()));
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
|
||||
Runtime::WeakCollectionSet(weakmap, key, object, hash);
|
||||
JSWeakCollection::Set(weakmap, key, object, hash);
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ TEST(Regress2060b) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
Handle<Smi> smi(Smi::FromInt(i), isolate);
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
|
||||
Runtime::WeakCollectionSet(weakmap, keys[i], smi, hash);
|
||||
JSWeakCollection::Set(weakmap, keys[i], smi, hash);
|
||||
}
|
||||
|
||||
// Force compacting garbage collection. The subsequent collections are used
|
||||
|
@ -90,7 +90,7 @@ TEST(WeakSet_Weakness) {
|
||||
HandleScope scope(isolate);
|
||||
Handle<Smi> smi(Smi::FromInt(23), isolate);
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
|
||||
Runtime::WeakCollectionSet(weakset, key, smi, hash);
|
||||
JSWeakCollection::Set(weakset, key, smi, hash);
|
||||
}
|
||||
CHECK_EQ(1, ObjectHashTable::cast(weakset->table())->NumberOfElements());
|
||||
|
||||
@ -146,7 +146,7 @@ TEST(WeakSet_Shrinking) {
|
||||
Handle<JSObject> object = factory->NewJSObjectFromMap(map);
|
||||
Handle<Smi> smi(Smi::FromInt(i), isolate);
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, object)->value();
|
||||
Runtime::WeakCollectionSet(weakset, object, smi, hash);
|
||||
JSWeakCollection::Set(weakset, object, smi, hash);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ TEST(WeakSet_Regress2060a) {
|
||||
CHECK(!heap->InNewSpace(object->address()));
|
||||
CHECK(!first_page->Contains(object->address()));
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, key)->value();
|
||||
Runtime::WeakCollectionSet(weakset, key, object, hash);
|
||||
JSWeakCollection::Set(weakset, key, object, hash);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ TEST(WeakSet_Regress2060b) {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
Handle<Smi> smi(Smi::FromInt(i), isolate);
|
||||
int32_t hash = Object::GetOrCreateHash(isolate, keys[i])->value();
|
||||
Runtime::WeakCollectionSet(weakset, keys[i], smi, hash);
|
||||
JSWeakCollection::Set(weakset, keys[i], smi, hash);
|
||||
}
|
||||
|
||||
// Force compacting garbage collection. The subsequent collections are used
|
||||
|
Loading…
Reference in New Issue
Block a user