hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/VFrame.java
author never
Mon, 05 Sep 2011 17:09:05 -0700
changeset 10517 f92c9ff3a15f
parent 5547 f4b087cbb361
child 28369 a62a208f18de
permissions -rw-r--r--
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244) Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2000, 2006, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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 sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
public class VFrame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  protected Frame       fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  protected RegisterMap regMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  protected JavaThread  thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  protected VFrame(Frame f, RegisterMap regMap, JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    this.regMap = (RegisterMap) regMap.clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    if (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      // the frame is null if we create a deoptimizedVFrame from a vframeArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
      fr = (Frame) f.clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    this.thread = thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  /** Factory method for creating vframes. The "unsafe" flag turns off
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      an assertion which the runtime system uses to ensure integrity,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
      but which must not be applied in the debugging situation. The
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      "mayBeImprecise" flag should be set to true for the case of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      top frame in the debugging system (obtained via
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      JavaThread.getCurrentFrameGuess()). */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  public static VFrame newVFrame(Frame f, RegisterMap regMap, JavaThread thread, boolean unsafe, boolean mayBeImprecise) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    if (f.isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return new InterpretedVFrame(f, regMap, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      CodeBlob cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      if (unsafe) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
        cb = VM.getVM().getCodeCache().findBlobUnsafe(f.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        cb = VM.getVM().getCodeCache().findBlob(f.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      if (cb != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        if (cb.isNMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
          NMethod nm = (NMethod) cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
          // Compiled method (native stub or Java code)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
          ScopeDesc scope = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
          // FIXME: should revisit the check of isDebugging(); should not be necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
          if (mayBeImprecise || VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
            scope = nm.getScopeDescNearDbg(f.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
            scope = nm.getScopeDescAt(f.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
          return new CompiledVFrame(f, regMap, thread, scope, mayBeImprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    80
        if (f.isRuntimeFrame()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
          // This is a conversion frame. Skip this frame and try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
          RegisterMap tempMap = regMap.copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
          Frame s = f.sender(tempMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
          return newVFrame(s, tempMap, thread, unsafe, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    // External frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return new ExternalVFrame(f, regMap, thread, mayBeImprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  /** Factory method for creating vframes. This is equivalent to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      calling the above version with the "unsafe" and "imprecise"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      flags set to false. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  public static VFrame newVFrame(Frame f, RegisterMap regMap, JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return newVFrame(f, regMap, thread, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  /** Accessors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  public Frame       getFrame()       { return fr;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  public RegisterMap getRegisterMap() { return regMap; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public JavaThread  getThread()      { return thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  /** Returns the sender vframe */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  public VFrame sender() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      Assert.that(isTop(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return sender(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  /** Returns the sender vframe; takes argument for debugging situation */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public VFrame sender(boolean mayBeImprecise) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    RegisterMap tempMap = (RegisterMap) getRegisterMap().clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    if (fr.isFirstFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    Frame s = fr.realSender(tempMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // ia64 in 1.4.1 only has java frames and no entryFrame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // so "s" can be null here for the first frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    if (s == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      Assert.that(VM.getVM().getCPU().equals("ia64"), "Only ia64 should have null here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (s.isFirstFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    return VFrame.newVFrame(s, tempMap, getThread(), VM.getVM().isDebugging(), mayBeImprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  /** Returns the next javaVFrame on the stack (skipping all other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      kinds of frames).  In the debugging situation, allows the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      "imprecise" flag to propagate up the stack. We must not assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      that a ScopeDesc exists for the topmost compiled frame on the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      stack. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public JavaVFrame javaSender() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    boolean imprecise = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    // Hack for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      if (!isJavaFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
        imprecise = mayBeImpreciseDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    VFrame f = sender(imprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    while (f != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (f.isJavaFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        return (JavaVFrame) f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      f = f.sender(imprecise);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  /** Answers if the this is the top vframe in the frame, i.e., if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      sender vframe is in the caller frame */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  public boolean isTop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  /** Returns top vframe within same frame (see isTop()) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  public VFrame top() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    VFrame vf = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    while (!vf.isTop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      vf = vf.sender();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return vf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  /** Type testing operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  public boolean isEntryFrame()       { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  public boolean isJavaFrame()        { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  public boolean isInterpretedFrame() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public boolean isCompiledFrame()    { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  public boolean isDeoptimized()      { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  /** An indication of whether this VFrame is "precise" or a best
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      guess. This is used in the debugging system to handle the top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      frame on the stack, which, since the system will in general not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      be at a safepoint, has to make some guesses about exactly where
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      in the execution it is. Any debugger should indicate to the user
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      that the information for this frame may not be 100% correct.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      FIXME: may need to move this up into VFrame instead of keeping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      it in CompiledVFrame. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  public boolean mayBeImpreciseDbg()  { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  /** Printing operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    printOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    if (VM.getVM().wizardMode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      fr.printValueOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  public void printValue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    printValueOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}