src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/PStack.java
author rehn
Tue, 21 May 2019 10:34:57 +0200
changeset 54955 46409371a691
parent 47216 71c04702a3d5
child 58743 083bbca50d2d
permissions -rw-r--r--
8223306: Remove threads linked list (use ThreadsList's array in SA) Reviewed-by: coleenp, dholmes, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 764
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 764
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 764
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.tools;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.cdbg.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.runtime.*;
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    35
import sun.jvm.hotspot.utilities.PlatformInfo;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
public class PStack extends Tool {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13088
diff changeset
    38
    // in non-verbose mode, Method*s are not printed in java frames
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
   public PStack(boolean v, boolean concurrentLocks) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      this.verbose = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
      this.concurrentLocks = concurrentLocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
   public PStack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      this(true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
18481
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16351
diff changeset
    48
   public PStack(JVMDebugger d) {
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16351
diff changeset
    49
      super(d);
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16351
diff changeset
    50
   }
fa7f6ad24216 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 16351
diff changeset
    51
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
   public void run() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      run(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
   public void run(PrintStream out) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      Debugger dbg = getAgent().getDebugger();
15798
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    58
      run(out, dbg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
   public void run(PrintStream out, Debugger dbg) {
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    62
      if (PlatformInfo.getOS().equals("darwin")) {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    63
        out.println("Not available on Darwin");
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    64
        return;
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    65
      }
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 15798
diff changeset
    66
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      CDebugger cdbg = dbg.getCDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      if (cdbg != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
         ConcurrentLocksPrinter concLocksPrinter = null;
15798
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    70
         // compute and cache java Vframes.
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    71
         initJFrameCache();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    72
         if (concurrentLocks) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    73
            concLocksPrinter = new ConcurrentLocksPrinter();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    74
         }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    75
         // print Java level deadlocks
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    76
         try {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    77
            DeadlockDetector.print(out);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    78
         } catch (Exception exp) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
    79
            out.println("can't print deadlock information: " + exp.getMessage());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
         List l = cdbg.getThreadList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
         final boolean cdbgCanDemangle = cdbg.canDemangle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
         for (Iterator itr = l.iterator() ; itr.hasNext();) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
            ThreadProxy th = (ThreadProxy) itr.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
               CFrame f = cdbg.topFrameForThread(th);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
               out.print("----------------- ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
               out.print(th);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
               out.println(" -----------------");
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    91
               JavaThread jthread = (JavaThread) proxyToThread.get(th);
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    92
               if (jthread != null) {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    93
                  jthread.printThreadInfoOn(out);
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 35217
diff changeset
    94
               }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
               while (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                  ClosestSymbol sym = f.closestSymbolToPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                  Address pc = f.pc();
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
    98
                  out.print(pc + "\t");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                  if (sym != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                     String name = sym.getName();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                     if (cdbgCanDemangle) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                        name = cdbg.demangle(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                     }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   104
                     out.print(name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                     long diff = sym.getOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                     if (diff != 0L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                        out.print(" + 0x" + Long.toHexString(diff));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                     out.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
                  } else {
15798
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   111
                      // look for one or more java frames
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   112
                      String[] names = null;
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   113
                      // check interpreter frame
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   114
                      Interpreter interp = VM.getVM().getInterpreter();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   115
                      if (interp.contains(pc)) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   116
                         names = getJavaNames(th, f.localVariableBase());
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   117
                         // print codelet name if we can't determine method
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   118
                         if (names == null || names.length == 0) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   119
                            out.print("<interpreter> ");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   120
                            InterpreterCodelet ic = interp.getCodeletContaining(pc);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   121
                            if (ic != null) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   122
                               String desc = ic.getDescription();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   123
                               if (desc != null) out.print(desc);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   124
                            }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   125
                            out.println();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   126
                         }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   127
                      } else {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   128
                         // look for known code blobs
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   129
                         CodeCache c = VM.getVM().getCodeCache();
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   130
                         if (c.contains(pc)) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   131
                            CodeBlob cb = c.findBlobUnsafe(pc);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   132
                            if (cb.isNMethod()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   133
                               names = getJavaNames(th, f.localVariableBase());
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   134
                               // just print compiled code, if can't determine method
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   135
                               if (names == null || names.length == 0) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   136
                                  out.println("<Unknown compiled code>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   137
                               }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   138
                            } else if (cb.isBufferBlob()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   139
                               out.println("<StubRoutines>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   140
                            } else if (cb.isRuntimeStub()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   141
                               out.println("<RuntimeStub>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   142
                            } else if (cb.isDeoptimizationStub()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   143
                               out.println("<DeoptimizationStub>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   144
                            } else if (cb.isUncommonTrapStub()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   145
                               out.println("<UncommonTrap>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   146
                            } else if (cb.isExceptionStub()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   147
                               out.println("<ExceptionStub>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   148
                            } else if (cb.isSafepointStub()) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   149
                               out.println("<SafepointStub>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   150
                            } else {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   151
                               out.println("<Unknown code blob>");
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   152
                            }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   153
                         } else {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   154
                            printUnknown(out);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   155
                         }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   156
                      }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   157
                      // print java frames, if any
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   158
                      if (names != null && names.length != 0) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   159
                         // print java frame(s)
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   160
                         for (int i = 0; i < names.length; i++) {
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   161
                             out.println(names[i]);
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   162
                         }
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   163
                      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                  }
13088
6d7b2029e597 6310967: SA: jstack -m produce failures in output
poonam
parents: 5547
diff changeset
   165
                  f = f.sender(th);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
            } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
               exp.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
               // continue, may be we can do a better job for other threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
            }
15798
cea39eefa98e 7165259: Remove BugSpot
sla
parents: 13728
diff changeset
   171
            if (concurrentLocks) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
               JavaThread jthread = (JavaThread) proxyToThread.get(th);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
               if (jthread != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
                   concLocksPrinter.print(jthread, out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
         } // for threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
          if (getDebugeeType() == DEBUGEE_REMOTE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
              out.println("remote configuration is not yet implemented");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
              out.println("not yet implemented (debugger does not support CDebugger)!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
   public static void main(String[] args) throws Exception {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      PStack t = new PStack();
21065
b8281f54308b 8025638: jmap returns 0 instead of 1 when it fails.
farvidsson
parents: 18481
diff changeset
   189
      t.execute(args);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
   // -- Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
   private Map jframeCache; // Map<ThreadProxy, JavaVFrame[]>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
   private Map proxyToThread; // Map<ThreadProxy, JavaThread>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
   private PrintStream out;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
   private boolean verbose;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
   private boolean concurrentLocks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
   private void initJFrameCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      // cache frames for subsequent reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      jframeCache = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      proxyToThread = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      Threads threads = VM.getVM().getThreads();
54955
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   204
      for (int i = 0; i < threads.getNumberOfThreads(); i++) {
46409371a691 8223306: Remove threads linked list (use ThreadsList's array in SA)
rehn
parents: 47216
diff changeset
   205
         JavaThread cur = threads.getJavaThreadAt(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
         List tmp = new ArrayList(10);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
         try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
            for (JavaVFrame vf = cur.getLastJavaVFrameDbg(); vf != null; vf = vf.javaSender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
               tmp.add(vf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
         } catch (Exception exp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
            // may be we may get frames for other threads, continue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
            // after printing stack trace.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            exp.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
         JavaVFrame[] jvframes = new JavaVFrame[tmp.size()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
         System.arraycopy(tmp.toArray(), 0, jvframes, 0, jvframes.length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
         jframeCache.put(cur.getThreadProxy(), jvframes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
         proxyToThread.put(cur.getThreadProxy(), cur);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   223
   private void printUnknown(PrintStream out) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   224
      out.println("\t????????");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
   private String[] getJavaNames(ThreadProxy th, Address fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      if (fp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
         return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      JavaVFrame[] jvframes = (JavaVFrame[]) jframeCache.get(th);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      if (jvframes == null) return null; // not a java thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      List names = new ArrayList(10);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      for (int fCount = 0; fCount < jvframes.length; fCount++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
         JavaVFrame vf = jvframes[fCount];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
         Frame f = vf.getFrame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
         if (fp.equals(f.getFP())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
            StringBuffer sb = new StringBuffer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
            Method method = vf.getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
            // a special char to identify java frames in output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
            sb.append("* ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
            sb.append(method.externalNameAndSignature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
            sb.append(" bci:" + vf.getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
            int lineNumber = method.getLineNumberFromBCI(vf.getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
            if (lineNumber != -1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
                sb.append(" line:" + lineNumber);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
            if (verbose) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13088
diff changeset
   250
               sb.append(" Method*:" + method.getAddress());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
            if (vf.isCompiledFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
               sb.append(" (Compiled frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
               if (vf.isDeoptimized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
                 sb.append(" [deoptimized]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
               }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
            } else if (vf.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
               sb.append(" (Interpreted frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
            if (vf.mayBeImpreciseDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
               sb.append("; information may be imprecise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
            sb.append(")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
            names.add(sb.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      String[] res = new String[names.size()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      System.arraycopy(names.toArray(), 0, res, 0, res.length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}