Tue, 05 May 2009 22:15:35 -0700
6833576: G1: assert illegal index, growableArray.hpp:186
Summary: The code that calculates the heap region index for an object address incorrectly used signed arithmetic.
Reviewed-by: jcoomes, ysr
ysr@777 | 1 | /* |
ysr@777 | 2 | * Copyright 2001-2007 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() : |
ysr@777 | 38 | ConcurrentGCThread(), |
ysr@777 | 39 | _co_tracker(G1ZFGroup) |
ysr@777 | 40 | { |
ysr@777 | 41 | create_and_start(); |
ysr@777 | 42 | } |
ysr@777 | 43 | |
ysr@777 | 44 | void ConcurrentZFThread::wait_for_ZF_completed(HeapRegion* hr) { |
ysr@777 | 45 | assert(ZF_mon->owned_by_self(), "Precondition."); |
ysr@777 | 46 | note_zf_wait(); |
ysr@777 | 47 | while (hr->zero_fill_state() == HeapRegion::ZeroFilling) { |
ysr@777 | 48 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 49 | } |
ysr@777 | 50 | } |
ysr@777 | 51 | |
ysr@777 | 52 | void ConcurrentZFThread::processHeapRegion(HeapRegion* hr) { |
ysr@777 | 53 | assert(!Universe::heap()->is_gc_active(), |
ysr@777 | 54 | "This should not happen during GC."); |
ysr@777 | 55 | assert(hr != NULL, "Precondition"); |
ysr@777 | 56 | // These are unlocked reads, but if this test is successful, then no |
ysr@777 | 57 | // other thread will attempt this zero filling. Only a GC thread can |
ysr@777 | 58 | // modify the ZF state of a region whose state is zero-filling, and this |
ysr@777 | 59 | // should only happen while the ZF thread is locking out GC. |
ysr@777 | 60 | if (hr->zero_fill_state() == HeapRegion::ZeroFilling |
ysr@777 | 61 | && hr->zero_filler() == Thread::current()) { |
ysr@777 | 62 | assert(hr->top() == hr->bottom(), "better be empty!"); |
ysr@777 | 63 | assert(!hr->isHumongous(), "Only free regions on unclean list."); |
ysr@777 | 64 | Copy::fill_to_words(hr->bottom(), hr->capacity()/HeapWordSize); |
ysr@777 | 65 | note_region_filled(); |
ysr@777 | 66 | } |
ysr@777 | 67 | } |
ysr@777 | 68 | |
ysr@777 | 69 | void ConcurrentZFThread::run() { |
ysr@777 | 70 | initialize_in_thread(); |
ysr@777 | 71 | Thread* thr_self = Thread::current(); |
ysr@777 | 72 | _vtime_start = os::elapsedVTime(); |
ysr@777 | 73 | wait_for_universe_init(); |
ysr@777 | 74 | _co_tracker.enable(); |
ysr@777 | 75 | _co_tracker.start(); |
ysr@777 | 76 | |
ysr@777 | 77 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
ysr@777 | 78 | _sts.join(); |
ysr@777 | 79 | while (!_should_terminate) { |
ysr@777 | 80 | _sts.leave(); |
ysr@777 | 81 | |
ysr@777 | 82 | { |
ysr@777 | 83 | MutexLockerEx x(ZF_mon, Mutex::_no_safepoint_check_flag); |
ysr@777 | 84 | |
ysr@777 | 85 | // This local variable will hold a region being zero-filled. This |
ysr@777 | 86 | // region will neither be on the unclean or zero-filled lists, and |
ysr@777 | 87 | // will not be available for allocation; thus, we might have an |
ysr@777 | 88 | // allocation fail, causing a full GC, because of this, but this is a |
ysr@777 | 89 | // price we will pay. (In future, we might want to make the fact |
ysr@777 | 90 | // that there's a region being zero-filled apparent to the G1 heap, |
ysr@777 | 91 | // which could then wait for it in this extreme case...) |
ysr@777 | 92 | HeapRegion* to_fill; |
ysr@777 | 93 | |
ysr@777 | 94 | while (!g1->should_zf() |
ysr@777 | 95 | || (to_fill = g1->pop_unclean_region_list_locked()) == NULL) |
ysr@777 | 96 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 97 | while (to_fill->zero_fill_state() == HeapRegion::ZeroFilling) |
ysr@777 | 98 | ZF_mon->wait(Mutex::_no_safepoint_check_flag); |
ysr@777 | 99 | |
ysr@777 | 100 | // So now to_fill is non-NULL and is not ZeroFilling. It might be |
ysr@777 | 101 | // Allocated or ZeroFilled. (The latter could happen if this thread |
ysr@777 | 102 | // starts the zero-filling of a region, but a GC intervenes and |
ysr@777 | 103 | // pushes new regions needing on the front of the filling on the |
ysr@777 | 104 | // front of the list.) |
ysr@777 | 105 | |
ysr@777 | 106 | switch (to_fill->zero_fill_state()) { |
ysr@777 | 107 | case HeapRegion::Allocated: |
ysr@777 | 108 | to_fill = NULL; |
ysr@777 | 109 | break; |
ysr@777 | 110 | |
ysr@777 | 111 | case HeapRegion::NotZeroFilled: |
ysr@777 | 112 | to_fill->set_zero_fill_in_progress(thr_self); |
ysr@777 | 113 | |
ysr@777 | 114 | ZF_mon->unlock(); |
ysr@777 | 115 | _sts.join(); |
ysr@777 | 116 | processHeapRegion(to_fill); |
ysr@777 | 117 | _sts.leave(); |
ysr@777 | 118 | ZF_mon->lock_without_safepoint_check(); |
ysr@777 | 119 | |
ysr@777 | 120 | if (to_fill->zero_fill_state() == HeapRegion::ZeroFilling |
ysr@777 | 121 | && to_fill->zero_filler() == thr_self) { |
ysr@777 | 122 | to_fill->set_zero_fill_complete(); |
ysr@777 | 123 | (void)g1->put_free_region_on_list_locked(to_fill); |
ysr@777 | 124 | } |
ysr@777 | 125 | break; |
ysr@777 | 126 | |
ysr@777 | 127 | case HeapRegion::ZeroFilled: |
ysr@777 | 128 | (void)g1->put_free_region_on_list_locked(to_fill); |
ysr@777 | 129 | break; |
ysr@777 | 130 | |
ysr@777 | 131 | case HeapRegion::ZeroFilling: |
ysr@777 | 132 | ShouldNotReachHere(); |
ysr@777 | 133 | break; |
ysr@777 | 134 | } |
ysr@777 | 135 | } |
ysr@777 | 136 | _vtime_accum = (os::elapsedVTime() - _vtime_start); |
ysr@777 | 137 | _sts.join(); |
ysr@777 | 138 | |
ysr@777 | 139 | _co_tracker.update(); |
ysr@777 | 140 | } |
ysr@777 | 141 | _co_tracker.update(false); |
ysr@777 | 142 | _sts.leave(); |
ysr@777 | 143 | |
ysr@777 | 144 | assert(_should_terminate, "just checking"); |
ysr@777 | 145 | terminate(); |
ysr@777 | 146 | } |
ysr@777 | 147 | |
ysr@777 | 148 | bool ConcurrentZFThread::offer_yield() { |
ysr@777 | 149 | if (_sts.should_yield()) { |
ysr@777 | 150 | _sts.yield("Concurrent ZF"); |
ysr@777 | 151 | return true; |
ysr@777 | 152 | } else { |
ysr@777 | 153 | return false; |
ysr@777 | 154 | } |
ysr@777 | 155 | } |
ysr@777 | 156 | |
ysr@777 | 157 | void ConcurrentZFThread::stop() { |
ysr@777 | 158 | // it is ok to take late safepoints here, if needed |
ysr@777 | 159 | MutexLockerEx mu(Terminator_lock); |
ysr@777 | 160 | _should_terminate = true; |
ysr@777 | 161 | while (!_has_terminated) { |
ysr@777 | 162 | Terminator_lock->wait(); |
ysr@777 | 163 | } |
ysr@777 | 164 | } |
ysr@777 | 165 | |
ysr@777 | 166 | void ConcurrentZFThread::print() { |
ysr@777 | 167 | gclog_or_tty->print("\"Concurrent ZF Thread\" "); |
ysr@777 | 168 | Thread::print(); |
ysr@777 | 169 | gclog_or_tty->cr(); |
ysr@777 | 170 | } |
ysr@777 | 171 | |
ysr@777 | 172 | |
ysr@777 | 173 | double ConcurrentZFThread::_vtime_accum; |
ysr@777 | 174 | |
ysr@777 | 175 | void ConcurrentZFThread::print_summary_info() { |
ysr@777 | 176 | gclog_or_tty->print("\nConcurrent Zero-Filling:\n"); |
ysr@777 | 177 | gclog_or_tty->print(" Filled %d regions, used %5.2fs.\n", |
ysr@777 | 178 | _regions_filled, |
ysr@777 | 179 | vtime_accum()); |
ysr@777 | 180 | gclog_or_tty->print(" Of %d region allocs, %d (%5.2f%%) required sync ZF,\n", |
ysr@777 | 181 | _region_allocs, _sync_zfs, |
ysr@777 | 182 | (_region_allocs > 0 ? |
ysr@777 | 183 | (float)_sync_zfs/(float)_region_allocs*100.0 : |
ysr@777 | 184 | 0.0)); |
ysr@777 | 185 | gclog_or_tty->print(" and %d (%5.2f%%) required a ZF wait.\n", |
ysr@777 | 186 | _zf_waits, |
ysr@777 | 187 | (_region_allocs > 0 ? |
ysr@777 | 188 | (float)_zf_waits/(float)_region_allocs*100.0 : |
ysr@777 | 189 | 0.0)); |
ysr@777 | 190 | |
ysr@777 | 191 | } |