src/share/vm/memory/defNewGeneration.hpp

Wed, 13 Jan 2010 15:26:39 -0800

author
ysr
date
Wed, 13 Jan 2010 15:26:39 -0800
changeset 1601
7b0e9cba0307
parent 704
850fdf70db2b
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6896647: card marks can be deferred too long
Summary: Deferred card marks are now flushed during the gc prologue. Parallel[Scavege,OldGC] and SerialGC no longer defer card marks generated by COMPILER2 as a result of ReduceInitialCardMarks. For these cases, introduced a diagnostic option to defer the card marks, only for the purposes of testing and diagnostics. CMS and G1 continue to defer card marks. Potential performance concern related to single-threaded flushing of deferred card marks in the gc prologue will be addressed in the future.
Reviewed-by: never, johnc

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

mercurial