OLD | NEW |
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 13 matching lines...) Expand all Loading... |
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 <cmath> | 31 #include <cmath> |
32 | 32 |
33 #include "allocation.h" | 33 #include "allocation.h" |
| 34 #include "assert-scope.h" |
34 #include "globals.h" | 35 #include "globals.h" |
35 #include "incremental-marking.h" | 36 #include "incremental-marking.h" |
36 #include "list.h" | 37 #include "list.h" |
37 #include "mark-compact.h" | 38 #include "mark-compact.h" |
38 #include "objects-visiting.h" | 39 #include "objects-visiting.h" |
39 #include "spaces.h" | 40 #include "spaces.h" |
40 #include "splay-tree-inl.h" | 41 #include "splay-tree-inl.h" |
41 #include "store-buffer.h" | 42 #include "store-buffer.h" |
42 #include "v8-counters.h" | 43 #include "v8-counters.h" |
43 #include "v8globals.h" | 44 #include "v8globals.h" |
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 | 1490 |
1490 // Given an address occupied by a live code object, return that object. | 1491 // Given an address occupied by a live code object, return that object. |
1491 Object* FindCodeObject(Address a); | 1492 Object* FindCodeObject(Address a); |
1492 | 1493 |
1493 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; | 1494 enum HeapState { NOT_IN_GC, SCAVENGE, MARK_COMPACT }; |
1494 inline HeapState gc_state() { return gc_state_; } | 1495 inline HeapState gc_state() { return gc_state_; } |
1495 | 1496 |
1496 inline bool IsInGCPostProcessing() { return gc_post_processing_depth_ > 0; } | 1497 inline bool IsInGCPostProcessing() { return gc_post_processing_depth_ > 0; } |
1497 | 1498 |
1498 #ifdef DEBUG | 1499 #ifdef DEBUG |
1499 bool IsAllocationAllowed() { return allocation_allowed_; } | |
1500 inline void set_allow_allocation(bool allocation_allowed); | |
1501 inline bool allow_allocation(bool enable); | |
1502 | |
1503 bool disallow_allocation_failure() { | 1500 bool disallow_allocation_failure() { |
1504 return disallow_allocation_failure_; | 1501 return disallow_allocation_failure_; |
1505 } | 1502 } |
1506 | 1503 |
1507 void TracePathToObjectFrom(Object* target, Object* root); | 1504 void TracePathToObjectFrom(Object* target, Object* root); |
1508 void TracePathToObject(Object* target); | 1505 void TracePathToObject(Object* target); |
1509 void TracePathToGlobal(); | 1506 void TracePathToGlobal(); |
1510 #endif | 1507 #endif |
1511 | 1508 |
1512 // Callback function passed to Heap::Iterate etc. Copies an object if | 1509 // Callback function passed to Heap::Iterate etc. Copies an object if |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1972 inline void set_##name(type* value) { \ | 1969 inline void set_##name(type* value) { \ |
1973 /* The deserializer makes use of the fact that these common roots are */ \ | 1970 /* The deserializer makes use of the fact that these common roots are */ \ |
1974 /* never in new space and never on a page that is being compacted. */ \ | 1971 /* never in new space and never on a page that is being compacted. */ \ |
1975 ASSERT(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \ | 1972 ASSERT(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \ |
1976 roots_[k##camel_name##RootIndex] = value; \ | 1973 roots_[k##camel_name##RootIndex] = value; \ |
1977 } | 1974 } |
1978 ROOT_LIST(ROOT_ACCESSOR) | 1975 ROOT_LIST(ROOT_ACCESSOR) |
1979 #undef ROOT_ACCESSOR | 1976 #undef ROOT_ACCESSOR |
1980 | 1977 |
1981 #ifdef DEBUG | 1978 #ifdef DEBUG |
1982 bool allocation_allowed_; | |
1983 | |
1984 // If the --gc-interval flag is set to a positive value, this | 1979 // If the --gc-interval flag is set to a positive value, this |
1985 // variable holds the value indicating the number of allocations | 1980 // variable holds the value indicating the number of allocations |
1986 // remain until the next failure and garbage collection. | 1981 // remain until the next failure and garbage collection. |
1987 int allocation_timeout_; | 1982 int allocation_timeout_; |
1988 | 1983 |
1989 // Do we expect to be able to handle allocation failure at this | 1984 // Do we expect to be able to handle allocation failure at this |
1990 // time? | 1985 // time? |
1991 bool disallow_allocation_failure_; | 1986 bool disallow_allocation_failure_; |
1992 #endif // DEBUG | 1987 #endif // DEBUG |
1993 | 1988 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2690 }; | 2685 }; |
2691 | 2686 |
2692 Key keys_[kLength]; | 2687 Key keys_[kLength]; |
2693 int results_[kLength]; | 2688 int results_[kLength]; |
2694 | 2689 |
2695 friend class Isolate; | 2690 friend class Isolate; |
2696 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); | 2691 DISALLOW_COPY_AND_ASSIGN(DescriptorLookupCache); |
2697 }; | 2692 }; |
2698 | 2693 |
2699 | 2694 |
2700 // A helper class to document/test C++ scopes where we do not | |
2701 // expect a GC. Usage: | |
2702 // | |
2703 // /* Allocation not allowed: we cannot handle a GC in this scope. */ | |
2704 // { AssertNoAllocation nogc; | |
2705 // ... | |
2706 // } | |
2707 | |
2708 #ifdef DEBUG | |
2709 inline bool EnterAllocationScope(Isolate* isolate, bool allow_allocation); | |
2710 inline void ExitAllocationScope(Isolate* isolate, bool last_state); | |
2711 #endif | |
2712 | |
2713 | |
2714 class AssertNoAllocation { | |
2715 public: | |
2716 inline AssertNoAllocation(); | |
2717 inline ~AssertNoAllocation(); | |
2718 | |
2719 #ifdef DEBUG | |
2720 private: | |
2721 bool last_state_; | |
2722 #endif | |
2723 }; | |
2724 | |
2725 | |
2726 class DisableAssertNoAllocation { | |
2727 public: | |
2728 inline DisableAssertNoAllocation(); | |
2729 inline ~DisableAssertNoAllocation(); | |
2730 | |
2731 #ifdef DEBUG | |
2732 private: | |
2733 bool last_state_; | |
2734 #endif | |
2735 }; | |
2736 | |
2737 // GCTracer collects and prints ONE line after each garbage collector | 2695 // GCTracer collects and prints ONE line after each garbage collector |
2738 // invocation IFF --trace_gc is used. | 2696 // invocation IFF --trace_gc is used. |
2739 | 2697 |
2740 class GCTracer BASE_EMBEDDED { | 2698 class GCTracer BASE_EMBEDDED { |
2741 public: | 2699 public: |
2742 class Scope BASE_EMBEDDED { | 2700 class Scope BASE_EMBEDDED { |
2743 public: | 2701 public: |
2744 enum ScopeId { | 2702 enum ScopeId { |
2745 EXTERNAL, | 2703 EXTERNAL, |
2746 MC_MARK, | 2704 MC_MARK, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3041 // done for all matches. | 2999 // done for all matches. |
3042 PathTracer(Object* search_target, | 3000 PathTracer(Object* search_target, |
3043 WhatToFind what_to_find, | 3001 WhatToFind what_to_find, |
3044 VisitMode visit_mode) | 3002 VisitMode visit_mode) |
3045 : search_target_(search_target), | 3003 : search_target_(search_target), |
3046 found_target_(false), | 3004 found_target_(false), |
3047 found_target_in_trace_(false), | 3005 found_target_in_trace_(false), |
3048 what_to_find_(what_to_find), | 3006 what_to_find_(what_to_find), |
3049 visit_mode_(visit_mode), | 3007 visit_mode_(visit_mode), |
3050 object_stack_(20), | 3008 object_stack_(20), |
3051 no_alloc() {} | 3009 no_allocation() {} |
3052 | 3010 |
3053 virtual void VisitPointers(Object** start, Object** end); | 3011 virtual void VisitPointers(Object** start, Object** end); |
3054 | 3012 |
3055 void Reset(); | 3013 void Reset(); |
3056 void TracePathFrom(Object** root); | 3014 void TracePathFrom(Object** root); |
3057 | 3015 |
3058 bool found() const { return found_target_; } | 3016 bool found() const { return found_target_; } |
3059 | 3017 |
3060 static Object* const kAnyGlobalObject; | 3018 static Object* const kAnyGlobalObject; |
3061 | 3019 |
3062 protected: | 3020 protected: |
3063 class MarkVisitor; | 3021 class MarkVisitor; |
3064 class UnmarkVisitor; | 3022 class UnmarkVisitor; |
3065 | 3023 |
3066 void MarkRecursively(Object** p, MarkVisitor* mark_visitor); | 3024 void MarkRecursively(Object** p, MarkVisitor* mark_visitor); |
3067 void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor); | 3025 void UnmarkRecursively(Object** p, UnmarkVisitor* unmark_visitor); |
3068 virtual void ProcessResults(); | 3026 virtual void ProcessResults(); |
3069 | 3027 |
3070 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. | 3028 // Tags 0, 1, and 3 are used. Use 2 for marking visited HeapObject. |
3071 static const int kMarkTag = 2; | 3029 static const int kMarkTag = 2; |
3072 | 3030 |
3073 Object* search_target_; | 3031 Object* search_target_; |
3074 bool found_target_; | 3032 bool found_target_; |
3075 bool found_target_in_trace_; | 3033 bool found_target_in_trace_; |
3076 WhatToFind what_to_find_; | 3034 WhatToFind what_to_find_; |
3077 VisitMode visit_mode_; | 3035 VisitMode visit_mode_; |
3078 List<Object*> object_stack_; | 3036 List<Object*> object_stack_; |
3079 | 3037 |
3080 AssertNoAllocation no_alloc; // i.e. no gc allowed. | 3038 DisallowHeapAllocation no_allocation; // i.e. no gc allowed. |
3081 | 3039 |
3082 private: | 3040 private: |
3083 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); | 3041 DISALLOW_IMPLICIT_CONSTRUCTORS(PathTracer); |
3084 }; | 3042 }; |
3085 #endif // DEBUG | 3043 #endif // DEBUG |
3086 | 3044 |
3087 } } // namespace v8::internal | 3045 } } // namespace v8::internal |
3088 | 3046 |
3089 #endif // V8_HEAP_H_ | 3047 #endif // V8_HEAP_H_ |
OLD | NEW |