Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/JStack.java
41161 views
/*1* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.tools;2526import sun.jvm.hotspot.debugger.JVMDebugger;2728public class JStack extends Tool {29public JStack(boolean mixedMode, boolean concurrentLocks) {30this.mixedMode = mixedMode;31this.concurrentLocks = concurrentLocks;32}3334public JStack() {35this(true, true);36}3738public JStack(JVMDebugger d) {39super(d);40}4142protected boolean needsJavaPrefix() {43return false;44}4546@Override47public String getName() {48return "jstack";49}5051protected void printFlagsUsage() {52System.out.println(" -l\tto print java.util.concurrent locks");53System.out.println(" -m\tto print both java and native frames (mixed mode)");54super.printFlagsUsage();55}5657public void run() {58Tool tool = null;59if (mixedMode) {60tool = new PStack(false, concurrentLocks);61} else {62tool = new StackTrace(false, concurrentLocks);63}64tool.setAgent(getAgent());65tool.setDebugeeType(getDebugeeType());66tool.run();67}6869public void runWithArgs(String... args) {70int used = 0;71for (int i = 0; i < args.length; i++) {72if (args[i].equals("-m")) {73mixedMode = true;74used++;75} else if (args[i].equals("-l")) {76concurrentLocks = true;77used++;78}79}8081if (used != 0) {82String[] newArgs = new String[args.length - used];83for (int i = 0; i < newArgs.length; i++) {84newArgs[i] = args[i + used];85}86args = newArgs;87}8889execute(args);90}9192public static void main(String[] args) {93JStack jstack = new JStack();94jstack.runWithArgs(args);95}9697private boolean mixedMode;98private boolean concurrentLocks;99}100101102