8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_GENCOLLECTEDHEAP_HPP
26 #define SHARE_VM_GC_SHARED_GENCOLLECTEDHEAP_HPP
27
28 #include "gc/shared/adaptiveSizePolicy.hpp"
29 #include "gc/shared/collectedHeap.hpp"
30 #include "gc/shared/collectorPolicy.hpp"
31 #include "gc/shared/generation.hpp"
32 #include "gc/shared/softRefGenPolicy.hpp"
33
34 class StrongRootsScope;
35 class SubTasksDone;
36 class WorkGang;
37
38 // A "GenCollectedHeap" is a CollectedHeap that uses generational
39 // collection. It has two generations, young and old.
40 class GenCollectedHeap : public CollectedHeap {
41 friend class GenCollectorPolicy;
42 friend class Generation;
43 friend class DefNewGeneration;
44 friend class TenuredGeneration;
45 friend class ConcurrentMarkSweepGeneration;
46 friend class CMSCollector;
47 friend class GenMarkSweep;
48 friend class VM_GenCollectForAllocation;
49 friend class VM_GenCollectFull;
50 friend class VM_GenCollectFullConcurrent;
51 friend class VM_GC_HeapInspection;
52 friend class VM_HeapDumper;
53 friend class HeapInspection;
56 public:
57 friend class VM_PopulateDumpSharedSpace;
58
59 enum GenerationType {
60 YoungGen,
61 OldGen
62 };
63
64 private:
65 Generation* _young_gen;
66 Generation* _old_gen;
67
68 // The singleton CardTable Remembered Set.
69 CardTableRS* _rem_set;
70
71 // The generational collector policy.
72 GenCollectorPolicy* _gen_policy;
73
74 SoftRefGenPolicy _soft_ref_gen_policy;
75
76 // Indicates that the most recent previous incremental collection failed.
77 // The flag is cleared when an action is taken that might clear the
78 // condition that caused that incremental collection to fail.
79 bool _incremental_collection_failed;
80
81 // In support of ExplicitGCInvokesConcurrent functionality
82 unsigned int _full_collections_completed;
83
84 // Collects the given generation.
85 void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
86 bool run_verification, bool clear_soft_refs,
87 bool restore_marks_for_biased_locking);
88
89 // Reserve aligned space for the heap as needed by the contained generations.
90 char* allocate(size_t alignment, ReservedSpace* heap_rs);
91
92 // Initialize ("weak") refs processing support
93 void ref_processing_init();
94
95 protected:
138 HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
139
140 // Callback from VM_GenCollectFull operation.
141 // Perform a full collection of the first max_level+1 generations.
142 virtual void do_full_collection(bool clear_all_soft_refs);
143 void do_full_collection(bool clear_all_soft_refs, GenerationType max_generation);
144
145 // Does the "cause" of GC indicate that
146 // we absolutely __must__ clear soft refs?
147 bool must_clear_all_soft_refs();
148
149 GenCollectedHeap(GenCollectorPolicy *policy);
150
151 virtual void check_gen_kinds() = 0;
152
153 public:
154
155 // Returns JNI_OK on success
156 virtual jint initialize();
157
158 // Does operations required after initialization has been done.
159 void post_initialize();
160
161 Generation* young_gen() const { return _young_gen; }
162 Generation* old_gen() const { return _old_gen; }
163
164 bool is_young_gen(const Generation* gen) const { return gen == _young_gen; }
165 bool is_old_gen(const Generation* gen) const { return gen == _old_gen; }
166
167 // The generational collector policy.
168 GenCollectorPolicy* gen_policy() const { return _gen_policy; }
169
170 virtual CollectorPolicy* collector_policy() const { return gen_policy(); }
171
172 virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_gen_policy; }
173
174 // Adaptive size policy
175 virtual AdaptiveSizePolicy* size_policy() {
176 return gen_policy()->size_policy();
177 }
178
179 // Return the (conservative) maximum heap alignment
180 static size_t conservative_max_heap_alignment() {
181 return Generation::GenGrain;
182 }
183
184 size_t capacity() const;
185 size_t used() const;
186
187 // Save the "used_region" for both generations.
188 void save_used_regions();
189
190 size_t max_capacity() const;
191
192 HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
193
194 // We may support a shared contiguous allocation area, if the youngest
195 // generation does.
196 bool supports_inline_contig_alloc() const;
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_GC_SHARED_GENCOLLECTEDHEAP_HPP
26 #define SHARE_VM_GC_SHARED_GENCOLLECTEDHEAP_HPP
27
28 #include "gc/shared/collectedHeap.hpp"
29 #include "gc/shared/collectorPolicy.hpp"
30 #include "gc/shared/generation.hpp"
31 #include "gc/shared/softRefGenPolicy.hpp"
32
33 class AdaptiveSizePolicy;
34 class StrongRootsScope;
35 class SubTasksDone;
36 class WorkGang;
37
38 // A "GenCollectedHeap" is a CollectedHeap that uses generational
39 // collection. It has two generations, young and old.
40 class GenCollectedHeap : public CollectedHeap {
41 friend class GenCollectorPolicy;
42 friend class Generation;
43 friend class DefNewGeneration;
44 friend class TenuredGeneration;
45 friend class ConcurrentMarkSweepGeneration;
46 friend class CMSCollector;
47 friend class GenMarkSweep;
48 friend class VM_GenCollectForAllocation;
49 friend class VM_GenCollectFull;
50 friend class VM_GenCollectFullConcurrent;
51 friend class VM_GC_HeapInspection;
52 friend class VM_HeapDumper;
53 friend class HeapInspection;
56 public:
57 friend class VM_PopulateDumpSharedSpace;
58
59 enum GenerationType {
60 YoungGen,
61 OldGen
62 };
63
64 private:
65 Generation* _young_gen;
66 Generation* _old_gen;
67
68 // The singleton CardTable Remembered Set.
69 CardTableRS* _rem_set;
70
71 // The generational collector policy.
72 GenCollectorPolicy* _gen_policy;
73
74 SoftRefGenPolicy _soft_ref_gen_policy;
75
76 // The sizing of the heap is controlled by a sizing policy.
77 AdaptiveSizePolicy* _size_policy;
78
79 // Indicates that the most recent previous incremental collection failed.
80 // The flag is cleared when an action is taken that might clear the
81 // condition that caused that incremental collection to fail.
82 bool _incremental_collection_failed;
83
84 // In support of ExplicitGCInvokesConcurrent functionality
85 unsigned int _full_collections_completed;
86
87 // Collects the given generation.
88 void collect_generation(Generation* gen, bool full, size_t size, bool is_tlab,
89 bool run_verification, bool clear_soft_refs,
90 bool restore_marks_for_biased_locking);
91
92 // Reserve aligned space for the heap as needed by the contained generations.
93 char* allocate(size_t alignment, ReservedSpace* heap_rs);
94
95 // Initialize ("weak") refs processing support
96 void ref_processing_init();
97
98 protected:
141 HeapWord* satisfy_failed_allocation(size_t size, bool is_tlab);
142
143 // Callback from VM_GenCollectFull operation.
144 // Perform a full collection of the first max_level+1 generations.
145 virtual void do_full_collection(bool clear_all_soft_refs);
146 void do_full_collection(bool clear_all_soft_refs, GenerationType max_generation);
147
148 // Does the "cause" of GC indicate that
149 // we absolutely __must__ clear soft refs?
150 bool must_clear_all_soft_refs();
151
152 GenCollectedHeap(GenCollectorPolicy *policy);
153
154 virtual void check_gen_kinds() = 0;
155
156 public:
157
158 // Returns JNI_OK on success
159 virtual jint initialize();
160
161 void initialize_size_policy(size_t init_eden_size,
162 size_t init_promo_size,
163 size_t init_survivor_size);
164
165 // Does operations required after initialization has been done.
166 void post_initialize();
167
168 Generation* young_gen() const { return _young_gen; }
169 Generation* old_gen() const { return _old_gen; }
170
171 bool is_young_gen(const Generation* gen) const { return gen == _young_gen; }
172 bool is_old_gen(const Generation* gen) const { return gen == _old_gen; }
173
174 // The generational collector policy.
175 GenCollectorPolicy* gen_policy() const { return _gen_policy; }
176
177 virtual CollectorPolicy* collector_policy() const { return gen_policy(); }
178
179 virtual SoftRefPolicy* soft_ref_policy() { return &_soft_ref_gen_policy; }
180
181 // Adaptive size policy
182 virtual AdaptiveSizePolicy* size_policy() {
183 return _size_policy;
184 }
185
186 // Return the (conservative) maximum heap alignment
187 static size_t conservative_max_heap_alignment() {
188 return Generation::GenGrain;
189 }
190
191 size_t capacity() const;
192 size_t used() const;
193
194 // Save the "used_region" for both generations.
195 void save_used_regions();
196
197 size_t max_capacity() const;
198
199 HeapWord* mem_allocate(size_t size, bool* gc_overhead_limit_was_exceeded);
200
201 // We may support a shared contiguous allocation area, if the youngest
202 // generation does.
203 bool supports_inline_contig_alloc() const;
|