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