src/share/vm/memory/tenuredGeneration.cpp

Tue, 24 Feb 2015 15:04:52 -0500

author
dlong
date
Tue, 24 Feb 2015 15:04:52 -0500
changeset 7598
ddce0b7cee93
parent 7576
1830156c6b7e
child 7994
04ff2f6cd0eb
child 9327
f96fcd9e1e1b
permissions
-rw-r--r--

8072383: resolve conflicts between open and closed ports
Summary: refactor close to remove references to closed ports
Reviewed-by: kvn, simonis, sgehwolf, dholmes

duke@435 1 /*
dholmes@7576 2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/shared/collectorCounters.hpp"
stefank@2314 27 #include "memory/allocation.inline.hpp"
stefank@2314 28 #include "memory/blockOffsetTable.inline.hpp"
stefank@2314 29 #include "memory/generation.inline.hpp"
stefank@2314 30 #include "memory/generationSpec.hpp"
stefank@2314 31 #include "memory/space.hpp"
stefank@2314 32 #include "memory/tenuredGeneration.hpp"
stefank@2314 33 #include "oops/oop.inline.hpp"
stefank@2314 34 #include "runtime/java.hpp"
jprovino@4542 35 #include "utilities/macros.hpp"
dholmes@7576 36 #if INCLUDE_ALL_GCS
dholmes@7576 37 #include "gc_implementation/shared/parGCAllocBuffer.hpp"
dholmes@7576 38 #endif
duke@435 39
duke@435 40 TenuredGeneration::TenuredGeneration(ReservedSpace rs,
duke@435 41 size_t initial_byte_size, int level,
duke@435 42 GenRemSet* remset) :
duke@435 43 OneContigSpaceCardGeneration(rs, initial_byte_size,
jmasa@4900 44 level, remset, NULL)
duke@435 45 {
duke@435 46 HeapWord* bottom = (HeapWord*) _virtual_space.low();
duke@435 47 HeapWord* end = (HeapWord*) _virtual_space.high();
duke@435 48 _the_space = new TenuredSpace(_bts, MemRegion(bottom, end));
duke@435 49 _the_space->reset_saved_mark();
duke@435 50 _shrink_factor = 0;
duke@435 51 _capacity_at_prologue = 0;
duke@435 52
duke@435 53 _gc_stats = new GCStats();
duke@435 54
duke@435 55 // initialize performance counters
duke@435 56
duke@435 57 const char* gen_name = "old";
duke@435 58
duke@435 59 // Generation Counters -- generation 1, 1 subspace
duke@435 60 _gen_counters = new GenerationCounters(gen_name, 1, 1, &_virtual_space);
duke@435 61
duke@435 62 _gc_counters = new CollectorCounters("MSC", 1);
duke@435 63
duke@435 64 _space_counters = new CSpaceCounters(gen_name, 0,
duke@435 65 _virtual_space.reserved_size(),
duke@435 66 _the_space, _gen_counters);
jprovino@4542 67 #if INCLUDE_ALL_GCS
brutisso@4387 68 if (UseParNewGC) {
duke@435 69 typedef ParGCAllocBufferWithBOT* ParGCAllocBufferWithBOTPtr;
duke@435 70 _alloc_buffers = NEW_C_HEAP_ARRAY(ParGCAllocBufferWithBOTPtr,
zgu@3900 71 ParallelGCThreads, mtGC);
duke@435 72 if (_alloc_buffers == NULL)
duke@435 73 vm_exit_during_initialization("Could not allocate alloc_buffers");
duke@435 74 for (uint i = 0; i < ParallelGCThreads; i++) {
duke@435 75 _alloc_buffers[i] =
duke@435 76 new ParGCAllocBufferWithBOT(OldPLABSize, _bts);
duke@435 77 if (_alloc_buffers[i] == NULL)
duke@435 78 vm_exit_during_initialization("Could not allocate alloc_buffers");
duke@435 79 }
duke@435 80 } else {
duke@435 81 _alloc_buffers = NULL;
duke@435 82 }
jprovino@4542 83 #endif // INCLUDE_ALL_GCS
duke@435 84 }
duke@435 85
duke@435 86
duke@435 87 const char* TenuredGeneration::name() const {
duke@435 88 return "tenured generation";
duke@435 89 }
duke@435 90
duke@435 91 void TenuredGeneration::gc_prologue(bool full) {
duke@435 92 _capacity_at_prologue = capacity();
duke@435 93 _used_at_prologue = used();
duke@435 94 if (VerifyBeforeGC) {
duke@435 95 verify_alloc_buffers_clean();
duke@435 96 }
duke@435 97 }
duke@435 98
duke@435 99 void TenuredGeneration::gc_epilogue(bool full) {
duke@435 100 if (VerifyAfterGC) {
duke@435 101 verify_alloc_buffers_clean();
duke@435 102 }
duke@435 103 OneContigSpaceCardGeneration::gc_epilogue(full);
duke@435 104 }
duke@435 105
duke@435 106
duke@435 107 bool TenuredGeneration::should_collect(bool full,
duke@435 108 size_t size,
duke@435 109 bool is_tlab) {
duke@435 110 // This should be one big conditional or (||), but I want to be able to tell
duke@435 111 // why it returns what it returns (without re-evaluating the conditionals
duke@435 112 // in case they aren't idempotent), so I'm doing it this way.
duke@435 113 // DeMorgan says it's okay.
duke@435 114 bool result = false;
duke@435 115 if (!result && full) {
duke@435 116 result = true;
duke@435 117 if (PrintGC && Verbose) {
duke@435 118 gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
duke@435 119 " full");
duke@435 120 }
duke@435 121 }
duke@435 122 if (!result && should_allocate(size, is_tlab)) {
duke@435 123 result = true;
duke@435 124 if (PrintGC && Verbose) {
duke@435 125 gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
duke@435 126 " should_allocate(" SIZE_FORMAT ")",
duke@435 127 size);
duke@435 128 }
duke@435 129 }
duke@435 130 // If we don't have very much free space.
duke@435 131 // XXX: 10000 should be a percentage of the capacity!!!
duke@435 132 if (!result && free() < 10000) {
duke@435 133 result = true;
duke@435 134 if (PrintGC && Verbose) {
duke@435 135 gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
duke@435 136 " free(): " SIZE_FORMAT,
duke@435 137 free());
duke@435 138 }
duke@435 139 }
duke@435 140 // If we had to expand to accomodate promotions from younger generations
duke@435 141 if (!result && _capacity_at_prologue < capacity()) {
duke@435 142 result = true;
duke@435 143 if (PrintGC && Verbose) {
duke@435 144 gclog_or_tty->print_cr("TenuredGeneration::should_collect: because"
duke@435 145 "_capacity_at_prologue: " SIZE_FORMAT " < capacity(): " SIZE_FORMAT,
duke@435 146 _capacity_at_prologue, capacity());
duke@435 147 }
duke@435 148 }
duke@435 149 return result;
duke@435 150 }
duke@435 151
duke@435 152 void TenuredGeneration::collect(bool full,
duke@435 153 bool clear_all_soft_refs,
duke@435 154 size_t size,
duke@435 155 bool is_tlab) {
duke@435 156 retire_alloc_buffers_before_full_gc();
duke@435 157 OneContigSpaceCardGeneration::collect(full, clear_all_soft_refs,
duke@435 158 size, is_tlab);
duke@435 159 }
duke@435 160
jmasa@4900 161 void TenuredGeneration::compute_new_size() {
jmasa@4900 162 assert_locked_or_safepoint(Heap_lock);
jmasa@4900 163
jmasa@4900 164 // Compute some numbers about the state of the heap.
jmasa@4900 165 const size_t used_after_gc = used();
jmasa@4900 166 const size_t capacity_after_gc = capacity();
jmasa@4900 167
jmasa@4900 168 CardGeneration::compute_new_size();
jmasa@4900 169
jmasa@4900 170 assert(used() == used_after_gc && used_after_gc <= capacity(),
jmasa@4900 171 err_msg("used: " SIZE_FORMAT " used_after_gc: " SIZE_FORMAT
jmasa@4900 172 " capacity: " SIZE_FORMAT, used(), used_after_gc, capacity()));
jmasa@4900 173 }
duke@435 174 void TenuredGeneration::update_gc_stats(int current_level,
duke@435 175 bool full) {
duke@435 176 // If the next lower level(s) has been collected, gather any statistics
duke@435 177 // that are of interest at this point.
duke@435 178 if (!full && (current_level + 1) == level()) {
duke@435 179 // Calculate size of data promoted from the younger generations
duke@435 180 // before doing the collection.
duke@435 181 size_t used_before_gc = used();
duke@435 182
duke@435 183 // If the younger gen collections were skipped, then the
duke@435 184 // number of promoted bytes will be 0 and adding it to the
duke@435 185 // average will incorrectly lessen the average. It is, however,
duke@435 186 // also possible that no promotion was needed.
duke@435 187 if (used_before_gc >= _used_at_prologue) {
duke@435 188 size_t promoted_in_bytes = used_before_gc - _used_at_prologue;
duke@435 189 gc_stats()->avg_promoted()->sample(promoted_in_bytes);
duke@435 190 }
duke@435 191 }
duke@435 192 }
duke@435 193
duke@435 194 void TenuredGeneration::update_counters() {
duke@435 195 if (UsePerfData) {
duke@435 196 _space_counters->update_all();
duke@435 197 _gen_counters->update_all();
duke@435 198 }
duke@435 199 }
duke@435 200
duke@435 201
jprovino@4542 202 #if INCLUDE_ALL_GCS
duke@435 203 oop TenuredGeneration::par_promote(int thread_num,
duke@435 204 oop old, markOop m, size_t word_sz) {
duke@435 205
duke@435 206 ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
duke@435 207 HeapWord* obj_ptr = buf->allocate(word_sz);
duke@435 208 bool is_lab = true;
duke@435 209 if (obj_ptr == NULL) {
duke@435 210 #ifndef PRODUCT
duke@435 211 if (Universe::heap()->promotion_should_fail()) {
duke@435 212 return NULL;
duke@435 213 }
duke@435 214 #endif // #ifndef PRODUCT
duke@435 215
duke@435 216 // Slow path:
duke@435 217 if (word_sz * 100 < ParallelGCBufferWastePct * buf->word_sz()) {
duke@435 218 // Is small enough; abandon this buffer and start a new one.
duke@435 219 size_t buf_size = buf->word_sz();
duke@435 220 HeapWord* buf_space =
duke@435 221 TenuredGeneration::par_allocate(buf_size, false);
duke@435 222 if (buf_space == NULL) {
duke@435 223 buf_space = expand_and_allocate(buf_size, false, true /* parallel*/);
duke@435 224 }
duke@435 225 if (buf_space != NULL) {
duke@435 226 buf->retire(false, false);
duke@435 227 buf->set_buf(buf_space);
duke@435 228 obj_ptr = buf->allocate(word_sz);
duke@435 229 assert(obj_ptr != NULL, "Buffer was definitely big enough...");
duke@435 230 }
duke@435 231 };
duke@435 232 // Otherwise, buffer allocation failed; try allocating object
duke@435 233 // individually.
duke@435 234 if (obj_ptr == NULL) {
duke@435 235 obj_ptr = TenuredGeneration::par_allocate(word_sz, false);
duke@435 236 if (obj_ptr == NULL) {
duke@435 237 obj_ptr = expand_and_allocate(word_sz, false, true /* parallel */);
duke@435 238 }
duke@435 239 }
duke@435 240 if (obj_ptr == NULL) return NULL;
duke@435 241 }
duke@435 242 assert(obj_ptr != NULL, "program logic");
duke@435 243 Copy::aligned_disjoint_words((HeapWord*)old, obj_ptr, word_sz);
duke@435 244 oop obj = oop(obj_ptr);
duke@435 245 // Restore the mark word copied above.
duke@435 246 obj->set_mark(m);
duke@435 247 return obj;
duke@435 248 }
duke@435 249
duke@435 250 void TenuredGeneration::par_promote_alloc_undo(int thread_num,
duke@435 251 HeapWord* obj,
duke@435 252 size_t word_sz) {
duke@435 253 ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
duke@435 254 if (buf->contains(obj)) {
duke@435 255 guarantee(buf->contains(obj + word_sz - 1),
duke@435 256 "should contain whole object");
duke@435 257 buf->undo_allocation(obj, word_sz);
duke@435 258 } else {
jcoomes@916 259 CollectedHeap::fill_with_object(obj, word_sz);
duke@435 260 }
duke@435 261 }
duke@435 262
duke@435 263 void TenuredGeneration::par_promote_alloc_done(int thread_num) {
duke@435 264 ParGCAllocBufferWithBOT* buf = _alloc_buffers[thread_num];
duke@435 265 buf->retire(true, ParallelGCRetainPLAB);
duke@435 266 }
duke@435 267
duke@435 268 void TenuredGeneration::retire_alloc_buffers_before_full_gc() {
duke@435 269 if (UseParNewGC) {
duke@435 270 for (uint i = 0; i < ParallelGCThreads; i++) {
duke@435 271 _alloc_buffers[i]->retire(true /*end_of_gc*/, false /*retain*/);
duke@435 272 }
duke@435 273 }
duke@435 274 }
duke@435 275
duke@435 276 // Verify that any retained parallel allocation buffers do not
duke@435 277 // intersect with dirty cards.
duke@435 278 void TenuredGeneration::verify_alloc_buffers_clean() {
duke@435 279 if (UseParNewGC) {
duke@435 280 for (uint i = 0; i < ParallelGCThreads; i++) {
jmasa@441 281 _rs->verify_aligned_region_empty(_alloc_buffers[i]->range());
duke@435 282 }
duke@435 283 }
duke@435 284 }
jmasa@441 285
jprovino@4542 286 #else // INCLUDE_ALL_GCS
duke@435 287 void TenuredGeneration::retire_alloc_buffers_before_full_gc() {}
duke@435 288 void TenuredGeneration::verify_alloc_buffers_clean() {}
jprovino@4542 289 #endif // INCLUDE_ALL_GCS
duke@435 290
ysr@2243 291 bool TenuredGeneration::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const {
ysr@2243 292 size_t available = max_contiguous_available();
ysr@2243 293 size_t av_promo = (size_t)gc_stats()->avg_promoted()->padded_average();
ysr@2243 294 bool res = (available >= av_promo) || (available >= max_promotion_in_bytes);
ysr@2243 295 if (PrintGC && Verbose) {
ysr@2243 296 gclog_or_tty->print_cr(
ysr@2243 297 "Tenured: promo attempt is%s safe: available("SIZE_FORMAT") %s av_promo("SIZE_FORMAT"),"
ysr@2243 298 "max_promo("SIZE_FORMAT")",
ysr@2243 299 res? "":" not", available, res? ">=":"<",
ysr@2243 300 av_promo, max_promotion_in_bytes);
duke@435 301 }
ysr@2243 302 return res;
duke@435 303 }

mercurial