Sat, 28 Mar 2009 15:47:29 -0700
6819891: ParNew: Fix work queue overflow code to deal correctly with +UseCompressedOops
Summary: When using compressed oops, rather than chaining the overflowed grey objects' pre-images through their klass words, we use GC-worker thread-local overflow stacks.
Reviewed-by: jcoomes, jmasa
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_interfaceSupport.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | // Implementation of InterfaceSupport |
duke@435 | 30 | |
duke@435 | 31 | #ifdef ASSERT |
duke@435 | 32 | |
duke@435 | 33 | long InterfaceSupport::_number_of_calls = 0; |
duke@435 | 34 | long InterfaceSupport::_scavenge_alot_counter = 1; |
duke@435 | 35 | long InterfaceSupport::_fullgc_alot_counter = 1; |
duke@435 | 36 | long InterfaceSupport::_fullgc_alot_invocation = 0; |
duke@435 | 37 | |
duke@435 | 38 | Histogram* RuntimeHistogram; |
duke@435 | 39 | |
duke@435 | 40 | RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) { |
duke@435 | 41 | static volatile jint RuntimeHistogram_lock = 0; |
duke@435 | 42 | _name = elementName; |
duke@435 | 43 | uintx count = 0; |
duke@435 | 44 | |
duke@435 | 45 | while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) { |
duke@435 | 46 | while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) { |
duke@435 | 47 | count +=1; |
duke@435 | 48 | if ( (WarnOnStalledSpinLock > 0) |
duke@435 | 49 | && (count % WarnOnStalledSpinLock == 0)) { |
duke@435 | 50 | warning("RuntimeHistogram_lock seems to be stalled"); |
duke@435 | 51 | } |
duke@435 | 52 | } |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | if (RuntimeHistogram == NULL) { |
duke@435 | 56 | RuntimeHistogram = new Histogram("VM Runtime Call Counts",200); |
duke@435 | 57 | } |
duke@435 | 58 | |
duke@435 | 59 | RuntimeHistogram->add_element(this); |
duke@435 | 60 | Atomic::dec(&RuntimeHistogram_lock); |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | void InterfaceSupport::trace(const char* result_type, const char* header) { |
duke@435 | 64 | tty->print_cr("%6d %s", _number_of_calls, header); |
duke@435 | 65 | } |
duke@435 | 66 | |
duke@435 | 67 | void InterfaceSupport::gc_alot() { |
duke@435 | 68 | Thread *thread = Thread::current(); |
duke@435 | 69 | if (thread->is_VM_thread()) return; // Avoid concurrent calls |
duke@435 | 70 | // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC. |
duke@435 | 71 | JavaThread *current_thread = (JavaThread *)thread; |
duke@435 | 72 | if (current_thread->active_handles() == NULL) return; |
duke@435 | 73 | |
duke@435 | 74 | if (is_init_completed()) { |
duke@435 | 75 | |
duke@435 | 76 | if (++_fullgc_alot_invocation < FullGCALotStart) { |
duke@435 | 77 | return; |
duke@435 | 78 | } |
duke@435 | 79 | |
duke@435 | 80 | // Use this line if you want to block at a specific point, |
duke@435 | 81 | // e.g. one number_of_calls/scavenge/gc before you got into problems |
duke@435 | 82 | if (FullGCALot) _fullgc_alot_counter--; |
duke@435 | 83 | |
duke@435 | 84 | // Check if we should force a full gc |
duke@435 | 85 | if (_fullgc_alot_counter == 0) { |
duke@435 | 86 | // Release dummy so objects are forced to move |
duke@435 | 87 | if (!Universe::release_fullgc_alot_dummy()) { |
duke@435 | 88 | warning("FullGCALot: Unable to release more dummies at bottom of heap"); |
duke@435 | 89 | } |
duke@435 | 90 | HandleMark hm(thread); |
duke@435 | 91 | Universe::heap()->collect(GCCause::_full_gc_alot); |
duke@435 | 92 | unsigned int invocations = Universe::heap()->total_full_collections(); |
duke@435 | 93 | // Compute new interval |
duke@435 | 94 | if (FullGCALotInterval > 1) { |
duke@435 | 95 | _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0)); |
duke@435 | 96 | if (PrintGCDetails && Verbose) { |
duke@435 | 97 | tty->print_cr("Full gc no: %u\tInterval: %d", invocations, |
duke@435 | 98 | _fullgc_alot_counter); |
duke@435 | 99 | } |
duke@435 | 100 | } else { |
duke@435 | 101 | _fullgc_alot_counter = 1; |
duke@435 | 102 | } |
duke@435 | 103 | // Print progress message |
duke@435 | 104 | if (invocations % 100 == 0) { |
duke@435 | 105 | if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations); |
duke@435 | 106 | } |
duke@435 | 107 | } else { |
duke@435 | 108 | if (ScavengeALot) _scavenge_alot_counter--; |
duke@435 | 109 | // Check if we should force a scavenge |
duke@435 | 110 | if (_scavenge_alot_counter == 0) { |
duke@435 | 111 | HandleMark hm(thread); |
duke@435 | 112 | Universe::heap()->collect(GCCause::_scavenge_alot); |
duke@435 | 113 | unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections(); |
duke@435 | 114 | // Compute new interval |
duke@435 | 115 | if (ScavengeALotInterval > 1) { |
duke@435 | 116 | _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0)); |
duke@435 | 117 | if (PrintGCDetails && Verbose) { |
duke@435 | 118 | tty->print_cr("Scavenge no: %u\tInterval: %d", invocations, |
duke@435 | 119 | _scavenge_alot_counter); |
duke@435 | 120 | } |
duke@435 | 121 | } else { |
duke@435 | 122 | _scavenge_alot_counter = 1; |
duke@435 | 123 | } |
duke@435 | 124 | // Print progress message |
duke@435 | 125 | if (invocations % 1000 == 0) { |
duke@435 | 126 | if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations); |
duke@435 | 127 | } |
duke@435 | 128 | } |
duke@435 | 129 | } |
duke@435 | 130 | } |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | |
duke@435 | 134 | vframe* vframe_array[50]; |
duke@435 | 135 | int walk_stack_counter = 0; |
duke@435 | 136 | |
duke@435 | 137 | void InterfaceSupport::walk_stack_from(vframe* start_vf) { |
duke@435 | 138 | // walk |
duke@435 | 139 | int i = 0; |
duke@435 | 140 | for (vframe* f = start_vf; f; f = f->sender() ) { |
duke@435 | 141 | if (i < 50) vframe_array[i++] = f; |
duke@435 | 142 | } |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | |
duke@435 | 146 | void InterfaceSupport::walk_stack() { |
duke@435 | 147 | JavaThread* thread = JavaThread::current(); |
duke@435 | 148 | walk_stack_counter++; |
duke@435 | 149 | if (!thread->has_last_Java_frame()) return; |
duke@435 | 150 | ResourceMark rm(thread); |
duke@435 | 151 | RegisterMap reg_map(thread); |
duke@435 | 152 | walk_stack_from(thread->last_java_vframe(®_map)); |
duke@435 | 153 | } |
duke@435 | 154 | |
duke@435 | 155 | |
duke@435 | 156 | # ifdef ENABLE_ZAP_DEAD_LOCALS |
duke@435 | 157 | |
duke@435 | 158 | static int zap_traversals = 0; |
duke@435 | 159 | |
duke@435 | 160 | void InterfaceSupport::zap_dead_locals_old() { |
duke@435 | 161 | JavaThread* thread = JavaThread::current(); |
duke@435 | 162 | if (zap_traversals == -1) // edit constant for debugging |
duke@435 | 163 | warning("I am here"); |
duke@435 | 164 | int zap_frame_count = 0; // count frames to help debugging |
duke@435 | 165 | for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) { |
duke@435 | 166 | sfs.current()->zap_dead_locals(thread, sfs.register_map()); |
duke@435 | 167 | ++zap_frame_count; |
duke@435 | 168 | } |
duke@435 | 169 | ++zap_traversals; |
duke@435 | 170 | } |
duke@435 | 171 | |
duke@435 | 172 | # endif |
duke@435 | 173 | |
duke@435 | 174 | |
duke@435 | 175 | int deoptimizeAllCounter = 0; |
duke@435 | 176 | int zombieAllCounter = 0; |
duke@435 | 177 | |
duke@435 | 178 | |
duke@435 | 179 | void InterfaceSupport::zombieAll() { |
duke@435 | 180 | if (is_init_completed() && zombieAllCounter > ZombieALotInterval) { |
duke@435 | 181 | zombieAllCounter = 0; |
duke@435 | 182 | VM_ZombieAll op; |
duke@435 | 183 | VMThread::execute(&op); |
duke@435 | 184 | } else { |
duke@435 | 185 | zombieAllCounter++; |
duke@435 | 186 | } |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | void InterfaceSupport::deoptimizeAll() { |
duke@435 | 190 | if (is_init_completed() ) { |
duke@435 | 191 | if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) { |
duke@435 | 192 | deoptimizeAllCounter = 0; |
duke@435 | 193 | VM_DeoptimizeAll op; |
duke@435 | 194 | VMThread::execute(&op); |
duke@435 | 195 | } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) { |
duke@435 | 196 | VM_DeoptimizeAll op; |
duke@435 | 197 | VMThread::execute(&op); |
duke@435 | 198 | } |
duke@435 | 199 | } |
duke@435 | 200 | deoptimizeAllCounter++; |
duke@435 | 201 | } |
duke@435 | 202 | |
duke@435 | 203 | |
duke@435 | 204 | void InterfaceSupport::stress_derived_pointers() { |
duke@435 | 205 | #ifdef COMPILER2 |
duke@435 | 206 | JavaThread *thread = JavaThread::current(); |
duke@435 | 207 | if (!is_init_completed()) return; |
duke@435 | 208 | ResourceMark rm(thread); |
duke@435 | 209 | bool found = false; |
duke@435 | 210 | for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) { |
duke@435 | 211 | CodeBlob* cb = sfs.current()->cb(); |
duke@435 | 212 | if (cb != NULL && cb->oop_maps() ) { |
duke@435 | 213 | // Find oopmap for current method |
duke@435 | 214 | OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc()); |
duke@435 | 215 | assert(map != NULL, "no oopmap found for pc"); |
duke@435 | 216 | found = map->has_derived_pointer(); |
duke@435 | 217 | } |
duke@435 | 218 | } |
duke@435 | 219 | if (found) { |
duke@435 | 220 | // $$$ Not sure what to do here. |
duke@435 | 221 | /* |
duke@435 | 222 | Scavenge::invoke(0); |
duke@435 | 223 | */ |
duke@435 | 224 | } |
duke@435 | 225 | #endif |
duke@435 | 226 | } |
duke@435 | 227 | |
duke@435 | 228 | |
duke@435 | 229 | void InterfaceSupport::verify_stack() { |
duke@435 | 230 | JavaThread* thread = JavaThread::current(); |
duke@435 | 231 | ResourceMark rm(thread); |
duke@435 | 232 | // disabled because it throws warnings that oop maps should only be accessed |
duke@435 | 233 | // in VM thread or during debugging |
duke@435 | 234 | |
duke@435 | 235 | if (!thread->has_pending_exception()) { |
duke@435 | 236 | // verification does not work if there are pending exceptions |
duke@435 | 237 | StackFrameStream sfs(thread); |
duke@435 | 238 | CodeBlob* cb = sfs.current()->cb(); |
duke@435 | 239 | // In case of exceptions we might not have a runtime_stub on |
duke@435 | 240 | // top of stack, hence, all callee-saved registers are not going |
duke@435 | 241 | // to be setup correctly, hence, we cannot do stack verify |
duke@435 | 242 | if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return; |
duke@435 | 243 | |
duke@435 | 244 | for (; !sfs.is_done(); sfs.next()) { |
duke@435 | 245 | sfs.current()->verify(sfs.register_map()); |
duke@435 | 246 | } |
duke@435 | 247 | } |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | |
duke@435 | 251 | void InterfaceSupport::verify_last_frame() { |
duke@435 | 252 | JavaThread* thread = JavaThread::current(); |
duke@435 | 253 | ResourceMark rm(thread); |
duke@435 | 254 | RegisterMap reg_map(thread); |
duke@435 | 255 | frame fr = thread->last_frame(); |
duke@435 | 256 | fr.verify(®_map); |
duke@435 | 257 | } |
duke@435 | 258 | |
duke@435 | 259 | |
duke@435 | 260 | #endif // ASSERT |
duke@435 | 261 | |
duke@435 | 262 | |
duke@435 | 263 | void InterfaceSupport_init() { |
duke@435 | 264 | #ifdef ASSERT |
duke@435 | 265 | if (ScavengeALot || FullGCALot) { |
duke@435 | 266 | srand(ScavengeALotInterval * FullGCALotInterval); |
duke@435 | 267 | } |
duke@435 | 268 | #endif |
duke@435 | 269 | } |