src/share/vm/services/threadService.cpp

Thu, 14 Jun 2018 09:15:08 -0700

author
kevinw
date
Thu, 14 Jun 2018 09:15:08 -0700
changeset 9327
f96fcd9e1e1b
parent 6911
ce8f6bb717c9
child 9448
73d689add964
permissions
-rw-r--r--

8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
Summary: Need to add a space between macro identifier and string literal
Reviewed-by: bpittore, stefank, dholmes, kbarrett

duke@435 1 /*
drchase@6680 2 * Copyright (c) 2003, 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 "classfile/systemDictionary.hpp"
stefank@2314 27 #include "memory/allocation.hpp"
stefank@2314 28 #include "memory/heapInspection.hpp"
stefank@2314 29 #include "memory/oopFactory.hpp"
stefank@2314 30 #include "oops/instanceKlass.hpp"
stefank@2314 31 #include "oops/oop.inline.hpp"
stefank@2314 32 #include "runtime/handles.inline.hpp"
stefank@2314 33 #include "runtime/init.hpp"
stefank@2314 34 #include "runtime/thread.hpp"
stefank@2314 35 #include "runtime/vframe.hpp"
goetz@6911 36 #include "runtime/thread.inline.hpp"
stefank@2314 37 #include "runtime/vmThread.hpp"
stefank@2314 38 #include "runtime/vm_operations.hpp"
stefank@2314 39 #include "services/threadService.hpp"
duke@435 40
drchase@6680 41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
drchase@6680 42
duke@435 43 // TODO: we need to define a naming convention for perf counters
duke@435 44 // to distinguish counters for:
duke@435 45 // - standard JSR174 use
duke@435 46 // - Hotspot extension (public and committed)
duke@435 47 // - Hotspot extension (private/internal and uncommitted)
duke@435 48
duke@435 49 // Default is disabled.
duke@435 50 bool ThreadService::_thread_monitoring_contention_enabled = false;
duke@435 51 bool ThreadService::_thread_cpu_time_enabled = false;
phh@2423 52 bool ThreadService::_thread_allocated_memory_enabled = false;
duke@435 53
duke@435 54 PerfCounter* ThreadService::_total_threads_count = NULL;
duke@435 55 PerfVariable* ThreadService::_live_threads_count = NULL;
duke@435 56 PerfVariable* ThreadService::_peak_threads_count = NULL;
duke@435 57 PerfVariable* ThreadService::_daemon_threads_count = NULL;
duke@435 58 volatile int ThreadService::_exiting_threads_count = 0;
duke@435 59 volatile int ThreadService::_exiting_daemon_threads_count = 0;
duke@435 60
duke@435 61 ThreadDumpResult* ThreadService::_threaddump_list = NULL;
duke@435 62
duke@435 63 static const int INITIAL_ARRAY_SIZE = 10;
duke@435 64
duke@435 65 void ThreadService::init() {
duke@435 66 EXCEPTION_MARK;
duke@435 67
duke@435 68 // These counters are for java.lang.management API support.
duke@435 69 // They are created even if -XX:-UsePerfData is set and in
duke@435 70 // that case, they will be allocated on C heap.
duke@435 71
duke@435 72 _total_threads_count =
duke@435 73 PerfDataManager::create_counter(JAVA_THREADS, "started",
duke@435 74 PerfData::U_Events, CHECK);
duke@435 75
duke@435 76 _live_threads_count =
duke@435 77 PerfDataManager::create_variable(JAVA_THREADS, "live",
duke@435 78 PerfData::U_None, CHECK);
duke@435 79
duke@435 80 _peak_threads_count =
duke@435 81 PerfDataManager::create_variable(JAVA_THREADS, "livePeak",
duke@435 82 PerfData::U_None, CHECK);
duke@435 83
duke@435 84 _daemon_threads_count =
duke@435 85 PerfDataManager::create_variable(JAVA_THREADS, "daemon",
duke@435 86 PerfData::U_None, CHECK);
duke@435 87
duke@435 88 if (os::is_thread_cpu_time_supported()) {
duke@435 89 _thread_cpu_time_enabled = true;
duke@435 90 }
phh@2423 91
phh@2423 92 _thread_allocated_memory_enabled = true; // Always on, so enable it
duke@435 93 }
duke@435 94
duke@435 95 void ThreadService::reset_peak_thread_count() {
duke@435 96 // Acquire the lock to update the peak thread count
duke@435 97 // to synchronize with thread addition and removal.
duke@435 98 MutexLockerEx mu(Threads_lock);
duke@435 99 _peak_threads_count->set_value(get_live_thread_count());
duke@435 100 }
duke@435 101
duke@435 102 void ThreadService::add_thread(JavaThread* thread, bool daemon) {
duke@435 103 // Do not count VM internal or JVMTI agent threads
duke@435 104 if (thread->is_hidden_from_external_view() ||
duke@435 105 thread->is_jvmti_agent_thread()) {
duke@435 106 return;
duke@435 107 }
duke@435 108
duke@435 109 _total_threads_count->inc();
duke@435 110 _live_threads_count->inc();
duke@435 111
duke@435 112 if (_live_threads_count->get_value() > _peak_threads_count->get_value()) {
duke@435 113 _peak_threads_count->set_value(_live_threads_count->get_value());
duke@435 114 }
duke@435 115
duke@435 116 if (daemon) {
duke@435 117 _daemon_threads_count->inc();
duke@435 118 }
duke@435 119 }
duke@435 120
duke@435 121 void ThreadService::remove_thread(JavaThread* thread, bool daemon) {
duke@435 122 Atomic::dec((jint*) &_exiting_threads_count);
duke@435 123
duke@435 124 if (thread->is_hidden_from_external_view() ||
duke@435 125 thread->is_jvmti_agent_thread()) {
duke@435 126 return;
duke@435 127 }
duke@435 128
duke@435 129 _live_threads_count->set_value(_live_threads_count->get_value() - 1);
duke@435 130
duke@435 131 if (daemon) {
duke@435 132 _daemon_threads_count->set_value(_daemon_threads_count->get_value() - 1);
duke@435 133 Atomic::dec((jint*) &_exiting_daemon_threads_count);
duke@435 134 }
duke@435 135 }
duke@435 136
duke@435 137 void ThreadService::current_thread_exiting(JavaThread* jt) {
duke@435 138 assert(jt == JavaThread::current(), "Called by current thread");
duke@435 139 Atomic::inc((jint*) &_exiting_threads_count);
duke@435 140
duke@435 141 oop threadObj = jt->threadObj();
duke@435 142 if (threadObj != NULL && java_lang_Thread::is_daemon(threadObj)) {
duke@435 143 Atomic::inc((jint*) &_exiting_daemon_threads_count);
duke@435 144 }
duke@435 145 }
duke@435 146
duke@435 147 // FIXME: JVMTI should call this function
duke@435 148 Handle ThreadService::get_current_contended_monitor(JavaThread* thread) {
duke@435 149 assert(thread != NULL, "should be non-NULL");
duke@435 150 assert(Threads_lock->owned_by_self(), "must grab Threads_lock or be at safepoint");
duke@435 151
duke@435 152 ObjectMonitor *wait_obj = thread->current_waiting_monitor();
duke@435 153
duke@435 154 oop obj = NULL;
duke@435 155 if (wait_obj != NULL) {
duke@435 156 // thread is doing an Object.wait() call
duke@435 157 obj = (oop) wait_obj->object();
duke@435 158 assert(obj != NULL, "Object.wait() should have an object");
duke@435 159 } else {
duke@435 160 ObjectMonitor *enter_obj = thread->current_pending_monitor();
duke@435 161 if (enter_obj != NULL) {
duke@435 162 // thread is trying to enter() or raw_enter() an ObjectMonitor.
duke@435 163 obj = (oop) enter_obj->object();
duke@435 164 }
duke@435 165 // If obj == NULL, then ObjectMonitor is raw which doesn't count.
duke@435 166 }
duke@435 167
duke@435 168 Handle h(obj);
duke@435 169 return h;
duke@435 170 }
duke@435 171
duke@435 172 bool ThreadService::set_thread_monitoring_contention(bool flag) {
duke@435 173 MutexLocker m(Management_lock);
duke@435 174
duke@435 175 bool prev = _thread_monitoring_contention_enabled;
duke@435 176 _thread_monitoring_contention_enabled = flag;
duke@435 177
duke@435 178 return prev;
duke@435 179 }
duke@435 180
duke@435 181 bool ThreadService::set_thread_cpu_time_enabled(bool flag) {
duke@435 182 MutexLocker m(Management_lock);
duke@435 183
duke@435 184 bool prev = _thread_cpu_time_enabled;
duke@435 185 _thread_cpu_time_enabled = flag;
duke@435 186
duke@435 187 return prev;
duke@435 188 }
duke@435 189
phh@2423 190 bool ThreadService::set_thread_allocated_memory_enabled(bool flag) {
phh@2423 191 MutexLocker m(Management_lock);
phh@2423 192
phh@2423 193 bool prev = _thread_allocated_memory_enabled;
phh@2423 194 _thread_allocated_memory_enabled = flag;
phh@2423 195
phh@2423 196 return prev;
phh@2423 197 }
phh@2423 198
duke@435 199 // GC support
duke@435 200 void ThreadService::oops_do(OopClosure* f) {
duke@435 201 for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) {
duke@435 202 dump->oops_do(f);
duke@435 203 }
duke@435 204 }
duke@435 205
sla@6122 206 void ThreadService::metadata_do(void f(Metadata*)) {
sla@6122 207 for (ThreadDumpResult* dump = _threaddump_list; dump != NULL; dump = dump->next()) {
sla@6122 208 dump->metadata_do(f);
sla@6122 209 }
sla@6122 210 }
sla@6122 211
duke@435 212 void ThreadService::add_thread_dump(ThreadDumpResult* dump) {
duke@435 213 MutexLocker ml(Management_lock);
duke@435 214 if (_threaddump_list == NULL) {
duke@435 215 _threaddump_list = dump;
duke@435 216 } else {
duke@435 217 dump->set_next(_threaddump_list);
duke@435 218 _threaddump_list = dump;
duke@435 219 }
duke@435 220 }
duke@435 221
duke@435 222 void ThreadService::remove_thread_dump(ThreadDumpResult* dump) {
duke@435 223 MutexLocker ml(Management_lock);
duke@435 224
duke@435 225 ThreadDumpResult* prev = NULL;
duke@435 226 bool found = false;
duke@435 227 for (ThreadDumpResult* d = _threaddump_list; d != NULL; prev = d, d = d->next()) {
duke@435 228 if (d == dump) {
duke@435 229 if (prev == NULL) {
duke@435 230 _threaddump_list = dump->next();
duke@435 231 } else {
duke@435 232 prev->set_next(dump->next());
duke@435 233 }
duke@435 234 found = true;
duke@435 235 break;
duke@435 236 }
duke@435 237 }
duke@435 238 assert(found, "The threaddump result to be removed must exist.");
duke@435 239 }
duke@435 240
duke@435 241 // Dump stack trace of threads specified in the given threads array.
duke@435 242 // Returns StackTraceElement[][] each element is the stack trace of a thread in
duke@435 243 // the corresponding entry in the given threads array
duke@435 244 Handle ThreadService::dump_stack_traces(GrowableArray<instanceHandle>* threads,
duke@435 245 int num_threads,
duke@435 246 TRAPS) {
duke@435 247 assert(num_threads > 0, "just checking");
duke@435 248
duke@435 249 ThreadDumpResult dump_result;
duke@435 250 VM_ThreadDump op(&dump_result,
duke@435 251 threads,
duke@435 252 num_threads,
duke@435 253 -1, /* entire stack */
duke@435 254 false, /* with locked monitors */
duke@435 255 false /* with locked synchronizers */);
duke@435 256 VMThread::execute(&op);
duke@435 257
duke@435 258 // Allocate the resulting StackTraceElement[][] object
duke@435 259
duke@435 260 ResourceMark rm(THREAD);
coleenp@4037 261 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_StackTraceElement_array(), true, CHECK_NH);
coleenp@4142 262 ObjArrayKlass* ik = ObjArrayKlass::cast(k);
coleenp@4037 263 objArrayOop r = oopFactory::new_objArray(ik, num_threads, CHECK_NH);
duke@435 264 objArrayHandle result_obj(THREAD, r);
duke@435 265
duke@435 266 int num_snapshots = dump_result.num_snapshots();
duke@435 267 assert(num_snapshots == num_threads, "Must have num_threads thread snapshots");
duke@435 268 int i = 0;
duke@435 269 for (ThreadSnapshot* ts = dump_result.snapshots(); ts != NULL; i++, ts = ts->next()) {
duke@435 270 ThreadStackTrace* stacktrace = ts->get_stack_trace();
duke@435 271 if (stacktrace == NULL) {
duke@435 272 // No stack trace
duke@435 273 result_obj->obj_at_put(i, NULL);
duke@435 274 } else {
duke@435 275 // Construct an array of java/lang/StackTraceElement object
duke@435 276 Handle backtrace_h = stacktrace->allocate_fill_stack_trace_element_array(CHECK_NH);
duke@435 277 result_obj->obj_at_put(i, backtrace_h());
duke@435 278 }
duke@435 279 }
duke@435 280
duke@435 281 return result_obj;
duke@435 282 }
duke@435 283
duke@435 284 void ThreadService::reset_contention_count_stat(JavaThread* thread) {
duke@435 285 ThreadStatistics* stat = thread->get_thread_stat();
duke@435 286 if (stat != NULL) {
duke@435 287 stat->reset_count_stat();
duke@435 288 }
duke@435 289 }
duke@435 290
duke@435 291 void ThreadService::reset_contention_time_stat(JavaThread* thread) {
duke@435 292 ThreadStatistics* stat = thread->get_thread_stat();
duke@435 293 if (stat != NULL) {
duke@435 294 stat->reset_time_stat();
duke@435 295 }
duke@435 296 }
duke@435 297
duke@435 298 // Find deadlocks involving object monitors and concurrent locks if concurrent_locks is true
duke@435 299 DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(bool concurrent_locks) {
duke@435 300 // This code was modified from the original Threads::find_deadlocks code.
duke@435 301 int globalDfn = 0, thisDfn;
duke@435 302 ObjectMonitor* waitingToLockMonitor = NULL;
duke@435 303 oop waitingToLockBlocker = NULL;
duke@435 304 bool blocked_on_monitor = false;
duke@435 305 JavaThread *currentThread, *previousThread;
duke@435 306 int num_deadlocks = 0;
duke@435 307
duke@435 308 for (JavaThread* p = Threads::first(); p != NULL; p = p->next()) {
duke@435 309 // Initialize the depth-first-number
duke@435 310 p->set_depth_first_number(-1);
duke@435 311 }
duke@435 312
duke@435 313 DeadlockCycle* deadlocks = NULL;
duke@435 314 DeadlockCycle* last = NULL;
duke@435 315 DeadlockCycle* cycle = new DeadlockCycle();
duke@435 316 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) {
duke@435 317 if (jt->depth_first_number() >= 0) {
duke@435 318 // this thread was already visited
duke@435 319 continue;
duke@435 320 }
duke@435 321
duke@435 322 thisDfn = globalDfn;
duke@435 323 jt->set_depth_first_number(globalDfn++);
duke@435 324 previousThread = jt;
duke@435 325 currentThread = jt;
duke@435 326
duke@435 327 cycle->reset();
duke@435 328
duke@435 329 // When there is a deadlock, all the monitors involved in the dependency
duke@435 330 // cycle must be contended and heavyweight. So we only care about the
duke@435 331 // heavyweight monitor a thread is waiting to lock.
duke@435 332 waitingToLockMonitor = (ObjectMonitor*)jt->current_pending_monitor();
duke@435 333 if (concurrent_locks) {
duke@435 334 waitingToLockBlocker = jt->current_park_blocker();
duke@435 335 }
duke@435 336 while (waitingToLockMonitor != NULL || waitingToLockBlocker != NULL) {
duke@435 337 cycle->add_thread(currentThread);
duke@435 338 if (waitingToLockMonitor != NULL) {
sla@5271 339 address currentOwner = (address)waitingToLockMonitor->owner();
sla@5271 340 if (currentOwner != NULL) {
sla@5271 341 currentThread = Threads::owning_thread_from_monitor_owner(
sla@5271 342 currentOwner,
sla@5271 343 false /* no locking needed */);
sla@5271 344 if (currentThread == NULL) {
sla@5271 345 // This function is called at a safepoint so the JavaThread
sla@5271 346 // that owns waitingToLockMonitor should be findable, but
sla@5271 347 // if it is not findable, then the previous currentThread is
sla@5271 348 // blocked permanently. We record this as a deadlock.
sla@5271 349 num_deadlocks++;
dcubed@4673 350
sla@5271 351 cycle->set_deadlock(true);
dcubed@4673 352
sla@5271 353 // add this cycle to the deadlocks list
sla@5271 354 if (deadlocks == NULL) {
sla@5271 355 deadlocks = cycle;
sla@5271 356 } else {
sla@5271 357 last->set_next(cycle);
sla@5271 358 }
sla@5271 359 last = cycle;
sla@5271 360 cycle = new DeadlockCycle();
sla@5271 361 break;
dcubed@4673 362 }
dcubed@4673 363 }
duke@435 364 } else {
duke@435 365 if (concurrent_locks) {
duke@435 366 if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
duke@435 367 oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
duke@435 368 currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
duke@435 369 } else {
duke@435 370 currentThread = NULL;
duke@435 371 }
duke@435 372 }
duke@435 373 }
duke@435 374
duke@435 375 if (currentThread == NULL) {
duke@435 376 // No dependency on another thread
duke@435 377 break;
duke@435 378 }
duke@435 379 if (currentThread->depth_first_number() < 0) {
duke@435 380 // First visit to this thread
duke@435 381 currentThread->set_depth_first_number(globalDfn++);
duke@435 382 } else if (currentThread->depth_first_number() < thisDfn) {
duke@435 383 // Thread already visited, and not on a (new) cycle
duke@435 384 break;
duke@435 385 } else if (currentThread == previousThread) {
duke@435 386 // Self-loop, ignore
duke@435 387 break;
duke@435 388 } else {
duke@435 389 // We have a (new) cycle
duke@435 390 num_deadlocks++;
duke@435 391
duke@435 392 cycle->set_deadlock(true);
duke@435 393
duke@435 394 // add this cycle to the deadlocks list
duke@435 395 if (deadlocks == NULL) {
duke@435 396 deadlocks = cycle;
duke@435 397 } else {
duke@435 398 last->set_next(cycle);
duke@435 399 }
duke@435 400 last = cycle;
duke@435 401 cycle = new DeadlockCycle();
duke@435 402 break;
duke@435 403 }
duke@435 404 previousThread = currentThread;
duke@435 405 waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor();
duke@435 406 if (concurrent_locks) {
duke@435 407 waitingToLockBlocker = currentThread->current_park_blocker();
duke@435 408 }
duke@435 409 }
duke@435 410
duke@435 411 }
fparain@3381 412 delete cycle;
duke@435 413 return deadlocks;
duke@435 414 }
duke@435 415
duke@435 416 ThreadDumpResult::ThreadDumpResult() : _num_threads(0), _num_snapshots(0), _snapshots(NULL), _next(NULL), _last(NULL) {
duke@435 417
duke@435 418 // Create a new ThreadDumpResult object and append to the list.
coleenp@4037 419 // If GC happens before this function returns, Method*
duke@435 420 // in the stack trace will be visited.
duke@435 421 ThreadService::add_thread_dump(this);
duke@435 422 }
duke@435 423
duke@435 424 ThreadDumpResult::ThreadDumpResult(int num_threads) : _num_threads(num_threads), _num_snapshots(0), _snapshots(NULL), _next(NULL), _last(NULL) {
duke@435 425 // Create a new ThreadDumpResult object and append to the list.
duke@435 426 // If GC happens before this function returns, oops
duke@435 427 // will be visited.
duke@435 428 ThreadService::add_thread_dump(this);
duke@435 429 }
duke@435 430
duke@435 431 ThreadDumpResult::~ThreadDumpResult() {
duke@435 432 ThreadService::remove_thread_dump(this);
duke@435 433
duke@435 434 // free all the ThreadSnapshot objects created during
duke@435 435 // the VM_ThreadDump operation
duke@435 436 ThreadSnapshot* ts = _snapshots;
duke@435 437 while (ts != NULL) {
duke@435 438 ThreadSnapshot* p = ts;
duke@435 439 ts = ts->next();
duke@435 440 delete p;
duke@435 441 }
duke@435 442 }
duke@435 443
duke@435 444
duke@435 445 void ThreadDumpResult::add_thread_snapshot(ThreadSnapshot* ts) {
duke@435 446 assert(_num_threads == 0 || _num_snapshots < _num_threads,
duke@435 447 "_num_snapshots must be less than _num_threads");
duke@435 448 _num_snapshots++;
duke@435 449 if (_snapshots == NULL) {
duke@435 450 _snapshots = ts;
duke@435 451 } else {
duke@435 452 _last->set_next(ts);
duke@435 453 }
duke@435 454 _last = ts;
duke@435 455 }
duke@435 456
duke@435 457 void ThreadDumpResult::oops_do(OopClosure* f) {
duke@435 458 for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) {
duke@435 459 ts->oops_do(f);
duke@435 460 }
duke@435 461 }
duke@435 462
sla@6122 463 void ThreadDumpResult::metadata_do(void f(Metadata*)) {
sla@6122 464 for (ThreadSnapshot* ts = _snapshots; ts != NULL; ts = ts->next()) {
sla@6122 465 ts->metadata_do(f);
sla@6122 466 }
sla@6122 467 }
sla@6122 468
duke@435 469 StackFrameInfo::StackFrameInfo(javaVFrame* jvf, bool with_lock_info) {
duke@435 470 _method = jvf->method();
duke@435 471 _bci = jvf->bci();
sla@6122 472 _class_holder = _method->method_holder()->klass_holder();
duke@435 473 _locked_monitors = NULL;
duke@435 474 if (with_lock_info) {
duke@435 475 ResourceMark rm;
duke@435 476 GrowableArray<MonitorInfo*>* list = jvf->locked_monitors();
duke@435 477 int length = list->length();
duke@435 478 if (length > 0) {
zgu@3900 479 _locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(length, true);
duke@435 480 for (int i = 0; i < length; i++) {
duke@435 481 MonitorInfo* monitor = list->at(i);
duke@435 482 assert(monitor->owner(), "This monitor must have an owning object");
duke@435 483 _locked_monitors->append(monitor->owner());
duke@435 484 }
duke@435 485 }
duke@435 486 }
duke@435 487 }
duke@435 488
duke@435 489 void StackFrameInfo::oops_do(OopClosure* f) {
duke@435 490 if (_locked_monitors != NULL) {
duke@435 491 int length = _locked_monitors->length();
duke@435 492 for (int i = 0; i < length; i++) {
duke@435 493 f->do_oop((oop*) _locked_monitors->adr_at(i));
duke@435 494 }
duke@435 495 }
sla@6122 496 f->do_oop(&_class_holder);
sla@6122 497 }
sla@6122 498
sla@6122 499 void StackFrameInfo::metadata_do(void f(Metadata*)) {
sla@6122 500 f(_method);
duke@435 501 }
duke@435 502
duke@435 503 void StackFrameInfo::print_on(outputStream* st) const {
duke@435 504 ResourceMark rm;
duke@435 505 java_lang_Throwable::print_stack_element(st, method(), bci());
duke@435 506 int len = (_locked_monitors != NULL ? _locked_monitors->length() : 0);
duke@435 507 for (int i = 0; i < len; i++) {
duke@435 508 oop o = _locked_monitors->at(i);
coleenp@4037 509 InstanceKlass* ik = InstanceKlass::cast(o->klass());
duke@435 510 st->print_cr("\t- locked <" INTPTR_FORMAT "> (a %s)", (address)o, ik->external_name());
duke@435 511 }
duke@435 512
duke@435 513 }
duke@435 514
duke@435 515 // Iterate through monitor cache to find JNI locked monitors
duke@435 516 class InflatedMonitorsClosure: public MonitorClosure {
duke@435 517 private:
duke@435 518 ThreadStackTrace* _stack_trace;
duke@435 519 Thread* _thread;
duke@435 520 public:
duke@435 521 InflatedMonitorsClosure(Thread* t, ThreadStackTrace* st) {
duke@435 522 _thread = t;
duke@435 523 _stack_trace = st;
duke@435 524 }
duke@435 525 void do_monitor(ObjectMonitor* mid) {
duke@435 526 if (mid->owner() == _thread) {
duke@435 527 oop object = (oop) mid->object();
duke@435 528 if (!_stack_trace->is_owned_monitor_on_stack(object)) {
duke@435 529 _stack_trace->add_jni_locked_monitor(object);
duke@435 530 }
duke@435 531 }
duke@435 532 }
duke@435 533 };
duke@435 534
duke@435 535 ThreadStackTrace::ThreadStackTrace(JavaThread* t, bool with_locked_monitors) {
duke@435 536 _thread = t;
zgu@3900 537 _frames = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<StackFrameInfo*>(INITIAL_ARRAY_SIZE, true);
duke@435 538 _depth = 0;
duke@435 539 _with_locked_monitors = with_locked_monitors;
duke@435 540 if (_with_locked_monitors) {
zgu@3900 541 _jni_locked_monitors = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true);
duke@435 542 } else {
duke@435 543 _jni_locked_monitors = NULL;
duke@435 544 }
duke@435 545 }
duke@435 546
duke@435 547 ThreadStackTrace::~ThreadStackTrace() {
duke@435 548 for (int i = 0; i < _frames->length(); i++) {
duke@435 549 delete _frames->at(i);
duke@435 550 }
duke@435 551 delete _frames;
duke@435 552 if (_jni_locked_monitors != NULL) {
duke@435 553 delete _jni_locked_monitors;
duke@435 554 }
duke@435 555 }
duke@435 556
duke@435 557 void ThreadStackTrace::dump_stack_at_safepoint(int maxDepth) {
duke@435 558 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
duke@435 559
duke@435 560 if (_thread->has_last_Java_frame()) {
duke@435 561 RegisterMap reg_map(_thread);
duke@435 562 vframe* start_vf = _thread->last_java_vframe(&reg_map);
duke@435 563 int count = 0;
duke@435 564 for (vframe* f = start_vf; f; f = f->sender() ) {
duke@435 565 if (f->is_java_frame()) {
duke@435 566 javaVFrame* jvf = javaVFrame::cast(f);
duke@435 567 add_stack_frame(jvf);
duke@435 568 count++;
duke@435 569 } else {
duke@435 570 // Ignore non-Java frames
duke@435 571 }
duke@435 572 if (maxDepth > 0 && count == maxDepth) {
duke@435 573 // Skip frames if more than maxDepth
duke@435 574 break;
duke@435 575 }
duke@435 576 }
duke@435 577 }
duke@435 578
duke@435 579 if (_with_locked_monitors) {
duke@435 580 // Iterate inflated monitors and find monitors locked by this thread
duke@435 581 // not found in the stack
duke@435 582 InflatedMonitorsClosure imc(_thread, this);
duke@435 583 ObjectSynchronizer::monitors_iterate(&imc);
duke@435 584 }
duke@435 585 }
duke@435 586
duke@435 587
duke@435 588 bool ThreadStackTrace::is_owned_monitor_on_stack(oop object) {
duke@435 589 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
duke@435 590
duke@435 591 bool found = false;
duke@435 592 int num_frames = get_stack_depth();
duke@435 593 for (int depth = 0; depth < num_frames; depth++) {
duke@435 594 StackFrameInfo* frame = stack_frame_at(depth);
duke@435 595 int len = frame->num_locked_monitors();
duke@435 596 GrowableArray<oop>* locked_monitors = frame->locked_monitors();
duke@435 597 for (int j = 0; j < len; j++) {
duke@435 598 oop monitor = locked_monitors->at(j);
duke@435 599 assert(monitor != NULL && monitor->is_instance(), "must be a Java object");
duke@435 600 if (monitor == object) {
duke@435 601 found = true;
duke@435 602 break;
duke@435 603 }
duke@435 604 }
duke@435 605 }
duke@435 606 return found;
duke@435 607 }
duke@435 608
duke@435 609 Handle ThreadStackTrace::allocate_fill_stack_trace_element_array(TRAPS) {
coleenp@4037 610 Klass* k = SystemDictionary::StackTraceElement_klass();
jrose@567 611 assert(k != NULL, "must be loaded in 1.4+");
duke@435 612 instanceKlassHandle ik(THREAD, k);
duke@435 613
duke@435 614 // Allocate an array of java/lang/StackTraceElement object
duke@435 615 objArrayOop ste = oopFactory::new_objArray(ik(), _depth, CHECK_NH);
duke@435 616 objArrayHandle backtrace(THREAD, ste);
duke@435 617 for (int j = 0; j < _depth; j++) {
duke@435 618 StackFrameInfo* frame = _frames->at(j);
duke@435 619 methodHandle mh(THREAD, frame->method());
duke@435 620 oop element = java_lang_StackTraceElement::create(mh, frame->bci(), CHECK_NH);
duke@435 621 backtrace->obj_at_put(j, element);
duke@435 622 }
duke@435 623 return backtrace;
duke@435 624 }
duke@435 625
duke@435 626 void ThreadStackTrace::add_stack_frame(javaVFrame* jvf) {
duke@435 627 StackFrameInfo* frame = new StackFrameInfo(jvf, _with_locked_monitors);
duke@435 628 _frames->append(frame);
duke@435 629 _depth++;
duke@435 630 }
duke@435 631
duke@435 632 void ThreadStackTrace::oops_do(OopClosure* f) {
duke@435 633 int length = _frames->length();
duke@435 634 for (int i = 0; i < length; i++) {
duke@435 635 _frames->at(i)->oops_do(f);
duke@435 636 }
duke@435 637
duke@435 638 length = (_jni_locked_monitors != NULL ? _jni_locked_monitors->length() : 0);
duke@435 639 for (int j = 0; j < length; j++) {
duke@435 640 f->do_oop((oop*) _jni_locked_monitors->adr_at(j));
duke@435 641 }
duke@435 642 }
duke@435 643
sla@6122 644 void ThreadStackTrace::metadata_do(void f(Metadata*)) {
sla@6122 645 int length = _frames->length();
sla@6122 646 for (int i = 0; i < length; i++) {
sla@6122 647 _frames->at(i)->metadata_do(f);
sla@6122 648 }
sla@6122 649 }
sla@6122 650
sla@6122 651
duke@435 652 ConcurrentLocksDump::~ConcurrentLocksDump() {
duke@435 653 if (_retain_map_on_free) {
duke@435 654 return;
duke@435 655 }
duke@435 656
duke@435 657 for (ThreadConcurrentLocks* t = _map; t != NULL;) {
duke@435 658 ThreadConcurrentLocks* tcl = t;
duke@435 659 t = t->next();
duke@435 660 delete tcl;
duke@435 661 }
duke@435 662 }
duke@435 663
duke@435 664 void ConcurrentLocksDump::dump_at_safepoint() {
duke@435 665 // dump all locked concurrent locks
duke@435 666 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
duke@435 667
duke@435 668 if (JDK_Version::is_gte_jdk16x_version()) {
duke@435 669 ResourceMark rm;
duke@435 670
duke@435 671 GrowableArray<oop>* aos_objects = new GrowableArray<oop>(INITIAL_ARRAY_SIZE);
duke@435 672
duke@435 673 // Find all instances of AbstractOwnableSynchronizer
duke@435 674 HeapInspection::find_instances_at_safepoint(SystemDictionary::abstract_ownable_synchronizer_klass(),
duke@435 675 aos_objects);
duke@435 676 // Build a map of thread to its owned AQS locks
duke@435 677 build_map(aos_objects);
duke@435 678 }
duke@435 679 }
duke@435 680
duke@435 681
duke@435 682 // build a map of JavaThread to all its owned AbstractOwnableSynchronizer
duke@435 683 void ConcurrentLocksDump::build_map(GrowableArray<oop>* aos_objects) {
duke@435 684 int length = aos_objects->length();
duke@435 685 for (int i = 0; i < length; i++) {
duke@435 686 oop o = aos_objects->at(i);
duke@435 687 oop owner_thread_obj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(o);
duke@435 688 if (owner_thread_obj != NULL) {
duke@435 689 JavaThread* thread = java_lang_Thread::thread(owner_thread_obj);
duke@435 690 assert(o->is_instance(), "Must be an instanceOop");
duke@435 691 add_lock(thread, (instanceOop) o);
duke@435 692 }
duke@435 693 }
duke@435 694 }
duke@435 695
duke@435 696 void ConcurrentLocksDump::add_lock(JavaThread* thread, instanceOop o) {
duke@435 697 ThreadConcurrentLocks* tcl = thread_concurrent_locks(thread);
duke@435 698 if (tcl != NULL) {
duke@435 699 tcl->add_lock(o);
duke@435 700 return;
duke@435 701 }
duke@435 702
duke@435 703 // First owned lock found for this thread
duke@435 704 tcl = new ThreadConcurrentLocks(thread);
duke@435 705 tcl->add_lock(o);
duke@435 706 if (_map == NULL) {
duke@435 707 _map = tcl;
duke@435 708 } else {
duke@435 709 _last->set_next(tcl);
duke@435 710 }
duke@435 711 _last = tcl;
duke@435 712 }
duke@435 713
duke@435 714 ThreadConcurrentLocks* ConcurrentLocksDump::thread_concurrent_locks(JavaThread* thread) {
duke@435 715 for (ThreadConcurrentLocks* tcl = _map; tcl != NULL; tcl = tcl->next()) {
duke@435 716 if (tcl->java_thread() == thread) {
duke@435 717 return tcl;
duke@435 718 }
duke@435 719 }
duke@435 720 return NULL;
duke@435 721 }
duke@435 722
duke@435 723 void ConcurrentLocksDump::print_locks_on(JavaThread* t, outputStream* st) {
duke@435 724 st->print_cr(" Locked ownable synchronizers:");
duke@435 725 ThreadConcurrentLocks* tcl = thread_concurrent_locks(t);
duke@435 726 GrowableArray<instanceOop>* locks = (tcl != NULL ? tcl->owned_locks() : NULL);
duke@435 727 if (locks == NULL || locks->is_empty()) {
duke@435 728 st->print_cr("\t- None");
duke@435 729 st->cr();
duke@435 730 return;
duke@435 731 }
duke@435 732
duke@435 733 for (int i = 0; i < locks->length(); i++) {
duke@435 734 instanceOop obj = locks->at(i);
coleenp@4037 735 InstanceKlass* ik = InstanceKlass::cast(obj->klass());
duke@435 736 st->print_cr("\t- <" INTPTR_FORMAT "> (a %s)", (address)obj, ik->external_name());
duke@435 737 }
duke@435 738 st->cr();
duke@435 739 }
duke@435 740
duke@435 741 ThreadConcurrentLocks::ThreadConcurrentLocks(JavaThread* thread) {
duke@435 742 _thread = thread;
zgu@3900 743 _owned_locks = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<instanceOop>(INITIAL_ARRAY_SIZE, true);
duke@435 744 _next = NULL;
duke@435 745 }
duke@435 746
duke@435 747 ThreadConcurrentLocks::~ThreadConcurrentLocks() {
duke@435 748 delete _owned_locks;
duke@435 749 }
duke@435 750
duke@435 751 void ThreadConcurrentLocks::add_lock(instanceOop o) {
duke@435 752 _owned_locks->append(o);
duke@435 753 }
duke@435 754
duke@435 755 void ThreadConcurrentLocks::oops_do(OopClosure* f) {
duke@435 756 int length = _owned_locks->length();
duke@435 757 for (int i = 0; i < length; i++) {
duke@435 758 f->do_oop((oop*) _owned_locks->adr_at(i));
duke@435 759 }
duke@435 760 }
duke@435 761
duke@435 762 ThreadStatistics::ThreadStatistics() {
duke@435 763 _contended_enter_count = 0;
duke@435 764 _monitor_wait_count = 0;
duke@435 765 _sleep_count = 0;
duke@435 766 _count_pending_reset = false;
duke@435 767 _timer_pending_reset = false;
mchung@1310 768 memset((void*) _perf_recursion_counts, 0, sizeof(_perf_recursion_counts));
duke@435 769 }
duke@435 770
duke@435 771 ThreadSnapshot::ThreadSnapshot(JavaThread* thread) {
duke@435 772 _thread = thread;
duke@435 773 _threadObj = thread->threadObj();
duke@435 774 _stack_trace = NULL;
duke@435 775 _concurrent_locks = NULL;
duke@435 776 _next = NULL;
duke@435 777
duke@435 778 ThreadStatistics* stat = thread->get_thread_stat();
duke@435 779 _contended_enter_ticks = stat->contended_enter_ticks();
duke@435 780 _contended_enter_count = stat->contended_enter_count();
duke@435 781 _monitor_wait_ticks = stat->monitor_wait_ticks();
duke@435 782 _monitor_wait_count = stat->monitor_wait_count();
duke@435 783 _sleep_ticks = stat->sleep_ticks();
duke@435 784 _sleep_count = stat->sleep_count();
duke@435 785
duke@435 786 _blocker_object = NULL;
duke@435 787 _blocker_object_owner = NULL;
duke@435 788
duke@435 789 _thread_status = java_lang_Thread::get_thread_status(_threadObj);
duke@435 790 _is_ext_suspended = thread->is_being_ext_suspended();
duke@435 791 _is_in_native = (thread->thread_state() == _thread_in_native);
duke@435 792
duke@435 793 if (_thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER ||
duke@435 794 _thread_status == java_lang_Thread::IN_OBJECT_WAIT ||
duke@435 795 _thread_status == java_lang_Thread::IN_OBJECT_WAIT_TIMED) {
duke@435 796
duke@435 797 Handle obj = ThreadService::get_current_contended_monitor(thread);
duke@435 798 if (obj() == NULL) {
duke@435 799 // monitor no longer exists; thread is not blocked
duke@435 800 _thread_status = java_lang_Thread::RUNNABLE;
duke@435 801 } else {
duke@435 802 _blocker_object = obj();
duke@435 803 JavaThread* owner = ObjectSynchronizer::get_lock_owner(obj, false);
duke@435 804 if ((owner == NULL && _thread_status == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER)
dcubed@3202 805 || (owner != NULL && owner->is_attaching_via_jni())) {
duke@435 806 // ownership information of the monitor is not available
duke@435 807 // (may no longer be owned or releasing to some other thread)
duke@435 808 // make this thread in RUNNABLE state.
duke@435 809 // And when the owner thread is in attaching state, the java thread
duke@435 810 // is not completely initialized. For example thread name and id
duke@435 811 // and may not be set, so hide the attaching thread.
duke@435 812 _thread_status = java_lang_Thread::RUNNABLE;
duke@435 813 _blocker_object = NULL;
duke@435 814 } else if (owner != NULL) {
duke@435 815 _blocker_object_owner = owner->threadObj();
duke@435 816 }
duke@435 817 }
duke@435 818 }
duke@435 819
duke@435 820 // Support for JSR-166 locks
kamg@677 821 if (JDK_Version::current().supports_thread_park_blocker() &&
duke@435 822 (_thread_status == java_lang_Thread::PARKED ||
duke@435 823 _thread_status == java_lang_Thread::PARKED_TIMED)) {
duke@435 824
duke@435 825 _blocker_object = thread->current_park_blocker();
duke@435 826 if (_blocker_object != NULL && _blocker_object->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
duke@435 827 _blocker_object_owner = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(_blocker_object);
duke@435 828 }
duke@435 829 }
duke@435 830 }
duke@435 831
duke@435 832 ThreadSnapshot::~ThreadSnapshot() {
duke@435 833 delete _stack_trace;
duke@435 834 delete _concurrent_locks;
duke@435 835 }
duke@435 836
duke@435 837 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors) {
duke@435 838 _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors);
duke@435 839 _stack_trace->dump_stack_at_safepoint(max_depth);
duke@435 840 }
duke@435 841
duke@435 842
duke@435 843 void ThreadSnapshot::oops_do(OopClosure* f) {
duke@435 844 f->do_oop(&_threadObj);
duke@435 845 f->do_oop(&_blocker_object);
duke@435 846 f->do_oop(&_blocker_object_owner);
duke@435 847 if (_stack_trace != NULL) {
duke@435 848 _stack_trace->oops_do(f);
duke@435 849 }
duke@435 850 if (_concurrent_locks != NULL) {
duke@435 851 _concurrent_locks->oops_do(f);
duke@435 852 }
duke@435 853 }
duke@435 854
sla@6122 855 void ThreadSnapshot::metadata_do(void f(Metadata*)) {
sla@6122 856 if (_stack_trace != NULL) {
sla@6122 857 _stack_trace->metadata_do(f);
sla@6122 858 }
sla@6122 859 }
sla@6122 860
sla@6122 861
duke@435 862 DeadlockCycle::DeadlockCycle() {
duke@435 863 _is_deadlock = false;
zgu@3900 864 _threads = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, true);
duke@435 865 _next = NULL;
duke@435 866 }
duke@435 867
duke@435 868 DeadlockCycle::~DeadlockCycle() {
duke@435 869 delete _threads;
duke@435 870 }
duke@435 871
duke@435 872 void DeadlockCycle::print_on(outputStream* st) const {
duke@435 873 st->cr();
duke@435 874 st->print_cr("Found one Java-level deadlock:");
duke@435 875 st->print("=============================");
duke@435 876
duke@435 877 JavaThread* currentThread;
duke@435 878 ObjectMonitor* waitingToLockMonitor;
duke@435 879 oop waitingToLockBlocker;
duke@435 880 int len = _threads->length();
duke@435 881 for (int i = 0; i < len; i++) {
duke@435 882 currentThread = _threads->at(i);
duke@435 883 waitingToLockMonitor = (ObjectMonitor*)currentThread->current_pending_monitor();
duke@435 884 waitingToLockBlocker = currentThread->current_park_blocker();
duke@435 885 st->cr();
duke@435 886 st->print_cr("\"%s\":", currentThread->get_thread_name());
duke@435 887 const char* owner_desc = ",\n which is held by";
duke@435 888 if (waitingToLockMonitor != NULL) {
duke@435 889 st->print(" waiting to lock monitor " INTPTR_FORMAT, waitingToLockMonitor);
duke@435 890 oop obj = (oop)waitingToLockMonitor->object();
duke@435 891 if (obj != NULL) {
kevinw@9327 892 st->print(" (object " INTPTR_FORMAT ", a %s)", (address)obj,
coleenp@4037 893 (InstanceKlass::cast(obj->klass()))->external_name());
duke@435 894
duke@435 895 if (!currentThread->current_pending_monitor_is_from_java()) {
duke@435 896 owner_desc = "\n in JNI, which is held by";
duke@435 897 }
duke@435 898 } else {
duke@435 899 // No Java object associated - a JVMTI raw monitor
duke@435 900 owner_desc = " (JVMTI raw monitor),\n which is held by";
duke@435 901 }
duke@435 902 currentThread = Threads::owning_thread_from_monitor_owner(
dcubed@4673 903 (address)waitingToLockMonitor->owner(),
dcubed@4673 904 false /* no locking needed */);
dcubed@4673 905 if (currentThread == NULL) {
dcubed@4673 906 // The deadlock was detected at a safepoint so the JavaThread
dcubed@4673 907 // that owns waitingToLockMonitor should be findable, but
dcubed@4673 908 // if it is not findable, then the previous currentThread is
dcubed@4673 909 // blocked permanently.
dcubed@4673 910 st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc,
dcubed@4673 911 (address)waitingToLockMonitor->owner());
dcubed@4673 912 continue;
dcubed@4673 913 }
duke@435 914 } else {
duke@435 915 st->print(" waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)",
duke@435 916 (address)waitingToLockBlocker,
coleenp@4037 917 (InstanceKlass::cast(waitingToLockBlocker->klass()))->external_name());
duke@435 918 assert(waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass()),
duke@435 919 "Must be an AbstractOwnableSynchronizer");
duke@435 920 oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
duke@435 921 currentThread = java_lang_Thread::thread(ownerObj);
duke@435 922 }
duke@435 923 st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name());
duke@435 924 }
duke@435 925
duke@435 926 st->cr();
duke@435 927 st->cr();
duke@435 928
duke@435 929 // Print stack traces
duke@435 930 bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace;
duke@435 931 JavaMonitorsInStackTrace = true;
duke@435 932 st->print_cr("Java stack information for the threads listed above:");
duke@435 933 st->print_cr("===================================================");
duke@435 934 for (int j = 0; j < len; j++) {
duke@435 935 currentThread = _threads->at(j);
duke@435 936 st->print_cr("\"%s\":", currentThread->get_thread_name());
duke@435 937 currentThread->print_stack_on(st);
duke@435 938 }
duke@435 939 JavaMonitorsInStackTrace = oldJavaMonitorsInStackTrace;
duke@435 940 }
duke@435 941
duke@435 942 ThreadsListEnumerator::ThreadsListEnumerator(Thread* cur_thread,
duke@435 943 bool include_jvmti_agent_threads,
duke@435 944 bool include_jni_attaching_threads) {
duke@435 945 assert(cur_thread == Thread::current(), "Check current thread");
duke@435 946
duke@435 947 int init_size = ThreadService::get_live_thread_count();
duke@435 948 _threads_array = new GrowableArray<instanceHandle>(init_size);
duke@435 949
duke@435 950 MutexLockerEx ml(Threads_lock);
duke@435 951
duke@435 952 for (JavaThread* jt = Threads::first(); jt != NULL; jt = jt->next()) {
duke@435 953 // skips JavaThreads in the process of exiting
duke@435 954 // and also skips VM internal JavaThreads
duke@435 955 // Threads in _thread_new or _thread_new_trans state are included.
duke@435 956 // i.e. threads have been started but not yet running.
duke@435 957 if (jt->threadObj() == NULL ||
duke@435 958 jt->is_exiting() ||
duke@435 959 !java_lang_Thread::is_alive(jt->threadObj()) ||
duke@435 960 jt->is_hidden_from_external_view()) {
duke@435 961 continue;
duke@435 962 }
duke@435 963
duke@435 964 // skip agent threads
duke@435 965 if (!include_jvmti_agent_threads && jt->is_jvmti_agent_thread()) {
duke@435 966 continue;
duke@435 967 }
duke@435 968
duke@435 969 // skip jni threads in the process of attaching
dcubed@3202 970 if (!include_jni_attaching_threads && jt->is_attaching_via_jni()) {
duke@435 971 continue;
duke@435 972 }
duke@435 973
duke@435 974 instanceHandle h(cur_thread, (instanceOop) jt->threadObj());
duke@435 975 _threads_array->append(h);
duke@435 976 }
duke@435 977 }

mercurial