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