Mercurial > hg > graal-jvmci-8
comparison src/share/vm/memory/collectorPolicy.hpp @ 1387:0bfd3fb24150
6858496: Clear all SoftReferences before an out-of-memory due to GC overhead limit.
Summary: Ensure a full GC that clears SoftReferences before throwing an out-of-memory
Reviewed-by: ysr, jcoomes
author | jmasa |
---|---|
date | Tue, 13 Apr 2010 13:52:10 -0700 |
parents | 1ee8caae33af |
children | c18cbe5936b8 |
comparison
equal
deleted
inserted
replaced
1361:6b73e879f1c2 | 1387:0bfd3fb24150 |
---|---|
1 /* | 1 /* |
2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 2001-2010 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
67 size_t _min_heap_byte_size; | 67 size_t _min_heap_byte_size; |
68 | 68 |
69 size_t _min_alignment; | 69 size_t _min_alignment; |
70 size_t _max_alignment; | 70 size_t _max_alignment; |
71 | 71 |
72 // The sizing of the heap are controlled by a sizing policy. | |
73 AdaptiveSizePolicy* _size_policy; | |
74 | |
75 // Set to true when policy wants soft refs cleared. | |
76 // Reset to false by gc after it clears all soft refs. | |
77 bool _should_clear_all_soft_refs; | |
78 // Set to true by the GC if the just-completed gc cleared all | |
79 // softrefs. This is set to true whenever a gc clears all softrefs, and | |
80 // set to false each time gc returns to the mutator. For example, in the | |
81 // ParallelScavengeHeap case the latter would be done toward the end of | |
82 // mem_allocate() where it returns op.result() | |
83 bool _all_soft_refs_clear; | |
84 | |
72 CollectorPolicy() : | 85 CollectorPolicy() : |
73 _min_alignment(1), | 86 _min_alignment(1), |
74 _max_alignment(1), | 87 _max_alignment(1), |
75 _initial_heap_byte_size(0), | 88 _initial_heap_byte_size(0), |
76 _max_heap_byte_size(0), | 89 _max_heap_byte_size(0), |
77 _min_heap_byte_size(0) | 90 _min_heap_byte_size(0), |
91 _size_policy(NULL), | |
92 _should_clear_all_soft_refs(false), | |
93 _all_soft_refs_clear(false) | |
78 {} | 94 {} |
79 | 95 |
80 public: | 96 public: |
81 void set_min_alignment(size_t align) { _min_alignment = align; } | 97 void set_min_alignment(size_t align) { _min_alignment = align; } |
82 size_t min_alignment() { return _min_alignment; } | 98 size_t min_alignment() { return _min_alignment; } |
95 TwoGenerationCollectorPolicyKind, | 111 TwoGenerationCollectorPolicyKind, |
96 ConcurrentMarkSweepPolicyKind, | 112 ConcurrentMarkSweepPolicyKind, |
97 ASConcurrentMarkSweepPolicyKind, | 113 ASConcurrentMarkSweepPolicyKind, |
98 G1CollectorPolicyKind | 114 G1CollectorPolicyKind |
99 }; | 115 }; |
116 | |
117 AdaptiveSizePolicy* size_policy() { return _size_policy; } | |
118 bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; } | |
119 void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; } | |
120 // Returns the current value of _should_clear_all_soft_refs. | |
121 // _should_clear_all_soft_refs is set to false as a side effect. | |
122 bool use_should_clear_all_soft_refs(bool v); | |
123 bool all_soft_refs_clear() { return _all_soft_refs_clear; } | |
124 void set_all_soft_refs_clear(bool v) { _all_soft_refs_clear = v; } | |
125 | |
126 // Called by the GC after Soft Refs have been cleared to indicate | |
127 // that the request in _should_clear_all_soft_refs has been fulfilled. | |
128 void cleared_all_soft_refs(); | |
100 | 129 |
101 // Identification methods. | 130 // Identification methods. |
102 virtual GenCollectorPolicy* as_generation_policy() { return NULL; } | 131 virtual GenCollectorPolicy* as_generation_policy() { return NULL; } |
103 virtual TwoGenerationCollectorPolicy* as_two_generation_policy() { return NULL; } | 132 virtual TwoGenerationCollectorPolicy* as_two_generation_policy() { return NULL; } |
104 virtual MarkSweepPolicy* as_mark_sweep_policy() { return NULL; } | 133 virtual MarkSweepPolicy* as_mark_sweep_policy() { return NULL; } |
163 return false; | 192 return false; |
164 } | 193 } |
165 | 194 |
166 }; | 195 }; |
167 | 196 |
197 class ClearedAllSoftRefs : public StackObj { | |
198 bool _clear_all_soft_refs; | |
199 CollectorPolicy* _collector_policy; | |
200 public: | |
201 ClearedAllSoftRefs(bool clear_all_soft_refs, | |
202 CollectorPolicy* collector_policy) : | |
203 _clear_all_soft_refs(clear_all_soft_refs), | |
204 _collector_policy(collector_policy) {} | |
205 | |
206 ~ClearedAllSoftRefs() { | |
207 if (_clear_all_soft_refs) { | |
208 _collector_policy->cleared_all_soft_refs(); | |
209 } | |
210 } | |
211 }; | |
212 | |
168 class GenCollectorPolicy : public CollectorPolicy { | 213 class GenCollectorPolicy : public CollectorPolicy { |
169 protected: | 214 protected: |
170 size_t _min_gen0_size; | 215 size_t _min_gen0_size; |
171 size_t _initial_gen0_size; | 216 size_t _initial_gen0_size; |
172 size_t _max_gen0_size; | 217 size_t _max_gen0_size; |
173 | 218 |
174 GenerationSpec **_generations; | 219 GenerationSpec **_generations; |
175 | |
176 // The sizing of the different generations in the heap are controlled | |
177 // by a sizing policy. | |
178 AdaptiveSizePolicy* _size_policy; | |
179 | 220 |
180 // Return true if an allocation should be attempted in the older | 221 // Return true if an allocation should be attempted in the older |
181 // generation if it fails in the younger generation. Return | 222 // generation if it fails in the younger generation. Return |
182 // false, otherwise. | 223 // false, otherwise. |
183 virtual bool should_try_older_generation_allocation(size_t word_size) const; | 224 virtual bool should_try_older_generation_allocation(size_t word_size) const; |
234 | 275 |
235 // The size that defines a "large array". | 276 // The size that defines a "large array". |
236 virtual size_t large_typearray_limit(); | 277 virtual size_t large_typearray_limit(); |
237 | 278 |
238 // Adaptive size policy | 279 // Adaptive size policy |
239 AdaptiveSizePolicy* size_policy() { return _size_policy; } | |
240 virtual void initialize_size_policy(size_t init_eden_size, | 280 virtual void initialize_size_policy(size_t init_eden_size, |
241 size_t init_promo_size, | 281 size_t init_promo_size, |
242 size_t init_survivor_size); | 282 size_t init_survivor_size); |
243 | 283 }; |
244 }; | |
245 | |
246 | 284 |
247 // All of hotspot's current collectors are subtypes of this | 285 // All of hotspot's current collectors are subtypes of this |
248 // class. Currently, these collectors all use the same gen[0], | 286 // class. Currently, these collectors all use the same gen[0], |
249 // but have different gen[1] types. If we add another subtype | 287 // but have different gen[1] types. If we add another subtype |
250 // of CollectorPolicy, this class should be broken out into | 288 // of CollectorPolicy, this class should be broken out into |