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

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

Issue 1107843002: Reland "Remove the weak list of views from array buffers" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use bounds check Created 5 years, 7 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/heap.cc ('k') | src/heap/objects-visiting-inl.h » ('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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 // Terminate the list if there is one or more elements. 237 // Terminate the list if there is one or more elements.
238 if (tail != NULL) { 238 if (tail != NULL) {
239 WeakListVisitor<T>::SetWeakNext(tail, undefined); 239 WeakListVisitor<T>::SetWeakNext(tail, undefined);
240 if (list_tail) *list_tail = tail; 240 if (list_tail) *list_tail = tail;
241 } 241 }
242 return head; 242 return head;
243 } 243 }
244 244
245 245
246 Object* VisitNewArrayBufferViewsWeakList(Heap* heap, Object* list,
247 WeakObjectRetainer* retainer) {
248 Object* undefined = heap->undefined_value();
249 Object* previous = undefined;
250 Object* head = undefined;
251 Object* next;
252 MarkCompactCollector* collector = heap->mark_compact_collector();
253 bool record_slots = MustRecordSlots(heap);
254
255 for (Object* o = list; o != undefined;) {
256 JSArrayBufferView* view = JSArrayBufferView::cast(o);
257 next = view->weak_next();
258 if (!heap->InNewSpace(view)) {
259 if (previous != undefined) {
260 // We are in the middle of the list, skip the old space element.
261 JSArrayBufferView* previous_view = JSArrayBufferView::cast(previous);
262 previous_view->set_weak_next(next);
263 if (record_slots) {
264 Object** next_slot = HeapObject::RawField(
265 previous_view, JSArrayBufferView::kWeakNextOffset);
266 collector->RecordSlot(next_slot, next_slot, next);
267 }
268 }
269 JSArrayBuffer* buffer = JSArrayBuffer::cast(view->buffer());
270 view->set_weak_next(buffer->weak_first_view());
271 if (record_slots) {
272 Object** next_slot =
273 HeapObject::RawField(view, JSArrayBufferView::kWeakNextOffset);
274 collector->RecordSlot(next_slot, next_slot, buffer->weak_first_view());
275 }
276 buffer->set_weak_first_view(view);
277 if (record_slots) {
278 Object** slot =
279 HeapObject::RawField(buffer, JSArrayBuffer::kWeakFirstViewOffset);
280 heap->mark_compact_collector()->RecordSlot(slot, slot, view);
281 }
282 } else {
283 // We found a valid new space view, remember it.
284 previous = view;
285 if (head == undefined) {
286 // We are at the list head.
287 head = view;
288 }
289 }
290 o = next;
291 }
292 return head;
293 }
294
295
296 template <class T> 246 template <class T>
297 static void ClearWeakList(Heap* heap, Object* list) { 247 static void ClearWeakList(Heap* heap, Object* list) {
298 Object* undefined = heap->undefined_value(); 248 Object* undefined = heap->undefined_value();
299 while (list != undefined) { 249 while (list != undefined) {
300 T* candidate = reinterpret_cast<T*>(list); 250 T* candidate = reinterpret_cast<T*>(list);
301 list = WeakListVisitor<T>::WeakNext(candidate); 251 list = WeakListVisitor<T>::WeakNext(candidate);
302 WeakListVisitor<T>::SetWeakNext(candidate, undefined); 252 WeakListVisitor<T>::SetWeakNext(candidate, undefined);
303 } 253 }
304 } 254 }
305 255
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 static void VisitPhantomObject(Heap* heap, Context* context) { 338 static void VisitPhantomObject(Heap* heap, Context* context) {
389 ClearWeakList<JSFunction>(heap, 339 ClearWeakList<JSFunction>(heap,
390 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); 340 context->get(Context::OPTIMIZED_FUNCTIONS_LIST));
391 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); 341 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST));
392 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); 342 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST));
393 } 343 }
394 }; 344 };
395 345
396 346
397 template <> 347 template <>
398 struct WeakListVisitor<JSArrayBufferView> {
399 static void SetWeakNext(JSArrayBufferView* obj, Object* next) {
400 obj->set_weak_next(next);
401 }
402
403 static Object* WeakNext(JSArrayBufferView* obj) { return obj->weak_next(); }
404
405 static int WeakNextOffset() { return JSArrayBufferView::kWeakNextOffset; }
406
407 static void VisitLiveObject(Heap*, JSArrayBufferView*, WeakObjectRetainer*) {}
408
409 static void VisitPhantomObject(Heap*, JSArrayBufferView*) {}
410 };
411
412
413 template <>
414 struct WeakListVisitor<JSArrayBuffer> { 348 struct WeakListVisitor<JSArrayBuffer> {
415 static void SetWeakNext(JSArrayBuffer* obj, Object* next) { 349 static void SetWeakNext(JSArrayBuffer* obj, Object* next) {
416 obj->set_weak_next(next); 350 obj->set_weak_next(next);
417 } 351 }
418 352
419 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } 353 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); }
420 354
421 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } 355 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; }
422 356
423 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, 357 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer,
424 WeakObjectRetainer* retainer) { 358 WeakObjectRetainer* retainer) {
425 Object* typed_array_obj = VisitWeakList<JSArrayBufferView>(
426 heap, array_buffer->weak_first_view(), retainer, false, NULL);
427 array_buffer->set_weak_first_view(typed_array_obj);
428 if (typed_array_obj != heap->undefined_value() && MustRecordSlots(heap)) {
429 Object** slot = HeapObject::RawField(array_buffer,
430 JSArrayBuffer::kWeakFirstViewOffset);
431 heap->mark_compact_collector()->RecordSlot(slot, slot, typed_array_obj);
432 }
433 } 359 }
434 360
435 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { 361 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) {
436 Runtime::FreeArrayBuffer(heap->isolate(), phantom); 362 Runtime::FreeArrayBuffer(heap->isolate(), phantom);
437 } 363 }
438 }; 364 };
439 365
440 366
441 template <> 367 template <>
442 struct WeakListVisitor<AllocationSite> { 368 struct WeakListVisitor<AllocationSite> {
(...skipping 15 matching lines...) Expand all
458 WeakObjectRetainer* retainer, 384 WeakObjectRetainer* retainer,
459 bool stop_after_young, 385 bool stop_after_young,
460 Object** list_tail); 386 Object** list_tail);
461 387
462 388
463 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, 389 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list,
464 WeakObjectRetainer* retainer, 390 WeakObjectRetainer* retainer,
465 bool stop_after_young, 391 bool stop_after_young,
466 Object** list_tail); 392 Object** list_tail);
467 393
468 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list,
469 WeakObjectRetainer* retainer,
470 bool stop_after_young,
471 Object** list_tail);
472
473 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, 394 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list,
474 WeakObjectRetainer* retainer, 395 WeakObjectRetainer* retainer,
475 bool stop_after_young, 396 bool stop_after_young,
476 Object** list_tail); 397 Object** list_tail);
477 } 398 }
478 } // namespace v8::internal 399 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/objects-visiting-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698