< prev index next >

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/StackTrace.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.tools;
  26 
  27 import sun.jvm.hotspot.debugger.*;
  28 import sun.jvm.hotspot.runtime.*;
  29 import sun.jvm.hotspot.oops.*;
  30 
  31 /** Traverses and prints the stack traces for all Java threads in the
  32  * remote VM */
  33 public class StackTrace extends Tool {





  34     // in non-verbose mode pc, sp and Method* are not printed
  35     public StackTrace(boolean v, boolean concurrentLocks) {
  36         this.verbose = v;
  37         this.concurrentLocks = concurrentLocks;
  38     }
  39 
  40     public StackTrace() {
  41         this(true, true);
  42     }
  43 
  44     public void run() {
  45         run(System.out);
  46     }
  47 
  48     public StackTrace(JVMDebugger d) {
  49         super(d);
  50     }
  51 
  52     public StackTrace(JVMDebugger d, boolean v, boolean concurrentLocks) {
  53         super(d);


  92                                     tty.print(", pc=" + pc);
  93                                 }
  94 
  95                                 tty.print(", Method*=" + method.getAddress());
  96                             }
  97 
  98                             if (vf.isCompiledFrame()) {
  99                                 tty.print(" (Compiled frame");
 100                                 if (vf.isDeoptimized()) {
 101                                   tty.print(" [deoptimized]");
 102                                 }
 103                             }
 104                             if (vf.isInterpretedFrame()) {
 105                                 tty.print(" (Interpreted frame");
 106                             }
 107                             if (vf.mayBeImpreciseDbg()) {
 108                                 tty.print("; information may be imprecise");
 109                             }
 110 
 111                             tty.println(")");






 112                         }
 113                     } catch (Exception e) {
 114                         tty.println("Error occurred during stack walking:");
 115                         e.printStackTrace();
 116                     }
 117                     tty.println();
 118                     if (concurrentLocks) {
 119                         concLocksPrinter.print(cur, tty);
 120                     }
 121                     tty.println();
 122               }
 123           }
 124       }
 125       catch (AddressException e) {
 126         System.err.println("Error accessing address 0x" + Long.toHexString(e.getAddress()));
 127         e.printStackTrace();
 128       }
 129    }
 130 
 131    public static void main(String[] args) {


  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.tools;
  26 
  27 import sun.jvm.hotspot.debugger.*;
  28 import sun.jvm.hotspot.runtime.*;
  29 import sun.jvm.hotspot.oops.*;
  30 
  31 /** Traverses and prints the stack traces for all Java threads in the
  32  * remote VM */
  33 public class StackTrace extends Tool {
  34 
  35     private static final String ADDRESS_FORMAT = VM.getVM().isLP64() ? "0x%016x" : "0x%08x";
  36 
  37     private static final String LOCK_OUTPUT = "    - locked <" + ADDRESS_FORMAT + "> (a %s)";
  38 
  39     // in non-verbose mode pc, sp and Method* are not printed
  40     public StackTrace(boolean v, boolean concurrentLocks) {
  41         this.verbose = v;
  42         this.concurrentLocks = concurrentLocks;
  43     }
  44 
  45     public StackTrace() {
  46         this(true, true);
  47     }
  48 
  49     public void run() {
  50         run(System.out);
  51     }
  52 
  53     public StackTrace(JVMDebugger d) {
  54         super(d);
  55     }
  56 
  57     public StackTrace(JVMDebugger d, boolean v, boolean concurrentLocks) {
  58         super(d);


  97                                     tty.print(", pc=" + pc);
  98                                 }
  99 
 100                                 tty.print(", Method*=" + method.getAddress());
 101                             }
 102 
 103                             if (vf.isCompiledFrame()) {
 104                                 tty.print(" (Compiled frame");
 105                                 if (vf.isDeoptimized()) {
 106                                   tty.print(" [deoptimized]");
 107                                 }
 108                             }
 109                             if (vf.isInterpretedFrame()) {
 110                                 tty.print(" (Interpreted frame");
 111                             }
 112                             if (vf.mayBeImpreciseDbg()) {
 113                                 tty.print("; information may be imprecise");
 114                             }
 115 
 116                             tty.println(")");
 117 
 118                             vf.getMonitors()
 119                               .stream()
 120                               .map(m -> m.ownerIsScalarReplaced() ? m.ownerKlass() : m.owner())
 121                               .map(m -> String.format(LOCK_OUTPUT, m.asLongValue(), Oop.getKlassForOopHandle(m).getName().asString().replace('/', '.')))
 122                               .forEach(tty::println);
 123                         }
 124                     } catch (Exception e) {
 125                         tty.println("Error occurred during stack walking:");
 126                         e.printStackTrace();
 127                     }
 128                     tty.println();
 129                     if (concurrentLocks) {
 130                         concLocksPrinter.print(cur, tty);
 131                     }
 132                     tty.println();
 133               }
 134           }
 135       }
 136       catch (AddressException e) {
 137         System.err.println("Error accessing address 0x" + Long.toHexString(e.getAddress()));
 138         e.printStackTrace();
 139       }
 140    }
 141 
 142    public static void main(String[] args) {
< prev index next >