Tue, 19 Aug 2014 02:05:49 -0700
8044406: JVM crash with JDK8 (build 1.8.0-b132) with G1 GC
Summary: Fill the last card that has been allocated into with a dummy object
Reviewed-by: tschatzl, mgerdin
ysr@777 | 1 | /* |
johnc@2060 | 2 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 | * |
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. |
ysr@777 | 22 | * |
ysr@777 | 23 | */ |
ysr@777 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "gc_implementation/g1/dirtyCardQueue.hpp" |
tschatzl@6541 | 27 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
stefank@2314 | 28 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
stefank@2314 | 29 | #include "runtime/atomic.hpp" |
stefank@2314 | 30 | #include "runtime/mutexLocker.hpp" |
stefank@2314 | 31 | #include "runtime/safepoint.hpp" |
stefank@4299 | 32 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 33 | #include "utilities/workgroup.hpp" |
ysr@777 | 34 | |
ysr@777 | 35 | bool DirtyCardQueue::apply_closure(CardTableEntryClosure* cl, |
ysr@777 | 36 | bool consume, |
vkempik@6552 | 37 | uint worker_i) { |
ysr@777 | 38 | bool res = true; |
ysr@777 | 39 | if (_buf != NULL) { |
ysr@777 | 40 | res = apply_closure_to_buffer(cl, _buf, _index, _sz, |
ysr@777 | 41 | consume, |
vkempik@6552 | 42 | worker_i); |
ysr@777 | 43 | if (res && consume) _index = _sz; |
ysr@777 | 44 | } |
ysr@777 | 45 | return res; |
ysr@777 | 46 | } |
ysr@777 | 47 | |
ysr@777 | 48 | bool DirtyCardQueue::apply_closure_to_buffer(CardTableEntryClosure* cl, |
ysr@777 | 49 | void** buf, |
ysr@777 | 50 | size_t index, size_t sz, |
ysr@777 | 51 | bool consume, |
vkempik@6552 | 52 | uint worker_i) { |
ysr@777 | 53 | if (cl == NULL) return true; |
ysr@777 | 54 | for (size_t i = index; i < sz; i += oopSize) { |
ysr@777 | 55 | int ind = byte_index_to_index((int)i); |
ysr@777 | 56 | jbyte* card_ptr = (jbyte*)buf[ind]; |
ysr@777 | 57 | if (card_ptr != NULL) { |
ysr@777 | 58 | // Set the entry to null, so we don't do it again (via the test |
ysr@777 | 59 | // above) if we reconsider this buffer. |
ysr@777 | 60 | if (consume) buf[ind] = NULL; |
ysr@777 | 61 | if (!cl->do_card_ptr(card_ptr, worker_i)) return false; |
ysr@777 | 62 | } |
ysr@777 | 63 | } |
ysr@777 | 64 | return true; |
ysr@777 | 65 | } |
ysr@777 | 66 | |
ysr@777 | 67 | #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away |
ysr@777 | 68 | #pragma warning( disable:4355 ) // 'this' : used in base member initializer list |
ysr@777 | 69 | #endif // _MSC_VER |
ysr@777 | 70 | |
iveresov@1546 | 71 | DirtyCardQueueSet::DirtyCardQueueSet(bool notify_when_complete) : |
iveresov@1546 | 72 | PtrQueueSet(notify_when_complete), |
ysr@777 | 73 | _closure(NULL), |
ysr@777 | 74 | _shared_dirty_card_queue(this, true /*perm*/), |
ysr@777 | 75 | _free_ids(NULL), |
ysr@777 | 76 | _processed_buffers_mut(0), _processed_buffers_rs_thread(0) |
ysr@777 | 77 | { |
ysr@777 | 78 | _all_active = true; |
ysr@777 | 79 | } |
ysr@777 | 80 | |
iveresov@1230 | 81 | // Determines how many mutator threads can process the buffers in parallel. |
vkempik@6552 | 82 | uint DirtyCardQueueSet::num_par_ids() { |
vkempik@6552 | 83 | return (uint)os::processor_count(); |
ysr@777 | 84 | } |
ysr@777 | 85 | |
ysr@777 | 86 | void DirtyCardQueueSet::initialize(Monitor* cbl_mon, Mutex* fl_lock, |
iveresov@1546 | 87 | int process_completed_threshold, |
ysr@777 | 88 | int max_completed_queue, |
iveresov@1051 | 89 | Mutex* lock, PtrQueueSet* fl_owner) { |
iveresov@1546 | 90 | PtrQueueSet::initialize(cbl_mon, fl_lock, process_completed_threshold, |
iveresov@1546 | 91 | max_completed_queue, fl_owner); |
tonyp@1318 | 92 | set_buffer_size(G1UpdateBufferSize); |
ysr@777 | 93 | _shared_dirty_card_queue.set_lock(lock); |
ysr@777 | 94 | _free_ids = new FreeIdSet((int) num_par_ids(), _cbl_mon); |
ysr@777 | 95 | } |
ysr@777 | 96 | |
ysr@777 | 97 | void DirtyCardQueueSet::handle_zero_index_for_thread(JavaThread* t) { |
ysr@777 | 98 | t->dirty_card_queue().handle_zero_index(); |
ysr@777 | 99 | } |
ysr@777 | 100 | |
ysr@777 | 101 | void DirtyCardQueueSet::set_closure(CardTableEntryClosure* closure) { |
ysr@777 | 102 | _closure = closure; |
ysr@777 | 103 | } |
ysr@777 | 104 | |
ysr@777 | 105 | void DirtyCardQueueSet::iterate_closure_all_threads(bool consume, |
vkempik@6552 | 106 | uint worker_i) { |
ysr@777 | 107 | assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
ysr@777 | 108 | for(JavaThread* t = Threads::first(); t; t = t->next()) { |
ysr@777 | 109 | bool b = t->dirty_card_queue().apply_closure(_closure, consume); |
ysr@777 | 110 | guarantee(b, "Should not be interrupted."); |
ysr@777 | 111 | } |
ysr@777 | 112 | bool b = shared_dirty_card_queue()->apply_closure(_closure, |
ysr@777 | 113 | consume, |
ysr@777 | 114 | worker_i); |
ysr@777 | 115 | guarantee(b, "Should not be interrupted."); |
ysr@777 | 116 | } |
ysr@777 | 117 | |
ysr@777 | 118 | bool DirtyCardQueueSet::mut_process_buffer(void** buf) { |
ysr@777 | 119 | |
ysr@777 | 120 | // Used to determine if we had already claimed a par_id |
ysr@777 | 121 | // before entering this method. |
ysr@777 | 122 | bool already_claimed = false; |
ysr@777 | 123 | |
ysr@777 | 124 | // We grab the current JavaThread. |
ysr@777 | 125 | JavaThread* thread = JavaThread::current(); |
ysr@777 | 126 | |
ysr@777 | 127 | // We get the the number of any par_id that this thread |
ysr@777 | 128 | // might have already claimed. |
vkempik@6552 | 129 | uint worker_i = thread->get_claimed_par_id(); |
ysr@777 | 130 | |
vkempik@6552 | 131 | // If worker_i is not UINT_MAX then the thread has already claimed |
ysr@777 | 132 | // a par_id. We make note of it using the already_claimed value |
vkempik@6552 | 133 | if (worker_i != UINT_MAX) { |
ysr@777 | 134 | already_claimed = true; |
ysr@777 | 135 | } else { |
ysr@777 | 136 | |
ysr@777 | 137 | // Otherwise we need to claim a par id |
ysr@777 | 138 | worker_i = _free_ids->claim_par_id(); |
ysr@777 | 139 | |
ysr@777 | 140 | // And store the par_id value in the thread |
ysr@777 | 141 | thread->set_claimed_par_id(worker_i); |
ysr@777 | 142 | } |
ysr@777 | 143 | |
ysr@777 | 144 | bool b = false; |
vkempik@6552 | 145 | if (worker_i != UINT_MAX) { |
ysr@777 | 146 | b = DirtyCardQueue::apply_closure_to_buffer(_closure, buf, 0, |
ysr@777 | 147 | _sz, true, worker_i); |
ysr@777 | 148 | if (b) Atomic::inc(&_processed_buffers_mut); |
ysr@777 | 149 | |
ysr@777 | 150 | // If we had not claimed an id before entering the method |
ysr@777 | 151 | // then we must release the id. |
ysr@777 | 152 | if (!already_claimed) { |
ysr@777 | 153 | |
ysr@777 | 154 | // we release the id |
ysr@777 | 155 | _free_ids->release_par_id(worker_i); |
ysr@777 | 156 | |
vkempik@6552 | 157 | // and set the claimed_id in the thread to UINT_MAX |
vkempik@6552 | 158 | thread->set_claimed_par_id(UINT_MAX); |
ysr@777 | 159 | } |
ysr@777 | 160 | } |
ysr@777 | 161 | return b; |
ysr@777 | 162 | } |
ysr@777 | 163 | |
iveresov@1546 | 164 | |
iveresov@1546 | 165 | BufferNode* |
johnc@1525 | 166 | DirtyCardQueueSet::get_completed_buffer(int stop_at) { |
iveresov@1546 | 167 | BufferNode* nd = NULL; |
ysr@777 | 168 | MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
ysr@777 | 169 | |
ysr@777 | 170 | if ((int)_n_completed_buffers <= stop_at) { |
ysr@777 | 171 | _process_completed = false; |
ysr@777 | 172 | return NULL; |
ysr@777 | 173 | } |
ysr@777 | 174 | |
ysr@777 | 175 | if (_completed_buffers_head != NULL) { |
ysr@777 | 176 | nd = _completed_buffers_head; |
iveresov@1546 | 177 | _completed_buffers_head = nd->next(); |
ysr@777 | 178 | if (_completed_buffers_head == NULL) |
ysr@777 | 179 | _completed_buffers_tail = NULL; |
ysr@777 | 180 | _n_completed_buffers--; |
iveresov@1546 | 181 | assert(_n_completed_buffers >= 0, "Invariant"); |
ysr@777 | 182 | } |
ysr@777 | 183 | debug_only(assert_completed_buffer_list_len_correct_locked()); |
ysr@777 | 184 | return nd; |
ysr@777 | 185 | } |
ysr@777 | 186 | |
ysr@777 | 187 | bool DirtyCardQueueSet:: |
johnc@2060 | 188 | apply_closure_to_completed_buffer_helper(CardTableEntryClosure* cl, |
vkempik@6552 | 189 | uint worker_i, |
iveresov@1546 | 190 | BufferNode* nd) { |
ysr@777 | 191 | if (nd != NULL) { |
iveresov@1546 | 192 | void **buf = BufferNode::make_buffer_from_node(nd); |
iveresov@1546 | 193 | size_t index = nd->index(); |
ysr@777 | 194 | bool b = |
johnc@2060 | 195 | DirtyCardQueue::apply_closure_to_buffer(cl, buf, |
iveresov@1546 | 196 | index, _sz, |
ysr@777 | 197 | true, worker_i); |
ysr@777 | 198 | if (b) { |
ysr@777 | 199 | deallocate_buffer(buf); |
ysr@777 | 200 | return true; // In normal case, go on to next buffer. |
ysr@777 | 201 | } else { |
iveresov@1546 | 202 | enqueue_complete_buffer(buf, index); |
ysr@777 | 203 | return false; |
ysr@777 | 204 | } |
ysr@777 | 205 | } else { |
ysr@777 | 206 | return false; |
ysr@777 | 207 | } |
ysr@777 | 208 | } |
ysr@777 | 209 | |
johnc@2060 | 210 | bool DirtyCardQueueSet::apply_closure_to_completed_buffer(CardTableEntryClosure* cl, |
vkempik@6552 | 211 | uint worker_i, |
johnc@2060 | 212 | int stop_at, |
johnc@2060 | 213 | bool during_pause) { |
johnc@2060 | 214 | assert(!during_pause || stop_at == 0, "Should not leave any completed buffers during a pause"); |
johnc@2060 | 215 | BufferNode* nd = get_completed_buffer(stop_at); |
johnc@2060 | 216 | bool res = apply_closure_to_completed_buffer_helper(cl, worker_i, nd); |
johnc@2060 | 217 | if (res) Atomic::inc(&_processed_buffers_rs_thread); |
johnc@2060 | 218 | return res; |
johnc@2060 | 219 | } |
johnc@2060 | 220 | |
vkempik@6552 | 221 | bool DirtyCardQueueSet::apply_closure_to_completed_buffer(uint worker_i, |
ysr@777 | 222 | int stop_at, |
johnc@2060 | 223 | bool during_pause) { |
johnc@2060 | 224 | return apply_closure_to_completed_buffer(_closure, worker_i, |
johnc@2060 | 225 | stop_at, during_pause); |
ysr@777 | 226 | } |
ysr@777 | 227 | |
ysr@777 | 228 | void DirtyCardQueueSet::apply_closure_to_all_completed_buffers() { |
iveresov@1546 | 229 | BufferNode* nd = _completed_buffers_head; |
ysr@777 | 230 | while (nd != NULL) { |
ysr@777 | 231 | bool b = |
iveresov@1546 | 232 | DirtyCardQueue::apply_closure_to_buffer(_closure, |
iveresov@1546 | 233 | BufferNode::make_buffer_from_node(nd), |
iveresov@1546 | 234 | 0, _sz, false); |
ysr@777 | 235 | guarantee(b, "Should not stop early."); |
iveresov@1546 | 236 | nd = nd->next(); |
ysr@777 | 237 | } |
ysr@777 | 238 | } |
ysr@777 | 239 | |
johnc@2060 | 240 | // Deallocates any completed log buffers |
johnc@2060 | 241 | void DirtyCardQueueSet::clear() { |
iveresov@1546 | 242 | BufferNode* buffers_to_delete = NULL; |
ysr@777 | 243 | { |
ysr@777 | 244 | MutexLockerEx x(_cbl_mon, Mutex::_no_safepoint_check_flag); |
ysr@777 | 245 | while (_completed_buffers_head != NULL) { |
iveresov@1546 | 246 | BufferNode* nd = _completed_buffers_head; |
iveresov@1546 | 247 | _completed_buffers_head = nd->next(); |
iveresov@1546 | 248 | nd->set_next(buffers_to_delete); |
ysr@777 | 249 | buffers_to_delete = nd; |
ysr@777 | 250 | } |
ysr@777 | 251 | _n_completed_buffers = 0; |
ysr@777 | 252 | _completed_buffers_tail = NULL; |
ysr@777 | 253 | debug_only(assert_completed_buffer_list_len_correct_locked()); |
ysr@777 | 254 | } |
ysr@777 | 255 | while (buffers_to_delete != NULL) { |
iveresov@1546 | 256 | BufferNode* nd = buffers_to_delete; |
iveresov@1546 | 257 | buffers_to_delete = nd->next(); |
iveresov@1546 | 258 | deallocate_buffer(BufferNode::make_buffer_from_node(nd)); |
ysr@777 | 259 | } |
johnc@2060 | 260 | |
johnc@2060 | 261 | } |
johnc@2060 | 262 | |
johnc@2060 | 263 | void DirtyCardQueueSet::abandon_logs() { |
johnc@2060 | 264 | assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
johnc@2060 | 265 | clear(); |
ysr@777 | 266 | // Since abandon is done only at safepoints, we can safely manipulate |
ysr@777 | 267 | // these queues. |
ysr@777 | 268 | for (JavaThread* t = Threads::first(); t; t = t->next()) { |
ysr@777 | 269 | t->dirty_card_queue().reset(); |
ysr@777 | 270 | } |
ysr@777 | 271 | shared_dirty_card_queue()->reset(); |
ysr@777 | 272 | } |
ysr@777 | 273 | |
ysr@777 | 274 | |
ysr@777 | 275 | void DirtyCardQueueSet::concatenate_logs() { |
ysr@777 | 276 | // Iterate over all the threads, if we find a partial log add it to |
ysr@777 | 277 | // the global list of logs. Temporarily turn off the limit on the number |
ysr@777 | 278 | // of outstanding buffers. |
ysr@777 | 279 | int save_max_completed_queue = _max_completed_queue; |
ysr@777 | 280 | _max_completed_queue = max_jint; |
ysr@777 | 281 | assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint."); |
ysr@777 | 282 | for (JavaThread* t = Threads::first(); t; t = t->next()) { |
ysr@777 | 283 | DirtyCardQueue& dcq = t->dirty_card_queue(); |
ysr@777 | 284 | if (dcq.size() != 0) { |
ysr@777 | 285 | void **buf = t->dirty_card_queue().get_buf(); |
ysr@777 | 286 | // We must NULL out the unused entries, then enqueue. |
ysr@777 | 287 | for (size_t i = 0; i < t->dirty_card_queue().get_index(); i += oopSize) { |
ysr@777 | 288 | buf[PtrQueue::byte_index_to_index((int)i)] = NULL; |
ysr@777 | 289 | } |
ysr@777 | 290 | enqueue_complete_buffer(dcq.get_buf(), dcq.get_index()); |
ysr@777 | 291 | dcq.reinitialize(); |
ysr@777 | 292 | } |
ysr@777 | 293 | } |
ysr@777 | 294 | if (_shared_dirty_card_queue.size() != 0) { |
ysr@777 | 295 | enqueue_complete_buffer(_shared_dirty_card_queue.get_buf(), |
ysr@777 | 296 | _shared_dirty_card_queue.get_index()); |
ysr@777 | 297 | _shared_dirty_card_queue.reinitialize(); |
ysr@777 | 298 | } |
ysr@777 | 299 | // Restore the completed buffer queue limit. |
ysr@777 | 300 | _max_completed_queue = save_max_completed_queue; |
ysr@777 | 301 | } |