annotate agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java @ 6725:da91efe96a93

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