Thu, 13 Jun 2013 22:02:40 -0700
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
Reviewed-by: dholmes, coleenp
Contributed-by: jeremymanson@google.com, calvin.cheung@oracle.com
duke@435 | 1 | /* |
jwilhelm@4554 | 2 | * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_MEMORY_COLLECTORPOLICY_HPP |
stefank@2314 | 26 | #define SHARE_VM_MEMORY_COLLECTORPOLICY_HPP |
stefank@2314 | 27 | |
coleenp@4037 | 28 | #include "memory/allocation.hpp" |
stefank@2314 | 29 | #include "memory/barrierSet.hpp" |
coleenp@4037 | 30 | #include "memory/generationSpec.hpp" |
stefank@2314 | 31 | #include "memory/genRemSet.hpp" |
jprovino@4542 | 32 | #include "utilities/macros.hpp" |
stefank@2314 | 33 | |
duke@435 | 34 | // This class (or more correctly, subtypes of this class) |
duke@435 | 35 | // are used to define global garbage collector attributes. |
duke@435 | 36 | // This includes initialization of generations and any other |
duke@435 | 37 | // shared resources they may need. |
duke@435 | 38 | // |
duke@435 | 39 | // In general, all flag adjustment and validation should be |
duke@435 | 40 | // done in initialize_flags(), which is called prior to |
duke@435 | 41 | // initialize_size_info(). |
duke@435 | 42 | // |
duke@435 | 43 | // This class is not fully developed yet. As more collector(s) |
duke@435 | 44 | // are added, it is expected that we will come across further |
duke@435 | 45 | // behavior that requires global attention. The correct place |
duke@435 | 46 | // to deal with those issues is this class. |
duke@435 | 47 | |
duke@435 | 48 | // Forward declarations. |
duke@435 | 49 | class GenCollectorPolicy; |
duke@435 | 50 | class TwoGenerationCollectorPolicy; |
ysr@777 | 51 | class AdaptiveSizePolicy; |
jprovino@4542 | 52 | #if INCLUDE_ALL_GCS |
duke@435 | 53 | class ConcurrentMarkSweepPolicy; |
ysr@777 | 54 | class G1CollectorPolicy; |
jprovino@4542 | 55 | #endif // INCLUDE_ALL_GCS |
ysr@777 | 56 | |
duke@435 | 57 | class GCPolicyCounters; |
duke@435 | 58 | class MarkSweepPolicy; |
duke@435 | 59 | |
zgu@3900 | 60 | class CollectorPolicy : public CHeapObj<mtGC> { |
duke@435 | 61 | protected: |
duke@435 | 62 | GCPolicyCounters* _gc_policy_counters; |
duke@435 | 63 | |
duke@435 | 64 | // Requires that the concrete subclass sets the alignment constraints |
duke@435 | 65 | // before calling. |
duke@435 | 66 | virtual void initialize_flags(); |
ysr@777 | 67 | virtual void initialize_size_info(); |
duke@435 | 68 | |
duke@435 | 69 | size_t _initial_heap_byte_size; |
duke@435 | 70 | size_t _max_heap_byte_size; |
duke@435 | 71 | size_t _min_heap_byte_size; |
duke@435 | 72 | |
duke@435 | 73 | size_t _min_alignment; |
duke@435 | 74 | size_t _max_alignment; |
duke@435 | 75 | |
jmasa@1822 | 76 | // The sizing of the heap are controlled by a sizing policy. |
jmasa@1822 | 77 | AdaptiveSizePolicy* _size_policy; |
jmasa@1822 | 78 | |
jmasa@1822 | 79 | // Set to true when policy wants soft refs cleared. |
jmasa@1822 | 80 | // Reset to false by gc after it clears all soft refs. |
jmasa@1822 | 81 | bool _should_clear_all_soft_refs; |
jmasa@1822 | 82 | // Set to true by the GC if the just-completed gc cleared all |
jmasa@1822 | 83 | // softrefs. This is set to true whenever a gc clears all softrefs, and |
jmasa@1822 | 84 | // set to false each time gc returns to the mutator. For example, in the |
jmasa@1822 | 85 | // ParallelScavengeHeap case the latter would be done toward the end of |
jmasa@1822 | 86 | // mem_allocate() where it returns op.result() |
jmasa@1822 | 87 | bool _all_soft_refs_clear; |
jmasa@1822 | 88 | |
duke@435 | 89 | CollectorPolicy() : |
duke@435 | 90 | _min_alignment(1), |
duke@435 | 91 | _max_alignment(1), |
duke@435 | 92 | _initial_heap_byte_size(0), |
duke@435 | 93 | _max_heap_byte_size(0), |
jmasa@1822 | 94 | _min_heap_byte_size(0), |
jmasa@1822 | 95 | _size_policy(NULL), |
jmasa@1822 | 96 | _should_clear_all_soft_refs(false), |
jmasa@1822 | 97 | _all_soft_refs_clear(false) |
duke@435 | 98 | {} |
duke@435 | 99 | |
duke@435 | 100 | public: |
duke@435 | 101 | void set_min_alignment(size_t align) { _min_alignment = align; } |
duke@435 | 102 | size_t min_alignment() { return _min_alignment; } |
duke@435 | 103 | void set_max_alignment(size_t align) { _max_alignment = align; } |
duke@435 | 104 | size_t max_alignment() { return _max_alignment; } |
duke@435 | 105 | |
duke@435 | 106 | size_t initial_heap_byte_size() { return _initial_heap_byte_size; } |
jmasa@448 | 107 | void set_initial_heap_byte_size(size_t v) { _initial_heap_byte_size = v; } |
duke@435 | 108 | size_t max_heap_byte_size() { return _max_heap_byte_size; } |
jmasa@448 | 109 | void set_max_heap_byte_size(size_t v) { _max_heap_byte_size = v; } |
duke@435 | 110 | size_t min_heap_byte_size() { return _min_heap_byte_size; } |
jmasa@448 | 111 | void set_min_heap_byte_size(size_t v) { _min_heap_byte_size = v; } |
duke@435 | 112 | |
duke@435 | 113 | enum Name { |
duke@435 | 114 | CollectorPolicyKind, |
duke@435 | 115 | TwoGenerationCollectorPolicyKind, |
duke@435 | 116 | ConcurrentMarkSweepPolicyKind, |
ysr@777 | 117 | ASConcurrentMarkSweepPolicyKind, |
ysr@777 | 118 | G1CollectorPolicyKind |
duke@435 | 119 | }; |
duke@435 | 120 | |
jmasa@1822 | 121 | AdaptiveSizePolicy* size_policy() { return _size_policy; } |
jmasa@1822 | 122 | bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; } |
jmasa@1822 | 123 | void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; } |
jmasa@1822 | 124 | // Returns the current value of _should_clear_all_soft_refs. |
jmasa@1822 | 125 | // _should_clear_all_soft_refs is set to false as a side effect. |
jmasa@1822 | 126 | bool use_should_clear_all_soft_refs(bool v); |
jmasa@1822 | 127 | bool all_soft_refs_clear() { return _all_soft_refs_clear; } |
jmasa@1822 | 128 | void set_all_soft_refs_clear(bool v) { _all_soft_refs_clear = v; } |
jmasa@1822 | 129 | |
jmasa@1822 | 130 | // Called by the GC after Soft Refs have been cleared to indicate |
jmasa@1822 | 131 | // that the request in _should_clear_all_soft_refs has been fulfilled. |
jmasa@1822 | 132 | void cleared_all_soft_refs(); |
jmasa@1822 | 133 | |
duke@435 | 134 | // Identification methods. |
ysr@777 | 135 | virtual GenCollectorPolicy* as_generation_policy() { return NULL; } |
duke@435 | 136 | virtual TwoGenerationCollectorPolicy* as_two_generation_policy() { return NULL; } |
duke@435 | 137 | virtual MarkSweepPolicy* as_mark_sweep_policy() { return NULL; } |
jprovino@4542 | 138 | #if INCLUDE_ALL_GCS |
duke@435 | 139 | virtual ConcurrentMarkSweepPolicy* as_concurrent_mark_sweep_policy() { return NULL; } |
ysr@777 | 140 | virtual G1CollectorPolicy* as_g1_policy() { return NULL; } |
jprovino@4542 | 141 | #endif // INCLUDE_ALL_GCS |
duke@435 | 142 | // Note that these are not virtual. |
duke@435 | 143 | bool is_generation_policy() { return as_generation_policy() != NULL; } |
duke@435 | 144 | bool is_two_generation_policy() { return as_two_generation_policy() != NULL; } |
duke@435 | 145 | bool is_mark_sweep_policy() { return as_mark_sweep_policy() != NULL; } |
jprovino@4542 | 146 | #if INCLUDE_ALL_GCS |
duke@435 | 147 | bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; } |
ysr@777 | 148 | bool is_g1_policy() { return as_g1_policy() != NULL; } |
jprovino@4542 | 149 | #else // INCLUDE_ALL_GCS |
duke@435 | 150 | bool is_concurrent_mark_sweep_policy() { return false; } |
ysr@777 | 151 | bool is_g1_policy() { return false; } |
jprovino@4542 | 152 | #endif // INCLUDE_ALL_GCS |
duke@435 | 153 | |
ysr@777 | 154 | |
duke@435 | 155 | virtual BarrierSet::Name barrier_set_name() = 0; |
duke@435 | 156 | virtual GenRemSet::Name rem_set_name() = 0; |
duke@435 | 157 | |
duke@435 | 158 | // Create the remembered set (to cover the given reserved region, |
duke@435 | 159 | // allowing breaking up into at most "max_covered_regions"). |
duke@435 | 160 | virtual GenRemSet* create_rem_set(MemRegion reserved, |
duke@435 | 161 | int max_covered_regions); |
duke@435 | 162 | |
duke@435 | 163 | // This method controls how a collector satisfies a request |
duke@435 | 164 | // for a block of memory. "gc_time_limit_was_exceeded" will |
duke@435 | 165 | // be set to true if the adaptive size policy determine that |
duke@435 | 166 | // an excessive amount of time is being spent doing collections |
duke@435 | 167 | // and caused a NULL to be returned. If a NULL is not returned, |
duke@435 | 168 | // "gc_time_limit_was_exceeded" has an undefined meaning. |
duke@435 | 169 | virtual HeapWord* mem_allocate_work(size_t size, |
duke@435 | 170 | bool is_tlab, |
duke@435 | 171 | bool* gc_overhead_limit_was_exceeded) = 0; |
duke@435 | 172 | |
duke@435 | 173 | // This method controls how a collector handles one or more |
duke@435 | 174 | // of its generations being fully allocated. |
duke@435 | 175 | virtual HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab) = 0; |
coleenp@4037 | 176 | // This method controls how a collector handles a metadata allocation |
coleenp@4037 | 177 | // failure. |
coleenp@4037 | 178 | virtual MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data, |
coleenp@4037 | 179 | size_t size, |
coleenp@4037 | 180 | Metaspace::MetadataType mdtype); |
coleenp@4037 | 181 | |
duke@435 | 182 | // Performace Counter support |
duke@435 | 183 | GCPolicyCounters* counters() { return _gc_policy_counters; } |
duke@435 | 184 | |
duke@435 | 185 | // Create the jstat counters for the GC policy. By default, policy's |
duke@435 | 186 | // don't have associated counters, and we complain if this is invoked. |
duke@435 | 187 | virtual void initialize_gc_policy_counters() { |
duke@435 | 188 | ShouldNotReachHere(); |
duke@435 | 189 | } |
duke@435 | 190 | |
duke@435 | 191 | virtual CollectorPolicy::Name kind() { |
duke@435 | 192 | return CollectorPolicy::CollectorPolicyKind; |
duke@435 | 193 | } |
duke@435 | 194 | |
duke@435 | 195 | // Returns true if a collector has eden space with soft end. |
duke@435 | 196 | virtual bool has_soft_ended_eden() { |
duke@435 | 197 | return false; |
duke@435 | 198 | } |
duke@435 | 199 | |
duke@435 | 200 | }; |
duke@435 | 201 | |
jmasa@1822 | 202 | class ClearedAllSoftRefs : public StackObj { |
jmasa@1822 | 203 | bool _clear_all_soft_refs; |
jmasa@1822 | 204 | CollectorPolicy* _collector_policy; |
jmasa@1822 | 205 | public: |
jmasa@1822 | 206 | ClearedAllSoftRefs(bool clear_all_soft_refs, |
jmasa@1822 | 207 | CollectorPolicy* collector_policy) : |
jmasa@1822 | 208 | _clear_all_soft_refs(clear_all_soft_refs), |
jmasa@1822 | 209 | _collector_policy(collector_policy) {} |
jmasa@1822 | 210 | |
jmasa@1822 | 211 | ~ClearedAllSoftRefs() { |
jmasa@1822 | 212 | if (_clear_all_soft_refs) { |
jmasa@1822 | 213 | _collector_policy->cleared_all_soft_refs(); |
jmasa@1822 | 214 | } |
jmasa@1822 | 215 | } |
jmasa@1822 | 216 | }; |
jmasa@1822 | 217 | |
duke@435 | 218 | class GenCollectorPolicy : public CollectorPolicy { |
duke@435 | 219 | protected: |
duke@435 | 220 | size_t _min_gen0_size; |
duke@435 | 221 | size_t _initial_gen0_size; |
duke@435 | 222 | size_t _max_gen0_size; |
duke@435 | 223 | |
duke@435 | 224 | GenerationSpec **_generations; |
duke@435 | 225 | |
duke@435 | 226 | // Return true if an allocation should be attempted in the older |
duke@435 | 227 | // generation if it fails in the younger generation. Return |
duke@435 | 228 | // false, otherwise. |
duke@435 | 229 | virtual bool should_try_older_generation_allocation(size_t word_size) const; |
duke@435 | 230 | |
duke@435 | 231 | void initialize_flags(); |
duke@435 | 232 | void initialize_size_info(); |
duke@435 | 233 | |
duke@435 | 234 | // Try to allocate space by expanding the heap. |
duke@435 | 235 | virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab); |
duke@435 | 236 | |
duke@435 | 237 | // compute max heap alignment |
duke@435 | 238 | size_t compute_max_alignment(); |
duke@435 | 239 | |
jmasa@448 | 240 | // Scale the base_size by NewRation according to |
jmasa@448 | 241 | // result = base_size / (NewRatio + 1) |
jmasa@448 | 242 | // and align by min_alignment() |
jmasa@448 | 243 | size_t scale_by_NewRatio_aligned(size_t base_size); |
jmasa@448 | 244 | |
jmasa@448 | 245 | // Bound the value by the given maximum minus the |
jmasa@448 | 246 | // min_alignment. |
jmasa@448 | 247 | size_t bound_minus_alignment(size_t desired_size, size_t maximum_size); |
duke@435 | 248 | |
duke@435 | 249 | public: |
jmasa@448 | 250 | // Accessors |
jmasa@448 | 251 | size_t min_gen0_size() { return _min_gen0_size; } |
jmasa@448 | 252 | void set_min_gen0_size(size_t v) { _min_gen0_size = v; } |
jmasa@448 | 253 | size_t initial_gen0_size() { return _initial_gen0_size; } |
jmasa@448 | 254 | void set_initial_gen0_size(size_t v) { _initial_gen0_size = v; } |
jmasa@448 | 255 | size_t max_gen0_size() { return _max_gen0_size; } |
jmasa@448 | 256 | void set_max_gen0_size(size_t v) { _max_gen0_size = v; } |
jmasa@448 | 257 | |
duke@435 | 258 | virtual int number_of_generations() = 0; |
duke@435 | 259 | |
duke@435 | 260 | virtual GenerationSpec **generations() { |
duke@435 | 261 | assert(_generations != NULL, "Sanity check"); |
duke@435 | 262 | return _generations; |
duke@435 | 263 | } |
duke@435 | 264 | |
duke@435 | 265 | virtual GenCollectorPolicy* as_generation_policy() { return this; } |
duke@435 | 266 | |
duke@435 | 267 | virtual void initialize_generations() = 0; |
duke@435 | 268 | |
duke@435 | 269 | virtual void initialize_all() { |
duke@435 | 270 | initialize_flags(); |
duke@435 | 271 | initialize_size_info(); |
duke@435 | 272 | initialize_generations(); |
duke@435 | 273 | } |
duke@435 | 274 | |
duke@435 | 275 | HeapWord* mem_allocate_work(size_t size, |
duke@435 | 276 | bool is_tlab, |
duke@435 | 277 | bool* gc_overhead_limit_was_exceeded); |
duke@435 | 278 | |
duke@435 | 279 | HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab); |
duke@435 | 280 | |
duke@435 | 281 | // Adaptive size policy |
duke@435 | 282 | virtual void initialize_size_policy(size_t init_eden_size, |
duke@435 | 283 | size_t init_promo_size, |
duke@435 | 284 | size_t init_survivor_size); |
duke@435 | 285 | }; |
duke@435 | 286 | |
duke@435 | 287 | // All of hotspot's current collectors are subtypes of this |
duke@435 | 288 | // class. Currently, these collectors all use the same gen[0], |
duke@435 | 289 | // but have different gen[1] types. If we add another subtype |
duke@435 | 290 | // of CollectorPolicy, this class should be broken out into |
duke@435 | 291 | // its own file. |
duke@435 | 292 | |
duke@435 | 293 | class TwoGenerationCollectorPolicy : public GenCollectorPolicy { |
duke@435 | 294 | protected: |
duke@435 | 295 | size_t _min_gen1_size; |
duke@435 | 296 | size_t _initial_gen1_size; |
duke@435 | 297 | size_t _max_gen1_size; |
duke@435 | 298 | |
duke@435 | 299 | void initialize_flags(); |
duke@435 | 300 | void initialize_size_info(); |
duke@435 | 301 | void initialize_generations() { ShouldNotReachHere(); } |
duke@435 | 302 | |
duke@435 | 303 | public: |
jmasa@448 | 304 | // Accessors |
jmasa@448 | 305 | size_t min_gen1_size() { return _min_gen1_size; } |
jmasa@448 | 306 | void set_min_gen1_size(size_t v) { _min_gen1_size = v; } |
jmasa@448 | 307 | size_t initial_gen1_size() { return _initial_gen1_size; } |
jmasa@448 | 308 | void set_initial_gen1_size(size_t v) { _initial_gen1_size = v; } |
jmasa@448 | 309 | size_t max_gen1_size() { return _max_gen1_size; } |
jmasa@448 | 310 | void set_max_gen1_size(size_t v) { _max_gen1_size = v; } |
jmasa@448 | 311 | |
duke@435 | 312 | // Inherited methods |
duke@435 | 313 | TwoGenerationCollectorPolicy* as_two_generation_policy() { return this; } |
duke@435 | 314 | |
duke@435 | 315 | int number_of_generations() { return 2; } |
duke@435 | 316 | BarrierSet::Name barrier_set_name() { return BarrierSet::CardTableModRef; } |
duke@435 | 317 | GenRemSet::Name rem_set_name() { return GenRemSet::CardTable; } |
duke@435 | 318 | |
duke@435 | 319 | virtual CollectorPolicy::Name kind() { |
duke@435 | 320 | return CollectorPolicy::TwoGenerationCollectorPolicyKind; |
duke@435 | 321 | } |
jmasa@448 | 322 | |
jmasa@448 | 323 | // Returns true is gen0 sizes were adjusted |
jmasa@448 | 324 | bool adjust_gen0_sizes(size_t* gen0_size_ptr, size_t* gen1_size_ptr, |
jwilhelm@4554 | 325 | const size_t heap_size, const size_t min_gen1_size); |
duke@435 | 326 | }; |
duke@435 | 327 | |
duke@435 | 328 | class MarkSweepPolicy : public TwoGenerationCollectorPolicy { |
duke@435 | 329 | protected: |
duke@435 | 330 | void initialize_generations(); |
duke@435 | 331 | |
duke@435 | 332 | public: |
duke@435 | 333 | MarkSweepPolicy(); |
duke@435 | 334 | |
duke@435 | 335 | MarkSweepPolicy* as_mark_sweep_policy() { return this; } |
duke@435 | 336 | |
duke@435 | 337 | void initialize_gc_policy_counters(); |
duke@435 | 338 | }; |
stefank@2314 | 339 | |
stefank@2314 | 340 | #endif // SHARE_VM_MEMORY_COLLECTORPOLICY_HPP |