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