Mercurial > hg > truffle
annotate src/share/vm/memory/space.hpp @ 347:60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
Summary: Initialize the field correctly in ContiguousSpace's constructor and initialize() methods, using the latter for the survivor spaces upon initial construction or a subsequent resizing of the young generation. Add some missing Space sub-class constructors.
Reviewed-by: apetrusenko
author | ysr |
---|---|
date | Mon, 23 Jun 2008 16:49:37 -0700 |
parents | 37f87013dfd8 |
children | 1ee8caae33af |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1997-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 // A space is an abstraction for the "storage units" backing | |
26 // up the generation abstraction. It includes specific | |
27 // implementations for keeping track of free and used space, | |
28 // for iterating over objects and free blocks, etc. | |
29 | |
30 // Here's the Space hierarchy: | |
31 // | |
32 // - Space -- an asbtract base class describing a heap area | |
33 // - CompactibleSpace -- a space supporting compaction | |
34 // - CompactibleFreeListSpace -- (used for CMS generation) | |
35 // - ContiguousSpace -- a compactible space in which all free space | |
36 // is contiguous | |
37 // - EdenSpace -- contiguous space used as nursery | |
38 // - ConcEdenSpace -- contiguous space with a 'soft end safe' allocation | |
39 // - OffsetTableContigSpace -- contiguous space with a block offset array | |
40 // that allows "fast" block_start calls | |
41 // - TenuredSpace -- (used for TenuredGeneration) | |
42 // - ContigPermSpace -- an offset table contiguous space for perm gen | |
43 | |
44 // Forward decls. | |
45 class Space; | |
46 class BlockOffsetArray; | |
47 class BlockOffsetArrayContigSpace; | |
48 class Generation; | |
49 class CompactibleSpace; | |
50 class BlockOffsetTable; | |
51 class GenRemSet; | |
52 class CardTableRS; | |
53 class DirtyCardToOopClosure; | |
54 | |
55 // An oop closure that is circumscribed by a filtering memory region. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
56 class SpaceMemRegionOopsIterClosure: public OopClosure { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
57 private: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
58 OopClosure* _cl; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
59 MemRegion _mr; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
60 protected: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
61 template <class T> void do_oop_work(T* p) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
62 if (_mr.contains(p)) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
63 _cl->do_oop(p); |
0 | 64 } |
65 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
66 public: |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
67 SpaceMemRegionOopsIterClosure(OopClosure* cl, MemRegion mr): |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
68 _cl(cl), _mr(mr) {} |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
69 virtual void do_oop(oop* p); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
70 virtual void do_oop(narrowOop* p); |
0 | 71 }; |
72 | |
73 // A Space describes a heap area. Class Space is an abstract | |
74 // base class. | |
75 // | |
76 // Space supports allocation, size computation and GC support is provided. | |
77 // | |
78 // Invariant: bottom() and end() are on page_size boundaries and | |
79 // bottom() <= top() <= end() | |
80 // top() is inclusive and end() is exclusive. | |
81 | |
82 class Space: public CHeapObj { | |
83 friend class VMStructs; | |
84 protected: | |
85 HeapWord* _bottom; | |
86 HeapWord* _end; | |
87 | |
88 // Used in support of save_marks() | |
89 HeapWord* _saved_mark_word; | |
90 | |
91 MemRegionClosure* _preconsumptionDirtyCardClosure; | |
92 | |
93 // A sequential tasks done structure. This supports | |
94 // parallel GC, where we have threads dynamically | |
95 // claiming sub-tasks from a larger parallel task. | |
96 SequentialSubTasksDone _par_seq_tasks; | |
97 | |
98 Space(): | |
99 _bottom(NULL), _end(NULL), _preconsumptionDirtyCardClosure(NULL) { } | |
100 | |
101 public: | |
102 // Accessors | |
103 HeapWord* bottom() const { return _bottom; } | |
104 HeapWord* end() const { return _end; } | |
105 virtual void set_bottom(HeapWord* value) { _bottom = value; } | |
106 virtual void set_end(HeapWord* value) { _end = value; } | |
107 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
108 virtual HeapWord* saved_mark_word() const { return _saved_mark_word; } |
0 | 109 void set_saved_mark_word(HeapWord* p) { _saved_mark_word = p; } |
110 | |
111 MemRegionClosure* preconsumptionDirtyCardClosure() const { | |
112 return _preconsumptionDirtyCardClosure; | |
113 } | |
114 void setPreconsumptionDirtyCardClosure(MemRegionClosure* cl) { | |
115 _preconsumptionDirtyCardClosure = cl; | |
116 } | |
117 | |
118 // Returns a subregion of the space containing all the objects in | |
119 // the space. | |
120 virtual MemRegion used_region() const { return MemRegion(bottom(), end()); } | |
121 | |
122 // Returns a region that is guaranteed to contain (at least) all objects | |
123 // allocated at the time of the last call to "save_marks". If the space | |
124 // initializes its DirtyCardToOopClosure's specifying the "contig" option | |
125 // (that is, if the space is contiguous), then this region must contain only | |
126 // such objects: the memregion will be from the bottom of the region to the | |
127 // saved mark. Otherwise, the "obj_allocated_since_save_marks" method of | |
128 // the space must distiguish between objects in the region allocated before | |
129 // and after the call to save marks. | |
130 virtual MemRegion used_region_at_save_marks() const { | |
131 return MemRegion(bottom(), saved_mark_word()); | |
132 } | |
133 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
134 // Initialization. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
135 // "initialize" should be called once on a space, before it is used for |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
136 // any purpose. The "mr" arguments gives the bounds of the space, and |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
137 // the "clear_space" argument should be true unless the memory in "mr" is |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
138 // known to be zeroed. |
0 | 139 virtual void initialize(MemRegion mr, bool clear_space); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
140 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
141 // Sets the bounds (bottom and end) of the current space to those of "mr." |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
142 void set_bounds(MemRegion mr); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
143 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
144 // The "clear" method must be called on a region that may have |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
145 // had allocation performed in it, but is now to be considered empty. |
0 | 146 virtual void clear(); |
147 | |
148 // For detecting GC bugs. Should only be called at GC boundaries, since | |
149 // some unused space may be used as scratch space during GC's. | |
150 // Default implementation does nothing. We also call this when expanding | |
151 // a space to satisfy an allocation request. See bug #4668531 | |
152 virtual void mangle_unused_area() {} | |
153 virtual void mangle_region(MemRegion mr) {} | |
154 | |
155 // Testers | |
156 bool is_empty() const { return used() == 0; } | |
157 bool not_empty() const { return used() > 0; } | |
158 | |
159 // Returns true iff the given the space contains the | |
160 // given address as part of an allocated object. For | |
161 // ceratin kinds of spaces, this might be a potentially | |
162 // expensive operation. To prevent performance problems | |
163 // on account of its inadvertent use in product jvm's, | |
164 // we restrict its use to assertion checks only. | |
165 virtual bool is_in(const void* p) const; | |
166 | |
167 // Returns true iff the given reserved memory of the space contains the | |
168 // given address. | |
169 bool is_in_reserved(const void* p) const { return _bottom <= p && p < _end; } | |
170 | |
171 // Returns true iff the given block is not allocated. | |
172 virtual bool is_free_block(const HeapWord* p) const = 0; | |
173 | |
174 // Test whether p is double-aligned | |
175 static bool is_aligned(void* p) { | |
176 return ((intptr_t)p & (sizeof(double)-1)) == 0; | |
177 } | |
178 | |
179 // Size computations. Sizes are in bytes. | |
180 size_t capacity() const { return byte_size(bottom(), end()); } | |
181 virtual size_t used() const = 0; | |
182 virtual size_t free() const = 0; | |
183 | |
184 // Iterate over all the ref-containing fields of all objects in the | |
185 // space, calling "cl.do_oop" on each. Fields in objects allocated by | |
186 // applications of the closure are not included in the iteration. | |
187 virtual void oop_iterate(OopClosure* cl); | |
188 | |
189 // Same as above, restricted to the intersection of a memory region and | |
190 // the space. Fields in objects allocated by applications of the closure | |
191 // are not included in the iteration. | |
192 virtual void oop_iterate(MemRegion mr, OopClosure* cl) = 0; | |
193 | |
194 // Iterate over all objects in the space, calling "cl.do_object" on | |
195 // each. Objects allocated by applications of the closure are not | |
196 // included in the iteration. | |
197 virtual void object_iterate(ObjectClosure* blk) = 0; | |
198 | |
199 // Iterate over all objects that intersect with mr, calling "cl->do_object" | |
200 // on each. There is an exception to this: if this closure has already | |
201 // been invoked on an object, it may skip such objects in some cases. This is | |
202 // Most likely to happen in an "upwards" (ascending address) iteration of | |
203 // MemRegions. | |
204 virtual void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl); | |
205 | |
206 // Iterate over as many initialized objects in the space as possible, | |
207 // calling "cl.do_object_careful" on each. Return NULL if all objects | |
208 // in the space (at the start of the iteration) were iterated over. | |
209 // Return an address indicating the extent of the iteration in the | |
210 // event that the iteration had to return because of finding an | |
211 // uninitialized object in the space, or if the closure "cl" | |
212 // signalled early termination. | |
213 virtual HeapWord* object_iterate_careful(ObjectClosureCareful* cl); | |
214 virtual HeapWord* object_iterate_careful_m(MemRegion mr, | |
215 ObjectClosureCareful* cl); | |
216 | |
217 // Create and return a new dirty card to oop closure. Can be | |
218 // overriden to return the appropriate type of closure | |
219 // depending on the type of space in which the closure will | |
220 // operate. ResourceArea allocated. | |
221 virtual DirtyCardToOopClosure* new_dcto_cl(OopClosure* cl, | |
222 CardTableModRefBS::PrecisionStyle precision, | |
223 HeapWord* boundary = NULL); | |
224 | |
225 // If "p" is in the space, returns the address of the start of the | |
226 // "block" that contains "p". We say "block" instead of "object" since | |
227 // some heaps may not pack objects densely; a chunk may either be an | |
228 // object or a non-object. If "p" is not in the space, return NULL. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
229 virtual HeapWord* block_start_const(const void* p) const = 0; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
230 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
231 // The non-const version may have benevolent side effects on the data |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
232 // structure supporting these calls, possibly speeding up future calls. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
233 // The default implementation, however, is simply to call the const |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
234 // version. |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
235 inline virtual HeapWord* block_start(const void* p); |
0 | 236 |
237 // Requires "addr" to be the start of a chunk, and returns its size. | |
238 // "addr + size" is required to be the start of a new chunk, or the end | |
239 // of the active area of the heap. | |
240 virtual size_t block_size(const HeapWord* addr) const = 0; | |
241 | |
242 // Requires "addr" to be the start of a block, and returns "TRUE" iff | |
243 // the block is an object. | |
244 virtual bool block_is_obj(const HeapWord* addr) const = 0; | |
245 | |
246 // Requires "addr" to be the start of a block, and returns "TRUE" iff | |
247 // the block is an object and the object is alive. | |
248 virtual bool obj_is_alive(const HeapWord* addr) const; | |
249 | |
250 // Allocation (return NULL if full). Assumes the caller has established | |
251 // mutually exclusive access to the space. | |
252 virtual HeapWord* allocate(size_t word_size) = 0; | |
253 | |
254 // Allocation (return NULL if full). Enforces mutual exclusion internally. | |
255 virtual HeapWord* par_allocate(size_t word_size) = 0; | |
256 | |
257 // Returns true if this object has been allocated since a | |
258 // generation's "save_marks" call. | |
259 virtual bool obj_allocated_since_save_marks(const oop obj) const = 0; | |
260 | |
261 // Mark-sweep-compact support: all spaces can update pointers to objects | |
262 // moving as a part of compaction. | |
263 virtual void adjust_pointers(); | |
264 | |
265 // PrintHeapAtGC support | |
266 virtual void print() const; | |
267 virtual void print_on(outputStream* st) const; | |
268 virtual void print_short() const; | |
269 virtual void print_short_on(outputStream* st) const; | |
270 | |
271 | |
272 // Accessor for parallel sequential tasks. | |
273 SequentialSubTasksDone* par_seq_tasks() { return &_par_seq_tasks; } | |
274 | |
275 // IF "this" is a ContiguousSpace, return it, else return NULL. | |
276 virtual ContiguousSpace* toContiguousSpace() { | |
277 return NULL; | |
278 } | |
279 | |
280 // Debugging | |
281 virtual void verify(bool allow_dirty) const = 0; | |
282 }; | |
283 | |
284 // A MemRegionClosure (ResourceObj) whose "do_MemRegion" function applies an | |
285 // OopClosure to (the addresses of) all the ref-containing fields that could | |
286 // be modified by virtue of the given MemRegion being dirty. (Note that | |
287 // because of the imprecise nature of the write barrier, this may iterate | |
288 // over oops beyond the region.) | |
289 // This base type for dirty card to oop closures handles memory regions | |
290 // in non-contiguous spaces with no boundaries, and should be sub-classed | |
291 // to support other space types. See ContiguousDCTOC for a sub-class | |
292 // that works with ContiguousSpaces. | |
293 | |
294 class DirtyCardToOopClosure: public MemRegionClosureRO { | |
295 protected: | |
296 OopClosure* _cl; | |
297 Space* _sp; | |
298 CardTableModRefBS::PrecisionStyle _precision; | |
299 HeapWord* _boundary; // If non-NULL, process only non-NULL oops | |
300 // pointing below boundary. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
301 HeapWord* _min_done; // ObjHeadPreciseArray precision requires |
0 | 302 // a downwards traversal; this is the |
303 // lowest location already done (or, | |
304 // alternatively, the lowest address that | |
305 // shouldn't be done again. NULL means infinity.) | |
306 NOT_PRODUCT(HeapWord* _last_bottom;) | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
307 NOT_PRODUCT(HeapWord* _last_explicit_min_done;) |
0 | 308 |
309 // Get the actual top of the area on which the closure will | |
310 // operate, given where the top is assumed to be (the end of the | |
311 // memory region passed to do_MemRegion) and where the object | |
312 // at the top is assumed to start. For example, an object may | |
313 // start at the top but actually extend past the assumed top, | |
314 // in which case the top becomes the end of the object. | |
315 virtual HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj); | |
316 | |
317 // Walk the given memory region from bottom to (actual) top | |
318 // looking for objects and applying the oop closure (_cl) to | |
319 // them. The base implementation of this treats the area as | |
320 // blocks, where a block may or may not be an object. Sub- | |
321 // classes should override this to provide more accurate | |
322 // or possibly more efficient walking. | |
323 virtual void walk_mem_region(MemRegion mr, HeapWord* bottom, HeapWord* top); | |
324 | |
325 public: | |
326 DirtyCardToOopClosure(Space* sp, OopClosure* cl, | |
327 CardTableModRefBS::PrecisionStyle precision, | |
328 HeapWord* boundary) : | |
329 _sp(sp), _cl(cl), _precision(precision), _boundary(boundary), | |
330 _min_done(NULL) { | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
331 NOT_PRODUCT(_last_bottom = NULL); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
332 NOT_PRODUCT(_last_explicit_min_done = NULL); |
0 | 333 } |
334 | |
335 void do_MemRegion(MemRegion mr); | |
336 | |
337 void set_min_done(HeapWord* min_done) { | |
338 _min_done = min_done; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
339 NOT_PRODUCT(_last_explicit_min_done = _min_done); |
0 | 340 } |
341 #ifndef PRODUCT | |
342 void set_last_bottom(HeapWord* last_bottom) { | |
343 _last_bottom = last_bottom; | |
344 } | |
345 #endif | |
346 }; | |
347 | |
348 // A structure to represent a point at which objects are being copied | |
349 // during compaction. | |
350 class CompactPoint : public StackObj { | |
351 public: | |
352 Generation* gen; | |
353 CompactibleSpace* space; | |
354 HeapWord* threshold; | |
355 CompactPoint(Generation* _gen, CompactibleSpace* _space, | |
356 HeapWord* _threshold) : | |
357 gen(_gen), space(_space), threshold(_threshold) {} | |
358 }; | |
359 | |
360 | |
361 // A space that supports compaction operations. This is usually, but not | |
362 // necessarily, a space that is normally contiguous. But, for example, a | |
363 // free-list-based space whose normal collection is a mark-sweep without | |
364 // compaction could still support compaction in full GC's. | |
365 | |
366 class CompactibleSpace: public Space { | |
367 friend class VMStructs; | |
368 friend class CompactibleFreeListSpace; | |
369 friend class CompactingPermGenGen; | |
370 friend class CMSPermGenGen; | |
371 private: | |
372 HeapWord* _compaction_top; | |
373 CompactibleSpace* _next_compaction_space; | |
374 | |
375 public: | |
347
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
376 CompactibleSpace() : |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
377 _compaction_top(NULL), _next_compaction_space(NULL) {} |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
378 |
0 | 379 virtual void initialize(MemRegion mr, bool clear_space); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
380 virtual void clear(); |
0 | 381 |
382 // Used temporarily during a compaction phase to hold the value | |
383 // top should have when compaction is complete. | |
384 HeapWord* compaction_top() const { return _compaction_top; } | |
385 | |
386 void set_compaction_top(HeapWord* value) { | |
387 assert(value == NULL || (value >= bottom() && value <= end()), | |
388 "should point inside space"); | |
389 _compaction_top = value; | |
390 } | |
391 | |
392 // Perform operations on the space needed after a compaction | |
393 // has been performed. | |
394 virtual void reset_after_compaction() {} | |
395 | |
396 // Returns the next space (in the current generation) to be compacted in | |
397 // the global compaction order. Also is used to select the next | |
398 // space into which to compact. | |
399 | |
400 virtual CompactibleSpace* next_compaction_space() const { | |
401 return _next_compaction_space; | |
402 } | |
403 | |
404 void set_next_compaction_space(CompactibleSpace* csp) { | |
405 _next_compaction_space = csp; | |
406 } | |
407 | |
408 // MarkSweep support phase2 | |
409 | |
410 // Start the process of compaction of the current space: compute | |
411 // post-compaction addresses, and insert forwarding pointers. The fields | |
412 // "cp->gen" and "cp->compaction_space" are the generation and space into | |
413 // which we are currently compacting. This call updates "cp" as necessary, | |
414 // and leaves the "compaction_top" of the final value of | |
415 // "cp->compaction_space" up-to-date. Offset tables may be updated in | |
416 // this phase as if the final copy had occurred; if so, "cp->threshold" | |
417 // indicates when the next such action should be taken. | |
418 virtual void prepare_for_compaction(CompactPoint* cp); | |
419 // MarkSweep support phase3 | |
420 virtual void adjust_pointers(); | |
421 // MarkSweep support phase4 | |
422 virtual void compact(); | |
423 | |
424 // The maximum percentage of objects that can be dead in the compacted | |
425 // live part of a compacted space ("deadwood" support.) | |
426 virtual int allowed_dead_ratio() const { return 0; }; | |
427 | |
428 // Some contiguous spaces may maintain some data structures that should | |
429 // be updated whenever an allocation crosses a boundary. This function | |
430 // returns the first such boundary. | |
431 // (The default implementation returns the end of the space, so the | |
432 // boundary is never crossed.) | |
433 virtual HeapWord* initialize_threshold() { return end(); } | |
434 | |
435 // "q" is an object of the given "size" that should be forwarded; | |
436 // "cp" names the generation ("gen") and containing "this" (which must | |
437 // also equal "cp->space"). "compact_top" is where in "this" the | |
438 // next object should be forwarded to. If there is room in "this" for | |
439 // the object, insert an appropriate forwarding pointer in "q". | |
440 // If not, go to the next compaction space (there must | |
441 // be one, since compaction must succeed -- we go to the first space of | |
442 // the previous generation if necessary, updating "cp"), reset compact_top | |
443 // and then forward. In either case, returns the new value of "compact_top". | |
444 // If the forwarding crosses "cp->threshold", invokes the "cross_threhold" | |
445 // function of the then-current compaction space, and updates "cp->threshold | |
446 // accordingly". | |
447 virtual HeapWord* forward(oop q, size_t size, CompactPoint* cp, | |
448 HeapWord* compact_top); | |
449 | |
450 // Return a size with adjusments as required of the space. | |
451 virtual size_t adjust_object_size_v(size_t size) const { return size; } | |
452 | |
453 protected: | |
454 // Used during compaction. | |
455 HeapWord* _first_dead; | |
456 HeapWord* _end_of_live; | |
457 | |
458 // Minimum size of a free block. | |
459 virtual size_t minimum_free_block_size() const = 0; | |
460 | |
461 // This the function is invoked when an allocation of an object covering | |
462 // "start" to "end occurs crosses the threshold; returns the next | |
463 // threshold. (The default implementation does nothing.) | |
464 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* the_end) { | |
465 return end(); | |
466 } | |
467 | |
468 // Requires "allowed_deadspace_words > 0", that "q" is the start of a | |
469 // free block of the given "word_len", and that "q", were it an object, | |
470 // would not move if forwared. If the size allows, fill the free | |
471 // block with an object, to prevent excessive compaction. Returns "true" | |
472 // iff the free region was made deadspace, and modifies | |
473 // "allowed_deadspace_words" to reflect the number of available deadspace | |
474 // words remaining after this operation. | |
475 bool insert_deadspace(size_t& allowed_deadspace_words, HeapWord* q, | |
476 size_t word_len); | |
477 }; | |
478 | |
479 #define SCAN_AND_FORWARD(cp,scan_limit,block_is_obj,block_size) { \ | |
480 /* Compute the new addresses for the live objects and store it in the mark \ | |
481 * Used by universe::mark_sweep_phase2() \ | |
482 */ \ | |
483 HeapWord* compact_top; /* This is where we are currently compacting to. */ \ | |
484 \ | |
485 /* We're sure to be here before any objects are compacted into this \ | |
486 * space, so this is a good time to initialize this: \ | |
487 */ \ | |
488 set_compaction_top(bottom()); \ | |
489 \ | |
490 if (cp->space == NULL) { \ | |
491 assert(cp->gen != NULL, "need a generation"); \ | |
492 assert(cp->threshold == NULL, "just checking"); \ | |
493 assert(cp->gen->first_compaction_space() == this, "just checking"); \ | |
494 cp->space = cp->gen->first_compaction_space(); \ | |
495 compact_top = cp->space->bottom(); \ | |
496 cp->space->set_compaction_top(compact_top); \ | |
497 cp->threshold = cp->space->initialize_threshold(); \ | |
498 } else { \ | |
499 compact_top = cp->space->compaction_top(); \ | |
500 } \ | |
501 \ | |
502 /* We allow some amount of garbage towards the bottom of the space, so \ | |
503 * we don't start compacting before there is a significant gain to be made.\ | |
504 * Occasionally, we want to ensure a full compaction, which is determined \ | |
505 * by the MarkSweepAlwaysCompactCount parameter. \ | |
506 */ \ | |
507 int invocations = SharedHeap::heap()->perm_gen()->stat_record()->invocations;\ | |
508 bool skip_dead = ((invocations % MarkSweepAlwaysCompactCount) != 0); \ | |
509 \ | |
510 size_t allowed_deadspace = 0; \ | |
511 if (skip_dead) { \ | |
512 int ratio = allowed_dead_ratio(); \ | |
513 allowed_deadspace = (capacity() * ratio / 100) / HeapWordSize; \ | |
514 } \ | |
515 \ | |
516 HeapWord* q = bottom(); \ | |
517 HeapWord* t = scan_limit(); \ | |
518 \ | |
519 HeapWord* end_of_live= q; /* One byte beyond the last byte of the last \ | |
520 live object. */ \ | |
521 HeapWord* first_dead = end();/* The first dead object. */ \ | |
522 LiveRange* liveRange = NULL; /* The current live range, recorded in the \ | |
523 first header of preceding free area. */ \ | |
524 _first_dead = first_dead; \ | |
525 \ | |
526 const intx interval = PrefetchScanIntervalInBytes; \ | |
527 \ | |
528 while (q < t) { \ | |
529 assert(!block_is_obj(q) || \ | |
530 oop(q)->mark()->is_marked() || oop(q)->mark()->is_unlocked() || \ | |
531 oop(q)->mark()->has_bias_pattern(), \ | |
532 "these are the only valid states during a mark sweep"); \ | |
533 if (block_is_obj(q) && oop(q)->is_gc_marked()) { \ | |
534 /* prefetch beyond q */ \ | |
535 Prefetch::write(q, interval); \ | |
536 /* size_t size = oop(q)->size(); changing this for cms for perm gen */\ | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
537 size_t size = block_size(q); \ |
0 | 538 compact_top = cp->space->forward(oop(q), size, cp, compact_top); \ |
539 q += size; \ | |
540 end_of_live = q; \ | |
541 } else { \ | |
542 /* run over all the contiguous dead objects */ \ | |
543 HeapWord* end = q; \ | |
544 do { \ | |
545 /* prefetch beyond end */ \ | |
546 Prefetch::write(end, interval); \ | |
547 end += block_size(end); \ | |
548 } while (end < t && (!block_is_obj(end) || !oop(end)->is_gc_marked()));\ | |
549 \ | |
550 /* see if we might want to pretend this object is alive so that \ | |
551 * we don't have to compact quite as often. \ | |
552 */ \ | |
553 if (allowed_deadspace > 0 && q == compact_top) { \ | |
554 size_t sz = pointer_delta(end, q); \ | |
555 if (insert_deadspace(allowed_deadspace, q, sz)) { \ | |
556 compact_top = cp->space->forward(oop(q), sz, cp, compact_top); \ | |
557 q = end; \ | |
558 end_of_live = end; \ | |
559 continue; \ | |
560 } \ | |
561 } \ | |
562 \ | |
563 /* otherwise, it really is a free region. */ \ | |
564 \ | |
565 /* for the previous LiveRange, record the end of the live objects. */ \ | |
566 if (liveRange) { \ | |
567 liveRange->set_end(q); \ | |
568 } \ | |
569 \ | |
570 /* record the current LiveRange object. \ | |
571 * liveRange->start() is overlaid on the mark word. \ | |
572 */ \ | |
573 liveRange = (LiveRange*)q; \ | |
574 liveRange->set_start(end); \ | |
575 liveRange->set_end(end); \ | |
576 \ | |
577 /* see if this is the first dead region. */ \ | |
578 if (q < first_dead) { \ | |
579 first_dead = q; \ | |
580 } \ | |
581 \ | |
582 /* move on to the next object */ \ | |
583 q = end; \ | |
584 } \ | |
585 } \ | |
586 \ | |
587 assert(q == t, "just checking"); \ | |
588 if (liveRange != NULL) { \ | |
589 liveRange->set_end(q); \ | |
590 } \ | |
591 _end_of_live = end_of_live; \ | |
592 if (end_of_live < first_dead) { \ | |
593 first_dead = end_of_live; \ | |
594 } \ | |
595 _first_dead = first_dead; \ | |
596 \ | |
597 /* save the compaction_top of the compaction space. */ \ | |
598 cp->space->set_compaction_top(compact_top); \ | |
599 } | |
600 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
601 #define SCAN_AND_ADJUST_POINTERS(adjust_obj_size) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
602 /* adjust all the interior pointers to point at the new locations of objects \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
603 * Used by MarkSweep::mark_sweep_phase3() */ \ |
0 | 604 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
605 HeapWord* q = bottom(); \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
606 HeapWord* t = _end_of_live; /* Established by "prepare_for_compaction". */ \ |
0 | 607 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
608 assert(_first_dead <= _end_of_live, "Stands to reason, no?"); \ |
0 | 609 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
610 if (q < t && _first_dead > q && \ |
0 | 611 !oop(q)->is_gc_marked()) { \ |
612 /* we have a chunk of the space which hasn't moved and we've \ | |
613 * reinitialized the mark word during the previous pass, so we can't \ | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
614 * use is_gc_marked for the traversal. */ \ |
0 | 615 HeapWord* end = _first_dead; \ |
616 \ | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
617 while (q < end) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
618 /* I originally tried to conjoin "block_start(q) == q" to the \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
619 * assertion below, but that doesn't work, because you can't \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
620 * accurately traverse previous objects to get to the current one \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
621 * after their pointers (including pointers into permGen) have been \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
622 * updated, until the actual compaction is done. dld, 4/00 */ \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
623 assert(block_is_obj(q), \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
624 "should be at block boundaries, and should be looking at objs"); \ |
0 | 625 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
626 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q))); \ |
0 | 627 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
628 /* point all the oops to the new location */ \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
629 size_t size = oop(q)->adjust_pointers(); \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
630 size = adjust_obj_size(size); \ |
0 | 631 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
632 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers()); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
633 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
634 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size)); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
635 \ |
0 | 636 q += size; \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
637 } \ |
0 | 638 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
639 if (_first_dead == t) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
640 q = t; \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
641 } else { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
642 /* $$$ This is funky. Using this to read the previously written \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
643 * LiveRange. See also use below. */ \ |
0 | 644 q = (HeapWord*)oop(_first_dead)->mark()->decode_pointer(); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
645 } \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
646 } \ |
0 | 647 \ |
648 const intx interval = PrefetchScanIntervalInBytes; \ | |
649 \ | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
650 debug_only(HeapWord* prev_q = NULL); \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
651 while (q < t) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
652 /* prefetch beyond q */ \ |
0 | 653 Prefetch::write(q, interval); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
654 if (oop(q)->is_gc_marked()) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
655 /* q is alive */ \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
656 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q))); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
657 /* point all the oops to the new location */ \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
658 size_t size = oop(q)->adjust_pointers(); \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
659 size = adjust_obj_size(size); \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
660 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers()); \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
661 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size)); \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
662 debug_only(prev_q = q); \ |
0 | 663 q += size; \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
664 } else { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
665 /* q is not a live object, so its mark should point at the next \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
666 * live object */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
667 debug_only(prev_q = q); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
668 q = (HeapWord*) oop(q)->mark()->decode_pointer(); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
669 assert(q > prev_q, "we should be moving forward through memory"); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
670 } \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
671 } \ |
0 | 672 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
673 assert(q == t, "just checking"); \ |
0 | 674 } |
675 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
676 #define SCAN_AND_COMPACT(obj_size) { \ |
0 | 677 /* Copy all live objects to their new location \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
678 * Used by MarkSweep::mark_sweep_phase4() */ \ |
0 | 679 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
680 HeapWord* q = bottom(); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
681 HeapWord* const t = _end_of_live; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
682 debug_only(HeapWord* prev_q = NULL); \ |
0 | 683 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
684 if (q < t && _first_dead > q && \ |
0 | 685 !oop(q)->is_gc_marked()) { \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
686 debug_only( \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
687 /* we have a chunk of the space which hasn't moved and we've reinitialized \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
688 * the mark word during the previous pass, so we can't use is_gc_marked for \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
689 * the traversal. */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
690 HeapWord* const end = _first_dead; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
691 \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
692 while (q < end) { \ |
0 | 693 size_t size = obj_size(q); \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
694 assert(!oop(q)->is_gc_marked(), \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
695 "should be unmarked (special dense prefix handling)"); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
696 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, q)); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
697 debug_only(prev_q = q); \ |
0 | 698 q += size; \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
699 } \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
700 ) /* debug_only */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
701 \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
702 if (_first_dead == t) { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
703 q = t; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
704 } else { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
705 /* $$$ Funky */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
706 q = (HeapWord*) oop(_first_dead)->mark()->decode_pointer(); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
707 } \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
708 } \ |
0 | 709 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
710 const intx scan_interval = PrefetchScanIntervalInBytes; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
711 const intx copy_interval = PrefetchCopyIntervalInBytes; \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
712 while (q < t) { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
713 if (!oop(q)->is_gc_marked()) { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
714 /* mark is pointer to next marked oop */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
715 debug_only(prev_q = q); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
716 q = (HeapWord*) oop(q)->mark()->decode_pointer(); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
717 assert(q > prev_q, "we should be moving forward through memory"); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
718 } else { \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
719 /* prefetch beyond q */ \ |
0 | 720 Prefetch::read(q, scan_interval); \ |
721 \ | |
722 /* size and destination */ \ | |
723 size_t size = obj_size(q); \ | |
724 HeapWord* compaction_top = (HeapWord*)oop(q)->forwardee(); \ | |
725 \ | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
726 /* prefetch beyond compaction_top */ \ |
0 | 727 Prefetch::write(compaction_top, copy_interval); \ |
728 \ | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
729 /* copy object and reinit its mark */ \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
730 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::live_oop_moved_to(q, size, \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
731 compaction_top)); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
732 assert(q != compaction_top, "everything in this pass should be moving"); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
733 Copy::aligned_conjoint_words(q, compaction_top, size); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
734 oop(compaction_top)->init_mark(); \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
735 assert(oop(compaction_top)->klass() != NULL, "should have a class"); \ |
0 | 736 \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
737 debug_only(prev_q = q); \ |
0 | 738 q += size; \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
739 } \ |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
740 } \ |
0 | 741 \ |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
742 /* Let's remember if we were empty before we did the compaction. */ \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
743 bool was_empty = used_region().is_empty(); \ |
0 | 744 /* Reset space after compaction is complete */ \ |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
745 reset_after_compaction(); \ |
0 | 746 /* We do this clear, below, since it has overloaded meanings for some */ \ |
747 /* space subtypes. For example, OffsetTableContigSpace's that were */ \ | |
748 /* compacted into will have had their offset table thresholds updated */ \ | |
749 /* continuously, but those that weren't need to have their thresholds */ \ | |
750 /* re-initialized. Also mangles unused area for debugging. */ \ | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
751 if (used_region().is_empty()) { \ |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
752 if (!was_empty) clear(); \ |
0 | 753 } else { \ |
754 if (ZapUnusedHeapArea) mangle_unused_area(); \ | |
755 } \ | |
756 } | |
757 | |
758 // A space in which the free area is contiguous. It therefore supports | |
759 // faster allocation, and compaction. | |
760 class ContiguousSpace: public CompactibleSpace { | |
761 friend class OneContigSpaceCardGeneration; | |
762 friend class VMStructs; | |
763 protected: | |
764 HeapWord* _top; | |
765 HeapWord* _concurrent_iteration_safe_limit; | |
766 | |
767 // Allocation helpers (return NULL if full). | |
768 inline HeapWord* allocate_impl(size_t word_size, HeapWord* end_value); | |
769 inline HeapWord* par_allocate_impl(size_t word_size, HeapWord* end_value); | |
770 | |
771 public: | |
347
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
772 ContiguousSpace() : |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
773 _top(NULL), |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
774 _concurrent_iteration_safe_limit(NULL) {} |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
775 |
0 | 776 virtual void initialize(MemRegion mr, bool clear_space); |
777 | |
778 // Accessors | |
779 HeapWord* top() const { return _top; } | |
780 void set_top(HeapWord* value) { _top = value; } | |
781 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
782 virtual void set_saved_mark() { _saved_mark_word = top(); } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
783 void reset_saved_mark() { _saved_mark_word = bottom(); } |
0 | 784 |
785 virtual void clear(); | |
786 | |
787 WaterMark bottom_mark() { return WaterMark(this, bottom()); } | |
788 WaterMark top_mark() { return WaterMark(this, top()); } | |
789 WaterMark saved_mark() { return WaterMark(this, saved_mark_word()); } | |
790 bool saved_mark_at_top() const { return saved_mark_word() == top(); } | |
791 | |
792 void mangle_unused_area(); | |
793 void mangle_region(MemRegion mr); | |
794 | |
795 // Size computations: sizes in bytes. | |
796 size_t capacity() const { return byte_size(bottom(), end()); } | |
797 size_t used() const { return byte_size(bottom(), top()); } | |
798 size_t free() const { return byte_size(top(), end()); } | |
799 | |
800 // Override from space. | |
801 bool is_in(const void* p) const; | |
802 | |
803 virtual bool is_free_block(const HeapWord* p) const; | |
804 | |
805 // In a contiguous space we have a more obvious bound on what parts | |
806 // contain objects. | |
807 MemRegion used_region() const { return MemRegion(bottom(), top()); } | |
808 | |
809 MemRegion used_region_at_save_marks() const { | |
810 return MemRegion(bottom(), saved_mark_word()); | |
811 } | |
812 | |
813 // Allocation (return NULL if full) | |
814 virtual HeapWord* allocate(size_t word_size); | |
815 virtual HeapWord* par_allocate(size_t word_size); | |
816 | |
817 virtual bool obj_allocated_since_save_marks(const oop obj) const { | |
818 return (HeapWord*)obj >= saved_mark_word(); | |
819 } | |
820 | |
821 // Iteration | |
822 void oop_iterate(OopClosure* cl); | |
823 void oop_iterate(MemRegion mr, OopClosure* cl); | |
824 void object_iterate(ObjectClosure* blk); | |
825 void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl); | |
826 // iterates on objects up to the safe limit | |
827 HeapWord* object_iterate_careful(ObjectClosureCareful* cl); | |
828 inline HeapWord* concurrent_iteration_safe_limit(); | |
829 // changes the safe limit, all objects from bottom() to the new | |
830 // limit should be properly initialized | |
831 inline void set_concurrent_iteration_safe_limit(HeapWord* new_limit); | |
832 | |
833 #ifndef SERIALGC | |
834 // In support of parallel oop_iterate. | |
835 #define ContigSpace_PAR_OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ | |
836 void par_oop_iterate(MemRegion mr, OopClosureType* blk); | |
837 | |
838 ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DECL) | |
839 #undef ContigSpace_PAR_OOP_ITERATE_DECL | |
840 #endif // SERIALGC | |
841 | |
842 // Compaction support | |
843 virtual void reset_after_compaction() { | |
844 assert(compaction_top() >= bottom() && compaction_top() <= end(), "should point inside space"); | |
845 set_top(compaction_top()); | |
846 // set new iteration safe limit | |
847 set_concurrent_iteration_safe_limit(compaction_top()); | |
848 } | |
849 virtual size_t minimum_free_block_size() const { return 0; } | |
850 | |
851 // Override. | |
852 DirtyCardToOopClosure* new_dcto_cl(OopClosure* cl, | |
853 CardTableModRefBS::PrecisionStyle precision, | |
854 HeapWord* boundary = NULL); | |
855 | |
856 // Apply "blk->do_oop" to the addresses of all reference fields in objects | |
857 // starting with the _saved_mark_word, which was noted during a generation's | |
858 // save_marks and is required to denote the head of an object. | |
859 // Fields in objects allocated by applications of the closure | |
860 // *are* included in the iteration. | |
861 // Updates _saved_mark_word to point to just after the last object | |
862 // iterated over. | |
863 #define ContigSpace_OOP_SINCE_SAVE_MARKS_DECL(OopClosureType, nv_suffix) \ | |
864 void oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk); | |
865 | |
866 ALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DECL) | |
867 #undef ContigSpace_OOP_SINCE_SAVE_MARKS_DECL | |
868 | |
869 // Same as object_iterate, but starting from "mark", which is required | |
870 // to denote the start of an object. Objects allocated by | |
871 // applications of the closure *are* included in the iteration. | |
872 virtual void object_iterate_from(WaterMark mark, ObjectClosure* blk); | |
873 | |
874 // Very inefficient implementation. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
875 virtual HeapWord* block_start_const(const void* p) const; |
0 | 876 size_t block_size(const HeapWord* p) const; |
877 // If a block is in the allocated area, it is an object. | |
878 bool block_is_obj(const HeapWord* p) const { return p < top(); } | |
879 | |
880 // Addresses for inlined allocation | |
881 HeapWord** top_addr() { return &_top; } | |
882 HeapWord** end_addr() { return &_end; } | |
883 | |
884 // Overrides for more efficient compaction support. | |
885 void prepare_for_compaction(CompactPoint* cp); | |
886 | |
887 // PrintHeapAtGC support. | |
888 virtual void print_on(outputStream* st) const; | |
889 | |
890 // Checked dynamic downcasts. | |
891 virtual ContiguousSpace* toContiguousSpace() { | |
892 return this; | |
893 } | |
894 | |
895 // Debugging | |
896 virtual void verify(bool allow_dirty) const; | |
897 | |
898 // Used to increase collection frequency. "factor" of 0 means entire | |
899 // space. | |
900 void allocate_temporary_filler(int factor); | |
901 | |
902 }; | |
903 | |
904 | |
905 // A dirty card to oop closure that does filtering. | |
906 // It knows how to filter out objects that are outside of the _boundary. | |
907 class Filtering_DCTOC : public DirtyCardToOopClosure { | |
908 protected: | |
909 // Override. | |
910 void walk_mem_region(MemRegion mr, | |
911 HeapWord* bottom, HeapWord* top); | |
912 | |
913 // Walk the given memory region, from bottom to top, applying | |
914 // the given oop closure to (possibly) all objects found. The | |
915 // given oop closure may or may not be the same as the oop | |
916 // closure with which this closure was created, as it may | |
917 // be a filtering closure which makes use of the _boundary. | |
918 // We offer two signatures, so the FilteringClosure static type is | |
919 // apparent. | |
920 virtual void walk_mem_region_with_cl(MemRegion mr, | |
921 HeapWord* bottom, HeapWord* top, | |
922 OopClosure* cl) = 0; | |
923 virtual void walk_mem_region_with_cl(MemRegion mr, | |
924 HeapWord* bottom, HeapWord* top, | |
925 FilteringClosure* cl) = 0; | |
926 | |
927 public: | |
928 Filtering_DCTOC(Space* sp, OopClosure* cl, | |
929 CardTableModRefBS::PrecisionStyle precision, | |
930 HeapWord* boundary) : | |
931 DirtyCardToOopClosure(sp, cl, precision, boundary) {} | |
932 }; | |
933 | |
934 // A dirty card to oop closure for contiguous spaces | |
935 // (ContiguousSpace and sub-classes). | |
936 // It is a FilteringClosure, as defined above, and it knows: | |
937 // | |
938 // 1. That the actual top of any area in a memory region | |
939 // contained by the space is bounded by the end of the contiguous | |
940 // region of the space. | |
941 // 2. That the space is really made up of objects and not just | |
942 // blocks. | |
943 | |
944 class ContiguousSpaceDCTOC : public Filtering_DCTOC { | |
945 protected: | |
946 // Overrides. | |
947 HeapWord* get_actual_top(HeapWord* top, HeapWord* top_obj); | |
948 | |
949 virtual void walk_mem_region_with_cl(MemRegion mr, | |
950 HeapWord* bottom, HeapWord* top, | |
951 OopClosure* cl); | |
952 virtual void walk_mem_region_with_cl(MemRegion mr, | |
953 HeapWord* bottom, HeapWord* top, | |
954 FilteringClosure* cl); | |
955 | |
956 public: | |
957 ContiguousSpaceDCTOC(ContiguousSpace* sp, OopClosure* cl, | |
958 CardTableModRefBS::PrecisionStyle precision, | |
959 HeapWord* boundary) : | |
960 Filtering_DCTOC(sp, cl, precision, boundary) | |
961 {} | |
962 }; | |
963 | |
964 | |
965 // Class EdenSpace describes eden-space in new generation. | |
966 | |
967 class DefNewGeneration; | |
968 | |
969 class EdenSpace : public ContiguousSpace { | |
970 friend class VMStructs; | |
971 private: | |
972 DefNewGeneration* _gen; | |
973 | |
974 // _soft_end is used as a soft limit on allocation. As soft limits are | |
975 // reached, the slow-path allocation code can invoke other actions and then | |
976 // adjust _soft_end up to a new soft limit or to end(). | |
977 HeapWord* _soft_end; | |
978 | |
979 public: | |
347
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
980 EdenSpace(DefNewGeneration* gen) : |
60fb9c4db4e6
6718086: CMS assert: _concurrent_iteration_safe_limit update missed
ysr
parents:
342
diff
changeset
|
981 _gen(gen), _soft_end(NULL) {} |
0 | 982 |
983 // Get/set just the 'soft' limit. | |
984 HeapWord* soft_end() { return _soft_end; } | |
985 HeapWord** soft_end_addr() { return &_soft_end; } | |
986 void set_soft_end(HeapWord* value) { _soft_end = value; } | |
987 | |
988 // Override. | |
989 void clear(); | |
990 | |
991 // Set both the 'hard' and 'soft' limits (_end and _soft_end). | |
992 void set_end(HeapWord* value) { | |
993 set_soft_end(value); | |
994 ContiguousSpace::set_end(value); | |
995 } | |
996 | |
997 // Allocation (return NULL if full) | |
998 HeapWord* allocate(size_t word_size); | |
999 HeapWord* par_allocate(size_t word_size); | |
1000 }; | |
1001 | |
1002 // Class ConcEdenSpace extends EdenSpace for the sake of safe | |
1003 // allocation while soft-end is being modified concurrently | |
1004 | |
1005 class ConcEdenSpace : public EdenSpace { | |
1006 public: | |
1007 ConcEdenSpace(DefNewGeneration* gen) : EdenSpace(gen) { } | |
1008 | |
1009 // Allocation (return NULL if full) | |
1010 HeapWord* par_allocate(size_t word_size); | |
1011 }; | |
1012 | |
1013 | |
1014 // A ContigSpace that Supports an efficient "block_start" operation via | |
1015 // a BlockOffsetArray (whose BlockOffsetSharedArray may be shared with | |
1016 // other spaces.) This is the abstract base class for old generation | |
1017 // (tenured, perm) spaces. | |
1018 | |
1019 class OffsetTableContigSpace: public ContiguousSpace { | |
1020 friend class VMStructs; | |
1021 protected: | |
1022 BlockOffsetArrayContigSpace _offsets; | |
1023 Mutex _par_alloc_lock; | |
1024 | |
1025 public: | |
1026 // Constructor | |
1027 OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray, | |
1028 MemRegion mr); | |
1029 | |
1030 void set_bottom(HeapWord* value); | |
1031 void set_end(HeapWord* value); | |
1032 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1033 virtual void initialize(MemRegion mr, bool clear_space); |
0 | 1034 void clear(); |
1035 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1036 inline HeapWord* block_start_const(const void* p) const; |
0 | 1037 |
1038 // Add offset table update. | |
1039 virtual inline HeapWord* allocate(size_t word_size); | |
1040 inline HeapWord* par_allocate(size_t word_size); | |
1041 | |
1042 // MarkSweep support phase3 | |
1043 virtual HeapWord* initialize_threshold(); | |
1044 virtual HeapWord* cross_threshold(HeapWord* start, HeapWord* end); | |
1045 | |
1046 virtual void print_on(outputStream* st) const; | |
1047 | |
1048 // Debugging | |
1049 void verify(bool allow_dirty) const; | |
1050 | |
1051 // Shared space support | |
1052 void serialize_block_offset_array_offsets(SerializeOopClosure* soc); | |
1053 }; | |
1054 | |
1055 | |
1056 // Class TenuredSpace is used by TenuredGeneration | |
1057 | |
1058 class TenuredSpace: public OffsetTableContigSpace { | |
1059 friend class VMStructs; | |
1060 protected: | |
1061 // Mark sweep support | |
1062 int allowed_dead_ratio() const; | |
1063 public: | |
1064 // Constructor | |
1065 TenuredSpace(BlockOffsetSharedArray* sharedOffsetArray, | |
1066 MemRegion mr) : | |
1067 OffsetTableContigSpace(sharedOffsetArray, mr) {} | |
1068 }; | |
1069 | |
1070 | |
1071 // Class ContigPermSpace is used by CompactingPermGen | |
1072 | |
1073 class ContigPermSpace: public OffsetTableContigSpace { | |
1074 friend class VMStructs; | |
1075 protected: | |
1076 // Mark sweep support | |
1077 int allowed_dead_ratio() const; | |
1078 public: | |
1079 // Constructor | |
1080 ContigPermSpace(BlockOffsetSharedArray* sharedOffsetArray, MemRegion mr) : | |
1081 OffsetTableContigSpace(sharedOffsetArray, mr) {} | |
1082 }; |