annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaFrame.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 0251d217257f
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: 6070
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.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
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
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public class JSJavaFrame extends DefaultScriptObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private static final int FIELD_METHOD = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final int FIELD_BCI = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int FIELD_LINE_NUMBER = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final int FIELD_LOCALS = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static final int FIELD_THIS_OBJECT = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static final int FIELD_THREAD = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static final int FIELD_UNDEFINED = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 public JSJavaFrame(JavaVFrame jvf, JSJavaFactory fac) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 this.jvf = jvf;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 this.factory = fac;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public Object get(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int fieldID = getFieldID(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
48 switch (fieldID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 case FIELD_METHOD:
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 case FIELD_BCI:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return new Integer(getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
53 case FIELD_LINE_NUMBER:
a61af66fc99e Initial load
duke
parents:
diff changeset
54 return new Integer(getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
55 case FIELD_LOCALS:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 return getLocals();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 case FIELD_THIS_OBJECT:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return getThisObject();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 case FIELD_THREAD:
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return getThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 case FIELD_UNDEFINED:
a61af66fc99e Initial load
duke
parents:
diff changeset
62 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return super.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public Object[] getIds() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 Object[] fieldNames = fields.keySet().toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Object[] superFields = super.getIds();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Object[] res = new Object[fieldNames.length + superFields.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
71 System.arraycopy(fieldNames, 0, res, 0, fieldNames.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 System.arraycopy(superFields, 0, res, fieldNames.length, superFields.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public boolean has(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (getFieldID(name) != FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return super.has(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
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 void put(String name, Object value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 if (getFieldID(name) == FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 super.put(name, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
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 String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 buf.append("Frame (method=");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 buf.append(jvf.getMethod().externalNameAndSignature());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 buf.append(", bci=");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 buf.append(getBCI());
a61af66fc99e Initial load
duke
parents:
diff changeset
96 buf.append(", line=");
a61af66fc99e Initial load
duke
parents:
diff changeset
97 buf.append(getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
98 buf.append(')');
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
103 private static Map fields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
104 private static void addField(String name, int fieldId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 fields.put(name, new Integer(fieldId));
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 private static int getFieldID(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 Integer res = (Integer) fields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return (res != null)? res.intValue() : FIELD_UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 addField("method", FIELD_METHOD);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 addField("bci", FIELD_BCI);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 addField("line", FIELD_LINE_NUMBER);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 addField("locals", FIELD_LOCALS);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 addField("thisObject", FIELD_THIS_OBJECT);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 addField("thread", FIELD_THREAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6070
diff changeset
122 private JSJavaMethod getMethod() {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6070
diff changeset
123 return factory.newJSJavaMethod(jvf.getMethod());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 private int getBCI() {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return jvf.getBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private int getLineNumber() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int bci = jvf.getBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 if (bci == -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 int lineNum = jvf.getMethod().getLineNumberFromBCI(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 return (lineNum <= 0)? 0 : lineNum;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 private synchronized JSMap getLocals() {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 if (localsCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
142 Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 localsCache = factory.newJSMap(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 StackValueCollection values = jvf.getLocals();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Method method = jvf.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (method.isNative() || ! method.hasLocalVariableTable() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
147 values == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 return localsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 LocalVariableTableElement[] localVars = method.getLocalVariableTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 int bci = getBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 List visibleVars = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (int i = 0; i < localVars.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 LocalVariableTableElement cur = localVars[i];
6070
0251d217257f 7162726: Wrong filter predicate of visible locals in SA JSJavaFrame
sla
parents: 1552
diff changeset
156 int startBCI = cur.getStartBCI();
0251d217257f 7162726: Wrong filter predicate of visible locals in SA JSJavaFrame
sla
parents: 1552
diff changeset
157 if (startBCI <= bci && bci < startBCI + cur.getLength()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
158 visibleVars.add(cur);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 OopHandle handle = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 ObjectHeap heap = VM.getVM().getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 for (Iterator varItr = visibleVars.iterator(); varItr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 LocalVariableTableElement cur = (LocalVariableTableElement) varItr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
166 String name = method.getConstants().getSymbolAt(cur.getNameCPIndex()).asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 int slot = cur.getSlot();
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 String signature = method.getConstants().getSymbolAt(cur.getDescriptorCPIndex()).asString();
a61af66fc99e Initial load
duke
parents:
diff changeset
170 BasicType variableType = BasicType.charToBasicType(signature.charAt(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Object value = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (variableType == BasicType.T_BOOLEAN) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 value = Boolean.valueOf(values.booleanAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
174 } else if (variableType == BasicType.T_CHAR) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 value = new Character(values.charAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else if (variableType == BasicType.T_FLOAT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 value = new Float(values.floatAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } else if (variableType == BasicType.T_DOUBLE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 value = new Double(values.doubleAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } else if (variableType == BasicType.T_BYTE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 value = new Byte(values.byteAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
182 } else if (variableType == BasicType.T_SHORT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
183 value = new Short(values.shortAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
184 } else if (variableType == BasicType.T_INT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 value = new Integer(values.intAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
186 } else if (variableType == BasicType.T_LONG) {
a61af66fc99e Initial load
duke
parents:
diff changeset
187 value = new Long(values.longAt(slot));
a61af66fc99e Initial load
duke
parents:
diff changeset
188 } else if (variableType == BasicType.T_OBJECT ||
a61af66fc99e Initial load
duke
parents:
diff changeset
189 variableType == BasicType.T_ARRAY) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 handle = values.oopHandleAt(slot);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 value = factory.newJSJavaObject(heap.newOop(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
192 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // ignore
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195 map.put(name, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 return localsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 private JSJavaObject getThisObject() {
a61af66fc99e Initial load
duke
parents:
diff changeset
202 Method method = jvf.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 if (method.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206 StackValueCollection values = jvf.getLocals();
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (values != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 // 'this' at index 0.
a61af66fc99e Initial load
duke
parents:
diff changeset
209 OopHandle handle = values.oopHandleAt(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
210 ObjectHeap heap = VM.getVM().getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return factory.newJSJavaObject(heap.newOop(handle));
a61af66fc99e Initial load
duke
parents:
diff changeset
212 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // can't get locals, return null.
a61af66fc99e Initial load
duke
parents:
diff changeset
214 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
217
a61af66fc99e Initial load
duke
parents:
diff changeset
218 private JSJavaThread getThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return factory.newJSJavaThread(jvf.getThread());
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 private final JavaVFrame jvf;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 private final JSJavaFactory factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
224 private JSMap localsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }