annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFactoryImpl.java @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents 63997f575155
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46 }
a61af66fc99e Initial load
duke
parents:
diff changeset
47 if (res != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 om.put(oop, new SoftReference(res));
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public JSJavaKlass newJSJavaKlass(Klass klass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 JSJavaKlass res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 if (klass instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 res = new JSJavaInstanceKlass((InstanceKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
57 } else if (klass instanceof ObjArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 res = new JSJavaObjArrayKlass((ObjArrayKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 } else if (klass instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 res = new JSJavaTypeArrayKlass((TypeArrayKlass) klass, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 if (res != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 om.put(klass, new SoftReference(res));
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
68 public JSJavaMethod newJSJavaMethod(Method method) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
69 JSJavaMethod res = new JSJavaMethod(method, this);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
70 if (res != null) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
71 om.put(method, new SoftReference(res));
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
72 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
73 return res;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
74 }
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 2411
diff changeset
75
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public JSJavaField newJSJavaField(Field field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (field == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return new JSJavaField(field, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public JSJavaThread newJSJavaThread(JavaThread jthread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (jthread == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return new JSJavaThread(jthread, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 public JSJavaFrame newJSJavaFrame(JavaVFrame jvf) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (jvf == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return new JSJavaFrame(jvf, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 public JSList newJSList(List list) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (list == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return new JSList(list, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 public JSMap newJSMap(Map map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 if (map == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 return new JSMap(map, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 }
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 public Object newJSJavaWrapper(Object item) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (item == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (item instanceof Oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return newJSJavaObject((Oop) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 } else if (item instanceof Field) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return newJSJavaField((Field) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else if (item instanceof JavaThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return newJSJavaThread((JavaThread) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 } else if (item instanceof JavaVFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return newJSJavaFrame((JavaVFrame) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 } else if (item instanceof List) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return newJSList((List) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } else if (item instanceof Map) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return newJSMap((Map) item);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // not-a-special-type, just return the input item
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 public JSJavaHeap newJSJavaHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return new JSJavaHeap(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public JSJavaVM newJSJavaVM() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return new JSJavaVM(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // -- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private Symbol javaLangString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 if (javaLangString == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 javaLangString = getSymbol("java/lang/String");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 private Symbol javaLangThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 if (javaLangThread == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 javaLangThread = getSymbol("java/lang/Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 return javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 private Symbol javaLangClass() {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (javaLangClass == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 javaLangClass = getSymbol("java/lang/Class");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 private Symbol getSymbol(String str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return VM.getVM().getSymbolTable().probe(str);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 private JSJavaObject newJavaInstance(Instance instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // look for well-known classes
a61af66fc99e Initial load
duke
parents:
diff changeset
157 Symbol className = instance.getKlass().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Assert.that(className != null, "Null class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161 JSJavaObject res = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (className.equals(javaLangString())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 res = new JSJavaString(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 } else if (className.equals(javaLangThread())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 res = new JSJavaThread(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } 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
167 Klass reflectedType = java_lang_Class.asKlass(instance);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (reflectedType != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 JSJavaKlass jk = newJSJavaKlass(reflectedType);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // we don't support mirrors of VM internal Klasses
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (jk == null) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 res = new JSJavaClass(instance, jk, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
173 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 // for primitive Classes, the reflected type is null
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // not a well-known class. But the base class may be
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // one of the known classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Klass kls = instance.getKlass().getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 while (kls != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 className = kls.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // java.lang.Class and java.lang.String are final classes
a61af66fc99e Initial load
duke
parents:
diff changeset
184 if (className.equals(javaLangThread())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 res = new JSJavaThread(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 kls = kls.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 if (res == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 res = new JSJavaInstance(instance, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 }
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Map<Oop, SoftReference<JSJavaObject>>
a61af66fc99e Initial load
duke
parents:
diff changeset
198 private Map om = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
199 private Symbol javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 private Symbol javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 private Symbol javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }