annotate src/share/vm/memory/defNewGeneration.hpp @ 196:d1605aabd0a1

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