Commit 80aaa879 authored by Marja Hölttä's avatar Marja Hölttä Committed by Commit Bot

[in-place weak refs] Make the WeakArrayList API more generic.

(Pre-work for adding special-purpose data structures as subclasses.)

BUG=v8:7308

Change-Id: I82a5a96e18c3321e9d5b783642516ff869b45f27
Reviewed-on: https://chromium-review.googlesource.com/1084474
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53482}
parent df1676e6
......@@ -5108,8 +5108,10 @@ void Heap::AddRetainedMap(Handle<Map> map) {
if (array->IsFull()) {
CompactRetainedMaps(*array);
}
array =
WeakArrayList::Add(array, map, Smi::FromInt(FLAG_retain_maps_for_n_gc));
array = WeakArrayList::AddToEnd(array, MaybeObjectHandle::Weak(map));
array = WeakArrayList::AddToEnd(
array,
MaybeObjectHandle(Smi::FromInt(FLAG_retain_maps_for_n_gc), isolate()));
if (*array != retained_maps()) {
set_retained_maps(*array);
}
......
......@@ -10372,15 +10372,14 @@ Handle<ArrayList> ArrayList::EnsureSpace(Handle<ArrayList> array, int length) {
}
// static
Handle<WeakArrayList> WeakArrayList::Add(Handle<WeakArrayList> array,
Handle<HeapObject> obj1, Smi* obj2) {
Handle<WeakArrayList> WeakArrayList::AddToEnd(Handle<WeakArrayList> array,
MaybeObjectHandle value) {
int length = array->length();
array = EnsureSpace(array, length + 2);
array = EnsureSpace(array, length + 1);
// Check that GC didn't remove elements from the array.
DCHECK_EQ(array->length(), length);
array->Set(length, HeapObjectReference::Weak(*obj1));
array->Set(length + 1, MaybeObject::FromSmi(obj2));
array->set_length(length + 2);
array->Set(length, *value);
array->set_length(length + 1);
return array;
}
......
......@@ -315,13 +315,13 @@ class WeakArrayList : public HeapObject {
DECL_VERIFIER(WeakArrayList)
DECL_PRINTER(WeakArrayList)
static Handle<WeakArrayList> Add(Handle<WeakArrayList> array,
Handle<HeapObject> obj1, Smi* obj2);
static Handle<WeakArrayList> AddToEnd(Handle<WeakArrayList> array,
MaybeObjectHandle value);
inline MaybeObject* Get(int index) const;
// Set the element at index to obj. The underlying array must be large enough.
// If you need to grow the WeakArrayList, use the static Add() methods
// If you need to grow the WeakArrayList, use the static AddToEnd() method
// instead.
inline void Set(int index, MaybeObject* value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
......
......@@ -453,16 +453,24 @@ TEST(WeakArrayListBasic) {
Handle<FixedArray> index6 = factory->NewFixedArray(1);
index6->set(0, Smi::FromInt(2019));
array = WeakArrayList::Add(array, index0, Smi::FromInt(1));
array = WeakArrayList::AddToEnd(array, MaybeObjectHandle::Weak(index0));
array = WeakArrayList::AddToEnd(
array, MaybeObjectHandle(Smi::FromInt(1), isolate));
CHECK_EQ(array->length(), 2);
array = WeakArrayList::Add(array, index2, Smi::FromInt(3));
array = WeakArrayList::AddToEnd(array, MaybeObjectHandle::Weak(index2));
array = WeakArrayList::AddToEnd(
array, MaybeObjectHandle(Smi::FromInt(3), isolate));
CHECK_EQ(array->length(), 4);
array = WeakArrayList::Add(array, index4, Smi::FromInt(5));
array = WeakArrayList::AddToEnd(array, MaybeObjectHandle::Weak(index4));
array = WeakArrayList::AddToEnd(
array, MaybeObjectHandle(Smi::FromInt(5), isolate));
CHECK_EQ(array->length(), 6);
array = WeakArrayList::Add(array, index6, Smi::FromInt(7));
array = WeakArrayList::AddToEnd(array, MaybeObjectHandle::Weak(index6));
array = WeakArrayList::AddToEnd(
array, MaybeObjectHandle(Smi::FromInt(7), isolate));
CHECK_EQ(array->length(), 8);
CHECK(heap->InNewSpace(*array));
......
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