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