Line data Source code
1 : // Copyright 2015 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #ifndef V8_HEAP_SCAVENGER_INL_H_
6 : #define V8_HEAP_SCAVENGER_INL_H_
7 :
8 : #include "src/heap/scavenger.h"
9 :
10 : namespace v8 {
11 : namespace internal {
12 :
13 180678478 : void Scavenger::ScavengeObject(HeapObject** p, HeapObject* object) {
14 : DCHECK(object->GetIsolate()->heap()->InFromSpace(object));
15 :
16 : // We use the first word (where the map pointer usually is) of a heap
17 : // object to record the forwarding pointer. A forwarding pointer can
18 : // point to an old space, the code space, or the to space of the new
19 : // generation.
20 : MapWord first_word = object->map_word();
21 :
22 : // If the first word is a forwarding address, the object has already been
23 : // copied.
24 180678478 : if (first_word.IsForwardingAddress()) {
25 64035658 : HeapObject* dest = first_word.ToForwardingAddress();
26 : DCHECK(object->GetIsolate()->heap()->InFromSpace(*p));
27 64035658 : *p = dest;
28 64035658 : return;
29 : }
30 :
31 : object->GetHeap()->UpdateAllocationSite<Heap::kGlobal>(
32 116642820 : object, object->GetHeap()->global_pretenuring_feedback_);
33 :
34 : // AllocationMementos are unrooted and shouldn't survive a scavenge
35 : DCHECK(object->map() != object->GetHeap()->allocation_memento_map());
36 : // Call the slow part of scavenge object.
37 116642820 : return ScavengeObjectSlow(p, object);
38 : }
39 :
40 80860843 : SlotCallbackResult Scavenger::CheckAndScavengeObject(Heap* heap,
41 : Address slot_address) {
42 : Object** slot = reinterpret_cast<Object**>(slot_address);
43 80860843 : Object* object = *slot;
44 80860843 : if (heap->InFromSpace(object)) {
45 : HeapObject* heap_object = reinterpret_cast<HeapObject*>(object);
46 : DCHECK(heap_object->IsHeapObject());
47 :
48 79889024 : ScavengeObject(reinterpret_cast<HeapObject**>(slot), heap_object);
49 :
50 79889024 : object = *slot;
51 : // If the object was in from space before and is after executing the
52 : // callback in to space, the object is still live.
53 : // Unfortunately, we do not know about the slot. It could be in a
54 : // just freed free space object.
55 79889024 : if (heap->InToSpace(object)) {
56 : return KEEP_SLOT;
57 : }
58 : }
59 : // Slots can point to "to" space if the slot has been recorded multiple
60 : // times in the remembered set. We remove the redundant slot now.
61 : return REMOVE_SLOT;
62 : }
63 :
64 : // static
65 412217033 : void StaticScavengeVisitor::VisitPointer(Heap* heap, HeapObject* obj,
66 : Object** p) {
67 412217033 : Object* object = *p;
68 824434066 : if (!heap->InNewSpace(object)) return;
69 : Scavenger::ScavengeObject(reinterpret_cast<HeapObject**>(p),
70 55845653 : reinterpret_cast<HeapObject*>(object));
71 : }
72 :
73 : } // namespace internal
74 : } // namespace v8
75 :
76 : #endif // V8_HEAP_SCAVENGER_INL_H_
|