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

Side by Side Diff: Source/platform/heap/Heap.cpp

Issue 468083002: Reapply: [oilpan]: Change marking to do precise roots first and conservative (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 2064 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 static_cast<MarkingVisitor*>(s_markingVisitor)->objectGraph().clear(); 2075 static_cast<MarkingVisitor*>(s_markingVisitor)->objectGraph().clear();
2076 #endif 2076 #endif
2077 2077
2078 // Disallow allocation during garbage collection (but not 2078 // Disallow allocation during garbage collection (but not
2079 // during the finalization that happens when the gcScope is 2079 // during the finalization that happens when the gcScope is
2080 // torn down). 2080 // torn down).
2081 NoAllocationScope<AnyThread> noAllocationScope; 2081 NoAllocationScope<AnyThread> noAllocationScope;
2082 2082
2083 prepareForGC(); 2083 prepareForGC();
2084 2084
2085 traceRootsAndPerformGlobalWeakProcessing<GlobalMarking>(); 2085 // 1. trace persistent roots.
2086 ThreadState::visitPersistentRoots(s_markingVisitor);
2087
2088 // 2. trace objects reachable from the persistent roots including ephemerons .
2089 processMarkingStack<GlobalMarking>();
2090
2091 // 3. trace objects reachable from the stack. We do this independent of the
2092 // given stackState since other threads might have a different stack state.
2093 ThreadState::visitStackRoots(s_markingVisitor);
2094
2095 // 4. trace objects reachable from the stack "roots" including ephemerons.
2096 // Only do the processing if we found a pointer to an object on one of the
2097 // thread stacks.
2098 if (lastGCWasConservative())
2099 processMarkingStack<GlobalMarking>();
2100
2101 globalWeakProcessingAndCleanup();
2086 2102
2087 // After a global marking we know that any orphaned page that was not reache d 2103 // After a global marking we know that any orphaned page that was not reache d
2088 // cannot be reached in a subsequent GC. This is due to a thread either havi ng 2104 // cannot be reached in a subsequent GC. This is due to a thread either havi ng
2089 // swept its heap or having done a "poor mans sweep" in prepareForGC which m arks 2105 // swept its heap or having done a "poor mans sweep" in prepareForGC which m arks
2090 // objects that are dead, but not swept in the previous GC as dead. In this GC's 2106 // objects that are dead, but not swept in the previous GC as dead. In this GC's
2091 // marking we check that any object marked as dead is not traced. E.g. via a 2107 // marking we check that any object marked as dead is not traced. E.g. via a
2092 // conservatively found pointer or a programming error with an object contai ning 2108 // conservatively found pointer or a programming error with an object contai ning
2093 // a dangling pointer. 2109 // a dangling pointer.
2094 orphanedPagePool()->decommitOrphanedPages(); 2110 orphanedPagePool()->decommitOrphanedPages();
2095 2111
(...skipping 19 matching lines...) Expand all
2115 // We explicitly do not enter a safepoint while doing thread specific 2131 // We explicitly do not enter a safepoint while doing thread specific
2116 // garbage collection since we don't want to allow a global GC at the 2132 // garbage collection since we don't want to allow a global GC at the
2117 // same time as a thread local GC. 2133 // same time as a thread local GC.
2118 2134
2119 { 2135 {
2120 NoAllocationScope<AnyThread> noAllocationScope; 2136 NoAllocationScope<AnyThread> noAllocationScope;
2121 2137
2122 state->enterGC(); 2138 state->enterGC();
2123 state->prepareForGC(); 2139 state->prepareForGC();
2124 2140
2125 traceRootsAndPerformGlobalWeakProcessing<ThreadLocalMarking>(); 2141 // 1. trace the thread local persistent roots. For thread local GCs we
2142 // don't trace the stack (ie. no conservative scanning) since this is
2143 // only called during thread shutdown where there should be no objects
2144 // on the stack.
2145 // We also assume that orphaned pages have no objects reachable from
2146 // persistent handles on other threads or CrossThreadPersistents. The
2147 // only cases where this could happen is if a subsequent conservative
2148 // global GC finds a "pointer" on the stack or due to a programming
2149 // error where an object has a dangling cross-thread pointer to an
2150 // object on this heap.
2151 state->visitPersistents(s_markingVisitor);
2152
2153 // 2. trace objects reachable from the thread's persistent roots
2154 // including ephemerons.
2155 processMarkingStack<ThreadLocalMarking>();
2156
2157 globalWeakProcessingAndCleanup();
2126 2158
2127 state->leaveGC(); 2159 state->leaveGC();
2128 } 2160 }
2129 state->performPendingSweep(); 2161 state->performPendingSweep();
2130 } 2162 }
2131 2163
2132 template<CallbackInvocationMode Mode> 2164 template<CallbackInvocationMode Mode>
2133 void Heap::traceRootsAndPerformGlobalWeakProcessing() 2165 void Heap::processMarkingStack()
2134 { 2166 {
2135 if (Mode == ThreadLocalMarking)
2136 ThreadState::current()->visitLocalRoots(s_markingVisitor);
2137 else
2138 ThreadState::visitRoots(s_markingVisitor);
2139
2140 // Ephemeron fixed point loop. 2167 // Ephemeron fixed point loop.
2141 do { 2168 do {
2142 // Recursively mark all objects that are reachable from the roots for 2169 // Iteratively mark all objects that are reachable from the objects
2143 // this thread. If Mode is ThreadLocalMarking don't continue tracing if 2170 // currently pushed onto the marking stack. If Mode is ThreadLocalMarkin g
2144 // the trace hits an object on another thread's heap. 2171 // don't continue tracing if the trace hits an object on another thread' s
2172 // heap.
2145 while (popAndInvokeTraceCallback<Mode>(s_markingVisitor)) { } 2173 while (popAndInvokeTraceCallback<Mode>(s_markingVisitor)) { }
2146 2174
2147 // Mark any strong pointers that have now become reachable in ephemeron 2175 // Mark any strong pointers that have now become reachable in ephemeron
2148 // maps. 2176 // maps.
2149 CallbackStack::invokeCallbacks(&s_ephemeronStack, s_markingVisitor); 2177 CallbackStack::invokeCallbacks(&s_ephemeronStack, s_markingVisitor);
2150 2178
2151 // Rerun loop if ephemeron processing queued more objects for tracing. 2179 // Rerun loop if ephemeron processing queued more objects for tracing.
2152 } while (!s_markingStack->isEmpty()); 2180 } while (!s_markingStack->isEmpty());
2181 }
2153 2182
2183 void Heap::globalWeakProcessingAndCleanup()
2184 {
2154 // Call weak callbacks on objects that may now be pointing to dead 2185 // Call weak callbacks on objects that may now be pointing to dead
2155 // objects and call ephemeronIterationDone callbacks on weak tables 2186 // objects and call ephemeronIterationDone callbacks on weak tables
2156 // to do cleanup (specifically clear the queued bits for weak hash 2187 // to do cleanup (specifically clear the queued bits for weak hash
2157 // tables). 2188 // tables).
2158 while (popAndInvokeWeakPointerCallback(s_markingVisitor)) { } 2189 while (popAndInvokeWeakPointerCallback(s_markingVisitor)) { }
2159 2190
2160 CallbackStack::clear(&s_ephemeronStack); 2191 CallbackStack::clear(&s_ephemeronStack);
2161 2192
2162 // It is not permitted to trace pointers of live objects in the weak 2193 // It is not permitted to trace pointers of live objects in the weak
2163 // callback phase, so the marking stack should still be empty here. 2194 // callback phase, so the marking stack should still be empty here.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 Visitor* Heap::s_markingVisitor; 2279 Visitor* Heap::s_markingVisitor;
2249 CallbackStack* Heap::s_markingStack; 2280 CallbackStack* Heap::s_markingStack;
2250 CallbackStack* Heap::s_weakCallbackStack; 2281 CallbackStack* Heap::s_weakCallbackStack;
2251 CallbackStack* Heap::s_ephemeronStack; 2282 CallbackStack* Heap::s_ephemeronStack;
2252 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; 2283 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache;
2253 bool Heap::s_shutdownCalled = false; 2284 bool Heap::s_shutdownCalled = false;
2254 bool Heap::s_lastGCWasConservative = false; 2285 bool Heap::s_lastGCWasConservative = false;
2255 FreePagePool* Heap::s_freePagePool; 2286 FreePagePool* Heap::s_freePagePool;
2256 OrphanedPagePool* Heap::s_orphanedPagePool; 2287 OrphanedPagePool* Heap::s_orphanedPagePool;
2257 } 2288 }
OLDNEW
« no previous file with comments | « Source/platform/heap/Heap.h ('k') | Source/platform/heap/HeapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698