Tue, 19 Oct 2010 16:14:34 -0700
6968367: can_post_on_exceptions is still using VM_DeoptimizeFrame in some places
Reviewed-by: kvn, twisti
1 /*
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.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
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) \
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(HandleFullCodeCache) \
45 template(Verify) \
46 template(PrintJNI) \
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) \
86 template(Exit) \
88 class VM_Operation: public CHeapObj {
89 public:
90 enum Mode {
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
95 };
97 enum VMOp_Type {
98 VM_OPS_DO(VM_OP_ENUM)
99 VMOp_Terminating
100 };
102 private:
103 Thread* _calling_thread;
104 ThreadPriority _priority;
105 long _timestamp;
106 VM_Operation* _next;
107 VM_Operation* _prev;
109 // The VM operation name array
110 static const char* _names[];
112 public:
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
125 void evaluate();
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
130 // the VMThread.
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
138 // Type test
139 virtual bool is_methodCompiler() const { return false; }
141 // Linking
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;
164 }
165 virtual bool evaluate_concurrently() const {
166 return evaluation_mode() == _concurrent ||
167 evaluation_mode() == _async_safepoint;
168 }
170 // Debugging
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");
175 return _names[type];
176 }
177 #ifndef PRODUCT
178 void print_on(outputStream* st) const { print_on_error(st); }
179 #endif
180 };
182 class VM_ThreadStop: public VM_Operation {
183 private:
184 oop _thread; // The Thread that the Throwable is thrown against
185 oop _throwable; // The Throwable thrown at the target Thread
186 public:
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) {
190 _thread = thread;
191 _throwable = throwable;
192 }
193 VMOp_Type type() const { return VMOp_ThreadStop; }
194 oop target_thread() const { return _thread; }
195 oop throwable() const { return _throwable;}
196 void doit();
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; }
202 // GC support
203 void oops_do(OopClosure* f) {
204 f->do_oop(&_thread); f->do_oop(&_throwable);
205 }
206 };
208 // dummy vm op, evaluated just to force a safepoint
209 class VM_ForceSafepoint: public VM_Operation {
210 public:
211 VM_ForceSafepoint() {}
212 void doit() {}
213 VMOp_Type type() const { return VMOp_ForceSafepoint; }
214 };
216 // dummy vm op, evaluated just to force a safepoint
217 class VM_ForceAsyncSafepoint: public VM_Operation {
218 public:
219 VM_ForceAsyncSafepoint() {}
220 void doit() {}
221 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
222 Mode evaluation_mode() const { return _async_safepoint; }
223 bool is_cheap_allocated() const { return true; }
224 };
226 class VM_Deoptimize: public VM_Operation {
227 public:
228 VM_Deoptimize() {}
229 VMOp_Type type() const { return VMOp_Deoptimize; }
230 void doit();
231 bool allow_nested_vm_operations() const { return true; }
232 };
235 // Deopt helper that can deoptimize frames in threads other than the
236 // current thread. Only used through Deoptimization::deoptimize_frame.
237 class VM_DeoptimizeFrame: public VM_Operation {
238 friend class Deoptimization;
240 private:
241 JavaThread* _thread;
242 intptr_t* _id;
243 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
245 public:
246 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
247 void doit();
248 bool allow_nested_vm_operations() const { return true; }
249 };
251 class VM_HandleFullCodeCache: public VM_Operation {
252 private:
253 bool _is_full;
254 public:
255 VM_HandleFullCodeCache(bool is_full) { _is_full = is_full; }
256 VMOp_Type type() const { return VMOp_HandleFullCodeCache; }
257 void doit();
258 bool allow_nested_vm_operations() const { return true; }
259 };
261 #ifndef PRODUCT
262 class VM_DeoptimizeAll: public VM_Operation {
263 private:
264 KlassHandle _dependee;
265 public:
266 VM_DeoptimizeAll() {}
267 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
268 void doit();
269 bool allow_nested_vm_operations() const { return true; }
270 };
273 class VM_ZombieAll: public VM_Operation {
274 public:
275 VM_ZombieAll() {}
276 VMOp_Type type() const { return VMOp_ZombieAll; }
277 void doit();
278 bool allow_nested_vm_operations() const { return true; }
279 };
280 #endif // PRODUCT
282 class VM_Verify: public VM_Operation {
283 private:
284 KlassHandle _dependee;
285 public:
286 VM_Verify() {}
287 VMOp_Type type() const { return VMOp_Verify; }
288 void doit();
289 };
292 class VM_PrintThreads: public VM_Operation {
293 private:
294 outputStream* _out;
295 bool _print_concurrent_locks;
296 public:
297 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
298 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
299 VMOp_Type type() const { return VMOp_PrintThreads; }
300 void doit();
301 bool doit_prologue();
302 void doit_epilogue();
303 };
305 class VM_PrintJNI: public VM_Operation {
306 private:
307 outputStream* _out;
308 public:
309 VM_PrintJNI() { _out = tty; }
310 VM_PrintJNI(outputStream* out) { _out = out; }
311 VMOp_Type type() const { return VMOp_PrintJNI; }
312 void doit();
313 };
315 class DeadlockCycle;
316 class VM_FindDeadlocks: public VM_Operation {
317 private:
318 bool _concurrent_locks;
319 DeadlockCycle* _deadlocks;
320 outputStream* _out;
322 public:
323 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
324 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
325 ~VM_FindDeadlocks();
327 DeadlockCycle* result() { return _deadlocks; };
328 VMOp_Type type() const { return VMOp_FindDeadlocks; }
329 void doit();
330 bool doit_prologue();
331 };
333 class ThreadDumpResult;
334 class ThreadSnapshot;
335 class ThreadConcurrentLocks;
337 class VM_ThreadDump : public VM_Operation {
338 private:
339 ThreadDumpResult* _result;
340 int _num_threads;
341 GrowableArray<instanceHandle>* _threads;
342 int _max_depth;
343 bool _with_locked_monitors;
344 bool _with_locked_synchronizers;
346 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
348 public:
349 VM_ThreadDump(ThreadDumpResult* result,
350 int max_depth, // -1 indicates entire stack
351 bool with_locked_monitors,
352 bool with_locked_synchronizers);
354 VM_ThreadDump(ThreadDumpResult* result,
355 GrowableArray<instanceHandle>* threads,
356 int num_threads, // -1 indicates entire stack
357 int max_depth,
358 bool with_locked_monitors,
359 bool with_locked_synchronizers);
361 VMOp_Type type() const { return VMOp_ThreadDump; }
362 void doit();
363 bool doit_prologue();
364 void doit_epilogue();
365 };
368 class VM_Exit: public VM_Operation {
369 private:
370 int _exit_code;
371 static volatile bool _vm_exited;
372 static Thread * _shutdown_thread;
373 static void wait_if_vm_exited();
374 public:
375 VM_Exit(int exit_code) {
376 _exit_code = exit_code;
377 }
378 static int wait_for_threads_in_native_to_block();
379 static int set_vm_exited();
380 static bool vm_exited() { return _vm_exited; }
381 static void block_if_vm_exited() {
382 if (_vm_exited) {
383 wait_if_vm_exited();
384 }
385 }
386 VMOp_Type type() const { return VMOp_Exit; }
387 void doit();
388 };