annotate agent/src/share/classes/sun/jvm/hotspot/jdi/VirtualMachineImpl.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 49036505ab5f
children 5a98bf7d847b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
5998
49036505ab5f 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 3939
diff changeset
2 * Copyright (c) 2002, 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.jdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import com.sun.jdi.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import com.sun.jdi.event.EventQueue;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import com.sun.jdi.request.EventRequestManager;
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.HotSpotAgent;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.types.TypeDataBase;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import sun.jvm.hotspot.oops.Klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.oops.InstanceKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.oops.ArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.oops.ObjArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.oops.TypeArrayKlass;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.oops.Oop;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.oops.Instance;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.oops.Array;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.oops.ObjArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.oops.TypeArray;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.oops.Symbol;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 import sun.jvm.hotspot.oops.ObjectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 import sun.jvm.hotspot.oops.DefaultHeapVisitor;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 import sun.jvm.hotspot.oops.JVMDIClassStatus;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 import sun.jvm.hotspot.runtime.VM;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 import sun.jvm.hotspot.runtime.JavaThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 import sun.jvm.hotspot.memory.SystemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 import sun.jvm.hotspot.memory.SymbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 import sun.jvm.hotspot.memory.Universe;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 import sun.jvm.hotspot.utilities.Assert;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 import java.util.List;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 import java.util.ArrayList;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 import java.util.Map;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 import java.util.Iterator;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 import java.util.Collections;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 import java.util.HashMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 import java.util.Observer;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 import java.util.StringTokenizer;
a61af66fc99e Initial load
duke
parents:
diff changeset
62 import java.lang.ref.SoftReference;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 import java.lang.ref.ReferenceQueue;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 import java.lang.ref.Reference;
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public class VirtualMachineImpl extends MirrorImpl implements PathSearchingVirtualMachine {
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 private HotSpotAgent saAgent = new HotSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 private VM saVM;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 private Universe saUniverse;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 private SystemDictionary saSystemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 private SymbolTable saSymbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 private ObjectHeap saObjectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 VM saVM() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return saVM;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 SystemDictionary saSystemDictionary() {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return saSystemDictionary;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82
a61af66fc99e Initial load
duke
parents:
diff changeset
83 SymbolTable saSymbolTable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return saSymbolTable;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Universe saUniverse() {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return saUniverse;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 ObjectHeap saObjectHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return saObjectHeap;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 com.sun.jdi.VirtualMachineManager vmmgr;
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 private final ThreadGroup threadGroupForJDI;
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // Per-vm singletons for primitive types and for void.
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // singleton-ness protected by "synchronized(this)".
a61af66fc99e Initial load
duke
parents:
diff changeset
101 private BooleanType theBooleanType;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 private ByteType theByteType;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 private CharType theCharType;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 private ShortType theShortType;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 private IntegerType theIntegerType;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 private LongType theLongType;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 private FloatType theFloatType;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 private DoubleType theDoubleType;
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 private VoidType theVoidType;
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private VoidValue voidVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private Map typesByID; // Map<Klass, ReferenceTypeImpl>
a61af66fc99e Initial load
duke
parents:
diff changeset
114 private List typesBySignature; // List<ReferenceTypeImpl> - used in signature search
a61af66fc99e Initial load
duke
parents:
diff changeset
115 private boolean retrievedAllTypes = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 private List bootstrapClasses; // all bootstrap classes
a61af66fc99e Initial load
duke
parents:
diff changeset
117 private ArrayList allThreads;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 private ArrayList topLevelGroups;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 final int sequenceNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // ObjectReference cache
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // "objectsByID" protected by "synchronized(this)".
a61af66fc99e Initial load
duke
parents:
diff changeset
123 private final Map objectsByID = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private final ReferenceQueue referenceQueue = new ReferenceQueue();
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // names of some well-known classes to jdi
a61af66fc99e Initial load
duke
parents:
diff changeset
127 private Symbol javaLangString;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 private Symbol javaLangThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 private Symbol javaLangThreadGroup;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private Symbol javaLangClass;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 private Symbol javaLangClassLoader;
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // used in ReferenceTypeImpl.isThrowableBacktraceField
a61af66fc99e Initial load
duke
parents:
diff changeset
134 private Symbol javaLangThrowable;
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // names of classes used in array assignment check
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // refer to ArrayTypeImpl.isAssignableTo
a61af66fc99e Initial load
duke
parents:
diff changeset
138 private Symbol javaLangObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 private Symbol javaLangCloneable;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 private Symbol javaIoSerializable;
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // symbol used in ClassTypeImpl.isEnum check
a61af66fc99e Initial load
duke
parents:
diff changeset
143 private Symbol javaLangEnum;
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Symbol javaLangObject() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return javaLangObject;
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 Symbol javaLangCloneable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 return javaLangCloneable;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 Symbol javaIoSerializable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return javaIoSerializable;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 Symbol javaLangEnum() {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return javaLangEnum;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 Symbol javaLangThrowable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return javaLangThrowable;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // name of the current default stratum
a61af66fc99e Initial load
duke
parents:
diff changeset
166 private String defaultStratum;
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // initialize known class name symbols
a61af66fc99e Initial load
duke
parents:
diff changeset
169 private void initClassNameSymbols() {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 SymbolTable st = saSymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 javaLangString = st.probe("java/lang/String");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 javaLangThread = st.probe("java/lang/Thread");
a61af66fc99e Initial load
duke
parents:
diff changeset
173 javaLangThreadGroup = st.probe("java/lang/ThreadGroup");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 javaLangClass = st.probe("java/lang/Class");
a61af66fc99e Initial load
duke
parents:
diff changeset
175 javaLangClassLoader = st.probe("java/lang/ClassLoader");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 javaLangThrowable = st.probe("java/lang/Throwable");
a61af66fc99e Initial load
duke
parents:
diff changeset
177 javaLangObject = st.probe("java/lang/Object");
a61af66fc99e Initial load
duke
parents:
diff changeset
178 javaLangCloneable = st.probe("java/lang/Cloneable");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 javaIoSerializable = st.probe("java/io/Serializable");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 javaLangEnum = st.probe("java/lang/Enum");
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 private void init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 saVM = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 saUniverse = saVM.getUniverse();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 saSystemDictionary = saVM.getSystemDictionary();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 saSymbolTable = saVM.getSymbolTable();
a61af66fc99e Initial load
duke
parents:
diff changeset
188 saObjectHeap = saVM.getObjectHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
189 initClassNameSymbols();
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 static public VirtualMachineImpl createVirtualMachineForCorefile(VirtualMachineManager mgr,
a61af66fc99e Initial load
duke
parents:
diff changeset
193 String javaExecutableName,
a61af66fc99e Initial load
duke
parents:
diff changeset
194 String coreFileName,
a61af66fc99e Initial load
duke
parents:
diff changeset
195 int sequenceNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
196 throws Exception {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 Assert.that(coreFileName != null, "SA VirtualMachineImpl: core filename = null is not yet implemented");
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Assert.that(javaExecutableName != null, "SA VirtualMachineImpl: java executable = null is not yet implemented");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 myvm.saAgent.attach(javaExecutableName, coreFileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 myvm.init();
a61af66fc99e Initial load
duke
parents:
diff changeset
208 } catch (Exception ee) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 myvm.saAgent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
210 throw ee;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return myvm;
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 static public VirtualMachineImpl createVirtualMachineForPID(VirtualMachineManager mgr,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 int pid,
a61af66fc99e Initial load
duke
parents:
diff changeset
217 int sequenceNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
218 throws Exception {
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
221 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 myvm.saAgent.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 myvm.init();
a61af66fc99e Initial load
duke
parents:
diff changeset
224 } catch (Exception ee) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 myvm.saAgent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 throw ee;
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 return myvm;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 static public VirtualMachineImpl createVirtualMachineForServer(VirtualMachineManager mgr,
a61af66fc99e Initial load
duke
parents:
diff changeset
232 String server,
a61af66fc99e Initial load
duke
parents:
diff changeset
233 int sequenceNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
234 throws Exception {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 Assert.that(server != null, "SA VirtualMachineImpl: DebugServer = null is not yet implemented");
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
240 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
241 myvm.saAgent.attach(server);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 myvm.init();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 } catch (Exception ee) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 myvm.saAgent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
245 throw ee;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 return myvm;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250
a61af66fc99e Initial load
duke
parents:
diff changeset
251 VirtualMachineImpl(VirtualMachineManager mgr, int sequenceNumber)
a61af66fc99e Initial load
duke
parents:
diff changeset
252 throws Exception {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 super(null); // Can't use super(this)
a61af66fc99e Initial load
duke
parents:
diff changeset
254 vm = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 this.sequenceNumber = sequenceNumber;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 this.vmmgr = mgr;
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 /* Create ThreadGroup to be used by all threads servicing
a61af66fc99e Initial load
duke
parents:
diff changeset
260 * this VM.
a61af66fc99e Initial load
duke
parents:
diff changeset
261 */
a61af66fc99e Initial load
duke
parents:
diff changeset
262 threadGroupForJDI = new ThreadGroup("JDI [" +
a61af66fc99e Initial load
duke
parents:
diff changeset
263 this.hashCode() + "]");
a61af66fc99e Initial load
duke
parents:
diff changeset
264
a61af66fc99e Initial load
duke
parents:
diff changeset
265 ((com.sun.tools.jdi.VirtualMachineManagerImpl)mgr).addVirtualMachine(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // we reflectively use newly spec'ed class because our ALT_BOOTDIR
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // is 1.4.2 and not 1.5.
a61af66fc99e Initial load
duke
parents:
diff changeset
270 private static Class vmCannotBeModifiedExceptionClass = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void throwNotReadOnlyException(String operation) {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 RuntimeException re = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 if (vmCannotBeModifiedExceptionClass == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 vmCannotBeModifiedExceptionClass = Class.forName("com.sun.jdi.VMCannotBeModifiedException");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 } catch (ClassNotFoundException cnfe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 vmCannotBeModifiedExceptionClass = UnsupportedOperationException.class;
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
281 re = (RuntimeException) vmCannotBeModifiedExceptionClass.newInstance();
a61af66fc99e Initial load
duke
parents:
diff changeset
282 } catch (Exception exp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
283 re = new RuntimeException(exp.getMessage());
a61af66fc99e Initial load
duke
parents:
diff changeset
284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
285 throw re;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 }
a61af66fc99e Initial load
duke
parents:
diff changeset
287
a61af66fc99e Initial load
duke
parents:
diff changeset
288 public boolean equals(Object obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // Oh boy; big recursion troubles if we don't have this!
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // See MirrorImpl.equals
a61af66fc99e Initial load
duke
parents:
diff changeset
291 return this == obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 public int hashCode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // big recursion if we don't have this. See MirrorImpl.hashCode
a61af66fc99e Initial load
duke
parents:
diff changeset
296 return System.identityHashCode(this);
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 List classesByName(String className) {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 String signature = JNITypeParser.typeNameToSignature(className);
a61af66fc99e Initial load
duke
parents:
diff changeset
301 List list;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 if (!retrievedAllTypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 retrieveAllClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 list = findReferenceTypes(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
306 return Collections.unmodifiableList(list);
a61af66fc99e Initial load
duke
parents:
diff changeset
307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
308
a61af66fc99e Initial load
duke
parents:
diff changeset
309 public List allClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (!retrievedAllTypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 retrieveAllClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 ArrayList a;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 synchronized (this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 a = new ArrayList(typesBySignature);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 return Collections.unmodifiableList(a);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // classes loaded by bootstrap loader
a61af66fc99e Initial load
duke
parents:
diff changeset
321 List bootstrapClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
322 if (bootstrapClasses == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 bootstrapClasses = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
324 List all = allClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
325 for (Iterator itr = all.iterator(); itr.hasNext();) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 ReferenceType type = (ReferenceType) itr.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
327 if (type.classLoader() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 bootstrapClasses.add(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 return bootstrapClasses;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 }
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 private synchronized List findReferenceTypes(String signature) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (typesByID == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 return new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // we haven't sorted types by signatures. But we can take
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // advantage of comparing symbols instead of name. In the worst
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // case, we will be comparing N addresses rather than N strings
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // where N being total no. of classes in allClasses() list.
a61af66fc99e Initial load
duke
parents:
diff changeset
344
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // The signature could be Lx/y/z; or [....
a61af66fc99e Initial load
duke
parents:
diff changeset
346 // If it is Lx/y/z; the internal type name is x/y/x
a61af66fc99e Initial load
duke
parents:
diff changeset
347 // for array klasses internal type name is same as
a61af66fc99e Initial load
duke
parents:
diff changeset
348 // signature
a61af66fc99e Initial load
duke
parents:
diff changeset
349 String typeName = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
350 if (signature.charAt(0) == 'L') {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 typeName = signature.substring(1, signature.length() - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 typeName = signature;
a61af66fc99e Initial load
duke
parents:
diff changeset
354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
355
a61af66fc99e Initial load
duke
parents:
diff changeset
356 Symbol typeNameSym = saSymbolTable().probe(typeName);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // if there is no symbol in VM, then we wouldn't have that type
a61af66fc99e Initial load
duke
parents:
diff changeset
358 if (typeNameSym == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
359 return new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 Iterator iter = typesBySignature.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 List list = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
364 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // We have cached type name as symbol in reference type
a61af66fc99e Initial load
duke
parents:
diff changeset
366 ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
367 if (typeNameSym.equals(type.typeNameAsSymbol())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 list.add(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 return list;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 }
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 private void retrieveAllClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 final List saKlasses = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
376 SystemDictionary.ClassVisitor visitor = new SystemDictionary.ClassVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 public void visit(Klass k) {
a61af66fc99e Initial load
duke
parents:
diff changeset
378 for (Klass l = k; l != null; l = l.arrayKlassOrNull()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
379 // for non-array classes filter out un-prepared classes
a61af66fc99e Initial load
duke
parents:
diff changeset
380 // refer to 'allClasses' in share/back/VirtualMachineImpl.c
a61af66fc99e Initial load
duke
parents:
diff changeset
381 if (l instanceof ArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 saKlasses.add(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 int status = l.getClassStatus();
a61af66fc99e Initial load
duke
parents:
diff changeset
385 if ((status & JVMDIClassStatus.PREPARED) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
386 saKlasses.add(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
391 };
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 // refer to jvmtiGetLoadedClasses.cpp - getLoadedClasses in VM code.
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // classes from SystemDictionary
a61af66fc99e Initial load
duke
parents:
diff changeset
396 saSystemDictionary.classesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // From SystemDictionary we do not get primitive single
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // dimensional array classes. add primitive single dimensional array
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // klasses from Universe.
a61af66fc99e Initial load
duke
parents:
diff changeset
401 saVM.getUniverse().basicTypeClassesDo(visitor);
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 // Hold lock during processing to improve performance
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // and to have safe check/set of retrievedAllTypes
a61af66fc99e Initial load
duke
parents:
diff changeset
405 synchronized (this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
406 if (!retrievedAllTypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // Number of classes
a61af66fc99e Initial load
duke
parents:
diff changeset
408 int count = saKlasses.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
409 for (int ii = 0; ii < count; ii++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 Klass kk = (Klass)saKlasses.get(ii);
a61af66fc99e Initial load
duke
parents:
diff changeset
411 ReferenceTypeImpl type = referenceType(kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
412 }
a61af66fc99e Initial load
duke
parents:
diff changeset
413 retrievedAllTypes = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 }
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 ReferenceTypeImpl referenceType(Klass kk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 ReferenceTypeImpl retType = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
420 synchronized (this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 if (typesByID != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
422 retType = (ReferenceTypeImpl)typesByID.get(kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 if (retType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 retType = addReferenceType(kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 return retType;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
430
a61af66fc99e Initial load
duke
parents:
diff changeset
431 private void initReferenceTypes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 typesByID = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
433 typesBySignature = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
435
a61af66fc99e Initial load
duke
parents:
diff changeset
436 private synchronized ReferenceTypeImpl addReferenceType(Klass kk) {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 if (typesByID == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
438 initReferenceTypes();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 ReferenceTypeImpl newRefType = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 if (kk instanceof ObjArrayKlass || kk instanceof TypeArrayKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
442 newRefType = new ArrayTypeImpl(this, (ArrayKlass)kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 } else if (kk instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
444 if (kk.isInterface()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
445 newRefType = new InterfaceTypeImpl(this, (InstanceKlass)kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
446 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 newRefType = new ClassTypeImpl(this, (InstanceKlass)kk);
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449 } else {
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 5998
diff changeset
450 throw new RuntimeException("should not reach here:" + kk);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
452
a61af66fc99e Initial load
duke
parents:
diff changeset
453 typesByID.put(kk, newRefType);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 typesBySignature.add(newRefType);
a61af66fc99e Initial load
duke
parents:
diff changeset
455 return newRefType;
a61af66fc99e Initial load
duke
parents:
diff changeset
456 }
a61af66fc99e Initial load
duke
parents:
diff changeset
457
a61af66fc99e Initial load
duke
parents:
diff changeset
458 ThreadGroup threadGroupForJDI() {
a61af66fc99e Initial load
duke
parents:
diff changeset
459 return threadGroupForJDI;
a61af66fc99e Initial load
duke
parents:
diff changeset
460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 public void redefineClasses(Map classToBytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 throwNotReadOnlyException("VirtualMachineImpl.redefineClasses()");
a61af66fc99e Initial load
duke
parents:
diff changeset
464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 private List getAllThreads() {
a61af66fc99e Initial load
duke
parents:
diff changeset
467 if (allThreads == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 allThreads = new ArrayList(10); // Might be enough, might not be
a61af66fc99e Initial load
duke
parents:
diff changeset
469 for (sun.jvm.hotspot.runtime.JavaThread thread =
a61af66fc99e Initial load
duke
parents:
diff changeset
470 saVM.getThreads().first(); thread != null;
a61af66fc99e Initial load
duke
parents:
diff changeset
471 thread = thread.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 // refer to JvmtiEnv::GetAllThreads in jvmtiEnv.cpp.
a61af66fc99e Initial load
duke
parents:
diff changeset
473 // filter out the hidden-from-external-view threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
474 if (thread.isHiddenFromExternalView() == false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
475 ThreadReferenceImpl myThread = threadMirror(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
476 allThreads.add(myThread);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 return allThreads;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 public List allThreads() { //fixme jjh
a61af66fc99e Initial load
duke
parents:
diff changeset
484 return Collections.unmodifiableList(getAllThreads());
a61af66fc99e Initial load
duke
parents:
diff changeset
485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 public void suspend() {
a61af66fc99e Initial load
duke
parents:
diff changeset
488 throwNotReadOnlyException("VirtualMachineImpl.suspend()");
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 public void resume() {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 throwNotReadOnlyException("VirtualMachineImpl.resume()");
a61af66fc99e Initial load
duke
parents:
diff changeset
493 }
a61af66fc99e Initial load
duke
parents:
diff changeset
494
a61af66fc99e Initial load
duke
parents:
diff changeset
495 public List topLevelThreadGroups() { //fixme jjh
a61af66fc99e Initial load
duke
parents:
diff changeset
496 // The doc for ThreadGroup says that The top-level thread group
a61af66fc99e Initial load
duke
parents:
diff changeset
497 // is the only thread group whose parent is null. This means there is
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // only one top level thread group. There will be a thread in this
a61af66fc99e Initial load
duke
parents:
diff changeset
499 // group so we will just find a thread whose threadgroup has no parent
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // and that will be it.
a61af66fc99e Initial load
duke
parents:
diff changeset
501
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (topLevelGroups == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
503 topLevelGroups = new ArrayList(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
504 Iterator myIt = getAllThreads().iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
505 while (myIt.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
506 ThreadReferenceImpl myThread = (ThreadReferenceImpl)myIt.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
507 ThreadGroupReference myGroup = myThread.threadGroup();
a61af66fc99e Initial load
duke
parents:
diff changeset
508 ThreadGroupReference myParent = myGroup.parent();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 if (myGroup.parent() == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
510 topLevelGroups.add(myGroup);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
513 }
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515 return Collections.unmodifiableList(topLevelGroups);
a61af66fc99e Initial load
duke
parents:
diff changeset
516 }
a61af66fc99e Initial load
duke
parents:
diff changeset
517
a61af66fc99e Initial load
duke
parents:
diff changeset
518 public EventQueue eventQueue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 throwNotReadOnlyException("VirtualMachine.eventQueue()");
a61af66fc99e Initial load
duke
parents:
diff changeset
520 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 public EventRequestManager eventRequestManager() {
a61af66fc99e Initial load
duke
parents:
diff changeset
524 throwNotReadOnlyException("VirtualMachineImpl.eventRequestManager()");
a61af66fc99e Initial load
duke
parents:
diff changeset
525 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
526 }
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 public BooleanValue mirrorOf(boolean value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
529 return new BooleanValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 public ByteValue mirrorOf(byte value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
533 return new ByteValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 public CharValue mirrorOf(char value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
537 return new CharValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
539
a61af66fc99e Initial load
duke
parents:
diff changeset
540 public ShortValue mirrorOf(short value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
541 return new ShortValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 public IntegerValue mirrorOf(int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 return new IntegerValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
546 }
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 public LongValue mirrorOf(long value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
549 return new LongValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
550 }
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552 public FloatValue mirrorOf(float value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 return new FloatValueImpl(this,value);
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 DoubleValue mirrorOf(double value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
557 return new DoubleValueImpl(this,value);
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 public StringReference mirrorOf(String value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 throwNotReadOnlyException("VirtualMachinestop.mirrorOf(String)");
a61af66fc99e Initial load
duke
parents:
diff changeset
562 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 public VoidValue mirrorOfVoid() {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 if (voidVal == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
567 voidVal = new VoidValueImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 }
a61af66fc99e Initial load
duke
parents:
diff changeset
569 return voidVal;
a61af66fc99e Initial load
duke
parents:
diff changeset
570 }
a61af66fc99e Initial load
duke
parents:
diff changeset
571
a61af66fc99e Initial load
duke
parents:
diff changeset
572
a61af66fc99e Initial load
duke
parents:
diff changeset
573 public Process process() {
a61af66fc99e Initial load
duke
parents:
diff changeset
574 throwNotReadOnlyException("VirtualMachine.process");
a61af66fc99e Initial load
duke
parents:
diff changeset
575 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577
a61af66fc99e Initial load
duke
parents:
diff changeset
578 // dispose observer for Class re-use. refer to ConnectorImpl.
a61af66fc99e Initial load
duke
parents:
diff changeset
579 private Observer disposeObserver;
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 // ConnectorImpl loaded by a different class loader can not access it.
a61af66fc99e Initial load
duke
parents:
diff changeset
582 // i.e., runtime package of <ConnectorImpl, L1> is not the same that of
a61af66fc99e Initial load
duke
parents:
diff changeset
583 // <VirtualMachineImpl, L2> when L1 != L2. So, package private method
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // can be called reflectively after using setAccessible(true).
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 void setDisposeObserver(Observer observer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 disposeObserver = observer;
a61af66fc99e Initial load
duke
parents:
diff changeset
588 }
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 private void notifyDispose() {
a61af66fc99e Initial load
duke
parents:
diff changeset
591 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
592 Assert.that(disposeObserver != null, "null VM.dispose observer");
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594 disposeObserver.update(null, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596
a61af66fc99e Initial load
duke
parents:
diff changeset
597 public void dispose() {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 saAgent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
599 notifyDispose();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 public void exit(int exitCode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 throwNotReadOnlyException("VirtualMachine.exit(int)");
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 public boolean canBeModified() {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610 public boolean canWatchFieldModification() {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
613
a61af66fc99e Initial load
duke
parents:
diff changeset
614 public boolean canWatchFieldAccess() {
a61af66fc99e Initial load
duke
parents:
diff changeset
615 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
616 }
a61af66fc99e Initial load
duke
parents:
diff changeset
617
a61af66fc99e Initial load
duke
parents:
diff changeset
618 public boolean canGetBytecodes() {
a61af66fc99e Initial load
duke
parents:
diff changeset
619 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 public boolean canGetSyntheticAttribute() {
a61af66fc99e Initial load
duke
parents:
diff changeset
623 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
625
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // FIXME: For now, all monitor capabilities are disabled
a61af66fc99e Initial load
duke
parents:
diff changeset
627 public boolean canGetOwnedMonitorInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
628 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
630
a61af66fc99e Initial load
duke
parents:
diff changeset
631 public boolean canGetCurrentContendedMonitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
632 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
634
a61af66fc99e Initial load
duke
parents:
diff changeset
635 public boolean canGetMonitorInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
636 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
637 }
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 // because this SA works only with 1.5 and update releases
a61af66fc99e Initial load
duke
parents:
diff changeset
640 // this should always succeed unlike JVMDI/JDI.
a61af66fc99e Initial load
duke
parents:
diff changeset
641 public boolean canGet1_5LanguageFeatures() {
a61af66fc99e Initial load
duke
parents:
diff changeset
642 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 public boolean canUseInstanceFilters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
646 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
647 }
a61af66fc99e Initial load
duke
parents:
diff changeset
648
a61af66fc99e Initial load
duke
parents:
diff changeset
649 public boolean canRedefineClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
650 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
652
a61af66fc99e Initial load
duke
parents:
diff changeset
653 public boolean canAddMethod() {
a61af66fc99e Initial load
duke
parents:
diff changeset
654 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
656
a61af66fc99e Initial load
duke
parents:
diff changeset
657 public boolean canUnrestrictedlyRedefineClasses() {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
659 }
a61af66fc99e Initial load
duke
parents:
diff changeset
660
a61af66fc99e Initial load
duke
parents:
diff changeset
661 public boolean canPopFrames() {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
664
a61af66fc99e Initial load
duke
parents:
diff changeset
665 public boolean canGetSourceDebugExtension() {
a61af66fc99e Initial load
duke
parents:
diff changeset
666 // We can use InstanceKlass.getSourceDebugExtension only if
a61af66fc99e Initial load
duke
parents:
diff changeset
667 // ClassFileParser parsed the info. But, ClassFileParser parses
a61af66fc99e Initial load
duke
parents:
diff changeset
668 // SourceDebugExtension attribute only if corresponding JVMDI/TI
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // capability is set to true. Currently, vmStructs does not expose
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // JVMDI/TI capabilities and hence we conservatively assume false.
a61af66fc99e Initial load
duke
parents:
diff changeset
671 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
673
a61af66fc99e Initial load
duke
parents:
diff changeset
674 public boolean canRequestVMDeathEvent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
675 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
676 }
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
679 public boolean canForceEarlyReturn() {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
682
a61af66fc99e Initial load
duke
parents:
diff changeset
683 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
684 public boolean canGetConstantPool() {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
686 }
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
689 public boolean canGetClassFileVersion() {
a61af66fc99e Initial load
duke
parents:
diff changeset
690 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
692
a61af66fc99e Initial load
duke
parents:
diff changeset
693 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
694 public boolean canGetMethodReturnValues() {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697
a61af66fc99e Initial load
duke
parents:
diff changeset
698 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // Real body will be supplied later.
a61af66fc99e Initial load
duke
parents:
diff changeset
700 public boolean canGetInstanceInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
701 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
703
a61af66fc99e Initial load
duke
parents:
diff changeset
704 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
705 public boolean canUseSourceNameFilters() {
a61af66fc99e Initial load
duke
parents:
diff changeset
706 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
707 }
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
710 public boolean canRequestMonitorEvents() {
a61af66fc99e Initial load
duke
parents:
diff changeset
711 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 // new method since 1.6.
a61af66fc99e Initial load
duke
parents:
diff changeset
715 public boolean canGetMonitorFrameInfo() {
a61af66fc99e Initial load
duke
parents:
diff changeset
716 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
718
a61af66fc99e Initial load
duke
parents:
diff changeset
719 // new method since 1.6
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // Real body will be supplied later.
a61af66fc99e Initial load
duke
parents:
diff changeset
721 public long[] instanceCounts(List classes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 if (!canGetInstanceInfo()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
723 throw new UnsupportedOperationException(
a61af66fc99e Initial load
duke
parents:
diff changeset
724 "target does not support getting instances");
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727 final long[] retValue = new long[classes.size()] ;
a61af66fc99e Initial load
duke
parents:
diff changeset
728
a61af66fc99e Initial load
duke
parents:
diff changeset
729 final Klass [] klassArray = new Klass[classes.size()];
a61af66fc99e Initial load
duke
parents:
diff changeset
730
a61af66fc99e Initial load
duke
parents:
diff changeset
731 boolean allAbstractClasses = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
732 for (int i=0; i < classes.size(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
733 ReferenceTypeImpl rti = (ReferenceTypeImpl)classes.get(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
734 klassArray[i] = rti.ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
735 retValue[i]=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
736 if (!(rti.isAbstract() || ((ReferenceType)rti instanceof InterfaceType))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 allAbstractClasses = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
739 }
a61af66fc99e Initial load
duke
parents:
diff changeset
740
a61af66fc99e Initial load
duke
parents:
diff changeset
741 if (allAbstractClasses) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 return retValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
744 final int size = classes.size();
a61af66fc99e Initial load
duke
parents:
diff changeset
745 saObjectHeap.iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
746 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
747 for (int i=0; i < size; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
748 if (klassArray[i].equals(oop.getKlass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
749 retValue[i]++;
a61af66fc99e Initial load
duke
parents:
diff changeset
750 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
751 }
a61af66fc99e Initial load
duke
parents:
diff changeset
752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
753 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 });
a61af66fc99e Initial load
duke
parents:
diff changeset
756
a61af66fc99e Initial load
duke
parents:
diff changeset
757 return retValue;
a61af66fc99e Initial load
duke
parents:
diff changeset
758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 private List getPath (String pathName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
761 String cp = saVM.getSystemProperty(pathName);
a61af66fc99e Initial load
duke
parents:
diff changeset
762 String pathSep = saVM.getSystemProperty("path.separator");
a61af66fc99e Initial load
duke
parents:
diff changeset
763 ArrayList al = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
764 StringTokenizer st = new StringTokenizer(cp, pathSep);
a61af66fc99e Initial load
duke
parents:
diff changeset
765 while (st.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
766 al.add(st.nextToken());
a61af66fc99e Initial load
duke
parents:
diff changeset
767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
768 al.trimToSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
769 return al;
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772 public List classPath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
773 return getPath("java.class.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
774 }
a61af66fc99e Initial load
duke
parents:
diff changeset
775
a61af66fc99e Initial load
duke
parents:
diff changeset
776 public List bootClassPath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
777 return getPath("sun.boot.class.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
778 }
a61af66fc99e Initial load
duke
parents:
diff changeset
779
a61af66fc99e Initial load
duke
parents:
diff changeset
780 public String baseDirectory() {
a61af66fc99e Initial load
duke
parents:
diff changeset
781 return saVM.getSystemProperty("user.dir");
a61af66fc99e Initial load
duke
parents:
diff changeset
782 }
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 public void setDefaultStratum(String stratum) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 defaultStratum = stratum;
a61af66fc99e Initial load
duke
parents:
diff changeset
786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 public String getDefaultStratum() {
a61af66fc99e Initial load
duke
parents:
diff changeset
789 return defaultStratum;
a61af66fc99e Initial load
duke
parents:
diff changeset
790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
791
a61af66fc99e Initial load
duke
parents:
diff changeset
792 public String description() {
a61af66fc99e Initial load
duke
parents:
diff changeset
793 return java.text.MessageFormat.format(java.util.ResourceBundle.
a61af66fc99e Initial load
duke
parents:
diff changeset
794 getBundle("com.sun.tools.jdi.resources.jdi").getString("version_format"),
2471
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
795 "" + vmmgr.majorInterfaceVersion(),
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
796 "" + vmmgr.minorInterfaceVersion(),
37be97a58393 7010849: 5/5 Extraneous javac source/target options when building sa-jdi
andrew
parents: 1552
diff changeset
797 name());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
798 }
a61af66fc99e Initial load
duke
parents:
diff changeset
799
a61af66fc99e Initial load
duke
parents:
diff changeset
800 public String version() {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 return saVM.getSystemProperty("java.version");
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803
a61af66fc99e Initial load
duke
parents:
diff changeset
804 public String name() {
a61af66fc99e Initial load
duke
parents:
diff changeset
805 StringBuffer sb = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
806 sb.append("JVM version ");
a61af66fc99e Initial load
duke
parents:
diff changeset
807 sb.append(version());
a61af66fc99e Initial load
duke
parents:
diff changeset
808 sb.append(" (");
a61af66fc99e Initial load
duke
parents:
diff changeset
809 sb.append(saVM.getSystemProperty("java.vm.name"));
a61af66fc99e Initial load
duke
parents:
diff changeset
810 sb.append(", ");
a61af66fc99e Initial load
duke
parents:
diff changeset
811 sb.append(saVM.getSystemProperty("java.vm.info"));
a61af66fc99e Initial load
duke
parents:
diff changeset
812 sb.append(")");
a61af66fc99e Initial load
duke
parents:
diff changeset
813 return sb.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
815
a61af66fc99e Initial load
duke
parents:
diff changeset
816 // from interface Mirror
a61af66fc99e Initial load
duke
parents:
diff changeset
817 public VirtualMachine virtualMachine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
818 return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 public String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
822 return name();
a61af66fc99e Initial load
duke
parents:
diff changeset
823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
824
a61af66fc99e Initial load
duke
parents:
diff changeset
825 public void setDebugTraceMode(int traceFlags) {
a61af66fc99e Initial load
duke
parents:
diff changeset
826 // spec. says output is implementation dependent
a61af66fc99e Initial load
duke
parents:
diff changeset
827 // and trace mode may be ignored. we ignore it :-)
a61af66fc99e Initial load
duke
parents:
diff changeset
828 }
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 // heap walking API
a61af66fc99e Initial load
duke
parents:
diff changeset
831
a61af66fc99e Initial load
duke
parents:
diff changeset
832 // capability check
a61af66fc99e Initial load
duke
parents:
diff changeset
833 public boolean canWalkHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
834 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
835 }
a61af66fc99e Initial load
duke
parents:
diff changeset
836
a61af66fc99e Initial load
duke
parents:
diff changeset
837 // return a list of all objects in heap
a61af66fc99e Initial load
duke
parents:
diff changeset
838 public List/*<ObjectReference>*/ allObjects() {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 final List objects = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
840 saObjectHeap.iterate(
a61af66fc99e Initial load
duke
parents:
diff changeset
841 new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
842 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
843 objects.add(objectMirror(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
844 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
845 }
a61af66fc99e Initial load
duke
parents:
diff changeset
846 });
a61af66fc99e Initial load
duke
parents:
diff changeset
847 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 // equivalent to objectsByType(type, true)
a61af66fc99e Initial load
duke
parents:
diff changeset
851 public List/*<ObjectReference>*/ objectsByType(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 return objectsByType(type, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 }
a61af66fc99e Initial load
duke
parents:
diff changeset
854
a61af66fc99e Initial load
duke
parents:
diff changeset
855 // returns objects of type exactly equal to given type
a61af66fc99e Initial load
duke
parents:
diff changeset
856 private List/*<ObjectReference>*/ objectsByExactType(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
857 final List objects = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
858 final Klass givenKls = ((ReferenceTypeImpl)type).ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
859 saObjectHeap.iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
861 if (givenKls.equals(oop.getKlass())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
862 objects.add(objectMirror(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
863 }
a61af66fc99e Initial load
duke
parents:
diff changeset
864 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866 });
a61af66fc99e Initial load
duke
parents:
diff changeset
867 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
869
a61af66fc99e Initial load
duke
parents:
diff changeset
870 // returns objects of given type as well as it's subtypes
a61af66fc99e Initial load
duke
parents:
diff changeset
871 private List/*<ObjectReference>*/ objectsBySubType(ReferenceType type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 final List objects = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
873 final ReferenceType givenType = type;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 saObjectHeap.iterate(new DefaultHeapVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 public boolean doObj(Oop oop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
876 ReferenceTypeImpl curType = (ReferenceTypeImpl) referenceType(oop.getKlass());
a61af66fc99e Initial load
duke
parents:
diff changeset
877 if (curType.isAssignableTo(givenType)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 objects.add(objectMirror(oop));
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
882 });
a61af66fc99e Initial load
duke
parents:
diff changeset
883 return objects;
a61af66fc99e Initial load
duke
parents:
diff changeset
884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 // includeSubtypes - do you want to include subclass/subtype instances of given
a61af66fc99e Initial load
duke
parents:
diff changeset
887 // ReferenceType or do we want objects of exact type only?
a61af66fc99e Initial load
duke
parents:
diff changeset
888 public List/*<ObjectReference>*/ objectsByType(ReferenceType type, boolean includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
889 Klass kls = ((ReferenceTypeImpl)type).ref();
a61af66fc99e Initial load
duke
parents:
diff changeset
890 if (kls instanceof InstanceKlass) {
a61af66fc99e Initial load
duke
parents:
diff changeset
891 InstanceKlass ik = (InstanceKlass) kls;
5998
49036505ab5f 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 3939
diff changeset
892 // if the Klass is final or if there are no subklasses loaded yet
49036505ab5f 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 3939
diff changeset
893 if (ik.getAccessFlagsObj().isFinal() || ik.getSubklassKlass() == null) {
49036505ab5f 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 3939
diff changeset
894 includeSubtypes = false;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
896 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
897 // no subtypes for primitive array types
a61af66fc99e Initial load
duke
parents:
diff changeset
898 ArrayTypeImpl arrayType = (ArrayTypeImpl) type;
a61af66fc99e Initial load
duke
parents:
diff changeset
899 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
900 Type componentType = arrayType.componentType();
a61af66fc99e Initial load
duke
parents:
diff changeset
901 if (componentType instanceof PrimitiveType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
902 includeSubtypes = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
903 }
a61af66fc99e Initial load
duke
parents:
diff changeset
904 } catch (ClassNotLoadedException cnle) {
a61af66fc99e Initial load
duke
parents:
diff changeset
905 // ignore. component type not yet loaded
a61af66fc99e Initial load
duke
parents:
diff changeset
906 }
a61af66fc99e Initial load
duke
parents:
diff changeset
907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
908
a61af66fc99e Initial load
duke
parents:
diff changeset
909 if (includeSubtypes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
910 return objectsBySubType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
911 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
912 return objectsByExactType(type);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 }
a61af66fc99e Initial load
duke
parents:
diff changeset
914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916 Type findBootType(String signature) throws ClassNotLoadedException {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 List types = allClasses();
a61af66fc99e Initial load
duke
parents:
diff changeset
918 Iterator iter = types.iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
919 while (iter.hasNext()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
920 ReferenceType type = (ReferenceType)iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
921 if ((type.classLoader() == null) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
922 (type.signature().equals(signature))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
923 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925 }
a61af66fc99e Initial load
duke
parents:
diff changeset
926 JNITypeParser parser = new JNITypeParser(signature);
a61af66fc99e Initial load
duke
parents:
diff changeset
927 throw new ClassNotLoadedException(parser.typeName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
928 "Type " + parser.typeName() + " not loaded");
a61af66fc99e Initial load
duke
parents:
diff changeset
929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 BooleanType theBooleanType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 if (theBooleanType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
933 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 if (theBooleanType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
935 theBooleanType = new BooleanTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
937 }
a61af66fc99e Initial load
duke
parents:
diff changeset
938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
939 return theBooleanType;
a61af66fc99e Initial load
duke
parents:
diff changeset
940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
941
a61af66fc99e Initial load
duke
parents:
diff changeset
942 ByteType theByteType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
943 if (theByteType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
944 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
945 if (theByteType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 theByteType = new ByteTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
948 }
a61af66fc99e Initial load
duke
parents:
diff changeset
949 }
a61af66fc99e Initial load
duke
parents:
diff changeset
950 return theByteType;
a61af66fc99e Initial load
duke
parents:
diff changeset
951 }
a61af66fc99e Initial load
duke
parents:
diff changeset
952
a61af66fc99e Initial load
duke
parents:
diff changeset
953 CharType theCharType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
954 if (theCharType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
955 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 if (theCharType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 theCharType = new CharTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
958 }
a61af66fc99e Initial load
duke
parents:
diff changeset
959 }
a61af66fc99e Initial load
duke
parents:
diff changeset
960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
961 return theCharType;
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963
a61af66fc99e Initial load
duke
parents:
diff changeset
964 ShortType theShortType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
965 if (theShortType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
967 if (theShortType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
968 theShortType = new ShortTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
969 }
a61af66fc99e Initial load
duke
parents:
diff changeset
970 }
a61af66fc99e Initial load
duke
parents:
diff changeset
971 }
a61af66fc99e Initial load
duke
parents:
diff changeset
972 return theShortType;
a61af66fc99e Initial load
duke
parents:
diff changeset
973 }
a61af66fc99e Initial load
duke
parents:
diff changeset
974
a61af66fc99e Initial load
duke
parents:
diff changeset
975 IntegerType theIntegerType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
976 if (theIntegerType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
977 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 if (theIntegerType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 theIntegerType = new IntegerTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
981 }
a61af66fc99e Initial load
duke
parents:
diff changeset
982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
983 return theIntegerType;
a61af66fc99e Initial load
duke
parents:
diff changeset
984 }
a61af66fc99e Initial load
duke
parents:
diff changeset
985
a61af66fc99e Initial load
duke
parents:
diff changeset
986 LongType theLongType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
987 if (theLongType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
988 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
989 if (theLongType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 theLongType = new LongTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
991 }
a61af66fc99e Initial load
duke
parents:
diff changeset
992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
993 }
a61af66fc99e Initial load
duke
parents:
diff changeset
994 return theLongType;
a61af66fc99e Initial load
duke
parents:
diff changeset
995 }
a61af66fc99e Initial load
duke
parents:
diff changeset
996
a61af66fc99e Initial load
duke
parents:
diff changeset
997 FloatType theFloatType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
998 if (theFloatType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
999 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 if (theFloatType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 theFloatType = new FloatTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 return theFloatType;
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1007
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 DoubleType theDoubleType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 if (theDoubleType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 if (theDoubleType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 theDoubleType = new DoubleTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 return theDoubleType;
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1018
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 VoidType theVoidType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 if (theVoidType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 synchronized(this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 if (theVoidType == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 theVoidType = new VoidTypeImpl(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 return theVoidType;
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1029
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 PrimitiveType primitiveTypeMirror(char tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 switch (tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 case 'Z':
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 return theBooleanType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 case 'B':
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 return theByteType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 case 'C':
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 return theCharType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 return theShortType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 case 'I':
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 return theIntegerType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 case 'J':
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 return theLongType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 case 'F':
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 return theFloatType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 case 'D':
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 return theDoubleType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 throw new IllegalArgumentException("Unrecognized primitive tag " + tag);
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1052
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 private void processQueue() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 Reference ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 while ((ref = referenceQueue.poll()) != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 SoftObjectReference softRef = (SoftObjectReference)ref;
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 removeObjectMirror(softRef);
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1060
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 // Address value is used as uniqueID by ObjectReferenceImpl
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 long getAddressValue(Oop obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 return vm.saVM.getDebugger().getAddressValue(obj.getHandle());
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1065
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 synchronized ObjectReferenceImpl objectMirror(Oop key) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1067
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 // Handle any queue elements that are not strongly reachable
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 processQueue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 if (key == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 ObjectReferenceImpl object = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 * Attempt to retrieve an existing object object reference
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 SoftObjectReference ref = (SoftObjectReference)objectsByID.get(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 if (ref != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 object = ref.object();
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1083
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 * If the object wasn't in the table, or it's soft reference was
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 * cleared, create a new instance.
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 if (object == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 if (key instanceof Instance) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 // look for well-known classes
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 Symbol className = key.getKlass().getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 Assert.that(className != null, "Null class name");
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 Instance inst = (Instance) key;
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 if (className.equals(javaLangString)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 object = new StringReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 } else if (className.equals(javaLangThread)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 object = new ThreadReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 } else if (className.equals(javaLangThreadGroup)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 object = new ThreadGroupReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 } else if (className.equals(javaLangClass)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 object = new ClassObjectReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 } else if (className.equals(javaLangClassLoader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 object = new ClassLoaderReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 // not a well-known class. But the base class may be
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 // one of the known classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 Klass kls = key.getKlass().getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 while (kls != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 className = kls.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 // java.lang.Class and java.lang.String are final classes
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 if (className.equals(javaLangThread)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 object = new ThreadReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 } else if(className.equals(javaLangThreadGroup)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 object = new ThreadGroupReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 } else if (className.equals(javaLangClassLoader)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 object = new ClassLoaderReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 kls = kls.getSuper();
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1125
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 if (object == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 // create generic object reference
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 object = new ObjectReferenceImpl(this, inst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 } else if (key instanceof TypeArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 object = new ArrayReferenceImpl(this, (Array) key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 } else if (key instanceof ObjArray) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 object = new ArrayReferenceImpl(this, (Array) key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 throw new RuntimeException("unexpected object type " + key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 ref = new SoftObjectReference(key, object, referenceQueue);
a61af66fc99e Initial load
duke
parents:
diff changeset
1139
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 * If there was no previous entry in the table, we add one here
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 * If the previous entry was cleared, we replace it here.
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 objectsByID.put(key, ref);
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 ref.incrementCount();
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1148
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 return object;
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 synchronized void removeObjectMirror(SoftObjectReference ref) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 * This will remove the soft reference if it has not been
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 * replaced in the cache.
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 objectsByID.remove(ref.key());
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1159
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 StringReferenceImpl stringMirror(Instance id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 return (StringReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 ArrayReferenceImpl arrayMirror(Array id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 return (ArrayReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1167
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 ThreadReferenceImpl threadMirror(Instance id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 return (ThreadReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1171
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 ThreadReferenceImpl threadMirror(JavaThread jt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 return (ThreadReferenceImpl) objectMirror(jt.getThreadObj());
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1175
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 ThreadGroupReferenceImpl threadGroupMirror(Instance id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 return (ThreadGroupReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1179
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 ClassLoaderReferenceImpl classLoaderMirror(Instance id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 return (ClassLoaderReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1183
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 ClassObjectReferenceImpl classObjectMirror(Instance id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 return (ClassObjectReferenceImpl) objectMirror(id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1187
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 // Use of soft refs and caching stuff here has to be re-examined.
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 // It might not make sense for JDI - SA.
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 static private class SoftObjectReference extends SoftReference {
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 int count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 Object key;
a61af66fc99e Initial load
duke
parents:
diff changeset
1193
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 SoftObjectReference(Object key, ObjectReferenceImpl mirror,
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 ReferenceQueue queue) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 super(mirror, queue);
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 this.count = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 this.key = key;
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1200
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 int count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 return count;
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1204
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 void incrementCount() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 count++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1208
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 Object key() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 return key;
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1212
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 ObjectReferenceImpl object() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 return (ObjectReferenceImpl)get();
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 }