hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/CompiledVFrame.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: 3261
diff changeset
     2
 * Copyright (c) 2000, 2009, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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.util.*;
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.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.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
/** FIXME: missing many accessors; all we have right now is the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    and BCI. NOTE that this has been modified from the VM's version to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    handle NULL ScopeDescs for the debugging case. This simplifies
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    using code a great deal. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
public class CompiledVFrame extends JavaVFrame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private ScopeDesc scope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private boolean mayBeImprecise;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  public CompiledVFrame(Frame fr, RegisterMap regMap, JavaThread thread, ScopeDesc scope, boolean mayBeImprecise) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    super(fr, regMap, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    this.scope = scope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    this.mayBeImprecise = mayBeImprecise;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    if (!VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
      Assert.that(scope != null, "scope must be present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  public boolean isTop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      return (getScope() == null || getScope().isTop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return getScope().isTop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  public boolean isCompiledFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  public boolean isDeoptimized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    return fr.isDeoptimized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  public boolean mayBeImpreciseDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    return mayBeImprecise;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  /** Returns the active method */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  public NMethod getCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return VM.getVM().getCodeCache().findNMethod(fr.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  /** Returns the active method. Does not perform a guarantee
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      regarding unloaded methods -- more suitable for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      system. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  public NMethod getCodeUnsafe() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return VM.getVM().getCodeCache().findNMethodUnsafe(fr.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  /** Returns the ScopeDesc */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  public ScopeDesc getScope() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    return scope;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  public Method getMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    if (VM.getVM().isDebugging() && getScope() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      return getCodeUnsafe().getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return getScope().getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  public StackValueCollection getLocals() {
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    96
    if (getScope() == null)
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    97
      return new StackValueCollection();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    List scvList = getScope().getLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (scvList == null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      return new StackValueCollection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // scvList is the list of ScopeValues describing the JVM stack state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // There is one scv_list entry for every JVM stack state in use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    int length = scvList.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    StackValueCollection result = new StackValueCollection(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    for( int i = 0; i < length; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      result.add( createStackValue((ScopeValue) scvList.get(i)) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  public StackValueCollection getExpressions() {
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   113
    if (getScope() == null)
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   114
      return new StackValueCollection();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    List scvList = getScope().getExpressions();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    if (scvList == null)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      return new StackValueCollection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    // scvList is the list of ScopeValues describing the JVM stack state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // There is one scv_list entry for every JVM stack state in use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    int length = scvList.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    StackValueCollection result = new StackValueCollection(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    for( int i = 0; i < length; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      result.add( createStackValue((ScopeValue) scvList.get(i)) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  /** Returns List<MonitorInfo> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public List   getMonitors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    List monitors = getScope().getMonitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    if (monitors == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      return new ArrayList();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    List result = new ArrayList(monitors.size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    for (int i = 0; i < monitors.size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      MonitorValue mv = (MonitorValue) monitors.get(i);
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   138
      ScopeValue ov = mv.owner();
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   139
      StackValue ownerSV = createStackValue(ov); // it is an oop
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   140
      if (ov.isObject()) { // The owner object was scalar replaced
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   141
        Assert.that(mv.eliminated() && ownerSV.objIsScalarReplaced(), "monitor should be eliminated for scalar replaced object");
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   142
        // Put klass for scalar replaced object.
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   143
        ScopeValue kv = ((ObjectValue)ov).getKlass();
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   144
        Assert.that(kv.isConstantOop(), "klass should be oop constant for scalar replaced object");
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   145
        OopHandle k = ((ConstantOopReadValue)kv).getValue();
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   146
        result.add(new MonitorInfo(k, resolveMonitorLock(mv.basicLock()), mv.eliminated(), true));
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   147
      } else {
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   148
        result.add(new MonitorInfo(ownerSV.getObject(), resolveMonitorLock(mv.basicLock()), mv.eliminated(), false));
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   149
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  public int getBCI() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    int raw = getRawBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return ((raw == DebugInformationRecorder.SYNCHRONIZATION_ENTRY_BCI) ? 0 : raw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  /** Returns SynchronizationEntryBCI or bci() (used for synchronization) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  public int getRawBCI() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    if (VM.getVM().isDebugging() && getScope() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      return 0; // No debugging information!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    return getScope().getBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  /** Returns the sender vframe */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  public VFrame sender() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      Assert.that(isTop(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return sender(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public VFrame sender(boolean mayBeImprecise) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (!VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        Assert.that(scope != null, "When new stub generator is in place, then scope can never be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    Frame f = (Frame) getFrame().clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    return (isTop()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
              ? super.sender(false)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
              : new CompiledVFrame(f, getRegisterMap(), getThread(), getScope().sender(), mayBeImprecise));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  private StackValue createStackValue(ScopeValue sv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    // FIXME: this code appears to be out-of-date with respect to the VM especially in 64-bit mode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    if (sv.isLocation()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      // Stack or register value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      Location loc = ((LocationValue) sv).getLocation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      if (loc.isIllegal()) return new StackValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      // First find address of value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      Address valueAddr = loc.isRegister()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        // Value was in a callee-save register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        ? getRegisterMap().getLocation(new VMReg(loc.getRegisterNumber()))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        // Else value was directly saved on the stack. The frame's original stack pointer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        // before any extension by its callee (due to Compiler1 linkage on SPARC), must be used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        : ((Address)fr.getUnextendedSP()).addOffsetTo(loc.getStackOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      // Then package it right depending on type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      if (loc.holdsFloat()) {    // Holds a float in a double register?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        // The callee has no clue whether the register holds a float,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        // double or is unused.  He always saves a double.  Here we know
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        // a double was saved, but we only want a float back.  Narrow the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        // saved double to the float that the JVM wants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
          Assert.that( loc.isRegister(), "floats always saved to stack in 1 word" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        float value = (float) valueAddr.getJDoubleAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        return new StackValue(Float.floatToIntBits(value) & 0xFFFFFFFF); // 64-bit high half is stack junk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      } else if (loc.holdsInt()) {  // Holds an int in a long register?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        // The callee has no clue whether the register holds an int,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        // long or is unused.  He always saves a long.  Here we know
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        // a long was saved, but we only want an int back.  Narrow the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        // saved long to the int that the JVM wants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
          Assert.that( loc.isRegister(), "ints always saved to stack in 1 word" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        return new StackValue(valueAddr.getJLongAt(0) & 0xFFFFFFFF);
1135
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   223
      } else if (loc.holdsNarrowOop()) {  // Holds an narrow oop?
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   224
        if (loc.isRegister() && VM.getVM().isBigEndian()) {
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   225
          // The callee has no clue whether the register holds an narrow oop,
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   226
          // long or is unused.  He always saves a long.  Here we know
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   227
          // a long was saved, but we only want an narrow oop back.  Narrow the
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   228
          // saved long to the narrow oop that the JVM wants.
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   229
          return new StackValue(valueAddr.getCompOopHandleAt(VM.getVM().getIntSize()), 0);
1135
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   230
        } else {
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   231
          return new StackValue(valueAddr.getCompOopHandleAt(0), 0);
1135
9487203e5789 6706829: Compressed Oops: add debug info for narrow oops
kvn
parents: 1
diff changeset
   232
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      } else if( loc.holdsOop() ) {  // Holds an oop?
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   234
        return new StackValue(valueAddr.getOopHandleAt(0), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      } else if( loc.holdsDouble() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        // Double value in a single stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        return new StackValue(valueAddr.getJIntAt(0) & 0xFFFFFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      } else if(loc.holdsAddr()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
          Assert.that(!VM.getVM().isServerCompiler(), "No address type for locations with C2 (jsr-s are inlined)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        // FIXME: not yet implemented (no access to safepoint state yet)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        return new StackValue(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        //      intptr_t return_addr_tmp = *(intptr_t *)value_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
        //      int bci = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        //      // Get the bci of the jsr that generated this returnAddress value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        //      // If the destination of a jsr is a block that ends with a return or throw, then
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        //      // the GraphBuilder converts the jsr into a direct goto.  This has the side effect that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        //      // the return address for the jsr gets emitted as a bci instead of as a real pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        //      if (code()->contains((address)return_addr_tmp)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
        //        ScopeDesc* scope = code()->scope_desc_at((address)(return_addr_tmp - jsr_call_offset), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
        //        bci = scope->bci();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        //      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        //        bci = (int)return_addr_tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        //      // no need to lock method as this happens at Safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        //      assert (SafepointSynchronize::is_at_safepoint(), "must be at safepoint, otherwise lock method()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        //      // make sure bci points to jsr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        //      Bytecode* bytecode = Bytecode_at(method()->bcp_from(bci));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
        //      Bytecodes::Code bc = bytecode->code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        //      assert (bc == Bytecodes::_jsr || bc == Bytecodes::_jsr_w, "must be jsr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        //      // the real returnAddress is the bytecode following the jsr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        //      return new StackValue((intptr_t)(bci + Bytecodes::length_for(bc)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      } else if (VM.getVM().isLP64() && loc.holdsLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        if ( loc.isRegister() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
          // Long value in two registers, high half in the first, low in the second
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
          return new StackValue(((valueAddr.getJLongAt(0) & 0xFFFFFFFF) << 32) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
                                ((valueAddr.getJLongAt(8) & 0xFFFFFFFF)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
          // Long value in a single stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
          return new StackValue(valueAddr.getJLongAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      } else if( loc.isRegister() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        // At the moment, all non-oop values in registers are 4 bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        // including double and long halves (see Compile::FillLocArray() in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        // opto/output.cpp).  Haul them out as such and return a StackValue
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        // containing an image of the value as it appears in a stack slot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
        // If this is a double or long half, the interpreter _must_ deal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        // with doubles and longs as entities split across two stack slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        // To change this so doubles and/or longs can live in one stack slot,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        // a StackValue will have to understand that it can contain an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        // undivided double or long, implying that a Location (and the debug
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        // info mechanism) and FillLocArray() will also have to understand it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        return new StackValue(valueAddr.getJIntAt(0) & 0xFFFFFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        return new StackValue(valueAddr.getJIntAt(0) & 0xFFFFFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    } else if (sv.isConstantInt()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      // Constant int: treat same as register int.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      return new StackValue(((ConstantIntValue) sv).getValue() & 0xFFFFFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    } else if (sv.isConstantOop()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      // constant oop
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   294
      return new StackValue(((ConstantOopReadValue) sv).getValue(), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    } else if (sv.isConstantDouble()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      // Constant double in a single stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      double d = ((ConstantDoubleValue) sv).getValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      return new StackValue(Double.doubleToLongBits(d) & 0xFFFFFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    } else if (VM.getVM().isLP64() && sv.isConstantLong()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      // Constant long in a single stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      return new StackValue(((ConstantLongValue) sv).getValue() & 0xFFFFFFFF);
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   302
    } else if (sv.isObject()) {
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   303
      // Scalar replaced object in compiled frame
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1217
diff changeset
   304
      return new StackValue(((ObjectValue)sv).getValue(), 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    // Unknown ScopeValue type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    Assert.that(false, "Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    return new StackValue(0);   // dummy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  private BasicLock resolveMonitorLock(Location location) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      Assert.that(location.isStack(), "for now we only look at the stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    int byteOffset = location.getStackOffset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    // (stack picture)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    // high: [     ]  byte_offset + wordSize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    // low   [     ]  byte_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    // sp->  [     ]  0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // the byte_offset is the distance from the stack pointer to the lowest address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // The frame's original stack pointer, before any extension by its callee
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // (due to Compiler1 linkage on SPARC), must be used.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    return new BasicLock(getFrame().getUnextendedSP().addOffsetTo(byteOffset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}