duke@435: /* trims@2708: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_RUNTIME_VM_OPERATIONS_HPP stefank@2314: #define SHARE_VM_RUNTIME_VM_OPERATIONS_HPP stefank@2314: stefank@2314: #include "classfile/javaClasses.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "oops/oop.hpp" stefank@2314: #include "runtime/thread.hpp" stefank@2314: #include "utilities/top.hpp" stefank@2314: duke@435: // The following classes are used for operations duke@435: // initiated by a Java thread but that must duke@435: // take place in the VMThread. duke@435: duke@435: #define VM_OP_ENUM(type) VMOp_##type, duke@435: duke@435: // Note: When new VM_XXX comes up, add 'XXX' to the template table. duke@435: #define VM_OPS_DO(template) \ duke@435: template(Dummy) \ duke@435: template(ThreadStop) \ duke@435: template(ThreadDump) \ duke@435: template(PrintThreads) \ duke@435: template(FindDeadlocks) \ duke@435: template(ForceSafepoint) \ duke@435: template(ForceAsyncSafepoint) \ duke@435: template(Deoptimize) \ duke@435: template(DeoptimizeFrame) \ duke@435: template(DeoptimizeAll) \ duke@435: template(ZombieAll) \ coleenp@2497: template(UnlinkSymbols) \ kvn@1637: template(HandleFullCodeCache) \ duke@435: template(Verify) \ duke@435: template(PrintJNI) \ duke@435: template(HeapDumper) \ duke@435: template(DeoptimizeTheWorld) \ duke@435: template(GC_HeapInspection) \ duke@435: template(GenCollectFull) \ duke@435: template(GenCollectFullConcurrent) \ duke@435: template(GenCollectForAllocation) \ apetrusenko@574: template(GenCollectForPermanentAllocation) \ duke@435: template(ParallelGCFailedAllocation) \ duke@435: template(ParallelGCFailedPermanentAllocation) \ duke@435: template(ParallelGCSystemGC) \ ysr@777: template(CGC_Operation) \ duke@435: template(CMS_Initial_Mark) \ duke@435: template(CMS_Final_Remark) \ ysr@777: template(G1CollectFull) \ ysr@777: template(G1CollectForAllocation) \ ysr@777: template(G1IncCollectionPause) \ duke@435: template(EnableBiasedLocking) \ duke@435: template(RevokeBias) \ duke@435: template(BulkRevokeBias) \ duke@435: template(PopulateDumpSharedSpace) \ duke@435: template(JNIFunctionTableCopier) \ duke@435: template(RedefineClasses) \ duke@435: template(GetOwnedMonitorInfo) \ duke@435: template(GetObjectMonitorUsage) \ duke@435: template(GetCurrentContendedMonitor) \ duke@435: template(GetStackTrace) \ duke@435: template(GetMultipleStackTraces) \ duke@435: template(GetAllStackTraces) \ duke@435: template(GetThreadListStackTraces) \ duke@435: template(GetFrameCount) \ duke@435: template(GetFrameLocation) \ duke@435: template(ChangeBreakpoints) \ duke@435: template(GetOrSetLocal) \ duke@435: template(GetCurrentLocation) \ duke@435: template(EnterInterpOnlyMode) \ duke@435: template(ChangeSingleStep) \ duke@435: template(HeapWalkOperation) \ duke@435: template(HeapIterateOperation) \ duke@435: template(ReportJavaOutOfMemory) \ phh@3427: template(JFRCheckpoint) \ duke@435: template(Exit) \ duke@435: duke@435: class VM_Operation: public CHeapObj { duke@435: public: duke@435: enum Mode { duke@435: _safepoint, // blocking, safepoint, vm_op C-heap allocated duke@435: _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated duke@435: _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated duke@435: _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated duke@435: }; duke@435: duke@435: enum VMOp_Type { duke@435: VM_OPS_DO(VM_OP_ENUM) duke@435: VMOp_Terminating duke@435: }; duke@435: duke@435: private: duke@435: Thread* _calling_thread; duke@435: ThreadPriority _priority; duke@435: long _timestamp; duke@435: VM_Operation* _next; duke@435: VM_Operation* _prev; duke@435: duke@435: // The VM operation name array duke@435: static const char* _names[]; duke@435: duke@435: public: duke@435: VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; } duke@435: virtual ~VM_Operation() {} duke@435: duke@435: // VM operation support (used by VM thread) duke@435: Thread* calling_thread() const { return _calling_thread; } duke@435: ThreadPriority priority() { return _priority; } duke@435: void set_calling_thread(Thread* thread, ThreadPriority priority); duke@435: duke@435: long timestamp() const { return _timestamp; } duke@435: void set_timestamp(long timestamp) { _timestamp = timestamp; } duke@435: duke@435: // Called by VM thread - does in turn invoke doit(). Do not override this duke@435: void evaluate(); duke@435: duke@435: // evaluate() is called by the VMThread and in turn calls doit(). duke@435: // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread, duke@435: // doit_prologue() is called in that thread before transferring control to duke@435: // the VMThread. duke@435: // If doit_prologue() returns true the VM operation will proceed, and duke@435: // doit_epilogue() will be called by the JavaThread once the VM operation duke@435: // completes. If doit_prologue() returns false the VM operation is cancelled. duke@435: virtual void doit() = 0; duke@435: virtual bool doit_prologue() { return true; }; duke@435: virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent duke@435: duke@435: // Type test duke@435: virtual bool is_methodCompiler() const { return false; } duke@435: duke@435: // Linking duke@435: VM_Operation *next() const { return _next; } duke@435: VM_Operation *prev() const { return _prev; } duke@435: void set_next(VM_Operation *next) { _next = next; } duke@435: void set_prev(VM_Operation *prev) { _prev = prev; } duke@435: duke@435: // Configuration. Override these appropriatly in subclasses. duke@435: virtual VMOp_Type type() const = 0; duke@435: virtual Mode evaluation_mode() const { return _safepoint; } duke@435: virtual bool allow_nested_vm_operations() const { return false; } duke@435: virtual bool is_cheap_allocated() const { return false; } duke@435: virtual void oops_do(OopClosure* f) { /* do nothing */ }; duke@435: duke@435: // CAUTION: duke@435: // If you override these methods, make sure that the evaluation duke@435: // of these methods is race-free and non-blocking, since these duke@435: // methods may be evaluated either by the mutators or by the duke@435: // vm thread, either concurrently with mutators or with the mutators duke@435: // stopped. In other words, taking locks is verboten, and if there duke@435: // are any races in evaluating the conditions, they'd better be benign. duke@435: virtual bool evaluate_at_safepoint() const { duke@435: return evaluation_mode() == _safepoint || duke@435: evaluation_mode() == _async_safepoint; duke@435: } duke@435: virtual bool evaluate_concurrently() const { duke@435: return evaluation_mode() == _concurrent || duke@435: evaluation_mode() == _async_safepoint; duke@435: } duke@435: duke@435: // Debugging duke@435: void print_on_error(outputStream* st) const; duke@435: const char* name() const { return _names[type()]; } duke@435: static const char* name(int type) { duke@435: assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type"); duke@435: return _names[type]; duke@435: } duke@435: #ifndef PRODUCT duke@435: void print_on(outputStream* st) const { print_on_error(st); } duke@435: #endif duke@435: }; duke@435: duke@435: class VM_ThreadStop: public VM_Operation { duke@435: private: duke@435: oop _thread; // The Thread that the Throwable is thrown against duke@435: oop _throwable; // The Throwable thrown at the target Thread duke@435: public: duke@435: // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the duke@435: // VM operation is executed. duke@435: VM_ThreadStop(oop thread, oop throwable) { duke@435: _thread = thread; duke@435: _throwable = throwable; duke@435: } duke@435: VMOp_Type type() const { return VMOp_ThreadStop; } duke@435: oop target_thread() const { return _thread; } duke@435: oop throwable() const { return _throwable;} duke@435: void doit(); duke@435: // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated duke@435: bool allow_nested_vm_operations() const { return true; } duke@435: Mode evaluation_mode() const { return _async_safepoint; } duke@435: bool is_cheap_allocated() const { return true; } duke@435: duke@435: // GC support duke@435: void oops_do(OopClosure* f) { duke@435: f->do_oop(&_thread); f->do_oop(&_throwable); duke@435: } duke@435: }; duke@435: duke@435: // dummy vm op, evaluated just to force a safepoint duke@435: class VM_ForceSafepoint: public VM_Operation { duke@435: public: duke@435: VM_ForceSafepoint() {} duke@435: void doit() {} duke@435: VMOp_Type type() const { return VMOp_ForceSafepoint; } duke@435: }; duke@435: duke@435: // dummy vm op, evaluated just to force a safepoint duke@435: class VM_ForceAsyncSafepoint: public VM_Operation { duke@435: public: duke@435: VM_ForceAsyncSafepoint() {} duke@435: void doit() {} duke@435: VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; } duke@435: Mode evaluation_mode() const { return _async_safepoint; } duke@435: bool is_cheap_allocated() const { return true; } duke@435: }; duke@435: duke@435: class VM_Deoptimize: public VM_Operation { duke@435: public: duke@435: VM_Deoptimize() {} duke@435: VMOp_Type type() const { return VMOp_Deoptimize; } duke@435: void doit(); duke@435: bool allow_nested_vm_operations() const { return true; } duke@435: }; duke@435: never@2260: never@2260: // Deopt helper that can deoptimize frames in threads other than the never@2260: // current thread. Only used through Deoptimization::deoptimize_frame. duke@435: class VM_DeoptimizeFrame: public VM_Operation { never@2260: friend class Deoptimization; never@2260: duke@435: private: duke@435: JavaThread* _thread; duke@435: intptr_t* _id; never@2260: VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id); never@2260: duke@435: public: duke@435: VMOp_Type type() const { return VMOp_DeoptimizeFrame; } duke@435: void doit(); duke@435: bool allow_nested_vm_operations() const { return true; } duke@435: }; duke@435: kvn@1637: class VM_HandleFullCodeCache: public VM_Operation { kvn@1637: private: kvn@1637: bool _is_full; kvn@1637: public: kvn@1637: VM_HandleFullCodeCache(bool is_full) { _is_full = is_full; } kvn@1637: VMOp_Type type() const { return VMOp_HandleFullCodeCache; } kvn@1637: void doit(); kvn@1637: bool allow_nested_vm_operations() const { return true; } kvn@1637: }; kvn@1637: duke@435: #ifndef PRODUCT duke@435: class VM_DeoptimizeAll: public VM_Operation { duke@435: private: duke@435: KlassHandle _dependee; duke@435: public: duke@435: VM_DeoptimizeAll() {} duke@435: VMOp_Type type() const { return VMOp_DeoptimizeAll; } duke@435: void doit(); duke@435: bool allow_nested_vm_operations() const { return true; } duke@435: }; duke@435: duke@435: duke@435: class VM_ZombieAll: public VM_Operation { duke@435: public: duke@435: VM_ZombieAll() {} duke@435: VMOp_Type type() const { return VMOp_ZombieAll; } duke@435: void doit(); duke@435: bool allow_nested_vm_operations() const { return true; } duke@435: }; duke@435: #endif // PRODUCT duke@435: coleenp@2497: class VM_UnlinkSymbols: public VM_Operation { coleenp@2497: public: coleenp@2497: VM_UnlinkSymbols() {} coleenp@2497: VMOp_Type type() const { return VMOp_UnlinkSymbols; } coleenp@2497: void doit(); coleenp@2497: bool allow_nested_vm_operations() const { return true; } coleenp@2497: }; coleenp@2497: duke@435: class VM_Verify: public VM_Operation { duke@435: private: duke@435: KlassHandle _dependee; duke@435: public: duke@435: VM_Verify() {} duke@435: VMOp_Type type() const { return VMOp_Verify; } duke@435: void doit(); duke@435: }; duke@435: duke@435: duke@435: class VM_PrintThreads: public VM_Operation { duke@435: private: duke@435: outputStream* _out; duke@435: bool _print_concurrent_locks; duke@435: public: duke@435: VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; } duke@435: VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; } duke@435: VMOp_Type type() const { return VMOp_PrintThreads; } duke@435: void doit(); duke@435: bool doit_prologue(); duke@435: void doit_epilogue(); duke@435: }; duke@435: duke@435: class VM_PrintJNI: public VM_Operation { duke@435: private: duke@435: outputStream* _out; duke@435: public: duke@435: VM_PrintJNI() { _out = tty; } duke@435: VM_PrintJNI(outputStream* out) { _out = out; } duke@435: VMOp_Type type() const { return VMOp_PrintJNI; } duke@435: void doit(); duke@435: }; duke@435: duke@435: class DeadlockCycle; duke@435: class VM_FindDeadlocks: public VM_Operation { duke@435: private: duke@435: bool _concurrent_locks; duke@435: DeadlockCycle* _deadlocks; duke@435: outputStream* _out; duke@435: duke@435: public: duke@435: VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {}; duke@435: VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {}; duke@435: ~VM_FindDeadlocks(); duke@435: duke@435: DeadlockCycle* result() { return _deadlocks; }; duke@435: VMOp_Type type() const { return VMOp_FindDeadlocks; } duke@435: void doit(); duke@435: bool doit_prologue(); duke@435: }; duke@435: duke@435: class ThreadDumpResult; duke@435: class ThreadSnapshot; duke@435: class ThreadConcurrentLocks; duke@435: duke@435: class VM_ThreadDump : public VM_Operation { duke@435: private: duke@435: ThreadDumpResult* _result; duke@435: int _num_threads; duke@435: GrowableArray* _threads; duke@435: int _max_depth; duke@435: bool _with_locked_monitors; duke@435: bool _with_locked_synchronizers; duke@435: duke@435: ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl); duke@435: duke@435: public: duke@435: VM_ThreadDump(ThreadDumpResult* result, duke@435: int max_depth, // -1 indicates entire stack duke@435: bool with_locked_monitors, duke@435: bool with_locked_synchronizers); duke@435: duke@435: VM_ThreadDump(ThreadDumpResult* result, duke@435: GrowableArray* threads, duke@435: int num_threads, // -1 indicates entire stack duke@435: int max_depth, duke@435: bool with_locked_monitors, duke@435: bool with_locked_synchronizers); duke@435: duke@435: VMOp_Type type() const { return VMOp_ThreadDump; } duke@435: void doit(); duke@435: bool doit_prologue(); duke@435: void doit_epilogue(); duke@435: }; duke@435: duke@435: duke@435: class VM_Exit: public VM_Operation { duke@435: private: duke@435: int _exit_code; duke@435: static volatile bool _vm_exited; duke@435: static Thread * _shutdown_thread; duke@435: static void wait_if_vm_exited(); duke@435: public: duke@435: VM_Exit(int exit_code) { duke@435: _exit_code = exit_code; duke@435: } duke@435: static int wait_for_threads_in_native_to_block(); duke@435: static int set_vm_exited(); duke@435: static bool vm_exited() { return _vm_exited; } duke@435: static void block_if_vm_exited() { duke@435: if (_vm_exited) { duke@435: wait_if_vm_exited(); duke@435: } duke@435: } duke@435: VMOp_Type type() const { return VMOp_Exit; } duke@435: void doit(); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_VM_OPERATIONS_HPP