annotate agent/src/share/classes/sun/jvm/hotspot/HotSpotTypeDataBase.java @ 2072:d6cd0d55d0b5

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