hotspot/agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.java
author mikael
Tue, 24 Dec 2013 11:48:39 -0800
changeset 22234 da823d78ad65
parent 16356 91b8c3a2ff99
permissions -rw-r--r--
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 16356
diff changeset
     2
 * Copyright (c) 2000, 2013, 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.types.basic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
16356
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    27
import java.util.HashMap;
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    28
import java.util.Iterator;
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    29
import java.util.Map;
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    30
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    31
import sun.jvm.hotspot.debugger.Address;
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    32
import sun.jvm.hotspot.debugger.MachineDescription;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    33
import sun.jvm.hotspot.runtime.VM;
16356
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    34
import sun.jvm.hotspot.types.Type;
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
    35
import sun.jvm.hotspot.types.TypeDataBase;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
/** <P> This is a basic implementation of the TypeDataBase interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    It allows an external type database builder to add types to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    consumed by a client through the Type interfaces. It has no
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    knowledge of symbol lookup; for example, the builder is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    responsible for providing the addresses of static fields. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    <P> Among other things, the database builder is responsible for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    providing the Types for the Java primitive types, as well as their
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    sizes. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
public class BasicTypeDataBase implements TypeDataBase {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private MachineDescription machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private VtblAccess vtblAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  /** Maps strings to Type objects. This does not contain the primitive types. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private Map nameToTypeMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  /** Maps strings to Integers, used for enums, etc. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private Map nameToIntConstantMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  /** Maps strings to Longs, used for 32/64-bit constants, etc. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  private Map nameToLongConstantMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  /** Primitive types. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private Type jbooleanType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private Type jbyteType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private Type jcharType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  private Type jdoubleType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  private Type jfloatType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private Type jintType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  private Type jlongType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  private Type jshortType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  /** For debugging */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  private static final boolean DEBUG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    DEBUG = System.getProperty("sun.jvm.hotspot.types.basic.BasicTypeDataBase.DEBUG") != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  public BasicTypeDataBase(MachineDescription machDesc, VtblAccess vtblAccess) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    this.machDesc   = machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    this.vtblAccess = vtblAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  public Type lookupType(String cTypeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    return lookupType(cTypeName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  public Type lookupType(String cTypeName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    Type type = (Type) nameToTypeMap.get(cTypeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    if (type == null && throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      throw new RuntimeException("No type named \"" + cTypeName + "\" in database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  public Integer lookupIntConstant(String constantName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return lookupIntConstant(constantName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  public Integer lookupIntConstant(String constantName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    Integer i = (Integer) nameToIntConstantMap.get(constantName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    if (i == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      if (throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        throw new RuntimeException("No integer constant named \"" + constantName + "\" present in type database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  public Long lookupLongConstant(String constantName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    return lookupLongConstant(constantName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  public Long lookupLongConstant(String constantName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    Long i = (Long) nameToLongConstantMap.get(constantName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    if (i == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      if (throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        throw new RuntimeException("No long constant named \"" + constantName + "\" present in type database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  public Type getJBooleanType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return jbooleanType;
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 Type getJByteType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return jbyteType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  public Type getJCharType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    return jcharType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  public Type getJDoubleType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    return jdoubleType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  public Type getJFloatType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    return jfloatType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  public Type getJIntType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    return jintType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  public Type getJLongType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    return jlongType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  public Type getJShortType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    return jshortType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  public long getAddressSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return machDesc.getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  public long getOopSize() {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   155
    return VM.getVM().getOopSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
16356
91b8c3a2ff99 8009456: SA: typeToVtbl of BasicTypeDataBase should not be static
sla
parents: 10547
diff changeset
   158
  HashMap typeToVtbl = new HashMap();
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   159
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   160
  private Address vtblForType(Type type) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   161
    Address vtblAddr = (Address)typeToVtbl.get(type);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   162
    if (vtblAddr == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   163
      vtblAddr = vtblAccess.getVtblForType(type);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   164
      if (vtblAddr != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   165
        typeToVtbl.put(type, vtblAddr);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   166
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   167
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   168
    return vtblAddr;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   169
  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   170
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  public boolean addressTypeIsEqualToType(Address addr, Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // This implementation should be suitably platform-independent; we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    // search nearby memory for the vtbl value of the given type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   179
    Address vtblAddr = vtblForType(type);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    if (vtblAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      // Type was not polymorphic, or an error occurred during lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // The first implementation searched three locations for this vtbl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // value; scanning through the entire object was considered, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // we thought we knew where we were looking, and looking only in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // these specific locations should reduce the probability of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // mistaking random bits as a pointer (although, realistically
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    // speaking, the likelihood of finding a match between the bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    // pattern of, for example, a double and the vtbl is vanishingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    // small.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    //    1. The first word of the object (should handle MSVC++ as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    //    well as the SparcWorks compilers with compatibility set to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    //    v5.0 or greater)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    //    2. and 3. The last two Address-aligned words of the part of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    //    the object defined by its topmost polymorphic superclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    //    This should handle the SparcWorks compilers, v4.2 or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    //    earlier, as well as any other compilers which place the vptr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    //    at the end of the user-defined fields of the first base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    //    class with virtual functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    // Unfortunately this algorithm did not work properly for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    // specific case of the ThreadShadow/Thread inheritance situation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    // because the Solaris compiler seems to cleverly eliminate the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    // vtbl for ThreadShadow since the only virtual is empty. (We
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // should get rid of the ThreadShadow and fix the include
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    // databases, but need to postpone this for the present.) The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    // current solution performs the three-location check for this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    // class and all of its known superclasses rather than just the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    // topmost polymorphic one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    Type curType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      while (curType != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
        // Using the size information we have for this type, check the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        // three locations described above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        // (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
        if (vtblAddr.equals(addr.getAddressAt(0))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        // (2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        long offset = curType.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        // I don't think this should be misaligned under any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        // circumstances, but I'm not sure (FIXME: also not sure which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        // way to go here, up or down -- assuming down)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        offset -= (offset % getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        if (offset <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        if (vtblAddr.equals(addr.getAddressAt(offset))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        offset -= getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        if (offset <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        if (vtblAddr.equals(addr.getAddressAt(offset))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
        curType = curType.getSuperclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      // Any UnmappedAddressExceptions, etc. are a good indication
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      // that the pointer is not of the specified type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        e.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
                         type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   272
  public Type findDynamicTypeForAddress(Address addr, Type baseType) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   273
    // This implementation should be suitably platform-independent; we
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   274
    // search nearby memory for the vtbl value of the given type.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   275
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   276
    if (vtblForType(baseType) == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   277
      // Type was not polymorphic which is an error of some sort
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   278
      throw new InternalError(baseType + " does not appear to be polymorphic");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   279
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   280
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   281
    // This is a more restricted version of guessTypeForAddress since
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   282
    // that function has some limitations since it doesn't really know
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   283
    // where in the hierarchy a virtual type starts and just poking
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   284
    // around in memory is likely to trip over some vtable address,
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   285
    // resulting in false positives.  Eventually all uses should
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   286
    // switch to this logic but in the interests of stability it will
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   287
    // be separate for the moment.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   288
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   289
    // Assuming that the base type is truly the first polymorphic type
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   290
    // then the vtbl for all subclasss should be at several defined
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   291
    // locations so only those locations will be checked.  It's also
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   292
    // required that the caller knows that the static type is at least
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   293
    // baseType.  See the notes in guessTypeForAddress for the logic of
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   294
    // the locations searched.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   295
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   296
    Address loc1 = addr.getAddressAt(0);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   297
    Address loc2 = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   298
    Address loc3 = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   299
    long offset2 = baseType.getSize();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   300
    // I don't think this should be misaligned under any
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   301
    // circumstances, but I'm not sure (FIXME: also not sure which
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   302
    // way to go here, up or down -- assuming down)
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   303
    offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   304
    if (offset2 > 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   305
      loc2 = addr.getAddressAt(offset2);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   306
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   307
    long offset3 = offset2 - getAddressSize();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   308
    if (offset3 > 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   309
      loc3 = addr.getAddressAt(offset3);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   310
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   311
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   312
    Type loc2Match = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   313
    Type loc3Match = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   314
    for (Iterator iter = getTypes(); iter.hasNext(); ) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   315
      Type type = (Type) iter.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   316
      Type superClass = type;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   317
      while (superClass != baseType && superClass != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   318
        superClass = superClass.getSuperclass();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   319
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   320
      if (superClass == null) continue;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   321
      Address vtblAddr = vtblForType(type);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   322
      if (vtblAddr == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   323
        // This occurs sometimes for intermediate types that are never
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   324
        // instantiated.
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   325
        if (DEBUG) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   326
          System.err.println("null vtbl for " + type);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   327
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   328
        continue;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   329
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   330
      // Prefer loc1 match
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   331
      if (vtblAddr.equals(loc1)) return type;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   332
      if (loc2 != null && loc2Match == null && vtblAddr.equals(loc2)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   333
          loc2Match = type;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   334
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   335
      if (loc3 != null && loc3Match == null && vtblAddr.equals(loc3)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   336
          loc3Match = type;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   337
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   338
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   339
    if (loc2Match != null) return loc2Match;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   340
    if (loc3Match != null) return loc3Match;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   341
    return null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   342
  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 5547
diff changeset
   343
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  public Type guessTypeForAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    for (Iterator iter = getTypes(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      Type t = (Type) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      if (addressTypeIsEqualToType(addr, t)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
        return t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    return null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  public Iterator getTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    return nameToTypeMap.values().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  public Iterator getIntConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    return nameToIntConstantMap.keySet().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  public Iterator getLongConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return nameToLongConstantMap.keySet().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // Public routines only for use by the database builder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  public void setJBooleanType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    jbooleanType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  public void setJByteType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    jbyteType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  public void setJCharType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    jcharType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  public void setJDoubleType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    jdoubleType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  public void setJFloatType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    jfloatType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  public void setJIntType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    jintType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  public void setJLongType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    jlongType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  public void setJShortType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    jshortType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      TypeDataBase. Throws a RuntimeException if a class with this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  public void addType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    if (nameToTypeMap.get(type.getName()) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      throw new RuntimeException("type of name \"" + type.getName() + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    nameToTypeMap.put(type.getName(), type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      TypeDataBase. Throws a RuntimeException if this class was not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
      present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  public void removeType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    Type curType = (Type) nameToTypeMap.get(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    if (curType == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      throw new RuntimeException("type of name \"" + type.getName() + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    if (!curType.equals(type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      throw new RuntimeException("a different type of name \"" + type.getName() + "\" was present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
    nameToTypeMap.remove(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      TypeDataBase. Throws a RuntimeException if an integer constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
      with this name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  public void addIntConstant(String name, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    if (nameToIntConstantMap.get(name) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
      throw new RuntimeException("int constant of name \"" + name + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
    nameToIntConstantMap.put(name, new Integer(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
      TypeDataBase. Throws a RuntimeException if an integer constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
      with this name was not present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  public void removeIntConstant(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    Integer curConstant = (Integer) nameToIntConstantMap.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    if (curConstant == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
      throw new RuntimeException("int constant of name \"" + name + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    nameToIntConstantMap.remove(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
      TypeDataBase. Throws a RuntimeException if a long constant with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      this name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  public void addLongConstant(String name, long value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    if (nameToLongConstantMap.get(name) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      throw new RuntimeException("long constant of name \"" + name + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    nameToLongConstantMap.put(name, new Long(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      TypeDataBase. Throws a RuntimeException if a long constant with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
      this name was not present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  public void removeLongConstant(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    Long curConstant = (Long) nameToLongConstantMap.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
    if (curConstant == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
      throw new RuntimeException("long constant of name \"" + name + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    nameToLongConstantMap.remove(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
}