2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores,
20 * CA 94065 USA or visit www.oracle.com if you need additional information or
25 // The following classes are used for operations
26 // initiated by a Java thread but that must
27 // take place in the VMThread.
29 #define VM_OP_ENUM(type) VMOp_##type,
31 // Note: When new VM_XXX comes up, add 'XXX' to the template table.
32 #define VM_OPS_DO(template) \
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) \
44 template(HandleFullCodeCache) \
47 template(HeapDumper) \
48 template(DeoptimizeTheWorld) \
49 template(GC_HeapInspection) \
50 template(GenCollectFull) \
51 template(GenCollectFullConcurrent) \
52 template(GenCollectForAllocation) \
53 template(GenCollectForPermanentAllocation) \
54 template(ParallelGCFailedAllocation) \
55 template(ParallelGCFailedPermanentAllocation) \
56 template(ParallelGCSystemGC) \
57 template(CGC_Operation) \
58 template(CMS_Initial_Mark) \
59 template(CMS_Final_Remark) \
60 template(G1CollectFull) \
61 template(G1CollectForAllocation) \
62 template(G1IncCollectionPause) \
63 template(EnableBiasedLocking) \
64 template(RevokeBias) \
65 template(BulkRevokeBias) \
66 template(PopulateDumpSharedSpace) \
67 template(JNIFunctionTableCopier) \
68 template(RedefineClasses) \
69 template(GetOwnedMonitorInfo) \
70 template(GetObjectMonitorUsage) \
71 template(GetCurrentContendedMonitor) \
72 template(GetStackTrace) \
73 template(GetMultipleStackTraces) \
74 template(GetAllStackTraces) \
75 template(GetThreadListStackTraces) \
76 template(GetFrameCount) \
77 template(GetFrameLocation) \
78 template(ChangeBreakpoints) \
79 template(GetOrSetLocal) \
80 template(GetCurrentLocation) \
81 template(EnterInterpOnlyMode) \
82 template(ChangeSingleStep) \
83 template(HeapWalkOperation) \
84 template(HeapIterateOperation) \
85 template(ReportJavaOutOfMemory) \
88 class VM_Operation: public CHeapObj {
91 _safepoint, // blocking, safepoint, vm_op C-heap allocated
92 _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated
93 _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated
94 _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated
103 Thread* _calling_thread;
104 ThreadPriority _priority;
109 // The VM operation name array
110 static const char* _names[];
113 VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; }
114 virtual ~VM_Operation() {}
116 // VM operation support (used by VM thread)
117 Thread* calling_thread() const { return _calling_thread; }
118 ThreadPriority priority() { return _priority; }
119 void set_calling_thread(Thread* thread, ThreadPriority priority);
121 long timestamp() const { return _timestamp; }
122 void set_timestamp(long timestamp) { _timestamp = timestamp; }
124 // Called by VM thread - does in turn invoke doit(). Do not override this
127 // evaluate() is called by the VMThread and in turn calls doit().
128 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
129 // doit_prologue() is called in that thread before transferring control to
131 // If doit_prologue() returns true the VM operation will proceed, and
132 // doit_epilogue() will be called by the JavaThread once the VM operation
133 // completes. If doit_prologue() returns false the VM operation is cancelled.
134 virtual void doit() = 0;
135 virtual bool doit_prologue() { return true; };
136 virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent
139 virtual bool is_methodCompiler() const { return false; }
142 VM_Operation *next() const { return _next; }
143 VM_Operation *prev() const { return _prev; }
144 void set_next(VM_Operation *next) { _next = next; }
145 void set_prev(VM_Operation *prev) { _prev = prev; }
147 // Configuration. Override these appropriatly in subclasses.
148 virtual VMOp_Type type() const = 0;
149 virtual Mode evaluation_mode() const { return _safepoint; }
150 virtual bool allow_nested_vm_operations() const { return false; }
151 virtual bool is_cheap_allocated() const { return false; }
152 virtual void oops_do(OopClosure* f) { /* do nothing */ };
154 // CAUTION: <don't hang yourself with following rope>
155 // If you override these methods, make sure that the evaluation
156 // of these methods is race-free and non-blocking, since these
157 // methods may be evaluated either by the mutators or by the
158 // vm thread, either concurrently with mutators or with the mutators
159 // stopped. In other words, taking locks is verboten, and if there
160 // are any races in evaluating the conditions, they'd better be benign.
161 virtual bool evaluate_at_safepoint() const {
162 return evaluation_mode() == _safepoint ||
163 evaluation_mode() == _async_safepoint;
165 virtual bool evaluate_concurrently() const {
166 return evaluation_mode() == _concurrent ||
167 evaluation_mode() == _async_safepoint;
171 void print_on_error(outputStream* st) const;
172 const char* name() const { return _names[type()]; }
173 static const char* name(int type) {
174 assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
178 void print_on(outputStream* st) const { print_on_error(st); }
182 class VM_ThreadStop: public VM_Operation {
184 oop _thread; // The Thread that the Throwable is thrown against
185 oop _throwable; // The Throwable thrown at the target Thread
187 // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
188 // VM operation is executed.
189 VM_ThreadStop(oop thread, oop throwable) {
191 _throwable = throwable;
193 VMOp_Type type() const { return VMOp_ThreadStop; }
194 oop target_thread() const { return _thread; }
195 oop throwable() const { return _throwable;}
197 // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
198 bool allow_nested_vm_operations() const { return true; }
199 Mode evaluation_mode() const { return _async_safepoint; }
200 bool is_cheap_allocated() const { return true; }
203 void oops_do(OopClosure* f) {
204 f->do_oop(&_thread); f->do_oop(&_throwable);
208 // dummy vm op, evaluated just to force a safepoint
209 class VM_ForceSafepoint: public VM_Operation {
211 VM_ForceSafepoint() {}
213 VMOp_Type type() const { return VMOp_ForceSafepoint; }
216 // dummy vm op, evaluated just to force a safepoint
217 class VM_ForceAsyncSafepoint: public VM_Operation {
219 VM_ForceAsyncSafepoint() {}
221 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
222 Mode evaluation_mode() const { return _async_safepoint; }
223 bool is_cheap_allocated() const { return true; }
226 class VM_Deoptimize: public VM_Operation {
229 VMOp_Type type() const { return VMOp_Deoptimize; }
231 bool allow_nested_vm_operations() const { return true; }
234 class VM_DeoptimizeFrame: public VM_Operation {
239 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
240 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
242 bool allow_nested_vm_operations() const { return true; }
245 class VM_HandleFullCodeCache: public VM_Operation {
249 VM_HandleFullCodeCache(bool is_full) { _is_full = is_full; }
250 VMOp_Type type() const { return VMOp_HandleFullCodeCache; }
252 bool allow_nested_vm_operations() const { return true; }
256 class VM_DeoptimizeAll: public VM_Operation {
258 KlassHandle _dependee;
260 VM_DeoptimizeAll() {}
261 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
263 bool allow_nested_vm_operations() const { return true; }
267 class VM_ZombieAll: public VM_Operation {
270 VMOp_Type type() const { return VMOp_ZombieAll; }
272 bool allow_nested_vm_operations() const { return true; }
276 class VM_Verify: public VM_Operation {
278 KlassHandle _dependee;
281 VMOp_Type type() const { return VMOp_Verify; }
286 class VM_PrintThreads: public VM_Operation {
289 bool _print_concurrent_locks;
291 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
292 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
293 VMOp_Type type() const { return VMOp_PrintThreads; }
295 bool doit_prologue();
296 void doit_epilogue();
299 class VM_PrintJNI: public VM_Operation {
303 VM_PrintJNI() { _out = tty; }
304 VM_PrintJNI(outputStream* out) { _out = out; }
305 VMOp_Type type() const { return VMOp_PrintJNI; }
310 class VM_FindDeadlocks: public VM_Operation {
312 bool _concurrent_locks;
313 DeadlockCycle* _deadlocks;
317 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
318 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
321 DeadlockCycle* result() { return _deadlocks; };
322 VMOp_Type type() const { return VMOp_FindDeadlocks; }
324 bool doit_prologue();
327 class ThreadDumpResult;
328 class ThreadSnapshot;
329 class ThreadConcurrentLocks;
331 class VM_ThreadDump : public VM_Operation {
333 ThreadDumpResult* _result;
335 GrowableArray<instanceHandle>* _threads;
337 bool _with_locked_monitors;
338 bool _with_locked_synchronizers;
340 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
343 VM_ThreadDump(ThreadDumpResult* result,
344 int max_depth, // -1 indicates entire stack
345 bool with_locked_monitors,
346 bool with_locked_synchronizers);
348 VM_ThreadDump(ThreadDumpResult* result,
349 GrowableArray<instanceHandle>* threads,
350 int num_threads, // -1 indicates entire stack
352 bool with_locked_monitors,
353 bool with_locked_synchronizers);
355 VMOp_Type type() const { return VMOp_ThreadDump; }
357 bool doit_prologue();
358 void doit_epilogue();
362 class VM_Exit: public VM_Operation {
365 static volatile bool _vm_exited;
366 static Thread * _shutdown_thread;
367 static void wait_if_vm_exited();
369 VM_Exit(int exit_code) {
370 _exit_code = exit_code;
372 static int wait_for_threads_in_native_to_block();
373 static int set_vm_exited();
374 static bool vm_exited() { return _vm_exited; }
375 static void block_if_vm_exited() {
380 VMOp_Type type() const { return VMOp_Exit; }