OLD | NEW |
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 Loading... |
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 |
246 template <class T> | 296 template <class T> |
247 static void ClearWeakList(Heap* heap, Object* list) { | 297 static void ClearWeakList(Heap* heap, Object* list) { |
248 Object* undefined = heap->undefined_value(); | 298 Object* undefined = heap->undefined_value(); |
249 while (list != undefined) { | 299 while (list != undefined) { |
250 T* candidate = reinterpret_cast<T*>(list); | 300 T* candidate = reinterpret_cast<T*>(list); |
251 list = WeakListVisitor<T>::WeakNext(candidate); | 301 list = WeakListVisitor<T>::WeakNext(candidate); |
252 WeakListVisitor<T>::SetWeakNext(candidate, undefined); | 302 WeakListVisitor<T>::SetWeakNext(candidate, undefined); |
253 } | 303 } |
254 } | 304 } |
255 | 305 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 static void VisitPhantomObject(Heap* heap, Context* context) { | 388 static void VisitPhantomObject(Heap* heap, Context* context) { |
339 ClearWeakList<JSFunction>(heap, | 389 ClearWeakList<JSFunction>(heap, |
340 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); | 390 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); |
341 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); | 391 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); |
342 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); | 392 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); |
343 } | 393 } |
344 }; | 394 }; |
345 | 395 |
346 | 396 |
347 template <> | 397 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 <> |
348 struct WeakListVisitor<JSArrayBuffer> { | 414 struct WeakListVisitor<JSArrayBuffer> { |
349 static void SetWeakNext(JSArrayBuffer* obj, Object* next) { | 415 static void SetWeakNext(JSArrayBuffer* obj, Object* next) { |
350 obj->set_weak_next(next); | 416 obj->set_weak_next(next); |
351 } | 417 } |
352 | 418 |
353 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } | 419 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } |
354 | 420 |
355 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } | 421 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } |
356 | 422 |
357 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, | 423 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, |
358 WeakObjectRetainer* retainer) { | 424 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 } |
359 } | 433 } |
360 | 434 |
361 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { | 435 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { |
362 Runtime::FreeArrayBuffer(heap->isolate(), phantom); | 436 Runtime::FreeArrayBuffer(heap->isolate(), phantom); |
363 } | 437 } |
364 }; | 438 }; |
365 | 439 |
366 | 440 |
367 template <> | 441 template <> |
368 struct WeakListVisitor<AllocationSite> { | 442 struct WeakListVisitor<AllocationSite> { |
(...skipping 15 matching lines...) Expand all Loading... |
384 WeakObjectRetainer* retainer, | 458 WeakObjectRetainer* retainer, |
385 bool stop_after_young, | 459 bool stop_after_young, |
386 Object** list_tail); | 460 Object** list_tail); |
387 | 461 |
388 | 462 |
389 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, | 463 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, |
390 WeakObjectRetainer* retainer, | 464 WeakObjectRetainer* retainer, |
391 bool stop_after_young, | 465 bool stop_after_young, |
392 Object** list_tail); | 466 Object** list_tail); |
393 | 467 |
| 468 template Object* VisitWeakList<JSArrayBufferView>(Heap* heap, Object* list, |
| 469 WeakObjectRetainer* retainer, |
| 470 bool stop_after_young, |
| 471 Object** list_tail); |
| 472 |
394 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, | 473 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, |
395 WeakObjectRetainer* retainer, | 474 WeakObjectRetainer* retainer, |
396 bool stop_after_young, | 475 bool stop_after_young, |
397 Object** list_tail); | 476 Object** list_tail); |
398 } | 477 } |
399 } // namespace v8::internal | 478 } // namespace v8::internal |
OLD | NEW |