| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, Object** list_tail) { |
| 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); |
| 200 | 201 |
| 201 while (list != undefined) { | 202 while (list != undefined) { |
| 202 // Check whether to keep the candidate in the list. | 203 // Check whether to keep the candidate in the list. |
| 203 T* candidate = reinterpret_cast<T*>(list); | 204 T* candidate = reinterpret_cast<T*>(list); |
| 204 | 205 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 227 | 228 |
| 228 } else { | 229 } else { |
| 229 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); | 230 WeakListVisitor<T>::VisitPhantomObject(heap, candidate); |
| 230 } | 231 } |
| 231 | 232 |
| 232 // Move to next element in the list. | 233 // Move to next element in the list. |
| 233 list = WeakListVisitor<T>::WeakNext(candidate); | 234 list = WeakListVisitor<T>::WeakNext(candidate); |
| 234 } | 235 } |
| 235 | 236 |
| 236 // Terminate the list if there is one or more elements. | 237 // Terminate the list if there is one or more elements. |
| 237 if (tail != NULL) WeakListVisitor<T>::SetWeakNext(tail, undefined); | 238 if (tail != NULL) { |
| 239 WeakListVisitor<T>::SetWeakNext(tail, undefined); |
| 240 if (list_tail) *list_tail = tail; |
| 241 } |
| 238 return head; | 242 return head; |
| 239 } | 243 } |
| 240 | 244 |
| 241 | 245 |
| 242 template <class T> | 246 template <class T> |
| 243 static void ClearWeakList(Heap* heap, Object* list) { | 247 static void ClearWeakList(Heap* heap, Object* list) { |
| 244 Object* undefined = heap->undefined_value(); | 248 Object* undefined = heap->undefined_value(); |
| 245 while (list != undefined) { | 249 while (list != undefined) { |
| 246 T* candidate = reinterpret_cast<T*>(list); | 250 T* candidate = reinterpret_cast<T*>(list); |
| 247 list = WeakListVisitor<T>::WeakNext(candidate); | 251 list = WeakListVisitor<T>::WeakNext(candidate); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (heap->gc_state() == Heap::MARK_COMPACT) { | 313 if (heap->gc_state() == Heap::MARK_COMPACT) { |
| 310 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); | 314 DoWeakList<Code>(heap, context, retainer, Context::OPTIMIZED_CODE_LIST); |
| 311 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); | 315 DoWeakList<Code>(heap, context, retainer, Context::DEOPTIMIZED_CODE_LIST); |
| 312 } | 316 } |
| 313 } | 317 } |
| 314 | 318 |
| 315 template <class T> | 319 template <class T> |
| 316 static void DoWeakList(Heap* heap, Context* context, | 320 static void DoWeakList(Heap* heap, Context* context, |
| 317 WeakObjectRetainer* retainer, int index) { | 321 WeakObjectRetainer* retainer, int index) { |
| 318 // Visit the weak list, removing dead intermediate elements. | 322 // Visit the weak list, removing dead intermediate elements. |
| 319 Object* list_head = VisitWeakList<T>(heap, context->get(index), retainer); | 323 Object* list_head = |
| 324 VisitWeakList<T>(heap, context->get(index), retainer, false, NULL); |
| 320 | 325 |
| 321 // Update the list head. | 326 // Update the list head. |
| 322 context->set(index, list_head, UPDATE_WRITE_BARRIER); | 327 context->set(index, list_head, UPDATE_WRITE_BARRIER); |
| 323 | 328 |
| 324 if (MustRecordSlots(heap)) { | 329 if (MustRecordSlots(heap)) { |
| 325 // Record the updated slot if necessary. | 330 // Record the updated slot if necessary. |
| 326 Object** head_slot = | 331 Object** head_slot = |
| 327 HeapObject::RawField(context, FixedArray::SizeFor(index)); | 332 HeapObject::RawField(context, FixedArray::SizeFor(index)); |
| 328 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, | 333 heap->mark_compact_collector()->RecordSlot(head_slot, head_slot, |
| 329 list_head); | 334 list_head); |
| 330 } | 335 } |
| 331 } | 336 } |
| 332 | 337 |
| 333 static void VisitPhantomObject(Heap* heap, Context* context) { | 338 static void VisitPhantomObject(Heap* heap, Context* context) { |
| 334 ClearWeakList<JSFunction>(heap, | 339 ClearWeakList<JSFunction>(heap, |
| 335 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); | 340 context->get(Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 336 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); | 341 ClearWeakList<Code>(heap, context->get(Context::OPTIMIZED_CODE_LIST)); |
| 337 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); | 342 ClearWeakList<Code>(heap, context->get(Context::DEOPTIMIZED_CODE_LIST)); |
| 338 } | 343 } |
| 339 }; | 344 }; |
| 340 | 345 |
| 341 | 346 |
| 342 template <> | 347 template <> |
| 348 struct WeakListVisitor<JSArrayBuffer> { |
| 349 static void SetWeakNext(JSArrayBuffer* obj, Object* next) { |
| 350 obj->set_weak_next(next); |
| 351 } |
| 352 |
| 353 static Object* WeakNext(JSArrayBuffer* obj) { return obj->weak_next(); } |
| 354 |
| 355 static int WeakNextOffset() { return JSArrayBuffer::kWeakNextOffset; } |
| 356 |
| 357 static void VisitLiveObject(Heap* heap, JSArrayBuffer* array_buffer, |
| 358 WeakObjectRetainer* retainer) { |
| 359 } |
| 360 |
| 361 static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) { |
| 362 Runtime::FreeArrayBuffer(heap->isolate(), phantom); |
| 363 } |
| 364 }; |
| 365 |
| 366 |
| 367 template <> |
| 343 struct WeakListVisitor<AllocationSite> { | 368 struct WeakListVisitor<AllocationSite> { |
| 344 static void SetWeakNext(AllocationSite* obj, Object* next) { | 369 static void SetWeakNext(AllocationSite* obj, Object* next) { |
| 345 obj->set_weak_next(next); | 370 obj->set_weak_next(next); |
| 346 } | 371 } |
| 347 | 372 |
| 348 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); } | 373 static Object* WeakNext(AllocationSite* obj) { return obj->weak_next(); } |
| 349 | 374 |
| 350 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } | 375 static int WeakNextOffset() { return AllocationSite::kWeakNextOffset; } |
| 351 | 376 |
| 352 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} | 377 static void VisitLiveObject(Heap*, AllocationSite*, WeakObjectRetainer*) {} |
| 353 | 378 |
| 354 static void VisitPhantomObject(Heap*, AllocationSite*) {} | 379 static void VisitPhantomObject(Heap*, AllocationSite*) {} |
| 355 }; | 380 }; |
| 356 | 381 |
| 357 | 382 |
| 358 template Object* VisitWeakList<Context>(Heap* heap, Object* list, | 383 template Object* VisitWeakList<Context>(Heap* heap, Object* list, |
| 359 WeakObjectRetainer* retainer); | 384 WeakObjectRetainer* retainer, |
| 385 bool stop_after_young, |
| 386 Object** list_tail); |
| 387 |
| 388 |
| 389 template Object* VisitWeakList<JSArrayBuffer>(Heap* heap, Object* list, |
| 390 WeakObjectRetainer* retainer, |
| 391 bool stop_after_young, |
| 392 Object** list_tail); |
| 360 | 393 |
| 361 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, | 394 template Object* VisitWeakList<AllocationSite>(Heap* heap, Object* list, |
| 362 WeakObjectRetainer* retainer); | 395 WeakObjectRetainer* retainer, |
| 396 bool stop_after_young, |
| 397 Object** list_tail); |
| 363 } | 398 } |
| 364 } // namespace v8::internal | 399 } // namespace v8::internal |
| OLD | NEW |