1 /*
  2  * Copyright (c) 1997, 2021, 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  */
 24 
 25 #ifndef SHARE_RUNTIME_VMOPERATION_HPP
 26 #define SHARE_RUNTIME_VMOPERATION_HPP
 27 
 28 #include "memory/allocation.hpp"
 29 
 30 // The following classes are used for operations
 31 // initiated by a Java thread but that must
 32 // take place in the VMThread.
 33 
 34 #define VM_OP_ENUM(type)   VMOp_##type,
 35 
 36 // Note: When new VM_XXX comes up, add 'XXX' to the template table.
 37 #define VM_OPS_DO(template)                       \
 38   template(None)                                  \
 39   template(Cleanup)                               \
 40   template(ThreadDump)                            \
 41   template(PrintThreads)                          \
 42   template(FindDeadlocks)                         \
 43   template(ClearICs)                              \
 44   template(ForceSafepoint)                        \
 45   template(ForceAsyncSafepoint)                   \
 46   template(DeoptimizeFrame)                       \
 47   template(DeoptimizeAll)                         \
 48   template(ZombieAll)                             \
 49   template(Verify)                                \
 50   template(PrintJNI)                              \
 51   template(HeapDumper)                            \
 52   template(DeoptimizeTheWorld)                    \
 53   template(CollectForMetadataAllocation)          \
 54   template(GC_HeapInspection)                     \
 55   template(GenCollectFull)                        \
 56   template(GenCollectFullConcurrent)              \
 57   template(GenCollectForAllocation)               \
 58   template(ParallelGCFailedAllocation)            \
 59   template(ParallelGCSystemGC)                    \
 60   template(G1CollectForAllocation)                \
 61   template(G1CollectFull)                         \
 62   template(G1PauseRemark)                         \
 63   template(G1PauseCleanup)                        \
 64   template(G1TryInitiateConcMark)                 \
 65   template(ZMarkStart)                            \
 66   template(ZMarkEnd)                              \
 67   template(ZRelocateStart)                        \
 68   template(ZVerify)                               \
 69   template(HandshakeOneThread)                    \
 70   template(HandshakeAllThreads)                   \
 71   template(HandshakeFallback)                     \
 72   template(EnableBiasedLocking)                   \
 73   template(BulkRevokeBias)                        \
 74   template(PopulateDumpSharedSpace)               \
 75   template(JNIFunctionTableCopier)                \
 76   template(RedefineClasses)                       \
 77   template(GetObjectMonitorUsage)                 \
 78   template(GetAllStackTraces)                     \
 79   template(GetThreadListStackTraces)              \
 80   template(ChangeBreakpoints)                     \
 81   template(GetOrSetLocal)                         \
 82   template(ChangeSingleStep)                      \
 83   template(HeapWalkOperation)                     \
 84   template(HeapIterateOperation)                  \
 85   template(HeapObjectStatistics)                  \
 86   template(ReportJavaOutOfMemory)                 \
 87   template(JFRCheckpoint)                         \
 88   template(ShenandoahFullGC)                      \
 89   template(ShenandoahInitMark)                    \
 90   template(ShenandoahFinalMarkStartEvac)          \
 91   template(ShenandoahInitUpdateRefs)              \
 92   template(ShenandoahFinalUpdateRefs)             \
 93   template(ShenandoahFinalRoots)                  \
 94   template(ShenandoahDegeneratedGC)               \
 95   template(RendezvousGCThreads)                   \
 96   template(Exit)                                  \
 97   template(LinuxDllLoad)                          \
 98   template(RotateGCLog)                           \
 99   template(WhiteBoxOperation)                     \
100   template(JVMCIResizeCounters)                   \
101   template(ClassLoaderStatsOperation)             \
102   template(ClassLoaderHierarchyOperation)         \
103   template(DumpHashtable)                         \
104   template(DumpTouchedMethods)                    \
105   template(CleanClassLoaderDataMetaspaces)        \
106   template(PrintCompileQueue)                     \
107   template(PrintClassHierarchy)                   \
108   template(ThreadSuspend)                         \
109   template(ThreadsSuspendJVMTI)                   \
110   template(ICBufferFull)                          \
111   template(ScavengeMonitors)                      \
112   template(PrintMetadata)                         \
113   template(GTestExecuteAtSafepoint)               \
114   template(JFROldObject)                          \
115   template(JvmtiPostObjectFree)
116 
117 class Thread;
118 class outputStream;
119 
120 class VM_Operation : public StackObj {
121  public:
122   enum VMOp_Type {
123     VM_OPS_DO(VM_OP_ENUM)
124     VMOp_Terminating
125   };
126 
127  private:
128   Thread*         _calling_thread;
129 
130   // The VM operation name array
131   static const char* _names[];
132 
133  public:
134   VM_Operation() : _calling_thread(NULL) {}
135 
136   // VM operation support (used by VM thread)
137   Thread* calling_thread() const                 { return _calling_thread; }
138   void set_calling_thread(Thread* thread);
139 
140   // Called by VM thread - does in turn invoke doit(). Do not override this
141   void evaluate();
142 
143   // evaluate() is called by the VMThread and in turn calls doit().
144   // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
145   // doit_prologue() is called in that thread before transferring control to
146   // the VMThread.
147   // If doit_prologue() returns true the VM operation will proceed, and
148   // doit_epilogue() will be called by the JavaThread once the VM operation
149   // completes. If doit_prologue() returns false the VM operation is cancelled.
150   virtual void doit()                            = 0;
151   virtual bool doit_prologue()                   { return true; };
152   virtual void doit_epilogue()                   {};
153 
154   // Configuration. Override these appropriately in subclasses.
155   virtual VMOp_Type type() const = 0;
156   virtual bool allow_nested_vm_operations() const { return false; }
157 
158   // You may override skip_thread_oop_barriers to return true if the operation
159   // does not access thread-private oops (including frames).
160   virtual bool skip_thread_oop_barriers() const { return false; }
161 
162   // An operation can either be done inside a safepoint
163   // or concurrently with Java threads running.
164   virtual bool evaluate_at_safepoint() const { return true; }
165 
166   // Debugging
167   virtual void print_on_error(outputStream* st) const;
168   virtual const char* name() const  { return _names[type()]; }
169   static const char* name(int type) {
170     assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
171     return _names[type];
172   }
173 #ifndef PRODUCT
174   void print_on(outputStream* st) const { print_on_error(st); }
175 #endif
176 };
177 
178 #endif // SHARE_RUNTIME_VMOPERATION_HPP