OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/base/atomicops.h" | 7 #include "src/base/atomicops.h" |
8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/compilation-cache.h" | 10 #include "src/compilation-cache.h" |
(...skipping 2095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 if (!code->CanDeoptAt(it.frame()->pc())) { | 2106 if (!code->CanDeoptAt(it.frame()->pc())) { |
2107 code->CodeIterateBody(visitor); | 2107 code->CodeIterateBody(visitor); |
2108 } | 2108 } |
2109 ProcessMarkingDeque(); | 2109 ProcessMarkingDeque(); |
2110 return; | 2110 return; |
2111 } | 2111 } |
2112 } | 2112 } |
2113 } | 2113 } |
2114 | 2114 |
2115 | 2115 |
| 2116 void MarkCompactCollector::RetainMaps() { |
| 2117 if (reduce_memory_footprint_ || abort_incremental_marking_ || |
| 2118 FLAG_retain_maps_for_n_gc == 0) { |
| 2119 // Do not retain dead maps if flag disables it or there is |
| 2120 // - memory pressure (reduce_memory_footprint_), |
| 2121 // - GC is requested by tests or dev-tools (abort_incremental_marking_). |
| 2122 return; |
| 2123 } |
| 2124 |
| 2125 ArrayList* retained_maps = heap()->retained_maps(); |
| 2126 int length = retained_maps->Length(); |
| 2127 int new_length = 0; |
| 2128 for (int i = 0; i < length; i += 2) { |
| 2129 WeakCell* cell = WeakCell::cast(retained_maps->Get(i)); |
| 2130 if (cell->cleared()) continue; |
| 2131 int age = Smi::cast(retained_maps->Get(i + 1))->value(); |
| 2132 int new_age; |
| 2133 Map* map = Map::cast(cell->value()); |
| 2134 MarkBit map_mark = Marking::MarkBitFrom(map); |
| 2135 if (!map_mark.Get()) { |
| 2136 if (age == 0) { |
| 2137 // The map has aged. Do not retain this map. |
| 2138 continue; |
| 2139 } |
| 2140 Object* constructor = map->GetConstructor(); |
| 2141 if (!constructor->IsHeapObject() || |
| 2142 !Marking::MarkBitFrom(HeapObject::cast(constructor)).Get()) { |
| 2143 // The constructor is dead, no new objects with this map can |
| 2144 // be created. Do not retain this map. |
| 2145 continue; |
| 2146 } |
| 2147 new_age = age - 1; |
| 2148 MarkObject(map, map_mark); |
| 2149 } else { |
| 2150 new_age = FLAG_retain_maps_for_n_gc; |
| 2151 } |
| 2152 if (i != new_length) { |
| 2153 retained_maps->Set(new_length, cell); |
| 2154 Object** slot = retained_maps->Slot(new_length); |
| 2155 RecordSlot(slot, slot, cell); |
| 2156 retained_maps->Set(new_length + 1, Smi::FromInt(new_age)); |
| 2157 } else if (new_age != age) { |
| 2158 retained_maps->Set(new_length + 1, Smi::FromInt(new_age)); |
| 2159 } |
| 2160 new_length += 2; |
| 2161 } |
| 2162 Object* undefined = heap()->undefined_value(); |
| 2163 for (int i = new_length; i < length; i++) { |
| 2164 retained_maps->Clear(i, undefined); |
| 2165 } |
| 2166 if (new_length != length) retained_maps->SetLength(new_length); |
| 2167 ProcessMarkingDeque(); |
| 2168 } |
| 2169 |
| 2170 |
2116 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize() { | 2171 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize() { |
2117 if (marking_deque_memory_ == NULL) { | 2172 if (marking_deque_memory_ == NULL) { |
2118 marking_deque_memory_ = new base::VirtualMemory(4 * MB); | 2173 marking_deque_memory_ = new base::VirtualMemory(4 * MB); |
2119 } | 2174 } |
2120 if (!marking_deque_memory_committed_) { | 2175 if (!marking_deque_memory_committed_) { |
2121 if (!marking_deque_memory_->Commit( | 2176 if (!marking_deque_memory_->Commit( |
2122 reinterpret_cast<Address>(marking_deque_memory_->address()), | 2177 reinterpret_cast<Address>(marking_deque_memory_->address()), |
2123 marking_deque_memory_->size(), | 2178 marking_deque_memory_->size(), |
2124 false)) { // Not executable. | 2179 false)) { // Not executable. |
2125 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted"); | 2180 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted"); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2221 } | 2276 } |
2222 } | 2277 } |
2223 } | 2278 } |
2224 } | 2279 } |
2225 | 2280 |
2226 RootMarkingVisitor root_visitor(heap()); | 2281 RootMarkingVisitor root_visitor(heap()); |
2227 MarkRoots(&root_visitor); | 2282 MarkRoots(&root_visitor); |
2228 | 2283 |
2229 ProcessTopOptimizedFrame(&root_visitor); | 2284 ProcessTopOptimizedFrame(&root_visitor); |
2230 | 2285 |
| 2286 // Retaining dying maps should happen before or during ephemeral marking |
| 2287 // because a map could keep the key of an ephemeron alive. Note that map |
| 2288 // aging is imprecise: maps that are kept alive only by ephemerons will age. |
| 2289 RetainMaps(); |
| 2290 |
2231 { | 2291 { |
2232 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_WEAKCLOSURE); | 2292 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_WEAKCLOSURE); |
2233 | 2293 |
2234 // The objects reachable from the roots are marked, yet unreachable | 2294 // The objects reachable from the roots are marked, yet unreachable |
2235 // objects are unmarked. Mark objects reachable due to host | 2295 // objects are unmarked. Mark objects reachable due to host |
2236 // application specific logic or through Harmony weak maps. | 2296 // application specific logic or through Harmony weak maps. |
2237 ProcessEphemeralMarking(&root_visitor, false); | 2297 ProcessEphemeralMarking(&root_visitor, false); |
2238 | 2298 |
2239 // The objects reachable from the roots, weak maps or object groups | 2299 // The objects reachable from the roots, weak maps or object groups |
2240 // are marked. Objects pointed to only by weak global handles cannot be | 2300 // are marked. Objects pointed to only by weak global handles cannot be |
(...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4416 SlotsBuffer* buffer = *buffer_address; | 4476 SlotsBuffer* buffer = *buffer_address; |
4417 while (buffer != NULL) { | 4477 while (buffer != NULL) { |
4418 SlotsBuffer* next_buffer = buffer->next(); | 4478 SlotsBuffer* next_buffer = buffer->next(); |
4419 DeallocateBuffer(buffer); | 4479 DeallocateBuffer(buffer); |
4420 buffer = next_buffer; | 4480 buffer = next_buffer; |
4421 } | 4481 } |
4422 *buffer_address = NULL; | 4482 *buffer_address = NULL; |
4423 } | 4483 } |
4424 } | 4484 } |
4425 } // namespace v8::internal | 4485 } // namespace v8::internal |
OLD | NEW |