annotate agent/src/share/classes/sun/jvm/hotspot/utilities/ObjectReader.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children d8a240abb23a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2007, 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: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
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.utilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.lang.reflect.Modifier;
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.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.runtime.*;
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 /**
a61af66fc99e Initial load
duke
parents:
diff changeset
35 * ObjectReader can "deserialize" objects from debuggee.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 *
a61af66fc99e Initial load
duke
parents:
diff changeset
37 * Class Loading:
a61af66fc99e Initial load
duke
parents:
diff changeset
38 *
a61af66fc99e Initial load
duke
parents:
diff changeset
39 * ObjectReader loads classes using the given class loader. If no
a61af66fc99e Initial load
duke
parents:
diff changeset
40 * class loader is supplied, it uses a ProcImageClassLoader, which
a61af66fc99e Initial load
duke
parents:
diff changeset
41 * loads classes from debuggee core or process.
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 * Object creation:
a61af66fc99e Initial load
duke
parents:
diff changeset
44 *
a61af66fc99e Initial load
duke
parents:
diff changeset
45 * This class uses no-arg constructor to construct objects. But if
a61af66fc99e Initial load
duke
parents:
diff changeset
46 * there is no no-arg constructor in a given class, then it tries to
a61af66fc99e Initial load
duke
parents:
diff changeset
47 * use other constructors with 'default' values - null for object
a61af66fc99e Initial load
duke
parents:
diff changeset
48 * types, 0, 0.0, false etc. for primitives. If this process fails to
a61af66fc99e Initial load
duke
parents:
diff changeset
49 * construct an instance (because of null checking by constructor or 0
a61af66fc99e Initial load
duke
parents:
diff changeset
50 * being invalid for an int arg etc.), then null is returned. While
a61af66fc99e Initial load
duke
parents:
diff changeset
51 * constructing complete object graph 'null' is inserted silently on
a61af66fc99e Initial load
duke
parents:
diff changeset
52 * failure and the deserialization continues to construct best-effort
a61af66fc99e Initial load
duke
parents:
diff changeset
53 * object graph.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 *
a61af66fc99e Initial load
duke
parents:
diff changeset
55 * Debug messages:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 *
a61af66fc99e Initial load
duke
parents:
diff changeset
57 * The flag sun.jvm.hotspot.utilities.ObjectReader.DEBUG may be set to
a61af66fc99e Initial load
duke
parents:
diff changeset
58 * non-null to get debug error messages and stack traces.
a61af66fc99e Initial load
duke
parents:
diff changeset
59 *
a61af66fc99e Initial load
duke
parents:
diff changeset
60 * JDK version:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 *
a61af66fc99e Initial load
duke
parents:
diff changeset
62 * JDK classes are loaded by bootstrap class loader and not by the
a61af66fc99e Initial load
duke
parents:
diff changeset
63 * supplied class loader or ProcImageClassLoader. This may create
a61af66fc99e Initial load
duke
parents:
diff changeset
64 * problems if a JDK class evolves. i.e., if SA runs a JDK version
a61af66fc99e Initial load
duke
parents:
diff changeset
65 * different from that of the debuggee, there is a possibility of
a61af66fc99e Initial load
duke
parents:
diff changeset
66 * schema change. It is recommended that the matching JDK version be
a61af66fc99e Initial load
duke
parents:
diff changeset
67 * used to run SA for proper object deserialization.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 *
a61af66fc99e Initial load
duke
parents:
diff changeset
69 */
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public class ObjectReader {
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private static final boolean DEBUG;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 DEBUG = System.getProperty("sun.jvm.hotspot.utilities.ObjectReader.DEBUG") != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 public ObjectReader(ClassLoader cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 this.cl = cl;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 this.oopToObjMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 this.fieldMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 public ObjectReader() {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 this(new ProcImageClassLoader());
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public Object readObject(Oop oop) throws ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 if (oop instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return readInstance((Instance) oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 } else if (oop instanceof TypeArray){
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return readPrimitiveArray((TypeArray)oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 } else if (oop instanceof ObjArray){
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return readObjectArray((ObjArray)oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 protected final Object getDefaultPrimitiveValue(Class clz) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (clz == Boolean.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return Boolean.FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else if (clz == Character.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return new Character(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
105 } else if (clz == Byte.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return new Byte((byte) 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else if (clz == Short.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return new Short((short) 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else if (clz == Integer.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return new Integer(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 } else if (clz == Long.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return new Long(0L);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } else if (clz == Float.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return new Float(0.0f);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else if (clz == Double.TYPE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return new Double(0.0);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 throw new RuntimeException("should not reach here!");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 protected Symbol javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 protected Symbol javaLangString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 if (javaLangString == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 javaLangString = VM.getVM().getSymbolTable().probe("java/lang/String");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public Object readInstance(Instance oop) throws ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Object result = getFromObjTable(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 InstanceKlass kls = (InstanceKlass) oop.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Handle java.lang.String instances differently. As part of JSR-133, fields of immutable
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // classes have been made final. The algorithm below will not be able to read Strings from
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // debuggee (can't use reflection to set final fields). But, need to read Strings is very
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // important. FIXME: need a framework to handle many other special cases.
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (kls.getName().equals(javaLangString())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return OopUtilities.stringOopToString(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 Class clz = readClass(kls);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 result = clz.newInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // no-arg constructor failed to create object. Let us try
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // to call constructors one-by-one with default arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // (null for objects, 0/0.0 etc. for primitives) till we
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // succeed or fail on all constructors.
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 java.lang.reflect.Constructor[] ctrs = clz.getDeclaredConstructors();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 for (int n = 0; n < ctrs.length; n++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 java.lang.reflect.Constructor c = ctrs[n];
a61af66fc99e Initial load
duke
parents:
diff changeset
154 Class[] paramTypes = c.getParameterTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
155 Object[] params = new Object[paramTypes.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
156 for (int i = 0; i < params.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 if (paramTypes[i].isPrimitive()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 params[i] = getDefaultPrimitiveValue(paramTypes[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 c.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 result = c.newInstance(params);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 System.err.println("Can't create object using " + c);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 exp.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (result != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 putIntoObjTable(oop, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
176 oop.iterate(new FieldSetter(result), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public Object readPrimitiveArray(final TypeArray array) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 Object result = getFromObjTable(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 int length = (int) array.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 TypeArrayKlass klass = (TypeArrayKlass) array.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 int type = (int) klass.getElementType();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 case TypeArrayKlass.T_BOOLEAN: {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 final boolean[] arrayObj = new boolean[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
192 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 public void doBoolean(BooleanField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
195 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
198 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 case TypeArrayKlass.T_CHAR: {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 final char[] arrayObj = new char[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
204 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 public void doChar(CharField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 case TypeArrayKlass.T_FLOAT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 final float[] arrayObj = new float[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
216 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 public void doFloat(FloatField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
219 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
225
a61af66fc99e Initial load
duke
parents:
diff changeset
226 case TypeArrayKlass.T_DOUBLE: {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 final double[] arrayObj = new double[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
228 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 public void doDouble(DoubleField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
230 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
231 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
234 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 case TypeArrayKlass.T_BYTE: {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 final byte[] arrayObj = new byte[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
240 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 public void doByte(ByteField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
246 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
248 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 case TypeArrayKlass.T_SHORT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 final short[] arrayObj = new short[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
252 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 public void doShort(ShortField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
258 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
261
a61af66fc99e Initial load
duke
parents:
diff changeset
262 case TypeArrayKlass.T_INT: {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 final int[] arrayObj = new int[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
264 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public void doInt(IntField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 }
a61af66fc99e Initial load
duke
parents:
diff changeset
272 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
273
a61af66fc99e Initial load
duke
parents:
diff changeset
274 case TypeArrayKlass.T_LONG: {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 final long[] arrayObj = new long[length];
a61af66fc99e Initial load
duke
parents:
diff changeset
276 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 public void doLong(LongField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
279 arrayObj[ifd.getIndex()] = field.getValue(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
284 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
287 throw new RuntimeException("should not reach here!");
a61af66fc99e Initial load
duke
parents:
diff changeset
288 }
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 putIntoObjTable(array, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 protected final boolean isRobust(OopHandle handle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 return RobustOopDeterminator.oopLooksValid(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 public Object readObjectArray(final ObjArray array) throws ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 Object result = getFromObjTable(array);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 int length = (int) array.getLength();
a61af66fc99e Initial load
duke
parents:
diff changeset
303 ObjArrayKlass klass = (ObjArrayKlass) array.getKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
304 Klass bottomKls = klass.getBottomKlass();
a61af66fc99e Initial load
duke
parents:
diff changeset
305 Class bottomCls = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 final int dimension = (int) klass.getDimension();
a61af66fc99e Initial load
duke
parents:
diff changeset
307 int[] dimArray = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
308 if (bottomKls instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 bottomCls = readClass((InstanceKlass) bottomKls);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 dimArray = new int[dimension];
a61af66fc99e Initial load
duke
parents:
diff changeset
311 } else { // instanceof TypeArrayKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
312 TypeArrayKlass botKls = (TypeArrayKlass) bottomKls;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 dimArray = new int[dimension -1];
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 // initialize the length
a61af66fc99e Initial load
duke
parents:
diff changeset
316 dimArray[0] = length;
a61af66fc99e Initial load
duke
parents:
diff changeset
317 final Object[] arrayObj = (Object[]) java.lang.reflect.Array.newInstance(bottomCls, dimArray);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 putIntoObjTable(array, arrayObj);
a61af66fc99e Initial load
duke
parents:
diff changeset
319 result = arrayObj;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 array.iterate(new DefaultOopVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
321 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 OopHandle handle = field.getValueAsOopHandle(getObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
323 if (! isRobust(handle)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 IndexableFieldIdentifier ifd = (IndexableFieldIdentifier) field.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
328 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
329 arrayObj[ifd.getIndex()] = readObject(field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
330 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
331 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
332 System.err.println("Array element set failed for " + ifd);
a61af66fc99e Initial load
duke
parents:
diff changeset
333 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337 }, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
340 }
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 protected class FieldSetter extends DefaultOopVisitor {
a61af66fc99e Initial load
duke
parents:
diff changeset
343 protected Object obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 public FieldSetter(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
346 this.obj = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 private void printFieldSetError(java.lang.reflect.Field f, Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (f != null) System.err.println("Field set failed for " + f);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 ex.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Callback methods for each field type in an object
a61af66fc99e Initial load
duke
parents:
diff changeset
357 public void doOop(OopField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 OopHandle handle = field.getValueAsOopHandle(getObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
359 if (! isRobust(handle) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
360 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
366 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
368 f.set(obj, readObject(field.getValue(getObj())));
a61af66fc99e Initial load
duke
parents:
diff changeset
369 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
370 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 public void doByte(ByteField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
378 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 f.setByte(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
381 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 public void doChar(CharField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
387 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
389 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
390 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
392 f.setChar(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
393 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
394 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 public void doBoolean(BooleanField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
400 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
401 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
402 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
403 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
404 f.setBoolean(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
405 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
409
a61af66fc99e Initial load
duke
parents:
diff changeset
410 public void doShort(ShortField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
411 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
413 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
416 f.setShort(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
417 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
418 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 public void doInt(IntField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
428 f.setInt(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
429 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
430 printFieldSetError(f, ex);
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 public void doLong(LongField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
436 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
439 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 f.setLong(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
441 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 public void doFloat(FloatField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
450 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
451 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
452 f.setFloat(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
453 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
454 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 public void doDouble(DoubleField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 java.lang.reflect.Field f = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
461 f = readField(field);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (Modifier.isFinal(f.getModifiers())) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
463 f.setAccessible(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
464 f.setDouble(obj, field.getValue(getObj()));
a61af66fc99e Initial load
duke
parents:
diff changeset
465 } catch (Exception ex) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 printFieldSetError(f, ex);
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
469
a61af66fc99e Initial load
duke
parents:
diff changeset
470 public void doCInt(CIntField field, boolean isVMField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 throw new RuntimeException("should not reach here!");
a61af66fc99e Initial load
duke
parents:
diff changeset
472 }
a61af66fc99e Initial load
duke
parents:
diff changeset
473 }
a61af66fc99e Initial load
duke
parents:
diff changeset
474
a61af66fc99e Initial load
duke
parents:
diff changeset
475 public Class readClass(InstanceKlass kls) throws ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 Class cls = (Class) getFromObjTable(kls);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 if (cls == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
478 cls = Class.forName(kls.getName().asString().replace('/', '.'), true, cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
479 putIntoObjTable(kls, cls);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481 return cls;
a61af66fc99e Initial load
duke
parents:
diff changeset
482 }
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 public Object readMethodOrConstructor(sun.jvm.hotspot.oops.Method m)
a61af66fc99e Initial load
duke
parents:
diff changeset
485 throws NoSuchMethodException, ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
486 String name = m.getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
487 if (name.equals("<init>")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 return readConstructor(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
490 return readMethod(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
492 }
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 public java.lang.reflect.Method readMethod(sun.jvm.hotspot.oops.Method m)
a61af66fc99e Initial load
duke
parents:
diff changeset
495 throws NoSuchMethodException, ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 java.lang.reflect.Method result = (java.lang.reflect.Method) getFromObjTable(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
497 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
498 Class clz = readClass((InstanceKlass)m.getMethodHolder());
a61af66fc99e Initial load
duke
parents:
diff changeset
499 String name = m.getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
500 Class[] paramTypes = getParamTypes(m.getSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
501 result = clz.getMethod(name, paramTypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 putIntoObjTable(m, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
505 }
a61af66fc99e Initial load
duke
parents:
diff changeset
506
a61af66fc99e Initial load
duke
parents:
diff changeset
507 public java.lang.reflect.Constructor readConstructor(sun.jvm.hotspot.oops.Method m)
a61af66fc99e Initial load
duke
parents:
diff changeset
508 throws NoSuchMethodException, ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
509 java.lang.reflect.Constructor result = (java.lang.reflect.Constructor) getFromObjTable(m);
a61af66fc99e Initial load
duke
parents:
diff changeset
510 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
511 Class clz = readClass((InstanceKlass)m.getMethodHolder());
a61af66fc99e Initial load
duke
parents:
diff changeset
512 String name = m.getName().asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
513 Class[] paramTypes = getParamTypes(m.getSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
514 result = clz.getDeclaredConstructor(paramTypes);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 putIntoObjTable(m, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519
a61af66fc99e Initial load
duke
parents:
diff changeset
520 public java.lang.reflect.Field readField(sun.jvm.hotspot.oops.Field f)
a61af66fc99e Initial load
duke
parents:
diff changeset
521 throws NoSuchFieldException, ClassNotFoundException {
a61af66fc99e Initial load
duke
parents:
diff changeset
522 java.lang.reflect.Field result = (java.lang.reflect.Field) fieldMap.get(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
523 if (result == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 FieldIdentifier fieldId = f.getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
525 Class clz = readClass((InstanceKlass) f.getFieldHolder());
a61af66fc99e Initial load
duke
parents:
diff changeset
526 String name = fieldId.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
528 result = clz.getField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 } catch (NoSuchFieldException nsfe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
530 result = clz.getDeclaredField(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 fieldMap.put(f, result);
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
536
a61af66fc99e Initial load
duke
parents:
diff changeset
537 protected final ClassLoader cl;
a61af66fc99e Initial load
duke
parents:
diff changeset
538 protected Map oopToObjMap; // Map<Oop, Object>
a61af66fc99e Initial load
duke
parents:
diff changeset
539 protected Map fieldMap; // Map<sun.jvm.hotspot.oops.Field, java.lang.reflect.Field>
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 protected void putIntoObjTable(Oop oop, Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
542 oopToObjMap.put(oop, obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 }
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 protected Object getFromObjTable(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
546 return oopToObjMap.get(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548
a61af66fc99e Initial load
duke
parents:
diff changeset
549 protected class SignatureParser extends SignatureIterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
550 protected Vector tmp = new Vector(); // Vector<Class>
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 public SignatureParser(Symbol s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 super(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 public void doBool () { tmp.add(Boolean.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
557 public void doChar () { tmp.add(Character.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
558 public void doFloat () { tmp.add(Float.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
559 public void doDouble() { tmp.add(Double.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
560 public void doByte () { tmp.add(Byte.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
561 public void doShort () { tmp.add(Short.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
562 public void doInt () { tmp.add(Integer.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
563 public void doLong () { tmp.add(Long.TYPE); }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 public void doVoid () {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 if(isReturnType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 tmp.add(Void.TYPE);
a61af66fc99e Initial load
duke
parents:
diff changeset
567 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 throw new RuntimeException("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
569 }
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572 public void doObject(int begin, int end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
573 tmp.add(getClass(begin, end));
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575
a61af66fc99e Initial load
duke
parents:
diff changeset
576 public void doArray (int begin, int end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
577 int inner = arrayInnerBegin(begin);
a61af66fc99e Initial load
duke
parents:
diff changeset
578 Class elemCls = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
579 switch (_signature.getByteAt(inner)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
580 case 'B': elemCls = Boolean.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
581 case 'C': elemCls = Character.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
582 case 'D': elemCls = Double.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
583 case 'F': elemCls = Float.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 case 'I': elemCls = Integer.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
585 case 'J': elemCls = Long.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
586 case 'S': elemCls = Short.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 case 'Z': elemCls = Boolean.TYPE; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 case 'L': elemCls = getClass(inner + 1, end); break;
a61af66fc99e Initial load
duke
parents:
diff changeset
589 default: break;
a61af66fc99e Initial load
duke
parents:
diff changeset
590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 int dimension = inner - begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // create 0 x 0 ... array and get class from that
a61af66fc99e Initial load
duke
parents:
diff changeset
594 int[] dimArray = new int[dimension];
a61af66fc99e Initial load
duke
parents:
diff changeset
595 tmp.add(java.lang.reflect.Array.newInstance(elemCls, dimArray).getClass());
a61af66fc99e Initial load
duke
parents:
diff changeset
596 }
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 protected Class getClass(int begin, int end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 String className = getClassName(begin, end);
a61af66fc99e Initial load
duke
parents:
diff changeset
600 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
601 return Class.forName(className, true, cl);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 } catch (Exception e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if (DEBUG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 System.err.println("Can't load class " + className);
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606 throw new RuntimeException(e);
a61af66fc99e Initial load
duke
parents:
diff changeset
607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610 protected String getClassName(int begin, int end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
612 for (int i = begin; i < end; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
613 char c = (char) (_signature.getByteAt(i) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
614 if (c == '/') {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 buf.append('.');
a61af66fc99e Initial load
duke
parents:
diff changeset
616 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 buf.append(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
621 }
a61af66fc99e Initial load
duke
parents:
diff changeset
622
a61af66fc99e Initial load
duke
parents:
diff changeset
623 protected int arrayInnerBegin(int begin) {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 while (_signature.getByteAt(begin) == '[') {
a61af66fc99e Initial load
duke
parents:
diff changeset
625 ++begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
626 }
a61af66fc99e Initial load
duke
parents:
diff changeset
627 return begin;
a61af66fc99e Initial load
duke
parents:
diff changeset
628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
629
a61af66fc99e Initial load
duke
parents:
diff changeset
630 public int getNumParams() {
a61af66fc99e Initial load
duke
parents:
diff changeset
631 return tmp.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 public Enumeration getParamTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 return tmp.elements();
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 protected Class[] getParamTypes(Symbol signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 SignatureParser sp = new SignatureParser(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 sp.iterateParameters();
a61af66fc99e Initial load
duke
parents:
diff changeset
642 Class result[] = new Class[sp.getNumParams()];
a61af66fc99e Initial load
duke
parents:
diff changeset
643 Enumeration e = sp.getParamTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
644 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
645 while (e.hasMoreElements()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 result[i] = (Class) e.nextElement();
a61af66fc99e Initial load
duke
parents:
diff changeset
647 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
650 }
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }