Mercurial > hg > icedtea8-forest > hotspot
changeset 10829:8065f7b6bea3
8185003: JMX: Add a version of ThreadMXBean.dumpAllThreads with a maxDepth argument
Summary: Added two new API's to limit the stack trace depth
Reviewed-by: mchung, dfuchs, rriggs, egahlin
Contributed-by: ujwal.vangapally@oracle.com
author | uvangapally |
---|---|
date | Thu, 05 Oct 2017 01:31:53 -0700 |
parents | 2de695626bf5 |
children | a3ac2e49cb4f |
files | src/share/vm/services/jmm.h src/share/vm/services/management.cpp src/share/vm/services/threadService.cpp |
diffstat | 3 files changed, 37 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/services/jmm.h Fri Sep 18 06:43:43 2020 +0100 +++ b/src/share/vm/services/jmm.h Thu Oct 05 01:31:53 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -317,7 +317,11 @@ void (JNICALL *SetVMGlobal) (JNIEnv *env, jstring flag_name, jvalue new_value); - void* reserved6; + jobjectArray (JNICALL *DumpThreadsMaxDepth) (JNIEnv *env, + jlongArray ids, + jboolean lockedMonitors, + jboolean lockedSynchronizers, + jint maxDepth); jobjectArray (JNICALL *DumpThreads) (JNIEnv *env, jlongArray ids, jboolean lockedMonitors,
--- a/src/share/vm/services/management.cpp Fri Sep 18 06:43:43 2020 +0100 +++ b/src/share/vm/services/management.cpp Thu Oct 05 01:31:53 2017 -0700 @@ -1249,8 +1249,12 @@ // ids - array of thread IDs; NULL indicates all live threads // locked_monitors - if true, dump locked object monitors // locked_synchronizers - if true, dump locked JSR-166 synchronizers +// maxDepth - the maximum depth of stack traces to be dumped: +// maxDepth == -1 requests to dump entire stack trace. +// maxDepth == 0 requests no stack trace. // -JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, jboolean locked_synchronizers)) +JVM_ENTRY(jobjectArray, jmm_DumpThreadsMaxDepth(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, + jboolean locked_synchronizers, jint maxDepth)) ResourceMark rm(THREAD); if (JDK_Version::is_gte_jdk16x_version()) { @@ -1273,14 +1277,14 @@ do_thread_dump(&dump_result, ids_ah, num_threads, - -1, /* entire stack */ + maxDepth, /* stack depth */ (locked_monitors ? true : false), /* with locked monitors */ (locked_synchronizers ? true : false), /* with locked synchronizers */ CHECK_NULL); } else { // obtain thread dump of all threads VM_ThreadDump op(&dump_result, - -1, /* entire stack */ + maxDepth, /* stack depth */ (locked_monitors ? true : false), /* with locked monitors */ (locked_synchronizers ? true : false) /* with locked synchronizers */); VMThread::execute(&op); @@ -1386,6 +1390,25 @@ return (jobjectArray) JNIHandles::make_local(env, result_h()); JVM_END +// Dump thread info for the specified threads. +// It returns an array of ThreadInfo objects. Each element is the ThreadInfo +// for the thread ID specified in the corresponding entry in +// the given array of thread IDs; or NULL if the thread does not exist +// or has terminated. +// +// Input parameter: +// ids - array of thread IDs; NULL indicates all live threads +// locked_monitors - if true, dump locked object monitors +// locked_synchronizers - if true, dump locked JSR-166 synchronizers +// +// This method exists only for compatbility with compiled binaries that call it. +// The JDK library uses jmm_DumpThreadsMaxDepth. +// +JVM_ENTRY(jobjectArray, jmm_DumpThreads(JNIEnv *env, jlongArray thread_ids, jboolean locked_monitors, + jboolean locked_synchronizers)) + return jmm_DumpThreadsMaxDepth(env, thread_ids, locked_monitors, locked_synchronizers, INT_MAX); +JVM_END + // Returns an array of Class objects. JVM_ENTRY(jobjectArray, jmm_GetLoadedClasses(JNIEnv *env)) ResourceMark rm(THREAD); @@ -2357,7 +2380,7 @@ jmm_DumpHeap0, jmm_FindDeadlockedThreads, jmm_SetVMGlobal, - NULL, + jmm_DumpThreadsMaxDepth, jmm_DumpThreads, jmm_SetGCNotificationEnabled, jmm_GetDiagnosticCommands,
--- a/src/share/vm/services/threadService.cpp Fri Sep 18 06:43:43 2020 +0100 +++ b/src/share/vm/services/threadService.cpp Thu Oct 05 01:31:53 2017 -0700 @@ -562,6 +562,10 @@ vframe* start_vf = _thread->last_java_vframe(®_map); int count = 0; for (vframe* f = start_vf; f; f = f->sender() ) { + if (maxDepth >= 0 && count == maxDepth) { + // Skip frames if more than maxDepth + break; + } if (f->is_java_frame()) { javaVFrame* jvf = javaVFrame::cast(f); add_stack_frame(jvf); @@ -569,10 +573,6 @@ } else { // Ignore non-Java frames } - if (maxDepth > 0 && count == maxDepth) { - // Skip frames if more than maxDepth - break; - } } }