Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_HEAP_H_ | 28 #ifndef V8_HEAP_H_ |
| 29 #define V8_HEAP_H_ | 29 #define V8_HEAP_H_ |
| 30 | 30 |
| 31 #include <math.h> | 31 #include <math.h> |
| 32 | 32 |
| 33 #include "list.h" | |
| 33 #include "spaces.h" | 34 #include "spaces.h" |
| 34 #include "splay-tree-inl.h" | 35 #include "splay-tree-inl.h" |
| 35 #include "v8-counters.h" | 36 #include "v8-counters.h" |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| 38 namespace internal { | 39 namespace internal { |
| 39 | 40 |
| 40 | 41 |
| 41 // Defines all the roots in Heap. | 42 // Defines all the roots in Heap. |
| 42 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ | 43 #define UNCONDITIONAL_STRONG_ROOT_LIST(V) \ |
| (...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 public: | 2146 public: |
| 2146 virtual ~WeakObjectRetainer() {} | 2147 virtual ~WeakObjectRetainer() {} |
| 2147 | 2148 |
| 2148 // Return whether this object should be retained. If NULL is returned the | 2149 // Return whether this object should be retained. If NULL is returned the |
| 2149 // object has no references. Otherwise the address of the retained object | 2150 // object has no references. Otherwise the address of the retained object |
| 2150 // should be returned as in some GC situations the object has been moved. | 2151 // should be returned as in some GC situations the object has been moved. |
| 2151 virtual Object* RetainAs(Object* object) = 0; | 2152 virtual Object* RetainAs(Object* object) = 0; |
| 2152 }; | 2153 }; |
| 2153 | 2154 |
| 2154 | 2155 |
| 2156 #if defined(DEBUG) || defined(LIVE_OBJECT_LIST) | |
| 2157 // Helper class for tracing paths to a search target Object from all roots. | |
| 2158 // The TracePathFrom() method can be used to trace paths from a specific | |
| 2159 // object to the search target object. | |
| 2160 // | |
| 2161 // The "what_to_find" can be kFindFirst or kFindAll. If kFindFirst is | |
| 2162 // specified, tracing will stop after the first match. If kFindAll is | |
| 2163 // specified, then tracing will be done for all matches. | |
| 2164 class PathTracer: public ObjectVisitor { | |
|
marklam
2011/02/20 00:41:15
PathTracer used to be called MarkRootVisitor in he
| |
| 2165 public: | |
| 2166 PathTracer(Object* search_target, | |
| 2167 bool search_for_any_global, | |
| 2168 int what_to_find, | |
| 2169 bool skip_weak_refs) | |
| 2170 : search_target_(search_target), | |
| 2171 search_for_any_global_(search_for_any_global), | |
| 2172 found_target_(false), | |
| 2173 what_to_find_(what_to_find), | |
| 2174 skip_weak_refs_(skip_weak_refs), | |
| 2175 object_stack_(20), | |
| 2176 mark_visitor(this), | |
| 2177 unmark_visitor(this) {} | |
| 2178 | |
| 2179 void VisitPointers(Object** start, Object** end) { | |
| 2180 bool done = false; | |
| 2181 // Visit all HeapObject pointers in [start, end) | |
| 2182 for (Object** p = start; !done && (p < end); p++) { | |
| 2183 if ((*p)->IsHeapObject()) { | |
| 2184 TracePathFrom(p); | |
| 2185 done = ((what_to_find_ == kFindFirst) && found_target_); | |
|
marklam
2011/02/20 00:41:15
I added an optimization to bail here if we've alre
| |
| 2186 } | |
| 2187 } | |
| 2188 } | |
| 2189 | |
| 2190 void TracePathFrom(Object** root); | |
|
marklam
2011/02/20 00:41:15
TracePathFrom() used to be called MarkRootObjectRe
| |
| 2191 | |
| 2192 bool found() const { return found_target_; } | |
| 2193 | |
| 2194 // Values for the "what_to_find" argument of the constructor. | |
| 2195 static const int kFindFirst = 1; // Will stop the search after first match. | |
| 2196 static const int kFindAll = 0; // Will find all matches. | |
| 2197 | |
| 2198 protected: | |
| 2199 class MarkVisitor: public ObjectVisitor { | |
|
marklam
2011/02/20 00:41:15
MarkVisitor used to be called MarkObjectVisitor in
| |
| 2200 public: | |
| 2201 explicit MarkVisitor(PathTracer* tracer) : tracer_(tracer) {} | |
| 2202 void VisitPointers(Object** start, Object** end) { | |
| 2203 // Scan all HeapObject pointers in [start, end) | |
| 2204 for (Object** p = start; !tracer_->found() && (p < end); p++) { | |
|
marklam
2011/02/20 00:41:15
The check for !tracer->found() is an optimization
| |
| 2205 if ((*p)->IsHeapObject()) | |
| 2206 tracer_->MarkRecursively(p); | |
| 2207 } | |
| 2208 } | |
| 2209 | |
| 2210 private: | |
| 2211 PathTracer* tracer_; | |
| 2212 }; | |
| 2213 | |
| 2214 | |
| 2215 class UnmarkVisitor: public ObjectVisitor { | |
|
marklam
2011/02/20 00:41:15
UnmarkVisitor used to be called UnmarkObjectVisito
| |
| 2216 public: | |
| 2217 explicit UnmarkVisitor(PathTracer* tracer) : tracer_(tracer) {} | |
| 2218 void VisitPointers(Object** start, Object** end) { | |
| 2219 // Scan all HeapObject pointers in [start, end) | |
| 2220 for (Object** p = start; p < end; p++) { | |
| 2221 if ((*p)->IsHeapObject()) | |
| 2222 tracer_->UnmarkRecursively(p); | |
| 2223 } | |
| 2224 } | |
| 2225 | |
| 2226 private: | |
| 2227 PathTracer* tracer_; | |
| 2228 }; | |
| 2229 | |
| 2230 PathTracer(); | |
| 2231 | |
| 2232 void MarkRecursively(Object** p); | |
|
marklam
2011/02/20 00:41:15
MarkRecursively() used to be called MarkObjectRecu
| |
| 2233 void UnmarkRecursively(Object** p); | |
|
marklam
2011/02/20 00:41:15
UnmarkRecursively() used to be called UnmarkObject
| |
| 2234 virtual void ProcessResults(); | |
| 2235 | |
| 2236 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. | |
| 2237 static const int kMarkTag = 2; | |
| 2238 | |
| 2239 Object* search_target_; | |
| 2240 bool search_for_any_global_; | |
| 2241 bool found_target_; | |
| 2242 bool what_to_find_; | |
| 2243 bool skip_weak_refs_; | |
| 2244 List<Object*> object_stack_; | |
|
marklam
2011/02/20 00:41:15
search_target_, search_for_any_global_, found_targ
| |
| 2245 | |
| 2246 MarkVisitor mark_visitor; | |
| 2247 UnmarkVisitor unmark_visitor; | |
|
marklam
2011/02/20 00:41:15
There used to be global static instances of these
| |
| 2248 }; | |
| 2249 #endif // DEBUG || LIVE_OBJECT_LIST | |
| 2250 | |
| 2251 | |
| 2155 } } // namespace v8::internal | 2252 } } // namespace v8::internal |
| 2156 | 2253 |
| 2157 #endif // V8_HEAP_H_ | 2254 #endif // V8_HEAP_H_ |
| OLD | NEW |