hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java
author coleenp
Thu, 27 Jan 2011 16:11:27 -0800
changeset 8076 96d498ec7ae1
parent 7696 e2aeacb8983b
child 8921 14bfe81f2a9d
permissions -rw-r--r--
6990754: Use native memory and reference counting to implement SymbolTable Summary: move symbols from permgen into C heap and reference count them Reviewed-by: never, acorn, jmasa, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
     2
 * Copyright (c) 2000, 2010, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
import sun.jvm.hotspot.debugger.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
import sun.jvm.hotspot.types.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
import sun.jvm.hotspot.types.basic.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
import sun.jvm.hotspot.utilities.*;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
/** <P> This is the cross-platform TypeDataBase used by the Oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    hierarchy. The decision was made to make this cross-platform by
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    having the VM export the necessary symbols via a built-in table;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    see src/share/vm/runtime/vmStructs.[ch]pp for more details. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    <P> <B>WARNING</B>: clients should refer to this class through the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    TypeDataBase interface and not directly to the HotSpotTypeDataBase
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    type. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    <P> NOTE: since we are fetching the sizes of the Java primitive types
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
public class HotSpotTypeDataBase extends BasicTypeDataBase {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  private Debugger symbolLookup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  private String[] jvmLibNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  private static final int UNINITIALIZED_SIZE = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  private static final int C_INT8_SIZE  = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  private static final int C_INT32_SIZE = 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private static final int C_INT64_SIZE = 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  private static final boolean DEBUG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    DEBUG = System.getProperty("sun.jvm.hotspot.HotSpotTypeDataBase.DEBUG")
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
            != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  /** <P> This requires a SymbolLookup mechanism as well as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      MachineDescription. Note that we do not need a NameMangler since
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      we use the vmStructs mechanism to avoid looking up C++
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      symbols. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      <P> NOTE that it is guaranteed that this constructor will not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      attempt to fetch any Java values from the remote process, only C
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      integers and addresses. This is required because we are fetching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      the sizes of the Java primitive types from the remote process,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      implying that attempting to fetch them before their sizes are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      known is illegal. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      <P> Throws NoSuchSymbolException if a problem occurred while
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      looking up one of the bootstrapping symbols related to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      VMStructs table in the remote VM; this may indicate that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      remote process is not actually a HotSpot VM. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  public HotSpotTypeDataBase(MachineDescription machDesc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                             VtblAccess vtblAccess,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                             Debugger symbolLookup,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                             String[] jvmLibNames) throws NoSuchSymbolException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    super(machDesc, vtblAccess);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    this.symbolLookup = symbolLookup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    this.jvmLibNames = jvmLibNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    readVMTypes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    initializePrimitiveTypes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    readVMStructs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    readVMIntConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    readVMLongConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    92
  public Type lookupType(String cTypeName, boolean throwException) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    93
    Type fieldType = super.lookupType(cTypeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    94
    if (fieldType == null && cTypeName.startsWith("const ")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    95
      fieldType = (BasicType)lookupType(cTypeName.substring(6), false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    96
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    97
    if (fieldType == null && cTypeName.endsWith(" const")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    98
        fieldType = (BasicType)lookupType(cTypeName.substring(0, cTypeName.length() - 6), false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    99
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   100
    if (fieldType == null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   101
      if (cTypeName.startsWith("GrowableArray<") && cTypeName.endsWith(">*")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   102
        String ttype = cTypeName.substring("GrowableArray<".length(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   103
                                            cTypeName.length() - 2);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   104
        Type templateType = lookupType(ttype, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   105
        if (templateType == null && typeNameIsPointerType(ttype)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   106
          templateType = recursiveCreateBasicPointerType(ttype);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   107
        }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   108
        if (templateType == null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   109
          lookupOrFail(ttype);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   110
        }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   111
        fieldType = recursiveCreateBasicPointerType(cTypeName);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   112
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   113
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   114
    if (fieldType == null && typeNameIsPointerType(cTypeName)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   115
      fieldType = recursiveCreateBasicPointerType(cTypeName);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   116
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   117
    if (fieldType == null && throwException) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   118
      super.lookupType(cTypeName, true);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   119
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   120
    return fieldType;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   121
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   122
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  private void readVMTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // Get the variables we need in order to traverse the VMTypeEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    long typeEntryTypeNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    long typeEntrySuperclassNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    long typeEntryIsOopTypeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    long typeEntryIsIntegerTypeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    long typeEntryIsUnsignedOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    long typeEntrySizeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    long typeEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   133
    // Fetch the address of the VMTypeEntry*. We get this symbol first
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   134
    // and try to use it to make sure that symbol lookup is working.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    Address entryAddr = lookupInProcess("gHotSpotVMTypes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    //    System.err.println("gHotSpotVMTypes address = " + entryAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    // Dereference this once to get the pointer to the first VMTypeEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    //    dumpMemory(entryAddr, 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      throw new RuntimeException("gHotSpotVMTypes was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   145
    typeEntryTypeNameOffset       = getLongValueFromProcess("gHotSpotVMTypeEntryTypeNameOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   146
    typeEntrySuperclassNameOffset = getLongValueFromProcess("gHotSpotVMTypeEntrySuperclassNameOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   147
    typeEntryIsOopTypeOffset      = getLongValueFromProcess("gHotSpotVMTypeEntryIsOopTypeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   148
    typeEntryIsIntegerTypeOffset  = getLongValueFromProcess("gHotSpotVMTypeEntryIsIntegerTypeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   149
    typeEntryIsUnsignedOffset     = getLongValueFromProcess("gHotSpotVMTypeEntryIsUnsignedOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   150
    typeEntrySizeOffset           = getLongValueFromProcess("gHotSpotVMTypeEntrySizeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   151
    typeEntryArrayStride          = getLongValueFromProcess("gHotSpotVMTypeEntryArrayStride");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   152
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    Address typeNameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      typeNameAddr = entryAddr.getAddressAt(typeEntryTypeNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      if (typeNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        String typeName = CStringUtilities.getString(typeNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
        String superclassName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        Address superclassNameAddr = entryAddr.getAddressAt(typeEntrySuperclassNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        if (superclassNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
          superclassName = CStringUtilities.getString(superclassNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        boolean isOopType     = (entryAddr.getCIntegerAt(typeEntryIsOopTypeOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
        boolean isIntegerType = (entryAddr.getCIntegerAt(typeEntryIsIntegerTypeOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
        boolean isUnsigned    = (entryAddr.getCIntegerAt(typeEntryIsUnsignedOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        long size             = entryAddr.getCIntegerAt(typeEntrySizeOffset, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
        createType(typeName, superclassName, isOopType, isIntegerType, isUnsigned, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      entryAddr = entryAddr.addOffsetTo(typeEntryArrayStride);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    } while (typeNameAddr != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  private void initializePrimitiveTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // Look up the needed primitive types by name...they had better be present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    setJBooleanType(lookupPrimitiveType("jboolean"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    setJByteType   (lookupPrimitiveType("jbyte"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    setJCharType   (lookupPrimitiveType("jchar"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    setJDoubleType (lookupPrimitiveType("jdouble"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    setJFloatType  (lookupPrimitiveType("jfloat"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    setJIntType    (lookupPrimitiveType("jint"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    setJLongType   (lookupPrimitiveType("jlong"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    setJShortType  (lookupPrimitiveType("jshort"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // Indicate that these are the Java primitive types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    ((BasicType) getJBooleanType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    ((BasicType) getJByteType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    ((BasicType) getJCharType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    ((BasicType) getJDoubleType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    ((BasicType) getJFloatType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    ((BasicType) getJIntType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    ((BasicType) getJLongType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    ((BasicType) getJShortType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  private Type lookupPrimitiveType(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    Type type = lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      throw new RuntimeException("Error initializing the HotSpotDataBase: could not find the primitive type \"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
                                 typeName + "\" in the remote VM's VMStructs table. This type is required in " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
                                 "order to determine the size of Java primitive types. Can not continue.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  private void readVMStructs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // Get the variables we need in order to traverse the VMStructEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    long structEntryTypeNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    long structEntryFieldNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    long structEntryTypeStringOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    long structEntryIsStaticOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    long structEntryOffsetOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    long structEntryAddressOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    long structEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    structEntryTypeNameOffset     = getLongValueFromProcess("gHotSpotVMStructEntryTypeNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    structEntryFieldNameOffset    = getLongValueFromProcess("gHotSpotVMStructEntryFieldNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    structEntryTypeStringOffset   = getLongValueFromProcess("gHotSpotVMStructEntryTypeStringOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    structEntryIsStaticOffset     = getLongValueFromProcess("gHotSpotVMStructEntryIsStaticOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    structEntryOffsetOffset       = getLongValueFromProcess("gHotSpotVMStructEntryOffsetOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    structEntryAddressOffset      = getLongValueFromProcess("gHotSpotVMStructEntryAddressOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    structEntryArrayStride        = getLongValueFromProcess("gHotSpotVMStructEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // Fetch the address of the VMStructEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    Address entryAddr = lookupInProcess("gHotSpotVMStructs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    // Dereference this once to get the pointer to the first VMStructEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      throw new RuntimeException("gHotSpotVMStructs was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    Address fieldNameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    String typeName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    String fieldName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    String typeString = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    boolean isStatic = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    long offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    Address staticFieldAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    long size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    long index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    String opaqueName = "<opaque>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    lookupOrCreateClass(opaqueName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      // Fetch the field name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      fieldNameAddr = entryAddr.getAddressAt(structEntryFieldNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      if (fieldNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        fieldName = CStringUtilities.getString(fieldNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        // Now the rest of the names. Keep in mind that the type name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        // may be NULL, indicating that the type is opaque.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
        Address addr = entryAddr.getAddressAt(structEntryTypeNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
          throw new RuntimeException("gHotSpotVMStructs unexpectedly had a NULL type name at index " + index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        typeName = CStringUtilities.getString(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
        addr = entryAddr.getAddressAt(structEntryTypeStringOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
          typeString = opaqueName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
          typeString = CStringUtilities.getString(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        isStatic = !(entryAddr.getCIntegerAt(structEntryIsStaticOffset, C_INT32_SIZE, false) == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        if (isStatic) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
          staticFieldAddr = entryAddr.getAddressAt(structEntryAddressOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
          offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
          offset = entryAddr.getCIntegerAt(structEntryOffsetOffset, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
          staticFieldAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        // The containing Type must already be in the database -- no exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        BasicType containingType = lookupOrFail(typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        // The field's Type must already be in the database -- no exceptions
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   284
        BasicType fieldType = (BasicType)lookupType(typeString);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        // Create field by type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        createField(containingType, fieldName, fieldType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
                    isStatic, offset, staticFieldAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      entryAddr = entryAddr.addOffsetTo(structEntryArrayStride);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    } while (fieldNameAddr != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  private void readVMIntConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    // Get the variables we need in order to traverse the VMIntConstantEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    long intConstantEntryNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    long intConstantEntryValueOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    long intConstantEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    intConstantEntryNameOffset  = getLongValueFromProcess("gHotSpotVMIntConstantEntryNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    intConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMIntConstantEntryValueOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    intConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMIntConstantEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // Fetch the address of the VMIntConstantEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    Address entryAddr = lookupInProcess("gHotSpotVMIntConstants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // Dereference this once to get the pointer to the first VMIntConstantEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      throw new RuntimeException("gHotSpotVMIntConstants was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    Address nameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      nameAddr = entryAddr.getAddressAt(intConstantEntryNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      if (nameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        String name = CStringUtilities.getString(nameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        int value = (int) entryAddr.getCIntegerAt(intConstantEntryValueOffset, C_INT32_SIZE, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
        // Be a little resilient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
        Integer oldValue = lookupIntConstant(name, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
        if (oldValue == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
          addIntConstant(name, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
          if (oldValue.intValue() != value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
            throw new RuntimeException("Error: the integer constant \"" + name +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
                                       "\" had its value redefined (old was " + oldValue +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
                                       ", new is " + value + ". Aborting.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
            System.err.println("Warning: the int constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMIntConstants) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
                               "had its value declared as " + value + " twice. Continuing.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      entryAddr = entryAddr.addOffsetTo(intConstantEntryArrayStride);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    } while (nameAddr != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  private void readVMLongConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    // Get the variables we need in order to traverse the VMLongConstantEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    long longConstantEntryNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    long longConstantEntryValueOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    long longConstantEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    longConstantEntryNameOffset  = getLongValueFromProcess("gHotSpotVMLongConstantEntryNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    longConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMLongConstantEntryValueOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    longConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMLongConstantEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    // Fetch the address of the VMLongConstantEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    Address entryAddr = lookupInProcess("gHotSpotVMLongConstants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    // Dereference this once to get the pointer to the first VMLongConstantEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      throw new RuntimeException("gHotSpotVMLongConstants was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    Address nameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
      nameAddr = entryAddr.getAddressAt(longConstantEntryNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      if (nameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
        String name = CStringUtilities.getString(nameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
        int value = (int) entryAddr.getCIntegerAt(longConstantEntryValueOffset, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
        // Be a little resilient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
        Long oldValue = lookupLongConstant(name, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
        if (oldValue == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
          addLongConstant(name, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
          if (oldValue.longValue() != value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
            throw new RuntimeException("Error: the long constant \"" + name +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
                                       "\" had its value redefined (old was " + oldValue +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
                                       ", new is " + value + ". Aborting.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
            System.err.println("Warning: the long constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMLongConstants) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                               "had its value declared as " + value + " twice. Continuing.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      entryAddr = entryAddr.addOffsetTo(longConstantEntryArrayStride);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    } while (nameAddr != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  private BasicType lookupOrFail(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    BasicType type = (BasicType) lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      throw new RuntimeException("Type \"" + typeName + "\", referenced in VMStructs::localHotSpotVMStructs in the remote VM, " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
                                 "was not present in the remote VMStructs::localHotSpotVMTypes table (should have been caught " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
                                 "in the debug build of that VM). Can not continue.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  private long getLongValueFromProcess(String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    return lookupInProcess(symbol).getCIntegerAt(0, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  private Address lookupInProcess(String symbol) throws NoSuchSymbolException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    // FIXME: abstract away the loadobject name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    for (int i = 0; i < jvmLibNames.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
      Address addr = symbolLookup.lookup(jvmLibNames[i], symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      if (addr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
        return addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    String errStr = "(";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    for (int i = 0; i < jvmLibNames.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      errStr += jvmLibNames[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      if (i < jvmLibNames.length - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
        errStr += ", ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    errStr += ")";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    throw new NoSuchSymbolException(symbol,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
                                    "Could not find symbol \"" + symbol +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
                                    "\" in any of the known library names " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
                                    errStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  private BasicType lookupOrCreateClass(String typeName, boolean isOopType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
                                        boolean isIntegerType, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    BasicType type = (BasicType) lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      // Create a new type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      type = createBasicType(typeName, isOopType, isIntegerType, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  /** Creates a new BasicType, initializes its size to -1 so we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      test to ensure that all types' sizes are initialized by VMTypes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      and adds it to the database. Takes care of initializing integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
      and oop types properly. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  private BasicType createBasicType(String typeName, boolean isOopType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
                                    boolean isIntegerType, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    BasicType type = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    if (isIntegerType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      type = new BasicCIntegerType(this, typeName, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      if (typeNameIsPointerType(typeName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        type = recursiveCreateBasicPointerType(typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        type = new BasicType(this, typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      if (isOopType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        // HACK: turn markOop into a C integer type. This allows
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
        // proper handling of it in the Serviceability Agent. (FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
        // -- consider doing something different here)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
        if (typeName.equals("markOop")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
          type = new BasicCIntegerType(this, typeName, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
          type.setIsOopType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    type.setSize(UNINITIALIZED_SIZE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    addType(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  /** Recursively creates a PointerType from the string representation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
      of the type's name. Note that this currently needs some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      workarounds due to incomplete information in the VMStructs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
      database. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  private BasicPointerType recursiveCreateBasicPointerType(String typeName) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   476
    BasicPointerType result = (BasicPointerType)super.lookupType(typeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   477
    if (result != null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   478
      return result;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   479
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    String targetTypeName = typeName.substring(0, typeName.lastIndexOf('*')).trim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    Type targetType = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    if (typeNameIsPointerType(targetTypeName)) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   483
      targetType = lookupType(targetTypeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   484
      if (targetType == null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   485
        targetType = recursiveCreateBasicPointerType(targetTypeName);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   486
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      targetType = lookupType(targetTypeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
      if (targetType == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
        // Workaround for missing C integer types in database.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
        // Also looks like we can't throw an exception for other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
        // missing target types because there are some in old
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
        // VMStructs tables that didn't have the target type declared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
        // For this case, we create basic types that never get filled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
        // in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
        if (targetTypeName.equals("char") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
            targetTypeName.equals("const char")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
          // We don't have a representation of const-ness of C types in the SA
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
          BasicType basicTargetType = createBasicType(targetTypeName, false, true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
          basicTargetType.setSize(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
          targetType = basicTargetType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
        } else if (targetTypeName.equals("u_char")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
          BasicType basicTargetType = createBasicType(targetTypeName, false, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          basicTargetType.setSize(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
          targetType = basicTargetType;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   507
        } else if (targetTypeName.startsWith("GrowableArray<")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   508
          BasicType basicTargetType = createBasicType(targetTypeName, false, false, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   509
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   510
          // transfer fields from GenericGrowableArray to template instance
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   511
          BasicType generic = lookupOrFail("GenericGrowableArray");
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   512
          basicTargetType.setSize(generic.getSize());
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   513
          Iterator fields = generic.getFields();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   514
          while (fields.hasNext()) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   515
              Field f = (Field)fields.next();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   516
              basicTargetType.addField(internalCreateField(basicTargetType, f.getName(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   517
                                                           f.getType(), f.isStatic(),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   518
                                                           f.getOffset(), null));
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   519
          }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   520
          targetType = basicTargetType;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
          if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
            System.err.println("WARNING: missing target type \"" + targetTypeName + "\" for pointer type \"" + typeName + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
          targetType = createBasicType(targetTypeName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   529
    result = new BasicPointerType(this, typeName, targetType);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   530
    result.setSize(UNINITIALIZED_SIZE);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   531
    addType(result);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   532
    return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  private boolean typeNameIsPointerType(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    int i = typeName.length() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    while (i >= 0 && Character.isWhitespace(typeName.charAt(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    if (i >= 0 && typeName.charAt(i) == '*') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
    public void createType(String typeName, String superclassName,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
                           boolean isOopType, boolean isIntegerType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
                           boolean isUnsigned, long size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
        // See whether we have a superclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
        BasicType superclass = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        if (superclassName != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
            // Fetch or create it (FIXME: would get oop types wrong if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
            // they had a hierarchy; consider using lookupOrFail)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
            superclass = lookupOrCreateClass(superclassName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
        // Lookup or create the current type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        BasicType curType = lookupOrCreateClass(typeName, isOopType, isIntegerType, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
        // Set superclass and/or ensure it's correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
        if (superclass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
            if (curType.getSuperclass() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
                // Set the superclass in the current type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
                curType.setSuperclass(superclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
            if (curType.getSuperclass() != superclass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
                throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
                                           "had its superclass redefined (old was " + curType.getSuperclass().getName() + ", new is " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
                                           superclass.getName() + ").");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        // Classes are created with a size of UNINITIALIZED_SIZE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
        // Set size if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
        if (curType.getSize() == UNINITIALIZED_SIZE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
            curType.setSize(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
            if (curType.getSize() != size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
                throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
                                           "had its size redefined (old was " + curType.getSize() + ", new is " + size + ").");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
            System.err.println("Warning: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
                               "had its size declared as " + size + " twice. Continuing.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    /** "Virtual constructor" for fields based on type */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    public void createField(BasicType containingType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
                            String name, Type type, boolean isStatic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
                            long offset, Address staticFieldAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
        // Add field to containing type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
        containingType.addField(internalCreateField(containingType, name, type, isStatic, offset, staticFieldAddress));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    Field internalCreateField(BasicType containingType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
                              String name, Type type, boolean isStatic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                              long offset, Address staticFieldAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    // "Virtual constructor" based on type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    if (type.isOopType()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
      return new BasicOopField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
                               isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    if (type instanceof CIntegerType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      return new BasicCIntegerField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
                                    isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    if (type.equals(getJBooleanType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
      return new BasicJBooleanField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
                                    isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    if (type.equals(getJByteType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      return new BasicJByteField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    if (type.equals(getJCharType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
      return new BasicJCharField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    if (type.equals(getJDoubleType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      return new BasicJDoubleField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
                                   isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    if (type.equals(getJFloatType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      return new BasicJFloatField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
                                  isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    if (type.equals(getJIntType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
      return new BasicJIntField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
                                isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    if (type.equals(getJLongType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      return new BasicJLongField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    if (type.equals(getJShortType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      return new BasicJShortField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
                                  isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    // Unknown ("opaque") type. Instantiate ordinary Field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    return new BasicField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
                          isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // For debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  private void dumpMemory(Address addr, int len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    while (i < len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
      System.err.print(addr.addOffsetTo(i) + ":");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
      for (int j = 0; j < 8 && i < len; i++, j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
        String s = Long.toHexString(addr.getCIntegerAt(i, 1, true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
        System.err.print(" 0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
        for (int k = 0; k < 2 - s.length(); k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
          System.err.print("0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
        System.err.print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
}