Mercurial > hg > truffle
annotate src/share/vm/memory/space.cpp @ 167:feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
Summary: decouple set_klass() with zeroing the gap when compressed.
Reviewed-by: kvn, ysr, jrose
author | coleenp |
---|---|
date | Wed, 28 May 2008 21:06:24 -0700 |
parents | ba764ed4b6f2 |
children | d1605aabd0a1 12eea04c8b06 6aae2f9d0294 |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1997-2006 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 # include "incls/_precompiled.incl" | |
26 # include "incls/_space.cpp.incl" | |
27 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
28 void SpaceMemRegionOopsIterClosure::do_oop(oop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
29 void SpaceMemRegionOopsIterClosure::do_oop(narrowOop* p) { SpaceMemRegionOopsIterClosure::do_oop_work(p); } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
30 |
0 | 31 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top, |
32 HeapWord* top_obj) { | |
33 if (top_obj != NULL) { | |
34 if (_sp->block_is_obj(top_obj)) { | |
35 if (_precision == CardTableModRefBS::ObjHeadPreciseArray) { | |
36 if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) { | |
37 // An arrayOop is starting on the dirty card - since we do exact | |
38 // store checks for objArrays we are done. | |
39 } else { | |
40 // Otherwise, it is possible that the object starting on the dirty | |
41 // card spans the entire card, and that the store happened on a | |
42 // later card. Figure out where the object ends. | |
43 // Use the block_size() method of the space over which | |
44 // the iteration is being done. That space (e.g. CMS) may have | |
45 // specific requirements on object sizes which will | |
46 // be reflected in the block_size() method. | |
47 top = top_obj + oop(top_obj)->size(); | |
48 } | |
49 } | |
50 } else { | |
51 top = top_obj; | |
52 } | |
53 } else { | |
54 assert(top == _sp->end(), "only case where top_obj == NULL"); | |
55 } | |
56 return top; | |
57 } | |
58 | |
59 void DirtyCardToOopClosure::walk_mem_region(MemRegion mr, | |
60 HeapWord* bottom, | |
61 HeapWord* top) { | |
62 // 1. Blocks may or may not be objects. | |
63 // 2. Even when a block_is_obj(), it may not entirely | |
64 // occupy the block if the block quantum is larger than | |
65 // the object size. | |
66 // We can and should try to optimize by calling the non-MemRegion | |
67 // version of oop_iterate() for all but the extremal objects | |
68 // (for which we need to call the MemRegion version of | |
69 // oop_iterate()) To be done post-beta XXX | |
70 for (; bottom < top; bottom += _sp->block_size(bottom)) { | |
71 // As in the case of contiguous space above, we'd like to | |
72 // just use the value returned by oop_iterate to increment the | |
73 // current pointer; unfortunately, that won't work in CMS because | |
74 // we'd need an interface change (it seems) to have the space | |
75 // "adjust the object size" (for instance pad it up to its | |
76 // block alignment or minimum block size restrictions. XXX | |
77 if (_sp->block_is_obj(bottom) && | |
78 !_sp->obj_allocated_since_save_marks(oop(bottom))) { | |
79 oop(bottom)->oop_iterate(_cl, mr); | |
80 } | |
81 } | |
82 } | |
83 | |
84 void DirtyCardToOopClosure::do_MemRegion(MemRegion mr) { | |
85 | |
86 // Some collectors need to do special things whenever their dirty | |
87 // cards are processed. For instance, CMS must remember mutator updates | |
88 // (i.e. dirty cards) so as to re-scan mutated objects. | |
89 // Such work can be piggy-backed here on dirty card scanning, so as to make | |
90 // it slightly more efficient than doing a complete non-detructive pre-scan | |
91 // of the card table. | |
92 MemRegionClosure* pCl = _sp->preconsumptionDirtyCardClosure(); | |
93 if (pCl != NULL) { | |
94 pCl->do_MemRegion(mr); | |
95 } | |
96 | |
97 HeapWord* bottom = mr.start(); | |
98 HeapWord* last = mr.last(); | |
99 HeapWord* top = mr.end(); | |
100 HeapWord* bottom_obj; | |
101 HeapWord* top_obj; | |
102 | |
103 assert(_precision == CardTableModRefBS::ObjHeadPreciseArray || | |
104 _precision == CardTableModRefBS::Precise, | |
105 "Only ones we deal with for now."); | |
106 | |
107 assert(_precision != CardTableModRefBS::ObjHeadPreciseArray || | |
108 _last_bottom == NULL || | |
109 top <= _last_bottom, | |
110 "Not decreasing"); | |
111 NOT_PRODUCT(_last_bottom = mr.start()); | |
112 | |
113 bottom_obj = _sp->block_start(bottom); | |
114 top_obj = _sp->block_start(last); | |
115 | |
116 assert(bottom_obj <= bottom, "just checking"); | |
117 assert(top_obj <= top, "just checking"); | |
118 | |
119 // Given what we think is the top of the memory region and | |
120 // the start of the object at the top, get the actual | |
121 // value of the top. | |
122 top = get_actual_top(top, top_obj); | |
123 | |
124 // If the previous call did some part of this region, don't redo. | |
125 if (_precision == CardTableModRefBS::ObjHeadPreciseArray && | |
126 _min_done != NULL && | |
127 _min_done < top) { | |
128 top = _min_done; | |
129 } | |
130 | |
131 // Top may have been reset, and in fact may be below bottom, | |
132 // e.g. the dirty card region is entirely in a now free object | |
133 // -- something that could happen with a concurrent sweeper. | |
134 bottom = MIN2(bottom, top); | |
135 mr = MemRegion(bottom, top); | |
136 assert(bottom <= top && | |
137 (_precision != CardTableModRefBS::ObjHeadPreciseArray || | |
138 _min_done == NULL || | |
139 top <= _min_done), | |
140 "overlap!"); | |
141 | |
142 // Walk the region if it is not empty; otherwise there is nothing to do. | |
143 if (!mr.is_empty()) { | |
144 walk_mem_region(mr, bottom_obj, top); | |
145 } | |
146 | |
147 _min_done = bottom; | |
148 } | |
149 | |
150 DirtyCardToOopClosure* Space::new_dcto_cl(OopClosure* cl, | |
151 CardTableModRefBS::PrecisionStyle precision, | |
152 HeapWord* boundary) { | |
153 return new DirtyCardToOopClosure(this, cl, precision, boundary); | |
154 } | |
155 | |
156 HeapWord* ContiguousSpaceDCTOC::get_actual_top(HeapWord* top, | |
157 HeapWord* top_obj) { | |
158 if (top_obj != NULL && top_obj < (_sp->toContiguousSpace())->top()) { | |
159 if (_precision == CardTableModRefBS::ObjHeadPreciseArray) { | |
160 if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) { | |
161 // An arrayOop is starting on the dirty card - since we do exact | |
162 // store checks for objArrays we are done. | |
163 } else { | |
164 // Otherwise, it is possible that the object starting on the dirty | |
165 // card spans the entire card, and that the store happened on a | |
166 // later card. Figure out where the object ends. | |
167 assert(_sp->block_size(top_obj) == (size_t) oop(top_obj)->size(), | |
168 "Block size and object size mismatch"); | |
169 top = top_obj + oop(top_obj)->size(); | |
170 } | |
171 } | |
172 } else { | |
173 top = (_sp->toContiguousSpace())->top(); | |
174 } | |
175 return top; | |
176 } | |
177 | |
178 void Filtering_DCTOC::walk_mem_region(MemRegion mr, | |
179 HeapWord* bottom, | |
180 HeapWord* top) { | |
181 // Note that this assumption won't hold if we have a concurrent | |
182 // collector in this space, which may have freed up objects after | |
183 // they were dirtied and before the stop-the-world GC that is | |
184 // examining cards here. | |
185 assert(bottom < top, "ought to be at least one obj on a dirty card."); | |
186 | |
187 if (_boundary != NULL) { | |
188 // We have a boundary outside of which we don't want to look | |
189 // at objects, so create a filtering closure around the | |
190 // oop closure before walking the region. | |
191 FilteringClosure filter(_boundary, _cl); | |
192 walk_mem_region_with_cl(mr, bottom, top, &filter); | |
193 } else { | |
194 // No boundary, simply walk the heap with the oop closure. | |
195 walk_mem_region_with_cl(mr, bottom, top, _cl); | |
196 } | |
197 | |
198 } | |
199 | |
200 // We must replicate this so that the static type of "FilteringClosure" | |
201 // (see above) is apparent at the oop_iterate calls. | |
202 #define ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(ClosureType) \ | |
203 void ContiguousSpaceDCTOC::walk_mem_region_with_cl(MemRegion mr, \ | |
204 HeapWord* bottom, \ | |
205 HeapWord* top, \ | |
206 ClosureType* cl) { \ | |
207 bottom += oop(bottom)->oop_iterate(cl, mr); \ | |
208 if (bottom < top) { \ | |
209 HeapWord* next_obj = bottom + oop(bottom)->size(); \ | |
210 while (next_obj < top) { \ | |
211 /* Bottom lies entirely below top, so we can call the */ \ | |
212 /* non-memRegion version of oop_iterate below. */ \ | |
213 oop(bottom)->oop_iterate(cl); \ | |
214 bottom = next_obj; \ | |
215 next_obj = bottom + oop(bottom)->size(); \ | |
216 } \ | |
217 /* Last object. */ \ | |
218 oop(bottom)->oop_iterate(cl, mr); \ | |
219 } \ | |
220 } | |
221 | |
222 // (There are only two of these, rather than N, because the split is due | |
223 // only to the introduction of the FilteringClosure, a local part of the | |
224 // impl of this abstraction.) | |
225 ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(OopClosure) | |
226 ContiguousSpaceDCTOC__walk_mem_region_with_cl_DEFN(FilteringClosure) | |
227 | |
228 DirtyCardToOopClosure* | |
229 ContiguousSpace::new_dcto_cl(OopClosure* cl, | |
230 CardTableModRefBS::PrecisionStyle precision, | |
231 HeapWord* boundary) { | |
232 return new ContiguousSpaceDCTOC(this, cl, precision, boundary); | |
233 } | |
234 | |
235 void Space::initialize(MemRegion mr, bool clear_space) { | |
236 HeapWord* bottom = mr.start(); | |
237 HeapWord* end = mr.end(); | |
238 assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end), | |
239 "invalid space boundaries"); | |
240 set_bottom(bottom); | |
241 set_end(end); | |
242 if (clear_space) clear(); | |
243 } | |
244 | |
245 void Space::clear() { | |
246 if (ZapUnusedHeapArea) mangle_unused_area(); | |
247 } | |
248 | |
249 void ContiguousSpace::initialize(MemRegion mr, bool clear_space) | |
250 { | |
251 CompactibleSpace::initialize(mr, clear_space); | |
252 _concurrent_iteration_safe_limit = top(); | |
253 } | |
254 | |
255 void ContiguousSpace::clear() { | |
256 set_top(bottom()); | |
257 set_saved_mark(); | |
258 Space::clear(); | |
259 } | |
260 | |
261 bool Space::is_in(const void* p) const { | |
262 HeapWord* b = block_start(p); | |
263 return b != NULL && block_is_obj(b); | |
264 } | |
265 | |
266 bool ContiguousSpace::is_in(const void* p) const { | |
267 return _bottom <= p && p < _top; | |
268 } | |
269 | |
270 bool ContiguousSpace::is_free_block(const HeapWord* p) const { | |
271 return p >= _top; | |
272 } | |
273 | |
274 void OffsetTableContigSpace::clear() { | |
275 ContiguousSpace::clear(); | |
276 _offsets.initialize_threshold(); | |
277 } | |
278 | |
279 void OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { | |
280 Space::set_bottom(new_bottom); | |
281 _offsets.set_bottom(new_bottom); | |
282 } | |
283 | |
284 void OffsetTableContigSpace::set_end(HeapWord* new_end) { | |
285 // Space should not advertize an increase in size | |
286 // until after the underlying offest table has been enlarged. | |
287 _offsets.resize(pointer_delta(new_end, bottom())); | |
288 Space::set_end(new_end); | |
289 } | |
290 | |
291 void ContiguousSpace::mangle_unused_area() { | |
292 // to-space is used for storing marks during mark-sweep | |
293 mangle_region(MemRegion(top(), end())); | |
294 } | |
295 | |
296 void ContiguousSpace::mangle_region(MemRegion mr) { | |
297 debug_only(Copy::fill_to_words(mr.start(), mr.word_size(), badHeapWord)); | |
298 } | |
299 | |
300 void CompactibleSpace::initialize(MemRegion mr, bool clear_space) { | |
301 Space::initialize(mr, clear_space); | |
302 _compaction_top = bottom(); | |
303 _next_compaction_space = NULL; | |
304 } | |
305 | |
306 HeapWord* CompactibleSpace::forward(oop q, size_t size, | |
307 CompactPoint* cp, HeapWord* compact_top) { | |
308 // q is alive | |
309 // First check if we should switch compaction space | |
310 assert(this == cp->space, "'this' should be current compaction space."); | |
311 size_t compaction_max_size = pointer_delta(end(), compact_top); | |
312 while (size > compaction_max_size) { | |
313 // switch to next compaction space | |
314 cp->space->set_compaction_top(compact_top); | |
315 cp->space = cp->space->next_compaction_space(); | |
316 if (cp->space == NULL) { | |
317 cp->gen = GenCollectedHeap::heap()->prev_gen(cp->gen); | |
318 assert(cp->gen != NULL, "compaction must succeed"); | |
319 cp->space = cp->gen->first_compaction_space(); | |
320 assert(cp->space != NULL, "generation must have a first compaction space"); | |
321 } | |
322 compact_top = cp->space->bottom(); | |
323 cp->space->set_compaction_top(compact_top); | |
324 cp->threshold = cp->space->initialize_threshold(); | |
325 compaction_max_size = pointer_delta(cp->space->end(), compact_top); | |
326 } | |
327 | |
328 // store the forwarding pointer into the mark word | |
329 if ((HeapWord*)q != compact_top) { | |
330 q->forward_to(oop(compact_top)); | |
331 assert(q->is_gc_marked(), "encoding the pointer should preserve the mark"); | |
332 } else { | |
333 // if the object isn't moving we can just set the mark to the default | |
334 // mark and handle it specially later on. | |
335 q->init_mark(); | |
336 assert(q->forwardee() == NULL, "should be forwarded to NULL"); | |
337 } | |
338 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
339 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::register_live_oop(q, size)); |
0 | 340 compact_top += size; |
341 | |
342 // we need to update the offset table so that the beginnings of objects can be | |
343 // found during scavenge. Note that we are updating the offset table based on | |
344 // where the object will be once the compaction phase finishes. | |
345 if (compact_top > cp->threshold) | |
346 cp->threshold = | |
347 cp->space->cross_threshold(compact_top - size, compact_top); | |
348 return compact_top; | |
349 } | |
350 | |
351 | |
352 bool CompactibleSpace::insert_deadspace(size_t& allowed_deadspace_words, | |
353 HeapWord* q, size_t deadlength) { | |
354 if (allowed_deadspace_words >= deadlength) { | |
355 allowed_deadspace_words -= deadlength; | |
356 oop(q)->set_mark(markOopDesc::prototype()->set_marked()); | |
357 const size_t min_int_array_size = typeArrayOopDesc::header_size(T_INT); | |
358 if (deadlength >= min_int_array_size) { | |
359 oop(q)->set_klass(Universe::intArrayKlassObj()); | |
360 typeArrayOop(q)->set_length((int)((deadlength - min_int_array_size) | |
361 * (HeapWordSize/sizeof(jint)))); | |
362 } else { | |
363 assert((int) deadlength == instanceOopDesc::header_size(), | |
364 "size for smallest fake dead object doesn't match"); | |
365 oop(q)->set_klass(SystemDictionary::object_klass()); | |
366 } | |
367 assert((int) deadlength == oop(q)->size(), | |
368 "make sure size for fake dead object match"); | |
369 // Recall that we required "q == compaction_top". | |
370 return true; | |
371 } else { | |
372 allowed_deadspace_words = 0; | |
373 return false; | |
374 } | |
375 } | |
376 | |
377 #define block_is_always_obj(q) true | |
378 #define obj_size(q) oop(q)->size() | |
379 #define adjust_obj_size(s) s | |
380 | |
381 void CompactibleSpace::prepare_for_compaction(CompactPoint* cp) { | |
382 SCAN_AND_FORWARD(cp, end, block_is_obj, block_size); | |
383 } | |
384 | |
385 // Faster object search. | |
386 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) { | |
387 SCAN_AND_FORWARD(cp, top, block_is_always_obj, obj_size); | |
388 } | |
389 | |
390 void Space::adjust_pointers() { | |
391 // adjust all the interior pointers to point at the new locations of objects | |
392 // Used by MarkSweep::mark_sweep_phase3() | |
393 | |
394 // First check to see if there is any work to be done. | |
395 if (used() == 0) { | |
396 return; // Nothing to do. | |
397 } | |
398 | |
399 // Otherwise... | |
400 HeapWord* q = bottom(); | |
401 HeapWord* t = end(); | |
402 | |
403 debug_only(HeapWord* prev_q = NULL); | |
404 while (q < t) { | |
405 if (oop(q)->is_gc_marked()) { | |
406 // q is alive | |
407 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
408 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::track_interior_pointers(oop(q))); |
0 | 409 // point all the oops to the new location |
410 size_t size = oop(q)->adjust_pointers(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
411 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::check_interior_pointers()); |
0 | 412 |
413 debug_only(prev_q = q); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
414 VALIDATE_MARK_SWEEP_ONLY(MarkSweep::validate_live_oop(oop(q), size)); |
0 | 415 |
416 q += size; | |
417 } else { | |
418 // q is not a live object. But we're not in a compactible space, | |
419 // So we don't have live ranges. | |
420 debug_only(prev_q = q); | |
421 q += block_size(q); | |
422 assert(q > prev_q, "we should be moving forward through memory"); | |
423 } | |
424 } | |
425 assert(q == t, "just checking"); | |
426 } | |
427 | |
428 void CompactibleSpace::adjust_pointers() { | |
429 // Check first is there is any work to do. | |
430 if (used() == 0) { | |
431 return; // Nothing to do. | |
432 } | |
433 | |
434 SCAN_AND_ADJUST_POINTERS(adjust_obj_size); | |
435 } | |
436 | |
437 void CompactibleSpace::compact() { | |
438 SCAN_AND_COMPACT(obj_size); | |
439 } | |
440 | |
441 void Space::print_short() const { print_short_on(tty); } | |
442 | |
443 void Space::print_short_on(outputStream* st) const { | |
444 st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K, | |
445 (int) ((double) used() * 100 / capacity())); | |
446 } | |
447 | |
448 void Space::print() const { print_on(tty); } | |
449 | |
450 void Space::print_on(outputStream* st) const { | |
451 print_short_on(st); | |
452 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
453 bottom(), end()); | |
454 } | |
455 | |
456 void ContiguousSpace::print_on(outputStream* st) const { | |
457 print_short_on(st); | |
458 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
459 bottom(), top(), end()); | |
460 } | |
461 | |
462 void OffsetTableContigSpace::print_on(outputStream* st) const { | |
463 print_short_on(st); | |
464 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " | |
465 INTPTR_FORMAT ", " INTPTR_FORMAT ")", | |
466 bottom(), top(), _offsets.threshold(), end()); | |
467 } | |
468 | |
469 void ContiguousSpace::verify(bool allow_dirty) const { | |
470 HeapWord* p = bottom(); | |
471 HeapWord* t = top(); | |
472 HeapWord* prev_p = NULL; | |
473 while (p < t) { | |
474 oop(p)->verify(); | |
475 prev_p = p; | |
476 p += oop(p)->size(); | |
477 } | |
478 guarantee(p == top(), "end of last object must match end of space"); | |
479 if (top() != end()) { | |
480 guarantee(top() == block_start(end()-1) && | |
481 top() == block_start(top()), | |
482 "top should be start of unallocated block, if it exists"); | |
483 } | |
484 } | |
485 | |
486 void Space::oop_iterate(OopClosure* blk) { | |
487 ObjectToOopClosure blk2(blk); | |
488 object_iterate(&blk2); | |
489 } | |
490 | |
491 HeapWord* Space::object_iterate_careful(ObjectClosureCareful* cl) { | |
492 guarantee(false, "NYI"); | |
493 return bottom(); | |
494 } | |
495 | |
496 HeapWord* Space::object_iterate_careful_m(MemRegion mr, | |
497 ObjectClosureCareful* cl) { | |
498 guarantee(false, "NYI"); | |
499 return bottom(); | |
500 } | |
501 | |
502 | |
503 void Space::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) { | |
504 assert(!mr.is_empty(), "Should be non-empty"); | |
505 // We use MemRegion(bottom(), end()) rather than used_region() below | |
506 // because the two are not necessarily equal for some kinds of | |
507 // spaces, in particular, certain kinds of free list spaces. | |
508 // We could use the more complicated but more precise: | |
509 // MemRegion(used_region().start(), round_to(used_region().end(), CardSize)) | |
510 // but the slight imprecision seems acceptable in the assertion check. | |
511 assert(MemRegion(bottom(), end()).contains(mr), | |
512 "Should be within used space"); | |
513 HeapWord* prev = cl->previous(); // max address from last time | |
514 if (prev >= mr.end()) { // nothing to do | |
515 return; | |
516 } | |
517 // This assert will not work when we go from cms space to perm | |
518 // space, and use same closure. Easy fix deferred for later. XXX YSR | |
519 // assert(prev == NULL || contains(prev), "Should be within space"); | |
520 | |
521 bool last_was_obj_array = false; | |
522 HeapWord *blk_start_addr, *region_start_addr; | |
523 if (prev > mr.start()) { | |
524 region_start_addr = prev; | |
525 blk_start_addr = prev; | |
526 assert(blk_start_addr == block_start(region_start_addr), "invariant"); | |
527 } else { | |
528 region_start_addr = mr.start(); | |
529 blk_start_addr = block_start(region_start_addr); | |
530 } | |
531 HeapWord* region_end_addr = mr.end(); | |
532 MemRegion derived_mr(region_start_addr, region_end_addr); | |
533 while (blk_start_addr < region_end_addr) { | |
534 const size_t size = block_size(blk_start_addr); | |
535 if (block_is_obj(blk_start_addr)) { | |
536 last_was_obj_array = cl->do_object_bm(oop(blk_start_addr), derived_mr); | |
537 } else { | |
538 last_was_obj_array = false; | |
539 } | |
540 blk_start_addr += size; | |
541 } | |
542 if (!last_was_obj_array) { | |
543 assert((bottom() <= blk_start_addr) && (blk_start_addr <= end()), | |
544 "Should be within (closed) used space"); | |
545 assert(blk_start_addr > prev, "Invariant"); | |
546 cl->set_previous(blk_start_addr); // min address for next time | |
547 } | |
548 } | |
549 | |
550 bool Space::obj_is_alive(const HeapWord* p) const { | |
551 assert (block_is_obj(p), "The address should point to an object"); | |
552 return true; | |
553 } | |
554 | |
555 void ContiguousSpace::object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl) { | |
556 assert(!mr.is_empty(), "Should be non-empty"); | |
557 assert(used_region().contains(mr), "Should be within used space"); | |
558 HeapWord* prev = cl->previous(); // max address from last time | |
559 if (prev >= mr.end()) { // nothing to do | |
560 return; | |
561 } | |
562 // See comment above (in more general method above) in case you | |
563 // happen to use this method. | |
564 assert(prev == NULL || is_in_reserved(prev), "Should be within space"); | |
565 | |
566 bool last_was_obj_array = false; | |
567 HeapWord *obj_start_addr, *region_start_addr; | |
568 if (prev > mr.start()) { | |
569 region_start_addr = prev; | |
570 obj_start_addr = prev; | |
571 assert(obj_start_addr == block_start(region_start_addr), "invariant"); | |
572 } else { | |
573 region_start_addr = mr.start(); | |
574 obj_start_addr = block_start(region_start_addr); | |
575 } | |
576 HeapWord* region_end_addr = mr.end(); | |
577 MemRegion derived_mr(region_start_addr, region_end_addr); | |
578 while (obj_start_addr < region_end_addr) { | |
579 oop obj = oop(obj_start_addr); | |
580 const size_t size = obj->size(); | |
581 last_was_obj_array = cl->do_object_bm(obj, derived_mr); | |
582 obj_start_addr += size; | |
583 } | |
584 if (!last_was_obj_array) { | |
585 assert((bottom() <= obj_start_addr) && (obj_start_addr <= end()), | |
586 "Should be within (closed) used space"); | |
587 assert(obj_start_addr > prev, "Invariant"); | |
588 cl->set_previous(obj_start_addr); // min address for next time | |
589 } | |
590 } | |
591 | |
592 #ifndef SERIALGC | |
593 #define ContigSpace_PAR_OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \ | |
594 \ | |
595 void ContiguousSpace::par_oop_iterate(MemRegion mr, OopClosureType* blk) {\ | |
596 HeapWord* obj_addr = mr.start(); \ | |
597 HeapWord* t = mr.end(); \ | |
598 while (obj_addr < t) { \ | |
599 assert(oop(obj_addr)->is_oop(), "Should be an oop"); \ | |
600 obj_addr += oop(obj_addr)->oop_iterate(blk); \ | |
601 } \ | |
602 } | |
603 | |
604 ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DEFN) | |
605 | |
606 #undef ContigSpace_PAR_OOP_ITERATE_DEFN | |
607 #endif // SERIALGC | |
608 | |
609 void ContiguousSpace::oop_iterate(OopClosure* blk) { | |
610 if (is_empty()) return; | |
611 HeapWord* obj_addr = bottom(); | |
612 HeapWord* t = top(); | |
613 // Could call objects iterate, but this is easier. | |
614 while (obj_addr < t) { | |
615 obj_addr += oop(obj_addr)->oop_iterate(blk); | |
616 } | |
617 } | |
618 | |
619 void ContiguousSpace::oop_iterate(MemRegion mr, OopClosure* blk) { | |
620 if (is_empty()) { | |
621 return; | |
622 } | |
623 MemRegion cur = MemRegion(bottom(), top()); | |
624 mr = mr.intersection(cur); | |
625 if (mr.is_empty()) { | |
626 return; | |
627 } | |
628 if (mr.equals(cur)) { | |
629 oop_iterate(blk); | |
630 return; | |
631 } | |
632 assert(mr.end() <= top(), "just took an intersection above"); | |
633 HeapWord* obj_addr = block_start(mr.start()); | |
634 HeapWord* t = mr.end(); | |
635 | |
636 // Handle first object specially. | |
637 oop obj = oop(obj_addr); | |
638 SpaceMemRegionOopsIterClosure smr_blk(blk, mr); | |
639 obj_addr += obj->oop_iterate(&smr_blk); | |
640 while (obj_addr < t) { | |
641 oop obj = oop(obj_addr); | |
642 assert(obj->is_oop(), "expected an oop"); | |
643 obj_addr += obj->size(); | |
644 // If "obj_addr" is not greater than top, then the | |
645 // entire object "obj" is within the region. | |
646 if (obj_addr <= t) { | |
647 obj->oop_iterate(blk); | |
648 } else { | |
649 // "obj" extends beyond end of region | |
650 obj->oop_iterate(&smr_blk); | |
651 break; | |
652 } | |
653 }; | |
654 } | |
655 | |
656 void ContiguousSpace::object_iterate(ObjectClosure* blk) { | |
657 if (is_empty()) return; | |
658 WaterMark bm = bottom_mark(); | |
659 object_iterate_from(bm, blk); | |
660 } | |
661 | |
662 void ContiguousSpace::object_iterate_from(WaterMark mark, ObjectClosure* blk) { | |
663 assert(mark.space() == this, "Mark does not match space"); | |
664 HeapWord* p = mark.point(); | |
665 while (p < top()) { | |
666 blk->do_object(oop(p)); | |
667 p += oop(p)->size(); | |
668 } | |
669 } | |
670 | |
671 HeapWord* | |
672 ContiguousSpace::object_iterate_careful(ObjectClosureCareful* blk) { | |
673 HeapWord * limit = concurrent_iteration_safe_limit(); | |
674 assert(limit <= top(), "sanity check"); | |
675 for (HeapWord* p = bottom(); p < limit;) { | |
676 size_t size = blk->do_object_careful(oop(p)); | |
677 if (size == 0) { | |
678 return p; // failed at p | |
679 } else { | |
680 p += size; | |
681 } | |
682 } | |
683 return NULL; // all done | |
684 } | |
685 | |
686 #define ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ | |
687 \ | |
688 void ContiguousSpace:: \ | |
689 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \ | |
690 HeapWord* t; \ | |
691 HeapWord* p = saved_mark_word(); \ | |
692 assert(p != NULL, "expected saved mark"); \ | |
693 \ | |
694 const intx interval = PrefetchScanIntervalInBytes; \ | |
695 do { \ | |
696 t = top(); \ | |
697 while (p < t) { \ | |
698 Prefetch::write(p, interval); \ | |
699 debug_only(HeapWord* prev = p); \ | |
700 oop m = oop(p); \ | |
701 p += m->oop_iterate(blk); \ | |
702 } \ | |
703 } while (t < top()); \ | |
704 \ | |
705 set_saved_mark_word(p); \ | |
706 } | |
707 | |
708 ALL_SINCE_SAVE_MARKS_CLOSURES(ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN) | |
709 | |
710 #undef ContigSpace_OOP_SINCE_SAVE_MARKS_DEFN | |
711 | |
712 // Very general, slow implementation. | |
713 HeapWord* ContiguousSpace::block_start(const void* p) const { | |
714 assert(MemRegion(bottom(), end()).contains(p), "p not in space"); | |
715 if (p >= top()) { | |
716 return top(); | |
717 } else { | |
718 HeapWord* last = bottom(); | |
719 HeapWord* cur = last; | |
720 while (cur <= p) { | |
721 last = cur; | |
722 cur += oop(cur)->size(); | |
723 } | |
724 assert(oop(last)->is_oop(), "Should be an object start"); | |
725 return last; | |
726 } | |
727 } | |
728 | |
729 size_t ContiguousSpace::block_size(const HeapWord* p) const { | |
730 assert(MemRegion(bottom(), end()).contains(p), "p not in space"); | |
731 HeapWord* current_top = top(); | |
732 assert(p <= current_top, "p is not a block start"); | |
733 assert(p == current_top || oop(p)->is_oop(), "p is not a block start"); | |
734 if (p < current_top) | |
735 return oop(p)->size(); | |
736 else { | |
737 assert(p == current_top, "just checking"); | |
738 return pointer_delta(end(), (HeapWord*) p); | |
739 } | |
740 } | |
741 | |
742 // This version requires locking. | |
743 inline HeapWord* ContiguousSpace::allocate_impl(size_t size, | |
744 HeapWord* const end_value) { | |
745 assert(Heap_lock->owned_by_self() || | |
746 (SafepointSynchronize::is_at_safepoint() && | |
747 Thread::current()->is_VM_thread()), | |
748 "not locked"); | |
749 HeapWord* obj = top(); | |
750 if (pointer_delta(end_value, obj) >= size) { | |
751 HeapWord* new_top = obj + size; | |
752 set_top(new_top); | |
753 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment"); | |
754 return obj; | |
755 } else { | |
756 return NULL; | |
757 } | |
758 } | |
759 | |
760 // This version is lock-free. | |
761 inline HeapWord* ContiguousSpace::par_allocate_impl(size_t size, | |
762 HeapWord* const end_value) { | |
763 do { | |
764 HeapWord* obj = top(); | |
765 if (pointer_delta(end_value, obj) >= size) { | |
766 HeapWord* new_top = obj + size; | |
767 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj); | |
768 // result can be one of two: | |
769 // the old top value: the exchange succeeded | |
770 // otherwise: the new value of the top is returned. | |
771 if (result == obj) { | |
772 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment"); | |
773 return obj; | |
774 } | |
775 } else { | |
776 return NULL; | |
777 } | |
778 } while (true); | |
779 } | |
780 | |
781 // Requires locking. | |
782 HeapWord* ContiguousSpace::allocate(size_t size) { | |
783 return allocate_impl(size, end()); | |
784 } | |
785 | |
786 // Lock-free. | |
787 HeapWord* ContiguousSpace::par_allocate(size_t size) { | |
788 return par_allocate_impl(size, end()); | |
789 } | |
790 | |
791 void ContiguousSpace::allocate_temporary_filler(int factor) { | |
792 // allocate temporary type array decreasing free size with factor 'factor' | |
793 assert(factor >= 0, "just checking"); | |
794 size_t size = pointer_delta(end(), top()); | |
795 | |
796 // if space is full, return | |
797 if (size == 0) return; | |
798 | |
799 if (factor > 0) { | |
800 size -= size/factor; | |
801 } | |
802 size = align_object_size(size); | |
803 | |
804 const size_t min_int_array_size = typeArrayOopDesc::header_size(T_INT); | |
805 if (size >= min_int_array_size) { | |
806 size_t length = (size - min_int_array_size) * (HeapWordSize / sizeof(jint)); | |
807 // allocate uninitialized int array | |
808 typeArrayOop t = (typeArrayOop) allocate(size); | |
809 assert(t != NULL, "allocation should succeed"); | |
810 t->set_mark(markOopDesc::prototype()); | |
811 t->set_klass(Universe::intArrayKlassObj()); | |
812 t->set_length((int)length); | |
813 } else { | |
814 assert((int) size == instanceOopDesc::header_size(), | |
815 "size for smallest fake object doesn't match"); | |
816 instanceOop obj = (instanceOop) allocate(size); | |
817 obj->set_mark(markOopDesc::prototype()); | |
167
feeb96a45707
6696264: assert("narrow oop can never be zero") for GCBasher & ParNewGC
coleenp
parents:
113
diff
changeset
|
818 obj->set_klass_gap(0); |
0 | 819 obj->set_klass(SystemDictionary::object_klass()); |
820 } | |
821 } | |
822 | |
823 void EdenSpace::clear() { | |
824 ContiguousSpace::clear(); | |
825 set_soft_end(end()); | |
826 } | |
827 | |
828 // Requires locking. | |
829 HeapWord* EdenSpace::allocate(size_t size) { | |
830 return allocate_impl(size, soft_end()); | |
831 } | |
832 | |
833 // Lock-free. | |
834 HeapWord* EdenSpace::par_allocate(size_t size) { | |
835 return par_allocate_impl(size, soft_end()); | |
836 } | |
837 | |
838 HeapWord* ConcEdenSpace::par_allocate(size_t size) | |
839 { | |
840 do { | |
841 // The invariant is top() should be read before end() because | |
842 // top() can't be greater than end(), so if an update of _soft_end | |
843 // occurs between 'end_val = end();' and 'top_val = top();' top() | |
844 // also can grow up to the new end() and the condition | |
845 // 'top_val > end_val' is true. To ensure the loading order | |
846 // OrderAccess::loadload() is required after top() read. | |
847 HeapWord* obj = top(); | |
848 OrderAccess::loadload(); | |
849 if (pointer_delta(*soft_end_addr(), obj) >= size) { | |
850 HeapWord* new_top = obj + size; | |
851 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj); | |
852 // result can be one of two: | |
853 // the old top value: the exchange succeeded | |
854 // otherwise: the new value of the top is returned. | |
855 if (result == obj) { | |
856 assert(is_aligned(obj) && is_aligned(new_top), "checking alignment"); | |
857 return obj; | |
858 } | |
859 } else { | |
860 return NULL; | |
861 } | |
862 } while (true); | |
863 } | |
864 | |
865 | |
866 HeapWord* OffsetTableContigSpace::initialize_threshold() { | |
867 return _offsets.initialize_threshold(); | |
868 } | |
869 | |
870 HeapWord* OffsetTableContigSpace::cross_threshold(HeapWord* start, HeapWord* end) { | |
871 _offsets.alloc_block(start, end); | |
872 return _offsets.threshold(); | |
873 } | |
874 | |
875 OffsetTableContigSpace::OffsetTableContigSpace(BlockOffsetSharedArray* sharedOffsetArray, | |
876 MemRegion mr) : | |
877 _offsets(sharedOffsetArray, mr), | |
878 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true) | |
879 { | |
880 _offsets.set_contig_space(this); | |
881 initialize(mr, true); | |
882 } | |
883 | |
884 | |
885 class VerifyOldOopClosure : public OopClosure { | |
886 public: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
887 oop _the_obj; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
888 bool _allow_dirty; |
0 | 889 void do_oop(oop* p) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
890 _the_obj->verify_old_oop(p, _allow_dirty); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
891 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
892 void do_oop(narrowOop* p) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
893 _the_obj->verify_old_oop(p, _allow_dirty); |
0 | 894 } |
895 }; | |
896 | |
897 #define OBJ_SAMPLE_INTERVAL 0 | |
898 #define BLOCK_SAMPLE_INTERVAL 100 | |
899 | |
900 void OffsetTableContigSpace::verify(bool allow_dirty) const { | |
901 HeapWord* p = bottom(); | |
902 HeapWord* prev_p = NULL; | |
903 VerifyOldOopClosure blk; // Does this do anything? | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
904 blk._allow_dirty = allow_dirty; |
0 | 905 int objs = 0; |
906 int blocks = 0; | |
907 | |
908 if (VerifyObjectStartArray) { | |
909 _offsets.verify(); | |
910 } | |
911 | |
912 while (p < top()) { | |
913 size_t size = oop(p)->size(); | |
914 // For a sampling of objects in the space, find it using the | |
915 // block offset table. | |
916 if (blocks == BLOCK_SAMPLE_INTERVAL) { | |
917 guarantee(p == block_start(p + (size/2)), "check offset computation"); | |
918 blocks = 0; | |
919 } else { | |
920 blocks++; | |
921 } | |
922 | |
923 if (objs == OBJ_SAMPLE_INTERVAL) { | |
924 oop(p)->verify(); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
925 blk._the_obj = oop(p); |
0 | 926 oop(p)->oop_iterate(&blk); |
927 objs = 0; | |
928 } else { | |
929 objs++; | |
930 } | |
931 prev_p = p; | |
932 p += size; | |
933 } | |
934 guarantee(p == top(), "end of last object must match end of space"); | |
935 } | |
936 | |
937 void OffsetTableContigSpace::serialize_block_offset_array_offsets( | |
938 SerializeOopClosure* soc) { | |
939 _offsets.serialize(soc); | |
940 } | |
941 | |
942 | |
943 int TenuredSpace::allowed_dead_ratio() const { | |
944 return MarkSweepDeadRatio; | |
945 } | |
946 | |
947 | |
948 int ContigPermSpace::allowed_dead_ratio() const { | |
949 return PermMarkSweepDeadRatio; | |
950 } |