hotspot/agent/src/share/classes/sun/jvm/hotspot/code/PCDesc.java
author never
Mon, 05 Sep 2011 17:09:05 -0700
changeset 10517 f92c9ff3a15f
parent 6418 6671edbd230e
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
/*
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
     2
 * Copyright (c) 2000, 2010, 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: 4095
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4095
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: 4095
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.code;
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.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
/** PcDescs map a physical PC (given as offset from start of nmethod)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    to the corresponding source scope and byte code index. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
public class PCDesc extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  private static CIntegerField pcOffsetField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private static CIntegerField scopeDecodeOffsetField;
4095
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    39
  private static CIntegerField objDecodeOffsetField;
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    40
  private static CIntegerField pcFlagsField;
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    41
  private static int reexecuteMask;
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    42
  private static int isMethodHandleInvokeMask;
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    43
  private static int returnOopMask;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private static void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    Type type = db.lookupType("PcDesc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    pcOffsetField          = type.getCIntegerField("_pc_offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    scopeDecodeOffsetField = type.getCIntegerField("_scope_decode_offset");
4095
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    58
    objDecodeOffsetField   = type.getCIntegerField("_obj_decode_offset");
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    59
    pcFlagsField           = type.getCIntegerField("_flags");
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    60
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    61
    reexecuteMask            = db.lookupIntConstant("PcDesc::PCDESC_reexecute");
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    62
    isMethodHandleInvokeMask = db.lookupIntConstant("PcDesc::PCDESC_is_method_handle_invoke");
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    63
    returnOopMask            = db.lookupIntConstant("PcDesc::PCDESC_return_oop");
1
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 PCDesc(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // FIXME: add additional constructor probably needed for ScopeDesc::sender()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  public int getPCOffset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return (int) pcOffsetField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  public int getScopeDecodeOffset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    return ((int) scopeDecodeOffsetField.getValue(addr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
4095
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    80
  public int getObjDecodeOffset() {
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    81
    return ((int) objDecodeOffsetField.getValue(addr));
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    82
  }
6e0acfda1d47 6892186: SA does not dump debug info for scalar replaced objects
kvn
parents: 3686
diff changeset
    83
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  public Address getRealPC(NMethod code) {
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
    85
    return code.codeBegin().addOffsetTo(getPCOffset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    88
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    89
  public boolean getReexecute() {
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    90
    int flags = (int)pcFlagsField.getValue(addr);
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    91
    return (flags & reexecuteMask) != 0;
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    92
  }
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    93
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    94
  public boolean isMethodHandleInvoke() {
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    95
    int flags = (int)pcFlagsField.getValue(addr);
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 6418
diff changeset
    96
    return (flags & isMethodHandleInvokeMask) != 0;
3686
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    97
  }
69c1b5228547 6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents: 3600
diff changeset
    98
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public void print(NMethod code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    printOn(System.out, code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public void printOn(PrintStream tty, NMethod code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    tty.println("PCDesc(" + getRealPC(code) + "):");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    for (ScopeDesc sd = code.getScopeDescAt(getRealPC(code));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
         sd != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
         sd = sd.sender()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      tty.print(" ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      sd.getMethod().printValueOn(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      tty.print("  @" + sd.getBCI());
3600
27aa4477d039 6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents: 1
diff changeset
   111
      tty.print("  reexecute=" + sd.getReexecute());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      tty.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
}