obj->set_buffer(*buffer);
- Heap* heap = isolate->heap();
- if (heap->InNewSpace(*obj)) {
- obj->set_weak_next(heap->new_array_buffer_views_list());
- heap->set_new_array_buffer_views_list(*obj);
- } else {
- obj->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(*obj);
- }
+ obj->set_weak_next(buffer->weak_first_view());
+ buffer->set_weak_first_view(*obj);
i::Handle<i::Object> byte_offset_object =
isolate->factory()->NewNumberFromSize(byte_offset);
external_string_table_(this),
chunks_queued_for_free_(NULL),
gc_callbacks_depth_(0),
- deserialization_complete_(false),
- promotion_failure_(false) {
+ deserialization_complete_(false) {
// Allow build-time customization of the max semispace size. Building
// V8 with snapshots and a non-default max semispace size is much
// easier if you can define it as part of the build environment.
// Remember the last top pointer so that we can later find out
// whether we allocated in new space since the last GC.
new_space_top_after_last_gc_ = new_space()->top();
- set_promotion_failure(false);
}
void Heap::ProcessAllWeakReferences(WeakObjectRetainer* retainer) {
- ProcessArrayBuffers(retainer, false);
- ProcessNewArrayBufferViews(retainer);
+ ProcessArrayBuffers(retainer);
ProcessNativeContexts(retainer);
ProcessAllocationSites(retainer);
}
void Heap::ProcessYoungWeakReferences(WeakObjectRetainer* retainer) {
- ProcessArrayBuffers(retainer, true);
- ProcessNewArrayBufferViews(retainer);
+ ProcessArrayBuffers(retainer);
ProcessNativeContexts(retainer);
}
void Heap::ProcessNativeContexts(WeakObjectRetainer* retainer) {
- Object* head =
- VisitWeakList<Context>(this, native_contexts_list(), retainer, false);
+ Object* head = VisitWeakList<Context>(this, native_contexts_list(), retainer);
// Update the head of the list of contexts.
set_native_contexts_list(head);
}
-void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer,
- bool stop_after_young) {
- Object* array_buffer_obj = VisitWeakList<JSArrayBuffer>(
- this, array_buffers_list(), retainer, stop_after_young);
+void Heap::ProcessArrayBuffers(WeakObjectRetainer* retainer) {
+ Object* array_buffer_obj =
+ VisitWeakList<JSArrayBuffer>(this, array_buffers_list(), retainer);
set_array_buffers_list(array_buffer_obj);
-
-#ifdef DEBUG
- // Verify invariant that young array buffers come before old array buffers
- // in array buffers list if there was no promotion failure.
- Object* undefined = undefined_value();
- Object* next = array_buffers_list();
- bool old_objects_recorded = false;
- if (promotion_failure()) return;
- while (next != undefined) {
- if (!old_objects_recorded) {
- old_objects_recorded = !InNewSpace(next);
- }
- DCHECK((InNewSpace(next) && !old_objects_recorded) || !InNewSpace(next));
- next = JSArrayBuffer::cast(next)->weak_next();
- }
-#endif
-}
-
-
-void Heap::ProcessNewArrayBufferViews(WeakObjectRetainer* retainer) {
- // Retain the list of new space views.
- Object* typed_array_obj = VisitWeakList<JSArrayBufferView>(
- this, new_array_buffer_views_list_, retainer, false);
- set_new_array_buffer_views_list(typed_array_obj);
-
- // Some objects in the list may be in old space now. Find them
- // and move them to the corresponding array buffer.
- Object* undefined = undefined_value();
- Object* previous = undefined;
- Object* head = undefined;
- Object* next;
- for (Object* o = new_array_buffer_views_list(); o != undefined;) {
- JSArrayBufferView* view = JSArrayBufferView::cast(o);
- next = view->weak_next();
- if (!InNewSpace(view)) {
- if (previous != undefined) {
- // We are in the middle of the list, skip the old space element.
- JSArrayBufferView::cast(previous)->set_weak_next(next);
- }
- JSArrayBuffer* buffer = JSArrayBuffer::cast(view->buffer());
- view->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(view);
- } else {
- // We found a valid new space view, remember it.
- previous = view;
- if (head == undefined) {
- // We are at the list head.
- head = view;
- }
- }
- o = next;
- }
- set_new_array_buffer_views_list(head);
}
void Heap::ProcessAllocationSites(WeakObjectRetainer* retainer) {
- Object* allocation_site_obj = VisitWeakList<AllocationSite>(
- this, allocation_sites_list(), retainer, false);
+ Object* allocation_site_obj =
+ VisitWeakList<AllocationSite>(this, allocation_sites_list(), retainer);
set_allocation_sites_list(allocation_site_obj);
}
return;
}
- heap->set_promotion_failure(true);
// If promotion failed, we try to copy the object to the other semi-space
if (SemiSpaceCopyObject<alignment>(map, slot, object, object_size)) return;
set_native_contexts_list(undefined_value());
set_array_buffers_list(undefined_value());
- set_new_array_buffer_views_list(undefined_value());
set_allocation_sites_list(undefined_value());
return true;
}
void set_array_buffers_list(Object* object) { array_buffers_list_ = object; }
Object* array_buffers_list() const { return array_buffers_list_; }
- void set_new_array_buffer_views_list(Object* object) {
- new_array_buffer_views_list_ = object;
- }
- Object* new_array_buffer_views_list() const {
- return new_array_buffer_views_list_;
- }
-
void set_allocation_sites_list(Object* object) {
allocation_sites_list_ = object;
}
bool deserialization_complete() const { return deserialization_complete_; }
- bool promotion_failure() const { return promotion_failure_; }
- void set_promotion_failure(bool promotion_failure) {
- promotion_failure_ = promotion_failure;
- }
-
protected:
// Methods made available to tests.
bool inline_allocation_disabled_;
// Weak list heads, threaded through the objects.
- // List heads are initialized lazily and contain the undefined_value at start.
+ // List heads are initilized lazily and contain the undefined_value at start.
Object* native_contexts_list_;
Object* array_buffers_list_;
Object* allocation_sites_list_;
- // This is a global list of array buffer views in new space. When the views
- // get promoted, they are removed form the list and added to the corresponding
- // array buffer.
- Object* new_array_buffer_views_list_;
-
// List of encountered weak collections (JSWeakMap and JSWeakSet) during
// marking. It is initialized during marking, destroyed after marking and
// contains Smi(0) while marking is not active.
void MarkCompactEpilogue();
void ProcessNativeContexts(WeakObjectRetainer* retainer);
- void ProcessArrayBuffers(WeakObjectRetainer* retainer, bool stop_after_young);
- void ProcessNewArrayBufferViews(WeakObjectRetainer* retainer);
+ void ProcessArrayBuffers(WeakObjectRetainer* retainer);
void ProcessAllocationSites(WeakObjectRetainer* retainer);
// Deopts all code that contains allocation instruction which are tenured or
bool deserialization_complete_;
- // A promotion failure indicates that old space promotion failed during
- // gc, i.e., some objects that should have gotten promoted had to stay in
- // the new space (they were copied to the other semi-space).
- bool promotion_failure_;
-
friend class AlwaysAllocateScope;
friend class Deserializer;
friend class Factory;
TryPromoteObject(object, size)) {
continue;
}
- heap()->set_promotion_failure(true);
AllocationResult allocation = new_space->AllocateRaw(size);
if (allocation.IsRetry()) {
template <class T>
-Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer,
- bool stop_after_young) {
+Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer) {
Object* undefined = heap->undefined_value();
Object* head = undefined;
T* tail = NULL;
MarkCompactCollector* collector = heap->mark_compact_collector();
bool record_slots = MustRecordSlots(heap);
-
while (list != undefined) {
// Check whether to keep the candidate in the list.
T* candidate = reinterpret_cast<T*>(list);
- T* original_candidate = candidate;
-
Object* retained = retainer->RetainAs(list);
if (retained != NULL) {
if (head == undefined) {
candidate = reinterpret_cast<T*>(retained);
tail = candidate;
+
// tail is a live object, visit it.
WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer);
-
- // The list of weak objects is usually order. It starts with objects
- // recently allocated in the young generation followed by objects
- // allocated in the old generation. When a promotion failure happens,
- // the list is not ordered until the next GC.
- // For young generation collections we just have to visit until the last
- // young generation objects.
- if (stop_after_young && !heap->promotion_failure() &&
- !heap->InNewSpace(original_candidate)) {
- return head;
- }
} else {
WeakListVisitor<T>::VisitPhantomObject(heap, candidate);
}
static void DoWeakList(Heap* heap, Context* context,
WeakObjectRetainer* retainer, int index) {
// Visit the weak list, removing dead intermediate elements.
- Object* list_head =
- VisitWeakList<T>(heap, context->get(index), retainer, false);
+ Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer);
// Update the list head.
context->set(index, list_head, UPDATE_WRITE_BARRIER);
static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer,
WeakObjectRetainer* retainer) {
Object* typed_array_obj = VisitWeakList<JSArrayBufferView>(
- heap, array_buffer->weak_first_view(), retainer, false);
+ heap, array_buffer->weak_first_view(), retainer);
array_buffer->set_weak_first_view(typed_array_obj);
if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) {
Object** slot = HeapObject::RawField(array_buffer,
};
+template Object* VisitWeakList<Code>(Heap* heap, Object* list,
+ WeakObjectRetainer* retainer);
+
+
+template Object* VisitWeakList<JSFunction>(Heap* heap, Object* list,
+ WeakObjectRetainer* retainer);
+
+
template Object* VisitWeakList<Context>(Heap* heap, Object* list,
- WeakObjectRetainer* retainer,
- bool stop_after_young);
+ WeakObjectRetainer* retainer);
template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list,
- WeakObjectRetainer* retainer,
- bool stop_after_young);
+ WeakObjectRetainer* retainer);
-template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list,
- WeakObjectRetainer* retainer,
- bool stop_after_young);
template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list,
- WeakObjectRetainer* retainer,
- bool stop_after_young);
+ WeakObjectRetainer* retainer);
}
} // namespace v8::internal
// pointers. The template parameter T is a WeakListVisitor that defines how to
// access the next-element pointers.
template <class T>
-Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer,
- bool stop_after_young);
+Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer);
}
} // namespace v8::internal
fixed_typed_array->length(), typed_array->type(),
static_cast<uint8_t*>(buffer->backing_store()));
- Heap* heap = isolate->heap();
- if (heap->InNewSpace(*typed_array)) {
- DCHECK(typed_array->weak_next() == isolate->heap()->undefined_value());
- typed_array->set_weak_next(heap->new_array_buffer_views_list());
- heap->set_new_array_buffer_views_list(*typed_array);
- } else {
- buffer->set_weak_first_view(*typed_array);
- DCHECK(typed_array->weak_next() == isolate->heap()->undefined_value());
- }
+ buffer->set_weak_first_view(*typed_array);
+ DCHECK(typed_array->weak_next() == isolate->heap()->undefined_value());
typed_array->set_buffer(*buffer);
JSObject::SetMapAndElements(typed_array, new_map, new_elements);
void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) {
Isolate* isolate = array_buffer->GetIsolate();
- // Firstly, iterate over the views which are referenced directly by the array
- // buffer.
for (Handle<Object> view_obj(array_buffer->weak_first_view(), isolate);
!view_obj->IsUndefined();) {
Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj));
}
view_obj = handle(view->weak_next(), isolate);
}
-
- // Secondly, iterate over the global list of new space views to find views
- // that belong to the neutered array buffer.
- Heap* heap = isolate->heap();
- for (Handle<Object> view_obj(heap->new_array_buffer_views_list(), isolate);
- !view_obj->IsUndefined();) {
- Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj));
- if (view->buffer() == *array_buffer) {
- if (view->IsJSTypedArray()) {
- JSTypedArray::cast(*view)->Neuter();
- } else if (view->IsJSDataView()) {
- JSDataView::cast(*view)->Neuter();
- } else {
- UNREACHABLE();
- }
- }
- view_obj = handle(view->weak_next(), isolate);
- }
array_buffer->Neuter();
}
holder->set_byte_offset(*byte_offset_object);
holder->set_byte_length(*byte_length_object);
- Heap* heap = isolate->heap();
if (!maybe_buffer->IsNull()) {
Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer);
holder->set_buffer(*buffer);
-
- if (heap->InNewSpace(*holder)) {
- holder->set_weak_next(heap->new_array_buffer_views_list());
- heap->set_new_array_buffer_views_list(*holder);
- } else {
- holder->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(*holder);
- }
+ holder->set_weak_next(buffer->weak_first_view());
+ buffer->set_weak_first_view(*holder);
Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
static_cast<int>(length), array_type,
isolate->factory()->NewNumberFromSize(byte_length));
holder->set_byte_length(*byte_length_obj);
holder->set_length(*length_obj);
-
- Heap* heap = isolate->heap();
- if (heap->InNewSpace(*holder)) {
- holder->set_weak_next(heap->new_array_buffer_views_list());
- heap->set_new_array_buffer_views_list(*holder);
- } else {
- holder->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(*holder);
- }
+ holder->set_weak_next(buffer->weak_first_view());
+ buffer->set_weak_first_view(*holder);
Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
static_cast<int>(length), array_type,
holder->set_byte_offset(*byte_offset);
holder->set_byte_length(*byte_length);
- Heap* heap = isolate->heap();
- if (heap->InNewSpace(*holder)) {
- holder->set_weak_next(heap->new_array_buffer_views_list());
- heap->set_new_array_buffer_views_list(*holder);
- } else {
- holder->set_weak_next(buffer->weak_first_view());
- buffer->set_weak_first_view(*holder);
- }
+ holder->set_weak_next(buffer->weak_first_view());
+ buffer->set_weak_first_view(*holder);
return isolate->heap()->undefined_value();
}
isolate_->heap()->undefined_value());
isolate_->heap()->set_array_buffers_list(
isolate_->heap()->undefined_value());
- isolate->heap()->set_new_array_buffer_views_list(
- isolate_->heap()->undefined_value());
// The allocation site list is build during root iteration, but if no sites
// were encountered then it needs to be initialized to undefined.
}
-static int CountViewsInNewSpaceList(Heap* heap, JSArrayBuffer* array_buffer) {
- int count = 0;
- for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();) {
- JSArrayBufferView* view = JSArrayBufferView::cast(o);
- if (array_buffer == view->buffer()) {
- count++;
- }
- o = view->weak_next();
- }
- return count;
-}
-
-
-static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) {
+static int CountViews(JSArrayBuffer* array_buffer) {
int count = 0;
for (Object* o = array_buffer->weak_first_view();
!o->IsUndefined();
count++;
}
- return count + CountViewsInNewSpaceList(heap, array_buffer);
-}
-
-
-static bool HasViewInNewSpaceList(Heap* heap, JSArrayBufferView* ta) {
- for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();
- o = JSArrayBufferView::cast(o)->weak_next()) {
- if (ta == o) return true;
- }
- return false;
+ return count;
}
-
-static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer,
+static bool HasViewInWeakList(JSArrayBuffer* array_buffer,
JSArrayBufferView* ta) {
for (Object* o = array_buffer->weak_first_view();
!o->IsUndefined();
o = JSArrayBufferView::cast(o)->weak_next()) {
if (ta == o) return true;
}
- return HasViewInNewSpaceList(heap, ta);
+ return false;
}
Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2);
- CHECK_EQ(2, CountViews(isolate->heap(), *iab));
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1));
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2));
+ CHECK_EQ(2, CountViews(*iab));
+ CHECK(HasViewInWeakList(*iab, *ita1));
+ CHECK(HasViewInWeakList(*iab, *ita2));
}
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(1, CountViews(isolate->heap(), *iab));
+ CHECK_EQ(1, CountViews(*iab));
Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1);
- CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1));
+ CHECK(HasViewInWeakList(*iab, *ita1));
}
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(0, CountViews(isolate->heap(), *iab));
+ CHECK_EQ(0, CountViews(*iab));
}
v8::Handle<TypedArray>::Cast(CompileRun("ta3"));
CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
- CHECK_EQ(3, CountViews(isolate->heap(), *iab));
- CHECK(HasViewInWeakList(isolate->heap(), *iab,
- *v8::Utils::OpenHandle(*ta1)));
- CHECK(HasViewInWeakList(isolate->heap(), *iab,
- *v8::Utils::OpenHandle(*ta2)));
- CHECK(HasViewInWeakList(isolate->heap(), *iab,
- *v8::Utils::OpenHandle(*ta3)));
+ CHECK_EQ(3, CountViews(*iab));
+ CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1)));
+ CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta2)));
+ CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta3)));
}
i::SNPrintF(source, "ta%d = null;", i);
v8::Handle<v8::ArrayBuffer> ab =
v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
- CHECK_EQ(2, CountViews(isolate->heap(), *iab));
+ CHECK_EQ(2, CountViews(*iab));
for (int j = 1; j <= 3; j++) {
if (j == i) continue;
i::SNPrintF(source, "ta%d", j);
v8::Handle<TypedArray> ta =
v8::Handle<TypedArray>::Cast(CompileRun(source.start()));
- CHECK(HasViewInWeakList(isolate->heap(), *iab,
- *v8::Utils::OpenHandle(*ta)));
+ CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta)));
}
}
v8::Handle<v8::ArrayBuffer> ab =
v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab"));
Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
- CHECK_EQ(0, CountViews(isolate->heap(), *iab));
+ CHECK_EQ(0, CountViews(*iab));
}
}
}