hotspot/agent/src/share/classes/sun/jvm/hotspot/compiler/OopMapSet.java
author coleenp
Sun, 13 Apr 2008 17:43:42 -0400
changeset 360 21d113ecbf6a
parent 1 489c9b5090e2
child 670 ddf3e9583f2f
permissions -rw-r--r--
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
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-2005 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.compiler;
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.code.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.runtime.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
public class OopMapSet extends VMObject {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.compiler.OopMapSet.DEBUG") != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  private static CIntegerField omCountField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  private static CIntegerField omSizeField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  private static AddressField  omDataField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  private static int REG_COUNT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  private static int SAVED_ON_ENTRY_REG_COUNT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  private static int C_SAVED_ON_ENTRY_REG_COUNT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private static class MyVisitor implements OopMapVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    private AddressVisitor addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    public MyVisitor(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
      setAddressVisitor(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    public void setAddressVisitor(AddressVisitor addressVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
      this.addressVisitor = addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    public void visitOopLocation(Address oopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      addressVisitor.visitAddress(oopAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    public void visitDerivedOopLocation(Address baseOopAddr, Address derivedOopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
        Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      } else if (VM.getVM().isServerCompiler() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                 VM.getVM().useDerivedPointerTable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
        Assert.that(false, "FIXME: add derived pointer table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    public void visitValueLocation(Address valueAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    71
    public void visitNarrowOopLocation(Address narrowOopAddr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    72
      addressVisitor.visitCompOopAddress(narrowOopAddr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    VM.registerVMInitializedObserver(new Observer() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        public void update(Observable o, Object data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
          initialize(VM.getVM().getTypeDataBase());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
      });
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  private static void initialize(TypeDataBase db) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    Type type = db.lookupType("OopMapSet");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    omCountField  = type.getCIntegerField("_om_count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    omSizeField   = type.getCIntegerField("_om_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    omDataField   = type.getAddressField("_om_data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      REG_COUNT = db.lookupIntConstant("REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      if (VM.getVM().isServerCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        SAVED_ON_ENTRY_REG_COUNT = (int) db.lookupIntConstant("SAVED_ON_ENTRY_REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        C_SAVED_ON_ENTRY_REG_COUNT = (int) db.lookupIntConstant("C_SAVED_ON_ENTRY_REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  public OopMapSet(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  /** Returns the number of OopMaps in this OopMapSet */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  public long getSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return omCountField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  /** returns the OopMap at a given index */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  public OopMap getMapAt(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      Assert.that((index >= 0) && (index <= getSize()),"bad index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    Address omDataAddr = omDataField.getValue(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    Address oopMapAddr = omDataAddr.getAddressAt(index * VM.getVM().getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    if (oopMapAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return new OopMap(oopMapAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  public OopMap findMapAtOffset(long pcOffset, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    int len = (int) getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      Assert.that(len > 0, "must have pointer maps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    // Scan through oopmaps. Stop when current offset is either equal or greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // than the one we are looking for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    for (i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      if (getMapAt(i).getOffset() >= pcOffset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    if (!debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        Assert.that(i < len, "oopmap not found for pcOffset = " + pcOffset + "; len = " + len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
        Assert.that(getMapAt(i).getOffset() == pcOffset, "oopmap not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      if (i == len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
          System.out.println("can't find oopmap at " + pcOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
          System.out.print("Oopmap offsets are [ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
          for (i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
            System.out.print(getMapAt(i).getOffset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
          System.out.println("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        i = len - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        return getMapAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    OopMap m = getMapAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  /** Visitation -- iterates through the frame for a compiled method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      This is a very generic mechanism that requires the Address to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      dereferenced by the callee. Other, more specialized, visitation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      mechanisms are given below. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  public static void oopsDo(Frame fr, CodeBlob cb, RegisterMap regMap, AddressVisitor oopVisitor, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    allDo(fr, cb, regMap, new MyVisitor(oopVisitor), debugging);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  /** Note that there are 4 required AddressVisitors: one for oops,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      one for derived oops, one for values, and one for dead values */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  public static void allDo(Frame fr, CodeBlob cb, RegisterMap regMap, OopMapVisitor visitor, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      CodeBlob tmpCB = VM.getVM().getCodeCache().findBlob(fr.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
      Assert.that(tmpCB != null && cb.equals(tmpCB), "wrong codeblob passed in");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    OopMapSet maps = cb.getOopMaps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    OopMap map = cb.getOopMapForReturnAddress(fr.getPC(), debugging);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      Assert.that(map != null, "no ptr map found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    // handle derived pointers first (otherwise base pointer may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    // changed before derived pointer offset has been collected)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    OopMapValue omv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      for (OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); !oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
          Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        if (loc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
          Address baseLoc    = fr.oopMapRegToLocation(omv.getContentReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
          Address derivedLoc = loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
          visitor.visitDerivedOopLocation(baseLoc, derivedLoc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   201
    // We want narow oop, value and oop oop_types
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    OopMapValue.OopTypes[] values = new OopMapValue.OopTypes[] {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   203
      OopMapValue.OopTypes.OOP_VALUE, OopMapValue.OopTypes.VALUE_VALUE, OopMapValue.OopTypes.NARROWOOP_VALUE
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      for (OopMapStream oms = new OopMapStream(map, values); !oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        if (loc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
          if (omv.getType() == OopMapValue.OopTypes.OOP_VALUE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
            // This assert commented out because this will be useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
            // to detect in the debugging system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
            // assert(Universe::is_heap_or_null(*loc), "found non oop pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
            visitor.visitOopLocation(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
          } else if (omv.getType() == OopMapValue.OopTypes.VALUE_VALUE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
            visitor.visitValueLocation(loc);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   218
          } else if (omv.getType() == OopMapValue.OopTypes.NARROWOOP_VALUE) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   219
            visitor.visitNarrowOopLocation(loc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  /** Update callee-saved register info for the following frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      Should only be called in non-core builds. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  public static void updateRegisterMap(Frame fr, CodeBlob cb, RegisterMap regMap, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      Assert.that(!VM.getVM().isCore(), "non-core builds only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    if (!VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        OopMapSet maps = cb.getOopMaps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        Assert.that((maps != null) && (maps.getSize() > 0), "found null or empty OopMapSet for CodeBlob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      // Hack for some topmost frames that have been found with empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      // OopMapSets. (Actually have not seen the null case, but don't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      // want to take any chances.) See HSDB.showThreadStackMemory().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      OopMapSet maps = cb.getOopMaps();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      if ((maps == null) || (maps.getSize() == 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        return;
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
    // Check if caller must update oop argument
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    regMap.setIncludeArgumentOops(cb.callerMustGCArguments(regMap.getThread()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    int nofCallee = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    Address[] locs = new Address[2 * REG_COUNT + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    VMReg  [] regs = new VMReg  [2 * REG_COUNT + 1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    // ("+1" because REG_COUNT might be zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    // Scan through oopmap and find location of all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    // (we do not do update in place, since info could be overwritten)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    OopMap map  = cb.getOopMapForReturnAddress(fr.getPC(), debugging);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      Assert.that(map != null, "no ptr map found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    OopMapValue omv = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    for(OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); !oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        Assert.that(nofCallee < 2 * REG_COUNT, "overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      regs[nofCallee] = omv.getContentReg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      locs[nofCallee] = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      nofCallee++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    // Check that runtime stubs save all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    // After adapter frames were deleted C2 doesn't use callee save registers at present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      if (VM.getVM().isServerCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        Assert.that(!cb.isRuntimeStub() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
                    (nofCallee >= SAVED_ON_ENTRY_REG_COUNT || nofCallee >= C_SAVED_ON_ENTRY_REG_COUNT),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
                    "must save all");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    // Copy found callee-saved register to reg_map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    for (int i = 0; i < nofCallee; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      regMap.setLocation(regs[i], locs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}