0
|
1 /*
|
|
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // The following classes are used for operations
|
|
26 // initiated by a Java thread but that must
|
|
27 // take place in the VMThread.
|
|
28
|
|
29 #define VM_OP_ENUM(type) VMOp_##type,
|
|
30
|
|
31 // Note: When new VM_XXX comes up, add 'XXX' to the template table.
|
|
32 #define VM_OPS_DO(template) \
|
|
33 template(Dummy) \
|
|
34 template(ThreadStop) \
|
|
35 template(ThreadDump) \
|
|
36 template(PrintThreads) \
|
|
37 template(FindDeadlocks) \
|
|
38 template(ForceSafepoint) \
|
|
39 template(ForceAsyncSafepoint) \
|
|
40 template(Deoptimize) \
|
|
41 template(DeoptimizeFrame) \
|
|
42 template(DeoptimizeAll) \
|
|
43 template(ZombieAll) \
|
|
44 template(Verify) \
|
|
45 template(PrintJNI) \
|
|
46 template(HeapDumper) \
|
|
47 template(DeoptimizeTheWorld) \
|
|
48 template(GC_HeapInspection) \
|
|
49 template(GenCollectFull) \
|
|
50 template(GenCollectFullConcurrent) \
|
|
51 template(GenCollectForAllocation) \
|
|
52 template(ParallelGCFailedAllocation) \
|
|
53 template(ParallelGCFailedPermanentAllocation) \
|
|
54 template(ParallelGCSystemGC) \
|
|
55 template(CMS_Initial_Mark) \
|
|
56 template(CMS_Final_Remark) \
|
|
57 template(EnableBiasedLocking) \
|
|
58 template(RevokeBias) \
|
|
59 template(BulkRevokeBias) \
|
|
60 template(PopulateDumpSharedSpace) \
|
|
61 template(JNIFunctionTableCopier) \
|
|
62 template(RedefineClasses) \
|
|
63 template(GetOwnedMonitorInfo) \
|
|
64 template(GetObjectMonitorUsage) \
|
|
65 template(GetCurrentContendedMonitor) \
|
|
66 template(GetStackTrace) \
|
|
67 template(GetMultipleStackTraces) \
|
|
68 template(GetAllStackTraces) \
|
|
69 template(GetThreadListStackTraces) \
|
|
70 template(GetFrameCount) \
|
|
71 template(GetFrameLocation) \
|
|
72 template(ChangeBreakpoints) \
|
|
73 template(GetOrSetLocal) \
|
|
74 template(GetCurrentLocation) \
|
|
75 template(EnterInterpOnlyMode) \
|
|
76 template(ChangeSingleStep) \
|
|
77 template(HeapWalkOperation) \
|
|
78 template(HeapIterateOperation) \
|
|
79 template(ReportJavaOutOfMemory) \
|
|
80 template(Exit) \
|
|
81
|
|
82 class VM_Operation: public CHeapObj {
|
|
83 public:
|
|
84 enum Mode {
|
|
85 _safepoint, // blocking, safepoint, vm_op C-heap allocated
|
|
86 _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated
|
|
87 _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated
|
|
88 _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated
|
|
89 };
|
|
90
|
|
91 enum VMOp_Type {
|
|
92 VM_OPS_DO(VM_OP_ENUM)
|
|
93 VMOp_Terminating
|
|
94 };
|
|
95
|
|
96 private:
|
|
97 Thread* _calling_thread;
|
|
98 ThreadPriority _priority;
|
|
99 long _timestamp;
|
|
100 VM_Operation* _next;
|
|
101 VM_Operation* _prev;
|
|
102
|
|
103 // The VM operation name array
|
|
104 static const char* _names[];
|
|
105
|
|
106 public:
|
|
107 VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; }
|
|
108 virtual ~VM_Operation() {}
|
|
109
|
|
110 // VM operation support (used by VM thread)
|
|
111 Thread* calling_thread() const { return _calling_thread; }
|
|
112 ThreadPriority priority() { return _priority; }
|
|
113 void set_calling_thread(Thread* thread, ThreadPriority priority);
|
|
114
|
|
115 long timestamp() const { return _timestamp; }
|
|
116 void set_timestamp(long timestamp) { _timestamp = timestamp; }
|
|
117
|
|
118 // Called by VM thread - does in turn invoke doit(). Do not override this
|
|
119 void evaluate();
|
|
120
|
|
121 // evaluate() is called by the VMThread and in turn calls doit().
|
|
122 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
|
|
123 // doit_prologue() is called in that thread before transferring control to
|
|
124 // the VMThread.
|
|
125 // If doit_prologue() returns true the VM operation will proceed, and
|
|
126 // doit_epilogue() will be called by the JavaThread once the VM operation
|
|
127 // completes. If doit_prologue() returns false the VM operation is cancelled.
|
|
128 virtual void doit() = 0;
|
|
129 virtual bool doit_prologue() { return true; };
|
|
130 virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent
|
|
131
|
|
132 // Type test
|
|
133 virtual bool is_methodCompiler() const { return false; }
|
|
134
|
|
135 // Linking
|
|
136 VM_Operation *next() const { return _next; }
|
|
137 VM_Operation *prev() const { return _prev; }
|
|
138 void set_next(VM_Operation *next) { _next = next; }
|
|
139 void set_prev(VM_Operation *prev) { _prev = prev; }
|
|
140
|
|
141 // Configuration. Override these appropriatly in subclasses.
|
|
142 virtual VMOp_Type type() const = 0;
|
|
143 virtual Mode evaluation_mode() const { return _safepoint; }
|
|
144 virtual bool allow_nested_vm_operations() const { return false; }
|
|
145 virtual bool is_cheap_allocated() const { return false; }
|
|
146 virtual void oops_do(OopClosure* f) { /* do nothing */ };
|
|
147
|
|
148 // CAUTION: <don't hang yourself with following rope>
|
|
149 // If you override these methods, make sure that the evaluation
|
|
150 // of these methods is race-free and non-blocking, since these
|
|
151 // methods may be evaluated either by the mutators or by the
|
|
152 // vm thread, either concurrently with mutators or with the mutators
|
|
153 // stopped. In other words, taking locks is verboten, and if there
|
|
154 // are any races in evaluating the conditions, they'd better be benign.
|
|
155 virtual bool evaluate_at_safepoint() const {
|
|
156 return evaluation_mode() == _safepoint ||
|
|
157 evaluation_mode() == _async_safepoint;
|
|
158 }
|
|
159 virtual bool evaluate_concurrently() const {
|
|
160 return evaluation_mode() == _concurrent ||
|
|
161 evaluation_mode() == _async_safepoint;
|
|
162 }
|
|
163
|
|
164 // Debugging
|
|
165 void print_on_error(outputStream* st) const;
|
|
166 const char* name() const { return _names[type()]; }
|
|
167 static const char* name(int type) {
|
|
168 assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
|
|
169 return _names[type];
|
|
170 }
|
|
171 #ifndef PRODUCT
|
|
172 void print_on(outputStream* st) const { print_on_error(st); }
|
|
173 #endif
|
|
174 };
|
|
175
|
|
176 class VM_ThreadStop: public VM_Operation {
|
|
177 private:
|
|
178 oop _thread; // The Thread that the Throwable is thrown against
|
|
179 oop _throwable; // The Throwable thrown at the target Thread
|
|
180 public:
|
|
181 // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
|
|
182 // VM operation is executed.
|
|
183 VM_ThreadStop(oop thread, oop throwable) {
|
|
184 _thread = thread;
|
|
185 _throwable = throwable;
|
|
186 }
|
|
187 VMOp_Type type() const { return VMOp_ThreadStop; }
|
|
188 oop target_thread() const { return _thread; }
|
|
189 oop throwable() const { return _throwable;}
|
|
190 void doit();
|
|
191 // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
|
|
192 bool allow_nested_vm_operations() const { return true; }
|
|
193 Mode evaluation_mode() const { return _async_safepoint; }
|
|
194 bool is_cheap_allocated() const { return true; }
|
|
195
|
|
196 // GC support
|
|
197 void oops_do(OopClosure* f) {
|
|
198 f->do_oop(&_thread); f->do_oop(&_throwable);
|
|
199 }
|
|
200 };
|
|
201
|
|
202 // dummy vm op, evaluated just to force a safepoint
|
|
203 class VM_ForceSafepoint: public VM_Operation {
|
|
204 public:
|
|
205 VM_ForceSafepoint() {}
|
|
206 void doit() {}
|
|
207 VMOp_Type type() const { return VMOp_ForceSafepoint; }
|
|
208 };
|
|
209
|
|
210 // dummy vm op, evaluated just to force a safepoint
|
|
211 class VM_ForceAsyncSafepoint: public VM_Operation {
|
|
212 public:
|
|
213 VM_ForceAsyncSafepoint() {}
|
|
214 void doit() {}
|
|
215 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
|
|
216 Mode evaluation_mode() const { return _async_safepoint; }
|
|
217 bool is_cheap_allocated() const { return true; }
|
|
218 };
|
|
219
|
|
220 class VM_Deoptimize: public VM_Operation {
|
|
221 public:
|
|
222 VM_Deoptimize() {}
|
|
223 VMOp_Type type() const { return VMOp_Deoptimize; }
|
|
224 void doit();
|
|
225 bool allow_nested_vm_operations() const { return true; }
|
|
226 };
|
|
227
|
|
228 class VM_DeoptimizeFrame: public VM_Operation {
|
|
229 private:
|
|
230 JavaThread* _thread;
|
|
231 intptr_t* _id;
|
|
232 public:
|
|
233 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
|
|
234 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
|
|
235 void doit();
|
|
236 bool allow_nested_vm_operations() const { return true; }
|
|
237 };
|
|
238
|
|
239 #ifndef PRODUCT
|
|
240 class VM_DeoptimizeAll: public VM_Operation {
|
|
241 private:
|
|
242 KlassHandle _dependee;
|
|
243 public:
|
|
244 VM_DeoptimizeAll() {}
|
|
245 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
|
|
246 void doit();
|
|
247 bool allow_nested_vm_operations() const { return true; }
|
|
248 };
|
|
249
|
|
250
|
|
251 class VM_ZombieAll: public VM_Operation {
|
|
252 public:
|
|
253 VM_ZombieAll() {}
|
|
254 VMOp_Type type() const { return VMOp_ZombieAll; }
|
|
255 void doit();
|
|
256 bool allow_nested_vm_operations() const { return true; }
|
|
257 };
|
|
258 #endif // PRODUCT
|
|
259
|
|
260 class VM_Verify: public VM_Operation {
|
|
261 private:
|
|
262 KlassHandle _dependee;
|
|
263 public:
|
|
264 VM_Verify() {}
|
|
265 VMOp_Type type() const { return VMOp_Verify; }
|
|
266 void doit();
|
|
267 };
|
|
268
|
|
269
|
|
270 class VM_PrintThreads: public VM_Operation {
|
|
271 private:
|
|
272 outputStream* _out;
|
|
273 bool _print_concurrent_locks;
|
|
274 public:
|
|
275 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
|
|
276 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
|
|
277 VMOp_Type type() const { return VMOp_PrintThreads; }
|
|
278 void doit();
|
|
279 bool doit_prologue();
|
|
280 void doit_epilogue();
|
|
281 };
|
|
282
|
|
283 class VM_PrintJNI: public VM_Operation {
|
|
284 private:
|
|
285 outputStream* _out;
|
|
286 public:
|
|
287 VM_PrintJNI() { _out = tty; }
|
|
288 VM_PrintJNI(outputStream* out) { _out = out; }
|
|
289 VMOp_Type type() const { return VMOp_PrintJNI; }
|
|
290 void doit();
|
|
291 };
|
|
292
|
|
293 class DeadlockCycle;
|
|
294 class VM_FindDeadlocks: public VM_Operation {
|
|
295 private:
|
|
296 bool _concurrent_locks;
|
|
297 DeadlockCycle* _deadlocks;
|
|
298 outputStream* _out;
|
|
299
|
|
300 public:
|
|
301 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
|
|
302 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
|
|
303 ~VM_FindDeadlocks();
|
|
304
|
|
305 DeadlockCycle* result() { return _deadlocks; };
|
|
306 VMOp_Type type() const { return VMOp_FindDeadlocks; }
|
|
307 void doit();
|
|
308 bool doit_prologue();
|
|
309 };
|
|
310
|
|
311 class ThreadDumpResult;
|
|
312 class ThreadSnapshot;
|
|
313 class ThreadConcurrentLocks;
|
|
314
|
|
315 class VM_ThreadDump : public VM_Operation {
|
|
316 private:
|
|
317 ThreadDumpResult* _result;
|
|
318 int _num_threads;
|
|
319 GrowableArray<instanceHandle>* _threads;
|
|
320 int _max_depth;
|
|
321 bool _with_locked_monitors;
|
|
322 bool _with_locked_synchronizers;
|
|
323
|
|
324 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
|
|
325
|
|
326 public:
|
|
327 VM_ThreadDump(ThreadDumpResult* result,
|
|
328 int max_depth, // -1 indicates entire stack
|
|
329 bool with_locked_monitors,
|
|
330 bool with_locked_synchronizers);
|
|
331
|
|
332 VM_ThreadDump(ThreadDumpResult* result,
|
|
333 GrowableArray<instanceHandle>* threads,
|
|
334 int num_threads, // -1 indicates entire stack
|
|
335 int max_depth,
|
|
336 bool with_locked_monitors,
|
|
337 bool with_locked_synchronizers);
|
|
338
|
|
339 VMOp_Type type() const { return VMOp_ThreadDump; }
|
|
340 void doit();
|
|
341 bool doit_prologue();
|
|
342 void doit_epilogue();
|
|
343 };
|
|
344
|
|
345
|
|
346 class VM_Exit: public VM_Operation {
|
|
347 private:
|
|
348 int _exit_code;
|
|
349 static volatile bool _vm_exited;
|
|
350 static Thread * _shutdown_thread;
|
|
351 static void wait_if_vm_exited();
|
|
352 public:
|
|
353 VM_Exit(int exit_code) {
|
|
354 _exit_code = exit_code;
|
|
355 }
|
|
356 static int wait_for_threads_in_native_to_block();
|
|
357 static int set_vm_exited();
|
|
358 static bool vm_exited() { return _vm_exited; }
|
|
359 static void block_if_vm_exited() {
|
|
360 if (_vm_exited) {
|
|
361 wait_if_vm_exited();
|
|
362 }
|
|
363 }
|
|
364 VMOp_Type type() const { return VMOp_Exit; }
|
|
365 void doit();
|
|
366 };
|