1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/defNewGeneration.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,332 @@ 1.4 +/* 1.5 + * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +class EdenSpace; 1.29 +class ContiguousSpace; 1.30 + 1.31 +// DefNewGeneration is a young generation containing eden, from- and 1.32 +// to-space. 1.33 + 1.34 +class DefNewGeneration: public Generation { 1.35 + friend class VMStructs; 1.36 + 1.37 +protected: 1.38 + Generation* _next_gen; 1.39 + int _tenuring_threshold; // Tenuring threshold for next collection. 1.40 + ageTable _age_table; 1.41 + // Size of object to pretenure in words; command line provides bytes 1.42 + size_t _pretenure_size_threshold_words; 1.43 + 1.44 + ageTable* age_table() { return &_age_table; } 1.45 + // Initialize state to optimistically assume no promotion failure will 1.46 + // happen. 1.47 + void init_assuming_no_promotion_failure(); 1.48 + // True iff a promotion has failed in the current collection. 1.49 + bool _promotion_failed; 1.50 + bool promotion_failed() { return _promotion_failed; } 1.51 + 1.52 + // Handling promotion failure. A young generation collection 1.53 + // can fail if a live object cannot be copied out of its 1.54 + // location in eden or from-space during the collection. If 1.55 + // a collection fails, the young generation is left in a 1.56 + // consistent state such that it can be collected by a 1.57 + // full collection. 1.58 + // Before the collection 1.59 + // Objects are in eden or from-space 1.60 + // All roots into the young generation point into eden or from-space. 1.61 + // 1.62 + // After a failed collection 1.63 + // Objects may be in eden, from-space, or to-space 1.64 + // An object A in eden or from-space may have a copy B 1.65 + // in to-space. If B exists, all roots that once pointed 1.66 + // to A must now point to B. 1.67 + // All objects in the young generation are unmarked. 1.68 + // Eden, from-space, and to-space will all be collected by 1.69 + // the full collection. 1.70 + void handle_promotion_failure(oop); 1.71 + 1.72 + // In the absence of promotion failure, we wouldn't look at "from-space" 1.73 + // objects after a young-gen collection. When promotion fails, however, 1.74 + // the subsequent full collection will look at from-space objects: 1.75 + // therefore we must remove their forwarding pointers. 1.76 + void remove_forwarding_pointers(); 1.77 + 1.78 + // Preserve the mark of "obj", if necessary, in preparation for its mark 1.79 + // word being overwritten with a self-forwarding-pointer. 1.80 + void preserve_mark_if_necessary(oop obj, markOop m); 1.81 + 1.82 + // When one is non-null, so is the other. Together, they each pair is 1.83 + // an object with a preserved mark, and its mark value. 1.84 + GrowableArray<oop>* _objs_with_preserved_marks; 1.85 + GrowableArray<markOop>* _preserved_marks_of_objs; 1.86 + 1.87 + // Returns true if the collection can be safely attempted. 1.88 + // If this method returns false, a collection is not 1.89 + // guaranteed to fail but the system may not be able 1.90 + // to recover from the failure. 1.91 + bool collection_attempt_is_safe(); 1.92 + 1.93 + // Promotion failure handling 1.94 + OopClosure *_promo_failure_scan_stack_closure; 1.95 + void set_promo_failure_scan_stack_closure(OopClosure *scan_stack_closure) { 1.96 + _promo_failure_scan_stack_closure = scan_stack_closure; 1.97 + } 1.98 + 1.99 + GrowableArray<oop>* _promo_failure_scan_stack; 1.100 + GrowableArray<oop>* promo_failure_scan_stack() const { 1.101 + return _promo_failure_scan_stack; 1.102 + } 1.103 + void push_on_promo_failure_scan_stack(oop); 1.104 + void drain_promo_failure_scan_stack(void); 1.105 + bool _promo_failure_drain_in_progress; 1.106 + 1.107 + // Performance Counters 1.108 + GenerationCounters* _gen_counters; 1.109 + CSpaceCounters* _eden_counters; 1.110 + CSpaceCounters* _from_counters; 1.111 + CSpaceCounters* _to_counters; 1.112 + 1.113 + // sizing information 1.114 + size_t _max_eden_size; 1.115 + size_t _max_survivor_size; 1.116 + 1.117 + // Allocation support 1.118 + bool _should_allocate_from_space; 1.119 + bool should_allocate_from_space() const { 1.120 + return _should_allocate_from_space; 1.121 + } 1.122 + void clear_should_allocate_from_space() { 1.123 + _should_allocate_from_space = false; 1.124 + } 1.125 + void set_should_allocate_from_space() { 1.126 + _should_allocate_from_space = true; 1.127 + } 1.128 + 1.129 + protected: 1.130 + // Spaces 1.131 + EdenSpace* _eden_space; 1.132 + ContiguousSpace* _from_space; 1.133 + ContiguousSpace* _to_space; 1.134 + 1.135 + enum SomeProtectedConstants { 1.136 + // Generations are GenGrain-aligned and have size that are multiples of 1.137 + // GenGrain. 1.138 + MinFreeScratchWords = 100 1.139 + }; 1.140 + 1.141 + // Return the size of a survivor space if this generation were of size 1.142 + // gen_size. 1.143 + size_t compute_survivor_size(size_t gen_size, size_t alignment) const { 1.144 + size_t n = gen_size / (SurvivorRatio + 2); 1.145 + return n > alignment ? align_size_down(n, alignment) : alignment; 1.146 + } 1.147 + 1.148 + public: // was "protected" but caused compile error on win32 1.149 + class IsAliveClosure: public BoolObjectClosure { 1.150 + Generation* _g; 1.151 + public: 1.152 + IsAliveClosure(Generation* g); 1.153 + void do_object(oop p); 1.154 + bool do_object_b(oop p); 1.155 + }; 1.156 + 1.157 + class KeepAliveClosure: public OopClosure { 1.158 + protected: 1.159 + ScanWeakRefClosure* _cl; 1.160 + CardTableRS* _rs; 1.161 + public: 1.162 + KeepAliveClosure(ScanWeakRefClosure* cl); 1.163 + void do_oop(oop* p); 1.164 + }; 1.165 + 1.166 + class FastKeepAliveClosure: public KeepAliveClosure { 1.167 + protected: 1.168 + HeapWord* _boundary; 1.169 + public: 1.170 + FastKeepAliveClosure(DefNewGeneration* g, ScanWeakRefClosure* cl); 1.171 + void do_oop(oop* p); 1.172 + }; 1.173 + 1.174 + class EvacuateFollowersClosure: public VoidClosure { 1.175 + GenCollectedHeap* _gch; 1.176 + int _level; 1.177 + ScanClosure* _scan_cur_or_nonheap; 1.178 + ScanClosure* _scan_older; 1.179 + public: 1.180 + EvacuateFollowersClosure(GenCollectedHeap* gch, int level, 1.181 + ScanClosure* cur, ScanClosure* older); 1.182 + void do_void(); 1.183 + }; 1.184 + 1.185 + class FastEvacuateFollowersClosure; 1.186 + friend class FastEvacuateFollowersClosure; 1.187 + class FastEvacuateFollowersClosure: public VoidClosure { 1.188 + GenCollectedHeap* _gch; 1.189 + int _level; 1.190 + DefNewGeneration* _gen; 1.191 + FastScanClosure* _scan_cur_or_nonheap; 1.192 + FastScanClosure* _scan_older; 1.193 + public: 1.194 + FastEvacuateFollowersClosure(GenCollectedHeap* gch, int level, 1.195 + DefNewGeneration* gen, 1.196 + FastScanClosure* cur, 1.197 + FastScanClosure* older); 1.198 + void do_void(); 1.199 + }; 1.200 + 1.201 + public: 1.202 + DefNewGeneration(ReservedSpace rs, size_t initial_byte_size, int level, 1.203 + const char* policy="Copy"); 1.204 + 1.205 + virtual Generation::Name kind() { return Generation::DefNew; } 1.206 + 1.207 + // Accessing spaces 1.208 + EdenSpace* eden() const { return _eden_space; } 1.209 + ContiguousSpace* from() const { return _from_space; } 1.210 + ContiguousSpace* to() const { return _to_space; } 1.211 + 1.212 + inline CompactibleSpace* first_compaction_space() const; 1.213 + 1.214 + // Space enquiries 1.215 + size_t capacity() const; 1.216 + size_t used() const; 1.217 + size_t free() const; 1.218 + size_t max_capacity() const; 1.219 + size_t capacity_before_gc() const; 1.220 + size_t unsafe_max_alloc_nogc() const; 1.221 + size_t contiguous_available() const; 1.222 + 1.223 + size_t max_eden_size() const { return _max_eden_size; } 1.224 + size_t max_survivor_size() const { return _max_survivor_size; } 1.225 + 1.226 + bool supports_inline_contig_alloc() const { return true; } 1.227 + HeapWord** top_addr() const; 1.228 + HeapWord** end_addr() const; 1.229 + 1.230 + // Thread-local allocation buffers 1.231 + bool supports_tlab_allocation() const { return true; } 1.232 + inline size_t tlab_capacity() const; 1.233 + inline size_t unsafe_max_tlab_alloc() const; 1.234 + 1.235 + // Grow the generation by the specified number of bytes. 1.236 + // The size of bytes is assumed to be properly aligned. 1.237 + // Return true if the expansion was successful. 1.238 + bool expand(size_t bytes); 1.239 + 1.240 + // DefNewGeneration cannot currently expand except at 1.241 + // a GC. 1.242 + virtual bool is_maximal_no_gc() const { return true; } 1.243 + 1.244 + // Iteration 1.245 + void object_iterate(ObjectClosure* blk); 1.246 + void object_iterate_since_last_GC(ObjectClosure* cl); 1.247 + 1.248 + void younger_refs_iterate(OopsInGenClosure* cl); 1.249 + 1.250 + void space_iterate(SpaceClosure* blk, bool usedOnly = false); 1.251 + 1.252 + // Allocation support 1.253 + virtual bool should_allocate(size_t word_size, bool is_tlab) { 1.254 + assert(UseTLAB || !is_tlab, "Should not allocate tlab"); 1.255 + 1.256 + size_t overflow_limit = (size_t)1 << (BitsPerSize_t - LogHeapWordSize); 1.257 + 1.258 + const bool non_zero = word_size > 0; 1.259 + const bool overflows = word_size >= overflow_limit; 1.260 + const bool check_too_big = _pretenure_size_threshold_words > 0; 1.261 + const bool not_too_big = word_size < _pretenure_size_threshold_words; 1.262 + const bool size_ok = is_tlab || !check_too_big || not_too_big; 1.263 + 1.264 + bool result = !overflows && 1.265 + non_zero && 1.266 + size_ok; 1.267 + 1.268 + return result; 1.269 + } 1.270 + 1.271 + inline HeapWord* allocate(size_t word_size, bool is_tlab); 1.272 + HeapWord* allocate_from_space(size_t word_size); 1.273 + 1.274 + inline HeapWord* par_allocate(size_t word_size, bool is_tlab); 1.275 + 1.276 + // Prologue & Epilogue 1.277 + inline virtual void gc_prologue(bool full); 1.278 + virtual void gc_epilogue(bool full); 1.279 + 1.280 + // Doesn't require additional work during GC prologue and epilogue 1.281 + virtual bool performs_in_place_marking() const { return false; } 1.282 + 1.283 + // Accessing marks 1.284 + void save_marks(); 1.285 + void reset_saved_marks(); 1.286 + bool no_allocs_since_save_marks(); 1.287 + 1.288 + // Need to declare the full complement of closures, whether we'll 1.289 + // override them or not, or get message from the compiler: 1.290 + // oop_since_save_marks_iterate_nv hides virtual function... 1.291 +#define DefNew_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ 1.292 + void oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl); 1.293 + 1.294 + ALL_SINCE_SAVE_MARKS_CLOSURES(DefNew_SINCE_SAVE_MARKS_DECL) 1.295 + 1.296 +#undef DefNew_SINCE_SAVE_MARKS_DECL 1.297 + 1.298 + // For non-youngest collection, the DefNewGeneration can contribute 1.299 + // "to-space". 1.300 + void contribute_scratch(ScratchBlock*& list, Generation* requestor, 1.301 + size_t max_alloc_words); 1.302 + 1.303 + // GC support 1.304 + virtual void compute_new_size(); 1.305 + virtual void collect(bool full, 1.306 + bool clear_all_soft_refs, 1.307 + size_t size, 1.308 + bool is_tlab); 1.309 + HeapWord* expand_and_allocate(size_t size, 1.310 + bool is_tlab, 1.311 + bool parallel = false); 1.312 + 1.313 + oop copy_to_survivor_space(oop old, oop* from); 1.314 + int tenuring_threshold() { return _tenuring_threshold; } 1.315 + 1.316 + // Performance Counter support 1.317 + void update_counters(); 1.318 + 1.319 + // Printing 1.320 + virtual const char* name() const; 1.321 + virtual const char* short_name() const { return "DefNew"; } 1.322 + 1.323 + bool must_be_youngest() const { return true; } 1.324 + bool must_be_oldest() const { return false; } 1.325 + 1.326 + // PrintHeapAtGC support. 1.327 + void print_on(outputStream* st) const; 1.328 + 1.329 + void verify(bool allow_dirty); 1.330 + 1.331 + protected: 1.332 + void compute_space_boundaries(uintx minimum_eden_size); 1.333 + // Scavenge support 1.334 + void swap_spaces(); 1.335 +};