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