< prev index next >

src/hotspot/share/runtime/vm_operations.cpp

Print this page
rev 47674 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47676 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp
rev 47677 : eosterlund CR - need more inline fixes.
rev 47678 : eosterlund, stefank CR - more inline and style cleanups
rev 47679 : stefank, coleenp CR - refactor most JavaThreadIterator usage to use JavaThreadIteratorWithHandle.

*** 1,7 **** /* ! * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 36,45 **** --- 36,46 ---- #include "runtime/arguments.hpp" #include "runtime/deoptimization.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/sweeper.hpp" #include "runtime/thread.inline.hpp" + #include "runtime/threadSMR.inline.hpp" #include "runtime/vm_operations.hpp" #include "services/threadService.hpp" #include "trace/tracing.hpp" #define VM_OP_NAME_INITIALIZE(name) #name,
*** 94,108 **** } } void VM_ThreadStop::doit() { assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); JavaThread* target = java_lang_Thread::thread(target_thread()); // Note that this now allows multiple ThreadDeath exceptions to be // thrown at a thread. ! if (target != NULL) { ! // the thread has run and is not already in the process of exiting target->send_thread_stop(throwable()); } } void VM_ClearICs::doit() { --- 95,110 ---- } } void VM_ThreadStop::doit() { assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint"); + ThreadsListHandle tlh; JavaThread* target = java_lang_Thread::thread(target_thread()); // Note that this now allows multiple ThreadDeath exceptions to be // thrown at a thread. ! if (target != NULL && (!EnableThreadSMRExtraValidityChecks || tlh.includes(target))) { ! // The target thread has run and has not exited yet. target->send_thread_stop(throwable()); } } void VM_ClearICs::doit() {
*** 144,156 **** #ifndef PRODUCT void VM_DeoptimizeAll::doit() { DeoptimizationMarker dm; // deoptimize all java threads in the system if (DeoptimizeALot) { ! for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { if (thread->has_last_Java_frame()) { thread->deoptimize(); } } } else if (DeoptimizeRandom) { --- 146,159 ---- #ifndef PRODUCT void VM_DeoptimizeAll::doit() { DeoptimizationMarker dm; + JavaThreadIteratorWithHandle jtiwh; // deoptimize all java threads in the system if (DeoptimizeALot) { ! for (; JavaThread *thread = jtiwh.next(); ) { if (thread->has_last_Java_frame()) { thread->deoptimize(); } } } else if (DeoptimizeRandom) {
*** 157,167 **** // Deoptimize some selected threads and frames int tnum = os::random() & 0x3; int fnum = os::random() & 0x3; int tcount = 0; ! for (JavaThread* thread = Threads::first(); thread != NULL; thread = thread->next()) { if (thread->has_last_Java_frame()) { if (tcount++ == tnum) { tcount = 0; int fcount = 0; // Deoptimize some selected frames. --- 160,170 ---- // Deoptimize some selected threads and frames int tnum = os::random() & 0x3; int fnum = os::random() & 0x3; int tcount = 0; ! for (; JavaThread *thread = jtiwh.next(); ) { if (thread->has_last_Java_frame()) { if (tcount++ == tnum) { tcount = 0; int fcount = 0; // Deoptimize some selected frames.
*** 253,268 **** return true; } void VM_FindDeadlocks::doit() { ! _deadlocks = ThreadService::find_deadlocks_at_safepoint(_concurrent_locks); if (_out != NULL) { int num_deadlocks = 0; for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { num_deadlocks++; ! cycle->print_on(_out); } if (num_deadlocks == 1) { _out->print_cr("\nFound 1 deadlock.\n"); _out->flush(); --- 256,278 ---- return true; } void VM_FindDeadlocks::doit() { ! // Update the hazard ptr in the originating thread to the current ! // list of threads. This VM operation needs the current list of ! // threads for proper deadlock detection and those are the ! // JavaThreads we need to be protected when we return info to the ! // originating thread. ! _setter.set(); ! ! _deadlocks = ThreadService::find_deadlocks_at_safepoint(_setter.list(), _concurrent_locks); if (_out != NULL) { int num_deadlocks = 0; for (DeadlockCycle* cycle = _deadlocks; cycle != NULL; cycle = cycle->next()) { num_deadlocks++; ! cycle->print_on_with(_setter.list(), _out); } if (num_deadlocks == 1) { _out->print_cr("\nFound 1 deadlock.\n"); _out->flush();
*** 325,342 **** } void VM_ThreadDump::doit() { ResourceMark rm; ConcurrentLocksDump concurrent_locks(true); if (_with_locked_synchronizers) { concurrent_locks.dump_at_safepoint(); } if (_num_threads == 0) { // Snapshot all live threads ! for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) { if (jt->is_exiting() || jt->is_hidden_from_external_view()) { // skip terminating threads and hidden threads continue; } --- 335,360 ---- } void VM_ThreadDump::doit() { ResourceMark rm; + // Set the hazard ptr in the originating thread to protect the + // current list of threads. This VM operation needs the current list + // of threads for a proper dump and those are the JavaThreads we need + // to be protected when we return info to the originating thread. + _result->set_t_list(); + ConcurrentLocksDump concurrent_locks(true); if (_with_locked_synchronizers) { concurrent_locks.dump_at_safepoint(); } if (_num_threads == 0) { // Snapshot all live threads ! ! for (uint i = 0; i < _result->t_list()->length(); i++) { ! JavaThread* jt = _result->t_list()->thread_at(i); if (jt->is_exiting() || jt->is_hidden_from_external_view()) { // skip terminating threads and hidden threads continue; }
*** 348,357 **** --- 366,376 ---- _result->add_thread_snapshot(ts); } } else { // Snapshot threads in the given _threads array // A dummy snapshot is created if a thread doesn't exist + for (int i = 0; i < _num_threads; i++) { instanceHandle th = _threads->at(i); if (th() == NULL) { // skip if the thread doesn't exist // Add a dummy snapshot
*** 360,369 **** --- 379,394 ---- } // Dump thread stack only if the thread is alive and not exiting // and not VM internal thread. JavaThread* jt = java_lang_Thread::thread(th()); + if (jt != NULL && !_result->t_list()->includes(jt)) { + // _threads[i] doesn't refer to a valid JavaThread; this check + // is primarily for JVM_DumpThreads() which doesn't have a good + // way to validate the _threads array. + jt = NULL; + } if (jt == NULL || /* thread not alive */ jt->is_exiting() || jt->is_hidden_from_external_view()) { // add a NULL snapshot if skipped _result->add_thread_snapshot(new ThreadSnapshot());
*** 378,388 **** } } } ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { ! ThreadSnapshot* snapshot = new ThreadSnapshot(java_thread); snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); snapshot->set_concurrent_locks(tcl); return snapshot; } --- 403,413 ---- } } } ThreadSnapshot* VM_ThreadDump::snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl) { ! ThreadSnapshot* snapshot = new ThreadSnapshot(_result->t_list(), java_thread); snapshot->dump_stack_at_safepoint(_max_depth, _with_locked_monitors); snapshot->set_concurrent_locks(tcl); return snapshot; }
*** 397,411 **** int num_active = 0; _shutdown_thread = thr_cur; _vm_exited = true; // global flag ! for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { ++num_active; thr->set_terminated(JavaThread::_vm_exited); // per-thread flag } return num_active; } int VM_Exit::wait_for_threads_in_native_to_block() { --- 422,437 ---- int num_active = 0; _shutdown_thread = thr_cur; _vm_exited = true; // global flag ! for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { ++num_active; thr->set_terminated(JavaThread::_vm_exited); // per-thread flag } + } return num_active; } int VM_Exit::wait_for_threads_in_native_to_block() {
*** 429,443 **** int max_wait_compiler_thread = 1000; // at least 10 seconds int max_wait = max_wait_compiler_thread; int attempts = 0; while (true) { int num_active = 0; int num_active_compiler_thread = 0; ! for(JavaThread *thr = Threads::first(); thr != NULL; thr = thr->next()) { if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { num_active++; if (thr->is_Compiler_thread()) { num_active_compiler_thread++; } --- 455,471 ---- int max_wait_compiler_thread = 1000; // at least 10 seconds int max_wait = max_wait_compiler_thread; int attempts = 0; + JavaThreadIteratorWithHandle jtiwh; while (true) { int num_active = 0; int num_active_compiler_thread = 0; ! jtiwh.rewind(); ! for (; JavaThread *thr = jtiwh.next(); ) { if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { num_active++; if (thr->is_Compiler_thread()) { num_active_compiler_thread++; }
< prev index next >