src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JavaThread.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46636 hotspot/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/runtime/JavaThread.java@26b8de0359a0
child 54955 46409371a691
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
     2
 * Copyright (c) 2000, 2017, 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: 5528
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5528
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: 5528
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.runtime;
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.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
/** This is an abstract class because there are certain OS- and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    CPU-specific operations (like the setting and getting of the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    Java frame pointer) which need to be factored out. These
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    operations are implemented by, for example,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    SolarisSPARCJavaThread, and the concrete subclasses are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    instantiated by the JavaThreadFactory in the Threads class. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
public class JavaThread extends Thread {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.runtime.JavaThread.DEBUG") != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private static AddressField  nextField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private static sun.jvm.hotspot.types.OopField threadObjField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private static AddressField  anchorField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private static AddressField  lastJavaSPField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private static AddressField  lastJavaPCField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private static CIntegerField threadStateField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private static AddressField  osThreadField;
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
    51
  private static AddressField  stackBaseField;
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
    52
  private static CIntegerField stackSizeField;
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
    53
  private static CIntegerField terminatedField;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  private static JavaThreadPDAccess access;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // JavaThreadStates read from underlying process
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private static int           UNINITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private static int           NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private static int           NEW_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private static int           IN_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private static int           IN_NATIVE_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private static int           IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private static int           IN_VM_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private static int           IN_JAVA;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  private static int           IN_JAVA_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  private static int           BLOCKED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  private static int           BLOCKED_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
    70
  private static int           NOT_TERMINATED;
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
    71
  private static int           EXITING;
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
    72
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
    73
  private static final String  ADDRESS_FORMAT = VM.getVM().isLP64() ? "0x%016x" : "0x%08x";
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
    74
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    Type type = db.lookupType("JavaThread");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    Type anchorType = db.lookupType("JavaFrameAnchor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    nextField         = type.getAddressField("_next");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    threadObjField    = type.getOopField("_threadObj");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    anchorField       = type.getAddressField("_anchor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    lastJavaSPField   = anchorType.getAddressField("_last_Java_sp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    lastJavaPCField   = anchorType.getAddressField("_last_Java_pc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    threadStateField  = type.getCIntegerField("_thread_state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    osThreadField     = type.getAddressField("_osthread");
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
    94
    stackBaseField    = type.getAddressField("_stack_base");
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
    95
    stackSizeField    = type.getCIntegerField("_stack_size");
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
    96
    terminatedField   = type.getCIntegerField("_terminated");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    UNINITIALIZED     = db.lookupIntConstant("_thread_uninitialized").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    NEW               = db.lookupIntConstant("_thread_new").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    NEW_TRANS         = db.lookupIntConstant("_thread_new_trans").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    IN_NATIVE         = db.lookupIntConstant("_thread_in_native").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    IN_NATIVE_TRANS   = db.lookupIntConstant("_thread_in_native_trans").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    IN_VM             = db.lookupIntConstant("_thread_in_vm").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    IN_VM_TRANS       = db.lookupIntConstant("_thread_in_vm_trans").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    IN_JAVA           = db.lookupIntConstant("_thread_in_Java").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    IN_JAVA_TRANS     = db.lookupIntConstant("_thread_in_Java_trans").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    BLOCKED           = db.lookupIntConstant("_thread_blocked").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    BLOCKED_TRANS     = db.lookupIntConstant("_thread_blocked_trans").intValue();
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   109
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   110
    NOT_TERMINATED    = db.lookupIntConstant("JavaThread::_not_terminated").intValue();
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   111
    EXITING           = db.lookupIntConstant("JavaThread::_thread_exiting").intValue();
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   112
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  public JavaThread(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void setThreadPDAccess(JavaThreadPDAccess access) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    this.access = access;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  public JavaThread next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    Address threadAddr = nextField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    if (threadAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    return VM.getVM().getThreads().createJavaThreadWrapper(threadAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
27475
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   132
  /** NOTE: for convenience, this differs in definition from the underlying VM.
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   133
      Only "pure" JavaThreads return true; CompilerThreads, the CodeCacheSweeperThread,
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   134
      JVMDIDebuggerThreads return false.
1f22a5d5be00 8062735: CodeCacheSweeperThread missing from SA
anoll
parents: 16351
diff changeset
   135
      FIXME:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      consider encapsulating platform-specific functionality in an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      object instead of using inheritance (which is the primary reason
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      we can't traverse CompilerThreads, etc; didn't want to have, for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      example, "SolarisSPARCCompilerThread".) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  public boolean isJavaThread() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   142
  public boolean isExiting () {
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   143
      return (getTerminated() == EXITING) || isTerminated();
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   144
  }
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   145
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   146
  public boolean isTerminated() {
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   147
      return (getTerminated() != NOT_TERMINATED) && (getTerminated() != EXITING);
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   148
  }
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   149
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public static AddressField getAnchorField() { return anchorField; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  /** Get the last Java stack pointer */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public Address getLastJavaSP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    Address sp = lastJavaSPField.getValue(addr.addOffsetTo(anchorField.getOffset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    return sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  public Address getLastJavaPC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    Address pc = lastJavaPCField.getValue(addr.addOffsetTo(anchorField.getOffset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    return pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  /** Abstract accessor to last Java frame pointer, implemented by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      OS/CPU-specific JavaThread implementation. May return null if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      there is no frame pointer or if it is not necessary on this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      platform. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  public Address getLastJavaFP(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        return access.getLastJavaFP(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  /** Abstract accessor to last Java pc, implemented by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      OS/CPU-specific JavaThread implementation. May return null if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      there is no frame pointer or if it is not necessary on this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      platform. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  public Address getLastJavaPC(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        return access.getLastJavaPC(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  //  public abstract void    setLastJavaFP(Address fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  /** A stack pointer older than any java frame stack pointer. Only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      needed on some platforms; for example, see
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      thread_solaris_sparc.hpp. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  public Address getBaseOfStackPointer(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        return access.getBaseOfStackPointer(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  //  public abstract void    setBaseOfStackPointer(Address fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  /** Tells whether the last Java frame is set */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  public boolean hasLastJavaFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    return (getLastJavaSP() != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  /** Accessing frames */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  public Frame getLastFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    // FIXME: would need to implement runtime routine
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    // "cacheStatePD(boolean)" for reflective system to be able to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    // flush register windows on SPARC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    return cookLastFrame(getLastFramePD());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  /** Internal routine implemented by platform-dependent subclasses */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  protected Frame getLastFramePD(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        return access.getLastFramePD(this, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  /** Accessing frames. Returns the last Java VFrame or null if none
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      was present. (NOTE that this is mostly unusable in a debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      system; see getLastJavaVFrameDbg, below, which provides very
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      different functionality.) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  public JavaVFrame getLastJavaVFrame(RegisterMap regMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      Assert.that(regMap != null, "a map must be given");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    Frame f = getLastFrame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    if (f == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    for (VFrame vf = VFrame.newVFrame(f, regMap, this); vf != null; vf = vf.sender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      if (vf.isJavaFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        return (JavaVFrame) vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    }
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  /** This should only be used by a debugger. Uses the current frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      guess to attempt to get the topmost JavaVFrame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      (getLastJavaVFrame, as a port of the VM's routine, assumes the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      VM is at a safepoint.) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  public JavaVFrame getLastJavaVFrameDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    RegisterMap regMap = newRegisterMap(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    sun.jvm.hotspot.runtime.Frame f = getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    if (f == null) return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    boolean imprecise = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    if (f.isInterpretedFrame() && !f.isInterpretedFrameValid()) {
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   242
       if (DEBUG) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   243
         System.out.println("Correcting for invalid interpreter frame");
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   244
       }
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   245
       f = f.sender(regMap);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   246
       imprecise = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    VFrame vf = VFrame.newVFrame(f, regMap, this, true, imprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (vf == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        System.out.println(" (Unable to create vframe for topmost frame guess)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   255
    return vf.isJavaFrame() ? (JavaVFrame)vf : vf.javaSender();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  /** In this system, a JavaThread is the top-level factory for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      RegisterMap, since the JavaThread implementation is already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      platform-specific and RegisterMap is also necessarily
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      platform-specific. The updateMap argument indicates whether the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      register map needs to be updated, for example during stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      traversal -- see frame.hpp. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  public RegisterMap newRegisterMap(boolean updateMap){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        return access.newRegisterMap(this, updateMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  /** This is only designed to be used by the debugging system.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      Returns a "best guess" of the topmost frame on the stack. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      guess should be as "raw" as possible. For example, if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      topmost frame is an interpreter frame (the return PC is in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      interpreter) but is not a valid frame (i.e., the BCI has not yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      been set up) this should still return the topmost frame and not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      the sender. Validity checks are done at higher levels. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  public  Frame getCurrentFrameGuess(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        return access.getCurrentFrameGuess(this, addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  /** Also only intended for use by the debugging system. Provides the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      same effect of OSThread::print(); that is, prints a value which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      allows the user to intuitively understand which native OS thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      maps to this Java thread. Does not print a newline or leading or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      trailing spaces. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  public  void printThreadIDOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        access.printThreadIDOn(addr,tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  public void printThreadID() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    printThreadIDOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  public ThreadProxy getThreadProxy() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    return access.getThreadProxy(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // Safepoint support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  public JavaThreadState getThreadState() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    int val = (int) threadStateField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (val == UNINITIALIZED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      return JavaThreadState.UNINITIALIZED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    } else if (val == NEW) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      return JavaThreadState.NEW;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    } else if (val == NEW_TRANS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      return JavaThreadState.NEW_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    } else if (val == IN_NATIVE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      return JavaThreadState.IN_NATIVE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    } else if (val == IN_NATIVE_TRANS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      return JavaThreadState.IN_NATIVE_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    } else if (val == IN_VM) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      return JavaThreadState.IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    } else if (val == IN_VM_TRANS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      return JavaThreadState.IN_VM_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    } else if (val == IN_JAVA) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      return JavaThreadState.IN_JAVA;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    } else if (val == IN_JAVA_TRANS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      return JavaThreadState.IN_JAVA_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    } else if (val == BLOCKED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
      return JavaThreadState.BLOCKED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    } else if (val == BLOCKED_TRANS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      return JavaThreadState.BLOCKED_TRANS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      throw new RuntimeException("Illegal thread state " + val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // public void setThreadState(JavaThreadState s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // Miscellaneous operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  public OSThread getOSThread() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    return (OSThread) VMObjectFactory.newObject(OSThread.class, osThreadField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   339
  public Address getStackBase() {
2861
073fc25fed0c 6843580: JavaThread.getStackBase throws sun.jvm.hotspot.WrongTypeException invoked by jstack
xlu
parents: 2526
diff changeset
   340
    return stackBaseField.getValue(addr);
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   341
  }
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   342
16351
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 5547
diff changeset
   343
  public long getStackBaseValue() {
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 5547
diff changeset
   344
    return VM.getVM().getAddressValue(getStackBase());
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 5547
diff changeset
   345
  }
032b310a3e2f 8003348: SA can not read core file on OS
minqi
parents: 5547
diff changeset
   346
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   347
  public long getStackSize() {
2861
073fc25fed0c 6843580: JavaThread.getStackBase throws sun.jvm.hotspot.WrongTypeException invoked by jstack
xlu
parents: 2526
diff changeset
   348
    return stackSizeField.getValue(addr);
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   349
  }
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   350
45371
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   351
  public int getTerminated() {
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   352
      return (int) terminatedField.getValue(addr);
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   353
  }
5d0b68ea07c3 6760477: Update SA to include stack traces in the heap dump
sballal
parents: 35217
diff changeset
   354
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  /** Gets the Java-side thread object for this JavaThread */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  public Oop getThreadObj() {
5528
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   357
    Oop obj = null;
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   358
    try {
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   359
      obj = VM.getVM().getObjectHeap().newOop(threadObjField.getValue(addr));
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   360
    } catch (Exception e) {
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   361
      e.printStackTrace();
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   362
    }
4c95c500fc8b 6745217: jmap assertion failure
poonam
parents: 3261
diff changeset
   363
    return obj;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  /** Get the Java-side name of this thread */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  public String getThreadName() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    Oop threadObj = getThreadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    if (threadObj == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
        return "<null>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    return OopUtilities.threadOopGetName(threadObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // Oop traversal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  public void oopsDo(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    super.oopsDo(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    // FIXME: add in the rest of the routine from the VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    // Traverse the execution stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    for(StackFrameStream fst = new StackFrameStream(this); !fst.isDone(); fst.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      fst.getCurrent().oopsDo(oopVisitor, fst.getRegisterMap());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  public boolean isInStack(Address a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      Assert.that(VM.getVM().isDebugging(), "Not yet implemented for non-debugging system");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    Address sp      = lastSPDbg();
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   395
    Address stackBase = getStackBase();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    // Be robust
2526
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   397
    if (sp == null) return false;
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   398
    return stackBase.greaterThanOrEqual(a) && sp.lessThanOrEqual(a);
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   399
  }
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   400
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   401
  public boolean isLockOwned(Address a) {
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   402
    Address stackBase = getStackBase();
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   403
    Address stackLimit = stackBase.addOffsetTo(-getStackSize());
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   404
39a58a50be35 6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents: 764
diff changeset
   405
    return stackBase.greaterThanOrEqual(a) && stackLimit.lessThanOrEqual(a);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    // FIXME: should traverse MonitorArray/MonitorChunks as in VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  public Oop getCurrentParkBlocker() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    Oop threadObj = getThreadObj();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    if (threadObj != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      return OopUtilities.threadOopGetParkBlocker(threadObj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  public void printInfoOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    tty.println("State: " + getThreadState().toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    // Attempt to figure out the addresses covered by Java frames.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    // NOTE: we should make this a method and let the Stackwalk panel use the result too.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    sun.jvm.hotspot.runtime.Frame tmpFrame = getCurrentFrameGuess();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    if (tmpFrame != null ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      Address sp = tmpFrame.getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      Address maxSP = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      Address minSP = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      RegisterMap tmpMap = newRegisterMap(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      while ((tmpFrame != null) && (!tmpFrame.isFirstFrame())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
          tmpFrame = tmpFrame.sender(tmpMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
          if (tmpFrame != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
            sp = tmpFrame.getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
            maxSP = AddressOps.max(maxSP, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
            minSP = AddressOps.min(minSP, sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      tty.println("Stack in use by Java: " + minSP + " .. " + maxSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      tty.println("No Java frames present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    }
34665
9fdcc78b5398 8140031: SA: Searching for a value in Threads does not work
poonam
parents: 27475
diff changeset
   442
    tty.println("Base of Stack: " + getStackBase());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    tty.println("Last_Java_SP: " + getLastJavaSP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    tty.println("Last_Java_FP: " + getLastJavaFP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    tty.println("Last_Java_PC: " + getLastJavaPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    // More stuff like saved_execption_pc, safepoint_state, ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    access.printInfoOn(addr, tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  ///////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  //                           //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // FIXME: add more accessors //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  //                           //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  ///////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  private Frame cookLastFrame(Frame fr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    if (fr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    Address pc        = fr.getPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
      if (pc == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
        Assert.that(VM.getVM().isDebugging(), "must have PC");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    return fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  private Address lastSPDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    return access.getLastSP(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
46636
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   480
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   481
  public void printThreadInfoOn(PrintStream out){
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   482
    Oop threadOop = this.getThreadObj();
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   483
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   484
    out.print("\"");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   485
    out.print(this.getThreadName());
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   486
    out.print("\" #");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   487
    out.print(OopUtilities.threadOopGetTID(threadOop));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   488
    if(OopUtilities.threadOopGetDaemon(threadOop)){
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   489
      out.print(" daemon");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   490
    }
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   491
    out.print(" prio=");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   492
    out.print(OopUtilities.threadOopGetPriority(threadOop));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   493
    out.print(" tid=");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   494
    out.print(this.getAddress());
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   495
    out.print(" nid=");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   496
    out.print(String.format("0x%x ",this.getOSThread().threadId()));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   497
    out.print(getOSThread().getThreadState().getPrintVal());
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   498
    out.print(" [");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   499
    if(this.getLastJavaSP() == null){
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   500
      out.print(String.format(ADDRESS_FORMAT,0L));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   501
    } else {
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   502
      out.print(this.getLastJavaSP().andWithMask(~0xFFF));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   503
    }
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   504
    out.println("]");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   505
    out.print("   java.lang.Thread.State: ");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   506
    out.println(OopUtilities.threadOopGetThreadStatusName(threadOop));
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   507
    out.print("   JavaThread state: _thread_");
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   508
    out.println(this.getThreadState().toString().toLowerCase());
26b8de0359a0 8181647: jhsdb jstack could not output thread name
dbuck
parents: 45371
diff changeset
   509
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
}