annotate agent/src/share/classes/sun/jvm/hotspot/jdi/VirtualMachineImpl.java @ 6782:5a98bf7d847b

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