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

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

Issue 881763005: Just visit young array buffers during scavenge. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@split-up-native-context
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
« src/heap/heap.cc ('K') | « src/heap/objects-visiting.h ('k') | no next file » | 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 Object* last_young_object,
196 Object** last_young_object_recorded) {
195 Object* undefined = heap->undefined_value(); 197 Object* undefined = heap->undefined_value();
196 Object* head = undefined; 198 Object* head = undefined;
197 T* tail = NULL; 199 T* tail = NULL;
198 MarkCompactCollector* collector = heap->mark_compact_collector(); 200 MarkCompactCollector* collector = heap->mark_compact_collector();
199 bool record_slots = MustRecordSlots(heap); 201 bool record_slots = MustRecordSlots(heap);
202 bool last_young_object_found = false;
200 while (list != undefined) { 203 while (list != undefined) {
201 // Check whether to keep the candidate in the list. 204 // Check whether to keep the candidate in the list.
202 T* candidate = reinterpret_cast<T*>(list); 205 T* candidate = reinterpret_cast<T*>(list);
206 if (last_young_object && !last_young_object_found) {
207 last_young_object_found = last_young_object == candidate;
208 }
209
203 Object* retained = retainer->RetainAs(list); 210 Object* retained = retainer->RetainAs(list);
204 if (retained != NULL) { 211 if (retained != NULL) {
205 if (head == undefined) { 212 if (head == undefined) {
206 // First element in the list. 213 // First element in the list.
207 head = retained; 214 head = retained;
208 } else { 215 } else {
209 // Subsequent elements in the list. 216 // Subsequent elements in the list.
210 DCHECK(tail != NULL); 217 DCHECK(tail != NULL);
211 WeakListVisitor<T>::SetWeakNext(tail, retained); 218 WeakListVisitor<T>::SetWeakNext(tail, retained);
212 if (record_slots) { 219 if (record_slots) {
213 Object** next_slot = 220 Object** next_slot =
214 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset()); 221 HeapObject::RawField(tail, WeakListVisitor<T>::WeakNextOffset());
215 collector->RecordSlot(next_slot, next_slot, retained); 222 collector->RecordSlot(next_slot, next_slot, retained);
216 } 223 }
217 } 224 }
218 // Retained object is new tail. 225 // Retained object is new tail.
219 DCHECK(!retained->IsUndefined()); 226 DCHECK(!retained->IsUndefined());
220 candidate = reinterpret_cast<T*>(retained); 227 candidate = reinterpret_cast<T*>(retained);
221 tail = candidate; 228 tail = candidate;
222 229
223 230
224 // tail is a live object, visit it. 231 // tail is a live object, visit it.
225 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer); 232 WeakListVisitor<T>::VisitLiveObject(heap, tail, retainer);
226 } else { 233 } else {
227 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); 234 WeakListVisitor<T>::VisitPhantomObject(heap, candidate);
228 } 235 }
229 236
237 if (last_young_object_recorded && !heap->InNewSpace(retained)) {
238 *last_young_object_recorded = retained;
239 }
240
241 // The list of weak objects is usually order. It starts with objects
242 // recently allocated in the young generation followed by objects
243 // allocated in the old generation.
244 // For young generation collections we just have to visit until the last
245 // young generation objects.
246 if (last_young_object_found && retained) {
247 return head;
248 }
249
230 // Move to next element in the list. 250 // Move to next element in the list.
231 list = WeakListVisitor<T>::WeakNext(candidate); 251 list = WeakListVisitor<T>::WeakNext(candidate);
232 } 252 }
233 253
234 // Terminate the list if there is one or more elements. 254 // Terminate the list if there is one or more elements.
235 if (tail != NULL) { 255 if (tail != NULL) {
236 WeakListVisitor<T>::SetWeakNext(tail, undefined); 256 WeakListVisitor<T>::SetWeakNext(tail, undefined);
237 } 257 }
258
238 return head; 259 return head;
239 } 260 }
240 261
241 262
242 template <class T> 263 template <class T>
243 static void ClearWeakList(Heap* heap, Object* list) { 264 static void ClearWeakList(Heap* heap, Object* list) {
244 Object* undefined = heap->undefined_value(); 265 Object* undefined = heap->undefined_value();
245 while (list != undefined) { 266 while (list != undefined) {
246 T* candidate = reinterpret_cast<T*>(list); 267 T* candidate = reinterpret_cast<T*>(list);
247 list = WeakListVisitor<T>::WeakNext(candidate); 268 list = WeakListVisitor<T>::WeakNext(candidate);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (heap->gc_state() == Heap::MARK_COMPACT) { 330 if (heap->gc_state() == Heap::MARK_COMPACT) {
310 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); 331 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST);
311 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); 332 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST);
312 } 333 }
313 } 334 }
314 335
315 template <class T> 336 template <class T>
316 static void DoWeakList(Heap* heap, Context* context, 337 static void DoWeakList(Heap* heap, Context* context,
317 WeakObjectRetainer* retainer, int index) { 338 WeakObjectRetainer* retainer, int index) {
318 // Visit the weak list, removing dead intermediate elements. 339 // Visit the weak list, removing dead intermediate elements.
319 Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer); 340 Object* list_head =
341 VisitWeakList<T>(heap, context->get(index), retainer, NULL, NULL);
320 342
321 // Update the list head. 343 // Update the list head.
322 context->set(index, list_head, UPDATE_WRITE_BARRIER); 344 context->set(index, list_head, UPDATE_WRITE_BARRIER);
323 345
324 if (MustRecordSlots(heap)) { 346 if (MustRecordSlots(heap)) {
325 // Record the updated slot if necessary. 347 // Record the updated slot if necessary.
326 Object** head_slot = 348 Object** head_slot =
327 HeapObject::RawField(context, FixedArray::SizeFor(index)); 349 HeapObject::RawField(context, FixedArray::SizeFor(index));
328 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, 350 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot,
329 list_head); 351 list_head);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 obj->set_weak_next(next); 383 obj->set_weak_next(next);
362 } 384 }
363 385
364 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } 386 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); }
365 387
366 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } 388 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; }
367 389
368 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, 390 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer,
369 WeakObjectRetainer* retainer) { 391 WeakObjectRetainer* retainer) {
370 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>( 392 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>(
371 heap, array_buffer->weak_first_view(), retainer); 393 heap, array_buffer->weak_first_view(), retainer, NULL, NULL);
372 array_buffer->set_weak_first_view(typed_array_obj); 394 array_buffer->set_weak_first_view(typed_array_obj);
373 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) { 395 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) {
374 Object** slot = HeapObject::RawField(array_buffer, 396 Object** slot = HeapObject::RawField(array_buffer,
375 JSArrayBuffer::kWeakFirstViewOffset); 397 JSArrayBuffer::kWeakFirstViewOffset);
376 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj); 398 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj);
377 } 399 }
378 } 400 }
379 401
380 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { 402 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) {
381 Runtime::FreeArrayBuffer(heap->isolate(), phantom); 403 Runtime::FreeArrayBuffer(heap->isolate(), phantom);
(...skipping 10 matching lines...) Expand all
392 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); } 414 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); }
393 415
394 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } 416 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; }
395 417
396 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} 418 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {}
397 419
398 static void VisitPhantomObject(Heap*, AllocationSite*) {} 420 static void VisitPhantomObject(Heap*, AllocationSite*) {}
399 }; 421 };
400 422
401 423
402 template Object* VisitWeakList<Code>(Heap* heap, Object* list, 424 template Object* VisitWeakList<Context>(Heap* heap, Object* list,
403 WeakObjectRetainer* retainer); 425 WeakObjectRetainer* retainer,
426 Object* last_young_object,
427 Object** last_young_object_recorded);
404 428
405 429
406 template Object* VisitWeakList<JSFunction>(Heap* heap, Object* list, 430 template Object* VisitWeakList<JSArrayBuffer>(
407 WeakObjectRetainer* retainer); 431 Heap* heap, Object* list, WeakObjectRetainer* retainer,
432 Object* last_young_object, Object** last_young_object_recorded);
408 433
409 434
410 template Object* VisitWeakList<Context>(Heap* heap, Object* list, 435 template Object* VisitWeakList<AllocationSite>(
411 WeakObjectRetainer* retainer); 436 Heap* heap, Object* list, WeakObjectRetainer* retainer,
412 437 Object* last_young_object, Object** last_young_object_recorded);
413
414 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list,
415 WeakObjectRetainer* retainer);
416
417
418 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list,
419 WeakObjectRetainer* retainer);
420 } 438 }
421 } // namespace v8::internal 439 } // namespace v8::internal
OLDNEW
« src/heap/heap.cc ('K') | « src/heap/objects-visiting.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698