1 /*
2 * Copyright (c) 1997, 2024, 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(Halt) \
39 template(SafepointALot) \
40 template(ThreadDump) \
41 template(PrintThreads) \
42 template(FindDeadlocks) \
43 template(ClearICs) \
44 template(ForceSafepoint) \
45 template(DeoptimizeFrame) \
46 template(DeoptimizeAll) \
47 template(ZombieAll) \
48 template(Verify) \
49 template(HeapDumper) \
50 template(CollectForMetadataAllocation) \
51 template(CollectForCodeCacheAllocation) \
52 template(GC_HeapInspection) \
53 template(SerialCollectForAllocation) \
54 template(SerialGCCollect) \
55 template(ParallelCollectForAllocation) \
56 template(ParallelGCCollect) \
57 template(G1CollectForAllocation) \
58 template(G1CollectFull) \
59 template(G1PauseRemark) \
60 template(G1PauseCleanup) \
61 template(G1TryInitiateConcMark) \
62 template(ZMarkEndOld) \
63 template(ZMarkEndYoung) \
64 template(ZMarkFlushOperation) \
65 template(ZMarkStartYoung) \
66 template(ZMarkStartYoungAndOld) \
67 template(ZRelocateStartOld) \
68 template(ZRelocateStartYoung) \
69 template(ZRendezvousGCThreads) \
70 template(ZVerifyOld) \
71 template(XMarkStart) \
72 template(XMarkEnd) \
73 template(XRelocateStart) \
74 template(XVerify) \
75 template(HandshakeAllThreads) \
76 template(PopulateDumpSharedSpace) \
77 template(JNIFunctionTableCopier) \
78 template(RedefineClasses) \
79 template(GetObjectMonitorUsage) \
80 template(GetAllStackTraces) \
81 template(GetThreadListStackTraces) \
82 template(ChangeBreakpoints) \
83 template(GetOrSetLocal) \
84 template(VirtualThreadGetOrSetLocal) \
85 template(ChangeSingleStep) \
86 template(SetNotifyJvmtiEventsMode) \
87 template(HeapWalkOperation) \
88 template(HeapIterateOperation) \
89 template(ReportJavaOutOfMemory) \
90 template(JFRSafepointClear) \
91 template(JFRSafepointWrite) \
92 template(ShenandoahFullGC) \
93 template(ShenandoahInitMark) \
94 template(ShenandoahFinalMarkStartEvac) \
95 template(ShenandoahInitUpdateRefs) \
96 template(ShenandoahFinalUpdateRefs) \
97 template(ShenandoahFinalRoots) \
98 template(ShenandoahDegeneratedGC) \
99 template(Exit) \
100 template(LinuxDllLoad) \
101 template(WhiteBoxOperation) \
102 template(JVMCIResizeCounters) \
103 template(ClassLoaderStatsOperation) \
104 template(ClassLoaderHierarchyOperation) \
105 template(DumpHashtable) \
106 template(CleanClassLoaderDataMetaspaces) \
107 template(RehashStringTable) \
108 template(RehashSymbolTable) \
109 template(PrintCompileQueue) \
110 template(PrintClassHierarchy) \
111 template(PrintClasses) \
112 template(ICBufferFull) \
113 template(PrintMetadata) \
114 template(GTestExecuteAtSafepoint) \
115 template(GTestStopSafepoint) \
116 template(JFROldObject) \
117 template(ClassPrintLayout) \
118 template(JvmtiPostObjectFree) \
119 template(RendezvousGCThreads)
120
121 class Thread;
122 class outputStream;
123
124 class VM_Operation : public StackObj {
125 public:
126 enum VMOp_Type {
127 VM_OPS_DO(VM_OP_ENUM)
128 VMOp_Terminating
129 };
130
131 private:
132 Thread* _calling_thread;
133
134 // The VM operation name array
135 static const char* _names[];
136
137 public:
138 VM_Operation() : _calling_thread(nullptr) {}
139
140 // VM operation support (used by VM thread)
141 Thread* calling_thread() const { return _calling_thread; }
142 void set_calling_thread(Thread* thread);
143
144 // Called by VM thread - does in turn invoke doit(). Do not override this
145 void evaluate();
146
147 // evaluate() is called by the VMThread and in turn calls doit().
148 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
149 // doit_prologue() is called in that thread before transferring control to
150 // the VMThread.
151 // If doit_prologue() returns true the VM operation will proceed, and
152 // doit_epilogue() will be called by the JavaThread once the VM operation
153 // completes. If doit_prologue() returns false the VM operation is cancelled.
154 virtual void doit() = 0;
155 virtual bool doit_prologue() { return true; };
156 virtual void doit_epilogue() {};
157
158 // Configuration. Override these appropriately in subclasses.
159 virtual VMOp_Type type() const = 0;
160 virtual bool allow_nested_vm_operations() const { return false; }
161
162 // You may override skip_thread_oop_barriers to return true if the operation
163 // does not access thread-private oops (including frames).
164 virtual bool skip_thread_oop_barriers() const { return false; }
165
166 // An operation can either be done inside a safepoint
167 // or concurrently with Java threads running.
168 virtual bool evaluate_at_safepoint() const { return true; }
169
170 // Debugging
171 virtual void print_on_error(outputStream* st) const;
172 virtual 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 // Extra information about what triggered this operation.
178 virtual const char* cause() const { return nullptr; }
179 #ifndef PRODUCT
180 void print_on(outputStream* st) const { print_on_error(st); }
181 #endif
182 };
183
184 #endif // SHARE_RUNTIME_VMOPERATION_HPP
--- EOF ---