hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/sparc/SPARCFrame.java
author swamyv
Tue, 24 Jun 2008 21:37:10 -0700
changeset 764 67578bc37423
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6620329: jstack prints double native methods on Solaris/sparc Summary: Fixed stack walking code in sparc to start frame walk from last_java_sp. Reviewed-by: sgoldman
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 2000-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.sparc;
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.asm.sparc.*;
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.debugger.cdbg.*;
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.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
import sun.jvm.hotspot.runtime.posix.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
/** Specialization of and implementation of abstract methods of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    Frame class for the SPARC CPU. (FIXME: this is as quick a port as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    possible to get things running; will have to do a better job right
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    away.) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
public class SPARCFrame extends Frame {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // The pc value is the raw return address, plus 8 (pcReturnOffset()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // the value of sp and youngerSP that is stored in this object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // is always, always, always the value that would be found in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // register (or window save area) while the target VM was executing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // The caller of the constructor will alwasy know if has a biased or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // unbiased version of the stack pointer and can convert real (unbiased)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // value via a helper routine we supply.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Whenever we return sp or youngerSP values we do not return the internal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // value but the real (unbiased) pointers since these are the true, usable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // memory addresses. The outlier case is that of the null pointer. The current
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // mechanism makes null pointers always look null whether biased or not.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // This seems to cause no problems. In theory null real pointers could be biased
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // just like other values however this has impact on things like addOffsetTo()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // to be able to take an Address that represents null and add an offset to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // This doesn't seem worth the bother and the impact on the rest of the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // when the biasSP and unbiasSP can make this invisible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // The general rule in this code is that when we have a variable like FP, youngerSP, SP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // that these are real (i.e. unbiased) addresses. The instance variables in a Frame are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // always raw values. The other rule is that it except for the frame constructors and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // the unBiasSP helper all methods accept parameters that are real addresses.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  /** Optional next-younger SP (used to locate O7, the PC) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  private Address raw_youngerSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  /** Intepreter adjusts the stack pointer to make all locals contiguous */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  private long    interpreterSPAdjustmentOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  /** Number of stack entries for longs */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  private static final int WORDS_PER_LONG = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  /** Normal SPARC return is 2 words past PC */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  public static final int PC_RETURN_OFFSET = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  /** Size of each block, in order of increasing address */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  public static final int REGISTER_SAVE_WORDS   = 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // FIXME: read these from the remote process
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  //#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  //    callee_aggregate_return_pointer_words        =  0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  //#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  //    callee_aggregate_return_pointer_words        =  1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public static final int CALLEE_AGGREGATE_RETURN_POINTER_WORDS     = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public static final int CALLEE_REGISTER_ARGUMENT_SAVE_AREA_WORDS  = 6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // offset of each block, in order of increasing address:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  public static final int REGISTER_SAVE_WORDS_SP_OFFSET             = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public static final int CALLEE_AGGREGATE_RETURN_POINTER_SP_OFFSET = REGISTER_SAVE_WORDS_SP_OFFSET + REGISTER_SAVE_WORDS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  public static final int CALLEE_REGISTER_ARGUMENT_SAVE_AREA_SP_OFFSET = (CALLEE_AGGREGATE_RETURN_POINTER_SP_OFFSET +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                                                          CALLEE_AGGREGATE_RETURN_POINTER_WORDS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  public static final int MEMORY_PARAMETER_WORD_SP_OFFSET              = (CALLEE_REGISTER_ARGUMENT_SAVE_AREA_SP_OFFSET +
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
                                                                          CALLEE_REGISTER_ARGUMENT_SAVE_AREA_WORDS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public static final int VARARGS_OFFSET                               = MEMORY_PARAMETER_WORD_SP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.runtime.sparc.SPARCFrame.DEBUG") != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public static Address unBiasSP(Address raw_sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (raw_sp != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      return raw_sp.addOffsetTo(VM.getVM().getStackBias());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  public static Address biasSP(Address real_sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    if (real_sp != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        System.out.println("biasing realsp: " + real_sp + " biased: " + real_sp.addOffsetTo(-VM.getVM().getStackBias()) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      return real_sp.addOffsetTo(-VM.getVM().getStackBias());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        System.out.println("biasing null realsp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // This is used to find the younger sp for a thread thatn has stopped but hasn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // conveniently told us the information where we can find the pc or the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // containing the pc that corresponds to last_java_sp. This method will walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // the frames trying to find the frame which we contains the data we need.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public static Address findYoungerSP(Address top, Address find) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    // top and find are unBiased sp values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // we return an unBiased value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    Address findRaw = biasSP(find);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (top == null || find == null || findRaw == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      throw new RuntimeException("bad values for findYoungerSP top: " + top + " find: " + find);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    // It would be unusual to find more than 20 native frames before we find the java frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    // we are looking for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    final int maxFrames = 20;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    int count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    Address search = top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    Address next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    Address pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      System.out.println("findYoungerSP top: " + top + " find: " + find + " findRaw: " + findRaw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    while ( count != maxFrames && search != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      next = search.getAddressAt(SPARCRegisters.I6.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      pc = search.getAddressAt(SPARCRegisters.I7.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        System.out.println("findYoungerSP next: " + next + " pc: " + pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      if (next.equals(findRaw)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
        return search;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      search = unBiasSP(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      System.out.println("findYoungerSP: never found younger, top: " + top + " find: " + find);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  public Address getSP()              {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      System.out.println("getSP raw: " + raw_sp + " unbiased: " + unBiasSP(raw_sp));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return  unBiasSP(raw_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  public Address getID()              {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  public Address getYoungerSP()       {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      System.out.println("getYoungerSP: " + raw_youngerSP + " unbiased: " + unBiasSP(raw_youngerSP));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return unBiasSP(raw_youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  /** This constructor relies on the fact that the creator of a frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      has flushed register windows which the frame will refer to, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      that those register windows will not be reloaded until the frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      is done reading and writing the stack.  Moreover, if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      "younger_pc" argument points into the register save area of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      next younger frame (though it need not), the register window for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      that next younger frame must also stay flushed.  (The caller is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      responsible for ensuring this.) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  public SPARCFrame(Address raw_sp, Address raw_youngerSP, boolean youngerFrameIsInterpreted) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      System.out.println("Constructing frame(1) raw_sp: " + raw_sp + " raw_youngerSP: " + raw_youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      Assert.that((unBiasSP(raw_sp).andWithMask(VM.getVM().getAddressSize() - 1) == null),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
                   "Expected raw sp likely got real sp, value was " + raw_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      if (raw_youngerSP != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        Assert.that((unBiasSP(raw_youngerSP).andWithMask(VM.getVM().getAddressSize() - 1) == null),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
                    "Expected raw youngerSP likely got real youngerSP, value was " + raw_youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    this.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    this.raw_youngerSP = raw_youngerSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    if (raw_youngerSP == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
      // make a deficient frame which doesn't know where its PC is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      pc = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      Address youngerSP = unBiasSP(raw_youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
      pc = youngerSP.getAddressAt(SPARCRegisters.I7.spOffsetInSavedWindow()).addOffsetTo(PC_RETURN_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        Assert.that(youngerSP.getAddressAt(SPARCRegisters.FP.spOffsetInSavedWindow()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
                    equals(raw_sp),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
                    "youngerSP must be valid");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    if (youngerFrameIsInterpreted) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      long IsavedSP = SPARCRegisters.IsavedSP.spOffsetInSavedWindow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      // compute adjustment to this frame's SP made by its interpreted callee
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      interpreterSPAdjustmentOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
      Address savedSP = unBiasSP(getYoungerSP().getAddressAt(IsavedSP));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      if (savedSP == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        if ( DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
          System.out.println("WARNING: IsavedSP was null for frame " + this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
        interpreterSPAdjustmentOffset = savedSP.minus(getSP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      interpreterSPAdjustmentOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    if ( pc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      // Look for a deopt pc and if it is deopted convert to original pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      CodeBlob cb = VM.getVM().getCodeCache().findBlob(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      if (cb != null && cb.isJavaMethod()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        NMethod nm = (NMethod) cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        if (pc.equals(nm.deoptBegin())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
          // adjust pc if frame is deoptimized.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
          pc = this.getUnextendedSP().getAddressAt(nm.origPCOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
          deoptimized = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  /** Make a deficient frame which doesn't know where its PC is (note
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      no youngerSP argument) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  public SPARCFrame(Address raw_sp, Address pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      System.out.println("Constructing frame(2) raw_sp: " + raw_sp );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    this.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      Assert.that((unBiasSP(raw_sp).andWithMask(VM.getVM().getAddressSize() - 1) == null),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
                   "Expected raw sp likely got real sp, value was " + raw_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    raw_youngerSP = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    this.pc = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    interpreterSPAdjustmentOffset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  /** Only used internally */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  private SPARCFrame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  public Object clone() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    SPARCFrame frame = new SPARCFrame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    frame.raw_sp = raw_sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    frame.pc = pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    frame.raw_youngerSP = raw_youngerSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    frame.interpreterSPAdjustmentOffset = interpreterSPAdjustmentOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    frame.deoptimized = deoptimized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  public boolean equals(Object arg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    if (arg == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    if (!(arg instanceof SPARCFrame)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    SPARCFrame other = (SPARCFrame) arg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    return (AddressOps.equal(getSP(), other.getSP()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
            AddressOps.equal(getFP(), other.getFP()) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
            AddressOps.equal(getPC(), other.getPC()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  public int hashCode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    if (raw_sp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    return raw_sp.hashCode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  public String toString() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    Address fp = getFP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    Address sp = getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    Address youngerSP = getYoungerSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    return "sp: " + (sp == null? "null" : sp.toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
         ", younger_sp: " + (youngerSP == null? "null" : youngerSP.toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
         ", fp: " + (fp == null? "null" : fp.toString()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
         ", pc: " + (pc == null? "null" : pc.toString());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  /** <P> Identifies a signal handler frame on the stack. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      <P> There are a few different algorithms for doing this, and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      they vary from platform to platform. For example, based on a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      conversation with Dave Dice, Solaris/x86 will be substantially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      simpler to handle than Solaris/SPARC because the signal handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      frame can be identified because of a program counter == -1. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      <P> The dbx group provided code and advice on these topics; the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      code below evolved from theirs, but is not correct/robust.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      Without going into too many details, it seems that looking for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      the incoming argument to the sigacthandler frame (which is what
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      this code identifies) is not guaranteed to be stable across
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      versions of Solaris, since that function is supplied by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      libthread and is not guaranteed not to clobber I2 before it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      calls __sighndlr later. From discussions, it sounds like a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      robust algorithm which wouldn't require traversal of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      ucontext chain (used by dbx, but which Dave Dice thinks isn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      robust in the face of libthread -- need to follow up) would be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      to be able to properly identify the __sighndlr frame, then get
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      I2 and treat that as a ucontext. To identify __sighndlr we would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      need to look up that symbol in the remote process and look for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      program counter within a certain (small) distance. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      <P> If the underlying Debugger supports CDebugger interface, we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      take the approach of __sighnldr symbol. This approach is more robust
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      compared to the original hueristic approach. Of course, if there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      is no CDebugger support, we fallback to the hueristic approach. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
      <P> The current implementation seems to work with Solaris 2.8.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
      A nice property of this system is that if we find a core file
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
      this algorithm doesn't work on, we can change the code and try
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      again, so I'm putting this in as the current mechanism for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      finding signal handler frames on Solaris/SPARC. </P> */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  public boolean isSignalHandlerFrameDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    CDebugger cdbg = VM.getVM().getDebugger().getCDebugger();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    if (cdbg != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
      LoadObject dso = cdbg.loadObjectContainingPC(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      if (dso != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
        ClosestSymbol cs = dso.closestSymbolToPC(getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
        if (cs != null && cs.getName().equals("__sighndlr")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      if (getYoungerSP() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
        //      System.err.println("  SPARCFrame.isSignalHandlerFrameDbg: youngerSP = " + getYoungerSP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
      Address i2 = getSP().getAddressAt(SPARCRegisters.I2.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      if (i2 == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      Address fp = getFP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      // My (mistaken) understanding of the dbx group's code was that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
      // the signal handler frame could be identified by testing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      // incoming argument to see whether it was a certain distance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      // below the frame pointer; in fact, their code did substantially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      // more than this (traversal of the ucontext chain, which this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      // code can't do because the topmost ucontext is not currently
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
      // available via the proc_service APIs in dbx). The current code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      // appears to work, but is probably not robust.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      int MAJOR_HACK_OFFSET = 8;  // Difference between expected location of the ucontext and reality
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      // System.err.println("  SPARCFrame.isSignalHandlerFrameDbg: I2 = " + i2 +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      //                          ", fp = " + fp + ", raw_youngerSP = " + getYoungerSP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
      boolean res = i2.equals(fp.addOffsetTo(VM.getVM().getAddressSize() * (REGISTER_SAVE_WORDS + MAJOR_HACK_OFFSET)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      if (res) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        // Qualify this with another test (FIXME: this is a gross heuristic found while testing)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
        Address sigInfoAddr = getSP().getAddressAt(SPARCRegisters.I5.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
        if (sigInfoAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
          System.err.println("Frame with fp = " + fp + " looked like a signal handler frame but wasn't");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
          res = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  public int getSignalNumberDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    // From looking at the stack trace in dbx, it looks like the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    // siginfo* comes into sigacthandler in I5. It would be much more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    // robust to look at the __sighndlr frame instead, but we can't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    // currently identify that frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    Address sigInfoAddr = getSP().getAddressAt(SPARCRegisters.I5.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // Read si_signo out of siginfo*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    return (int) sigInfoAddr.getCIntegerAt(0, 4, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  public String getSignalNameDbg() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    return POSIXSignals.getSignalName(getSignalNumberDbg());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  public boolean isInterpretedFrameValid() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
      Assert.that(isInterpretedFrame(), "Not an interpreted frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    // These are reasonable sanity checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    if (getFP() == null || (getFP().andWithMask(2 * VM.getVM().getAddressSize() - 1)) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    if (getSP() == null || (getSP().andWithMask(2 * VM.getVM().getAddressSize() - 1)) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    if (getFP().addOffsetTo(INTERPRETER_FRAME_VM_LOCAL_WORDS * VM.getVM().getAddressSize()).lessThan(getSP())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   425
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   426
    OopHandle methodHandle = addressOfInterpreterFrameMethod().getOopHandleAt(0);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   427
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   428
    if (VM.getVM().getObjectHeap().isValidMethod(methodHandle) == false) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   429
      return false;
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   430
    }
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   431
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    // These are hacks to keep us out of trouble.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    // The problem with these is that they mask other problems
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    if (getFP().lessThanOrEqual(getSP())) {        // this attempts to deal with unsigned comparison above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    if (getFP().minus(getSP()) > 4096 * VM.getVM().getAddressSize()) {  // stack frames shouldn't be large.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    // FIXME: this is not atomic with respect to GC and is unsuitable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    // for use in a non-debugging, or reflective, system. Need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    // figure out how to express this.
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   443
    Address bcx =  addressOfInterpreterFrameBCX().getAddressAt(0);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   444
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   445
    Method method;
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   446
    try {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   447
       method = (Method) VM.getVM().getObjectHeap().newOop(methodHandle);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   448
    } catch (UnknownOopException ex) {
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   449
       return false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    }
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   451
    int  bci = bcpToBci(bcx, method);
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   452
    //validate bci
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   453
    if (bci < 0) return false;
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   454
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  // Accessors:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  /** Accessors */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  public long frameSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    return (getSenderSP().minus(getSP()) / VM.getVM().getAddressSize());
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 Address getLink() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    return unBiasSP(getFP().getAddressAt(SPARCRegisters.FP.spOffsetInSavedWindow()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // FIXME: not implementable yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  //  public void setLink(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  //    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  //      Assert.that(getLink().equals(addr), "frame nesting is controlled by hardware");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  public Frame sender(RegisterMap regMap, CodeBlob cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    SPARCRegisterMap map = (SPARCRegisterMap) regMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    // Default is we don't have to follow them. The sender_for_xxx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    // will update it accordingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    map.setIncludeArgumentOops(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   490
    if (isEntryFrame()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
      return senderForEntryFrame(map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    Address youngerSP = getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    Address sp        = getSenderSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    boolean isInterpreted = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    // FIXME: this is a hack to get stackwalking to work in the face
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    // of a signal like a SEGV. For debugging purposes it's important
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    // that (a) we are able to traverse the stack if we take a signal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    // and (b) that we get the correct program counter in this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    // situation. If we are not using alternate signal stacks then (a)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    // seems to work all the time (on SPARC), but (b) is violated for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    // the frame just below the signal handler.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
    // The mechanism for finding the ucontext is not robust. In
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    // addition, we may find that we need to be able to fetch more
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    // registers from the ucontext than just the program counter,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    // since the register windows on the stack are "stale". This will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    // require substantial restructuring of this frame code, so has
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    // been avoided for now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    // It is difficult to find a clean solution for mixing debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    // situations with VM frame traversal. One could consider
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    // implementing generic frame traversal in the dbx style and only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
    // using the VM's stack walking mechanism on a per-frame basis,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    // for example to traverse Java-level activations in a compiled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    // frame. However, this will probably not interact well with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    // mechanism for finding oops on the stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
    if (VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      // If we are a signal handler frame, use a trick: make the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      // youngerSP of the caller frame point to the top of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      // ucontext's contained register set. This should allow fetching
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
      // of the registers for the frame just below the signal handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      // frame in the usual fashion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      if (isSignalHandlerFrameDbg()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
          System.out.println("SPARCFrame.sender: found signal handler frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
        // Try to give a valid SP and PC for a "deficient frame" since
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
        // we don't have a real register save area; making this class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        // work by reading its information from a ucontext as well as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        // a register save area is a major undertaking and has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
        // deferred for now. It is very important that the PC is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
        // correct, which is why we don't just fall through to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
        // other code (which would read the PC from the stale register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
        // window and thereby fail to get the actual location of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        // fault).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        long offset = getMContextAreaOffsetInUContext();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        Address fp = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
        // System.out.println("  FP: " + fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
        fp = fp.addOffsetTo(getUContextOffset() + getMContextAreaOffsetInUContext());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
        // System.out.println("  start of mcontext: " + fp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
        // FIXME: put these elsewhere. These are the register numbers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
        // in /usr/include/sys/regset.h. They might belong in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
        // SPARCReigsters.java, but we currently don't have that list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        // of numbers in the SA code (because all of the registers are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
        // listed as instances of SPARCRegister) and it appears that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
        // our numbering of the registers and this one don't match up.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        int PC_OFFSET_IN_GREGSET = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
        int SP_OFFSET_IN_GREGSET = 17;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        raw_sp = fp.getAddressAt(VM.getVM().getAddressSize() * SP_OFFSET_IN_GREGSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
        Address pc = fp.getAddressAt(VM.getVM().getAddressSize() * PC_OFFSET_IN_GREGSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        return new SPARCFrame(raw_sp, pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      // Note:  The version of this operation on any platform with callee-save
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      //        registers must update the register map (if not null).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      //        In order to do this correctly, the various subtypes of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      //        of frame (interpreted, compiled, glue, native),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      //        must be distinguished.  There is no need on SPARC for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
      //        such distinctions, because all callee-save registers are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      //        preserved for all frames via SPARC-specific mechanisms.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      //        *** HOWEVER, *** if and when we make any floating-point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
      //        registers callee-saved, then we will have to copy over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      //        the RegisterMap update logic from the Intel code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
      // The constructor of the sender must know whether this frame is interpreted so it can set the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
      // sender's _interpreter_sp_adjustment field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
      if (VM.getVM().getInterpreter().contains(pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
        isInterpreted = true;
764
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   580
        map.makeIntegerRegsUnsaved();
67578bc37423 6620329: jstack prints double native methods on Solaris/sparc
swamyv
parents: 1
diff changeset
   581
        map.shiftWindow(sp, youngerSP);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
        // Find a CodeBlob containing this frame's pc or elide the lookup and use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
        // supplied blob which is already known to be associated with this frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
        cb = VM.getVM().getCodeCache().findBlob(pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
        if (cb != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
          if (cb.callerMustGCArguments(map.getThread())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
            map.setIncludeArgumentOops(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
          // Update the location of all implicitly saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
          // as the address of these registers in the register save
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
          // area (for %o registers we use the address of the %i
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
          // register in the next younger frame)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
          map.shiftWindow(sp, youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
          if (map.getUpdateMap()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
            if (cb.getOopMaps() != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
              OopMapSet.updateRegisterMap(this, cb, map, VM.getVM().isDebugging());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    } // #ifndef CORE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    return new SPARCFrame(biasSP(sp), biasSP(youngerSP), isInterpreted);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  protected boolean hasSenderPD() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      // FIXME: should not happen!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      if (getSP() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
      if ( unBiasSP(getSP().getAddressAt(SPARCRegisters.FP.spOffsetInSavedWindow())) == null ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    } catch (RuntimeException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
        System.out.println("Bad frame " + this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      throw e;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  // Return address:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
  public Address getSenderPC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    return addressOfI7().getAddressAt(0).addOffsetTo(PC_RETURN_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  // FIXME: currently unimplementable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  // inline void     frame::set_sender_pc(address addr) { *I7_addr() = addr - pc_return_offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  public Address getUnextendedSP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    return getSP().addOffsetTo(interpreterSPAdjustmentOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  public Address getSenderSP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    return getFP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
  /** Given the next-younger sp for a given frame's sp, compute the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      frame. We need the next-younger sp, because its register save
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
      area holds the flushed copy of its I7, which is the PC of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      frame we are interested in. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
  public SPARCFrame afterSave() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    return new SPARCFrame(biasSP(getYoungerSP()), null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  /** Accessors for the instance variables */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  public Address getFP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    Address sp = getSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    if (sp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
      System.out.println("SPARCFrame.getFP(): sp == null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    Address fpAddr = sp.addOffsetTo(SPARCRegisters.FP.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
      Address fp = unBiasSP(fpAddr.getAddressAt(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
      if (fp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
        System.out.println("SPARCFrame.getFP(): fp == null (&fp == " + fpAddr + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      return fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    } catch (RuntimeException e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      System.out.println("SPARCFrame.getFP(): is bad (&fp == " + fpAddr + " sp = " + sp + ")");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  private Address addressOfFPSlot(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
    return getFP().addOffsetTo(index * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  // FIXME: temporarily elided
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  //  // All frames
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  //  intptr_t*  fp_addr_at(int index) const   { return &fp()[index];    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  //  intptr_t*  sp_addr_at(int index) const   { return &sp()[index];    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  //  intptr_t    fp_at(     int index) const   { return *fp_addr_at(index); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  //  intptr_t    sp_at(     int index) const   { return *sp_addr_at(index); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  // private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  //  inline address* I7_addr() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  //  inline address* O7_addr() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  //  inline address* I0_addr() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  //  inline address* O0_addr() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  // public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  //  // access to SPARC arguments and argument registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  //  intptr_t*     register_addr(Register reg) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  //    return sp_addr_at(reg.sp_offset_in_saved_window());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  //  intptr_t* memory_param_addr(int param_ix, bool is_in) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  //    int offset = callee_register_argument_save_area_sp_offset + param_ix;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  //    if (is_in)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  //      return fp_addr_at(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  //    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  //      return sp_addr_at(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  //  intptr_t*        param_addr(int param_ix, bool is_in) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  //    if (param_ix >= callee_register_argument_save_area_words)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  //      return memory_param_addr(param_ix, is_in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  //    else if (is_in)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  //      return register_addr(Argument(param_ix, true).as_register());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  //    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  //      // the registers are stored in the next younger frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
  //      // %%% is this really necessary?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  //      frame next_younger = after_save();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  //      return next_younger.register_addr(Argument(param_ix, true).as_register());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  //    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  // Interpreter frames:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
  /** 2 words, also used to save float regs across  calls to C */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  public static final int INTERPRETER_FRAME_D_SCRATCH_FP_OFFSET           = -2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
  public static final int INTERPRETER_FRAME_L_SCRATCH_FP_OFFSET           = -4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  /** For native calls only */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  public static final int INTERPRETER_FRAME_PADDING_OFFSET                = -5;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  /** For native calls only */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  public static final int INTERPRETER_FRAME_MIRROR_OFFSET                 = -6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  /** Should be same as above, and should be zero mod 8 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  public static final int INTERPRETER_FRAME_VM_LOCALS_FP_OFFSET           = -6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  public static final int INTERPRETER_FRAME_VM_LOCAL_WORDS                = -INTERPRETER_FRAME_VM_LOCALS_FP_OFFSET;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  /** Interpreter frame set-up needs to save 2 extra words in outgoing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
      param area for class and jnienv arguments for native stubs (see
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
      nativeStubGen_sparc.cpp) */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  public static final int INTERPRETER_FRAME_EXTRA_OUTGOING_ARGUMENT_WORDS = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  // FIXME: elided for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  //  // the compiler frame has many of the same fields as the interpreter frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  //  // %%%%% factor out declarations of the shared fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  //  enum compiler_frame_fixed_locals {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  //       compiler_frame_d_scratch_fp_offset          = -2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  //       compiler_frame_vm_locals_fp_offset          = -2, // should be same as above
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  //       compiler_frame_vm_local_words = -compiler_frame_vm_locals_fp_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  //  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  // private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
  //  // where LcpoolCache is saved:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  //  constantPoolCacheOop* interpreter_frame_cpoolcache_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  //    return (constantPoolCacheOop*)sp_addr_at( LcpoolCache.sp_offset_in_saved_window());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
  //  // where Lmonitors is saved:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  //  BasicObjectLock**  interpreter_frame_monitors_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  //    return (BasicObjectLock**) sp_addr_at( Lmonitors.sp_offset_in_saved_window());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  //  intptr_t** interpreter_frame_esp_addr() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  //    return (intptr_t**)sp_addr_at( Lesp.sp_offset_in_saved_window());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  //  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  //  inline void interpreter_frame_set_tos_address(intptr_t* x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  //  // next two fns read and write Lmonitors value,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  // private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  //  BasicObjectLock* interpreter_frame_monitors()           const  { return *interpreter_frame_monitors_addr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  //  void interpreter_frame_set_monitors(BasicObjectLock* monitors) {        *interpreter_frame_monitors_addr() = monitors; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
  //#ifndef CORE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  //inline oop *frame::pd_compiled_argument_to_location(VMReg::Name reg, RegisterMap reg_map, int arg_size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  //  COMPILER1_ONLY(return (oop *) (arg_size - 1 - reg + sp() + memory_parameter_word_sp_offset);   )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  //  COMPILER2_ONLY(return oopmapreg_to_location(reg, &reg_map); )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  //#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  // FIXME: NOT FINISHED
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
  public Address addressOfInterpreterFrameLocals() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
    return getSP().addOffsetTo(SPARCRegisters.Llocals.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  // FIXME: this is not atomic with respect to GC and is unsuitable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  // for use in a non-debugging, or reflective, system.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  private Address addressOfInterpreterFrameBCX() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    // %%%%% reinterpreting Lbcp as a bcx
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
    return getSP().addOffsetTo(SPARCRegisters.Lbcp.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  public int getInterpreterFrameBCI() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
    // FIXME: this is not atomic with respect to GC and is unsuitable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
    // for use in a non-debugging, or reflective, system. Need to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    // figure out how to express this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    Address bcp = addressOfInterpreterFrameBCX().getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    OopHandle methodHandle = addressOfInterpreterFrameMethod().getOopHandleAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    Method method = (Method) VM.getVM().getObjectHeap().newOop(methodHandle);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    return bcpToBci(bcp, method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  public Address addressOfInterpreterFrameExpressionStack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
    return addressOfInterpreterFrameMonitors().addOffsetTo(-1 * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
  public int getInterpreterFrameExpressionStackDirection() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
  /** Top of expression stack */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
  public Address addressOfInterpreterFrameTOS() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    return getSP().getAddressAt(SPARCRegisters.Lesp.spOffsetInSavedWindow()).addOffsetTo(VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  /** Expression stack from top down */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  public Address addressOfInterpreterFrameTOSAt(int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    return addressOfInterpreterFrameTOS().addOffsetTo(slot * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
  public Address getInterpreterFrameSenderSP() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
      Assert.that(isInterpretedFrame(), "interpreted frame expected");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    return getFP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
  // FIXME: elided for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
  //inline void frame::interpreter_frame_set_tos_address( intptr_t* x ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  //  *interpreter_frame_esp_addr() = x - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  //}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  // Monitors:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  private Address addressOfInterpreterFrameMonitors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    return getSP().addOffsetTo(SPARCRegisters.Lmonitors.spOffsetInSavedWindow()).getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
  // Monitors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
  public BasicObjectLock interpreterFrameMonitorBegin() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    int roundedVMLocalWords = Bits.roundTo(INTERPRETER_FRAME_VM_LOCAL_WORDS, WORDS_PER_LONG);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    return new BasicObjectLock(addressOfFPSlot(-1 * roundedVMLocalWords));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  public BasicObjectLock interpreterFrameMonitorEnd() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
    return new BasicObjectLock(addressOfInterpreterFrameMonitors());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  public int interpreterFrameMonitorSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    return Bits.roundTo(BasicObjectLock.size(), WORDS_PER_LONG * (int) VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  // FIXME: elided for now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  // // monitor elements
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // // in keeping with Intel side: end is lower in memory than begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  // // and beginning element is oldest element
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  // // Also begin is one past last monitor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  // inline BasicObjectLock* frame::interpreter_frame_monitor_begin()       const  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  //   int rounded_vm_local_words = round_to(frame::interpreter_frame_vm_local_words, WordsPerLong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  //   return (BasicObjectLock *)fp_addr_at(-rounded_vm_local_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  // inline BasicObjectLock* frame::interpreter_frame_monitor_end()         const  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  //   return interpreter_frame_monitors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  // inline void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  //   interpreter_frame_set_monitors(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // inline int frame::interpreter_frame_monitor_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  //   return round_to(BasicObjectLock::size(), WordsPerLong);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  public Address addressOfInterpreterFrameMethod() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    return getSP().addOffsetTo(SPARCRegisters.Lmethod.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  public Address addressOfInterpreterFrameCPCache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    return getSP().addOffsetTo(SPARCRegisters.LcpoolCache.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  // Entry frames:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  public JavaCallWrapper getEntryFrameCallWrapper() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
    // Note: adjust this code if the link argument in StubGenerator::call_stub() changes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
    SPARCArgument link = new SPARCArgument(0, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
    return (JavaCallWrapper) VMObjectFactory.newObject(JavaCallWrapper.class,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
                                                       getSP().getAddressAt(link.asIn().asRegister().spOffsetInSavedWindow()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  // inline JavaCallWrapper* frame::entry_frame_call_wrapper() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  //   // note: adjust this code if the link argument in StubGenerator::call_stub() changes!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  //   const Argument link = Argument(0, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  //   return (JavaCallWrapper*)sp()[link.as_in().as_register().sp_offset_in_saved_window()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  // }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  // Safepoints:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  protected Address addressOfSavedOopResult() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
    return addressOfO0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  protected Address addressOfSavedReceiver() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
    return addressOfO0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  // Internals only below this point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  private Address addressOfI7() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
    return getSP().addOffsetTo(SPARCRegisters.I7.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
  private Address addressOfO7() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    return afterSave().addressOfI7();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  private Address addressOfI0() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
    return getSP().addOffsetTo(SPARCRegisters.I0.spOffsetInSavedWindow());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  private Address addressOfO0() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    return afterSave().addressOfI0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  private static boolean addressesEqual(Address a1, Address a2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    if ((a1 == null) && (a2 == null)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
    if ((a1 == null) || (a2 == null)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    return (a1.equals(a2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  private Frame senderForEntryFrame(RegisterMap regMap) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    SPARCRegisterMap map = (SPARCRegisterMap) regMap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      Assert.that(map != null, "map must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    // Java frame called from C; skip all C frames and return top C
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    // frame of that chunk as the sender
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
    JavaCallWrapper jcw = getEntryFrameCallWrapper();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
      Assert.that(!entryFrameIsFirst(), "next Java fp must be non zero");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
      Assert.that(jcw.getLastJavaSP().greaterThan(getSP()), "must be above this frame on stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
    Address lastJavaSP = jcw.getLastJavaSP();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    Address lastJavaPC = jcw.getLastJavaPC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    map.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
      map.makeIntegerRegsUnsaved();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
      map.shiftWindow(lastJavaSP, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
      Assert.that(map.getIncludeArgumentOops(), "should be set by clear");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
    if (lastJavaPC != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
      return new SPARCFrame(biasSP(lastJavaSP), lastJavaPC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      Address youngerSP  = getNextYoungerSP(lastJavaSP, getSP());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
      return new SPARCFrame(biasSP(lastJavaSP), biasSP(youngerSP), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  private static Address getNextYoungerSP(Address oldSP, Address youngSP) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
    Address sp = getNextYoungerSPOrNull(oldSP, youngSP, null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
      Assert.that(sp != null, "missed the SP");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    return sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  private static Address getNextYoungerSPOrNull(Address oldSP, Address youngSP, Address sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    if (youngSP == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
      // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
      throw new RuntimeException("can not handle null youngSP in debugging system (seems to require register window flush)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    if (sp == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
      sp = youngSP;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    Address previousSP = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    /** Minimum frame size is 16 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
    int maxFrames = (int) (oldSP.minus(sp) / (16 * VM.getVM().getAddressSize()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    while(!sp.equals(oldSP) && spIsValid(oldSP, youngSP, sp)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      if (maxFrames-- <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
        // too many frames have gone by; invalid parameters given to this function
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
      previousSP = sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      sp = unBiasSP(sp.getAddressAt(SPARCRegisters.FP.spOffsetInSavedWindow()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
    return (sp.equals(oldSP) ? previousSP : null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  private static boolean spIsValid(Address oldSP, Address youngSP, Address sp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    long mask = VM.getVM().getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
    mask = 2 * mask - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    return ((sp.andWithMask(mask) == null) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
            (sp.lessThanOrEqual(oldSP)) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
            (sp.greaterThanOrEqual(youngSP)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
  // FIXME: this is a hopefully temporary hack (not sure what is going on)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  public long getUContextOffset() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    // FIXME: there is something I clearly don't understand about the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    // way the signal handler frame is laid out, because I shouldn't need this extra offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    int MAJOR_HACK_OFFSET = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    //    System.out.println("  SPARCFrame.isSignalHandlerFrameDbg: I2 = " + i2 + ", fp = " + fp + ", youngerSP = " + youngerSP);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
    return VM.getVM().getAddressSize() * (REGISTER_SAVE_WORDS + MAJOR_HACK_OFFSET);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
  public long getMContextAreaOffsetInUContext() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
    // From dbx-related sources:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    // /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    //  * struct sigframe is declaredf in the kernel sources in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    //  * .../uts/sun4c/os/machdep.c/sendsig()
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    //  * unfortunately we only get a pointer to the 'uc' passed
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    //  * to the sighandler so we need to do this stuff to get
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    //  * to 'rwin'.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
    //  * Have to do it like this to take account of alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    //  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
    // static struct sigframe {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    //     struct rwindow rwin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    //     ucontext_t uc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
    // } sf_help;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    // From /usr/include/sys/ucontext.h:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    // #if !defined(_XPG4_2) || defined(__EXTENSIONS__)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    // struct   ucontext {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
    // #else
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    // struct   __ucontext {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
    // #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    //  uint_t          uc_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
    //  ucontext_t      *uc_link;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    //  sigset_t        uc_sigmask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    //  stack_t         uc_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
    //  mcontext_t      uc_mcontext;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    // #ifdef   __sparcv9
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
    //  long            uc_filler[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
    // #else    /* __sparcv9 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    //  long            uc_filler[23];
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
    // #endif   /* __sparcv9 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    // };
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
    // This walks to the start of the gregs in the mcontext_t
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    // (first entry in that data structure). Really should read
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
    // this from header file.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    // Also not sure exactly how alignment works...maybe should read these offsets from the target VM
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    // (When you have a hammer, everything looks like a nail)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
    long offset = VM.getVM().alignUp(4, VM.getVM().getAddressSize());   // uc_flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
    offset      = VM.getVM().alignUp(offset + VM.getVM().getAddressSize(), 8); // uc_link plus
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
                                                                        // doubleword alignment for structs?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
    offset     += 16 +                                                  // uc_sigmask
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
                   2 * VM.getVM().getAddressSize() + 4;                 // uc_stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    offset      = VM.getVM().alignUp(offset + VM.getVM().getAddressSize(), 8); // doubleword alignment for structs?
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    //    System.out.println("SPARCFrame.getMContextAreaOffsetInUContext: offset = " + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
    return offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
}