src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java
author stefank
Tue, 06 Aug 2019 10:48:21 +0200
changeset 57777 90ead0febf56
parent 50107 300e4a88c400
permissions -rw-r--r--
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier Reviewed-by: rkennke, coleenp, kbarrett, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
50107
300e4a88c400 8195613: [SA] HotSpotTypeDataBase.readVMLongConstants truncates values to int
jgeorge
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, 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;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
    53
  private static int pointerSize = UNINITIALIZED_SIZE;
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
    54
  // Counter to ensure read loops terminate:
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
    55
  private static final int MAX_DUPLICATE_DEFINITIONS = 100;
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
    56
  private int duplicateDefCount = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  private static final boolean DEBUG;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  static {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    DEBUG = System.getProperty("sun.jvm.hotspot.HotSpotTypeDataBase.DEBUG")
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
            != null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  /** <P> This requires a SymbolLookup mechanism as well as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      MachineDescription. Note that we do not need a NameMangler since
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      we use the vmStructs mechanism to avoid looking up C++
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      symbols. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      <P> NOTE that it is guaranteed that this constructor will not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      attempt to fetch any Java values from the remote process, only C
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      integers and addresses. This is required because we are fetching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      the sizes of the Java primitive types from the remote process,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      implying that attempting to fetch them before their sizes are
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      known is illegal. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      <P> Throws NoSuchSymbolException if a problem occurred while
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
      looking up one of the bootstrapping symbols related to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      VMStructs table in the remote VM; this may indicate that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      remote process is not actually a HotSpot VM. </P>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  public HotSpotTypeDataBase(MachineDescription machDesc,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                             VtblAccess vtblAccess,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
                             Debugger symbolLookup,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
                             String[] jvmLibNames) throws NoSuchSymbolException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    super(machDesc, vtblAccess);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    this.symbolLookup = symbolLookup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    this.jvmLibNames = jvmLibNames;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    readVMTypes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    initializePrimitiveTypes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    readVMStructs();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    readVMIntConstants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    readVMLongConstants();
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
    94
    readExternalDefinitions();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    97
  public Type lookupType(String cTypeName, boolean throwException) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    98
    Type fieldType = super.lookupType(cTypeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
    99
    if (fieldType == null && cTypeName.startsWith("const ")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   100
      fieldType = (BasicType)lookupType(cTypeName.substring(6), false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   101
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   102
    if (fieldType == null && cTypeName.endsWith(" const")) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   103
        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
   104
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   105
    if (fieldType == null) {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   106
      if (cTypeName.startsWith("GrowableArray<") && cTypeName.endsWith(">")) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   107
        String ttype = cTypeName.substring("GrowableArray<".length(),
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   108
                                            cTypeName.length() - 1);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   109
        Type templateType = lookupType(ttype, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   110
        if (templateType == null && typeNameIsPointerType(ttype)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   111
          templateType = recursiveCreateBasicPointerType(ttype);
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
        if (templateType == null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   114
          lookupOrFail(ttype);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   115
        }
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   116
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   117
        BasicType basicTargetType = createBasicType(cTypeName, false, false, false);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   118
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   119
        // transfer fields from GenericGrowableArray to template instance
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   120
        BasicType generic = lookupOrFail("GenericGrowableArray");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   121
        BasicType specific = lookupOrFail("GrowableArray<int>");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   122
        basicTargetType.setSize(specific.getSize());
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   123
        Iterator fields = generic.getFields();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   124
        while (fields.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   125
          Field f = (Field)fields.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   126
          basicTargetType.addField(internalCreateField(basicTargetType, f.getName(),
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   127
                                                       f.getType(), f.isStatic(),
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   128
                                                       f.getOffset(), null));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   129
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   130
        fieldType = basicTargetType;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   131
      }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   132
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   133
    if (fieldType == null && typeNameIsPointerType(cTypeName)) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   134
      fieldType = recursiveCreateBasicPointerType(cTypeName);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   135
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   136
    if (fieldType == null && throwException) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   137
      super.lookupType(cTypeName, true);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   138
    }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   139
    return fieldType;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   140
  }
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   141
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  private void readVMTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    // Get the variables we need in order to traverse the VMTypeEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    long typeEntryTypeNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    long typeEntrySuperclassNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    long typeEntryIsOopTypeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    long typeEntryIsIntegerTypeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    long typeEntryIsUnsignedOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    long typeEntrySizeOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    long typeEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   152
    // 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
   153
    // and try to use it to make sure that symbol lookup is working.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    Address entryAddr = lookupInProcess("gHotSpotVMTypes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    //    System.err.println("gHotSpotVMTypes address = " + entryAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    // Dereference this once to get the pointer to the first VMTypeEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    //    dumpMemory(entryAddr, 80);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      throw new RuntimeException("gHotSpotVMTypes was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
7696
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   164
    typeEntryTypeNameOffset       = getLongValueFromProcess("gHotSpotVMTypeEntryTypeNameOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   165
    typeEntrySuperclassNameOffset = getLongValueFromProcess("gHotSpotVMTypeEntrySuperclassNameOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   166
    typeEntryIsOopTypeOffset      = getLongValueFromProcess("gHotSpotVMTypeEntryIsOopTypeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   167
    typeEntryIsIntegerTypeOffset  = getLongValueFromProcess("gHotSpotVMTypeEntryIsIntegerTypeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   168
    typeEntryIsUnsignedOffset     = getLongValueFromProcess("gHotSpotVMTypeEntryIsUnsignedOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   169
    typeEntrySizeOffset           = getLongValueFromProcess("gHotSpotVMTypeEntrySizeOffset");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   170
    typeEntryArrayStride          = getLongValueFromProcess("gHotSpotVMTypeEntryArrayStride");
e2aeacb8983b 6987812: 2/3 SAJDI: "gHotSpotVMTypes was not initialized properly in the remote process"
dcubed
parents: 5547
diff changeset
   171
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   172
    if (typeEntryArrayStride == 0L) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   173
      throw new RuntimeException("zero stride: cannot read types.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   174
    }
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   175
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    Address typeNameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      typeNameAddr = entryAddr.getAddressAt(typeEntryTypeNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      if (typeNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        String typeName = CStringUtilities.getString(typeNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        String superclassName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        Address superclassNameAddr = entryAddr.getAddressAt(typeEntrySuperclassNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        if (superclassNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
          superclassName = CStringUtilities.getString(superclassNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        boolean isOopType     = (entryAddr.getCIntegerAt(typeEntryIsOopTypeOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        boolean isIntegerType = (entryAddr.getCIntegerAt(typeEntryIsIntegerTypeOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        boolean isUnsigned    = (entryAddr.getCIntegerAt(typeEntryIsUnsignedOffset, C_INT32_SIZE, false) != 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        long size             = entryAddr.getCIntegerAt(typeEntrySizeOffset, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        createType(typeName, superclassName, isOopType, isIntegerType, isUnsigned, size);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   196
        if (pointerSize == UNINITIALIZED_SIZE && typeName.equals("void*")) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   197
          pointerSize = (int)size;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   198
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
      entryAddr = entryAddr.addOffsetTo(typeEntryArrayStride);
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   202
    } while (typeNameAddr != null && duplicateDefCount < MAX_DUPLICATE_DEFINITIONS);
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   203
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   204
    if (duplicateDefCount >= MAX_DUPLICATE_DEFINITIONS) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   205
      throw new RuntimeException("too many duplicate definitions");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   206
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  private void initializePrimitiveTypes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    // Look up the needed primitive types by name...they had better be present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    setJBooleanType(lookupPrimitiveType("jboolean"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    setJByteType   (lookupPrimitiveType("jbyte"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    setJCharType   (lookupPrimitiveType("jchar"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    setJDoubleType (lookupPrimitiveType("jdouble"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    setJFloatType  (lookupPrimitiveType("jfloat"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    setJIntType    (lookupPrimitiveType("jint"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    setJLongType   (lookupPrimitiveType("jlong"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    setJShortType  (lookupPrimitiveType("jshort"));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    // Indicate that these are the Java primitive types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    ((BasicType) getJBooleanType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    ((BasicType) getJByteType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    ((BasicType) getJCharType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    ((BasicType) getJDoubleType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    ((BasicType) getJFloatType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    ((BasicType) getJIntType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    ((BasicType) getJLongType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    ((BasicType) getJShortType()).setIsJavaPrimitiveType(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  private Type lookupPrimitiveType(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    Type type = lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      throw new RuntimeException("Error initializing the HotSpotDataBase: could not find the primitive type \"" +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
                                 typeName + "\" in the remote VM's VMStructs table. This type is required in " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
                                 "order to determine the size of Java primitive types. Can not continue.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   241
  private void readExternalDefinitions() {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   242
    String file = System.getProperty("sun.jvm.hotspot.typedb");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   243
    if (file != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   244
      System.out.println("Reading " + file);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   245
      BufferedReader in = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   246
      try {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   247
        StreamTokenizer t = new StreamTokenizer(in = new BufferedReader(new InputStreamReader(new FileInputStream(file))));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   248
        t.resetSyntax();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   249
        t.wordChars('\u0000','\uFFFF');
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   250
        t.whitespaceChars(' ', ' ');
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   251
        t.whitespaceChars('\n', '\n');
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   252
        t.whitespaceChars('\r', '\r');
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   253
        t.quoteChar('\"');
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   254
        t.eolIsSignificant(true);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   255
        while (t.nextToken() != StreamTokenizer.TT_EOF) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   256
          if (t.ttype == StreamTokenizer.TT_EOL) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   257
            continue;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   258
          }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   259
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   260
          if (t.sval.equals("field")) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   261
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   262
            BasicType containingType = (BasicType)lookupType(t.sval);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   263
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   264
            String fieldName = t.sval;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   265
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   266
            // The field's Type must already be in the database -- no exceptions
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   267
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   268
            Type fieldType = lookupType(t.sval);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   269
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   270
            boolean isStatic = Boolean.valueOf(t.sval).booleanValue();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   271
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   272
            long offset = Long.parseLong(t.sval);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   273
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   274
            Address staticAddress = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   275
            if (isStatic) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   276
              throw new InternalError("static fields not supported");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   277
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   278
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   279
            // check to see if the field already exists
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   280
            Iterator i = containingType.getFields();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   281
            boolean defined = false;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   282
            while (i.hasNext()) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   283
              Field f = (Field) i.next();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   284
              if (f.getName().equals(fieldName)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   285
                if (f.isStatic() != isStatic) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   286
                  throw new RuntimeException("static/nonstatic mismatch: " + fieldName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   287
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   288
                if (!isStatic) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   289
                  if (f.getOffset() != offset) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   290
                    throw new RuntimeException("bad redefinition of field offset: " + fieldName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   291
                  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   292
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   293
                  if (!f.getStaticFieldAddress().equals(staticAddress)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   294
                    throw new RuntimeException("bad redefinition of field location: " + fieldName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   295
                  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   296
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   297
                if (f.getType() != fieldType) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   298
                  System.out.println(fieldType);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   299
                  System.out.println(f.getType());
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   300
                  throw new RuntimeException("bad redefinition of field type: " + fieldName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   301
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   302
                defined = true;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   303
                break;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   304
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   305
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   306
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   307
            if (!defined) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   308
              // Create field by type
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   309
              createField(containingType,
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   310
                          fieldName, fieldType,
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   311
                          isStatic,
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   312
                          offset,
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   313
                          staticAddress);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   314
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   315
          } else if (t.sval.equals("type")) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   316
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   317
            String typeName = t.sval;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   318
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   319
            String superclassName = t.sval;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   320
            if (superclassName.equals("null")) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   321
              superclassName = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   322
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   323
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   324
            boolean isOop = Boolean.valueOf(t.sval).booleanValue();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   325
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   326
            boolean isInteger = Boolean.valueOf(t.sval).booleanValue();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   327
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   328
            boolean isUnsigned = Boolean.valueOf(t.sval).booleanValue();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   329
            t.nextToken();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   330
            long size = Long.parseLong(t.sval);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   331
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   332
            BasicType type = null;
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   333
            try {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   334
              type = (BasicType)lookupType(typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   335
            } catch (RuntimeException e) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   336
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   337
            if (type != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   338
              if (type.isOopType() != isOop) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   339
                throw new RuntimeException("oop mismatch in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   340
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   341
              if (type.isCIntegerType() != isInteger) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   342
                throw new RuntimeException("integer type mismatch in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   343
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   344
              if (type.isCIntegerType() && (((CIntegerType)type).isUnsigned()) != isUnsigned) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   345
                throw new RuntimeException("unsigned mismatch in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   346
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   347
              if (type.getSuperclass() == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   348
                if (superclassName != null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   349
                  if (type.getSize() == -1) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   350
                    type.setSuperclass(lookupType(superclassName));
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   351
                  } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   352
                    throw new RuntimeException("unexpected superclass in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   353
                  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   354
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   355
              } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   356
                if (superclassName == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   357
                  throw new RuntimeException("missing superclass in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   358
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   359
                if (!type.getSuperclass().getName().equals(superclassName)) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   360
                  throw new RuntimeException("incorrect superclass in type definition: " + typeName);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   361
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   362
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   363
              if (type.getSize() != size) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   364
                if (type.getSize() == -1 || type.getSize() == 0) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   365
                  type.setSize(size);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   366
                } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   367
                  throw new RuntimeException("size mismatch in type definition: " + typeName + ": " + type.getSize() + " != " + size);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   368
                }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   369
              }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   370
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   371
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   372
            if (lookupType(typeName, false) == null) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   373
              // Create type
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   374
              createType(typeName, superclassName, isOop, isInteger, isUnsigned, size);
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   375
            }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   376
          } else {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   377
            throw new InternalError("\"" + t.sval + "\"");
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   378
          }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   379
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   380
      } catch (IOException ioe) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   381
        ioe.printStackTrace();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   382
      } finally {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   383
        try {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   384
          in.close();
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   385
        } catch (Exception e) {
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   386
        }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   387
      }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   388
    }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   389
  }
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   390
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  private void readVMStructs() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    // Get the variables we need in order to traverse the VMStructEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    long structEntryTypeNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    long structEntryFieldNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    long structEntryTypeStringOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    long structEntryIsStaticOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    long structEntryOffsetOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    long structEntryAddressOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    long structEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    structEntryTypeNameOffset     = getLongValueFromProcess("gHotSpotVMStructEntryTypeNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    structEntryFieldNameOffset    = getLongValueFromProcess("gHotSpotVMStructEntryFieldNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    structEntryTypeStringOffset   = getLongValueFromProcess("gHotSpotVMStructEntryTypeStringOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    structEntryIsStaticOffset     = getLongValueFromProcess("gHotSpotVMStructEntryIsStaticOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    structEntryOffsetOffset       = getLongValueFromProcess("gHotSpotVMStructEntryOffsetOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    structEntryAddressOffset      = getLongValueFromProcess("gHotSpotVMStructEntryAddressOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
    structEntryArrayStride        = getLongValueFromProcess("gHotSpotVMStructEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   409
    if (structEntryArrayStride == 0L) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   410
      throw new RuntimeException("zero stride: cannot read types.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   411
    }
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   412
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    // Fetch the address of the VMStructEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    Address entryAddr = lookupInProcess("gHotSpotVMStructs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    // Dereference this once to get the pointer to the first VMStructEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
      throw new RuntimeException("gHotSpotVMStructs was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    Address fieldNameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    String typeName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    String fieldName = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    String typeString = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    boolean isStatic = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    long offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    Address staticFieldAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    long size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    long index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    String opaqueName = "<opaque>";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    lookupOrCreateClass(opaqueName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
      // Fetch the field name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      fieldNameAddr = entryAddr.getAddressAt(structEntryFieldNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      if (fieldNameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        fieldName = CStringUtilities.getString(fieldNameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
        // Now the rest of the names. Keep in mind that the type name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
        // may be NULL, indicating that the type is opaque.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
        Address addr = entryAddr.getAddressAt(structEntryTypeNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
          throw new RuntimeException("gHotSpotVMStructs unexpectedly had a NULL type name at index " + index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        typeName = CStringUtilities.getString(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        addr = entryAddr.getAddressAt(structEntryTypeStringOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        if (addr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
          typeString = opaqueName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
          typeString = CStringUtilities.getString(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
        isStatic = !(entryAddr.getCIntegerAt(structEntryIsStaticOffset, C_INT32_SIZE, false) == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
        if (isStatic) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
          staticFieldAddr = entryAddr.getAddressAt(structEntryAddressOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
          offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
          offset = entryAddr.getCIntegerAt(structEntryOffsetOffset, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
          staticFieldAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
        // The containing Type must already be in the database -- no exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
        BasicType containingType = lookupOrFail(typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
        // 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
   468
        BasicType fieldType = (BasicType)lookupType(typeString);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
        // Create field by type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
        createField(containingType, fieldName, fieldType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
                    isStatic, offset, staticFieldAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      ++index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
      entryAddr = entryAddr.addOffsetTo(structEntryArrayStride);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    } while (fieldNameAddr != null);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  private void readVMIntConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    // Get the variables we need in order to traverse the VMIntConstantEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    long intConstantEntryNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    long intConstantEntryValueOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
    long intConstantEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    intConstantEntryNameOffset  = getLongValueFromProcess("gHotSpotVMIntConstantEntryNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    intConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMIntConstantEntryValueOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    intConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMIntConstantEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   490
    if (intConstantEntryArrayStride == 0L) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   491
      throw new RuntimeException("zero stride: cannot read types.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   492
    }
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   493
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   494
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    // Fetch the address of the VMIntConstantEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    Address entryAddr = lookupInProcess("gHotSpotVMIntConstants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    // Dereference this once to get the pointer to the first VMIntConstantEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
      throw new RuntimeException("gHotSpotVMIntConstants was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    Address nameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      nameAddr = entryAddr.getAddressAt(intConstantEntryNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      if (nameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
        String name = CStringUtilities.getString(nameAddr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
        int value = (int) entryAddr.getCIntegerAt(intConstantEntryValueOffset, C_INT32_SIZE, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
        // Be a little resilient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
        Integer oldValue = lookupIntConstant(name, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
        if (oldValue == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
          addIntConstant(name, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
          if (oldValue.intValue() != value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
            throw new RuntimeException("Error: the integer constant \"" + name +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
                                       "\" had its value redefined (old was " + oldValue +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
                                       ", new is " + value + ". Aborting.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
            System.err.println("Warning: the int constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMIntConstants) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
                               "had its value declared as " + value + " twice. Continuing.");
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   524
            duplicateDefCount++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      entryAddr = entryAddr.addOffsetTo(intConstantEntryArrayStride);
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   530
    } while (nameAddr != null && duplicateDefCount < MAX_DUPLICATE_DEFINITIONS);
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   531
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   532
    if (duplicateDefCount >= MAX_DUPLICATE_DEFINITIONS) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   533
      throw new RuntimeException("too many duplicate definitions");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   534
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  private void readVMLongConstants() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
    // Get the variables we need in order to traverse the VMLongConstantEntry[]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
    long longConstantEntryNameOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    long longConstantEntryValueOffset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
    long longConstantEntryArrayStride;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    longConstantEntryNameOffset  = getLongValueFromProcess("gHotSpotVMLongConstantEntryNameOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    longConstantEntryValueOffset = getLongValueFromProcess("gHotSpotVMLongConstantEntryValueOffset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    longConstantEntryArrayStride = getLongValueFromProcess("gHotSpotVMLongConstantEntryArrayStride");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   547
    if (longConstantEntryArrayStride == 0L) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   548
      throw new RuntimeException("zero stride: cannot read types.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   549
    }
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   550
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    // Fetch the address of the VMLongConstantEntry*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    Address entryAddr = lookupInProcess("gHotSpotVMLongConstants");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    // Dereference this once to get the pointer to the first VMLongConstantEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    entryAddr = entryAddr.getAddressAt(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    if (entryAddr == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
      throw new RuntimeException("gHotSpotVMLongConstants was not initialized properly in the remote process; can not continue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    // Start iterating down it until we find an entry with no name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    Address nameAddr = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
      // Fetch the type name first
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
      nameAddr = entryAddr.getAddressAt(longConstantEntryNameOffset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      if (nameAddr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
        String name = CStringUtilities.getString(nameAddr);
50107
300e4a88c400 8195613: [SA] HotSpotTypeDataBase.readVMLongConstants truncates values to int
jgeorge
parents: 47216
diff changeset
   566
        long value = entryAddr.getCIntegerAt(longConstantEntryValueOffset, C_INT64_SIZE, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        // Be a little resilient
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
        Long oldValue = lookupLongConstant(name, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
        if (oldValue == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
          addLongConstant(name, value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
          if (oldValue.longValue() != value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
            throw new RuntimeException("Error: the long constant \"" + name +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
                                       "\" had its value redefined (old was " + oldValue +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
                                       ", new is " + value + ". Aborting.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
            System.err.println("Warning: the long constant \"" + name + "\" (declared in the remote VM in VMStructs::localHotSpotVMLongConstants) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
                               "had its value declared as " + value + " twice. Continuing.");
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   580
            duplicateDefCount++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      entryAddr = entryAddr.addOffsetTo(longConstantEntryArrayStride);
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   586
    } while (nameAddr != null && duplicateDefCount < MAX_DUPLICATE_DEFINITIONS);
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   587
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   588
    if (duplicateDefCount >= MAX_DUPLICATE_DEFINITIONS) {
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   589
      throw new RuntimeException("too many duplicate definitions.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   590
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  private BasicType lookupOrFail(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    BasicType type = (BasicType) lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
      throw new RuntimeException("Type \"" + typeName + "\", referenced in VMStructs::localHotSpotVMStructs in the remote VM, " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
                                 "was not present in the remote VMStructs::localHotSpotVMTypes table (should have been caught " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
                                 "in the debug build of that VM). Can not continue.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  private long getLongValueFromProcess(String symbol) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    return lookupInProcess(symbol).getCIntegerAt(0, C_INT64_SIZE, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  private Address lookupInProcess(String symbol) throws NoSuchSymbolException {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    // FIXME: abstract away the loadobject name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    for (int i = 0; i < jvmLibNames.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
      Address addr = symbolLookup.lookup(jvmLibNames[i], symbol);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      if (addr != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
        return addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    String errStr = "(";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    for (int i = 0; i < jvmLibNames.length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      errStr += jvmLibNames[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
      if (i < jvmLibNames.length - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
        errStr += ", ";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    errStr += ")";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    throw new NoSuchSymbolException(symbol,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
                                    "Could not find symbol \"" + symbol +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
                                    "\" in any of the known library names " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
                                    errStr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  private BasicType lookupOrCreateClass(String typeName, boolean isOopType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
                                        boolean isIntegerType, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    BasicType type = (BasicType) lookupType(typeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
    if (type == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      // Create a new type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
      type = createBasicType(typeName, isOopType, isIntegerType, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  /** Creates a new BasicType, initializes its size to -1 so we can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
      test to ensure that all types' sizes are initialized by VMTypes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
      and adds it to the database. Takes care of initializing integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      and oop types properly. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  private BasicType createBasicType(String typeName, boolean isOopType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
                                    boolean isIntegerType, boolean isUnsigned) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    BasicType type = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    if (isIntegerType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
      type = new BasicCIntegerType(this, typeName, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
      if (typeNameIsPointerType(typeName)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
        type = recursiveCreateBasicPointerType(typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
        type = new BasicType(this, typeName);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
      if (isOopType) {
57777
90ead0febf56 8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents: 50107
diff changeset
   658
        type.setIsOopType(true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    type.setSize(UNINITIALIZED_SIZE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    addType(type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    return type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  /** Recursively creates a PointerType from the string representation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      of the type's name. Note that this currently needs some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      workarounds due to incomplete information in the VMStructs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
      database. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  private BasicPointerType recursiveCreateBasicPointerType(String typeName) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   672
    BasicPointerType result = (BasicPointerType)super.lookupType(typeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   673
    if (result != null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   674
      return result;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   675
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    String targetTypeName = typeName.substring(0, typeName.lastIndexOf('*')).trim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    Type targetType = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    if (typeNameIsPointerType(targetTypeName)) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   679
      targetType = lookupType(targetTypeName, false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   680
      if (targetType == null) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   681
        targetType = recursiveCreateBasicPointerType(targetTypeName);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   682
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      targetType = lookupType(targetTypeName, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      if (targetType == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
        // Workaround for missing C integer types in database.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
        // Also looks like we can't throw an exception for other
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
        // missing target types because there are some in old
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        // VMStructs tables that didn't have the target type declared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
        // For this case, we create basic types that never get filled
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
        // in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
        if (targetTypeName.equals("char") ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
            targetTypeName.equals("const char")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
          // We don't have a representation of const-ness of C types in the SA
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
          BasicType basicTargetType = createBasicType(targetTypeName, false, true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
          basicTargetType.setSize(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
          targetType = basicTargetType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
        } else if (targetTypeName.equals("u_char")) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
          BasicType basicTargetType = createBasicType(targetTypeName, false, true, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
          basicTargetType.setSize(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
          targetType = basicTargetType;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
          if (DEBUG) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
            System.err.println("WARNING: missing target type \"" + targetTypeName + "\" for pointer type \"" + typeName + "\"");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
          targetType = createBasicType(targetTypeName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    }
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   711
    result = new BasicPointerType(this, typeName, targetType);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   712
    if (pointerSize == UNINITIALIZED_SIZE && !typeName.equals("void*")) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   713
      // void* must be declared early so that other pointer types can use that to set their size.
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   714
      throw new InternalError("void* type hasn't been seen when parsing " + typeName);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   715
    }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   716
    result.setSize(pointerSize);
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   717
    addType(result);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7696
diff changeset
   718
    return result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  private boolean typeNameIsPointerType(String typeName) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    int i = typeName.length() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
    while (i >= 0 && Character.isWhitespace(typeName.charAt(i))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
      --i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
    if (i >= 0 && typeName.charAt(i) == '*') {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
    public void createType(String typeName, String superclassName,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
                           boolean isOopType, boolean isIntegerType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
                           boolean isUnsigned, long size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
        // See whether we have a superclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
        BasicType superclass = null;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
        if (superclassName != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
            // Fetch or create it (FIXME: would get oop types wrong if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
            // they had a hierarchy; consider using lookupOrFail)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
            superclass = lookupOrCreateClass(superclassName, false, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
        // Lookup or create the current type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
        BasicType curType = lookupOrCreateClass(typeName, isOopType, isIntegerType, isUnsigned);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
        // Set superclass and/or ensure it's correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
        if (superclass != null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
            if (curType.getSuperclass() == null) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
                // Set the superclass in the current type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
                curType.setSuperclass(superclass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
            if (curType.getSuperclass() != superclass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
                throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
                                           "had its superclass redefined (old was " + curType.getSuperclass().getName() + ", new is " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
                                           superclass.getName() + ").");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
        // Classes are created with a size of UNINITIALIZED_SIZE.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
        // Set size if necessary.
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 8921
diff changeset
   761
        if (curType.getSize() == UNINITIALIZED_SIZE || curType.getSize() == 0) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
            curType.setSize(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
            if (curType.getSize() != size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
                throw new RuntimeException("Error: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
                                           "had its size redefined (old was " + curType.getSize() + ", new is " + size + ").");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   769
            if (!typeNameIsPointerType(typeName)) {
29457
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   770
                System.err.println("Warning: the type \"" + typeName + "\" (declared in the remote VM in VMStructs::localHotSpotVMTypes) " +
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   771
                                   "had its size declared as " + size + " twice. Continuing.");
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   772
                duplicateDefCount++;
7cfe74042cef 8073688: Infinite loop reading types during jmap attach.
kevinw
parents: 13728
diff changeset
   773
            }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 10547
diff changeset
   774
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    /** "Virtual constructor" for fields based on type */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
    public void createField(BasicType containingType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
                            String name, Type type, boolean isStatic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
                            long offset, Address staticFieldAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
        // Add field to containing type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
        containingType.addField(internalCreateField(containingType, name, type, isStatic, offset, staticFieldAddress));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    Field internalCreateField(BasicType containingType,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
                              String name, Type type, boolean isStatic,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
                              long offset, Address staticFieldAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
    // "Virtual constructor" based on type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    if (type.isOopType()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
      return new BasicOopField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
                               isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
    if (type instanceof CIntegerType) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
      return new BasicCIntegerField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
                                    isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    if (type.equals(getJBooleanType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
      return new BasicJBooleanField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
                                    isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    if (type.equals(getJByteType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
      return new BasicJByteField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    if (type.equals(getJCharType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      return new BasicJCharField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    if (type.equals(getJDoubleType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      return new BasicJDoubleField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
                                   isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    if (type.equals(getJFloatType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      return new BasicJFloatField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
                                  isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    if (type.equals(getJIntType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      return new BasicJIntField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
                                isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    if (type.equals(getJLongType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      return new BasicJLongField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
                                 isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    if (type.equals(getJShortType())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
      return new BasicJShortField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
                                  isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    // Unknown ("opaque") type. Instantiate ordinary Field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
    return new BasicField(this, containingType, name, type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
                          isStatic, offset, staticFieldAddress);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  // For debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  private void dumpMemory(Address addr, int len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
    while (i < len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
      System.err.print(addr.addOffsetTo(i) + ":");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
      for (int j = 0; j < 8 && i < len; i++, j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
        String s = Long.toHexString(addr.getCIntegerAt(i, 1, true));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
        System.err.print(" 0x");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
        for (int k = 0; k < 2 - s.length(); k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
          System.err.print("0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
        System.err.print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
      System.err.println();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
}