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(HeapDumper)                            \
 51   template(DeoptimizeTheWorld)                    \
 52   template(CollectForMetadataAllocation)          \
 53   template(GC_HeapInspection)                     \
 54   template(GenCollectFull)                        \
 55   template(GenCollectFullConcurrent)              \
 56   template(GenCollectForAllocation)               \
 57   template(ParallelGCFailedAllocation)            \
 58   template(ParallelGCSystemGC)                    \
 59   template(G1CollectForAllocation)                \
 60   template(G1CollectFull)                         \
 61   template(G1Concurrent)                          \
 62   template(G1TryInitiateConcMark)                 \
 63   template(ZMarkStart)                            \
 64   template(ZMarkEnd)                              \
 65   template(ZRelocateStart)                        \
 66   template(ZVerify)                               \
 67   template(HandshakeOneThread)                    \
 68   template(HandshakeAllThreads)                   \
 69   template(HandshakeFallback)                     \
 70   template(PopulateDumpSharedSpace)               \
 71   template(JNIFunctionTableCopier)                \
 72   template(RedefineClasses)                       \
 73   template(GetObjectMonitorUsage)                 \
 74   template(GetAllStackTraces)                     \
 75   template(GetThreadListStackTraces)              \
 76   template(ChangeBreakpoints)                     \
 77   template(GetOrSetLocal)                         \
 78   template(ChangeSingleStep)                      \
 79   template(HeapWalkOperation)                     \
 80   template(HeapIterateOperation)                  \
 81   template(HeapObjectStatistics)                  \
 82   template(ReportJavaOutOfMemory)                 \
 83   template(JFRCheckpoint)                         \
 84   template(ShenandoahFullGC)                      \
 85   template(ShenandoahInitMark)                    \
 86   template(ShenandoahFinalMarkStartEvac)          \
 87   template(ShenandoahInitUpdateRefs)              \
 88   template(ShenandoahFinalUpdateRefs)             \
 89   template(ShenandoahFinalRoots)                  \
 90   template(ShenandoahDegeneratedGC)               \
 91   template(RendezvousGCThreads)                   \
 92   template(Exit)                                  \
 93   template(LinuxDllLoad)                          \
 94   template(RotateGCLog)                           \
 95   template(WhiteBoxOperation)                     \
 96   template(JVMCIResizeCounters)                   \
 97   template(ClassLoaderStatsOperation)             \
 98   template(ClassLoaderHierarchyOperation)         \
 99   template(DumpHashtable)                         \
100   template(DumpTouchedMethods)                    \
101   template(CleanClassLoaderDataMetaspaces)        \
102   template(PrintCompileQueue)                     \
103   template(PrintClassHierarchy)                   \
104   template(ThreadSuspend)                         \
105   template(ThreadsSuspendJVMTI)                   \
106   template(ICBufferFull)                          \
107   template(ScavengeMonitors)                      \
108   template(PrintMetadata)                         \
109   template(GTestExecuteAtSafepoint)               \
110   template(JFROldObject)                          \
111   template(JvmtiPostObjectFree)
112 
113 class Thread;
114 class outputStream;
115 
116 class VM_Operation : public StackObj {
117  public:
118   enum VMOp_Type {
119     VM_OPS_DO(VM_OP_ENUM)
120     VMOp_Terminating
121   };
122 
123  private:
124   Thread*         _calling_thread;
125 
126   // The VM operation name array
127   static const char* _names[];
128 
129  public:
130   VM_Operation() : _calling_thread(NULL) {}
131 
132   // VM operation support (used by VM thread)
133   Thread* calling_thread() const                 { return _calling_thread; }
134   void set_calling_thread(Thread* thread);
135 
136   // Called by VM thread - does in turn invoke doit(). Do not override this
137   void evaluate();
138 
139   // evaluate() is called by the VMThread and in turn calls doit().
140   // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
141   // doit_prologue() is called in that thread before transferring control to
142   // the VMThread.
143   // If doit_prologue() returns true the VM operation will proceed, and
144   // doit_epilogue() will be called by the JavaThread once the VM operation
145   // completes. If doit_prologue() returns false the VM operation is cancelled.
146   virtual void doit()                            = 0;
147   virtual bool doit_prologue()                   { return true; };
148   virtual void doit_epilogue()                   {};
149 
150   // Configuration. Override these appropriately in subclasses.
151   virtual VMOp_Type type() const = 0;
152   virtual bool allow_nested_vm_operations() const { return false; }
153 
154   // You may override skip_thread_oop_barriers to return true if the operation
155   // does not access thread-private oops (including frames).
156   virtual bool skip_thread_oop_barriers() const { return false; }
157 
158   // An operation can either be done inside a safepoint
159   // or concurrently with Java threads running.
160   virtual bool evaluate_at_safepoint() const { return true; }
161 
162   // Debugging
163   virtual void print_on_error(outputStream* st) const;
164   virtual const char* name() const  { return _names[type()]; }
165   static const char* name(int type) {
166     assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
167     return _names[type];
168   }
169 #ifndef PRODUCT
170   void print_on(outputStream* st) const { print_on_error(st); }
171 #endif
172 };
173 
174 #endif // SHARE_RUNTIME_VMOPERATION_HPP