OLD | NEW |
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 2061 matching lines...) Loading... |
2072 static_cast<MarkingVisitor*>(s_markingVisitor)->objectGraph().clear(); | 2072 static_cast<MarkingVisitor*>(s_markingVisitor)->objectGraph().clear(); |
2073 #endif | 2073 #endif |
2074 | 2074 |
2075 // Disallow allocation during garbage collection (but not | 2075 // Disallow allocation during garbage collection (but not |
2076 // during the finalization that happens when the gcScope is | 2076 // during the finalization that happens when the gcScope is |
2077 // torn down). | 2077 // torn down). |
2078 NoAllocationScope<AnyThread> noAllocationScope; | 2078 NoAllocationScope<AnyThread> noAllocationScope; |
2079 | 2079 |
2080 prepareForGC(); | 2080 prepareForGC(); |
2081 | 2081 |
2082 traceRootsAndPerformGlobalWeakProcessing<GlobalMarking>(); | 2082 // 1. trace persistent roots. |
| 2083 ThreadState::visitPersistentRoots(s_markingVisitor); |
| 2084 |
| 2085 // 2. trace objects reachable from the persistent roots including ephemerons
. |
| 2086 processMarkingStack<GlobalMarking>(); |
| 2087 |
| 2088 // 3. trace objects reachable from the stack. We do this independent of the |
| 2089 // given stackState since other threads might have a different stack state. |
| 2090 ThreadState::visitStackRoots(s_markingVisitor); |
| 2091 |
| 2092 // 4. trace objects reachable from the stack "roots" including ephemerons. |
| 2093 // Only do the processing if we found a pointer to an object on one of the |
| 2094 // thread stacks. |
| 2095 if (lastGCWasConservative()) |
| 2096 processMarkingStack<GlobalMarking>(); |
| 2097 |
| 2098 globalWeakProcessingAndCleanup(); |
2083 | 2099 |
2084 // After a global marking we know that any orphaned page that was not reache
d | 2100 // After a global marking we know that any orphaned page that was not reache
d |
2085 // cannot be reached in a subsequent GC. This is due to a thread either havi
ng | 2101 // cannot be reached in a subsequent GC. This is due to a thread either havi
ng |
2086 // swept its heap or having done a "poor mans sweep" in prepareForGC which m
arks | 2102 // swept its heap or having done a "poor mans sweep" in prepareForGC which m
arks |
2087 // objects that are dead, but not swept in the previous GC as dead. In this
GC's | 2103 // objects that are dead, but not swept in the previous GC as dead. In this
GC's |
2088 // marking we check that any object marked as dead is not traced. E.g. via a | 2104 // marking we check that any object marked as dead is not traced. E.g. via a |
2089 // conservatively found pointer or a programming error with an object contai
ning | 2105 // conservatively found pointer or a programming error with an object contai
ning |
2090 // a dangling pointer. | 2106 // a dangling pointer. |
2091 orphanedPagePool()->decommitOrphanedPages(); | 2107 orphanedPagePool()->decommitOrphanedPages(); |
2092 | 2108 |
(...skipping 16 matching lines...) Loading... |
2109 // We explicitly do not enter a safepoint while doing thread specific | 2125 // We explicitly do not enter a safepoint while doing thread specific |
2110 // garbage collection since we don't want to allow a global GC at the | 2126 // garbage collection since we don't want to allow a global GC at the |
2111 // same time as a thread local GC. | 2127 // same time as a thread local GC. |
2112 | 2128 |
2113 { | 2129 { |
2114 NoAllocationScope<AnyThread> noAllocationScope; | 2130 NoAllocationScope<AnyThread> noAllocationScope; |
2115 | 2131 |
2116 state->enterGC(); | 2132 state->enterGC(); |
2117 state->prepareForGC(); | 2133 state->prepareForGC(); |
2118 | 2134 |
2119 traceRootsAndPerformGlobalWeakProcessing<ThreadLocalMarking>(); | 2135 // 1. trace the thread local persistent roots. For thread local GCs we |
| 2136 // don't trace the stack (ie. no conservative scanning) since this is |
| 2137 // only called during thread shutdown where there should be no objects |
| 2138 // on the stack. |
| 2139 // We also assume that orphaned pages have no objects reachable from |
| 2140 // persistent handles on other threads or CrossThreadPersistents. The |
| 2141 // only cases where this could happen is if a subsequent conservative |
| 2142 // global GC finds a "pointer" on the stack or due to a programming |
| 2143 // error where an object has a dangling cross-thread pointer to an |
| 2144 // object on this heap. |
| 2145 state->visitPersistents(s_markingVisitor); |
| 2146 |
| 2147 // 2. trace objects reachable from the thread's persistent roots |
| 2148 // including ephemerons. |
| 2149 processMarkingStack<ThreadLocalMarking>(); |
| 2150 |
| 2151 globalWeakProcessingAndCleanup(); |
2120 | 2152 |
2121 state->leaveGC(); | 2153 state->leaveGC(); |
2122 } | 2154 } |
2123 state->performPendingSweep(); | 2155 state->performPendingSweep(); |
2124 } | 2156 } |
2125 | 2157 |
2126 template<CallbackInvocationMode Mode> | 2158 template<CallbackInvocationMode Mode> |
2127 void Heap::traceRootsAndPerformGlobalWeakProcessing() | 2159 void Heap::processMarkingStack() |
2128 { | 2160 { |
2129 if (Mode == ThreadLocalMarking) | |
2130 ThreadState::current()->visitLocalRoots(s_markingVisitor); | |
2131 else | |
2132 ThreadState::visitRoots(s_markingVisitor); | |
2133 | |
2134 // Ephemeron fixed point loop. | 2161 // Ephemeron fixed point loop. |
2135 do { | 2162 do { |
2136 // Recursively mark all objects that are reachable from the roots for | 2163 // Iteratively mark all objects that are reachable from the objects |
2137 // this thread. If Mode is ThreadLocalMarking don't continue tracing if | 2164 // currently pushed onto the marking stack. If Mode is ThreadLocalMarkin
g |
2138 // the trace hits an object on another thread's heap. | 2165 // don't continue tracing if the trace hits an object on another thread'
s |
| 2166 // heap. |
2139 while (popAndInvokeTraceCallback<Mode>(s_markingVisitor)) { } | 2167 while (popAndInvokeTraceCallback<Mode>(s_markingVisitor)) { } |
2140 | 2168 |
2141 // Mark any strong pointers that have now become reachable in ephemeron | 2169 // Mark any strong pointers that have now become reachable in ephemeron |
2142 // maps. | 2170 // maps. |
2143 CallbackStack::invokeCallbacks(&s_ephemeronStack, s_markingVisitor); | 2171 CallbackStack::invokeCallbacks(&s_ephemeronStack, s_markingVisitor); |
2144 | 2172 |
2145 // Rerun loop if ephemeron processing queued more objects for tracing. | 2173 // Rerun loop if ephemeron processing queued more objects for tracing. |
2146 } while (!s_markingStack->isEmpty()); | 2174 } while (!s_markingStack->isEmpty()); |
| 2175 } |
2147 | 2176 |
| 2177 void Heap::globalWeakProcessingAndCleanup() |
| 2178 { |
2148 // Call weak callbacks on objects that may now be pointing to dead | 2179 // Call weak callbacks on objects that may now be pointing to dead |
2149 // objects and call ephemeronIterationDone callbacks on weak tables | 2180 // objects and call ephemeronIterationDone callbacks on weak tables |
2150 // to do cleanup (specifically clear the queued bits for weak hash | 2181 // to do cleanup (specifically clear the queued bits for weak hash |
2151 // tables). | 2182 // tables). |
2152 while (popAndInvokeWeakPointerCallback(s_markingVisitor)) { } | 2183 while (popAndInvokeWeakPointerCallback(s_markingVisitor)) { } |
2153 | 2184 |
2154 CallbackStack::clear(&s_ephemeronStack); | 2185 CallbackStack::clear(&s_ephemeronStack); |
2155 | 2186 |
2156 // It is not permitted to trace pointers of live objects in the weak | 2187 // It is not permitted to trace pointers of live objects in the weak |
2157 // callback phase, so the marking stack should still be empty here. | 2188 // callback phase, so the marking stack should still be empty here. |
(...skipping 84 matching lines...) Loading... |
2242 Visitor* Heap::s_markingVisitor; | 2273 Visitor* Heap::s_markingVisitor; |
2243 CallbackStack* Heap::s_markingStack; | 2274 CallbackStack* Heap::s_markingStack; |
2244 CallbackStack* Heap::s_weakCallbackStack; | 2275 CallbackStack* Heap::s_weakCallbackStack; |
2245 CallbackStack* Heap::s_ephemeronStack; | 2276 CallbackStack* Heap::s_ephemeronStack; |
2246 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; | 2277 HeapDoesNotContainCache* Heap::s_heapDoesNotContainCache; |
2247 bool Heap::s_shutdownCalled = false; | 2278 bool Heap::s_shutdownCalled = false; |
2248 bool Heap::s_lastGCWasConservative = false; | 2279 bool Heap::s_lastGCWasConservative = false; |
2249 FreePagePool* Heap::s_freePagePool; | 2280 FreePagePool* Heap::s_freePagePool; |
2250 OrphanedPagePool* Heap::s_orphanedPagePool; | 2281 OrphanedPagePool* Heap::s_orphanedPagePool; |
2251 } | 2282 } |
OLD | NEW |