Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: src/heap/objects-visiting.cc

Issue 904633003: Just visit young array buffers during scavenge. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/objects-visiting.h ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/heap/objects-visiting.h" 7 #include "src/heap/objects-visiting.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return heap->gc_state() == Heap::MARK_COMPACT && 184 return heap->gc_state() == Heap::MARK_COMPACT &&
185 heap->mark_compact_collector()->is_compacting(); 185 heap->mark_compact_collector()->is_compacting();
186 } 186 }
187 187
188 188
189 template <class T> 189 template <class T>
190 struct WeakListVisitor; 190 struct WeakListVisitor;
191 191
192 192
193 template <class T> 193 template <class T>
194 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer) { 194 Object* VisitWeakList(Heap* heap, Object* list, WeakObjectRetainer* retainer,
195 bool stop_after_young) {
195 Object* undefined = heap->undefined_value(); 196 Object* undefined = heap->undefined_value();
196 Object* head = undefined; 197 Object* head = undefined;
197 T* tail = NULL; 198 T* tail = NULL;
198 MarkCompactCollector* collector = heap->mark_compact_collector(); 199 MarkCompactCollector* collector = heap->mark_compact_collector();
199 bool record_slots = MustRecordSlots(heap); 200 bool record_slots = MustRecordSlots(heap);
201
200 while (list != undefined) { 202 while (list != undefined) {
201 // Check whether to keep the candidate in the list. 203 // Check whether to keep the candidate in the list.
202 T* candidate = reinterpret_cast<T*>(list); 204 T* candidate = reinterpret_cast<T*>(list);
205 T* original_candidate = candidate;
206
203 Object* retained = retainer->RetainAs(list); 207 Object* retained = retainer->RetainAs(list);
204 if (retained != NULL) { 208 if (retained != NULL) {
205 if (head == undefined) { 209 if (head == undefined) {
206 // First element in the list. 210 // First element in the list.
207 head = retained; 211 head = retained;
208 } else { 212 } else {
209 // Subsequent elements in the list. 213 // Subsequent elements in the list.
210 DCHECK(tail != NULL); 214 DCHECK(tail != NULL);
211 WeakListVisitor<T>::SetWeakNext(tail, retained); 215 WeakListVisitor<T>::SetWeakNext(tail, retained);
212 if (record_slots) { 216 if (record_slots) {
213 Object** next_slot = 217 Object** next_slot =
214 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); 218 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset());
215 collector->RecordSlot(next_slot, next_slot, retained); 219 collector->RecordSlot(next_slot, next_slot, retained);
216 } 220 }
217 } 221 }
218 // Retained object is new tail. 222 // Retained object is new tail.
219 DCHECK(!retained->IsUndefined()); 223 DCHECK(!retained->IsUndefined());
220 candidate = reinterpret_cast<T*>(retained); 224 candidate = reinterpret_cast<T*>(retained);
221 tail = candidate; 225 tail = candidate;
222 226
223
224 // tail is a live object, visit it. 227 // tail is a live object, visit it.
225 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer); 228 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer);
229
230 // The list of weak objects is usually order. It starts with objects
231 // recently allocated in the young generation followed by objects
232 // allocated in the old generation. When a promotion failure happens,
233 // the list is not ordered until the next GC.
234 // For young generation collections we just have to visit until the last
235 // young generation objects.
236 if (stop_after_young && !heap->promotion_failure() &&
237 !heap->InNewSpace(original_candidate)) {
238 return head;
239 }
226 } else { 240 } else {
227 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); 241 WeakListVisitor<T>::VisitPhantomObject(heap, candidate);
228 } 242 }
229 243
230 // Move to next element in the list. 244 // Move to next element in the list.
231 list = WeakListVisitor<T>::WeakNext(candidate); 245 list = WeakListVisitor<T>::WeakNext(candidate);
232 } 246 }
233 247
234 // Terminate the list if there is one or more elements. 248 // Terminate the list if there is one or more elements.
235 if (tail != NULL) { 249 if (tail != NULL) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (heap->gc_state() == Heap::MARK_COMPACT) { 323 if (heap->gc_state() == Heap::MARK_COMPACT) {
310 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); 324 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST);
311 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); 325 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST);
312 } 326 }
313 } 327 }
314 328
315 template <class T> 329 template <class T>
316 static void DoWeakList(Heap* heap, Context* context, 330 static void DoWeakList(Heap* heap, Context* context,
317 WeakObjectRetainer* retainer, int index) { 331 WeakObjectRetainer* retainer, int index) {
318 // Visit the weak list, removing dead intermediate elements. 332 // Visit the weak list, removing dead intermediate elements.
319 Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer); 333 Object* list_head =
334 VisitWeakList<T>(heap, context->get(index), retainer, false);
320 335
321 // Update the list head. 336 // Update the list head.
322 context->set(index, list_head, UPDATE_WRITE_BARRIER); 337 context->set(index, list_head, UPDATE_WRITE_BARRIER);
323 338
324 if (MustRecordSlots(heap)) { 339 if (MustRecordSlots(heap)) {
325 // Record the updated slot if necessary. 340 // Record the updated slot if necessary.
326 Object** head_slot = 341 Object** head_slot =
327 HeapObject::RawField(context, FixedArray::SizeFor(index)); 342 HeapObject::RawField(context, FixedArray::SizeFor(index));
328 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, 343 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot,
329 list_head); 344 list_head);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 obj->set_weak_next(next); 376 obj->set_weak_next(next);
362 } 377 }
363 378
364 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } 379 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); }
365 380
366 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } 381 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; }
367 382
368 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, 383 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer,
369 WeakObjectRetainer* retainer) { 384 WeakObjectRetainer* retainer) {
370 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>( 385 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>(
371 heap, array_buffer->weak_first_view(), retainer); 386 heap, array_buffer->weak_first_view(), retainer, false);
372 array_buffer->set_weak_first_view(typed_array_obj); 387 array_buffer->set_weak_first_view(typed_array_obj);
373 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) { 388 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) {
374 Object** slot = HeapObject::RawField(array_buffer, 389 Object** slot = HeapObject::RawField(array_buffer,
375 JSArrayBuffer::kWeakFirstViewOffset); 390 JSArrayBuffer::kWeakFirstViewOffset);
376 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); 391 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj);
377 } 392 }
378 } 393 }
379 394
380 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { 395 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) {
381 Runtime::FreeArrayBuffer(heap->isolate(), phantom); 396 Runtime::FreeArrayBuffer(heap->isolate(), phantom);
(...skipping 10 matching lines...) Expand all
392 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); } 407 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); }
393 408
394 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } 409 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; }
395 410
396 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} 411 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {}
397 412
398 static void VisitPhantomObject(Heap*, AllocationSite*) {} 413 static void VisitPhantomObject(Heap*, AllocationSite*) {}
399 }; 414 };
400 415
401 416
402 template Object* VisitWeakList<Code>(Heap* heap, Object* list,
403 WeakObjectRetainer* retainer);
404
405
406 template Object* VisitWeakList<JSFunction>(Heap* heap, Object* list,
407 WeakObjectRetainer* retainer);
408
409
410 template Object* VisitWeakList<Context>(Heap* heap, Object* list, 417 template Object* VisitWeakList<Context>(Heap* heap, Object* list,
411 WeakObjectRetainer* retainer); 418 WeakObjectRetainer* retainer,
419 bool stop_after_young);
412 420
413 421
414 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, 422 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list,
415 WeakObjectRetainer* retainer); 423 WeakObjectRetainer* retainer,
424 bool stop_after_young);
416 425
417 426
418 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, 427 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list,
419 WeakObjectRetainer* retainer); 428 WeakObjectRetainer* retainer,
429 bool stop_after_young);
420 } 430 }
421 } // namespace v8::internal 431 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/objects-visiting.h ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698