annotate agent/src/share/classes/sun/jvm/hotspot/jdi/VirtualMachineImpl.java @ 1552:c18cbe5936b8

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