annotate agent/src/share/classes/sun/jvm/hotspot/ui/tree/CTypeTreeNodeAdapter.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 c18cbe5936b8
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: 1552
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.ui.tree;
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.oops.FieldIdentifier;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.oops.UnknownOopException;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.utilities.CStringUtilities;
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 /** Encapsulates an arbitrary type value in a tree handled by SimpleTreeModel */
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 public class CTypeTreeNodeAdapter extends FieldTreeNodeAdapter {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 final private Address addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 final private Type type;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private CTypeFieldIdentifier[] fields = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private void collectFields(Type type, ArrayList list, boolean statics, boolean recurse) {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 Type supertype = type.getSuperclass();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 if (supertype != null && recurse) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 collectFields(supertype, list, statics, recurse);
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 Iterator i = type.getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 while (i.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 Field f = (Field) i.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 if (f.isStatic() == statics) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 list.add(new CTypeFieldIdentifier(type, f));
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 private CTypeFieldIdentifier[] getFields() {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (fields == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 ArrayList f = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 collectFields(type, f, false, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 fields = (CTypeFieldIdentifier[]) f.toArray(new CTypeFieldIdentifier[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
63 }
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return fields;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 static class CTypeFieldIdentifier extends FieldIdentifier {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 final private Field field;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 final private Type holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 CTypeFieldIdentifier(Type t, Field f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 holder = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 field = f;
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 Field getField() {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return field;
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 String getName() {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return field.getType().getName() + " " + holder.getName() + "::" + field.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
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 CTypeTreeNodeAdapter(Address a, Type t, FieldIdentifier id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 this(a, t, id, false);
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 CTypeTreeNodeAdapter(Address a, Type t, FieldIdentifier id, boolean treeTableMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 super(id, treeTableMode);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 type = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 addr = a;
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 CTypeTreeNodeAdapter(Type t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 super(null, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
98 type = t;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 addr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ArrayList statics = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 collectFields(type, statics, true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 fields = (CTypeFieldIdentifier[])statics.toArray(new CTypeFieldIdentifier[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public CTypeTreeNodeAdapter(Iterator types) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 super(null, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 addr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 type = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 ArrayList statics = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
110 while (types.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 collectFields((Type)types.next(), statics, true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 fields = (CTypeFieldIdentifier[])statics.toArray(new CTypeFieldIdentifier[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 public int getChildCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return getFields().length;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 public SimpleTreeNode getChild(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 CTypeFieldIdentifier cf = getFields()[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
122 Field f = cf.getField();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Type t = f.getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (t.isOopType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 OopHandle handle;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 handle = f.getOopHandle();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 handle = f.getOopHandle(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 Oop oop = VM.getVM().getObjectHeap().newOop(handle);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return new OopTreeNodeAdapter(oop, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
135 } catch (AddressException e) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
136 return new BadAddressTreeNodeAdapter(handle,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
137 new CTypeFieldIdentifier(type, f),
a61af66fc99e Initial load
duke
parents:
diff changeset
138 getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
139 } catch (UnknownOopException e) {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 1552
diff changeset
140 return new BadAddressTreeNodeAdapter(handle,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 new CTypeFieldIdentifier(type, f),
a61af66fc99e Initial load
duke
parents:
diff changeset
142 getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 } else if (t.isCIntegerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 long value = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 value = f.getCInteger((CIntegerType)t);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 value = f.getCInteger(addr, (CIntegerType)t);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return new LongTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
152 } else if (t.isJavaPrimitiveType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 boolean isStatic = f.isStatic();
a61af66fc99e Initial load
duke
parents:
diff changeset
154 if (f instanceof JByteField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 long value = isStatic? f.getJByte() : f.getJByte(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return new LongTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
157 } else if (f instanceof JShortField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 long value = isStatic? f.getJShort() : f.getJShort(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 return new LongTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else if (f instanceof JIntField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 long value = isStatic? f.getJInt() : f.getJInt(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return new LongTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 } else if (f instanceof JLongField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 long value = isStatic? f.getJLong() : f.getJLong(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return new LongTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 } else if (f instanceof JCharField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 char value = isStatic? f.getJChar() : f.getJChar(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return new CharTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
169 } else if (f instanceof JBooleanField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 boolean value = isStatic? f.getJBoolean() : f.getJBoolean(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return new BooleanTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } else if (f instanceof JFloatField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
173 float value = isStatic? f.getJFloat() : f.getJFloat(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return new DoubleTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
175 } else if (f instanceof JDoubleField) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 double value = isStatic? f.getJDouble() : f.getJDouble(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 return new DoubleTreeNodeAdapter(value, cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 throw new RuntimeException("unhandled type: " + t.getName());
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 } else if (t.isPointerType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 Address ptr;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 ptr = f.getAddress();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 ptr = f.getAddress(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 if (t.isCStringType()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return new CStringTreeNodeAdapter(CStringUtilities.getString(ptr), cf);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return new CTypeTreeNodeAdapter(ptr, ((PointerType) t).getTargetType(), cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
194 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (f.isStatic()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 return new CTypeTreeNodeAdapter(f.getStaticFieldAddress(), f.getType(),
a61af66fc99e Initial load
duke
parents:
diff changeset
197 cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
198 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 return new CTypeTreeNodeAdapter(addr.addOffsetTo(f.getOffset()), f.getType(),
a61af66fc99e Initial load
duke
parents:
diff changeset
200 cf, getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return new BadAddressTreeNodeAdapter(e.getAddress(),
a61af66fc99e Initial load
duke
parents:
diff changeset
205 new CTypeFieldIdentifier(type, f),
a61af66fc99e Initial load
duke
parents:
diff changeset
206 getTreeTableMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 public boolean isLeaf() {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 return getFields().length == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 public int getIndexOfChild(SimpleTreeNode child) {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 CTypeFieldIdentifier id = (CTypeFieldIdentifier)((FieldTreeNodeAdapter) child).getID();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 CTypeFieldIdentifier[] f = getFields();
a61af66fc99e Initial load
duke
parents:
diff changeset
217 for (int i = 0; i < f.length; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (id == f[i]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
220 }
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222 return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 public String getValue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
226 if (type != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
227 return type.getName() + " @ " + addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return "<statics>";
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232 }