hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/InterpretedVFrame.java
author xdono
Tue, 28 Jul 2009 12:12:40 -0700
changeset 3261 c7d5aae8d3f7
parent 3171 aa289b22b577
child 5547 f4b087cbb361
permissions -rw-r--r--
6862919: Update copyright year Summary: Update copyright for files that have been modified in 2009, up to 07/09 Reviewed-by: tbell, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 3171
diff changeset
     2
 * Copyright 2000-2009 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.interpreter.*;
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
public class InterpretedVFrame extends JavaVFrame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  /** JVM state */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  public Method getMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    return getFrame().getInterpreterFrameMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  public StackValueCollection getLocals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    Method m = getMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    int length = (int) m.getMaxLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    if (m.isNative()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      // If the method is native, getMaxLocals is not telling the truth.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
      // maxlocals then equals the size of parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
      length = (int) m.getSizeOfParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    StackValueCollection result = new StackValueCollection(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    // Get oopmap describing oops and int for current bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    OopMapCacheEntry oopMask = getMethod().getMaskFor(getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // handle locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    for(int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      // Find stack location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      Address addr = addressOfLocalAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // Depending on oop/int put it in the right package
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      StackValue sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      if (oopMask.isOop(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        // oop value
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    64
        sv = new StackValue(addr.getOopHandleAt(0), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        // integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        // Fetch a signed integer the size of a stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
        sv = new StackValue(addr.getCIntegerAt(0, VM.getVM().getAddressSize(), false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      result.add(sv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return result;
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 StackValueCollection getExpressions() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    int length = getFrame().getInterpreterFrameExpressionStackSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    if (getMethod().isNative()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      // If the method is native, there is no expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      length = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    int nofLocals = (int) getMethod().getMaxLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    StackValueCollection result = new StackValueCollection(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    // Get oopmap describing oops and int for current bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    OopMapCacheEntry oopMask = getMethod().getMaskFor(getBCI());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    for(int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      // Find stack location
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      Address addr = addressOfExpressionStackAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      // Depending on oop/int put it in the right package
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      StackValue sv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      if (oopMask.isOop(i + nofLocals)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        // oop value
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
    98
        sv = new StackValue(addr.getOopHandleAt(0), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
        // integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        // Fetch a signed integer the size of a stack slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
        sv = new StackValue(addr.getCIntegerAt(0, VM.getVM().getAddressSize(), false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      result.add(sv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  /** Returns List<MonitorInfo> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  public List   getMonitors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    List result = new ArrayList(5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    for (BasicObjectLock current = getFrame().interpreterFrameMonitorEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
         current.address().lessThan(getFrame().interpreterFrameMonitorBegin().address());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
         current = getFrame().nextMonitorInInterpreterFrame(current)) {
3171
aa289b22b577 6837472: com/sun/jdi/MonitorFrameInfo.java fails with AggressiveOpts in 6u14
kvn
parents: 1
diff changeset
   116
      result.add(new MonitorInfo(current.obj(), current.lock(), false, false));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  /** Test operation */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public boolean isInterpretedFrame() { return true; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  /** Package-internal constructor */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  InterpretedVFrame(Frame fr, RegisterMap regMap, JavaThread thread) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    super(fr, regMap, thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  /** Accessor for Byte Code Index (NOTE: access to BCP is not allowed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      in this system; see Frame.java) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  public int getBCI() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    return getFrame().getInterpreterFrameBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  /** Setter for Byte Code Index */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  //  public void setBCI(int bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  //    getFrame().setInterpreterFrameBCI(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  public void verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  private Address addressOfLocalAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      Assert.that(getFrame().isInterpretedFrame(), "frame should be an interpreted frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    return fr.addressOfInterpreterFrameLocal(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  private Address addressOfExpressionStackAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return fr.addressOfInterpreterFrameExpressionStackSlot(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}