src/share/vm/runtime/vm_operations.cpp

Fri, 14 Jun 2013 08:02:32 +0200

author
brutisso
date
Fri, 14 Jun 2013 08:02:32 +0200
changeset 5276
0abfeed51c9e
parent 5237
f2110083203d
child 5792
510fbd28919c
permissions
-rw-r--r--

8012265: VM often crashes on solaris with a lot of memory
Summary: Increase HeapBaseMinAddress for G1 from 256m to 1g on Solaris x86
Reviewed-by: mgerdin, coleenp, kvn

duke@435 1 /*
sla@5237 2 * Copyright (c) 1997, 2013, 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"
coleenp@2497 26 #include "classfile/symbolTable.hpp"
stefank@2314 27 #include "classfile/vmSymbols.hpp"
stefank@2314 28 #include "compiler/compileBroker.hpp"
stefank@2314 29 #include "compiler/compilerOracle.hpp"
stefank@2314 30 #include "gc_implementation/shared/isGCActiveMark.hpp"
stefank@2314 31 #include "memory/resourceArea.hpp"
coleenp@2497 32 #include "oops/symbol.hpp"
stefank@2314 33 #include "runtime/arguments.hpp"
stefank@2314 34 #include "runtime/deoptimization.hpp"
stefank@2314 35 #include "runtime/interfaceSupport.hpp"
stefank@2314 36 #include "runtime/sweeper.hpp"
stefank@4299 37 #include "runtime/thread.inline.hpp"
stefank@2314 38 #include "runtime/vm_operations.hpp"
stefank@2314 39 #include "services/threadService.hpp"
sla@5237 40 #include "trace/tracing.hpp"
duke@435 41
duke@435 42 #define VM_OP_NAME_INITIALIZE(name) #name,
duke@435 43
duke@435 44 const char* VM_Operation::_names[VM_Operation::VMOp_Terminating] = \
duke@435 45 { VM_OPS_DO(VM_OP_NAME_INITIALIZE) };
duke@435 46
duke@435 47 void VM_Operation::set_calling_thread(Thread* thread, ThreadPriority priority) {
duke@435 48 _calling_thread = thread;
duke@435 49 assert(MinPriority <= priority && priority <= MaxPriority, "sanity check");
duke@435 50 _priority = priority;
duke@435 51 }
duke@435 52
duke@435 53
duke@435 54 void VM_Operation::evaluate() {
duke@435 55 ResourceMark rm;
duke@435 56 if (TraceVMOperation) {
duke@435 57 tty->print("[");
duke@435 58 NOT_PRODUCT(print();)
duke@435 59 }
duke@435 60 doit();
duke@435 61 if (TraceVMOperation) {
duke@435 62 tty->print_cr("]");
duke@435 63 }
duke@435 64 }
duke@435 65
sla@5237 66 const char* VM_Operation::mode_to_string(Mode mode) {
sla@5237 67 switch(mode) {
sla@5237 68 case _safepoint : return "safepoint";
sla@5237 69 case _no_safepoint : return "no safepoint";
sla@5237 70 case _concurrent : return "concurrent";
sla@5237 71 case _async_safepoint: return "async safepoint";
sla@5237 72 default : return "unknown";
sla@5237 73 }
sla@5237 74 }
duke@435 75 // Called by fatal error handler.
duke@435 76 void VM_Operation::print_on_error(outputStream* st) const {
duke@435 77 st->print("VM_Operation (" PTR_FORMAT "): ", this);
duke@435 78 st->print("%s", name());
duke@435 79
sla@5237 80 const char* mode = mode_to_string(evaluation_mode());
duke@435 81 st->print(", mode: %s", mode);
duke@435 82
duke@435 83 if (calling_thread()) {
duke@435 84 st->print(", requested by thread " PTR_FORMAT, calling_thread());
duke@435 85 }
duke@435 86 }
duke@435 87
duke@435 88 void VM_ThreadStop::doit() {
duke@435 89 assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
duke@435 90 JavaThread* target = java_lang_Thread::thread(target_thread());
duke@435 91 // Note that this now allows multiple ThreadDeath exceptions to be
duke@435 92 // thrown at a thread.
duke@435 93 if (target != NULL) {
duke@435 94 // the thread has run and is not already in the process of exiting
duke@435 95 target->send_thread_stop(throwable());
duke@435 96 }
duke@435 97 }
duke@435 98
duke@435 99 void VM_Deoptimize::doit() {
duke@435 100 // We do not want any GCs to happen while we are in the middle of this VM operation
duke@435 101 ResourceMark rm;
duke@435 102 DeoptimizationMarker dm;
duke@435 103
duke@435 104 // Deoptimize all activations depending on marked nmethods
duke@435 105 Deoptimization::deoptimize_dependents();
duke@435 106
duke@435 107 // Make the dependent methods zombies
duke@435 108 CodeCache::make_marked_nmethods_zombies();
duke@435 109 }
duke@435 110
duke@435 111
duke@435 112 VM_DeoptimizeFrame::VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id) {
duke@435 113 _thread = thread;
duke@435 114 _id = id;
duke@435 115 }
duke@435 116
duke@435 117
duke@435 118 void VM_DeoptimizeFrame::doit() {
never@2260 119 Deoptimization::deoptimize_frame_internal(_thread, _id);
duke@435 120 }
duke@435 121
duke@435 122
duke@435 123 #ifndef PRODUCT
duke@435 124
duke@435 125 void VM_DeoptimizeAll::doit() {
duke@435 126 DeoptimizationMarker dm;
duke@435 127 // deoptimize all java threads in the system
duke@435 128 if (DeoptimizeALot) {
duke@435 129 for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
duke@435 130 if (thread->has_last_Java_frame()) {
duke@435 131 thread->deoptimize();
duke@435 132 }
duke@435 133 }
duke@435 134 } else if (DeoptimizeRandom) {
duke@435 135
duke@435 136 // Deoptimize some selected threads and frames
duke@435 137 int tnum = os::random() & 0x3;
duke@435 138 int fnum = os::random() & 0x3;
duke@435 139 int tcount = 0;
duke@435 140 for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) {
duke@435 141 if (thread->has_last_Java_frame()) {
duke@435 142 if (tcount++ == tnum) {
duke@435 143 tcount = 0;
duke@435 144 int fcount = 0;
duke@435 145 // Deoptimize some selected frames.
duke@435 146 // Biased llocking wants a updated register map
duke@435 147 for(StackFrameStream fst(thread, UseBiasedLocking); !fst.is_done(); fst.next()) {
duke@435 148 if (fst.current()->can_be_deoptimized()) {
duke@435 149 if (fcount++ == fnum) {
duke@435 150 fcount = 0;
duke@435 151 Deoptimization::deoptimize(thread, *fst.current(), fst.register_map());
duke@435 152 }
duke@435 153 }
duke@435 154 }
duke@435 155 }
duke@435 156 }
duke@435 157 }
duke@435 158 }
duke@435 159 }
duke@435 160
duke@435 161
duke@435 162 void VM_ZombieAll::doit() {
duke@435 163 JavaThread *thread = (JavaThread *)calling_thread();
duke@435 164 assert(thread->is_Java_thread(), "must be a Java thread");
duke@435 165 thread->make_zombies();
duke@435 166 }
duke@435 167
duke@435 168 #endif // !PRODUCT
duke@435 169
coleenp@2497 170 void VM_UnlinkSymbols::doit() {
coleenp@2497 171 JavaThread *thread = (JavaThread *)calling_thread();
coleenp@2497 172 assert(thread->is_Java_thread(), "must be a Java thread");
coleenp@2497 173 SymbolTable::unlink();
coleenp@2497 174 }
coleenp@2497 175
kvn@1637 176 void VM_HandleFullCodeCache::doit() {
kvn@1637 177 NMethodSweeper::speculative_disconnect_nmethods(_is_full);
kvn@1637 178 }
kvn@1637 179
duke@435 180 void VM_Verify::doit() {
johnc@4899 181 Universe::heap()->prepare_for_verify();
johnc@4899 182 Universe::verify(_silent);
duke@435 183 }
duke@435 184
duke@435 185 bool VM_PrintThreads::doit_prologue() {
duke@435 186 assert(Thread::current()->is_Java_thread(), "just checking");
duke@435 187
duke@435 188 // Make sure AbstractOwnableSynchronizer is loaded
duke@435 189 if (JDK_Version::is_gte_jdk16x_version()) {
duke@435 190 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
duke@435 191 }
duke@435 192
duke@435 193 // Get Heap_lock if concurrent locks will be dumped
duke@435 194 if (_print_concurrent_locks) {
duke@435 195 Heap_lock->lock();
duke@435 196 }
duke@435 197 return true;
duke@435 198 }
duke@435 199
duke@435 200 void VM_PrintThreads::doit() {
duke@435 201 Threads::print_on(_out, true, false, _print_concurrent_locks);
duke@435 202 }
duke@435 203
duke@435 204 void VM_PrintThreads::doit_epilogue() {
duke@435 205 if (_print_concurrent_locks) {
duke@435 206 // Release Heap_lock
duke@435 207 Heap_lock->unlock();
duke@435 208 }
duke@435 209 }
duke@435 210
duke@435 211 void VM_PrintJNI::doit() {
duke@435 212 JNIHandles::print_on(_out);
duke@435 213 }
duke@435 214
duke@435 215 VM_FindDeadlocks::~VM_FindDeadlocks() {
duke@435 216 if (_deadlocks != NULL) {
duke@435 217 DeadlockCycle* cycle = _deadlocks;
duke@435 218 while (cycle != NULL) {
duke@435 219 DeadlockCycle* d = cycle;
duke@435 220 cycle = cycle->next();
duke@435 221 delete d;
duke@435 222 }
duke@435 223 }
duke@435 224 }
duke@435 225
duke@435 226 bool VM_FindDeadlocks::doit_prologue() {
duke@435 227 assert(Thread::current()->is_Java_thread(), "just checking");
duke@435 228
duke@435 229 // Load AbstractOwnableSynchronizer class
duke@435 230 if (_concurrent_locks && JDK_Version::is_gte_jdk16x_version()) {
duke@435 231 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
duke@435 232 }
duke@435 233
duke@435 234 return true;
duke@435 235 }
duke@435 236
duke@435 237 void VM_FindDeadlocks::doit() {
duke@435 238 _deadlocks = ThreadService::find_deadlocks_at_safepoint(_concurrent_locks);
duke@435 239 if (_out != NULL) {
duke@435 240 int num_deadlocks = 0;
duke@435 241 for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) {
duke@435 242 num_deadlocks++;
duke@435 243 cycle->print_on(_out);
duke@435 244 }
duke@435 245
duke@435 246 if (num_deadlocks == 1) {
duke@435 247 _out->print_cr("\nFound 1 deadlock.\n");
duke@435 248 _out->flush();
duke@435 249 } else if (num_deadlocks > 1) {
duke@435 250 _out->print_cr("\nFound %d deadlocks.\n", num_deadlocks);
duke@435 251 _out->flush();
duke@435 252 }
duke@435 253 }
duke@435 254 }
duke@435 255
duke@435 256 VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result,
duke@435 257 int max_depth,
duke@435 258 bool with_locked_monitors,
duke@435 259 bool with_locked_synchronizers) {
duke@435 260 _result = result;
duke@435 261 _num_threads = 0; // 0 indicates all threads
duke@435 262 _threads = NULL;
duke@435 263 _result = result;
duke@435 264 _max_depth = max_depth;
duke@435 265 _with_locked_monitors = with_locked_monitors;
duke@435 266 _with_locked_synchronizers = with_locked_synchronizers;
duke@435 267 }
duke@435 268
duke@435 269 VM_ThreadDump::VM_ThreadDump(ThreadDumpResult* result,
duke@435 270 GrowableArray<instanceHandle>* threads,
duke@435 271 int num_threads,
duke@435 272 int max_depth,
duke@435 273 bool with_locked_monitors,
duke@435 274 bool with_locked_synchronizers) {
duke@435 275 _result = result;
duke@435 276 _num_threads = num_threads;
duke@435 277 _threads = threads;
duke@435 278 _result = result;
duke@435 279 _max_depth = max_depth;
duke@435 280 _with_locked_monitors = with_locked_monitors;
duke@435 281 _with_locked_synchronizers = with_locked_synchronizers;
duke@435 282 }
duke@435 283
duke@435 284 bool VM_ThreadDump::doit_prologue() {
duke@435 285 assert(Thread::current()->is_Java_thread(), "just checking");
duke@435 286
duke@435 287 // Load AbstractOwnableSynchronizer class before taking thread snapshots
duke@435 288 if (JDK_Version::is_gte_jdk16x_version()) {
duke@435 289 java_util_concurrent_locks_AbstractOwnableSynchronizer::initialize(JavaThread::current());
duke@435 290 }
duke@435 291
duke@435 292 if (_with_locked_synchronizers) {
duke@435 293 // Acquire Heap_lock to dump concurrent locks
duke@435 294 Heap_lock->lock();
duke@435 295 }
duke@435 296
duke@435 297 return true;
duke@435 298 }
duke@435 299
duke@435 300 void VM_ThreadDump::doit_epilogue() {
duke@435 301 if (_with_locked_synchronizers) {
duke@435 302 // Release Heap_lock
duke@435 303 Heap_lock->unlock();
duke@435 304 }
duke@435 305 }
duke@435 306
duke@435 307 void VM_ThreadDump::doit() {
duke@435 308 ResourceMark rm;
duke@435 309
duke@435 310 ConcurrentLocksDump concurrent_locks(true);
duke@435 311 if (_with_locked_synchronizers) {
duke@435 312 concurrent_locks.dump_at_safepoint();
duke@435 313 }
duke@435 314
duke@435 315 if (_num_threads == 0) {
duke@435 316 // Snapshot all live threads
duke@435 317 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) {
duke@435 318 if (jt->is_exiting() ||
duke@435 319 jt->is_hidden_from_external_view()) {
duke@435 320 // skip terminating threads and hidden threads
duke@435 321 continue;
duke@435 322 }
duke@435 323 ThreadConcurrentLocks* tcl = NULL;
duke@435 324 if (_with_locked_synchronizers) {
duke@435 325 tcl = concurrent_locks.thread_concurrent_locks(jt);
duke@435 326 }
duke@435 327 ThreadSnapshot* ts = snapshot_thread(jt, tcl);
duke@435 328 _result->add_thread_snapshot(ts);
duke@435 329 }
duke@435 330 } else {
duke@435 331 // Snapshot threads in the given _threads array
duke@435 332 // A dummy snapshot is created if a thread doesn't exist
duke@435 333 for (int i = 0; i < _num_threads; i++) {
duke@435 334 instanceHandle th = _threads->at(i);
duke@435 335 if (th() == NULL) {
duke@435 336 // skip if the thread doesn't exist
duke@435 337 // Add a dummy snapshot
duke@435 338 _result->add_thread_snapshot(new ThreadSnapshot());
duke@435 339 continue;
duke@435 340 }
duke@435 341
duke@435 342 // Dump thread stack only if the thread is alive and not exiting
duke@435 343 // and not VM internal thread.
duke@435 344 JavaThread* jt = java_lang_Thread::thread(th());
duke@435 345 if (jt == NULL || /* thread not alive */
duke@435 346 jt->is_exiting() ||
duke@435 347 jt->is_hidden_from_external_view()) {
duke@435 348 // add a NULL snapshot if skipped
duke@435 349 _result->add_thread_snapshot(new ThreadSnapshot());
duke@435 350 continue;
duke@435 351 }
duke@435 352 ThreadConcurrentLocks* tcl = NULL;
duke@435 353 if (_with_locked_synchronizers) {
duke@435 354 tcl = concurrent_locks.thread_concurrent_locks(jt);
duke@435 355 }
duke@435 356 ThreadSnapshot* ts = snapshot_thread(jt, tcl);
duke@435 357 _result->add_thread_snapshot(ts);
duke@435 358 }
duke@435 359 }
duke@435 360 }
duke@435 361
duke@435 362 ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) {
duke@435 363 ThreadSnapshot* snapshot = new ThreadSnapshot(java_thread);
duke@435 364 snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors);
duke@435 365 snapshot->set_concurrent_locks(tcl);
duke@435 366 return snapshot;
duke@435 367 }
duke@435 368
duke@435 369 volatile bool VM_Exit::_vm_exited = false;
duke@435 370 Thread * VM_Exit::_shutdown_thread = NULL;
duke@435 371
duke@435 372 int VM_Exit::set_vm_exited() {
duke@435 373 Thread * thr_cur = ThreadLocalStorage::get_thread_slow();
duke@435 374
duke@435 375 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
duke@435 376
duke@435 377 int num_active = 0;
duke@435 378
duke@435 379 _shutdown_thread = thr_cur;
duke@435 380 _vm_exited = true; // global flag
duke@435 381 for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next())
duke@435 382 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
duke@435 383 ++num_active;
duke@435 384 thr->set_terminated(JavaThread::_vm_exited); // per-thread flag
duke@435 385 }
duke@435 386
duke@435 387 return num_active;
duke@435 388 }
duke@435 389
duke@435 390 int VM_Exit::wait_for_threads_in_native_to_block() {
duke@435 391 // VM exits at safepoint. This function must be called at the final safepoint
duke@435 392 // to wait for threads in _thread_in_native state to be quiescent.
duke@435 393 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already");
duke@435 394
duke@435 395 Thread * thr_cur = ThreadLocalStorage::get_thread_slow();
duke@435 396 Monitor timer(Mutex::leaf, "VM_Exit timer", true);
duke@435 397
duke@435 398 // Compiler threads need longer wait because they can access VM data directly
duke@435 399 // while in native. If they are active and some structures being used are
duke@435 400 // deleted by the shutdown sequence, they will crash. On the other hand, user
duke@435 401 // threads must go through native=>Java/VM transitions first to access VM
duke@435 402 // data, and they will be stopped during state transition. In theory, we
duke@435 403 // don't have to wait for user threads to be quiescent, but it's always
duke@435 404 // better to terminate VM when current thread is the only active thread, so
duke@435 405 // wait for user threads too. Numbers are in 10 milliseconds.
duke@435 406 int max_wait_user_thread = 30; // at least 300 milliseconds
duke@435 407 int max_wait_compiler_thread = 1000; // at least 10 seconds
duke@435 408
duke@435 409 int max_wait = max_wait_compiler_thread;
duke@435 410
duke@435 411 int attempts = 0;
duke@435 412 while (true) {
duke@435 413 int num_active = 0;
duke@435 414 int num_active_compiler_thread = 0;
duke@435 415
duke@435 416 for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) {
duke@435 417 if (thr!=thr_cur && thr->thread_state() == _thread_in_native) {
duke@435 418 num_active++;
duke@435 419 if (thr->is_Compiler_thread()) {
duke@435 420 num_active_compiler_thread++;
duke@435 421 }
duke@435 422 }
duke@435 423 }
duke@435 424
duke@435 425 if (num_active == 0) {
duke@435 426 return 0;
duke@435 427 } else if (attempts > max_wait) {
duke@435 428 return num_active;
duke@435 429 } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) {
duke@435 430 return num_active;
duke@435 431 }
duke@435 432
duke@435 433 attempts++;
duke@435 434
duke@435 435 MutexLockerEx ml(&timer, Mutex::_no_safepoint_check_flag);
duke@435 436 timer.wait(Mutex::_no_safepoint_check_flag, 10);
duke@435 437 }
duke@435 438 }
duke@435 439
duke@435 440 void VM_Exit::doit() {
duke@435 441 CompileBroker::set_should_block();
duke@435 442
duke@435 443 // Wait for a short period for threads in native to block. Any thread
duke@435 444 // still executing native code after the wait will be stopped at
duke@435 445 // native==>Java/VM barriers.
duke@435 446 // Among 16276 JCK tests, 94% of them come here without any threads still
duke@435 447 // running in native; the other 6% are quiescent within 250ms (Ultra 80).
duke@435 448 wait_for_threads_in_native_to_block();
duke@435 449
duke@435 450 set_vm_exited();
duke@435 451
duke@435 452 // cleanup globals resources before exiting. exit_globals() currently
duke@435 453 // cleans up outputStream resources and PerfMemory resources.
duke@435 454 exit_globals();
duke@435 455
duke@435 456 // Check for exit hook
duke@435 457 exit_hook_t exit_hook = Arguments::exit_hook();
duke@435 458 if (exit_hook != NULL) {
duke@435 459 // exit hook should exit.
duke@435 460 exit_hook(_exit_code);
duke@435 461 // ... but if it didn't, we must do it here
duke@435 462 vm_direct_exit(_exit_code);
duke@435 463 } else {
duke@435 464 vm_direct_exit(_exit_code);
duke@435 465 }
duke@435 466 }
duke@435 467
duke@435 468
duke@435 469 void VM_Exit::wait_if_vm_exited() {
duke@435 470 if (_vm_exited &&
duke@435 471 ThreadLocalStorage::get_thread_slow() != _shutdown_thread) {
duke@435 472 // _vm_exited is set at safepoint, and the Threads_lock is never released
duke@435 473 // we will block here until the process dies
duke@435 474 Threads_lock->lock_without_safepoint_check();
duke@435 475 ShouldNotReachHere();
duke@435 476 }
duke@435 477 }

mercurial