26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP |
27 |
27 |
28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp" |
28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp" |
29 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" |
29 #include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp" |
30 #include "gc_implementation/parallelScavenge/psOldGen.hpp" |
30 #include "gc_implementation/parallelScavenge/psOldGen.hpp" |
31 #include "gc_implementation/parallelScavenge/psPermGen.hpp" |
|
32 #include "gc_implementation/parallelScavenge/psYoungGen.hpp" |
31 #include "gc_implementation/parallelScavenge/psYoungGen.hpp" |
33 #include "gc_implementation/shared/gcPolicyCounters.hpp" |
32 #include "gc_implementation/shared/gcPolicyCounters.hpp" |
34 #include "gc_interface/collectedHeap.inline.hpp" |
33 #include "gc_interface/collectedHeap.inline.hpp" |
35 #include "utilities/ostream.hpp" |
34 #include "utilities/ostream.hpp" |
36 |
35 |
43 class ParallelScavengeHeap : public CollectedHeap { |
42 class ParallelScavengeHeap : public CollectedHeap { |
44 friend class VMStructs; |
43 friend class VMStructs; |
45 private: |
44 private: |
46 static PSYoungGen* _young_gen; |
45 static PSYoungGen* _young_gen; |
47 static PSOldGen* _old_gen; |
46 static PSOldGen* _old_gen; |
48 static PSPermGen* _perm_gen; |
|
49 |
47 |
50 // Sizing policy for entire heap |
48 // Sizing policy for entire heap |
51 static PSAdaptiveSizePolicy* _size_policy; |
49 static PSAdaptiveSizePolicy* _size_policy; |
52 static PSGCAdaptivePolicyCounters* _gc_policy_counters; |
50 static PSGCAdaptivePolicyCounters* _gc_policy_counters; |
53 |
51 |
54 static ParallelScavengeHeap* _psh; |
52 static ParallelScavengeHeap* _psh; |
55 |
53 |
56 size_t _perm_gen_alignment; |
|
57 size_t _young_gen_alignment; |
54 size_t _young_gen_alignment; |
58 size_t _old_gen_alignment; |
55 size_t _old_gen_alignment; |
59 |
56 |
60 GenerationSizer* _collector_policy; |
57 GenerationSizer* _collector_policy; |
61 |
58 |
77 HeapWord* mem_allocate_old_gen(size_t size); |
74 HeapWord* mem_allocate_old_gen(size_t size); |
78 |
75 |
79 public: |
76 public: |
80 ParallelScavengeHeap() : CollectedHeap() { |
77 ParallelScavengeHeap() : CollectedHeap() { |
81 _death_march_count = 0; |
78 _death_march_count = 0; |
82 set_alignment(_perm_gen_alignment, intra_heap_alignment()); |
|
83 set_alignment(_young_gen_alignment, intra_heap_alignment()); |
79 set_alignment(_young_gen_alignment, intra_heap_alignment()); |
84 set_alignment(_old_gen_alignment, intra_heap_alignment()); |
80 set_alignment(_old_gen_alignment, intra_heap_alignment()); |
85 } |
81 } |
86 |
82 |
87 // For use by VM operations |
83 // For use by VM operations |
92 |
88 |
93 ParallelScavengeHeap::Name kind() const { |
89 ParallelScavengeHeap::Name kind() const { |
94 return CollectedHeap::ParallelScavengeHeap; |
90 return CollectedHeap::ParallelScavengeHeap; |
95 } |
91 } |
96 |
92 |
97 CollectorPolicy* collector_policy() const { return (CollectorPolicy*) _collector_policy; } |
93 virtual CollectorPolicy* collector_policy() const { return (CollectorPolicy*) _collector_policy; } |
98 // GenerationSizer* collector_policy() const { return _collector_policy; } |
|
99 |
94 |
100 static PSYoungGen* young_gen() { return _young_gen; } |
95 static PSYoungGen* young_gen() { return _young_gen; } |
101 static PSOldGen* old_gen() { return _old_gen; } |
96 static PSOldGen* old_gen() { return _old_gen; } |
102 static PSPermGen* perm_gen() { return _perm_gen; } |
|
103 |
97 |
104 virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; } |
98 virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; } |
105 |
99 |
106 static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; } |
100 static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; } |
107 |
101 |
115 virtual jint initialize(); |
109 virtual jint initialize(); |
116 |
110 |
117 void post_initialize(); |
111 void post_initialize(); |
118 void update_counters(); |
112 void update_counters(); |
119 // The alignment used for the various generations. |
113 // The alignment used for the various generations. |
120 size_t perm_gen_alignment() const { return _perm_gen_alignment; } |
|
121 size_t young_gen_alignment() const { return _young_gen_alignment; } |
114 size_t young_gen_alignment() const { return _young_gen_alignment; } |
122 size_t old_gen_alignment() const { return _old_gen_alignment; } |
115 size_t old_gen_alignment() const { return _old_gen_alignment; } |
123 |
116 |
124 // The alignment used for eden and survivors within the young gen |
117 // The alignment used for eden and survivors within the young gen |
125 // and for boundary between young gen and old gen. |
118 // and for boundary between young gen and old gen. |
126 size_t intra_heap_alignment() const { return 64 * K; } |
119 size_t intra_heap_alignment() const { return 64 * K; } |
127 |
120 |
128 size_t capacity() const; |
121 size_t capacity() const; |
129 size_t used() const; |
122 size_t used() const; |
130 |
123 |
131 // Return "true" if all generations (but perm) have reached the |
124 // Return "true" if all generations have reached the |
132 // maximal committed limit that they can reach, without a garbage |
125 // maximal committed limit that they can reach, without a garbage |
133 // collection. |
126 // collection. |
134 virtual bool is_maximal_no_gc() const; |
127 virtual bool is_maximal_no_gc() const; |
135 |
128 |
136 // Return true if the reference points to an object that |
129 // Return true if the reference points to an object that |
140 virtual bool is_scavengable(const void* addr); |
133 virtual bool is_scavengable(const void* addr); |
141 |
134 |
142 // Does this heap support heap inspection? (+PrintClassHistogram) |
135 // Does this heap support heap inspection? (+PrintClassHistogram) |
143 bool supports_heap_inspection() const { return true; } |
136 bool supports_heap_inspection() const { return true; } |
144 |
137 |
145 size_t permanent_capacity() const; |
|
146 size_t permanent_used() const; |
|
147 |
|
148 size_t max_capacity() const; |
138 size_t max_capacity() const; |
149 |
139 |
150 // Whether p is in the allocated part of the heap |
140 // Whether p is in the allocated part of the heap |
151 bool is_in(const void* p) const; |
141 bool is_in(const void* p) const; |
152 |
142 |
153 bool is_in_reserved(const void* p) const; |
143 bool is_in_reserved(const void* p) const; |
154 bool is_in_permanent(const void *p) const { // reserved part |
|
155 return perm_gen()->reserved().contains(p); |
|
156 } |
|
157 |
144 |
158 #ifdef ASSERT |
145 #ifdef ASSERT |
159 virtual bool is_in_partial_collection(const void *p); |
146 virtual bool is_in_partial_collection(const void *p); |
160 #endif |
147 #endif |
161 |
148 |
162 bool is_permanent(const void *p) const { // committed part |
149 bool is_in_young(oop p); // reserved part |
163 return perm_gen()->is_in(p); |
150 bool is_in_old(oop p); // reserved part |
164 } |
|
165 |
|
166 inline bool is_in_young(oop p); // reserved part |
|
167 inline bool is_in_old_or_perm(oop p); // reserved part |
|
168 |
151 |
169 // Memory allocation. "gc_time_limit_was_exceeded" will |
152 // Memory allocation. "gc_time_limit_was_exceeded" will |
170 // be set to true if the adaptive size policy determine that |
153 // be set to true if the adaptive size policy determine that |
171 // an excessive amount of time is being spent doing collections |
154 // an excessive amount of time is being spent doing collections |
172 // and caused a NULL to be returned. If a NULL is not returned, |
155 // and caused a NULL to be returned. If a NULL is not returned, |
177 // Allocation attempt(s) during a safepoint. It should never be called |
160 // Allocation attempt(s) during a safepoint. It should never be called |
178 // to allocate a new TLAB as this allocation might be satisfied out |
161 // to allocate a new TLAB as this allocation might be satisfied out |
179 // of the old generation. |
162 // of the old generation. |
180 HeapWord* failed_mem_allocate(size_t size); |
163 HeapWord* failed_mem_allocate(size_t size); |
181 |
164 |
182 HeapWord* permanent_mem_allocate(size_t size); |
|
183 HeapWord* failed_permanent_mem_allocate(size_t size); |
|
184 |
|
185 // Support for System.gc() |
165 // Support for System.gc() |
186 void collect(GCCause::Cause cause); |
166 void collect(GCCause::Cause cause); |
187 |
|
188 // This interface assumes that it's being called by the |
|
189 // vm thread. It collects the heap assuming that the |
|
190 // heap lock is already held and that we are executing in |
|
191 // the context of the vm thread. |
|
192 void collect_as_vm_thread(GCCause::Cause cause); |
|
193 |
167 |
194 // These also should be called by the vm thread at a safepoint (e.g., from a |
168 // These also should be called by the vm thread at a safepoint (e.g., from a |
195 // VM operation). |
169 // VM operation). |
196 // |
170 // |
197 // The first collects the young generation only, unless the scavenge fails; it |
171 // The first collects the young generation only, unless the scavenge fails; it |
198 // will then attempt a full gc. The second collects the entire heap; if |
172 // will then attempt a full gc. The second collects the entire heap; if |
199 // maximum_compaction is true, it will compact everything and clear all soft |
173 // maximum_compaction is true, it will compact everything and clear all soft |
200 // references. |
174 // references. |
201 inline void invoke_scavenge(); |
175 inline void invoke_scavenge(); |
202 inline void invoke_full_gc(bool maximum_compaction); |
176 |
|
177 // Perform a full collection |
|
178 virtual void do_full_collection(bool clear_all_soft_refs); |
203 |
179 |
204 bool supports_inline_contig_alloc() const { return !UseNUMA; } |
180 bool supports_inline_contig_alloc() const { return !UseNUMA; } |
205 |
181 |
206 HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; } |
182 HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; } |
207 HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; } |
183 HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; } |
230 |
206 |
231 // Return true if we don't we need a store barrier for |
207 // Return true if we don't we need a store barrier for |
232 // initializing stores to an object at this address. |
208 // initializing stores to an object at this address. |
233 virtual bool can_elide_initializing_store_barrier(oop new_obj); |
209 virtual bool can_elide_initializing_store_barrier(oop new_obj); |
234 |
210 |
235 // Can a compiler elide a store barrier when it writes |
211 void oop_iterate(ExtendedOopClosure* cl); |
236 // a permanent oop into the heap? Applies when the compiler |
|
237 // is storing x to the heap, where x->is_perm() is true. |
|
238 virtual bool can_elide_permanent_oop_store_barriers() const { |
|
239 return true; |
|
240 } |
|
241 |
|
242 void oop_iterate(OopClosure* cl); |
|
243 void object_iterate(ObjectClosure* cl); |
212 void object_iterate(ObjectClosure* cl); |
244 void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); } |
213 void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); } |
245 void permanent_oop_iterate(OopClosure* cl); |
|
246 void permanent_object_iterate(ObjectClosure* cl); |
|
247 |
214 |
248 HeapWord* block_start(const void* addr) const; |
215 HeapWord* block_start(const void* addr) const; |
249 size_t block_size(const HeapWord* addr) const; |
216 size_t block_size(const HeapWord* addr) const; |
250 bool block_is_obj(const HeapWord* addr) const; |
217 bool block_is_obj(const HeapWord* addr) const; |
251 |
218 |