hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/JavaVFrame.java
author never
Mon, 05 Sep 2011 17:09:05 -0700
changeset 10517 f92c9ff3a15f
parent 5547 f4b087cbb361
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, 2007, 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 java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
public abstract class JavaVFrame extends VFrame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  /** JVM state */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  public abstract Method getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  public abstract int    getBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  public abstract StackValueCollection getLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  public abstract StackValueCollection getExpressions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  public abstract List   getMonitors();    // List<MonitorInfo>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  /** Test operation */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  public boolean isJavaFrame() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  /** Package-internal constructor */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  JavaVFrame(Frame fr, RegisterMap regMap, JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    super(fr, regMap, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  /** Get monitor (if any) that this JavaVFrame is trying to enter */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // FIXME: not yet implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  //  public Address getPendingMonitor(int frameCount);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  /** Printing used during stack dumps */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // FIXME: not yet implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  //  void print_lock_info(int frame_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  /** Printing operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // FIXME: implement visitor pattern for traversing vframe contents?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    printOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    super.printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    tty.print("\t");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    getMethod().printValueOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    tty.println("\tbci:\t" + getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    printStackValuesOn(tty, "locals",      getLocals());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    printStackValuesOn(tty, "expressions", getExpressions());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // List<MonitorInfo>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // FIXME: not yet implemented
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    //    List list = getMonitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    //    if (list.isEmpty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    //      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    //    for (int index = 0; index < list.size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    //      MonitorInfo monitor = (MonitorInfo) list.get(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    //      tty.print("\t  obj\t");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    //      monitor.getOwner().printValueOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    //      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    //      tty.print("\t  ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    //      monitor.lock().printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    //      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public void printActivation(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    printActivationOn(System.out, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  public void printActivationOn(PrintStream tty, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    // frame number and method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    tty.print(index + " - ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    printValueOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (VM.getVM().wizardMode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  /** Verification operations */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  public void verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public boolean equals(Object o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      if (o == null || !(o instanceof JavaVFrame)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      JavaVFrame other = (JavaVFrame) o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      // Check static part
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      if (!getMethod().equals(other.getMethod())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      if (getBCI() != other.getBCI()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      // dynamic part - we just compare the frame pointer
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   131
      if (! getFrame().equals(other.getFrame())) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public int hashCode() {
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   138
      return getMethod().hashCode() ^ getBCI() ^ getFrame().hashCode();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  /** Structural compare */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  public boolean structuralCompare(JavaVFrame other) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // Check static part
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (!getMethod().equals(other.getMethod())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    if (getBCI() != other.getBCI()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    // Check locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    StackValueCollection locs      = getLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    StackValueCollection otherLocs = other.getLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      Assert.that(locs.size() == otherLocs.size(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    for (int i = 0; i < locs.size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      // it might happen the compiler reports a conflict and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      // the interpreter reports a bogus int.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      if (      isCompiledFrame() && (locs.get(i)).getType()      == BasicType.getTConflict()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      if (other.isCompiledFrame() && (otherLocs.get(i)).getType() == BasicType.getTConflict()) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      if (!locs.get(i).equals(otherLocs.get(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // Check expressions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    StackValueCollection exprs      = getExpressions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    StackValueCollection otherExprs = other.getExpressions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      Assert.that(exprs.size() == otherExprs.size(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    for (int i = 0; i < exprs.size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      if (!exprs.get(i).equals(otherExprs.get(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  private void printStackValuesOn(PrintStream tty, String title, StackValueCollection values) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    if (values.isEmpty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    tty.println("\t" + title + ":");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    for (int index = 0; index < values.size(); index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      tty.print("\t" + index + "\t");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      values.get(index).printOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}