hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Frame.java
author rbackman
Tue, 05 May 2015 16:50:25 +0200
changeset 30590 14f7f48c1377
parent 13728 882756847a04
child 31389 e0688be912e5
permissions -rw-r--r--
8064458: OopMap class could be more compact Reviewed-by: kvn, bdelsart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
     2
 * Copyright (c) 2000, 2012, 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: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
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: 670
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.*;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 13728
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.compiler.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.interpreter.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
/** <P> A frame represents a physical stack frame (an activation).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    Frames can be C or Java frames, and the Java frames can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    interpreted or compiled. In contrast, vframes represent
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    source-level activations, so that one physical frame can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    correspond to multiple source level frames because of inlining.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    <P> NOTE that this is not a VMObject and does not wrap an Address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    -- this is an actual port of the VM's Frame code to Java. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    <P> NOTE also that this is incomplete -- just trying to get
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    reading of interpreted frames working for now, so all non-core and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    setter methods are removed for now. (FIXME) </P> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
public abstract class Frame implements Cloneable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  /** A raw stack pointer. The accessor getSP() will return a real (usable)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      stack pointer (e.g. from Thread::last_Java_sp) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  protected Address raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  /** Program counter (the next instruction after the call) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  protected Address pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  protected boolean deoptimized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  public Frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    deoptimized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    73
  /** Size of ConstMethod for computing BCI from BCP (FIXME: hack) */
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    74
  private static long    ConstMethodSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    76
  private static int pcReturnOffset;
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    77
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    78
  public static int pcReturnOffset() {
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    79
    return pcReturnOffset;
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    80
  }
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    81
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  private static synchronized void initialize(TypeDataBase db) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    83
    Type ConstMethodType = db.lookupType("ConstMethod");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // FIXME: not sure whether alignment here is correct or how to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    // force it (round up to address size?)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    86
    ConstMethodSize = ConstMethodType.getSize();
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    87
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
    88
    pcReturnOffset = db.lookupIntConstant("frame::pc_return_offset").intValue();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  protected int bcpToBci(Address bcp, ConstMethod cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // bcp will be null for interpreter native methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // in addition depending on where we catch the system the value can
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    // be a bcp or a bci.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    if (bcp == null) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    long bci = bcp.minus(null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (bci >= 0 && bci < cm.getCodeSize()) return (int) bci;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    98
    return (int) (bcp.minus(cm.getAddress()) - ConstMethodSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  protected int bcpToBci(Address bcp, Method m) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    return bcpToBci(bcp, m.getConstMethod());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  public abstract Object clone();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  /** pc: Returns the pc at which this frame will continue normally.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      It must point at the beginning of the next instruction to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      execute. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  public Address getPC()              { return pc; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  public void    setPC(Address newpc) { pc = newpc; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  public boolean isDeoptimized()      { return deoptimized; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   116
  public CodeBlob cb() {
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   117
    return VM.getVM().getCodeCache().findBlob(getPC());
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   118
  }
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   119
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  public abstract Address getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public abstract Address getID();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public abstract Address getFP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  /** testers -- platform dependent */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  public abstract boolean equals(Object arg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  /** type testers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  public boolean isInterpretedFrame()           { return VM.getVM().getInterpreter().contains(getPC()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public boolean isJavaFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    if (isInterpretedFrame()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      if (isCompiledFrame())    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  /** Java frame called from C? */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  public boolean isEntryFrame()                 { return VM.getVM().getStubRoutines().returnsToCallStub(getPC()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  public boolean isNativeFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      CodeBlob cb = VM.getVM().getCodeCache().findBlob(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      return (cb != null && cb.isNativeMethod());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  public boolean isCompiledFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      Assert.that(!VM.getVM().isCore(), "noncore builds only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    CodeBlob cb = VM.getVM().getCodeCache().findBlob(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    return (cb != null && cb.isJavaMethod());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   156
  public boolean isRuntimeFrame() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      Assert.that(!VM.getVM().isCore(), "noncore builds only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    CodeBlob cb = VM.getVM().getCodeCache().findBlob(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    if (cb == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    if (cb.isRuntimeStub()) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    else 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
  /** oldest frame? (has no sender) FIXME: this is modified from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      C++ code to handle the debugging situation where we try to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      traverse the stack for, for example, the signal thread, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      don't find any valid Java frames. Would really like to put the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      second half of the conditional in some sort of debugging-only if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      statement. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // *** FIXME: THE CALL TO isJavaFrame() IS WAY TOO EXPENSIVE!!!!! ***
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public boolean isFirstFrame()                 { return ((isEntryFrame() && entryFrameIsFirst()) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                                                          (!isJavaFrame() && !hasSenderPD()));       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  /** same for Java frame */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  public boolean isFirstJavaFrame()             { throw new RuntimeException("not yet implemented"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  /** This is an addition for debugging purposes on platforms which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      have the notion of signals. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  public abstract boolean isSignalHandlerFrameDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  /** If this is a signal handler frame (again, on a platform with a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      notion of signals), get the signal number. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  public abstract int getSignalNumberDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  /** If this is a signal handler frame (again, on a platform with a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      notion of signals), get the name of the signal. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  public abstract String getSignalNameDbg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  /** performs sanity checks on interpreted frames. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  public abstract boolean isInterpretedFrameValid();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  /** tells whether this frame is marked for deoptimization */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  public boolean shouldBeDeoptimized()          { throw new RuntimeException("not yet implemented"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  /** tells whether this frame can be deoptimized */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  public boolean canBeDeoptimized()             { throw new RuntimeException("not yet implemented"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  /** returns the sending frame */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  public abstract Frame sender(RegisterMap map, CodeBlob nm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  /** equivalent to sender(map, null) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  public Frame sender(RegisterMap map)          { return sender(map, null); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  /** returns the sender, but skips conversion frames */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  public Frame realSender(RegisterMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      Frame result = sender(map);
13391
30245956af37 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 10517
diff changeset
   211
      while (result.isRuntimeFrame()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        result = result.sender(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      return sender(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  /** Platform-dependent query indicating whether this frame has a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      sender. Should return true if it is possible to call sender() at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      all on this frame. (This is currently only needed for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      debugging system, if a stack trace is attempted for a Java
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      thread which has no Java frames, i.e., the signal thread; we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      have to know to stop traversal at the bottom frame.) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  protected abstract boolean hasSenderPD();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // All frames:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // A low-level interface for vframes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  /** Returns the address of the requested "slot" on the stack. Slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      are as wide as addresses, so are 32 bits wide on a 32-bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      machine and 64 bits wide on a 64-bit machine. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  public Address   addressOfStackSlot(int slot)              { return getFP().addOffsetTo(slot * VM.getVM().getAddressSize()); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  /** Fetches the OopHandle at the requested slot */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  public OopHandle getOopHandleAt(int slot)                  { return addressOfStackSlot(slot).getOopHandleAt(0);              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  /** Fetches the OopHandle at the slot, adjusted for compiler frames */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // FIXME: looks like this is only used for compiled frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  //  public OopHandle getOopHandleAtAdjusted(MethodOop method, int slot) { return addressOfStackSlot(slot).getOopHandleAt(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // FIXME: Not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  //  public void  setOopHandleAt(int slot, OopHandle value) { addressOfStackSlot(slot).setOopHandleAt(0, value);              }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  /** Fetches the (Java) int at the requested slot */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  public int       getIntAt(int slot)                        { return addressOfStackSlot(slot).getJIntAt(0);                   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // FIXME: Not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // public void setIntAt(int slot, int value)               { addressOfStackSlot(slot).setJIntAt(0, value);                   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  /** returns the frame size in stack slots */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  public abstract long frameSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  /** Link (i.e., the pointer to the previous frame) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  public abstract Address getLink();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  //  public abstract void    setLink(Address addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  /** Return address */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  public abstract Address getSenderPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // FIXME: currently unimplementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  //  public abstract void    setSenderPC(Address addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  /** The frame's original SP, before any extension by an interpreted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      callee; used for packing debug info into vframeArray objects and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      vframeArray lookup. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  public abstract Address getUnextendedSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  /** Returns the stack pointer of the calling frame */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  public abstract Address getSenderSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  // Interpreter frames:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  public abstract Address addressOfInterpreterFrameLocals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  public Address addressOfInterpreterFrameLocal(int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return addressOfInterpreterFrameLocals().getAddressAt(0).addOffsetTo(-slot * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  //  void interpreter_frame_set_locals(intptr_t* locs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // NOTE that the accessor "addressOfInterpreterFrameBCX" has
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // necessarily been eliminated. The byte code pointer is inherently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // an interior pointer to a Method (the bytecodes follow the
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   286
  // Method data structure) and therefore acquisition of it in
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // this system can not be allowed. All accesses to interpreter frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // byte codes are via the byte code index (BCI).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  /** Byte code index. In the underlying frame, what is actually
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      stored is a byte code pointer (BCP), which is converted to a BCI
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      and back by the GC when methods are moved. In this system,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      interior pointers are not allowed, so we must make the access to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      the interpreter frame's BCI atomic with respect to GC. This may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      mean implementation with an underlying call through native code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      into the VM or a magic sequence in the compiler. (FIXME) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  public abstract int     getInterpreterFrameBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // public abstract void setInterpreterFrameBCI(int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // FIXME: elided for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  //  public abstract Address addressOfInterpreterCalleeReceiver(Symbol signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  /** Find receiver for an invoke when arguments are just pushed on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      stack (i.e., callee stack-frame is not setup) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  // FIXME: elided for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  //  public OopHandle getInterpreterCalleeReceiver(SymbolOop signature) { return addressOfInterpreterCalleeReceiver(signature).getOopHandleAt(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // Expression stack (may go up or down, direction == 1 or -1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  public abstract Address addressOfInterpreterFrameExpressionStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  public abstract int     getInterpreterFrameExpressionStackDirection();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  public Address addressOfInterpreterFrameExpressionStackSlot(int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    return addressOfInterpreterFrameExpressionStack().addOffsetTo(-slot * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  /** Top of expression stack */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  public abstract Address addressOfInterpreterFrameTOS();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  /** Expression stack from top down */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  public abstract Address addressOfInterpreterFrameTOSAt(int slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  /** FIXME: is this portable? */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  public int getInterpreterFrameExpressionStackSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    return (int) (1 + (getInterpreterFrameExpressionStackDirection() *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
                       (addressOfInterpreterFrameTOS().minus(addressOfInterpreterFrameExpressionStack()))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  public abstract Address getInterpreterFrameSenderSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  //  public abstract void    setInterpreterFrameSenderSP(Address senderSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  // BasicObjectLocks:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  public abstract BasicObjectLock interpreterFrameMonitorBegin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  public abstract BasicObjectLock interpreterFrameMonitorEnd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  /** NOTE: this returns a size in BYTES in this system! */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  public abstract int     interpreterFrameMonitorSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  public          BasicObjectLock nextMonitorInInterpreterFrame(BasicObjectLock cur) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    return new BasicObjectLock(cur.address().addOffsetTo(interpreterFrameMonitorSize()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  public          BasicObjectLock previousMonitorInInterpreterFrame(BasicObjectLock cur) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    return new BasicObjectLock(cur.address().addOffsetTo(-1 * interpreterFrameMonitorSize()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  // interpreter_frame_monitor_begin is higher in memory than interpreter_frame_monitor_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // Interpreter_frame_monitor_begin points to one element beyond the oldest one,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // interpreter_frame_monitor_end   points to the youngest one, or if there are none,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  //                                 it points to one beyond where the first element will be.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  // interpreter_frame_monitor_size  reports the allocation size of a monitor in the interpreter stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  //                                 this value is >= BasicObjectLock::size(), and may be rounded up
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  // FIXME: avoiding implementing this for now if possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  //  public void interpreter_frame_set_monitor_end(BasicObjectLock* value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  //  public void interpreter_frame_verify_monitor(BasicObjectLock* value) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  // Tells whether the current interpreter_frame frame pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  // corresponds to the old compiled/deoptimized fp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  // The receiver used to be a top level frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  // public boolean interpreter_frame_equals_unpacked_fp(intptr_t* fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // Method and constant pool cache:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  /** Current method */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  public abstract Address  addressOfInterpreterFrameMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  /** Current method */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  public Method            getInterpreterFrameMethod() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   375
    return (Method)Metadata.instantiateWrapperFor(addressOfInterpreterFrameMethod().getAddressAt(0));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  /** Current method */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  //  public void          setInterpreterFrameMethod(Method method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  /** Constant pool cache */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  public abstract Address  addressOfInterpreterFrameCPCache();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  /** Constant pool cache */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  public ConstantPoolCache getInterpreterFrameCPCache() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   386
    return (ConstantPoolCache) Metadata.instantiateWrapperFor(addressOfInterpreterFrameCPCache().getAddressAt(0));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // Entry frames:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  public abstract JavaCallWrapper getEntryFrameCallWrapper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  // FIXME: add
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  //  inline intptr_t* entry_frame_argument_at(int offset) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  /** Tells whether there is another chunk of Delta stack above */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  public boolean entryFrameIsFirst()            { return (getEntryFrameCallWrapper().getLastJavaSP() == null); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // Safepoints:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  protected abstract Address addressOfSavedOopResult();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  protected abstract Address addressOfSavedReceiver();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  public OopHandle getSavedOopResult() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    return addressOfSavedOopResult().getOopHandleAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  //  public void      setSavedOopResult(OopHandle obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  public OopHandle getSavedReceiver() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    return addressOfSavedReceiver().getOopHandleAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // FIXME: not yet implementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  //  public void      setSavedReceiver(OopHandle obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // Oop traversals:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  public void oopsInterpretedArgumentsDo(Symbol signature, boolean isStatic, AddressVisitor f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    ArgumentOopFinder finder = new ArgumentOopFinder(signature, isStatic, this, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    finder.oopsDo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  /** Conversion from an VMReg::Name to physical stack location */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  public Address oopMapRegToLocation(VMReg reg, RegisterMap regMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    VMReg stack0 = VM.getVM().getVMRegImplInfo().getStack0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    if (reg.lessThan(stack0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      // If it is passed in a register, it got spilled in the stub frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      return regMap.getLocation(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
      long spOffset = VM.getVM().getAddressSize() * reg.minus(stack0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      return getUnextendedSP().addOffsetTo(spOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  public void oopsDo(AddressVisitor oopVisitor, RegisterMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    if (isInterpretedFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      oopsInterpretedDo(oopVisitor, map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    } else if (isEntryFrame()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      oopsEntryDo(oopVisitor, map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    } else if (VM.getVM().getCodeCache().contains(getPC())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      oopsCodeBlobDo(oopVisitor, map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // Printing code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  public void printValue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    printValueOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  public void printValueOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    //    FIXME;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  public void print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    printOn(System.out);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  public void printOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    //    FIXME;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  public void interpreterFramePrintOn(PrintStream tty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    //    FIXME;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  // Get/set typed locals from a frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  // Respects platform dependent word-ordering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  // FIXME: avoiding implementing this for now if possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  // Currently these work only for interpreted frames.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  // Todo: make these work for compiled frames.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  //  oop     get_local_object(jint slot) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  //  jint    get_local_int   (jint slot) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  //  jlong   get_local_long  (jint slot) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  //  jfloat  get_local_float (jint slot) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  //  jdouble get_local_double(jint slot) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  //  void set_local_object(jint slot, oop     obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  //  void set_local_int   (jint slot, jint    i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  //  void set_local_long  (jint slot, jlong   l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  //  void set_local_float (jint slot, jfloat  f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  //  void set_local_double(jint slot, jdouble d);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  // FIXME: add safepoint code, oops_do, etc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // FIXME: NOT FINISHED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  //   /** Helper method for better factored code in frame::sender */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  //   private frame sender_for_entry_frame(RegisterMap* map)        { throw new RuntimeException("not yet implemented"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  //   private frame sender_for_interpreter_frame(RegisterMap* map)  { throw new RuntimeException("not yet implemented"); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // Oop iteration (FIXME: NOT FINISHED)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  private static class InterpVisitor implements OopMapVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    private AddressVisitor addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    public InterpVisitor(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      setAddressVisitor(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    public void setAddressVisitor(AddressVisitor addressVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      this.addressVisitor = addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    public void visitOopLocation(Address oopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      addressVisitor.visitAddress(oopAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    public void visitDerivedOopLocation(Address baseOopAddr, Address derivedOopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
        Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      } else if (VM.getVM().isServerCompiler() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
                 VM.getVM().useDerivedPointerTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        Assert.that(false, "FIXME: add derived pointer table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    public void visitValueLocation(Address valueAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   548
    public void visitNarrowOopLocation(Address compOopAddr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   549
      addressVisitor.visitCompOopAddress(compOopAddr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  private void oopsInterpretedDo(AddressVisitor oopVisitor, RegisterMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    Method m = getInterpreterFrameMethod();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    int bci  = getInterpreterFrameBCI();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    // FIXME: Seeing this sometimes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      if (bci < 0 || bci >= m.getCodeSize()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      //      Assert.that(VM.getVM().getUniverse().heap().isIn(m), "method must be valid oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      Assert.that((m.isNative() && (bci == 0)) || ((bci >= 0) && (bci < m.getCodeSize())), "invalid bci value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
    // Handle the monitor elements in the activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
    // FIXME: monitor information not yet exposed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
    //    for (
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
    //      BasicObjectLock* current = interpreter_frame_monitor_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    //      current < interpreter_frame_monitor_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    //      current = next_monitor_in_interpreter_frame(current)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    //    ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    //#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    //      interpreter_frame_verify_monitor(current);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    //#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    //      current->oops_do(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    // process fixed part
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   584
    // FIXME: these are no longer oops, so should anything be visitied?
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   585
    // oopVisitor.visitAddress(addressOfInterpreterFrameMethod());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   586
    // oopVisitor.visitAddress(addressOfInterpreterFrameCPCache());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    // FIXME: expose interpreterFrameMirrorOffset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    //    if (m.isNative() && m.isStatic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    //      oopVisitor.visitAddress(getFP().addOffsetTo(interpreterFrameMirrorOffset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    int maxLocals = (int) (m.isNative() ? m.getSizeOfParameters() : m.getMaxLocals());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    InterpreterFrameClosure blk = new InterpreterFrameClosure(this, maxLocals, (int) m.getMaxStack(), oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    // process locals & expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    OopMapCacheEntry mask = m.getMaskFor(bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    mask.iterateOop(blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    // process a callee's arguments if we are at a call site
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    // (i.e., if we are at an invoke bytecode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    if (map.getIncludeArgumentOops() && !m.isNative()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      BytecodeInvoke call = BytecodeInvoke.atCheck(m, bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      if (call != null && getInterpreterFrameExpressionStackSize() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
        // we are at a call site & the expression stack is not empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
        // => process callee's arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
        //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
        // Note: The expression stack can be empty if an exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
        //       occured during method resolution/execution. In all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
        //       cases we empty the expression stack completely be-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
        //       fore handling the exception (the exception handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
        //       code in the interpreter calls a blocking runtime
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
        //       routine which can cause this code to be executed).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
        //       (was bug gri 7/27/98)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
        oopsInterpretedArgumentsDo(call.signature(), call.isInvokestatic(), oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  private void oopsEntryDo      (AddressVisitor oopVisitor, RegisterMap regMap) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  private void oopsCodeBlobDo   (AddressVisitor oopVisitor, RegisterMap regMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    CodeBlob cb = VM.getVM().getCodeCache().findBlob(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
      Assert.that(cb != null, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    if (cb.getOopMaps() != null) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 13728
diff changeset
   627
      ImmutableOopMapSet.oopsDo(this, cb, regMap, oopVisitor, VM.getVM().isDebugging());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
      // FIXME: add in traversal of argument oops (skipping this for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
      // now until we have the other stuff tested)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    // FIXME: would add this in in non-debugging system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    // If we see an activation belonging to a non_entrant nmethod, we mark it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    //    if (cb->is_nmethod() && ((nmethod *)cb)->is_not_entrant()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    //      ((nmethod*)cb)->mark_as_seen_on_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  // FIXME: implement the above routines, plus add
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  // oops_interpreted_arguments_do and oops_compiled_arguments_do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
// Only used internally, to iterate through oop slots in interpreted
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
// frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
class InterpreterFrameClosure implements OffsetClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // Used for debugging this code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  private static final boolean DEBUG = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  private Frame fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  private AddressVisitor f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  private int maxLocals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  private int maxStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  InterpreterFrameClosure(Frame fr, int maxLocals, int maxStack, AddressVisitor f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    this.fr = fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    this.maxLocals = maxLocals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    this.maxStack = maxStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    this.f = f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  public void offsetDo(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      System.err.println("Visiting offset " + offset + ", maxLocals = " + maxLocals +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
                         " for frame " + fr + ", method " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
                         fr.getInterpreterFrameMethod().getMethodHolder().getName().asString() +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
                         fr.getInterpreterFrameMethod().getName().asString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    Address addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    if (offset < maxLocals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
      addr = fr.addressOfInterpreterFrameLocal(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
        Assert.that(AddressOps.gte(addr, fr.getSP()), "must be inside the frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
        System.err.println("  Visiting local at addr " + addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
      f.visitAddress(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      addr = fr.addressOfInterpreterFrameExpressionStackSlot(offset - maxLocals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
        System.err.println("  Address of expression stack slot: " + addr + ", TOS = " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
                           fr.addressOfInterpreterFrameTOS());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
      // In case of exceptions, the expression stack is invalid and the esp will be reset to express
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
      boolean inStack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
      if (fr.getInterpreterFrameExpressionStackDirection() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        inStack = AddressOps.lte(addr, fr.addressOfInterpreterFrameTOS());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
        inStack = AddressOps.gte(addr, fr.addressOfInterpreterFrameTOS());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
      if (inStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
          System.err.println("  In stack; visiting location.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
        f.visitAddress(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
      } else if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
        System.err.println("  *** WARNING: Address is out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
// Only used internally, to find arguments in interpreted frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
class ArgumentOopFinder extends SignatureInfo {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  private AddressVisitor f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  private int            offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  private boolean        isStatic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  private Frame          fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  protected void set(int size, int type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    offset -= size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    if (type == BasicType.getTObject() || type == BasicType.getTArray()) oopOffsetDo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  private void oopOffsetDo() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    f.visitAddress(fr.addressOfInterpreterFrameTOSAt(offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  public ArgumentOopFinder(Symbol signature, boolean isStatic, Frame fr, AddressVisitor f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    super(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    // compute size of arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    int argsSize = new ArgumentSizeComputer(signature).size() + (isStatic ? 0 : 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
      Assert.that(!fr.isInterpretedFrame() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
                  argsSize <= fr.getInterpreterFrameExpressionStackSize(), "args cannot be on stack anymore");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
    // initialize ArgumentOopFinder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    this.f        = f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
    this.fr       = fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
    this.offset   = argsSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    this.isStatic = isStatic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  public void oopsDo() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
    if (!isStatic) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      --offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      oopOffsetDo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    iterateParameters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
}