src/share/vm/gc_implementation/parNew/parGCAllocBuffer.cpp

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 916
7d7a7c599c17
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

duke@435 1 /*
xdono@1014 2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_parGCAllocBuffer.cpp.incl"
duke@435 27
duke@435 28 ParGCAllocBuffer::ParGCAllocBuffer(size_t desired_plab_sz_) :
duke@435 29 _word_sz(desired_plab_sz_), _bottom(NULL), _top(NULL),
duke@435 30 _end(NULL), _hard_end(NULL),
duke@435 31 _retained(false), _retained_filler(),
duke@435 32 _allocated(0), _wasted(0)
duke@435 33 {
duke@435 34 assert (min_size() > AlignmentReserve, "Inconsistency!");
coleenp@548 35 // arrayOopDesc::header_size depends on command line initialization.
coleenp@548 36 FillerHeaderSize = align_object_size(arrayOopDesc::header_size(T_INT));
coleenp@548 37 AlignmentReserve = oopDesc::header_size() > MinObjAlignment ? FillerHeaderSize : 0;
duke@435 38 }
duke@435 39
coleenp@548 40 size_t ParGCAllocBuffer::FillerHeaderSize;
duke@435 41
duke@435 42 // If the minimum object size is greater than MinObjAlignment, we can
duke@435 43 // end up with a shard at the end of the buffer that's smaller than
duke@435 44 // the smallest object. We can't allow that because the buffer must
duke@435 45 // look like it's full of objects when we retire it, so we make
duke@435 46 // sure we have enough space for a filler int array object.
coleenp@548 47 size_t ParGCAllocBuffer::AlignmentReserve;
duke@435 48
duke@435 49 void ParGCAllocBuffer::retire(bool end_of_gc, bool retain) {
duke@435 50 assert(!retain || end_of_gc, "Can only retain at GC end.");
duke@435 51 if (_retained) {
duke@435 52 // If the buffer had been retained shorten the previous filler object.
duke@435 53 assert(_retained_filler.end() <= _top, "INVARIANT");
jcoomes@916 54 CollectedHeap::fill_with_object(_retained_filler);
duke@435 55 // Wasted space book-keeping, otherwise (normally) done in invalidate()
duke@435 56 _wasted += _retained_filler.word_size();
duke@435 57 _retained = false;
duke@435 58 }
duke@435 59 assert(!end_of_gc || !_retained, "At this point, end_of_gc ==> !_retained.");
duke@435 60 if (_top < _hard_end) {
jcoomes@916 61 CollectedHeap::fill_with_object(_top, _hard_end);
duke@435 62 if (!retain) {
duke@435 63 invalidate();
duke@435 64 } else {
duke@435 65 // Is there wasted space we'd like to retain for the next GC?
duke@435 66 if (pointer_delta(_end, _top) > FillerHeaderSize) {
duke@435 67 _retained = true;
duke@435 68 _retained_filler = MemRegion(_top, FillerHeaderSize);
duke@435 69 _top = _top + FillerHeaderSize;
duke@435 70 } else {
duke@435 71 invalidate();
duke@435 72 }
duke@435 73 }
duke@435 74 }
duke@435 75 }
duke@435 76
duke@435 77 void ParGCAllocBuffer::flush_stats(PLABStats* stats) {
duke@435 78 assert(ResizePLAB, "Wasted work");
duke@435 79 stats->add_allocated(_allocated);
duke@435 80 stats->add_wasted(_wasted);
duke@435 81 stats->add_unused(pointer_delta(_end, _top));
duke@435 82 }
duke@435 83
duke@435 84 // Compute desired plab size and latch result for later
duke@435 85 // use. This should be called once at the end of parallel
duke@435 86 // scavenge; it clears the sensor accumulators.
duke@435 87 void PLABStats::adjust_desired_plab_sz() {
duke@435 88 assert(ResizePLAB, "Not set");
duke@435 89 if (_allocated == 0) {
duke@435 90 assert(_unused == 0, "Inconsistency in PLAB stats");
duke@435 91 _allocated = 1;
duke@435 92 }
duke@435 93 double wasted_frac = (double)_unused/(double)_allocated;
duke@435 94 size_t target_refills = (size_t)((wasted_frac*TargetSurvivorRatio)/
duke@435 95 TargetPLABWastePct);
duke@435 96 if (target_refills == 0) {
duke@435 97 target_refills = 1;
duke@435 98 }
duke@435 99 _used = _allocated - _wasted - _unused;
duke@435 100 size_t plab_sz = _used/(target_refills*ParallelGCThreads);
duke@435 101 if (PrintPLAB) gclog_or_tty->print(" (plab_sz = %d ", plab_sz);
duke@435 102 // Take historical weighted average
duke@435 103 _filter.sample(plab_sz);
duke@435 104 // Clip from above and below, and align to object boundary
duke@435 105 plab_sz = MAX2(min_size(), (size_t)_filter.average());
duke@435 106 plab_sz = MIN2(max_size(), plab_sz);
duke@435 107 plab_sz = align_object_size(plab_sz);
duke@435 108 // Latch the result
duke@435 109 if (PrintPLAB) gclog_or_tty->print(" desired_plab_sz = %d) ", plab_sz);
duke@435 110 if (ResizePLAB) {
duke@435 111 _desired_plab_sz = plab_sz;
duke@435 112 }
duke@435 113 // Now clear the accumulators for next round:
duke@435 114 // note this needs to be fixed in the case where we
duke@435 115 // are retaining across scavenges. FIX ME !!! XXX
duke@435 116 _allocated = 0;
duke@435 117 _wasted = 0;
duke@435 118 _unused = 0;
duke@435 119 }
duke@435 120
duke@435 121 #ifndef PRODUCT
duke@435 122 void ParGCAllocBuffer::print() {
duke@435 123 gclog_or_tty->print("parGCAllocBuffer: _bottom: %p _top: %p _end: %p _hard_end: %p"
duke@435 124 "_retained: %c _retained_filler: [%p,%p)\n",
duke@435 125 _bottom, _top, _end, _hard_end,
duke@435 126 "FT"[_retained], _retained_filler.start(), _retained_filler.end());
duke@435 127 }
duke@435 128 #endif // !PRODUCT
duke@435 129
duke@435 130 const size_t ParGCAllocBufferWithBOT::ChunkSizeInWords =
duke@435 131 MIN2(CardTableModRefBS::par_chunk_heapword_alignment(),
duke@435 132 ((size_t)Generation::GenGrain)/HeapWordSize);
duke@435 133 const size_t ParGCAllocBufferWithBOT::ChunkSizeInBytes =
duke@435 134 MIN2(CardTableModRefBS::par_chunk_heapword_alignment() * HeapWordSize,
duke@435 135 (size_t)Generation::GenGrain);
duke@435 136
duke@435 137 ParGCAllocBufferWithBOT::ParGCAllocBufferWithBOT(size_t word_sz,
duke@435 138 BlockOffsetSharedArray* bsa) :
duke@435 139 ParGCAllocBuffer(word_sz),
duke@435 140 _bsa(bsa),
duke@435 141 _bt(bsa, MemRegion(_bottom, _hard_end)),
duke@435 142 _true_end(_hard_end)
duke@435 143 {}
duke@435 144
duke@435 145 // The buffer comes with its own BOT, with a shared (obviously) underlying
duke@435 146 // BlockOffsetSharedArray. We manipulate this BOT in the normal way
duke@435 147 // as we would for any contiguous space. However, on accasion we
duke@435 148 // need to do some buffer surgery at the extremities before we
duke@435 149 // start using the body of the buffer for allocations. Such surgery
duke@435 150 // (as explained elsewhere) is to prevent allocation on a card that
duke@435 151 // is in the process of being walked concurrently by another GC thread.
duke@435 152 // When such surgery happens at a point that is far removed (to the
duke@435 153 // right of the current allocation point, top), we use the "contig"
duke@435 154 // parameter below to directly manipulate the shared array without
duke@435 155 // modifying the _next_threshold state in the BOT.
duke@435 156 void ParGCAllocBufferWithBOT::fill_region_with_block(MemRegion mr,
duke@435 157 bool contig) {
jcoomes@916 158 CollectedHeap::fill_with_object(mr);
duke@435 159 if (contig) {
duke@435 160 _bt.alloc_block(mr.start(), mr.end());
duke@435 161 } else {
duke@435 162 _bt.BlockOffsetArray::alloc_block(mr.start(), mr.end());
duke@435 163 }
duke@435 164 }
duke@435 165
duke@435 166 HeapWord* ParGCAllocBufferWithBOT::allocate_slow(size_t word_sz) {
duke@435 167 HeapWord* res = NULL;
duke@435 168 if (_true_end > _hard_end) {
duke@435 169 assert((HeapWord*)align_size_down(intptr_t(_hard_end),
duke@435 170 ChunkSizeInBytes) == _hard_end,
duke@435 171 "or else _true_end should be equal to _hard_end");
duke@435 172 assert(_retained, "or else _true_end should be equal to _hard_end");
duke@435 173 assert(_retained_filler.end() <= _top, "INVARIANT");
jcoomes@916 174 CollectedHeap::fill_with_object(_retained_filler);
duke@435 175 if (_top < _hard_end) {
duke@435 176 fill_region_with_block(MemRegion(_top, _hard_end), true);
duke@435 177 }
duke@435 178 HeapWord* next_hard_end = MIN2(_true_end, _hard_end + ChunkSizeInWords);
duke@435 179 _retained_filler = MemRegion(_hard_end, FillerHeaderSize);
duke@435 180 _bt.alloc_block(_retained_filler.start(), _retained_filler.word_size());
duke@435 181 _top = _retained_filler.end();
duke@435 182 _hard_end = next_hard_end;
duke@435 183 _end = _hard_end - AlignmentReserve;
duke@435 184 res = ParGCAllocBuffer::allocate(word_sz);
duke@435 185 if (res != NULL) {
duke@435 186 _bt.alloc_block(res, word_sz);
duke@435 187 }
duke@435 188 }
duke@435 189 return res;
duke@435 190 }
duke@435 191
duke@435 192 void
duke@435 193 ParGCAllocBufferWithBOT::undo_allocation(HeapWord* obj, size_t word_sz) {
duke@435 194 ParGCAllocBuffer::undo_allocation(obj, word_sz);
duke@435 195 // This may back us up beyond the previous threshold, so reset.
duke@435 196 _bt.set_region(MemRegion(_top, _hard_end));
duke@435 197 _bt.initialize_threshold();
duke@435 198 }
duke@435 199
duke@435 200 void ParGCAllocBufferWithBOT::retire(bool end_of_gc, bool retain) {
duke@435 201 assert(!retain || end_of_gc, "Can only retain at GC end.");
duke@435 202 if (_retained) {
duke@435 203 // We're about to make the retained_filler into a block.
duke@435 204 _bt.BlockOffsetArray::alloc_block(_retained_filler.start(),
duke@435 205 _retained_filler.end());
duke@435 206 }
duke@435 207 // Reset _hard_end to _true_end (and update _end)
duke@435 208 if (retain && _hard_end != NULL) {
duke@435 209 assert(_hard_end <= _true_end, "Invariant.");
duke@435 210 _hard_end = _true_end;
duke@435 211 _end = MAX2(_top, _hard_end - AlignmentReserve);
duke@435 212 assert(_end <= _hard_end, "Invariant.");
duke@435 213 }
duke@435 214 _true_end = _hard_end;
duke@435 215 HeapWord* pre_top = _top;
duke@435 216
duke@435 217 ParGCAllocBuffer::retire(end_of_gc, retain);
duke@435 218 // Now any old _retained_filler is cut back to size, the free part is
duke@435 219 // filled with a filler object, and top is past the header of that
duke@435 220 // object.
duke@435 221
duke@435 222 if (retain && _top < _end) {
duke@435 223 assert(end_of_gc && retain, "Or else retain should be false.");
duke@435 224 // If the lab does not start on a card boundary, we don't want to
duke@435 225 // allocate onto that card, since that might lead to concurrent
duke@435 226 // allocation and card scanning, which we don't support. So we fill
duke@435 227 // the first card with a garbage object.
duke@435 228 size_t first_card_index = _bsa->index_for(pre_top);
duke@435 229 HeapWord* first_card_start = _bsa->address_for_index(first_card_index);
duke@435 230 if (first_card_start < pre_top) {
duke@435 231 HeapWord* second_card_start =
jmasa@736 232 _bsa->inc_by_region_size(first_card_start);
duke@435 233
duke@435 234 // Ensure enough room to fill with the smallest block
duke@435 235 second_card_start = MAX2(second_card_start, pre_top + AlignmentReserve);
duke@435 236
duke@435 237 // If the end is already in the first card, don't go beyond it!
duke@435 238 // Or if the remainder is too small for a filler object, gobble it up.
duke@435 239 if (_hard_end < second_card_start ||
duke@435 240 pointer_delta(_hard_end, second_card_start) < AlignmentReserve) {
duke@435 241 second_card_start = _hard_end;
duke@435 242 }
duke@435 243 if (pre_top < second_card_start) {
duke@435 244 MemRegion first_card_suffix(pre_top, second_card_start);
duke@435 245 fill_region_with_block(first_card_suffix, true);
duke@435 246 }
duke@435 247 pre_top = second_card_start;
duke@435 248 _top = pre_top;
duke@435 249 _end = MAX2(_top, _hard_end - AlignmentReserve);
duke@435 250 }
duke@435 251
duke@435 252 // If the lab does not end on a card boundary, we don't want to
duke@435 253 // allocate onto that card, since that might lead to concurrent
duke@435 254 // allocation and card scanning, which we don't support. So we fill
duke@435 255 // the last card with a garbage object.
duke@435 256 size_t last_card_index = _bsa->index_for(_hard_end);
duke@435 257 HeapWord* last_card_start = _bsa->address_for_index(last_card_index);
duke@435 258 if (last_card_start < _hard_end) {
duke@435 259
duke@435 260 // Ensure enough room to fill with the smallest block
duke@435 261 last_card_start = MIN2(last_card_start, _hard_end - AlignmentReserve);
duke@435 262
duke@435 263 // If the top is already in the last card, don't go back beyond it!
duke@435 264 // Or if the remainder is too small for a filler object, gobble it up.
duke@435 265 if (_top > last_card_start ||
duke@435 266 pointer_delta(last_card_start, _top) < AlignmentReserve) {
duke@435 267 last_card_start = _top;
duke@435 268 }
duke@435 269 if (last_card_start < _hard_end) {
duke@435 270 MemRegion last_card_prefix(last_card_start, _hard_end);
duke@435 271 fill_region_with_block(last_card_prefix, false);
duke@435 272 }
duke@435 273 _hard_end = last_card_start;
duke@435 274 _end = MAX2(_top, _hard_end - AlignmentReserve);
duke@435 275 _true_end = _hard_end;
duke@435 276 assert(_end <= _hard_end, "Invariant.");
duke@435 277 }
duke@435 278
duke@435 279 // At this point:
duke@435 280 // 1) we had a filler object from the original top to hard_end.
duke@435 281 // 2) We've filled in any partial cards at the front and back.
duke@435 282 if (pre_top < _hard_end) {
duke@435 283 // Now we can reset the _bt to do allocation in the given area.
duke@435 284 MemRegion new_filler(pre_top, _hard_end);
duke@435 285 fill_region_with_block(new_filler, false);
duke@435 286 _top = pre_top + ParGCAllocBuffer::FillerHeaderSize;
duke@435 287 // If there's no space left, don't retain.
duke@435 288 if (_top >= _end) {
duke@435 289 _retained = false;
duke@435 290 invalidate();
duke@435 291 return;
duke@435 292 }
duke@435 293 _retained_filler = MemRegion(pre_top, _top);
duke@435 294 _bt.set_region(MemRegion(_top, _hard_end));
duke@435 295 _bt.initialize_threshold();
duke@435 296 assert(_bt.threshold() > _top, "initialize_threshold failed!");
duke@435 297
duke@435 298 // There may be other reasons for queries into the middle of the
duke@435 299 // filler object. When such queries are done in parallel with
duke@435 300 // allocation, bad things can happen, if the query involves object
duke@435 301 // iteration. So we ensure that such queries do not involve object
duke@435 302 // iteration, by putting another filler object on the boundaries of
duke@435 303 // such queries. One such is the object spanning a parallel card
duke@435 304 // chunk boundary.
duke@435 305
duke@435 306 // "chunk_boundary" is the address of the first chunk boundary less
duke@435 307 // than "hard_end".
duke@435 308 HeapWord* chunk_boundary =
duke@435 309 (HeapWord*)align_size_down(intptr_t(_hard_end-1), ChunkSizeInBytes);
duke@435 310 assert(chunk_boundary < _hard_end, "Or else above did not work.");
duke@435 311 assert(pointer_delta(_true_end, chunk_boundary) >= AlignmentReserve,
duke@435 312 "Consequence of last card handling above.");
duke@435 313
duke@435 314 if (_top <= chunk_boundary) {
duke@435 315 assert(_true_end == _hard_end, "Invariant.");
duke@435 316 while (_top <= chunk_boundary) {
duke@435 317 assert(pointer_delta(_hard_end, chunk_boundary) >= AlignmentReserve,
duke@435 318 "Consequence of last card handling above.");
jcoomes@916 319 _bt.BlockOffsetArray::alloc_block(chunk_boundary, _hard_end);
jcoomes@916 320 CollectedHeap::fill_with_object(chunk_boundary, _hard_end);
jcoomes@916 321 _hard_end = chunk_boundary;
duke@435 322 chunk_boundary -= ChunkSizeInWords;
duke@435 323 }
duke@435 324 _end = _hard_end - AlignmentReserve;
duke@435 325 assert(_top <= _end, "Invariant.");
duke@435 326 // Now reset the initial filler chunk so it doesn't overlap with
duke@435 327 // the one(s) inserted above.
duke@435 328 MemRegion new_filler(pre_top, _hard_end);
duke@435 329 fill_region_with_block(new_filler, false);
duke@435 330 }
duke@435 331 } else {
duke@435 332 _retained = false;
duke@435 333 invalidate();
duke@435 334 }
duke@435 335 } else {
duke@435 336 assert(!end_of_gc ||
duke@435 337 (!_retained && _true_end == _hard_end), "Checking.");
duke@435 338 }
duke@435 339 assert(_end <= _hard_end, "Invariant.");
duke@435 340 assert(_top < _end || _top == _hard_end, "Invariant");
duke@435 341 }

mercurial