src/share/vm/services/threadService.cpp

Mon, 31 Mar 2014 13:09:35 -0700

author
minqi
date
Mon, 31 Mar 2014 13:09:35 -0700
changeset 6535
f42c10a3d4b1
parent 6122
0b9ea9a72436
child 6680
78bbf4d43a14
permissions
-rw-r--r--

7090324: gclog rotation via external tool
Summary: GC log rotation can be set via java command line, but customer sometime need to sync with OS level rotation setting.
Reviewed-by: sla, minqi, ehelin
Contributed-by: suenaga.yasumasa@lab.ntt.co.jp

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

mercurial