Wed, 30 Sep 2009 14:50:51 -0400
6890137: G1: revamp reachable object dump
Summary: Revamp the reachable object dump debugging facility.
Reviewed-by: jmasa, apetrusenko
ysr@777 | 1 | /* |
xdono@1383 | 2 | * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved. |
ysr@777 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ysr@777 | 4 | * |
ysr@777 | 5 | * This code is free software; you can redistribute it and/or modify it |
ysr@777 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ysr@777 | 7 | * published by the Free Software Foundation. |
ysr@777 | 8 | * |
ysr@777 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ysr@777 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ysr@777 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ysr@777 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ysr@777 | 13 | * accompanied this code). |
ysr@777 | 14 | * |
ysr@777 | 15 | * You should have received a copy of the GNU General Public License version |
ysr@777 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ysr@777 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ysr@777 | 18 | * |
ysr@777 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
ysr@777 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
ysr@777 | 21 | * have any questions. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
ysr@777 | 25 | #include "incls/_precompiled.incl" |
ysr@777 | 26 | #include "incls/_concurrentZFThread.cpp.incl" |
ysr@777 | 27 | |
ysr@777 | 28 | // ======= Concurrent Zero-Fill Thread ======== |
ysr@777 | 29 | |
ysr@777 | 30 | // The CM thread is created when the G1 garbage collector is used |
ysr@777 | 31 | |
ysr@777 | 32 | int ConcurrentZFThread::_region_allocs = 0; |
ysr@777 | 33 | int ConcurrentZFThread::_sync_zfs = 0; |
ysr@777 | 34 | int ConcurrentZFThread::_zf_waits = 0; |
ysr@777 | 35 | int ConcurrentZFThread::_regions_filled = 0; |
ysr@777 | 36 | |
ysr@777 | 37 | ConcurrentZFThread::ConcurrentZFThread() : |
tonyp@1371 | 38 | ConcurrentGCThread() |
ysr@777 | 39 | { |
ysr@777 | 40 | create_and_start(); |
ysr@777 | 41 | } |
ysr@777 | 42 | |
ysr@777 | 43 | void ConcurrentZFThread::wait_for_ZF_completed(HeapRegion* hr) { |
ysr@777 | 44 | assert(ZF_mon->owned_by_self(), "Precondition."); |
ysr@777 | 45 | note_zf_wait(); |
ysr@777 | 46 | while (hr->zero_fill_state() == HeapRegion::ZeroFilling) { |
ysr@777 | 47 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 48 | } |
ysr@777 | 49 | } |
ysr@777 | 50 | |
ysr@777 | 51 | void ConcurrentZFThread::processHeapRegion(HeapRegion* hr) { |
ysr@777 | 52 | assert(!Universe::heap()->is_gc_active(), |
ysr@777 | 53 | "This should not happen during GC."); |
ysr@777 | 54 | assert(hr != NULL, "Precondition"); |
ysr@777 | 55 | // These are unlocked reads, but if this test is successful, then no |
ysr@777 | 56 | // other thread will attempt this zero filling. Only a GC thread can |
ysr@777 | 57 | // modify the ZF state of a region whose state is zero-filling, and this |
ysr@777 | 58 | // should only happen while the ZF thread is locking out GC. |
ysr@777 | 59 | if (hr->zero_fill_state() == HeapRegion::ZeroFilling |
ysr@777 | 60 | && hr->zero_filler() == Thread::current()) { |
ysr@777 | 61 | assert(hr->top() == hr->bottom(), "better be empty!"); |
ysr@777 | 62 | assert(!hr->isHumongous(), "Only free regions on unclean list."); |
ysr@777 | 63 | Copy::fill_to_words(hr->bottom(), hr->capacity()/HeapWordSize); |
ysr@777 | 64 | note_region_filled(); |
ysr@777 | 65 | } |
ysr@777 | 66 | } |
ysr@777 | 67 | |
ysr@777 | 68 | void ConcurrentZFThread::run() { |
ysr@777 | 69 | initialize_in_thread(); |
ysr@777 | 70 | Thread* thr_self = Thread::current(); |
ysr@777 | 71 | _vtime_start = os::elapsedVTime(); |
ysr@777 | 72 | wait_for_universe_init(); |
ysr@777 | 73 | |
ysr@777 | 74 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
ysr@777 | 75 | _sts.join(); |
ysr@777 | 76 | while (!_should_terminate) { |
ysr@777 | 77 | _sts.leave(); |
ysr@777 | 78 | |
ysr@777 | 79 | { |
ysr@777 | 80 | MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); |
ysr@777 | 81 | |
ysr@777 | 82 | // This local variable will hold a region being zero-filled. This |
ysr@777 | 83 | // region will neither be on the unclean or zero-filled lists, and |
ysr@777 | 84 | // will not be available for allocation; thus, we might have an |
ysr@777 | 85 | // allocation fail, causing a full GC, because of this, but this is a |
ysr@777 | 86 | // price we will pay. (In future, we might want to make the fact |
ysr@777 | 87 | // that there's a region being zero-filled apparent to the G1 heap, |
ysr@777 | 88 | // which could then wait for it in this extreme case...) |
ysr@777 | 89 | HeapRegion* to_fill; |
ysr@777 | 90 | |
ysr@777 | 91 | while (!g1->should_zf() |
ysr@777 | 92 | || (to_fill = g1->pop_unclean_region_list_locked()) == NULL) |
ysr@777 | 93 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 94 | while (to_fill->zero_fill_state() == HeapRegion::ZeroFilling) |
ysr@777 | 95 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 96 | |
ysr@777 | 97 | // So now to_fill is non-NULL and is not ZeroFilling. It might be |
ysr@777 | 98 | // Allocated or ZeroFilled. (The latter could happen if this thread |
ysr@777 | 99 | // starts the zero-filling of a region, but a GC intervenes and |
ysr@777 | 100 | // pushes new regions needing on the front of the filling on the |
ysr@777 | 101 | // front of the list.) |
ysr@777 | 102 | |
ysr@777 | 103 | switch (to_fill->zero_fill_state()) { |
ysr@777 | 104 | case HeapRegion::Allocated: |
ysr@777 | 105 | to_fill = NULL; |
ysr@777 | 106 | break; |
ysr@777 | 107 | |
ysr@777 | 108 | case HeapRegion::NotZeroFilled: |
ysr@777 | 109 | to_fill->set_zero_fill_in_progress(thr_self); |
ysr@777 | 110 | |
ysr@777 | 111 | ZF_mon->unlock(); |
ysr@777 | 112 | _sts.join(); |
ysr@777 | 113 | processHeapRegion(to_fill); |
ysr@777 | 114 | _sts.leave(); |
ysr@777 | 115 | ZF_mon->lock_without_safepoint_check(); |
ysr@777 | 116 | |
ysr@777 | 117 | if (to_fill->zero_fill_state() == HeapRegion::ZeroFilling |
ysr@777 | 118 | && to_fill->zero_filler() == thr_self) { |
ysr@777 | 119 | to_fill->set_zero_fill_complete(); |
ysr@777 | 120 | (void)g1->put_free_region_on_list_locked(to_fill); |
ysr@777 | 121 | } |
ysr@777 | 122 | break; |
ysr@777 | 123 | |
ysr@777 | 124 | case HeapRegion::ZeroFilled: |
ysr@777 | 125 | (void)g1->put_free_region_on_list_locked(to_fill); |
ysr@777 | 126 | break; |
ysr@777 | 127 | |
ysr@777 | 128 | case HeapRegion::ZeroFilling: |
ysr@777 | 129 | ShouldNotReachHere(); |
ysr@777 | 130 | break; |
ysr@777 | 131 | } |
ysr@777 | 132 | } |
ysr@777 | 133 | _vtime_accum = (os::elapsedVTime() - _vtime_start); |
ysr@777 | 134 | _sts.join(); |
ysr@777 | 135 | } |
ysr@777 | 136 | _sts.leave(); |
ysr@777 | 137 | |
ysr@777 | 138 | assert(_should_terminate, "just checking"); |
ysr@777 | 139 | terminate(); |
ysr@777 | 140 | } |
ysr@777 | 141 | |
ysr@777 | 142 | bool ConcurrentZFThread::offer_yield() { |
ysr@777 | 143 | if (_sts.should_yield()) { |
ysr@777 | 144 | _sts.yield("Concurrent ZF"); |
ysr@777 | 145 | return true; |
ysr@777 | 146 | } else { |
ysr@777 | 147 | return false; |
ysr@777 | 148 | } |
ysr@777 | 149 | } |
ysr@777 | 150 | |
ysr@777 | 151 | void ConcurrentZFThread::stop() { |
ysr@777 | 152 | // it is ok to take late safepoints here, if needed |
ysr@777 | 153 | MutexLockerEx mu(Terminator_lock); |
ysr@777 | 154 | _should_terminate = true; |
ysr@777 | 155 | while (!_has_terminated) { |
ysr@777 | 156 | Terminator_lock->wait(); |
ysr@777 | 157 | } |
ysr@777 | 158 | } |
ysr@777 | 159 | |
tonyp@1454 | 160 | void ConcurrentZFThread::print() const { |
tonyp@1454 | 161 | print_on(tty); |
tonyp@1454 | 162 | } |
tonyp@1454 | 163 | |
tonyp@1454 | 164 | void ConcurrentZFThread::print_on(outputStream* st) const { |
tonyp@1454 | 165 | st->print("\"G1 Concurrent Zero-Fill Thread\" "); |
tonyp@1454 | 166 | Thread::print_on(st); |
tonyp@1454 | 167 | st->cr(); |
ysr@777 | 168 | } |
ysr@777 | 169 | |
ysr@777 | 170 | |
ysr@777 | 171 | double ConcurrentZFThread::_vtime_accum; |
ysr@777 | 172 | |
ysr@777 | 173 | void ConcurrentZFThread::print_summary_info() { |
ysr@777 | 174 | gclog_or_tty->print("\nConcurrent Zero-Filling:\n"); |
ysr@777 | 175 | gclog_or_tty->print(" Filled %d regions, used %5.2fs.\n", |
ysr@777 | 176 | _regions_filled, |
ysr@777 | 177 | vtime_accum()); |
ysr@777 | 178 | gclog_or_tty->print(" Of %d region allocs, %d (%5.2f%%) required sync ZF,\n", |
ysr@777 | 179 | _region_allocs, _sync_zfs, |
ysr@777 | 180 | (_region_allocs > 0 ? |
ysr@777 | 181 | (float)_sync_zfs/(float)_region_allocs*100.0 : |
ysr@777 | 182 | 0.0)); |
ysr@777 | 183 | gclog_or_tty->print(" and %d (%5.2f%%) required a ZF wait.\n", |
ysr@777 | 184 | _zf_waits, |
ysr@777 | 185 | (_region_allocs > 0 ? |
ysr@777 | 186 | (float)_zf_waits/(float)_region_allocs*100.0 : |
ysr@777 | 187 | 0.0)); |
ysr@777 | 188 | |
ysr@777 | 189 | } |