hotspot/agent/src/share/classes/sun/jvm/hotspot/compiler/ImmutableOopMapSet.java
author rbackman
Tue, 05 May 2015 16:50:25 +0200
changeset 30590 14f7f48c1377
parent 10517 hotspot/agent/src/share/classes/sun/jvm/hotspot/compiler/OopMapSet.java@f92c9ff3a15f
child 30774 6745424a720f
permissions -rw-r--r--
8064458: OopMap class could be more compact Reviewed-by: kvn, bdelsart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
     2
 * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
package sun.jvm.hotspot.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
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    35
public class ImmutableOopMapSet extends VMObject {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    36
  private static final boolean DEBUG = System.getProperty("sun.jvm.hotspot.compiler.ImmutableOopMapSet.DEBUG") != null;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    38
  private static CIntegerField countField;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    39
  private static CIntegerField sizeField;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    40
  private static AddressField omDataField;
1
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;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    44
  private static long classSize;
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    45
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  private static class MyVisitor implements OopMapVisitor {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    private AddressVisitor addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    public MyVisitor(AddressVisitor oopVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
      setAddressVisitor(oopVisitor);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    public void setAddressVisitor(AddressVisitor addressVisitor) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      this.addressVisitor = addressVisitor;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    public void visitOopLocation(Address oopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      addressVisitor.visitAddress(oopAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    public void visitDerivedOopLocation(Address baseOopAddr, Address derivedOopAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
        Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      } else if (VM.getVM().isServerCompiler() &&
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    65
          VM.getVM().useDerivedPointerTable()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
        Assert.that(false, "FIXME: add derived pointer table");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    public void visitValueLocation(Address valueAddr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    73
    public void visitNarrowOopLocation(Address narrowOopAddr) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    74
      addressVisitor.visitCompOopAddress(narrowOopAddr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    VM.registerVMInitializedObserver(new Observer() {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    80
      public void update(Observable o, Object data) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    81
        initialize(VM.getVM().getTypeDataBase());
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    82
      }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    83
    });
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  private static void initialize(TypeDataBase db) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    87
    Type type = db.lookupType("ImmutableOopMapSet");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    89
    countField = type.getCIntegerField("_count");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    90
    sizeField = type.getCIntegerField("_size");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
    91
    classSize = type.getSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if (!VM.getVM().isCore()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      REG_COUNT = db.lookupIntConstant("REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      if (VM.getVM().isServerCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
        SAVED_ON_ENTRY_REG_COUNT = (int) db.lookupIntConstant("SAVED_ON_ENTRY_REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        C_SAVED_ON_ENTRY_REG_COUNT = (int) db.lookupIntConstant("C_SAVED_ON_ENTRY_REG_COUNT").intValue();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   102
  public ImmutableOopMapSet(Address addr) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    super(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   106
  /**
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   107
   * Returns the number of OopMaps in this ImmutableOopMapSet
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   108
   */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  public long getSize() {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   110
    return countField.getValue(addr);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   111
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   112
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   113
  public int getCount() { return (int) countField.getValue(addr); }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   114
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   115
  private Address dataStart() {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   116
    return (addr.addOffsetTo(ImmutableOopMapSet.classSize * getCount()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   119
  public ImmutableOopMapPair pairAt(int index) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   120
    Assert.that((index >= 0) && (index < getCount()), "bad index");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   121
    return new ImmutableOopMapPair(addr.addOffsetTo(index * ImmutableOopMapPair.classSize()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   124
  /**
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   125
   * returns the OopMap at a given index
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   126
   */
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   127
  public ImmutableOopMap getMapAt(int index) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   128
    if (Assert.ASSERTS_ENABLED) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   129
      Assert.that((index >= 0) && (index <= getSize()), "bad index");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   130
    }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   131
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   132
    ImmutableOopMapPair immutableOopMapPair = pairAt(index);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   133
    return getMap(immutableOopMapPair);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   134
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   135
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   136
  public ImmutableOopMap findMapAtOffset(long pcOffset, boolean debugging) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    int len = (int) getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      Assert.that(len > 0, "must have pointer maps");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // Scan through oopmaps. Stop when current offset is either equal or greater
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    // than the one we are looking for.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    for (i = 0; i < len; i++) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   146
      if (pairAt(i).getPC() >= pcOffset) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    if (!debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        Assert.that(i < len, "oopmap not found for pcOffset = " + pcOffset + "; len = " + len);
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   154
        Assert.that(pairAt(i).getPC() == pcOffset, "oopmap not found");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      if (i == len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
          System.out.println("can't find oopmap at " + pcOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          System.out.print("Oopmap offsets are [ ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          for (i = 0; i < len; i++) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   162
            System.out.print(pairAt(i).getPC());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
          System.out.println("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        i = len - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        return getMapAt(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   171
    ImmutableOopMap m = getMapAt(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   175
  /**
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   176
   * Visitation -- iterates through the frame for a compiled method.
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   177
   * This is a very generic mechanism that requires the Address to be
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   178
   * dereferenced by the callee. Other, more specialized, visitation
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   179
   * mechanisms are given below.
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   180
   */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  public static void oopsDo(Frame fr, CodeBlob cb, RegisterMap regMap, AddressVisitor oopVisitor, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    allDo(fr, cb, regMap, new MyVisitor(oopVisitor), debugging);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   185
  /**
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   186
   * Note that there are 4 required AddressVisitors: one for oops,
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   187
   * one for derived oops, one for values, and one for dead values
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   188
   */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  public static void allDo(Frame fr, CodeBlob cb, RegisterMap regMap, OopMapVisitor visitor, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      CodeBlob tmpCB = VM.getVM().getCodeCache().findBlob(fr.getPC());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      Assert.that(tmpCB != null && cb.equals(tmpCB), "wrong codeblob passed in");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   195
    ImmutableOopMapSet maps = cb.getOopMaps();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   196
    ImmutableOopMap map = cb.getOopMapForReturnAddress(fr.getPC(), debugging);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      Assert.that(map != null, "no ptr map found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    // handle derived pointers first (otherwise base pointer may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    // changed before derived pointer offset has been collected)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    OopMapValue omv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
      for (OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.DERIVED_OOP_VALUE); !oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        if (VM.getVM().isClientCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
          Assert.that(false, "should not reach here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
        omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        if (loc != null) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   212
          Address baseLoc = fr.oopMapRegToLocation(omv.getContentReg(), regMap);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
          Address derivedLoc = loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
          visitor.visitDerivedOopLocation(baseLoc, derivedLoc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   219
    // We want narow oop, value and oop oop_types
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   220
    OopMapValue.OopTypes[] values = new OopMapValue.OopTypes[]{
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   221
        OopMapValue.OopTypes.OOP_VALUE, OopMapValue.OopTypes.VALUE_VALUE, OopMapValue.OopTypes.NARROWOOP_VALUE
1
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
      for (OopMapStream oms = new OopMapStream(map, values); !oms.isDone(); oms.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        Address loc = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        if (loc != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
          if (omv.getType() == OopMapValue.OopTypes.OOP_VALUE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
            // This assert commented out because this will be useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
            // to detect in the debugging system
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
            // assert(Universe::is_heap_or_null(*loc), "found non oop pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
            visitor.visitOopLocation(loc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
          } else if (omv.getType() == OopMapValue.OopTypes.VALUE_VALUE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
            visitor.visitValueLocation(loc);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   236
          } 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
   237
            visitor.visitNarrowOopLocation(loc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   244
  /**
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   245
   * Update callee-saved register info for the following frame.
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   246
   * Should only be called in non-core builds.
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   247
   */
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  public static void updateRegisterMap(Frame fr, CodeBlob cb, RegisterMap regMap, boolean debugging) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      Assert.that(!VM.getVM().isCore(), "non-core builds only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    if (!VM.getVM().isDebugging()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      if (Assert.ASSERTS_ENABLED) {
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   255
        ImmutableOopMapSet maps = cb.getOopMaps();
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   256
        Assert.that((maps != null) && (maps.getSize() > 0), "found null or empty ImmutableOopMapSet for CodeBlob");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      // Hack for some topmost frames that have been found with empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      // OopMapSets. (Actually have not seen the null case, but don't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      // want to take any chances.) See HSDB.showThreadStackMemory().
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   262
      ImmutableOopMapSet maps = cb.getOopMaps();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      if ((maps == null) || (maps.getSize() == 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    // Check if caller must update oop argument
10517
f92c9ff3a15f 7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents: 5547
diff changeset
   269
    regMap.setIncludeArgumentOops(cb.callerMustGCArguments());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    int nofCallee = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    Address[] locs = new Address[2 * REG_COUNT + 1];
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   273
    VMReg[] regs = new VMReg[2 * REG_COUNT + 1];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    // ("+1" because REG_COUNT might be zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    // Scan through oopmap and find location of all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    // (we do not do update in place, since info could be overwritten)
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   278
    ImmutableOopMap map = cb.getOopMapForReturnAddress(fr.getPC(), debugging);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      Assert.that(map != null, "no ptr map found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    OopMapValue omv = null;
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   284
    for (OopMapStream oms = new OopMapStream(map, OopMapValue.OopTypes.CALLEE_SAVED_VALUE); !oms.isDone(); oms.next()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      omv = oms.getCurrent();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        Assert.that(nofCallee < 2 * REG_COUNT, "overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      regs[nofCallee] = omv.getContentReg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      locs[nofCallee] = fr.oopMapRegToLocation(omv.getReg(), regMap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      nofCallee++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    // Check that runtime stubs save all callee-saved registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    // After adapter frames were deleted C2 doesn't use callee save registers at present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    if (Assert.ASSERTS_ENABLED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      if (VM.getVM().isServerCompiler()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
        Assert.that(!cb.isRuntimeStub() ||
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   299
                (nofCallee >= SAVED_ON_ENTRY_REG_COUNT || nofCallee >= C_SAVED_ON_ENTRY_REG_COUNT),
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   300
            "must save all");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // Copy found callee-saved register to reg_map
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    for (int i = 0; i < nofCallee; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      regMap.setLocation(regs[i], locs[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   309
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   310
  public ImmutableOopMapPair getPairAt(int index) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   311
    return pairAt(index);
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   312
  }
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   313
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   314
  public ImmutableOopMap getMap(ImmutableOopMapPair pair) {
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   315
    Assert.that(pair.getOffset() < (int) sizeField.getValue(), "boundary check");
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   316
    return new ImmutableOopMap(dataStart().addOffsetTo(pair.getOffset()));
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 10517
diff changeset
   317
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}