hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/x86/X86Frame.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2006 Sun Microsystems, Inc.  All Rights Reserved.
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.x86;
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.asm.x86.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.compiler.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.oops.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
/** Specialization of and implementation of abstract methods of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    Frame class for the x86 family of CPUs. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
public class X86Frame extends Frame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static final boolean DEBUG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    DEBUG = System.getProperty("sun.jvm.hotspot.runtime.x86.X86Frame.DEBUG") != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // All frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private static final int LINK_OFFSET                =  0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private static final int RETURN_ADDR_OFFSET         =  1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private static final int SENDER_SP_OFFSET           =  2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // Interpreter frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private static final int INTERPRETER_FRAME_MIRROR_OFFSET    =  2; // for native calls only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private static final int INTERPRETER_FRAME_SENDER_SP_OFFSET = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private static final int INTERPRETER_FRAME_LAST_SP_OFFSET   = INTERPRETER_FRAME_SENDER_SP_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  private static final int INTERPRETER_FRAME_METHOD_OFFSET    = INTERPRETER_FRAME_LAST_SP_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  private static       int INTERPRETER_FRAME_MDX_OFFSET;         // Non-core builds only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  private static       int INTERPRETER_FRAME_CACHE_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private static       int INTERPRETER_FRAME_LOCALS_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private static       int INTERPRETER_FRAME_BCX_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private static       int INTERPRETER_FRAME_INITIAL_SP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private static       int INTERPRETER_FRAME_MONITOR_BLOCK_TOP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private static       int INTERPRETER_FRAME_MONITOR_BLOCK_BOTTOM_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Entry frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private static final int ENTRY_FRAME_CALL_WRAPPER_OFFSET   =  2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // Native frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  private static final int NATIVE_FRAME_INITIAL_PARAM_OFFSET =  2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  private static synchronized void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    if (VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      INTERPRETER_FRAME_CACHE_OFFSET = INTERPRETER_FRAME_METHOD_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      INTERPRETER_FRAME_MDX_OFFSET   = INTERPRETER_FRAME_METHOD_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      INTERPRETER_FRAME_CACHE_OFFSET = INTERPRETER_FRAME_MDX_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    INTERPRETER_FRAME_LOCALS_OFFSET               = INTERPRETER_FRAME_CACHE_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    INTERPRETER_FRAME_BCX_OFFSET                  = INTERPRETER_FRAME_LOCALS_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    INTERPRETER_FRAME_INITIAL_SP_OFFSET           = INTERPRETER_FRAME_BCX_OFFSET - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    INTERPRETER_FRAME_MONITOR_BLOCK_TOP_OFFSET    = INTERPRETER_FRAME_INITIAL_SP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    INTERPRETER_FRAME_MONITOR_BLOCK_BOTTOM_OFFSET = INTERPRETER_FRAME_INITIAL_SP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // an additional field beyond sp and pc:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  Address raw_fp; // frame pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  private Address raw_unextendedSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  private X86Frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  private void adjustForDeopt() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    if ( pc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      // Look for a deopt pc and if it is deopted convert to original pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      CodeBlob cb = VM.getVM().getCodeCache().findBlob(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      if (cb != null && cb.isJavaMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
        NMethod nm = (NMethod) cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        if (pc.equals(nm.deoptBegin())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
          if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
            Assert.that(this.getUnextendedSP() != null, "null SP in Java frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
          // adjust pc if frame is deoptimized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
          pc = this.getUnextendedSP().getAddressAt(nm.origPCOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
          deoptimized = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  public X86Frame(Address raw_sp, Address raw_fp, Address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    this.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    this.raw_unextendedSP = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    this.raw_fp = raw_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    this.pc = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // Frame must be fully constructed before this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    adjustForDeopt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      System.out.println("X86Frame(sp, fp, pc): " + this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      dumpStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  public X86Frame(Address raw_sp, Address raw_fp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    this.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    this.raw_unextendedSP = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    this.raw_fp = raw_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    this.pc = raw_sp.getAddressAt(-1 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    // Frame must be fully constructed before this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    adjustForDeopt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      System.out.println("X86Frame(sp, fp): " + this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      dumpStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // This constructor should really take the unextended SP as an arg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // but then the constructor is ambiguous with constructor that takes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // a PC so take an int and convert it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public X86Frame(Address raw_sp, Address raw_fp, long extension) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    this.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    if (raw_sp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      this.raw_unextendedSP = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      this.raw_unextendedSP = raw_sp.addOffsetTo(extension);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    this.raw_fp = raw_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    this.pc = raw_sp.getAddressAt(-1 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    // Frame must be fully constructed before this call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    adjustForDeopt();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      System.out.println("X86Frame(sp, fp): " + this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      dumpStack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  public Object clone() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    X86Frame frame = new X86Frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    frame.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    frame.raw_unextendedSP = raw_unextendedSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    frame.raw_fp = raw_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    frame.raw_fp = raw_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    frame.pc = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    frame.deoptimized = deoptimized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  public boolean equals(Object arg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    if (arg == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    if (!(arg instanceof X86Frame)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    X86Frame other = (X86Frame) arg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    return (AddressOps.equal(getSP(), other.getSP()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
            AddressOps.equal(getUnextendedSP(), other.getUnextendedSP()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
            AddressOps.equal(getFP(), other.getFP()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
            AddressOps.equal(getPC(), other.getPC()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  public int hashCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (raw_sp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    return raw_sp.hashCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    return "sp: " + (getSP() == null? "null" : getSP().toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
         ", unextendedSP: " + (getUnextendedSP() == null? "null" : getUnextendedSP().toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
         ", fp: " + (getFP() == null? "null" : getFP().toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
         ", pc: " + (pc == null? "null" : pc.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // accessors for the instance variables
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  public Address getFP() { return raw_fp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  public Address getSP() { return raw_sp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  public Address getID() { return raw_sp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // FIXME: not implemented yet (should be done for Solaris/X86)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  public boolean isSignalHandlerFrameDbg() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  public int     getSignalNumberDbg()      { return 0;     }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  public String  getSignalNameDbg()        { return null;  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  public boolean isInterpretedFrameValid() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      Assert.that(isInterpretedFrame(), "Not an interpreted frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    // These are reasonable sanity checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    if (getFP() == null || getFP().andWithMask(0x3) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    if (getSP() == null || getSP().andWithMask(0x3) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    if (getFP().addOffsetTo(INTERPRETER_FRAME_INITIAL_SP_OFFSET * VM.getVM().getAddressSize()).lessThan(getSP())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    // These are hacks to keep us out of trouble.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    // The problem with these is that they mask other problems
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    if (getFP().lessThanOrEqual(getSP())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      // this attempts to deal with unsigned comparison above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    if (getFP().minus(getSP()) > 4096 * VM.getVM().getAddressSize()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      // stack frames shouldn't be large.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // FIXME: not applicable in current system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  //  void    patch_pc(Thread* thread, address pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  public Frame sender(RegisterMap regMap, CodeBlob cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    X86RegisterMap map = (X86RegisterMap) regMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // Default is we done have to follow them. The sender_for_xxx will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    // update it accordingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    map.setIncludeArgumentOops(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (isEntryFrame())       return senderForEntryFrame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    if (isInterpretedFrame()) return senderForInterpreterFrame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      if(cb == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        cb = VM.getVM().getCodeCache().findBlob(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
          Assert.that(cb.equals(VM.getVM().getCodeCache().findBlob(getPC())), "Must be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      if (cb != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
         return senderForCompiledFrame(map, cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    // Must be native-compiled frame, i.e. the marshaling code for native
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    // methods that exists in the core system.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    return new X86Frame(getSenderSP(), getLink(), getSenderPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  private Frame senderForEntryFrame(X86RegisterMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    // Java frame called from C; skip all C frames and return top C
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    // frame of that chunk as the sender
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    X86JavaCallWrapper jcw = (X86JavaCallWrapper) getEntryFrameCallWrapper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      Assert.that(!entryFrameIsFirst(), "next Java fp must be non zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      Assert.that(jcw.getLastJavaSP().greaterThan(getSP()), "must be above this frame on stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    X86Frame fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    if (jcw.getLastJavaPC() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      fr = new X86Frame(jcw.getLastJavaSP(), jcw.getLastJavaFP(), jcw.getLastJavaPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      fr = new X86Frame(jcw.getLastJavaSP(), jcw.getLastJavaFP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    map.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      Assert.that(map.getIncludeArgumentOops(), "should be set by clear");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return fr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  private Frame senderForInterpreterFrame(X86RegisterMap map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    Address unextendedSP = addressOfStackSlot(INTERPRETER_FRAME_SENDER_SP_OFFSET).getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    Address sp = addressOfStackSlot(SENDER_SP_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    // We do not need to update the callee-save register mapping because above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    // us is either another interpreter frame or a converter-frame, but never
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    // directly a compiled frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    // 11/24/04 SFG. With the removal of adapter frames this is no longer true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    // However c2 no longer uses callee save register for java calls so there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // are no callee register to find.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    return new X86Frame(sp, getLink(), unextendedSP.minus(sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  private Frame senderForCompiledFrame(X86RegisterMap map, CodeBlob cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    // NOTE: some of this code is (unfortunately) duplicated in X86CurrentFrameGuess
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    // frame owned by optimizing compiler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    Address        sender_sp = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
      sender_sp        = addressOfStackSlot(SENDER_SP_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
        Assert.that(cb.getFrameSize() >= 0, "Compiled by Compiler1: do not use");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      sender_sp = getUnextendedSP().addOffsetTo(cb.getFrameSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    // On Intel the return_address is always the word on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    Address sender_pc = sender_sp.getAddressAt(-1 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    if (map.getUpdateMap() && cb.getOopMaps() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      OopMapSet.updateRegisterMap(this, cb, map, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      // Move this here for C1 and collecting oops in arguments (According to Rene)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      map.setIncludeArgumentOops(cb.callerMustGCArguments(map.getThread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    Address saved_fp = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      saved_fp = getFP().getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    } else if (VM.getVM().isServerCompiler() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
               (VM.getVM().getInterpreter().contains(sender_pc) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
               VM.getVM().getStubRoutines().returnsToCallStub(sender_pc))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      // C2 prologue saves EBP in the usual place.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
      // however only use it if the sender had link infomration in it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      saved_fp = sender_sp.getAddressAt(-2 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    return new X86Frame(sender_sp, saved_fp, sender_pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  protected boolean hasSenderPD() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    // Check for null ebp? Need to do some tests.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  public long frameSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    return (getSenderSP().minus(getSP()) / VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  public Address getLink() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    return addressOfStackSlot(LINK_OFFSET).getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // FIXME: not implementable yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  //inline void      frame::set_link(intptr_t* addr)  { *(intptr_t **)addr_at(link_offset) = addr; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  public Address getUnextendedSP() { return raw_unextendedSP; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  // Return address:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  public Address getSenderPCAddr() { return addressOfStackSlot(RETURN_ADDR_OFFSET); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  public Address getSenderPC()     { return getSenderPCAddr().getAddressAt(0);      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // return address of param, zero origin index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  public Address getNativeParamAddr(int idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    return addressOfStackSlot(NATIVE_FRAME_INITIAL_PARAM_OFFSET + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  public Address getSenderSP()     { return addressOfStackSlot(SENDER_SP_OFFSET); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  public Address compiledArgumentToLocationPD(VMReg reg, RegisterMap regMap, int argSize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    if (VM.getVM().isCore() || VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      throw new RuntimeException("Should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    return oopMapRegToLocation(reg, regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  public Address addressOfInterpreterFrameLocals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    return addressOfStackSlot(INTERPRETER_FRAME_LOCALS_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  private Address addressOfInterpreterFrameBCX() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    return addressOfStackSlot(INTERPRETER_FRAME_BCX_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  public int getInterpreterFrameBCI() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    // FIXME: this is not atomic with respect to GC and is unsuitable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    // for use in a non-debugging, or reflective, system. Need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    // figure out how to express this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    Address bcp = addressOfInterpreterFrameBCX().getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    OopHandle methodHandle = addressOfInterpreterFrameMethod().getOopHandleAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    Method method = (Method) VM.getVM().getObjectHeap().newOop(methodHandle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    return bcpToBci(bcp, method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  public Address addressOfInterpreterFrameMDX() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    return addressOfStackSlot(INTERPRETER_FRAME_MDX_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  //inline int frame::interpreter_frame_monitor_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  //  return BasicObjectLock::size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  // expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  // (the max_stack arguments are used by the GC; see class FrameClosure)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  public Address addressOfInterpreterFrameExpressionStack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    Address monitorEnd = interpreterFrameMonitorEnd().address();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    return monitorEnd.addOffsetTo(-1 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  public int getInterpreterFrameExpressionStackDirection() { return -1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // top of expression stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  public Address addressOfInterpreterFrameTOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    return getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  /** Expression stack from top down */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  public Address addressOfInterpreterFrameTOSAt(int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    return addressOfInterpreterFrameTOS().addOffsetTo(slot * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  public Address getInterpreterFrameSenderSP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      Assert.that(isInterpretedFrame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    return addressOfStackSlot(INTERPRETER_FRAME_SENDER_SP_OFFSET).getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // Monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  public BasicObjectLock interpreterFrameMonitorBegin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    return new BasicObjectLock(addressOfStackSlot(INTERPRETER_FRAME_MONITOR_BLOCK_BOTTOM_OFFSET));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  public BasicObjectLock interpreterFrameMonitorEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    Address result = addressOfStackSlot(INTERPRETER_FRAME_MONITOR_BLOCK_TOP_OFFSET).getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
      // make sure the pointer points inside the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
      Assert.that(AddressOps.gt(getFP(), result), "result must <  than frame pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      Assert.that(AddressOps.lte(getSP(), result), "result must >= than stack pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    return new BasicObjectLock(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  public int interpreterFrameMonitorSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    return BasicObjectLock.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  // Method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  public Address addressOfInterpreterFrameMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    return addressOfStackSlot(INTERPRETER_FRAME_METHOD_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // Constant pool cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  public Address addressOfInterpreterFrameCPCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    return addressOfStackSlot(INTERPRETER_FRAME_CACHE_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  // Entry frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  public JavaCallWrapper getEntryFrameCallWrapper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    return new X86JavaCallWrapper(addressOfStackSlot(ENTRY_FRAME_CALL_WRAPPER_OFFSET).getAddressAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  protected Address addressOfSavedOopResult() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    // offset is 2 for compiler2 and 3 for compiler1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    return getSP().addOffsetTo((VM.getVM().isClientCompiler() ? 2 : 3) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
                               VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  protected Address addressOfSavedReceiver() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    return getSP().addOffsetTo(-4 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  private void dumpStack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    if (getFP() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
      for (Address addr = getSP().addOffsetTo(-5 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
           AddressOps.lte(addr, getFP().addOffsetTo(5 * VM.getVM().getAddressSize()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
           addr = addr.addOffsetTo(VM.getVM().getAddressSize())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
        System.out.println(addr + ": " + addr.getAddressAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      for (Address addr = getSP().addOffsetTo(-5 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
           AddressOps.lte(addr, getSP().addOffsetTo(20 * VM.getVM().getAddressSize()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
           addr = addr.addOffsetTo(VM.getVM().getAddressSize())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
        System.out.println(addr + ": " + addr.getAddressAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
}