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) 2002, 2014, 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/parallelScavenge/parallelScavengeHeap.hpp" |
aoqi@0 | 27 | #include "gc_implementation/parallelScavenge/psOldGen.hpp" |
aoqi@0 | 28 | #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp" |
aoqi@0 | 29 | #include "gc_implementation/parallelScavenge/psScavenge.inline.hpp" |
aoqi@0 | 30 | #include "gc_implementation/shared/gcTrace.hpp" |
aoqi@0 | 31 | #include "gc_implementation/shared/mutableSpace.hpp" |
aoqi@0 | 32 | #include "memory/allocation.inline.hpp" |
aoqi@0 | 33 | #include "memory/memRegion.hpp" |
aoqi@0 | 34 | #include "memory/padded.inline.hpp" |
aoqi@0 | 35 | #include "oops/oop.inline.hpp" |
aoqi@0 | 36 | #include "oops/oop.psgc.inline.hpp" |
aoqi@0 | 37 | |
aoqi@0 | 38 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
aoqi@0 | 39 | |
aoqi@0 | 40 | PaddedEnd<PSPromotionManager>* PSPromotionManager::_manager_array = NULL; |
aoqi@0 | 41 | OopStarTaskQueueSet* PSPromotionManager::_stack_array_depth = NULL; |
aoqi@0 | 42 | PSOldGen* PSPromotionManager::_old_gen = NULL; |
aoqi@0 | 43 | MutableSpace* PSPromotionManager::_young_space = NULL; |
aoqi@0 | 44 | |
aoqi@0 | 45 | void PSPromotionManager::initialize() { |
aoqi@0 | 46 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
aoqi@0 | 47 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
aoqi@0 | 48 | |
aoqi@0 | 49 | _old_gen = heap->old_gen(); |
aoqi@0 | 50 | _young_space = heap->young_gen()->to_space(); |
aoqi@0 | 51 | |
aoqi@0 | 52 | // To prevent false sharing, we pad the PSPromotionManagers |
aoqi@0 | 53 | // and make sure that the first instance starts at a cache line. |
aoqi@0 | 54 | assert(_manager_array == NULL, "Attempt to initialize twice"); |
aoqi@0 | 55 | _manager_array = PaddedArray<PSPromotionManager, mtGC>::create_unfreeable(ParallelGCThreads + 1); |
aoqi@0 | 56 | guarantee(_manager_array != NULL, "Could not initialize promotion manager"); |
aoqi@0 | 57 | |
aoqi@0 | 58 | _stack_array_depth = new OopStarTaskQueueSet(ParallelGCThreads); |
aoqi@0 | 59 | guarantee(_stack_array_depth != NULL, "Could not initialize promotion manager"); |
aoqi@0 | 60 | |
aoqi@0 | 61 | // Create and register the PSPromotionManager(s) for the worker threads. |
aoqi@0 | 62 | for(uint i=0; i<ParallelGCThreads; i++) { |
aoqi@0 | 63 | stack_array_depth()->register_queue(i, _manager_array[i].claimed_stack_depth()); |
aoqi@0 | 64 | } |
aoqi@0 | 65 | // The VMThread gets its own PSPromotionManager, which is not available |
aoqi@0 | 66 | // for work stealing. |
aoqi@0 | 67 | } |
aoqi@0 | 68 | |
aoqi@0 | 69 | PSPromotionManager* PSPromotionManager::gc_thread_promotion_manager(int index) { |
aoqi@0 | 70 | assert(index >= 0 && index < (int)ParallelGCThreads, "index out of range"); |
aoqi@0 | 71 | assert(_manager_array != NULL, "Sanity"); |
aoqi@0 | 72 | return &_manager_array[index]; |
aoqi@0 | 73 | } |
aoqi@0 | 74 | |
aoqi@0 | 75 | PSPromotionManager* PSPromotionManager::vm_thread_promotion_manager() { |
aoqi@0 | 76 | assert(_manager_array != NULL, "Sanity"); |
aoqi@0 | 77 | return &_manager_array[ParallelGCThreads]; |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | void PSPromotionManager::pre_scavenge() { |
aoqi@0 | 81 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
aoqi@0 | 82 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
aoqi@0 | 83 | |
aoqi@0 | 84 | _young_space = heap->young_gen()->to_space(); |
aoqi@0 | 85 | |
aoqi@0 | 86 | for(uint i=0; i<ParallelGCThreads+1; i++) { |
aoqi@0 | 87 | manager_array(i)->reset(); |
aoqi@0 | 88 | } |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | bool PSPromotionManager::post_scavenge(YoungGCTracer& gc_tracer) { |
aoqi@0 | 92 | bool promotion_failure_occurred = false; |
aoqi@0 | 93 | |
aoqi@0 | 94 | TASKQUEUE_STATS_ONLY(if (PrintGCDetails && ParallelGCVerbose) print_stats()); |
aoqi@0 | 95 | for (uint i = 0; i < ParallelGCThreads + 1; i++) { |
aoqi@0 | 96 | PSPromotionManager* manager = manager_array(i); |
aoqi@0 | 97 | assert(manager->claimed_stack_depth()->is_empty(), "should be empty"); |
aoqi@0 | 98 | if (manager->_promotion_failed_info.has_failed()) { |
aoqi@0 | 99 | gc_tracer.report_promotion_failed(manager->_promotion_failed_info); |
aoqi@0 | 100 | promotion_failure_occurred = true; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | manager->flush_labs(); |
aoqi@0 | 103 | } |
aoqi@0 | 104 | return promotion_failure_occurred; |
aoqi@0 | 105 | } |
aoqi@0 | 106 | |
aoqi@0 | 107 | #if TASKQUEUE_STATS |
aoqi@0 | 108 | void |
aoqi@0 | 109 | PSPromotionManager::print_taskqueue_stats(uint i) const { |
aoqi@0 | 110 | tty->print("%3u ", i); |
aoqi@0 | 111 | _claimed_stack_depth.stats.print(); |
aoqi@0 | 112 | tty->cr(); |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | void |
aoqi@0 | 116 | PSPromotionManager::print_local_stats(uint i) const { |
aoqi@0 | 117 | #define FMT " " SIZE_FORMAT_W(10) |
aoqi@0 | 118 | tty->print_cr("%3u" FMT FMT FMT FMT, i, _masked_pushes, _masked_steals, |
aoqi@0 | 119 | _arrays_chunked, _array_chunks_processed); |
aoqi@0 | 120 | #undef FMT |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | static const char* const pm_stats_hdr[] = { |
aoqi@0 | 124 | " --------masked------- arrays array", |
aoqi@0 | 125 | "thr push steal chunked chunks", |
aoqi@0 | 126 | "--- ---------- ---------- ---------- ----------" |
aoqi@0 | 127 | }; |
aoqi@0 | 128 | |
aoqi@0 | 129 | void |
aoqi@0 | 130 | PSPromotionManager::print_stats() { |
aoqi@0 | 131 | tty->print_cr("== GC Tasks Stats, GC %3d", |
aoqi@0 | 132 | Universe::heap()->total_collections()); |
aoqi@0 | 133 | |
aoqi@0 | 134 | tty->print("thr "); TaskQueueStats::print_header(1); tty->cr(); |
aoqi@0 | 135 | tty->print("--- "); TaskQueueStats::print_header(2); tty->cr(); |
aoqi@0 | 136 | for (uint i = 0; i < ParallelGCThreads + 1; ++i) { |
aoqi@0 | 137 | manager_array(i)->print_taskqueue_stats(i); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | |
aoqi@0 | 140 | const uint hlines = sizeof(pm_stats_hdr) / sizeof(pm_stats_hdr[0]); |
aoqi@0 | 141 | for (uint i = 0; i < hlines; ++i) tty->print_cr("%s", pm_stats_hdr[i]); |
aoqi@0 | 142 | for (uint i = 0; i < ParallelGCThreads + 1; ++i) { |
aoqi@0 | 143 | manager_array(i)->print_local_stats(i); |
aoqi@0 | 144 | } |
aoqi@0 | 145 | } |
aoqi@0 | 146 | |
aoqi@0 | 147 | void |
aoqi@0 | 148 | PSPromotionManager::reset_stats() { |
aoqi@0 | 149 | claimed_stack_depth()->stats.reset(); |
aoqi@0 | 150 | _masked_pushes = _masked_steals = 0; |
aoqi@0 | 151 | _arrays_chunked = _array_chunks_processed = 0; |
aoqi@0 | 152 | } |
aoqi@0 | 153 | #endif // TASKQUEUE_STATS |
aoqi@0 | 154 | |
aoqi@0 | 155 | PSPromotionManager::PSPromotionManager() { |
aoqi@0 | 156 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
aoqi@0 | 157 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
aoqi@0 | 158 | |
aoqi@0 | 159 | // We set the old lab's start array. |
aoqi@0 | 160 | _old_lab.set_start_array(old_gen()->start_array()); |
aoqi@0 | 161 | |
aoqi@0 | 162 | uint queue_size; |
aoqi@0 | 163 | claimed_stack_depth()->initialize(); |
aoqi@0 | 164 | queue_size = claimed_stack_depth()->max_elems(); |
aoqi@0 | 165 | |
aoqi@0 | 166 | _totally_drain = (ParallelGCThreads == 1) || (GCDrainStackTargetSize == 0); |
aoqi@0 | 167 | if (_totally_drain) { |
aoqi@0 | 168 | _target_stack_size = 0; |
aoqi@0 | 169 | } else { |
aoqi@0 | 170 | // don't let the target stack size to be more than 1/4 of the entries |
aoqi@0 | 171 | _target_stack_size = (uint) MIN2((uint) GCDrainStackTargetSize, |
aoqi@0 | 172 | (uint) (queue_size / 4)); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | _array_chunk_size = ParGCArrayScanChunk; |
aoqi@0 | 176 | // let's choose 1.5x the chunk size |
aoqi@0 | 177 | _min_array_size_for_chunking = 3 * _array_chunk_size / 2; |
aoqi@0 | 178 | |
aoqi@0 | 179 | reset(); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | |
aoqi@0 | 182 | void PSPromotionManager::reset() { |
aoqi@0 | 183 | assert(stacks_empty(), "reset of non-empty stack"); |
aoqi@0 | 184 | |
aoqi@0 | 185 | // We need to get an assert in here to make sure the labs are always flushed. |
aoqi@0 | 186 | |
aoqi@0 | 187 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
aoqi@0 | 188 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
aoqi@0 | 189 | |
aoqi@0 | 190 | // Do not prefill the LAB's, save heap wastage! |
aoqi@0 | 191 | HeapWord* lab_base = young_space()->top(); |
aoqi@0 | 192 | _young_lab.initialize(MemRegion(lab_base, (size_t)0)); |
aoqi@0 | 193 | _young_gen_is_full = false; |
aoqi@0 | 194 | |
aoqi@0 | 195 | lab_base = old_gen()->object_space()->top(); |
aoqi@0 | 196 | _old_lab.initialize(MemRegion(lab_base, (size_t)0)); |
aoqi@0 | 197 | _old_gen_is_full = false; |
aoqi@0 | 198 | |
aoqi@0 | 199 | _promotion_failed_info.reset(); |
aoqi@0 | 200 | |
aoqi@0 | 201 | TASKQUEUE_STATS_ONLY(reset_stats()); |
aoqi@0 | 202 | } |
aoqi@0 | 203 | |
aoqi@0 | 204 | |
aoqi@0 | 205 | void PSPromotionManager::drain_stacks_depth(bool totally_drain) { |
aoqi@0 | 206 | totally_drain = totally_drain || _totally_drain; |
aoqi@0 | 207 | |
aoqi@0 | 208 | #ifdef ASSERT |
aoqi@0 | 209 | ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); |
aoqi@0 | 210 | assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); |
aoqi@0 | 211 | MutableSpace* to_space = heap->young_gen()->to_space(); |
aoqi@0 | 212 | MutableSpace* old_space = heap->old_gen()->object_space(); |
aoqi@0 | 213 | #endif /* ASSERT */ |
aoqi@0 | 214 | |
aoqi@0 | 215 | OopStarTaskQueue* const tq = claimed_stack_depth(); |
aoqi@0 | 216 | do { |
aoqi@0 | 217 | StarTask p; |
aoqi@0 | 218 | |
aoqi@0 | 219 | // Drain overflow stack first, so other threads can steal from |
aoqi@0 | 220 | // claimed stack while we work. |
aoqi@0 | 221 | while (tq->pop_overflow(p)) { |
aoqi@0 | 222 | process_popped_location_depth(p); |
aoqi@0 | 223 | } |
aoqi@0 | 224 | |
aoqi@0 | 225 | if (totally_drain) { |
aoqi@0 | 226 | while (tq->pop_local(p)) { |
aoqi@0 | 227 | process_popped_location_depth(p); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | } else { |
aoqi@0 | 230 | while (tq->size() > _target_stack_size && tq->pop_local(p)) { |
aoqi@0 | 231 | process_popped_location_depth(p); |
aoqi@0 | 232 | } |
aoqi@0 | 233 | } |
aoqi@0 | 234 | } while (totally_drain && !tq->taskqueue_empty() || !tq->overflow_empty()); |
aoqi@0 | 235 | |
aoqi@0 | 236 | assert(!totally_drain || tq->taskqueue_empty(), "Sanity"); |
aoqi@0 | 237 | assert(totally_drain || tq->size() <= _target_stack_size, "Sanity"); |
aoqi@0 | 238 | assert(tq->overflow_empty(), "Sanity"); |
aoqi@0 | 239 | } |
aoqi@0 | 240 | |
aoqi@0 | 241 | void PSPromotionManager::flush_labs() { |
aoqi@0 | 242 | assert(stacks_empty(), "Attempt to flush lab with live stack"); |
aoqi@0 | 243 | |
aoqi@0 | 244 | // If either promotion lab fills up, we can flush the |
aoqi@0 | 245 | // lab but not refill it, so check first. |
aoqi@0 | 246 | assert(!_young_lab.is_flushed() || _young_gen_is_full, "Sanity"); |
aoqi@0 | 247 | if (!_young_lab.is_flushed()) |
aoqi@0 | 248 | _young_lab.flush(); |
aoqi@0 | 249 | |
aoqi@0 | 250 | assert(!_old_lab.is_flushed() || _old_gen_is_full, "Sanity"); |
aoqi@0 | 251 | if (!_old_lab.is_flushed()) |
aoqi@0 | 252 | _old_lab.flush(); |
aoqi@0 | 253 | |
aoqi@0 | 254 | // Let PSScavenge know if we overflowed |
aoqi@0 | 255 | if (_young_gen_is_full) { |
aoqi@0 | 256 | PSScavenge::set_survivor_overflow(true); |
aoqi@0 | 257 | } |
aoqi@0 | 258 | } |
aoqi@0 | 259 | |
aoqi@0 | 260 | template <class T> void PSPromotionManager::process_array_chunk_work( |
aoqi@0 | 261 | oop obj, |
aoqi@0 | 262 | int start, int end) { |
aoqi@0 | 263 | assert(start <= end, "invariant"); |
aoqi@0 | 264 | T* const base = (T*)objArrayOop(obj)->base(); |
aoqi@0 | 265 | T* p = base + start; |
aoqi@0 | 266 | T* const chunk_end = base + end; |
aoqi@0 | 267 | while (p < chunk_end) { |
aoqi@0 | 268 | if (PSScavenge::should_scavenge(p)) { |
aoqi@0 | 269 | claim_or_forward_depth(p); |
aoqi@0 | 270 | } |
aoqi@0 | 271 | ++p; |
aoqi@0 | 272 | } |
aoqi@0 | 273 | } |
aoqi@0 | 274 | |
aoqi@0 | 275 | void PSPromotionManager::process_array_chunk(oop old) { |
aoqi@0 | 276 | assert(PSChunkLargeArrays, "invariant"); |
aoqi@0 | 277 | assert(old->is_objArray(), "invariant"); |
aoqi@0 | 278 | assert(old->is_forwarded(), "invariant"); |
aoqi@0 | 279 | |
aoqi@0 | 280 | TASKQUEUE_STATS_ONLY(++_array_chunks_processed); |
aoqi@0 | 281 | |
aoqi@0 | 282 | oop const obj = old->forwardee(); |
aoqi@0 | 283 | |
aoqi@0 | 284 | int start; |
aoqi@0 | 285 | int const end = arrayOop(old)->length(); |
aoqi@0 | 286 | if (end > (int) _min_array_size_for_chunking) { |
aoqi@0 | 287 | // we'll chunk more |
aoqi@0 | 288 | start = end - _array_chunk_size; |
aoqi@0 | 289 | assert(start > 0, "invariant"); |
aoqi@0 | 290 | arrayOop(old)->set_length(start); |
aoqi@0 | 291 | push_depth(mask_chunked_array_oop(old)); |
aoqi@0 | 292 | TASKQUEUE_STATS_ONLY(++_masked_pushes); |
aoqi@0 | 293 | } else { |
aoqi@0 | 294 | // this is the final chunk for this array |
aoqi@0 | 295 | start = 0; |
aoqi@0 | 296 | int const actual_length = arrayOop(obj)->length(); |
aoqi@0 | 297 | arrayOop(old)->set_length(actual_length); |
aoqi@0 | 298 | } |
aoqi@0 | 299 | |
aoqi@0 | 300 | if (UseCompressedOops) { |
aoqi@0 | 301 | process_array_chunk_work<narrowOop>(obj, start, end); |
aoqi@0 | 302 | } else { |
aoqi@0 | 303 | process_array_chunk_work<oop>(obj, start, end); |
aoqi@0 | 304 | } |
aoqi@0 | 305 | } |
aoqi@0 | 306 | |
aoqi@0 | 307 | oop PSPromotionManager::oop_promotion_failed(oop obj, markOop obj_mark) { |
aoqi@0 | 308 | assert(_old_gen_is_full || PromotionFailureALot, "Sanity"); |
aoqi@0 | 309 | |
aoqi@0 | 310 | // Attempt to CAS in the header. |
aoqi@0 | 311 | // This tests if the header is still the same as when |
aoqi@0 | 312 | // this started. If it is the same (i.e., no forwarding |
aoqi@0 | 313 | // pointer has been installed), then this thread owns |
aoqi@0 | 314 | // it. |
aoqi@0 | 315 | if (obj->cas_forward_to(obj, obj_mark)) { |
aoqi@0 | 316 | // We won any races, we "own" this object. |
aoqi@0 | 317 | assert(obj == obj->forwardee(), "Sanity"); |
aoqi@0 | 318 | |
aoqi@0 | 319 | _promotion_failed_info.register_copy_failure(obj->size()); |
aoqi@0 | 320 | |
aoqi@0 | 321 | obj->push_contents(this); |
aoqi@0 | 322 | |
aoqi@0 | 323 | // Save the mark if needed |
aoqi@0 | 324 | PSScavenge::oop_promotion_failed(obj, obj_mark); |
aoqi@0 | 325 | } else { |
aoqi@0 | 326 | // We lost, someone else "owns" this object |
aoqi@0 | 327 | guarantee(obj->is_forwarded(), "Object must be forwarded if the cas failed."); |
aoqi@0 | 328 | |
aoqi@0 | 329 | // No unallocation to worry about. |
aoqi@0 | 330 | obj = obj->forwardee(); |
aoqi@0 | 331 | } |
aoqi@0 | 332 | |
aoqi@0 | 333 | #ifndef PRODUCT |
aoqi@0 | 334 | if (TraceScavenge) { |
aoqi@0 | 335 | gclog_or_tty->print_cr("{%s %s 0x%x (%d)}", |
aoqi@0 | 336 | "promotion-failure", |
aoqi@0 | 337 | obj->klass()->internal_name(), |
aoqi@0 | 338 | (void *)obj, obj->size()); |
aoqi@0 | 339 | |
aoqi@0 | 340 | } |
aoqi@0 | 341 | #endif |
aoqi@0 | 342 | |
aoqi@0 | 343 | return obj; |
aoqi@0 | 344 | } |