annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFactoryImpl.java @ 2411:63997f575155

7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue Reviewed-by: kvn, dcubed
author never
date Wed, 30 Mar 2011 07:47:19 -0700
parents c18cbe5936b8
children da91efe96a93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
2 * Copyright (c) 2004, 2011, 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.soql;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.lang.ref.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class JSJavaFactoryImpl implements JSJavaFactory {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 public JSJavaObject newJSJavaObject(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 if (oop == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 SoftReference sref = (SoftReference) om.get(oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
37 JSJavaObject res = (sref != null)? (JSJavaObject) sref.get() : null;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 if (res == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 if (oop instanceof TypeArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 res = new JSJavaTypeArray((TypeArray)oop, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 } else if (oop instanceof ObjArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 res = new JSJavaObjArray((ObjArray)oop, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 } else if (oop instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 res = newJavaInstance((Instance) oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 } else if (oop instanceof Method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 res = new JSJavaMethod((Method) oop, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (res != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 om.put(oop, new SoftReference(res));
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public JSJavaKlass newJSJavaKlass(Klass klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 JSJavaKlass res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 if (klass instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 res = new JSJavaInstanceKlass((InstanceKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 } else if (klass instanceof ObjArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 res = new JSJavaObjArrayKlass((ObjArrayKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 } else if (klass instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 res = new JSJavaTypeArrayKlass((TypeArrayKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if (res != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 om.put(klass, new SoftReference(res));
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 public JSJavaField newJSJavaField(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 if (field == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return new JSJavaField(field, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public JSJavaThread newJSJavaThread(JavaThread jthread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (jthread == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return new JSJavaThread(jthread, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public JSJavaFrame newJSJavaFrame(JavaVFrame jvf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (jvf == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return new JSJavaFrame(jvf, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 public JSList newJSList(List list) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (list == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return new JSList(list, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 }
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 public JSMap newJSMap(Map map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (map == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return new JSMap(map, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 public Object newJSJavaWrapper(Object item) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (item == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (item instanceof Oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return newJSJavaObject((Oop) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 } else if (item instanceof Field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return newJSJavaField((Field) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 } else if (item instanceof JavaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return newJSJavaThread((JavaThread) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 } else if (item instanceof JavaVFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return newJSJavaFrame((JavaVFrame) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 } else if (item instanceof List) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return newJSList((List) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else if (item instanceof Map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return newJSMap((Map) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // not-a-special-type, just return the input item
a61af66fc99e Initial load
duke
parents:
diff changeset
111 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 public JSJavaHeap newJSJavaHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return new JSJavaHeap(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public JSJavaVM newJSJavaVM() {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return new JSJavaVM(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // -- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private Symbol javaLangString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (javaLangString == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 javaLangString = getSymbol("java/lang/String");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128 return javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 private Symbol javaLangThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (javaLangThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 javaLangThread = getSymbol("java/lang/Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 return javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 private Symbol javaLangClass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if (javaLangClass == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 javaLangClass = getSymbol("java/lang/Class");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 private Symbol getSymbol(String str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return VM.getVM().getSymbolTable().probe(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 private JSJavaObject newJavaInstance(Instance instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // look for well-known classes
a61af66fc99e Initial load
duke
parents:
diff changeset
151 Symbol className = instance.getKlass().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 Assert.that(className != null, "Null class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 JSJavaObject res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (className.equals(javaLangString())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 res = new JSJavaString(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else if (className.equals(javaLangThread())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 res = new JSJavaThread(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else if (className.equals(javaLangClass())) {
2411
63997f575155 7031614: jmap -permstat fails with java.lang.InternalError in sun.jvm.hotspot.oops.OopField.getValue
never
parents: 1552
diff changeset
161 Klass reflectedType = java_lang_Class.asKlass(instance);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (reflectedType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 JSJavaKlass jk = newJSJavaKlass(reflectedType);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 // we don't support mirrors of VM internal Klasses
a61af66fc99e Initial load
duke
parents:
diff changeset
165 if (jk == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 res = new JSJavaClass(instance, jk, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // for primitive Classes, the reflected type is null
a61af66fc99e Initial load
duke
parents:
diff changeset
169 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // not a well-known class. But the base class may be
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // one of the known classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
174 Klass kls = instance.getKlass().getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 while (kls != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 className = kls.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // java.lang.Class and java.lang.String are final classes
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (className.equals(javaLangThread())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 res = new JSJavaThread(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 kls = kls.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 if (res == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 res = new JSJavaInstance(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // Map<Oop, SoftReference<JSJavaObject>>
a61af66fc99e Initial load
duke
parents:
diff changeset
192 private Map om = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 private Symbol javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 private Symbol javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 private Symbol javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }