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

Side by Side Diff: src/heap.h

Issue 9121033: Break a circular include dependency. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Incorporated reviewer comments. Created 8 years, 11 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 | « no previous file | src/heap-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 27 matching lines...) Expand all
38 #include "objects-visiting.h" 38 #include "objects-visiting.h"
39 #include "spaces.h" 39 #include "spaces.h"
40 #include "splay-tree-inl.h" 40 #include "splay-tree-inl.h"
41 #include "store-buffer.h" 41 #include "store-buffer.h"
42 #include "v8-counters.h" 42 #include "v8-counters.h"
43 #include "v8globals.h" 43 #include "v8globals.h"
44 44
45 namespace v8 { 45 namespace v8 {
46 namespace internal { 46 namespace internal {
47 47
48 // TODO(isolates): remove HEAP here
49 #define HEAP (_inline_get_heap_())
50 class Heap;
51 inline Heap* _inline_get_heap_();
52
53
54 // Defines all the roots in Heap. 48 // Defines all the roots in Heap.
55 #define STRONG_ROOT_LIST(V) \ 49 #define STRONG_ROOT_LIST(V) \
56 V(Map, byte_array_map, ByteArrayMap) \ 50 V(Map, byte_array_map, ByteArrayMap) \
57 V(Map, free_space_map, FreeSpaceMap) \ 51 V(Map, free_space_map, FreeSpaceMap) \
58 V(Map, one_pointer_filler_map, OnePointerFillerMap) \ 52 V(Map, one_pointer_filler_map, OnePointerFillerMap) \
59 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ 53 V(Map, two_pointer_filler_map, TwoPointerFillerMap) \
60 /* Cluster the most popular ones in a few cache lines here at the top. */ \ 54 /* Cluster the most popular ones in a few cache lines here at the top. */ \
61 V(Smi, store_buffer_top, StoreBufferTop) \ 55 V(Smi, store_buffer_top, StoreBufferTop) \
62 V(Oddball, undefined_value, UndefinedValue) \ 56 V(Oddball, undefined_value, UndefinedValue) \
63 V(Oddball, the_hole_value, TheHoleValue) \ 57 V(Oddball, the_hole_value, TheHoleValue) \
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 intptr_t* memory_allocator_capacity; // 20 1982 intptr_t* memory_allocator_capacity; // 20
1989 int* objects_per_type; // 21 1983 int* objects_per_type; // 21
1990 int* size_per_type; // 22 1984 int* size_per_type; // 22
1991 int* os_error; // 23 1985 int* os_error; // 23
1992 int* end_marker; // 24 1986 int* end_marker; // 24
1993 }; 1987 };
1994 1988
1995 1989
1996 class AlwaysAllocateScope { 1990 class AlwaysAllocateScope {
1997 public: 1991 public:
1998 AlwaysAllocateScope() { 1992 inline AlwaysAllocateScope();
1999 // We shouldn't hit any nested scopes, because that requires 1993 inline ~AlwaysAllocateScope();
2000 // non-handle code to call handle code. The code still works but
2001 // performance will degrade, so we want to catch this situation
2002 // in debug mode.
2003 ASSERT(HEAP->always_allocate_scope_depth_ == 0);
2004 HEAP->always_allocate_scope_depth_++;
2005 }
2006
2007 ~AlwaysAllocateScope() {
2008 HEAP->always_allocate_scope_depth_--;
2009 ASSERT(HEAP->always_allocate_scope_depth_ == 0);
2010 }
2011 }; 1994 };
2012 1995
2013 1996
2014 class LinearAllocationScope { 1997 class LinearAllocationScope {
2015 public: 1998 public:
2016 LinearAllocationScope() { 1999 inline LinearAllocationScope();
2017 HEAP->linear_allocation_scope_depth_++; 2000 inline ~LinearAllocationScope();
2018 }
2019
2020 ~LinearAllocationScope() {
2021 HEAP->linear_allocation_scope_depth_--;
2022 ASSERT(HEAP->linear_allocation_scope_depth_ >= 0);
2023 }
2024 }; 2001 };
2025 2002
2026 2003
2027 #ifdef DEBUG 2004 #ifdef DEBUG
2028 // Visitor class to verify interior pointers in spaces that do not contain 2005 // Visitor class to verify interior pointers in spaces that do not contain
2029 // or care about intergenerational references. All heap object pointers have to 2006 // or care about intergenerational references. All heap object pointers have to
2030 // point into the heap to a location that has a map pointer at its first word. 2007 // point into the heap to a location that has a map pointer at its first word.
2031 // Caveat: Heap::Contains is an approximation because it can return true for 2008 // Caveat: Heap::Contains is an approximation because it can return true for
2032 // objects in a heap space but above the allocation pointer. 2009 // objects in a heap space but above the allocation pointer.
2033 class VerifyPointersVisitor: public ObjectVisitor { 2010 class VerifyPointersVisitor: public ObjectVisitor {
2034 public: 2011 public:
2035 void VisitPointers(Object** start, Object** end) { 2012 inline void VisitPointers(Object** start, Object** end);
2036 for (Object** current = start; current < end; current++) {
2037 if ((*current)->IsHeapObject()) {
2038 HeapObject* object = HeapObject::cast(*current);
2039 ASSERT(HEAP->Contains(object));
2040 ASSERT(object->map()->IsMap());
2041 }
2042 }
2043 }
2044 }; 2013 };
2045 #endif 2014 #endif
2046 2015
2047 2016
2048 // Space iterator for iterating over all spaces of the heap. 2017 // Space iterator for iterating over all spaces of the heap.
2049 // Returns each space in turn, and null when it is done. 2018 // Returns each space in turn, and null when it is done.
2050 class AllSpaces BASE_EMBEDDED { 2019 class AllSpaces BASE_EMBEDDED {
2051 public: 2020 public:
2052 Space* next(); 2021 Space* next();
2053 AllSpaces() { counter_ = FIRST_SPACE; } 2022 AllSpaces() { counter_ = FIRST_SPACE; }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2259 }; 2228 };
2260 2229
2261 Key keys_[kLength]; 2230 Key keys_[kLength];
2262 int results_[kLength]; 2231 int results_[kLength];
2263 2232
2264 friend class Isolate; 2233 friend class Isolate;
2265 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); 2234 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache);
2266 }; 2235 };
2267 2236
2268 2237
2238 #ifdef DEBUG
2239 class DisallowAllocationFailure {
2240 public:
2241 inline DisallowAllocationFailure();
2242 inline ~DisallowAllocationFailure();
2243
2244 private:
2245 bool old_state_;
2246 };
2247 #endif
2248
2249
2269 // A helper class to document/test C++ scopes where we do not 2250 // A helper class to document/test C++ scopes where we do not
2270 // expect a GC. Usage: 2251 // expect a GC. Usage:
2271 // 2252 //
2272 // /* Allocation not allowed: we cannot handle a GC in this scope. */ 2253 // /* Allocation not allowed: we cannot handle a GC in this scope. */
2273 // { AssertNoAllocation nogc; 2254 // { AssertNoAllocation nogc;
2274 // ... 2255 // ...
2275 // } 2256 // }
2257 class AssertNoAllocation {
2258 public:
2259 inline AssertNoAllocation();
2260 inline ~AssertNoAllocation();
2276 2261
2277 #ifdef DEBUG 2262 #ifdef DEBUG
2278
2279 class DisallowAllocationFailure {
2280 public:
2281 DisallowAllocationFailure() {
2282 old_state_ = HEAP->disallow_allocation_failure_;
2283 HEAP->disallow_allocation_failure_ = true;
2284 }
2285 ~DisallowAllocationFailure() {
2286 HEAP->disallow_allocation_failure_ = old_state_;
2287 }
2288 private: 2263 private:
2289 bool old_state_; 2264 bool old_state_;
2265 #endif
2290 }; 2266 };
2291 2267
2292 class AssertNoAllocation {
2293 public:
2294 AssertNoAllocation() {
2295 old_state_ = HEAP->allow_allocation(false);
2296 }
2297
2298 ~AssertNoAllocation() {
2299 HEAP->allow_allocation(old_state_);
2300 }
2301
2302 private:
2303 bool old_state_;
2304 };
2305 2268
2306 class DisableAssertNoAllocation { 2269 class DisableAssertNoAllocation {
2307 public: 2270 public:
2308 DisableAssertNoAllocation() { 2271 inline DisableAssertNoAllocation();
2309 old_state_ = HEAP->allow_allocation(true); 2272 inline ~DisableAssertNoAllocation();
2310 }
2311 2273
2312 ~DisableAssertNoAllocation() { 2274 #ifdef DEBUG
2313 HEAP->allow_allocation(old_state_);
2314 }
2315
2316 private: 2275 private:
2317 bool old_state_; 2276 bool old_state_;
2277 #endif
2318 }; 2278 };
2319 2279
2320 #else // ndef DEBUG
2321
2322 class AssertNoAllocation {
2323 public:
2324 AssertNoAllocation() { }
2325 ~AssertNoAllocation() { }
2326 };
2327
2328 class DisableAssertNoAllocation {
2329 public:
2330 DisableAssertNoAllocation() { }
2331 ~DisableAssertNoAllocation() { }
2332 };
2333
2334 #endif
2335
2336 // GCTracer collects and prints ONE line after each garbage collector 2280 // GCTracer collects and prints ONE line after each garbage collector
2337 // invocation IFF --trace_gc is used. 2281 // invocation IFF --trace_gc is used.
2338 2282
2339 class GCTracer BASE_EMBEDDED { 2283 class GCTracer BASE_EMBEDDED {
2340 public: 2284 public:
2341 class Scope BASE_EMBEDDED { 2285 class Scope BASE_EMBEDDED {
2342 public: 2286 public:
2343 enum ScopeId { 2287 enum ScopeId {
2344 EXTERNAL, 2288 EXTERNAL,
2345 MC_MARK, 2289 MC_MARK,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 2331
2388 void increment_promoted_objects_size(int object_size) { 2332 void increment_promoted_objects_size(int object_size) {
2389 promoted_objects_size_ += object_size; 2333 promoted_objects_size_ += object_size;
2390 } 2334 }
2391 2335
2392 private: 2336 private:
2393 // Returns a string matching the collector. 2337 // Returns a string matching the collector.
2394 const char* CollectorString(); 2338 const char* CollectorString();
2395 2339
2396 // Returns size of object in heap (in MB). 2340 // Returns size of object in heap (in MB).
2397 double SizeOfHeapObjects() { 2341 inline double SizeOfHeapObjects();
2398 return (static_cast<double>(HEAP->SizeOfObjects())) / MB;
2399 }
2400 2342
2401 double start_time_; // Timestamp set in the constructor. 2343 double start_time_; // Timestamp set in the constructor.
2402 intptr_t start_size_; // Size of objects in heap set in constructor. 2344 intptr_t start_size_; // Size of objects in heap set in constructor.
2403 GarbageCollector collector_; // Type of collector. 2345 GarbageCollector collector_; // Type of collector.
2404 2346
2405 // A count (including this one, e.g. the first collection is 1) of the 2347 // A count (including this one, e.g. the first collection is 1) of the
2406 // number of garbage collections. 2348 // number of garbage collections.
2407 unsigned int gc_count_; 2349 unsigned int gc_count_;
2408 2350
2409 // A count (including this one) of the number of full garbage collections. 2351 // A count (including this one) of the number of full garbage collections.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2639 2581
2640 AssertNoAllocation no_alloc; // i.e. no gc allowed. 2582 AssertNoAllocation no_alloc; // i.e. no gc allowed.
2641 2583
2642 private: 2584 private:
2643 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); 2585 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer);
2644 }; 2586 };
2645 #endif // DEBUG || LIVE_OBJECT_LIST 2587 #endif // DEBUG || LIVE_OBJECT_LIST
2646 2588
2647 } } // namespace v8::internal 2589 } } // namespace v8::internal
2648 2590
2649 #undef HEAP
2650
2651 #endif // V8_HEAP_H_ 2591 #endif // V8_HEAP_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698