annotate src/hotspot/share/gc/serial/defNewGeneration.hpp @ 54215:5ef581e59d91

8214236: sun.gc.collector.2.name should be changed Reviewed-by: pliden, tschatzl
author cito
date Tue, 12 Feb 2019 08:56:03 +0900
parents 9807daeb47c4
children 93f09ca4a7f8
rev   line source
duke@1 1 /*
coleenp@53729 2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
coleenp@53729 25 #ifndef SHARE_GC_SERIAL_DEFNEWGENERATION_HPP
coleenp@53729 26 #define SHARE_GC_SERIAL_DEFNEWGENERATION_HPP
stefank@7397 27
pliden@30764 28 #include "gc/serial/cSpaceCounters.hpp"
pliden@30764 29 #include "gc/shared/ageTable.hpp"
pliden@30764 30 #include "gc/shared/copyFailedInfo.hpp"
pliden@30764 31 #include "gc/shared/generation.hpp"
pliden@30764 32 #include "gc/shared/generationCounters.hpp"
tonyp@36202 33 #include "gc/shared/preservedMarks.hpp"
stefank@46625 34 #include "utilities/align.hpp"
stefank@7397 35 #include "utilities/stack.hpp"
stefank@7397 36
duke@1 37 class ContiguousSpace;
coleenp@360 38 class ScanClosure;
sla@18025 39 class STWGCTimer;
stefank@29701 40 class CSpaceCounters;
stefank@29701 41 class ScanWeakRefClosure;
stefank@50333 42 class SerialHeap;
duke@1 43
duke@1 44 // DefNewGeneration is a young generation containing eden, from- and
duke@1 45 // to-space.
duke@1 46
duke@1 47 class DefNewGeneration: public Generation {
duke@1 48 friend class VMStructs;
duke@1 49
duke@1 50 protected:
jwilhelm@29684 51 Generation* _old_gen;
jwilhelm@13925 52 uint _tenuring_threshold; // Tenuring threshold for next collection.
david@35492 53 AgeTable _age_table;
duke@1 54 // Size of object to pretenure in words; command line provides bytes
sla@18025 55 size_t _pretenure_size_threshold_words;
duke@1 56
david@35492 57 AgeTable* age_table() { return &_age_table; }
sla@18025 58
duke@1 59 // Initialize state to optimistically assume no promotion failure will
duke@1 60 // happen.
duke@1 61 void init_assuming_no_promotion_failure();
duke@1 62 // True iff a promotion has failed in the current collection.
duke@1 63 bool _promotion_failed;
duke@1 64 bool promotion_failed() { return _promotion_failed; }
sla@18025 65 PromotionFailedInfo _promotion_failed_info;
duke@1 66
duke@1 67 // Handling promotion failure. A young generation collection
duke@1 68 // can fail if a live object cannot be copied out of its
duke@1 69 // location in eden or from-space during the collection. If
duke@1 70 // a collection fails, the young generation is left in a
duke@1 71 // consistent state such that it can be collected by a
duke@1 72 // full collection.
duke@1 73 // Before the collection
duke@1 74 // Objects are in eden or from-space
duke@1 75 // All roots into the young generation point into eden or from-space.
duke@1 76 //
duke@1 77 // After a failed collection
duke@1 78 // Objects may be in eden, from-space, or to-space
duke@1 79 // An object A in eden or from-space may have a copy B
duke@1 80 // in to-space. If B exists, all roots that once pointed
duke@1 81 // to A must now point to B.
duke@1 82 // All objects in the young generation are unmarked.
duke@1 83 // Eden, from-space, and to-space will all be collected by
duke@1 84 // the full collection.
duke@1 85 void handle_promotion_failure(oop);
duke@1 86
duke@1 87 // In the absence of promotion failure, we wouldn't look at "from-space"
duke@1 88 // objects after a young-gen collection. When promotion fails, however,
duke@1 89 // the subsequent full collection will look at from-space objects:
duke@1 90 // therefore we must remove their forwarding pointers.
duke@1 91 void remove_forwarding_pointers();
duke@1 92
rkennke@47419 93 virtual void restore_preserved_marks();
rkennke@47419 94
tonyp@36202 95 // Preserved marks
tonyp@36202 96 PreservedMarksSet _preserved_marks_set;
duke@1 97
duke@1 98 // Promotion failure handling
stefank@51171 99 OopIterateClosure *_promo_failure_scan_stack_closure;
stefank@51171 100 void set_promo_failure_scan_stack_closure(OopIterateClosure *scan_stack_closure) {
duke@1 101 _promo_failure_scan_stack_closure = scan_stack_closure;
duke@1 102 }
duke@1 103
zgu@13195 104 Stack<oop, mtGC> _promo_failure_scan_stack;
duke@1 105 void drain_promo_failure_scan_stack(void);
duke@1 106 bool _promo_failure_drain_in_progress;
duke@1 107
duke@1 108 // Performance Counters
duke@1 109 GenerationCounters* _gen_counters;
duke@1 110 CSpaceCounters* _eden_counters;
duke@1 111 CSpaceCounters* _from_counters;
duke@1 112 CSpaceCounters* _to_counters;
duke@1 113
duke@1 114 // sizing information
duke@1 115 size_t _max_eden_size;
duke@1 116 size_t _max_survivor_size;
duke@1 117
duke@1 118 // Allocation support
duke@1 119 bool _should_allocate_from_space;
duke@1 120 bool should_allocate_from_space() const {
duke@1 121 return _should_allocate_from_space;
duke@1 122 }
duke@1 123 void clear_should_allocate_from_space() {
duke@1 124 _should_allocate_from_space = false;
duke@1 125 }
duke@1 126 void set_should_allocate_from_space() {
duke@1 127 _should_allocate_from_space = true;
duke@1 128 }
duke@1 129
brutisso@15215 130 // Tenuring
brutisso@15215 131 void adjust_desired_tenuring_threshold();
brutisso@15215 132
duke@1 133 // Spaces
brutisso@27625 134 ContiguousSpace* _eden_space;
duke@1 135 ContiguousSpace* _from_space;
duke@1 136 ContiguousSpace* _to_space;
duke@1 137
sla@18025 138 STWGCTimer* _gc_timer;
sla@18025 139
duke@1 140 enum SomeProtectedConstants {
duke@1 141 // Generations are GenGrain-aligned and have size that are multiples of
duke@1 142 // GenGrain.
duke@1 143 MinFreeScratchWords = 100
duke@1 144 };
duke@1 145
duke@1 146 // Return the size of a survivor space if this generation were of size
duke@1 147 // gen_size.
duke@1 148 size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
duke@1 149 size_t n = gen_size / (SurvivorRatio + 2);
stefank@46619 150 return n > alignment ? align_down(n, alignment) : alignment;
duke@1 151 }
duke@1 152
duke@1 153 public: // was "protected" but caused compile error on win32
duke@1 154 class IsAliveClosure: public BoolObjectClosure {
jwilhelm@31358 155 Generation* _young_gen;
duke@1 156 public:
jwilhelm@31358 157 IsAliveClosure(Generation* young_gen);
duke@1 158 bool do_object_b(oop p);
duke@1 159 };
duke@1 160
duke@1 161 class KeepAliveClosure: public OopClosure {
duke@1 162 protected:
duke@1 163 ScanWeakRefClosure* _cl;
duke@1 164 CardTableRS* _rs;
coleenp@360 165 template <class T> void do_oop_work(T* p);
duke@1 166 public:
duke@1 167 KeepAliveClosure(ScanWeakRefClosure* cl);
coleenp@360 168 virtual void do_oop(oop* p);
coleenp@360 169 virtual void do_oop(narrowOop* p);
duke@1 170 };
duke@1 171
duke@1 172 class FastKeepAliveClosure: public KeepAliveClosure {
duke@1 173 protected:
duke@1 174 HeapWord* _boundary;
coleenp@360 175 template <class T> void do_oop_work(T* p);
duke@1 176 public:
duke@1 177 FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);
coleenp@360 178 virtual void do_oop(oop* p);
coleenp@360 179 virtual void do_oop(narrowOop* p);
duke@1 180 };
duke@1 181
duke@1 182 class FastEvacuateFollowersClosure: public VoidClosure {
stefank@50333 183 SerialHeap* _heap;
duke@1 184 FastScanClosure* _scan_cur_or_nonheap;
duke@1 185 FastScanClosure* _scan_older;
duke@1 186 public:
stefank@50333 187 FastEvacuateFollowersClosure(SerialHeap* heap,
duke@1 188 FastScanClosure* cur,
duke@1 189 FastScanClosure* older);
duke@1 190 void do_void();
duke@1 191 };
duke@1 192
duke@1 193 public:
jwilhelm@31358 194 DefNewGeneration(ReservedSpace rs, size_t initial_byte_size,
cito@54215 195 const char* policy="Serial young collection pauses");
duke@1 196
sla@18025 197 virtual void ref_processor_init();
sla@18025 198
duke@1 199 virtual Generation::Name kind() { return Generation::DefNew; }
duke@1 200
duke@1 201 // Accessing spaces
brutisso@27625 202 ContiguousSpace* eden() const { return _eden_space; }
brutisso@27625 203 ContiguousSpace* from() const { return _from_space; }
brutisso@27625 204 ContiguousSpace* to() const { return _to_space; }
duke@1 205
coleenp@360 206 virtual CompactibleSpace* first_compaction_space() const;
duke@1 207
duke@1 208 // Space enquiries
duke@1 209 size_t capacity() const;
duke@1 210 size_t used() const;
duke@1 211 size_t free() const;
duke@1 212 size_t max_capacity() const;
duke@1 213 size_t capacity_before_gc() const;
duke@1 214 size_t unsafe_max_alloc_nogc() const;
duke@1 215 size_t contiguous_available() const;
duke@1 216
duke@1 217 size_t max_eden_size() const { return _max_eden_size; }
duke@1 218 size_t max_survivor_size() const { return _max_survivor_size; }
duke@1 219
duke@1 220 bool supports_inline_contig_alloc() const { return true; }
eosterlund@41283 221 HeapWord* volatile* top_addr() const;
duke@1 222 HeapWord** end_addr() const;
duke@1 223
duke@1 224 // Thread-local allocation buffers
duke@1 225 bool supports_tlab_allocation() const { return true; }
coleenp@360 226 size_t tlab_capacity() const;
brutisso@22552 227 size_t tlab_used() const;
coleenp@360 228 size_t unsafe_max_tlab_alloc() const;
duke@1 229
duke@1 230 // Grow the generation by the specified number of bytes.
duke@1 231 // The size of bytes is assumed to be properly aligned.
duke@1 232 // Return true if the expansion was successful.
duke@1 233 bool expand(size_t bytes);
duke@1 234
duke@1 235 // DefNewGeneration cannot currently expand except at
duke@1 236 // a GC.
duke@1 237 virtual bool is_maximal_no_gc() const { return true; }
duke@1 238
duke@1 239 // Iteration
duke@1 240 void object_iterate(ObjectClosure* blk);
duke@1 241
stefank@30870 242 void younger_refs_iterate(OopsInGenClosure* cl, uint n_threads);
duke@1 243
duke@1 244 void space_iterate(SpaceClosure* blk, bool usedOnly = false);
duke@1 245
duke@1 246 // Allocation support
duke@1 247 virtual bool should_allocate(size_t word_size, bool is_tlab) {
duke@1 248 assert(UseTLAB || !is_tlab, "Should not allocate tlab");
duke@1 249
duke@1 250 size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
duke@1 251
duke@1 252 const bool non_zero = word_size > 0;
duke@1 253 const bool overflows = word_size >= overflow_limit;
duke@1 254 const bool check_too_big = _pretenure_size_threshold_words > 0;
duke@1 255 const bool not_too_big = word_size < _pretenure_size_threshold_words;
duke@1 256 const bool size_ok = is_tlab || !check_too_big || not_too_big;
duke@1 257
duke@1 258 bool result = !overflows &&
duke@1 259 non_zero &&
duke@1 260 size_ok;
duke@1 261
duke@1 262 return result;
duke@1 263 }
duke@1 264
coleenp@360 265 HeapWord* allocate(size_t word_size, bool is_tlab);
duke@1 266 HeapWord* allocate_from_space(size_t word_size);
duke@1 267
coleenp@360 268 HeapWord* par_allocate(size_t word_size, bool is_tlab);
duke@1 269
duke@1 270 virtual void gc_epilogue(bool full);
duke@1 271
jmasa@971 272 // Save the tops for eden, from, and to
jmasa@971 273 virtual void record_spaces_top();
jmasa@971 274
duke@1 275 // Accessing marks
duke@1 276 void save_marks();
duke@1 277 void reset_saved_marks();
duke@1 278 bool no_allocs_since_save_marks();
duke@1 279
duke@1 280 // Need to declare the full complement of closures, whether we'll
duke@1 281 // override them or not, or get message from the compiler:
duke@1 282 // oop_since_save_marks_iterate_nv hides virtual function...
stefank@50334 283 template <typename OopClosureType>
stefank@50334 284 void oop_since_save_marks_iterate(OopClosureType* cl);
duke@1 285
duke@1 286 // For non-youngest collection, the DefNewGeneration can contribute
duke@1 287 // "to-space".
jmasa@971 288 virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
duke@1 289 size_t max_alloc_words);
duke@1 290
jmasa@971 291 // Reset for contribution of "to-space".
jmasa@971 292 virtual void reset_scratch();
jmasa@971 293
duke@1 294 // GC support
duke@1 295 virtual void compute_new_size();
ysr@6985 296
ysr@6985 297 // Returns true if the collection is likely to be safely
ysr@6985 298 // completed. Even if this method returns true, a collection
ysr@6985 299 // may not be guaranteed to succeed, and the system should be
ysr@6985 300 // able to safely unwind and recover from that failure, albeit
ysr@6985 301 // at some additional cost. Override superclass's implementation.
ysr@6985 302 virtual bool collection_attempt_is_safe();
ysr@6985 303
duke@1 304 virtual void collect(bool full,
duke@1 305 bool clear_all_soft_refs,
duke@1 306 size_t size,
duke@1 307 bool is_tlab);
duke@1 308 HeapWord* expand_and_allocate(size_t size,
duke@1 309 bool is_tlab,
duke@1 310 bool parallel = false);
duke@1 311
coleenp@360 312 oop copy_to_survivor_space(oop old);
jwilhelm@13925 313 uint tenuring_threshold() { return _tenuring_threshold; }
duke@1 314
duke@1 315 // Performance Counter support
duke@1 316 void update_counters();
duke@1 317
duke@1 318 // Printing
duke@1 319 virtual const char* name() const;
duke@1 320 virtual const char* short_name() const { return "DefNew"; }
duke@1 321
duke@1 322 void print_on(outputStream* st) const;
duke@1 323
brutisso@12379 324 void verify();
duke@1 325
jcoomes@6762 326 bool promo_failure_scan_is_complete() const {
jcoomes@6762 327 return _promo_failure_scan_stack.is_empty();
jcoomes@6762 328 }
jcoomes@6762 329
duke@1 330 protected:
jmasa@971 331 // If clear_space is true, clear the survivor spaces. Eden is
jmasa@971 332 // cleared if the minimum size of eden is 0. If mangle_space
jmasa@971 333 // is true, also mangle the space in debug mode.
jmasa@971 334 void compute_space_boundaries(uintx minimum_eden_size,
jmasa@971 335 bool clear_space,
jmasa@971 336 bool mangle_space);
sangheki@35458 337
sangheki@35458 338 // Return adjusted new size for NewSizeThreadIncrease.
sangheki@35458 339 // If any overflow happens, revert to previous new size.
sangheki@35458 340 size_t adjust_for_thread_increase(size_t new_size_candidate,
sangheki@35458 341 size_t new_size_before,
sangheki@35458 342 size_t alignment) const;
sangheki@35458 343
sangheki@35458 344
duke@1 345 // Scavenge support
duke@1 346 void swap_spaces();
duke@1 347 };
stefank@7397 348
coleenp@53729 349 #endif // SHARE_GC_SERIAL_DEFNEWGENERATION_HPP