hotspot/agent/src/share/classes/sun/jvm/hotspot/types/basic/BasicTypeDataBase.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-2004 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.types.basic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.types.*;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    30
import sun.jvm.hotspot.runtime.VM;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
/** <P> This is a basic implementation of the TypeDataBase interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    It allows an external type database builder to add types to be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    consumed by a client through the Type interfaces. It has no
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    knowledge of symbol lookup; for example, the builder is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    responsible for providing the addresses of static fields. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    <P> Among other things, the database builder is responsible for
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    providing the Types for the Java primitive types, as well as their
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    sizes. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
*/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
public class BasicTypeDataBase implements TypeDataBase {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  private MachineDescription machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  private VtblAccess vtblAccess;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  /** Maps strings to Type objects. This does not contain the primitive types. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private Map nameToTypeMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  /** Maps strings to Integers, used for enums, etc. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private Map nameToIntConstantMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  /** Maps strings to Longs, used for 32/64-bit constants, etc. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private Map nameToLongConstantMap = new HashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  /** Primitive types. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  private Type jbooleanType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private Type jbyteType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  private Type jcharType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  private Type jdoubleType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  private Type jfloatType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private Type jintType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  private Type jlongType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  private Type jshortType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  /** For debugging */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  private static final boolean DEBUG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    DEBUG = System.getProperty("sun.jvm.hotspot.types.basic.BasicTypeDataBase.DEBUG") != null;
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 BasicTypeDataBase(MachineDescription machDesc, VtblAccess vtblAccess) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    this.machDesc   = machDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    this.vtblAccess = vtblAccess;
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 Type lookupType(String cTypeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    return lookupType(cTypeName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public Type lookupType(String cTypeName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    Type type = (Type) nameToTypeMap.get(cTypeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    if (type == null && throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      throw new RuntimeException("No type named \"" + cTypeName + "\" in database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  public Integer lookupIntConstant(String constantName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    return lookupIntConstant(constantName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  public Integer lookupIntConstant(String constantName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    Integer i = (Integer) nameToIntConstantMap.get(constantName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (i == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      if (throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        throw new RuntimeException("No integer constant named \"" + constantName + "\" present in type database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  public Long lookupLongConstant(String constantName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return lookupLongConstant(constantName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  public Long lookupLongConstant(String constantName, boolean throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    Long i = (Long) nameToLongConstantMap.get(constantName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (i == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      if (throwException) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        throw new RuntimeException("No long constant named \"" + constantName + "\" present in type database");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  public Type getJBooleanType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    return jbooleanType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  public Type getJByteType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    return jbyteType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  public Type getJCharType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return jcharType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  public Type getJDoubleType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    return jdoubleType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  public Type getJFloatType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    return jfloatType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  public Type getJIntType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return jintType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  public Type getJLongType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    return jlongType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  public Type getJShortType() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return jshortType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  public long getAddressSize() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return machDesc.getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  public long getOopSize() {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   150
    return VM.getVM().getOopSize();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  public boolean addressTypeIsEqualToType(Address addr, Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // This implementation should be suitably platform-independent; we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    // search nearby memory for the vtbl value of the given type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    Address vtblAddr = vtblAccess.getVtblForType(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (vtblAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      // Type was not polymorphic, or an error occurred during lookup
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
        System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: vtblAddr == null");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    // The first implementation searched three locations for this vtbl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // value; scanning through the entire object was considered, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // we thought we knew where we were looking, and looking only in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    // these specific locations should reduce the probability of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // mistaking random bits as a pointer (although, realistically
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    // speaking, the likelihood of finding a match between the bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    // pattern of, for example, a double and the vtbl is vanishingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    // small.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    //    1. The first word of the object (should handle MSVC++ as
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    //    well as the SparcWorks compilers with compatibility set to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    //    v5.0 or greater)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    //    2. and 3. The last two Address-aligned words of the part of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    //    the object defined by its topmost polymorphic superclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    //    This should handle the SparcWorks compilers, v4.2 or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    //    earlier, as well as any other compilers which place the vptr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    //    at the end of the user-defined fields of the first base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    //    class with virtual functions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // Unfortunately this algorithm did not work properly for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // specific case of the ThreadShadow/Thread inheritance situation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // because the Solaris compiler seems to cleverly eliminate the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // vtbl for ThreadShadow since the only virtual is empty. (We
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    // should get rid of the ThreadShadow and fix the include
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    // databases, but need to postpone this for the present.) The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    // current solution performs the three-location check for this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    // class and all of its known superclasses rather than just the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    // topmost polymorphic one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    Type curType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    try {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
      while (curType != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        // Using the size information we have for this type, check the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
        // three locations described above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        // (1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
        if (vtblAddr.equals(addr.getAddressAt(0))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        // (2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        long offset = curType.getSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        // I don't think this should be misaligned under any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        // circumstances, but I'm not sure (FIXME: also not sure which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
        // way to go here, up or down -- assuming down)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        offset -= (offset % getAddressSize());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
        if (offset <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        if (vtblAddr.equals(addr.getAddressAt(offset))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
        offset -= getAddressSize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
        if (offset <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
          return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
        if (vtblAddr.equals(addr.getAddressAt(offset))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
          return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        curType = curType.getSuperclass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    catch (Exception e) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      // Any UnmappedAddressExceptions, etc. are a good indication
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      // that the pointer is not of the specified type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: exception occurred during lookup:");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        e.printStackTrace();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      System.err.println("BasicTypeDataBase.addressTypeIsEqualToType: all vptr tests failed for type " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
                         type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  public Type guessTypeForAddress(Address addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    for (Iterator iter = getTypes(); iter.hasNext(); ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      Type t = (Type) iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      if (addressTypeIsEqualToType(addr, t)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        return t;
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 null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  public long cIntegerTypeMaxValue(long sizeInBytes, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    return machDesc.cIntegerTypeMaxValue(sizeInBytes, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  public long cIntegerTypeMinValue(long sizeInBytes, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    return machDesc.cIntegerTypeMinValue(sizeInBytes, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  public Iterator getTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    return nameToTypeMap.values().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  public Iterator getIntConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return nameToIntConstantMap.keySet().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  public Iterator getLongConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    return nameToLongConstantMap.keySet().iterator();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  //--------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // Public routines only for use by the database builder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  public void setJBooleanType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    jbooleanType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  public void setJByteType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    jbyteType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  public void setJCharType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    jcharType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  public void setJDoubleType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    jdoubleType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  public void setJFloatType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    jfloatType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  public void setJIntType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    jintType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  public void setJLongType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    jlongType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  /** This method should only be called by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
      TypeDataBase and at most once */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  public void setJShortType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    jshortType = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      TypeDataBase. Throws a RuntimeException if a class with this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  public void addType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    if (nameToTypeMap.get(type.getName()) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      throw new RuntimeException("type of name \"" + type.getName() + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    nameToTypeMap.put(type.getName(), type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      TypeDataBase. Throws a RuntimeException if this class was not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
      present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  public void removeType(Type type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    Type curType = (Type) nameToTypeMap.get(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    if (curType == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
      throw new RuntimeException("type of name \"" + type.getName() + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    if (!curType.equals(type)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      throw new RuntimeException("a different type of name \"" + type.getName() + "\" was present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    nameToTypeMap.remove(type.getName());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      TypeDataBase. Throws a RuntimeException if an integer constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      with this name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  public void addIntConstant(String name, int value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    if (nameToIntConstantMap.get(name) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      throw new RuntimeException("int constant of name \"" + name + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    nameToIntConstantMap.put(name, new Integer(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      TypeDataBase. Throws a RuntimeException if an integer constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
      with this name was not present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  public void removeIntConstant(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    Integer curConstant = (Integer) nameToIntConstantMap.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    if (curConstant == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      throw new RuntimeException("int constant of name \"" + name + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    nameToIntConstantMap.remove(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      TypeDataBase. Throws a RuntimeException if a long constant with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      this name was already present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  public void addLongConstant(String name, long value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    if (nameToLongConstantMap.get(name) != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      throw new RuntimeException("long constant of name \"" + name + "\" already present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    nameToLongConstantMap.put(name, new Long(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  /** This method should only be used by the builder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
      TypeDataBase. Throws a RuntimeException if a long constant with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
      this name was not present. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  public void removeLongConstant(String name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    Long curConstant = (Long) nameToLongConstantMap.get(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    if (curConstant == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      throw new RuntimeException("long constant of name \"" + name + "\" not present");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    nameToLongConstantMap.remove(name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
}