src/share/vm/runtime/interfaceSupport.cpp

Tue, 11 Nov 2014 13:39:00 -0500

author
kbarrett
date
Tue, 11 Nov 2014 13:39:00 -0500
changeset 7360
4e4ebe50c8e3
parent 6911
ce8f6bb717c9
child 7535
7ae4e26cb1e0
child 7875
fb260f267e87
permissions
-rw-r--r--

8062036: ConcurrentMarkThread::slt may be invoked before ConcurrentMarkThread::makeSurrogateLockerThread causing intermittent crashes
Summary: Suppress gc_alot during VM init, improve error for SLT uninitialized.
Reviewed-by: jmasa, brutisso, tschatzl

duke@435 1 /*
drchase@6680 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. 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 *
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.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/shared/markSweep.hpp"
stefank@2314 27 #include "gc_interface/collectedHeap.hpp"
stefank@2314 28 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 29 #include "memory/genCollectedHeap.hpp"
stefank@2314 30 #include "memory/resourceArea.hpp"
stefank@2314 31 #include "runtime/init.hpp"
stefank@2314 32 #include "runtime/interfaceSupport.hpp"
goetz@6911 33 #include "runtime/orderAccess.inline.hpp"
stefank@2314 34 #include "runtime/threadLocalStorage.hpp"
stefank@2314 35 #include "runtime/vframe.hpp"
stefank@2314 36 #include "utilities/preserveException.hpp"
duke@435 37
drchase@6680 38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
duke@435 39
duke@435 40 // Implementation of InterfaceSupport
duke@435 41
duke@435 42 #ifdef ASSERT
duke@435 43
duke@435 44 long InterfaceSupport::_number_of_calls = 0;
duke@435 45 long InterfaceSupport::_scavenge_alot_counter = 1;
duke@435 46 long InterfaceSupport::_fullgc_alot_counter = 1;
duke@435 47 long InterfaceSupport::_fullgc_alot_invocation = 0;
duke@435 48
duke@435 49 Histogram* RuntimeHistogram;
duke@435 50
duke@435 51 RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
duke@435 52 static volatile jint RuntimeHistogram_lock = 0;
duke@435 53 _name = elementName;
duke@435 54 uintx count = 0;
duke@435 55
duke@435 56 while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
duke@435 57 while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
duke@435 58 count +=1;
duke@435 59 if ( (WarnOnStalledSpinLock > 0)
duke@435 60 && (count % WarnOnStalledSpinLock == 0)) {
duke@435 61 warning("RuntimeHistogram_lock seems to be stalled");
duke@435 62 }
duke@435 63 }
duke@435 64 }
duke@435 65
duke@435 66 if (RuntimeHistogram == NULL) {
duke@435 67 RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
duke@435 68 }
duke@435 69
duke@435 70 RuntimeHistogram->add_element(this);
duke@435 71 Atomic::dec(&RuntimeHistogram_lock);
duke@435 72 }
duke@435 73
duke@435 74 void InterfaceSupport::trace(const char* result_type, const char* header) {
duke@435 75 tty->print_cr("%6d %s", _number_of_calls, header);
duke@435 76 }
duke@435 77
duke@435 78 void InterfaceSupport::gc_alot() {
duke@435 79 Thread *thread = Thread::current();
ysr@1241 80 if (!thread->is_Java_thread()) return; // Avoid concurrent calls
duke@435 81 // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
duke@435 82 JavaThread *current_thread = (JavaThread *)thread;
duke@435 83 if (current_thread->active_handles() == NULL) return;
duke@435 84
ysr@1241 85 // Short-circuit any possible re-entrant gc-a-lot attempt
ysr@1241 86 if (thread->skip_gcalot()) return;
ysr@1241 87
kbarrett@7360 88 if (Threads::is_vm_complete()) {
duke@435 89
duke@435 90 if (++_fullgc_alot_invocation < FullGCALotStart) {
duke@435 91 return;
duke@435 92 }
duke@435 93
duke@435 94 // Use this line if you want to block at a specific point,
duke@435 95 // e.g. one number_of_calls/scavenge/gc before you got into problems
duke@435 96 if (FullGCALot) _fullgc_alot_counter--;
duke@435 97
duke@435 98 // Check if we should force a full gc
duke@435 99 if (_fullgc_alot_counter == 0) {
duke@435 100 // Release dummy so objects are forced to move
duke@435 101 if (!Universe::release_fullgc_alot_dummy()) {
duke@435 102 warning("FullGCALot: Unable to release more dummies at bottom of heap");
duke@435 103 }
duke@435 104 HandleMark hm(thread);
duke@435 105 Universe::heap()->collect(GCCause::_full_gc_alot);
duke@435 106 unsigned int invocations = Universe::heap()->total_full_collections();
duke@435 107 // Compute new interval
duke@435 108 if (FullGCALotInterval > 1) {
duke@435 109 _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
duke@435 110 if (PrintGCDetails && Verbose) {
duke@435 111 tty->print_cr("Full gc no: %u\tInterval: %d", invocations,
duke@435 112 _fullgc_alot_counter);
duke@435 113 }
duke@435 114 } else {
duke@435 115 _fullgc_alot_counter = 1;
duke@435 116 }
duke@435 117 // Print progress message
duke@435 118 if (invocations % 100 == 0) {
duke@435 119 if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);
duke@435 120 }
duke@435 121 } else {
duke@435 122 if (ScavengeALot) _scavenge_alot_counter--;
duke@435 123 // Check if we should force a scavenge
duke@435 124 if (_scavenge_alot_counter == 0) {
duke@435 125 HandleMark hm(thread);
duke@435 126 Universe::heap()->collect(GCCause::_scavenge_alot);
duke@435 127 unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
duke@435 128 // Compute new interval
duke@435 129 if (ScavengeALotInterval > 1) {
duke@435 130 _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
duke@435 131 if (PrintGCDetails && Verbose) {
duke@435 132 tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,
duke@435 133 _scavenge_alot_counter);
duke@435 134 }
duke@435 135 } else {
duke@435 136 _scavenge_alot_counter = 1;
duke@435 137 }
duke@435 138 // Print progress message
duke@435 139 if (invocations % 1000 == 0) {
duke@435 140 if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);
duke@435 141 }
duke@435 142 }
duke@435 143 }
duke@435 144 }
duke@435 145 }
duke@435 146
duke@435 147
duke@435 148 vframe* vframe_array[50];
duke@435 149 int walk_stack_counter = 0;
duke@435 150
duke@435 151 void InterfaceSupport::walk_stack_from(vframe* start_vf) {
duke@435 152 // walk
duke@435 153 int i = 0;
duke@435 154 for (vframe* f = start_vf; f; f = f->sender() ) {
duke@435 155 if (i < 50) vframe_array[i++] = f;
duke@435 156 }
duke@435 157 }
duke@435 158
duke@435 159
duke@435 160 void InterfaceSupport::walk_stack() {
duke@435 161 JavaThread* thread = JavaThread::current();
duke@435 162 walk_stack_counter++;
duke@435 163 if (!thread->has_last_Java_frame()) return;
duke@435 164 ResourceMark rm(thread);
duke@435 165 RegisterMap reg_map(thread);
duke@435 166 walk_stack_from(thread->last_java_vframe(&reg_map));
duke@435 167 }
duke@435 168
duke@435 169
duke@435 170 # ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 171
duke@435 172 static int zap_traversals = 0;
duke@435 173
duke@435 174 void InterfaceSupport::zap_dead_locals_old() {
duke@435 175 JavaThread* thread = JavaThread::current();
duke@435 176 if (zap_traversals == -1) // edit constant for debugging
duke@435 177 warning("I am here");
duke@435 178 int zap_frame_count = 0; // count frames to help debugging
duke@435 179 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
duke@435 180 sfs.current()->zap_dead_locals(thread, sfs.register_map());
duke@435 181 ++zap_frame_count;
duke@435 182 }
duke@435 183 ++zap_traversals;
duke@435 184 }
duke@435 185
duke@435 186 # endif
duke@435 187
duke@435 188
duke@435 189 int deoptimizeAllCounter = 0;
duke@435 190 int zombieAllCounter = 0;
duke@435 191
duke@435 192
duke@435 193 void InterfaceSupport::zombieAll() {
duke@435 194 if (is_init_completed() && zombieAllCounter > ZombieALotInterval) {
duke@435 195 zombieAllCounter = 0;
duke@435 196 VM_ZombieAll op;
duke@435 197 VMThread::execute(&op);
duke@435 198 } else {
duke@435 199 zombieAllCounter++;
duke@435 200 }
duke@435 201 }
duke@435 202
coleenp@2497 203 void InterfaceSupport::unlinkSymbols() {
coleenp@2497 204 VM_UnlinkSymbols op;
coleenp@2497 205 VMThread::execute(&op);
coleenp@2497 206 }
coleenp@2497 207
duke@435 208 void InterfaceSupport::deoptimizeAll() {
duke@435 209 if (is_init_completed() ) {
duke@435 210 if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) {
duke@435 211 deoptimizeAllCounter = 0;
duke@435 212 VM_DeoptimizeAll op;
duke@435 213 VMThread::execute(&op);
duke@435 214 } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) {
duke@435 215 VM_DeoptimizeAll op;
duke@435 216 VMThread::execute(&op);
duke@435 217 }
duke@435 218 }
duke@435 219 deoptimizeAllCounter++;
duke@435 220 }
duke@435 221
duke@435 222
duke@435 223 void InterfaceSupport::stress_derived_pointers() {
duke@435 224 #ifdef COMPILER2
duke@435 225 JavaThread *thread = JavaThread::current();
duke@435 226 if (!is_init_completed()) return;
duke@435 227 ResourceMark rm(thread);
duke@435 228 bool found = false;
duke@435 229 for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
duke@435 230 CodeBlob* cb = sfs.current()->cb();
duke@435 231 if (cb != NULL && cb->oop_maps() ) {
duke@435 232 // Find oopmap for current method
duke@435 233 OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
duke@435 234 assert(map != NULL, "no oopmap found for pc");
duke@435 235 found = map->has_derived_pointer();
duke@435 236 }
duke@435 237 }
duke@435 238 if (found) {
duke@435 239 // $$$ Not sure what to do here.
duke@435 240 /*
duke@435 241 Scavenge::invoke(0);
duke@435 242 */
duke@435 243 }
duke@435 244 #endif
duke@435 245 }
duke@435 246
duke@435 247
duke@435 248 void InterfaceSupport::verify_stack() {
duke@435 249 JavaThread* thread = JavaThread::current();
duke@435 250 ResourceMark rm(thread);
duke@435 251 // disabled because it throws warnings that oop maps should only be accessed
duke@435 252 // in VM thread or during debugging
duke@435 253
duke@435 254 if (!thread->has_pending_exception()) {
duke@435 255 // verification does not work if there are pending exceptions
duke@435 256 StackFrameStream sfs(thread);
duke@435 257 CodeBlob* cb = sfs.current()->cb();
duke@435 258 // In case of exceptions we might not have a runtime_stub on
duke@435 259 // top of stack, hence, all callee-saved registers are not going
duke@435 260 // to be setup correctly, hence, we cannot do stack verify
duke@435 261 if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
duke@435 262
duke@435 263 for (; !sfs.is_done(); sfs.next()) {
duke@435 264 sfs.current()->verify(sfs.register_map());
duke@435 265 }
duke@435 266 }
duke@435 267 }
duke@435 268
duke@435 269
duke@435 270 void InterfaceSupport::verify_last_frame() {
duke@435 271 JavaThread* thread = JavaThread::current();
duke@435 272 ResourceMark rm(thread);
duke@435 273 RegisterMap reg_map(thread);
duke@435 274 frame fr = thread->last_frame();
duke@435 275 fr.verify(&reg_map);
duke@435 276 }
duke@435 277
duke@435 278
duke@435 279 #endif // ASSERT
duke@435 280
duke@435 281
duke@435 282 void InterfaceSupport_init() {
duke@435 283 #ifdef ASSERT
duke@435 284 if (ScavengeALot || FullGCALot) {
duke@435 285 srand(ScavengeALotInterval * FullGCALotInterval);
duke@435 286 }
duke@435 287 #endif
duke@435 288 }

mercurial