src/share/vm/runtime/vm_operations.hpp

Tue, 29 May 2018 20:20:25 +0800

author
aoqi
date
Tue, 29 May 2018 20:20:25 +0800
changeset 9122
024be04bb151
parent 9063
777ace6655eb
parent 8856
ac27a9c85bea
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
poonam@8720 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_VM_OPERATIONS_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_VM_OPERATIONS_HPP
aoqi@0 27
aoqi@0 28 #include "classfile/javaClasses.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
aoqi@0 30 #include "oops/oop.hpp"
aoqi@0 31 #include "runtime/thread.hpp"
aoqi@0 32 #include "utilities/top.hpp"
aoqi@0 33
aoqi@0 34 // The following classes are used for operations
aoqi@0 35 // initiated by a Java thread but that must
aoqi@0 36 // take place in the VMThread.
aoqi@0 37
aoqi@0 38 #define VM_OP_ENUM(type) VMOp_##type,
aoqi@0 39
aoqi@0 40 // Note: When new VM_XXX comes up, add 'XXX' to the template table.
aoqi@0 41 #define VM_OPS_DO(template) \
aoqi@0 42 template(Dummy) \
aoqi@0 43 template(ThreadStop) \
aoqi@0 44 template(ThreadDump) \
aoqi@0 45 template(PrintThreads) \
aoqi@0 46 template(FindDeadlocks) \
aoqi@0 47 template(ForceSafepoint) \
aoqi@0 48 template(ForceAsyncSafepoint) \
aoqi@0 49 template(Deoptimize) \
aoqi@0 50 template(DeoptimizeFrame) \
aoqi@0 51 template(DeoptimizeAll) \
aoqi@0 52 template(ZombieAll) \
aoqi@0 53 template(UnlinkSymbols) \
aoqi@0 54 template(Verify) \
aoqi@0 55 template(PrintJNI) \
aoqi@0 56 template(HeapDumper) \
aoqi@0 57 template(DeoptimizeTheWorld) \
aoqi@0 58 template(CollectForMetadataAllocation) \
aoqi@0 59 template(GC_HeapInspection) \
aoqi@0 60 template(GenCollectFull) \
aoqi@0 61 template(GenCollectFullConcurrent) \
aoqi@0 62 template(GenCollectForAllocation) \
aoqi@0 63 template(ParallelGCFailedAllocation) \
aoqi@0 64 template(ParallelGCSystemGC) \
aoqi@0 65 template(CGC_Operation) \
aoqi@0 66 template(CMS_Initial_Mark) \
aoqi@0 67 template(CMS_Final_Remark) \
aoqi@0 68 template(G1CollectFull) \
aoqi@0 69 template(G1CollectForAllocation) \
aoqi@0 70 template(G1IncCollectionPause) \
sjohanss@7118 71 template(DestroyAllocationContext) \
aoqi@0 72 template(EnableBiasedLocking) \
aoqi@0 73 template(RevokeBias) \
aoqi@0 74 template(BulkRevokeBias) \
aoqi@0 75 template(PopulateDumpSharedSpace) \
aoqi@0 76 template(JNIFunctionTableCopier) \
aoqi@0 77 template(RedefineClasses) \
aoqi@0 78 template(GetOwnedMonitorInfo) \
aoqi@0 79 template(GetObjectMonitorUsage) \
aoqi@0 80 template(GetCurrentContendedMonitor) \
aoqi@0 81 template(GetStackTrace) \
aoqi@0 82 template(GetMultipleStackTraces) \
aoqi@0 83 template(GetAllStackTraces) \
aoqi@0 84 template(GetThreadListStackTraces) \
aoqi@0 85 template(GetFrameCount) \
aoqi@0 86 template(GetFrameLocation) \
aoqi@0 87 template(ChangeBreakpoints) \
aoqi@0 88 template(GetOrSetLocal) \
aoqi@0 89 template(GetCurrentLocation) \
aoqi@0 90 template(EnterInterpOnlyMode) \
aoqi@0 91 template(ChangeSingleStep) \
aoqi@0 92 template(HeapWalkOperation) \
aoqi@0 93 template(HeapIterateOperation) \
aoqi@0 94 template(ReportJavaOutOfMemory) \
aoqi@0 95 template(JFRCheckpoint) \
aoqi@0 96 template(Exit) \
aoqi@0 97 template(LinuxDllLoad) \
aoqi@0 98 template(RotateGCLog) \
aoqi@0 99 template(WhiteBoxOperation) \
dbuck@9063 100 template(ClassLoaderStatsOperation) \
aoqi@0 101
aoqi@0 102 class VM_Operation: public CHeapObj<mtInternal> {
aoqi@0 103 public:
aoqi@0 104 enum Mode {
aoqi@0 105 _safepoint, // blocking, safepoint, vm_op C-heap allocated
aoqi@0 106 _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated
aoqi@0 107 _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated
aoqi@0 108 _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated
aoqi@0 109 };
aoqi@0 110
aoqi@0 111 enum VMOp_Type {
aoqi@0 112 VM_OPS_DO(VM_OP_ENUM)
aoqi@0 113 VMOp_Terminating
aoqi@0 114 };
aoqi@0 115
aoqi@0 116 private:
aoqi@0 117 Thread* _calling_thread;
aoqi@0 118 ThreadPriority _priority;
aoqi@0 119 long _timestamp;
aoqi@0 120 VM_Operation* _next;
aoqi@0 121 VM_Operation* _prev;
aoqi@0 122
aoqi@0 123 // The VM operation name array
aoqi@0 124 static const char* _names[];
aoqi@0 125
aoqi@0 126 public:
aoqi@0 127 VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; }
aoqi@0 128 virtual ~VM_Operation() {}
aoqi@0 129
aoqi@0 130 // VM operation support (used by VM thread)
aoqi@0 131 Thread* calling_thread() const { return _calling_thread; }
aoqi@0 132 ThreadPriority priority() { return _priority; }
aoqi@0 133 void set_calling_thread(Thread* thread, ThreadPriority priority);
aoqi@0 134
aoqi@0 135 long timestamp() const { return _timestamp; }
aoqi@0 136 void set_timestamp(long timestamp) { _timestamp = timestamp; }
aoqi@0 137
aoqi@0 138 // Called by VM thread - does in turn invoke doit(). Do not override this
aoqi@0 139 void evaluate();
aoqi@0 140
aoqi@0 141 // evaluate() is called by the VMThread and in turn calls doit().
aoqi@0 142 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
aoqi@0 143 // doit_prologue() is called in that thread before transferring control to
aoqi@0 144 // the VMThread.
aoqi@0 145 // If doit_prologue() returns true the VM operation will proceed, and
aoqi@0 146 // doit_epilogue() will be called by the JavaThread once the VM operation
aoqi@0 147 // completes. If doit_prologue() returns false the VM operation is cancelled.
aoqi@0 148 virtual void doit() = 0;
aoqi@0 149 virtual bool doit_prologue() { return true; };
aoqi@0 150 virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent
aoqi@0 151
aoqi@0 152 // Type test
aoqi@0 153 virtual bool is_methodCompiler() const { return false; }
aoqi@0 154
aoqi@0 155 // Linking
aoqi@0 156 VM_Operation *next() const { return _next; }
aoqi@0 157 VM_Operation *prev() const { return _prev; }
aoqi@0 158 void set_next(VM_Operation *next) { _next = next; }
aoqi@0 159 void set_prev(VM_Operation *prev) { _prev = prev; }
aoqi@0 160
aoqi@0 161 // Configuration. Override these appropriatly in subclasses.
aoqi@0 162 virtual VMOp_Type type() const = 0;
aoqi@0 163 virtual Mode evaluation_mode() const { return _safepoint; }
aoqi@0 164 virtual bool allow_nested_vm_operations() const { return false; }
aoqi@0 165 virtual bool is_cheap_allocated() const { return false; }
aoqi@0 166 virtual void oops_do(OopClosure* f) { /* do nothing */ };
aoqi@0 167
aoqi@0 168 // CAUTION: <don't hang yourself with following rope>
aoqi@0 169 // If you override these methods, make sure that the evaluation
aoqi@0 170 // of these methods is race-free and non-blocking, since these
aoqi@0 171 // methods may be evaluated either by the mutators or by the
aoqi@0 172 // vm thread, either concurrently with mutators or with the mutators
aoqi@0 173 // stopped. In other words, taking locks is verboten, and if there
aoqi@0 174 // are any races in evaluating the conditions, they'd better be benign.
aoqi@0 175 virtual bool evaluate_at_safepoint() const {
aoqi@0 176 return evaluation_mode() == _safepoint ||
aoqi@0 177 evaluation_mode() == _async_safepoint;
aoqi@0 178 }
aoqi@0 179 virtual bool evaluate_concurrently() const {
aoqi@0 180 return evaluation_mode() == _concurrent ||
aoqi@0 181 evaluation_mode() == _async_safepoint;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 static const char* mode_to_string(Mode mode);
aoqi@0 185
aoqi@0 186 // Debugging
poonam@8720 187 virtual void print_on_error(outputStream* st) const;
aoqi@0 188 const char* name() const { return _names[type()]; }
aoqi@0 189 static const char* name(int type) {
aoqi@0 190 assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
aoqi@0 191 return _names[type];
aoqi@0 192 }
aoqi@0 193 #ifndef PRODUCT
aoqi@0 194 void print_on(outputStream* st) const { print_on_error(st); }
aoqi@0 195 #endif
aoqi@0 196 };
aoqi@0 197
aoqi@0 198 class VM_ThreadStop: public VM_Operation {
aoqi@0 199 private:
aoqi@0 200 oop _thread; // The Thread that the Throwable is thrown against
aoqi@0 201 oop _throwable; // The Throwable thrown at the target Thread
aoqi@0 202 public:
aoqi@0 203 // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
aoqi@0 204 // VM operation is executed.
aoqi@0 205 VM_ThreadStop(oop thread, oop throwable) {
aoqi@0 206 _thread = thread;
aoqi@0 207 _throwable = throwable;
aoqi@0 208 }
aoqi@0 209 VMOp_Type type() const { return VMOp_ThreadStop; }
aoqi@0 210 oop target_thread() const { return _thread; }
aoqi@0 211 oop throwable() const { return _throwable;}
aoqi@0 212 void doit();
aoqi@0 213 // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
aoqi@0 214 bool allow_nested_vm_operations() const { return true; }
aoqi@0 215 Mode evaluation_mode() const { return _async_safepoint; }
aoqi@0 216 bool is_cheap_allocated() const { return true; }
aoqi@0 217
aoqi@0 218 // GC support
aoqi@0 219 void oops_do(OopClosure* f) {
aoqi@0 220 f->do_oop(&_thread); f->do_oop(&_throwable);
aoqi@0 221 }
aoqi@0 222 };
aoqi@0 223
aoqi@0 224 // dummy vm op, evaluated just to force a safepoint
aoqi@0 225 class VM_ForceSafepoint: public VM_Operation {
aoqi@0 226 public:
aoqi@0 227 VM_ForceSafepoint() {}
aoqi@0 228 void doit() {}
aoqi@0 229 VMOp_Type type() const { return VMOp_ForceSafepoint; }
aoqi@0 230 };
aoqi@0 231
aoqi@0 232 // dummy vm op, evaluated just to force a safepoint
aoqi@0 233 class VM_ForceAsyncSafepoint: public VM_Operation {
aoqi@0 234 public:
aoqi@0 235 VM_ForceAsyncSafepoint() {}
aoqi@0 236 void doit() {}
aoqi@0 237 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
aoqi@0 238 Mode evaluation_mode() const { return _async_safepoint; }
aoqi@0 239 bool is_cheap_allocated() const { return true; }
aoqi@0 240 };
aoqi@0 241
aoqi@0 242 class VM_Deoptimize: public VM_Operation {
aoqi@0 243 public:
aoqi@0 244 VM_Deoptimize() {}
aoqi@0 245 VMOp_Type type() const { return VMOp_Deoptimize; }
aoqi@0 246 void doit();
aoqi@0 247 bool allow_nested_vm_operations() const { return true; }
aoqi@0 248 };
aoqi@0 249
aoqi@0 250
aoqi@0 251 // Deopt helper that can deoptimize frames in threads other than the
aoqi@0 252 // current thread. Only used through Deoptimization::deoptimize_frame.
aoqi@0 253 class VM_DeoptimizeFrame: public VM_Operation {
aoqi@0 254 friend class Deoptimization;
aoqi@0 255
aoqi@0 256 private:
aoqi@0 257 JavaThread* _thread;
aoqi@0 258 intptr_t* _id;
aoqi@0 259 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
aoqi@0 260
aoqi@0 261 public:
aoqi@0 262 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
aoqi@0 263 void doit();
aoqi@0 264 bool allow_nested_vm_operations() const { return true; }
aoqi@0 265 };
aoqi@0 266
aoqi@0 267 #ifndef PRODUCT
aoqi@0 268 class VM_DeoptimizeAll: public VM_Operation {
aoqi@0 269 private:
aoqi@0 270 KlassHandle _dependee;
aoqi@0 271 public:
aoqi@0 272 VM_DeoptimizeAll() {}
aoqi@0 273 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
aoqi@0 274 void doit();
aoqi@0 275 bool allow_nested_vm_operations() const { return true; }
aoqi@0 276 };
aoqi@0 277
aoqi@0 278
aoqi@0 279 class VM_ZombieAll: public VM_Operation {
aoqi@0 280 public:
aoqi@0 281 VM_ZombieAll() {}
aoqi@0 282 VMOp_Type type() const { return VMOp_ZombieAll; }
aoqi@0 283 void doit();
aoqi@0 284 bool allow_nested_vm_operations() const { return true; }
aoqi@0 285 };
aoqi@0 286 #endif // PRODUCT
aoqi@0 287
aoqi@0 288 class VM_UnlinkSymbols: public VM_Operation {
aoqi@0 289 public:
aoqi@0 290 VM_UnlinkSymbols() {}
aoqi@0 291 VMOp_Type type() const { return VMOp_UnlinkSymbols; }
aoqi@0 292 void doit();
aoqi@0 293 bool allow_nested_vm_operations() const { return true; }
aoqi@0 294 };
aoqi@0 295
aoqi@0 296 class VM_Verify: public VM_Operation {
aoqi@0 297 private:
aoqi@0 298 bool _silent;
aoqi@0 299 public:
aoqi@0 300 VM_Verify(bool silent = VerifySilently) : _silent(silent) {}
aoqi@0 301 VMOp_Type type() const { return VMOp_Verify; }
aoqi@0 302 void doit();
aoqi@0 303 };
aoqi@0 304
aoqi@0 305
aoqi@0 306 class VM_PrintThreads: public VM_Operation {
aoqi@0 307 private:
aoqi@0 308 outputStream* _out;
aoqi@0 309 bool _print_concurrent_locks;
aoqi@0 310 public:
aoqi@0 311 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
aoqi@0 312 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
aoqi@0 313 VMOp_Type type() const { return VMOp_PrintThreads; }
aoqi@0 314 void doit();
aoqi@0 315 bool doit_prologue();
aoqi@0 316 void doit_epilogue();
aoqi@0 317 };
aoqi@0 318
aoqi@0 319 class VM_PrintJNI: public VM_Operation {
aoqi@0 320 private:
aoqi@0 321 outputStream* _out;
aoqi@0 322 public:
aoqi@0 323 VM_PrintJNI() { _out = tty; }
aoqi@0 324 VM_PrintJNI(outputStream* out) { _out = out; }
aoqi@0 325 VMOp_Type type() const { return VMOp_PrintJNI; }
aoqi@0 326 void doit();
aoqi@0 327 };
aoqi@0 328
aoqi@0 329 class DeadlockCycle;
aoqi@0 330 class VM_FindDeadlocks: public VM_Operation {
aoqi@0 331 private:
aoqi@0 332 bool _concurrent_locks;
aoqi@0 333 DeadlockCycle* _deadlocks;
aoqi@0 334 outputStream* _out;
aoqi@0 335
aoqi@0 336 public:
aoqi@0 337 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
aoqi@0 338 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
aoqi@0 339 ~VM_FindDeadlocks();
aoqi@0 340
aoqi@0 341 DeadlockCycle* result() { return _deadlocks; };
aoqi@0 342 VMOp_Type type() const { return VMOp_FindDeadlocks; }
aoqi@0 343 void doit();
aoqi@0 344 bool doit_prologue();
aoqi@0 345 };
aoqi@0 346
aoqi@0 347 class ThreadDumpResult;
aoqi@0 348 class ThreadSnapshot;
aoqi@0 349 class ThreadConcurrentLocks;
aoqi@0 350
aoqi@0 351 class VM_ThreadDump : public VM_Operation {
aoqi@0 352 private:
aoqi@0 353 ThreadDumpResult* _result;
aoqi@0 354 int _num_threads;
aoqi@0 355 GrowableArray<instanceHandle>* _threads;
aoqi@0 356 int _max_depth;
aoqi@0 357 bool _with_locked_monitors;
aoqi@0 358 bool _with_locked_synchronizers;
aoqi@0 359
aoqi@0 360 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
aoqi@0 361
aoqi@0 362 public:
aoqi@0 363 VM_ThreadDump(ThreadDumpResult* result,
aoqi@0 364 int max_depth, // -1 indicates entire stack
aoqi@0 365 bool with_locked_monitors,
aoqi@0 366 bool with_locked_synchronizers);
aoqi@0 367
aoqi@0 368 VM_ThreadDump(ThreadDumpResult* result,
aoqi@0 369 GrowableArray<instanceHandle>* threads,
aoqi@0 370 int num_threads, // -1 indicates entire stack
aoqi@0 371 int max_depth,
aoqi@0 372 bool with_locked_monitors,
aoqi@0 373 bool with_locked_synchronizers);
aoqi@0 374
aoqi@0 375 VMOp_Type type() const { return VMOp_ThreadDump; }
aoqi@0 376 void doit();
aoqi@0 377 bool doit_prologue();
aoqi@0 378 void doit_epilogue();
aoqi@0 379 };
aoqi@0 380
aoqi@0 381
aoqi@0 382 class VM_Exit: public VM_Operation {
aoqi@0 383 private:
aoqi@0 384 int _exit_code;
aoqi@0 385 static volatile bool _vm_exited;
aoqi@0 386 static Thread * _shutdown_thread;
aoqi@0 387 static void wait_if_vm_exited();
aoqi@0 388 public:
aoqi@0 389 VM_Exit(int exit_code) {
aoqi@0 390 _exit_code = exit_code;
aoqi@0 391 }
aoqi@0 392 static int wait_for_threads_in_native_to_block();
aoqi@0 393 static int set_vm_exited();
aoqi@0 394 static bool vm_exited() { return _vm_exited; }
aoqi@0 395 static void block_if_vm_exited() {
aoqi@0 396 if (_vm_exited) {
aoqi@0 397 wait_if_vm_exited();
aoqi@0 398 }
aoqi@0 399 }
aoqi@0 400 VMOp_Type type() const { return VMOp_Exit; }
aoqi@0 401 void doit();
aoqi@0 402 };
aoqi@0 403
aoqi@0 404
aoqi@0 405 class VM_RotateGCLog: public VM_Operation {
aoqi@0 406 private:
aoqi@0 407 outputStream* _out;
aoqi@0 408
aoqi@0 409 public:
aoqi@0 410 VM_RotateGCLog(outputStream* st) : _out(st) {}
aoqi@0 411 VMOp_Type type() const { return VMOp_RotateGCLog; }
aoqi@0 412 void doit() { gclog_or_tty->rotate_log(true, _out); }
aoqi@0 413 };
aoqi@0 414
aoqi@0 415 #endif // SHARE_VM_RUNTIME_VM_OPERATIONS_HPP

mercurial