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