src/share/vm/memory/defNewGeneration.hpp

Tue, 16 Feb 2016 21:42:29 +0000

author
poonam
date
Tue, 16 Feb 2016 21:42:29 +0000
changeset 8308
6acf14e730dd
parent 6376
cfd4aac53239
child 6876
710a3c8b516e
child 9858
b985cbb00e68
permissions
-rw-r--r--

8072725: Provide more granular levels for GC verification
Summary: Add option VerifySubSet to selectively verify the memory sub-systems
Reviewed-by: kevinw, jmasa

duke@435 1 /*
sla@5237 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_DEFNEWGENERATION_HPP
stefank@2314 26 #define SHARE_VM_MEMORY_DEFNEWGENERATION_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/shared/ageTable.hpp"
stefank@2314 29 #include "gc_implementation/shared/cSpaceCounters.hpp"
stefank@2314 30 #include "gc_implementation/shared/generationCounters.hpp"
sla@5237 31 #include "gc_implementation/shared/copyFailedInfo.hpp"
stefank@2314 32 #include "memory/generation.inline.hpp"
stefank@2314 33 #include "utilities/stack.hpp"
stefank@2314 34
duke@435 35 class EdenSpace;
duke@435 36 class ContiguousSpace;
coleenp@548 37 class ScanClosure;
sla@5237 38 class STWGCTimer;
duke@435 39
duke@435 40 // DefNewGeneration is a young generation containing eden, from- and
duke@435 41 // to-space.
duke@435 42
duke@435 43 class DefNewGeneration: public Generation {
duke@435 44 friend class VMStructs;
duke@435 45
duke@435 46 protected:
duke@435 47 Generation* _next_gen;
jwilhelm@4129 48 uint _tenuring_threshold; // Tenuring threshold for next collection.
duke@435 49 ageTable _age_table;
duke@435 50 // Size of object to pretenure in words; command line provides bytes
sla@5237 51 size_t _pretenure_size_threshold_words;
duke@435 52
duke@435 53 ageTable* age_table() { return &_age_table; }
sla@5237 54
duke@435 55 // Initialize state to optimistically assume no promotion failure will
duke@435 56 // happen.
duke@435 57 void init_assuming_no_promotion_failure();
duke@435 58 // True iff a promotion has failed in the current collection.
duke@435 59 bool _promotion_failed;
duke@435 60 bool promotion_failed() { return _promotion_failed; }
sla@5237 61 PromotionFailedInfo _promotion_failed_info;
duke@435 62
duke@435 63 // Handling promotion failure. A young generation collection
duke@435 64 // can fail if a live object cannot be copied out of its
duke@435 65 // location in eden or from-space during the collection. If
duke@435 66 // a collection fails, the young generation is left in a
duke@435 67 // consistent state such that it can be collected by a
duke@435 68 // full collection.
duke@435 69 // Before the collection
duke@435 70 // Objects are in eden or from-space
duke@435 71 // All roots into the young generation point into eden or from-space.
duke@435 72 //
duke@435 73 // After a failed collection
duke@435 74 // Objects may be in eden, from-space, or to-space
duke@435 75 // An object A in eden or from-space may have a copy B
duke@435 76 // in to-space. If B exists, all roots that once pointed
duke@435 77 // to A must now point to B.
duke@435 78 // All objects in the young generation are unmarked.
duke@435 79 // Eden, from-space, and to-space will all be collected by
duke@435 80 // the full collection.
duke@435 81 void handle_promotion_failure(oop);
duke@435 82
duke@435 83 // In the absence of promotion failure, we wouldn't look at "from-space"
duke@435 84 // objects after a young-gen collection. When promotion fails, however,
duke@435 85 // the subsequent full collection will look at from-space objects:
duke@435 86 // therefore we must remove their forwarding pointers.
duke@435 87 void remove_forwarding_pointers();
duke@435 88
duke@435 89 // Preserve the mark of "obj", if necessary, in preparation for its mark
duke@435 90 // word being overwritten with a self-forwarding-pointer.
duke@435 91 void preserve_mark_if_necessary(oop obj, markOop m);
ysr@2380 92 void preserve_mark(oop obj, markOop m); // work routine used by the above
duke@435 93
jcoomes@2191 94 // Together, these keep <object with a preserved mark, mark value> pairs.
jcoomes@2191 95 // They should always contain the same number of elements.
zgu@3900 96 Stack<oop, mtGC> _objs_with_preserved_marks;
zgu@3900 97 Stack<markOop, mtGC> _preserved_marks_of_objs;
duke@435 98
duke@435 99 // Promotion failure handling
coleenp@4037 100 ExtendedOopClosure *_promo_failure_scan_stack_closure;
coleenp@4037 101 void set_promo_failure_scan_stack_closure(ExtendedOopClosure *scan_stack_closure) {
duke@435 102 _promo_failure_scan_stack_closure = scan_stack_closure;
duke@435 103 }
duke@435 104
zgu@3900 105 Stack<oop, mtGC> _promo_failure_scan_stack;
duke@435 106 void drain_promo_failure_scan_stack(void);
duke@435 107 bool _promo_failure_drain_in_progress;
duke@435 108
duke@435 109 // Performance Counters
duke@435 110 GenerationCounters* _gen_counters;
duke@435 111 CSpaceCounters* _eden_counters;
duke@435 112 CSpaceCounters* _from_counters;
duke@435 113 CSpaceCounters* _to_counters;
duke@435 114
duke@435 115 // sizing information
duke@435 116 size_t _max_eden_size;
duke@435 117 size_t _max_survivor_size;
duke@435 118
duke@435 119 // Allocation support
duke@435 120 bool _should_allocate_from_space;
duke@435 121 bool should_allocate_from_space() const {
duke@435 122 return _should_allocate_from_space;
duke@435 123 }
duke@435 124 void clear_should_allocate_from_space() {
duke@435 125 _should_allocate_from_space = false;
duke@435 126 }
duke@435 127 void set_should_allocate_from_space() {
duke@435 128 _should_allocate_from_space = true;
duke@435 129 }
duke@435 130
brutisso@4452 131 // Tenuring
brutisso@4452 132 void adjust_desired_tenuring_threshold();
brutisso@4452 133
duke@435 134 // Spaces
duke@435 135 EdenSpace* _eden_space;
duke@435 136 ContiguousSpace* _from_space;
duke@435 137 ContiguousSpace* _to_space;
duke@435 138
sla@5237 139 STWGCTimer* _gc_timer;
sla@5237 140
duke@435 141 enum SomeProtectedConstants {
duke@435 142 // Generations are GenGrain-aligned and have size that are multiples of
duke@435 143 // GenGrain.
duke@435 144 MinFreeScratchWords = 100
duke@435 145 };
duke@435 146
duke@435 147 // Return the size of a survivor space if this generation were of size
duke@435 148 // gen_size.
duke@435 149 size_t compute_survivor_size(size_t gen_size, size_t alignment) const {
duke@435 150 size_t n = gen_size / (SurvivorRatio + 2);
duke@435 151 return n > alignment ? align_size_down(n, alignment) : alignment;
duke@435 152 }
duke@435 153
duke@435 154 public: // was "protected" but caused compile error on win32
duke@435 155 class IsAliveClosure: public BoolObjectClosure {
duke@435 156 Generation* _g;
duke@435 157 public:
duke@435 158 IsAliveClosure(Generation* g);
duke@435 159 bool do_object_b(oop p);
duke@435 160 };
duke@435 161
duke@435 162 class KeepAliveClosure: public OopClosure {
duke@435 163 protected:
duke@435 164 ScanWeakRefClosure* _cl;
duke@435 165 CardTableRS* _rs;
coleenp@548 166 template <class T> void do_oop_work(T* p);
duke@435 167 public:
duke@435 168 KeepAliveClosure(ScanWeakRefClosure* cl);
coleenp@548 169 virtual void do_oop(oop* p);
coleenp@548 170 virtual void do_oop(narrowOop* p);
duke@435 171 };
duke@435 172
duke@435 173 class FastKeepAliveClosure: public KeepAliveClosure {
duke@435 174 protected:
duke@435 175 HeapWord* _boundary;
coleenp@548 176 template <class T> void do_oop_work(T* p);
duke@435 177 public:
duke@435 178 FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl);
coleenp@548 179 virtual void do_oop(oop* p);
coleenp@548 180 virtual void do_oop(narrowOop* p);
duke@435 181 };
duke@435 182
duke@435 183 class EvacuateFollowersClosure: public VoidClosure {
duke@435 184 GenCollectedHeap* _gch;
duke@435 185 int _level;
duke@435 186 ScanClosure* _scan_cur_or_nonheap;
duke@435 187 ScanClosure* _scan_older;
duke@435 188 public:
duke@435 189 EvacuateFollowersClosure(GenCollectedHeap* gch, int level,
duke@435 190 ScanClosure* cur, ScanClosure* older);
duke@435 191 void do_void();
duke@435 192 };
duke@435 193
duke@435 194 class FastEvacuateFollowersClosure: public VoidClosure {
duke@435 195 GenCollectedHeap* _gch;
duke@435 196 int _level;
duke@435 197 DefNewGeneration* _gen;
duke@435 198 FastScanClosure* _scan_cur_or_nonheap;
duke@435 199 FastScanClosure* _scan_older;
duke@435 200 public:
duke@435 201 FastEvacuateFollowersClosure(GenCollectedHeap* gch, int level,
duke@435 202 DefNewGeneration* gen,
duke@435 203 FastScanClosure* cur,
duke@435 204 FastScanClosure* older);
duke@435 205 void do_void();
duke@435 206 };
duke@435 207
duke@435 208 public:
duke@435 209 DefNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level,
duke@435 210 const char* policy="Copy");
duke@435 211
sla@5237 212 virtual void ref_processor_init();
sla@5237 213
duke@435 214 virtual Generation::Name kind() { return Generation::DefNew; }
duke@435 215
duke@435 216 // Accessing spaces
duke@435 217 EdenSpace* eden() const { return _eden_space; }
duke@435 218 ContiguousSpace* from() const { return _from_space; }
duke@435 219 ContiguousSpace* to() const { return _to_space; }
duke@435 220
coleenp@548 221 virtual CompactibleSpace* first_compaction_space() const;
duke@435 222
duke@435 223 // Space enquiries
duke@435 224 size_t capacity() const;
duke@435 225 size_t used() const;
duke@435 226 size_t free() const;
duke@435 227 size_t max_capacity() const;
duke@435 228 size_t capacity_before_gc() const;
duke@435 229 size_t unsafe_max_alloc_nogc() const;
duke@435 230 size_t contiguous_available() const;
duke@435 231
duke@435 232 size_t max_eden_size() const { return _max_eden_size; }
duke@435 233 size_t max_survivor_size() const { return _max_survivor_size; }
duke@435 234
duke@435 235 bool supports_inline_contig_alloc() const { return true; }
duke@435 236 HeapWord** top_addr() const;
duke@435 237 HeapWord** end_addr() const;
duke@435 238
duke@435 239 // Thread-local allocation buffers
duke@435 240 bool supports_tlab_allocation() const { return true; }
coleenp@548 241 size_t tlab_capacity() const;
brutisso@6376 242 size_t tlab_used() const;
coleenp@548 243 size_t unsafe_max_tlab_alloc() const;
duke@435 244
duke@435 245 // Grow the generation by the specified number of bytes.
duke@435 246 // The size of bytes is assumed to be properly aligned.
duke@435 247 // Return true if the expansion was successful.
duke@435 248 bool expand(size_t bytes);
duke@435 249
duke@435 250 // DefNewGeneration cannot currently expand except at
duke@435 251 // a GC.
duke@435 252 virtual bool is_maximal_no_gc() const { return true; }
duke@435 253
duke@435 254 // Iteration
duke@435 255 void object_iterate(ObjectClosure* blk);
duke@435 256
duke@435 257 void younger_refs_iterate(OopsInGenClosure* cl);
duke@435 258
duke@435 259 void space_iterate(SpaceClosure* blk, bool usedOnly = false);
duke@435 260
duke@435 261 // Allocation support
duke@435 262 virtual bool should_allocate(size_t word_size, bool is_tlab) {
duke@435 263 assert(UseTLAB || !is_tlab, "Should not allocate tlab");
duke@435 264
duke@435 265 size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize);
duke@435 266
duke@435 267 const bool non_zero = word_size > 0;
duke@435 268 const bool overflows = word_size >= overflow_limit;
duke@435 269 const bool check_too_big = _pretenure_size_threshold_words > 0;
duke@435 270 const bool not_too_big = word_size < _pretenure_size_threshold_words;
duke@435 271 const bool size_ok = is_tlab || !check_too_big || not_too_big;
duke@435 272
duke@435 273 bool result = !overflows &&
duke@435 274 non_zero &&
duke@435 275 size_ok;
duke@435 276
duke@435 277 return result;
duke@435 278 }
duke@435 279
coleenp@548 280 HeapWord* allocate(size_t word_size, bool is_tlab);
duke@435 281 HeapWord* allocate_from_space(size_t word_size);
duke@435 282
coleenp@548 283 HeapWord* par_allocate(size_t word_size, bool is_tlab);
duke@435 284
duke@435 285 // Prologue & Epilogue
coleenp@548 286 virtual void gc_prologue(bool full);
duke@435 287 virtual void gc_epilogue(bool full);
duke@435 288
jmasa@698 289 // Save the tops for eden, from, and to
jmasa@698 290 virtual void record_spaces_top();
jmasa@698 291
duke@435 292 // Doesn't require additional work during GC prologue and epilogue
duke@435 293 virtual bool performs_in_place_marking() const { return false; }
duke@435 294
duke@435 295 // Accessing marks
duke@435 296 void save_marks();
duke@435 297 void reset_saved_marks();
duke@435 298 bool no_allocs_since_save_marks();
duke@435 299
duke@435 300 // Need to declare the full complement of closures, whether we'll
duke@435 301 // override them or not, or get message from the compiler:
duke@435 302 // oop_since_save_marks_iterate_nv hides virtual function...
duke@435 303 #define DefNew_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \
duke@435 304 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl);
duke@435 305
duke@435 306 ALL_SINCE_SAVE_MARKS_CLOSURES(DefNew_SINCE_SAVE_MARKS_DECL)
duke@435 307
duke@435 308 #undef DefNew_SINCE_SAVE_MARKS_DECL
duke@435 309
duke@435 310 // For non-youngest collection, the DefNewGeneration can contribute
duke@435 311 // "to-space".
jmasa@698 312 virtual void contribute_scratch(ScratchBlock*& list, Generation* requestor,
duke@435 313 size_t max_alloc_words);
duke@435 314
jmasa@698 315 // Reset for contribution of "to-space".
jmasa@698 316 virtual void reset_scratch();
jmasa@698 317
duke@435 318 // GC support
duke@435 319 virtual void compute_new_size();
ysr@2243 320
ysr@2243 321 // Returns true if the collection is likely to be safely
ysr@2243 322 // completed. Even if this method returns true, a collection
ysr@2243 323 // may not be guaranteed to succeed, and the system should be
ysr@2243 324 // able to safely unwind and recover from that failure, albeit
ysr@2243 325 // at some additional cost. Override superclass's implementation.
ysr@2243 326 virtual bool collection_attempt_is_safe();
ysr@2243 327
duke@435 328 virtual void collect(bool full,
duke@435 329 bool clear_all_soft_refs,
duke@435 330 size_t size,
duke@435 331 bool is_tlab);
duke@435 332 HeapWord* expand_and_allocate(size_t size,
duke@435 333 bool is_tlab,
duke@435 334 bool parallel = false);
duke@435 335
coleenp@548 336 oop copy_to_survivor_space(oop old);
jwilhelm@4129 337 uint tenuring_threshold() { return _tenuring_threshold; }
duke@435 338
duke@435 339 // Performance Counter support
duke@435 340 void update_counters();
duke@435 341
duke@435 342 // Printing
duke@435 343 virtual const char* name() const;
duke@435 344 virtual const char* short_name() const { return "DefNew"; }
duke@435 345
duke@435 346 bool must_be_youngest() const { return true; }
duke@435 347 bool must_be_oldest() const { return false; }
duke@435 348
duke@435 349 // PrintHeapAtGC support.
duke@435 350 void print_on(outputStream* st) const;
duke@435 351
brutisso@3711 352 void verify();
duke@435 353
jcoomes@2191 354 bool promo_failure_scan_is_complete() const {
jcoomes@2191 355 return _promo_failure_scan_stack.is_empty();
jcoomes@2191 356 }
jcoomes@2191 357
duke@435 358 protected:
jmasa@698 359 // If clear_space is true, clear the survivor spaces. Eden is
jmasa@698 360 // cleared if the minimum size of eden is 0. If mangle_space
jmasa@698 361 // is true, also mangle the space in debug mode.
jmasa@698 362 void compute_space_boundaries(uintx minimum_eden_size,
jmasa@698 363 bool clear_space,
jmasa@698 364 bool mangle_space);
duke@435 365 // Scavenge support
duke@435 366 void swap_spaces();
duke@435 367 };
stefank@2314 368
stefank@2314 369 #endif // SHARE_VM_MEMORY_DEFNEWGENERATION_HPP

mercurial