Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: src/heap/mark-compact.cc

Issue 980523004: Retain maps embedded in optimized code for several garbage collections. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Clear on context disposal Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 if (!code->CanDeoptAt(it.frame()->pc())) { 2105 if (!code->CanDeoptAt(it.frame()->pc())) {
2106 code->CodeIterateBody(visitor); 2106 code->CodeIterateBody(visitor);
2107 } 2107 }
2108 ProcessMarkingDeque(); 2108 ProcessMarkingDeque();
2109 return; 2109 return;
2110 } 2110 }
2111 } 2111 }
2112 } 2112 }
2113 2113
2114 2114
2115 void MarkCompactCollector::RetainMaps() {
2116 if (reduce_memory_footprint_ || abort_incremental_marking_ ||
2117 FLAG_retain_maps_for_n_gc == 0) {
2118 // Do not retain dead maps if flag disables it or there is
2119 // - memory pressure (reduce_memory_footprint_),
2120 // - GC is requested by tests or dev-tools (abort_incremental_marking_).
2121 return;
2122 }
2123
2124 ArrayList* retained_maps = heap()->retained_maps();
2125 int length = retained_maps->Length();
2126 int new_length = 0;
2127 for (int i = 0; i < length; i += 2) {
2128 WeakCell* cell = WeakCell::cast(retained_maps->Get(i));
2129 if (cell->cleared()) continue;
2130 int age = Smi::cast(retained_maps->Get(i + 1))->value();
2131 int new_age;
2132 Map* map = Map::cast(cell->value());
2133 MarkBit map_mark = Marking::MarkBitFrom(map);
2134 if (!map_mark.Get()) {
2135 if (age == 0) {
2136 // The map has aged. Do not retain this map.
2137 continue;
2138 }
2139 Object* constructor = map->GetConstructor();
2140 if (!constructor->IsHeapObject() ||
2141 !Marking::MarkBitFrom(HeapObject::cast(constructor)).Get()) {
2142 // The constructor is dead, no new objects with this map can
2143 // be created. Do not retain this map.
2144 continue;
2145 }
2146 new_age = age - 1;
2147 MarkObject(map, map_mark);
2148 } else {
2149 new_age = FLAG_retain_maps_for_n_gc;
2150 }
2151 if (i != new_length) {
2152 retained_maps->Set(new_length, cell);
2153 retained_maps->Set(new_length + 1, Smi::FromInt(new_age));
2154 } else if (new_age != age) {
2155 retained_maps->Set(new_length + 1, Smi::FromInt(new_age));
2156 }
2157 new_length += 2;
2158 }
2159 Object* undefined = heap()->undefined_value();
2160 for (int i = new_length; i < length; i++) {
2161 retained_maps->Clear(i, undefined);
2162 }
2163 if (new_length != length) retained_maps->SetLength(new_length);
2164 ProcessMarkingDeque();
2165 }
2166
2167
2115 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize() { 2168 void MarkCompactCollector::EnsureMarkingDequeIsCommittedAndInitialize() {
2116 if (marking_deque_memory_ == NULL) { 2169 if (marking_deque_memory_ == NULL) {
2117 marking_deque_memory_ = new base::VirtualMemory(4 * MB); 2170 marking_deque_memory_ = new base::VirtualMemory(4 * MB);
2118 } 2171 }
2119 if (!marking_deque_memory_committed_) { 2172 if (!marking_deque_memory_committed_) {
2120 if (!marking_deque_memory_->Commit( 2173 if (!marking_deque_memory_->Commit(
2121 reinterpret_cast<Address>(marking_deque_memory_->address()), 2174 reinterpret_cast<Address>(marking_deque_memory_->address()),
2122 marking_deque_memory_->size(), 2175 marking_deque_memory_->size(),
2123 false)) { // Not executable. 2176 false)) { // Not executable.
2124 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted"); 2177 V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted");
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2220 } 2273 }
2221 } 2274 }
2222 } 2275 }
2223 } 2276 }
2224 2277
2225 RootMarkingVisitor root_visitor(heap()); 2278 RootMarkingVisitor root_visitor(heap());
2226 MarkRoots(&root_visitor); 2279 MarkRoots(&root_visitor);
2227 2280
2228 ProcessTopOptimizedFrame(&root_visitor); 2281 ProcessTopOptimizedFrame(&root_visitor);
2229 2282
2283 // Retaining dying maps should happen before or during ephemeral marking
2284 // because a map could keep the key of an ephemeron alive. Note that map
2285 // aging is imprecise: maps that are kept alive only by ephemerons will age.
2286 RetainMaps();
2287
2230 { 2288 {
2231 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_WEAKCLOSURE); 2289 GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_WEAKCLOSURE);
2232 2290
2233 // The objects reachable from the roots are marked, yet unreachable 2291 // The objects reachable from the roots are marked, yet unreachable
2234 // objects are unmarked. Mark objects reachable due to host 2292 // objects are unmarked. Mark objects reachable due to host
2235 // application specific logic or through Harmony weak maps. 2293 // application specific logic or through Harmony weak maps.
2236 ProcessEphemeralMarking(&root_visitor, false); 2294 ProcessEphemeralMarking(&root_visitor, false);
2237 2295
2238 // The objects reachable from the roots, weak maps or object groups 2296 // The objects reachable from the roots, weak maps or object groups
2239 // are marked. Objects pointed to only by weak global handles cannot be 2297 // are marked. Objects pointed to only by weak global handles cannot be
(...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 SlotsBuffer* buffer = *buffer_address; 4473 SlotsBuffer* buffer = *buffer_address;
4416 while (buffer != NULL) { 4474 while (buffer != NULL) {
4417 SlotsBuffer* next_buffer = buffer->next(); 4475 SlotsBuffer* next_buffer = buffer->next();
4418 DeallocateBuffer(buffer); 4476 DeallocateBuffer(buffer);
4419 buffer = next_buffer; 4477 buffer = next_buffer;
4420 } 4478 }
4421 *buffer_address = NULL; 4479 *buffer_address = NULL;
4422 } 4480 }
4423 } 4481 }
4424 } // namespace v8::internal 4482 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap/mark-compact.h ('k') | src/lithium.cc » ('j') | src/objects-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698