OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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/heap/concurrent-marking.h" | 5 #include "src/heap/concurrent-marking.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 | 9 |
10 #include "src/heap/heap-inl.h" | 10 #include "src/heap/heap-inl.h" |
11 #include "src/heap/heap.h" | 11 #include "src/heap/heap.h" |
12 #include "src/heap/marking.h" | 12 #include "src/heap/marking.h" |
| 13 #include "src/heap/objects-visiting-inl.h" |
| 14 #include "src/heap/objects-visiting.h" |
13 #include "src/isolate.h" | 15 #include "src/isolate.h" |
14 #include "src/locked-queue-inl.h" | 16 #include "src/locked-queue-inl.h" |
15 #include "src/utils-inl.h" | 17 #include "src/utils-inl.h" |
16 #include "src/utils.h" | 18 #include "src/utils.h" |
17 #include "src/v8.h" | 19 #include "src/v8.h" |
18 | 20 |
19 namespace v8 { | 21 namespace v8 { |
20 namespace internal { | 22 namespace internal { |
21 | 23 |
22 class ConcurrentMarkingMarkbits { | 24 class ConcurrentMarkingMarkbits { |
(...skipping 20 matching lines...) Expand all Loading... |
43 Bitmap* AllocateBitmap() { | 45 Bitmap* AllocateBitmap() { |
44 return static_cast<Bitmap*>(calloc(1, Bitmap::kSize)); | 46 return static_cast<Bitmap*>(calloc(1, Bitmap::kSize)); |
45 } | 47 } |
46 | 48 |
47 void FreeBitmap(Bitmap* bitmap) { free(bitmap); } | 49 void FreeBitmap(Bitmap* bitmap) { free(bitmap); } |
48 | 50 |
49 private: | 51 private: |
50 std::unordered_map<MemoryChunk*, Bitmap*> bitmap_; | 52 std::unordered_map<MemoryChunk*, Bitmap*> bitmap_; |
51 }; | 53 }; |
52 | 54 |
53 class ConcurrentMarkingVisitor : public ObjectVisitor { | 55 class ConcurrentMarkingVisitor final |
| 56 : public HeapVisitor<int, ConcurrentMarkingVisitor> { |
54 public: | 57 public: |
| 58 using BaseClass = HeapVisitor<int, ConcurrentMarkingVisitor>; |
| 59 |
55 ConcurrentMarkingVisitor() : bytes_marked_(0) {} | 60 ConcurrentMarkingVisitor() : bytes_marked_(0) {} |
56 | 61 |
57 void VisitPointers(HeapObject* host, Object** start, Object** end) override { | 62 void VisitPointers(HeapObject* host, Object** start, Object** end) override { |
58 for (Object** p = start; p < end; p++) { | 63 for (Object** p = start; p < end; p++) { |
59 if (!(*p)->IsHeapObject()) continue; | 64 if (!(*p)->IsHeapObject()) continue; |
60 MarkObject(HeapObject::cast(*p)); | 65 MarkObject(HeapObject::cast(*p)); |
61 } | 66 } |
62 } | 67 } |
63 | 68 |
| 69 // =========================================================================== |
| 70 // JS object ================================================================= |
| 71 // =========================================================================== |
| 72 |
| 73 int VisitJSObject(Map* map, JSObject* object) override { |
| 74 // TODO(ulan): impement snapshot iteration. |
| 75 return BaseClass::VisitJSObject(map, object); |
| 76 } |
| 77 |
| 78 int VisitJSObjectFast(Map* map, JSObject* object) override { |
| 79 return VisitJSObject(map, object); |
| 80 } |
| 81 |
| 82 int VisitJSApiObject(Map* map, JSObject* object) override { |
| 83 return VisitJSObject(map, object); |
| 84 } |
| 85 |
| 86 // =========================================================================== |
| 87 // Fixed array object ======================================================== |
| 88 // =========================================================================== |
| 89 |
| 90 int VisitFixedArray(Map* map, FixedArray* object) override { |
| 91 // TODO(ulan): implement iteration with prefetched length. |
| 92 return BaseClass::VisitFixedArray(map, object); |
| 93 } |
| 94 |
| 95 // =========================================================================== |
| 96 // Code object =============================================================== |
| 97 // =========================================================================== |
| 98 |
| 99 int VisitCode(Map* map, Code* object) override { |
| 100 // TODO(ulan): push the object to the bail-out deque. |
| 101 return 0; |
| 102 } |
| 103 |
| 104 // =========================================================================== |
| 105 // Objects with weak fields and/or side-effectiful visitation. |
| 106 // =========================================================================== |
| 107 |
| 108 int VisitBytecodeArray(Map* map, BytecodeArray* object) override { |
| 109 // TODO(ulan): implement iteration of strong fields and push the object to |
| 110 // the bailout deque. |
| 111 return 0; |
| 112 } |
| 113 |
| 114 int VisitJSFunction(Map* map, JSFunction* object) override { |
| 115 // TODO(ulan): implement iteration of strong fields and push the object to |
| 116 // the bailout deque. |
| 117 return 0; |
| 118 } |
| 119 |
| 120 int VisitMap(Map* map, Map* object) override { |
| 121 // TODO(ulan): implement iteration of strong fields and push the object to |
| 122 // the bailout deque. |
| 123 return 0; |
| 124 } |
| 125 |
| 126 int VisitNativeContext(Map* map, Context* object) override { |
| 127 // TODO(ulan): implement iteration of strong fields and push the object to |
| 128 // the bailout deque. |
| 129 return 0; |
| 130 } |
| 131 |
| 132 int VisitSharedFunctionInfo(Map* map, SharedFunctionInfo* object) override { |
| 133 // TODO(ulan): implement iteration of strong fields and push the object to |
| 134 // the bailout deque. |
| 135 return 0; |
| 136 } |
| 137 |
| 138 int VisitTransitionArray(Map* map, TransitionArray* object) override { |
| 139 // TODO(ulan): implement iteration of strong fields and push the object to |
| 140 // the bailout deque. |
| 141 return 0; |
| 142 } |
| 143 |
| 144 int VisitWeakCell(Map* map, WeakCell* object) override { |
| 145 // TODO(ulan): implement iteration of strong fields and push the object to |
| 146 // the bailout deque. |
| 147 return 0; |
| 148 } |
| 149 |
| 150 int VisitJSWeakCollection(Map* map, JSWeakCollection* object) override { |
| 151 // TODO(ulan): implement iteration of strong fields and push the object to |
| 152 // the bailout deque. |
| 153 return 0; |
| 154 } |
| 155 |
64 void MarkObject(HeapObject* obj) { | 156 void MarkObject(HeapObject* obj) { |
65 if (markbits_.Mark(obj)) { | 157 if (markbits_.Mark(obj)) { |
66 bytes_marked_ += obj->Size(); | |
67 marking_stack_.push(obj); | 158 marking_stack_.push(obj); |
68 } | 159 } |
69 } | 160 } |
70 | 161 |
71 void MarkTransitively() { | 162 void MarkTransitively() { |
72 while (!marking_stack_.empty()) { | 163 while (!marking_stack_.empty()) { |
73 HeapObject* obj = marking_stack_.top(); | 164 HeapObject* obj = marking_stack_.top(); |
74 marking_stack_.pop(); | 165 marking_stack_.pop(); |
75 obj->Iterate(this); | 166 bytes_marked_ += IterateBody(obj); |
76 } | 167 } |
77 } | 168 } |
78 | 169 |
79 size_t bytes_marked() { return bytes_marked_; } | 170 size_t bytes_marked() { return bytes_marked_; } |
80 | 171 |
81 private: | 172 private: |
82 size_t bytes_marked_; | 173 size_t bytes_marked_; |
83 std::stack<HeapObject*> marking_stack_; | 174 std::stack<HeapObject*> marking_stack_; |
84 ConcurrentMarkingMarkbits markbits_; | 175 ConcurrentMarkingMarkbits markbits_; |
85 }; | 176 }; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 } | 243 } |
153 | 244 |
154 void ConcurrentMarking::EnsureTaskCompleted() { | 245 void ConcurrentMarking::EnsureTaskCompleted() { |
155 if (IsTaskPending()) { | 246 if (IsTaskPending()) { |
156 WaitForTaskToComplete(); | 247 WaitForTaskToComplete(); |
157 } | 248 } |
158 } | 249 } |
159 | 250 |
160 } // namespace internal | 251 } // namespace internal |
161 } // namespace v8 | 252 } // namespace v8 |
OLD | NEW |