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

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 548
ba764ed4b6f2
child 1069
09f82af55c3e
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

duke@435 1 /*
xdono@631 2 * Copyright 2001-2008 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 // Forward decl.
duke@435 26
duke@435 27 class PLABStats;
duke@435 28
duke@435 29 // A per-thread allocation buffer used during GC.
duke@435 30 class ParGCAllocBuffer: public CHeapObj {
duke@435 31 protected:
duke@435 32 char head[32];
duke@435 33 size_t _word_sz; // in HeapWord units
duke@435 34 HeapWord* _bottom;
duke@435 35 HeapWord* _top;
duke@435 36 HeapWord* _end; // last allocatable address + 1
duke@435 37 HeapWord* _hard_end; // _end + AlignmentReserve
duke@435 38 bool _retained; // whether we hold a _retained_filler
duke@435 39 MemRegion _retained_filler;
duke@435 40 // In support of ergonomic sizing of PLAB's
duke@435 41 size_t _allocated; // in HeapWord units
duke@435 42 size_t _wasted; // in HeapWord units
duke@435 43 char tail[32];
coleenp@548 44 static size_t FillerHeaderSize;
coleenp@548 45 static size_t AlignmentReserve;
duke@435 46
duke@435 47 public:
duke@435 48 // Initializes the buffer to be empty, but with the given "word_sz".
duke@435 49 // Must get initialized with "set_buf" for an allocation to succeed.
duke@435 50 ParGCAllocBuffer(size_t word_sz);
duke@435 51
duke@435 52 static const size_t min_size() {
duke@435 53 return ThreadLocalAllocBuffer::min_size();
duke@435 54 }
duke@435 55
duke@435 56 static const size_t max_size() {
duke@435 57 return ThreadLocalAllocBuffer::max_size();
duke@435 58 }
duke@435 59
duke@435 60 // If an allocation of the given "word_sz" can be satisfied within the
duke@435 61 // buffer, do the allocation, returning a pointer to the start of the
duke@435 62 // allocated block. If the allocation request cannot be satisfied,
duke@435 63 // return NULL.
duke@435 64 HeapWord* allocate(size_t word_sz) {
duke@435 65 HeapWord* res = _top;
duke@435 66 HeapWord* new_top = _top + word_sz;
duke@435 67 if (new_top <= _end) {
duke@435 68 _top = new_top;
duke@435 69 return res;
duke@435 70 } else {
duke@435 71 return NULL;
duke@435 72 }
duke@435 73 }
duke@435 74
duke@435 75 // Undo the last allocation in the buffer, which is required to be of the
duke@435 76 // "obj" of the given "word_sz".
duke@435 77 void undo_allocation(HeapWord* obj, size_t word_sz) {
duke@435 78 assert(_top - word_sz >= _bottom
duke@435 79 && _top - word_sz == obj,
duke@435 80 "Bad undo_allocation");
duke@435 81 _top = _top - word_sz;
duke@435 82 }
duke@435 83
duke@435 84 // The total (word) size of the buffer, including both allocated and
duke@435 85 // unallocted space.
duke@435 86 size_t word_sz() { return _word_sz; }
duke@435 87
duke@435 88 // Should only be done if we are about to reset with a new buffer of the
duke@435 89 // given size.
duke@435 90 void set_word_size(size_t new_word_sz) {
duke@435 91 assert(new_word_sz > AlignmentReserve, "Too small");
duke@435 92 _word_sz = new_word_sz;
duke@435 93 }
duke@435 94
duke@435 95 // The number of words of unallocated space remaining in the buffer.
duke@435 96 size_t words_remaining() {
duke@435 97 assert(_end >= _top, "Negative buffer");
duke@435 98 return pointer_delta(_end, _top, HeapWordSize);
duke@435 99 }
duke@435 100
duke@435 101 bool contains(void* addr) {
duke@435 102 return (void*)_bottom <= addr && addr < (void*)_hard_end;
duke@435 103 }
duke@435 104
duke@435 105 // Sets the space of the buffer to be [buf, space+word_sz()).
duke@435 106 void set_buf(HeapWord* buf) {
duke@435 107 _bottom = buf;
duke@435 108 _top = _bottom;
duke@435 109 _hard_end = _bottom + word_sz();
duke@435 110 _end = _hard_end - AlignmentReserve;
duke@435 111 assert(_end >= _top, "Negative buffer");
duke@435 112 // In support of ergonomic sizing
duke@435 113 _allocated += word_sz();
duke@435 114 }
duke@435 115
duke@435 116 // Flush the stats supporting ergonomic sizing of PLAB's
duke@435 117 void flush_stats(PLABStats* stats);
duke@435 118 void flush_stats_and_retire(PLABStats* stats, bool retain) {
duke@435 119 // We flush the stats first in order to get a reading of
duke@435 120 // unused space in the last buffer.
duke@435 121 if (ResizePLAB) {
duke@435 122 flush_stats(stats);
duke@435 123 }
duke@435 124 // Retire the last allocation buffer.
duke@435 125 retire(true, retain);
duke@435 126 }
duke@435 127
duke@435 128 // Force future allocations to fail and queries for contains()
duke@435 129 // to return false
duke@435 130 void invalidate() {
duke@435 131 assert(!_retained, "Shouldn't retain an invalidated buffer.");
duke@435 132 _end = _hard_end;
duke@435 133 _wasted += pointer_delta(_end, _top); // unused space
duke@435 134 _top = _end; // force future allocations to fail
duke@435 135 _bottom = _end; // force future contains() queries to return false
duke@435 136 }
duke@435 137
duke@435 138 // Fills in the unallocated portion of the buffer with a garbage object.
duke@435 139 // If "end_of_gc" is TRUE, is after the last use in the GC. IF "retain"
duke@435 140 // is true, attempt to re-use the unused portion in the next GC.
duke@435 141 void retire(bool end_of_gc, bool retain);
duke@435 142
duke@435 143 void print() PRODUCT_RETURN;
duke@435 144 };
duke@435 145
duke@435 146 // PLAB stats book-keeping
duke@435 147 class PLABStats VALUE_OBJ_CLASS_SPEC {
duke@435 148 size_t _allocated; // total allocated
duke@435 149 size_t _wasted; // of which wasted (internal fragmentation)
duke@435 150 size_t _unused; // Unused in last buffer
duke@435 151 size_t _used; // derived = allocated - wasted - unused
duke@435 152 size_t _desired_plab_sz;// output of filter (below), suitably trimmed and quantized
duke@435 153 AdaptiveWeightedAverage
duke@435 154 _filter; // integrator with decay
duke@435 155
duke@435 156 public:
duke@435 157 PLABStats(size_t desired_plab_sz_, unsigned wt) :
duke@435 158 _allocated(0),
duke@435 159 _wasted(0),
duke@435 160 _unused(0),
duke@435 161 _used(0),
duke@435 162 _desired_plab_sz(desired_plab_sz_),
duke@435 163 _filter(wt)
duke@435 164 {
duke@435 165 size_t min_sz = min_size();
duke@435 166 size_t max_sz = max_size();
duke@435 167 size_t aligned_min_sz = align_object_size(min_sz);
duke@435 168 size_t aligned_max_sz = align_object_size(max_sz);
duke@435 169 assert(min_sz <= aligned_min_sz && max_sz >= aligned_max_sz &&
duke@435 170 min_sz <= max_sz,
duke@435 171 "PLAB clipping computation in adjust_desired_plab_sz()"
duke@435 172 " may be incorrect");
duke@435 173 }
duke@435 174
duke@435 175 static const size_t min_size() {
duke@435 176 return ParGCAllocBuffer::min_size();
duke@435 177 }
duke@435 178
duke@435 179 static const size_t max_size() {
duke@435 180 return ParGCAllocBuffer::max_size();
duke@435 181 }
duke@435 182
duke@435 183 size_t desired_plab_sz() {
duke@435 184 return _desired_plab_sz;
duke@435 185 }
duke@435 186
duke@435 187 void adjust_desired_plab_sz(); // filter computation, latches output to
duke@435 188 // _desired_plab_sz, clears sensor accumulators
duke@435 189
duke@435 190 void add_allocated(size_t v) {
duke@435 191 Atomic::add_ptr(v, &_allocated);
duke@435 192 }
duke@435 193
duke@435 194 void add_unused(size_t v) {
duke@435 195 Atomic::add_ptr(v, &_unused);
duke@435 196 }
duke@435 197
duke@435 198 void add_wasted(size_t v) {
duke@435 199 Atomic::add_ptr(v, &_wasted);
duke@435 200 }
duke@435 201 };
duke@435 202
duke@435 203 class ParGCAllocBufferWithBOT: public ParGCAllocBuffer {
duke@435 204 BlockOffsetArrayContigSpace _bt;
duke@435 205 BlockOffsetSharedArray* _bsa;
duke@435 206 HeapWord* _true_end; // end of the whole ParGCAllocBuffer
duke@435 207
duke@435 208 static const size_t ChunkSizeInWords;
duke@435 209 static const size_t ChunkSizeInBytes;
duke@435 210 HeapWord* allocate_slow(size_t word_sz);
duke@435 211
duke@435 212 void fill_region_with_block(MemRegion mr, bool contig);
duke@435 213
duke@435 214 public:
duke@435 215 ParGCAllocBufferWithBOT(size_t word_sz, BlockOffsetSharedArray* bsa);
duke@435 216
duke@435 217 HeapWord* allocate(size_t word_sz) {
duke@435 218 HeapWord* res = ParGCAllocBuffer::allocate(word_sz);
duke@435 219 if (res != NULL) {
duke@435 220 _bt.alloc_block(res, word_sz);
duke@435 221 } else {
duke@435 222 res = allocate_slow(word_sz);
duke@435 223 }
duke@435 224 return res;
duke@435 225 }
duke@435 226
duke@435 227 void undo_allocation(HeapWord* obj, size_t word_sz);
duke@435 228
duke@435 229 void set_buf(HeapWord* buf_start) {
duke@435 230 ParGCAllocBuffer::set_buf(buf_start);
duke@435 231 _true_end = _hard_end;
duke@435 232 _bt.set_region(MemRegion(buf_start, word_sz()));
duke@435 233 _bt.initialize_threshold();
duke@435 234 }
duke@435 235
duke@435 236 void retire(bool end_of_gc, bool retain);
duke@435 237
duke@435 238 MemRegion range() {
duke@435 239 return MemRegion(_top, _true_end);
duke@435 240 }
duke@435 241 };

mercurial