src/share/vm/memory/defNewGeneration.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

merge

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

mercurial