src/share/vm/runtime/vm_operations.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, 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) \
aoqi@0 71 template(EnableBiasedLocking) \
aoqi@0 72 template(RevokeBias) \
aoqi@0 73 template(BulkRevokeBias) \
aoqi@0 74 template(PopulateDumpSharedSpace) \
aoqi@0 75 template(JNIFunctionTableCopier) \
aoqi@0 76 template(RedefineClasses) \
aoqi@0 77 template(GetOwnedMonitorInfo) \
aoqi@0 78 template(GetObjectMonitorUsage) \
aoqi@0 79 template(GetCurrentContendedMonitor) \
aoqi@0 80 template(GetStackTrace) \
aoqi@0 81 template(GetMultipleStackTraces) \
aoqi@0 82 template(GetAllStackTraces) \
aoqi@0 83 template(GetThreadListStackTraces) \
aoqi@0 84 template(GetFrameCount) \
aoqi@0 85 template(GetFrameLocation) \
aoqi@0 86 template(ChangeBreakpoints) \
aoqi@0 87 template(GetOrSetLocal) \
aoqi@0 88 template(GetCurrentLocation) \
aoqi@0 89 template(EnterInterpOnlyMode) \
aoqi@0 90 template(ChangeSingleStep) \
aoqi@0 91 template(HeapWalkOperation) \
aoqi@0 92 template(HeapIterateOperation) \
aoqi@0 93 template(ReportJavaOutOfMemory) \
aoqi@0 94 template(JFRCheckpoint) \
aoqi@0 95 template(Exit) \
aoqi@0 96 template(LinuxDllLoad) \
aoqi@0 97 template(RotateGCLog) \
aoqi@0 98 template(WhiteBoxOperation) \
aoqi@0 99
aoqi@0 100 class VM_Operation: public CHeapObj<mtInternal> {
aoqi@0 101 public:
aoqi@0 102 enum Mode {
aoqi@0 103 _safepoint, // blocking, safepoint, vm_op C-heap allocated
aoqi@0 104 _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated
aoqi@0 105 _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated
aoqi@0 106 _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated
aoqi@0 107 };
aoqi@0 108
aoqi@0 109 enum VMOp_Type {
aoqi@0 110 VM_OPS_DO(VM_OP_ENUM)
aoqi@0 111 VMOp_Terminating
aoqi@0 112 };
aoqi@0 113
aoqi@0 114 private:
aoqi@0 115 Thread* _calling_thread;
aoqi@0 116 ThreadPriority _priority;
aoqi@0 117 long _timestamp;
aoqi@0 118 VM_Operation* _next;
aoqi@0 119 VM_Operation* _prev;
aoqi@0 120
aoqi@0 121 // The VM operation name array
aoqi@0 122 static const char* _names[];
aoqi@0 123
aoqi@0 124 public:
aoqi@0 125 VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; }
aoqi@0 126 virtual ~VM_Operation() {}
aoqi@0 127
aoqi@0 128 // VM operation support (used by VM thread)
aoqi@0 129 Thread* calling_thread() const { return _calling_thread; }
aoqi@0 130 ThreadPriority priority() { return _priority; }
aoqi@0 131 void set_calling_thread(Thread* thread, ThreadPriority priority);
aoqi@0 132
aoqi@0 133 long timestamp() const { return _timestamp; }
aoqi@0 134 void set_timestamp(long timestamp) { _timestamp = timestamp; }
aoqi@0 135
aoqi@0 136 // Called by VM thread - does in turn invoke doit(). Do not override this
aoqi@0 137 void evaluate();
aoqi@0 138
aoqi@0 139 // evaluate() is called by the VMThread and in turn calls doit().
aoqi@0 140 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
aoqi@0 141 // doit_prologue() is called in that thread before transferring control to
aoqi@0 142 // the VMThread.
aoqi@0 143 // If doit_prologue() returns true the VM operation will proceed, and
aoqi@0 144 // doit_epilogue() will be called by the JavaThread once the VM operation
aoqi@0 145 // completes. If doit_prologue() returns false the VM operation is cancelled.
aoqi@0 146 virtual void doit() = 0;
aoqi@0 147 virtual bool doit_prologue() { return true; };
aoqi@0 148 virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent
aoqi@0 149
aoqi@0 150 // Type test
aoqi@0 151 virtual bool is_methodCompiler() const { return false; }
aoqi@0 152
aoqi@0 153 // Linking
aoqi@0 154 VM_Operation *next() const { return _next; }
aoqi@0 155 VM_Operation *prev() const { return _prev; }
aoqi@0 156 void set_next(VM_Operation *next) { _next = next; }
aoqi@0 157 void set_prev(VM_Operation *prev) { _prev = prev; }
aoqi@0 158
aoqi@0 159 // Configuration. Override these appropriatly in subclasses.
aoqi@0 160 virtual VMOp_Type type() const = 0;
aoqi@0 161 virtual Mode evaluation_mode() const { return _safepoint; }
aoqi@0 162 virtual bool allow_nested_vm_operations() const { return false; }
aoqi@0 163 virtual bool is_cheap_allocated() const { return false; }
aoqi@0 164 virtual void oops_do(OopClosure* f) { /* do nothing */ };
aoqi@0 165
aoqi@0 166 // CAUTION: <don't hang yourself with following rope>
aoqi@0 167 // If you override these methods, make sure that the evaluation
aoqi@0 168 // of these methods is race-free and non-blocking, since these
aoqi@0 169 // methods may be evaluated either by the mutators or by the
aoqi@0 170 // vm thread, either concurrently with mutators or with the mutators
aoqi@0 171 // stopped. In other words, taking locks is verboten, and if there
aoqi@0 172 // are any races in evaluating the conditions, they'd better be benign.
aoqi@0 173 virtual bool evaluate_at_safepoint() const {
aoqi@0 174 return evaluation_mode() == _safepoint ||
aoqi@0 175 evaluation_mode() == _async_safepoint;
aoqi@0 176 }
aoqi@0 177 virtual bool evaluate_concurrently() const {
aoqi@0 178 return evaluation_mode() == _concurrent ||
aoqi@0 179 evaluation_mode() == _async_safepoint;
aoqi@0 180 }
aoqi@0 181
aoqi@0 182 static const char* mode_to_string(Mode mode);
aoqi@0 183
aoqi@0 184 // Debugging
aoqi@0 185 void print_on_error(outputStream* st) const;
aoqi@0 186 const char* name() const { return _names[type()]; }
aoqi@0 187 static const char* name(int type) {
aoqi@0 188 assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
aoqi@0 189 return _names[type];
aoqi@0 190 }
aoqi@0 191 #ifndef PRODUCT
aoqi@0 192 void print_on(outputStream* st) const { print_on_error(st); }
aoqi@0 193 #endif
aoqi@0 194 };
aoqi@0 195
aoqi@0 196 class VM_ThreadStop: public VM_Operation {
aoqi@0 197 private:
aoqi@0 198 oop _thread; // The Thread that the Throwable is thrown against
aoqi@0 199 oop _throwable; // The Throwable thrown at the target Thread
aoqi@0 200 public:
aoqi@0 201 // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
aoqi@0 202 // VM operation is executed.
aoqi@0 203 VM_ThreadStop(oop thread, oop throwable) {
aoqi@0 204 _thread = thread;
aoqi@0 205 _throwable = throwable;
aoqi@0 206 }
aoqi@0 207 VMOp_Type type() const { return VMOp_ThreadStop; }
aoqi@0 208 oop target_thread() const { return _thread; }
aoqi@0 209 oop throwable() const { return _throwable;}
aoqi@0 210 void doit();
aoqi@0 211 // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
aoqi@0 212 bool allow_nested_vm_operations() const { return true; }
aoqi@0 213 Mode evaluation_mode() const { return _async_safepoint; }
aoqi@0 214 bool is_cheap_allocated() const { return true; }
aoqi@0 215
aoqi@0 216 // GC support
aoqi@0 217 void oops_do(OopClosure* f) {
aoqi@0 218 f->do_oop(&_thread); f->do_oop(&_throwable);
aoqi@0 219 }
aoqi@0 220 };
aoqi@0 221
aoqi@0 222 // dummy vm op, evaluated just to force a safepoint
aoqi@0 223 class VM_ForceSafepoint: public VM_Operation {
aoqi@0 224 public:
aoqi@0 225 VM_ForceSafepoint() {}
aoqi@0 226 void doit() {}
aoqi@0 227 VMOp_Type type() const { return VMOp_ForceSafepoint; }
aoqi@0 228 };
aoqi@0 229
aoqi@0 230 // dummy vm op, evaluated just to force a safepoint
aoqi@0 231 class VM_ForceAsyncSafepoint: public VM_Operation {
aoqi@0 232 public:
aoqi@0 233 VM_ForceAsyncSafepoint() {}
aoqi@0 234 void doit() {}
aoqi@0 235 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
aoqi@0 236 Mode evaluation_mode() const { return _async_safepoint; }
aoqi@0 237 bool is_cheap_allocated() const { return true; }
aoqi@0 238 };
aoqi@0 239
aoqi@0 240 class VM_Deoptimize: public VM_Operation {
aoqi@0 241 public:
aoqi@0 242 VM_Deoptimize() {}
aoqi@0 243 VMOp_Type type() const { return VMOp_Deoptimize; }
aoqi@0 244 void doit();
aoqi@0 245 bool allow_nested_vm_operations() const { return true; }
aoqi@0 246 };
aoqi@0 247
aoqi@0 248
aoqi@0 249 // Deopt helper that can deoptimize frames in threads other than the
aoqi@0 250 // current thread. Only used through Deoptimization::deoptimize_frame.
aoqi@0 251 class VM_DeoptimizeFrame: public VM_Operation {
aoqi@0 252 friend class Deoptimization;
aoqi@0 253
aoqi@0 254 private:
aoqi@0 255 JavaThread* _thread;
aoqi@0 256 intptr_t* _id;
aoqi@0 257 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
aoqi@0 258
aoqi@0 259 public:
aoqi@0 260 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
aoqi@0 261 void doit();
aoqi@0 262 bool allow_nested_vm_operations() const { return true; }
aoqi@0 263 };
aoqi@0 264
aoqi@0 265 #ifndef PRODUCT
aoqi@0 266 class VM_DeoptimizeAll: public VM_Operation {
aoqi@0 267 private:
aoqi@0 268 KlassHandle _dependee;
aoqi@0 269 public:
aoqi@0 270 VM_DeoptimizeAll() {}
aoqi@0 271 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
aoqi@0 272 void doit();
aoqi@0 273 bool allow_nested_vm_operations() const { return true; }
aoqi@0 274 };
aoqi@0 275
aoqi@0 276
aoqi@0 277 class VM_ZombieAll: public VM_Operation {
aoqi@0 278 public:
aoqi@0 279 VM_ZombieAll() {}
aoqi@0 280 VMOp_Type type() const { return VMOp_ZombieAll; }
aoqi@0 281 void doit();
aoqi@0 282 bool allow_nested_vm_operations() const { return true; }
aoqi@0 283 };
aoqi@0 284 #endif // PRODUCT
aoqi@0 285
aoqi@0 286 class VM_UnlinkSymbols: public VM_Operation {
aoqi@0 287 public:
aoqi@0 288 VM_UnlinkSymbols() {}
aoqi@0 289 VMOp_Type type() const { return VMOp_UnlinkSymbols; }
aoqi@0 290 void doit();
aoqi@0 291 bool allow_nested_vm_operations() const { return true; }
aoqi@0 292 };
aoqi@0 293
aoqi@0 294 class VM_Verify: public VM_Operation {
aoqi@0 295 private:
aoqi@0 296 bool _silent;
aoqi@0 297 public:
aoqi@0 298 VM_Verify(bool silent = VerifySilently) : _silent(silent) {}
aoqi@0 299 VMOp_Type type() const { return VMOp_Verify; }
aoqi@0 300 void doit();
aoqi@0 301 };
aoqi@0 302
aoqi@0 303
aoqi@0 304 class VM_PrintThreads: public VM_Operation {
aoqi@0 305 private:
aoqi@0 306 outputStream* _out;
aoqi@0 307 bool _print_concurrent_locks;
aoqi@0 308 public:
aoqi@0 309 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
aoqi@0 310 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
aoqi@0 311 VMOp_Type type() const { return VMOp_PrintThreads; }
aoqi@0 312 void doit();
aoqi@0 313 bool doit_prologue();
aoqi@0 314 void doit_epilogue();
aoqi@0 315 };
aoqi@0 316
aoqi@0 317 class VM_PrintJNI: public VM_Operation {
aoqi@0 318 private:
aoqi@0 319 outputStream* _out;
aoqi@0 320 public:
aoqi@0 321 VM_PrintJNI() { _out = tty; }
aoqi@0 322 VM_PrintJNI(outputStream* out) { _out = out; }
aoqi@0 323 VMOp_Type type() const { return VMOp_PrintJNI; }
aoqi@0 324 void doit();
aoqi@0 325 };
aoqi@0 326
aoqi@0 327 class DeadlockCycle;
aoqi@0 328 class VM_FindDeadlocks: public VM_Operation {
aoqi@0 329 private:
aoqi@0 330 bool _concurrent_locks;
aoqi@0 331 DeadlockCycle* _deadlocks;
aoqi@0 332 outputStream* _out;
aoqi@0 333
aoqi@0 334 public:
aoqi@0 335 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
aoqi@0 336 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
aoqi@0 337 ~VM_FindDeadlocks();
aoqi@0 338
aoqi@0 339 DeadlockCycle* result() { return _deadlocks; };
aoqi@0 340 VMOp_Type type() const { return VMOp_FindDeadlocks; }
aoqi@0 341 void doit();
aoqi@0 342 bool doit_prologue();
aoqi@0 343 };
aoqi@0 344
aoqi@0 345 class ThreadDumpResult;
aoqi@0 346 class ThreadSnapshot;
aoqi@0 347 class ThreadConcurrentLocks;
aoqi@0 348
aoqi@0 349 class VM_ThreadDump : public VM_Operation {
aoqi@0 350 private:
aoqi@0 351 ThreadDumpResult* _result;
aoqi@0 352 int _num_threads;
aoqi@0 353 GrowableArray<instanceHandle>* _threads;
aoqi@0 354 int _max_depth;
aoqi@0 355 bool _with_locked_monitors;
aoqi@0 356 bool _with_locked_synchronizers;
aoqi@0 357
aoqi@0 358 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
aoqi@0 359
aoqi@0 360 public:
aoqi@0 361 VM_ThreadDump(ThreadDumpResult* result,
aoqi@0 362 int max_depth, // -1 indicates entire stack
aoqi@0 363 bool with_locked_monitors,
aoqi@0 364 bool with_locked_synchronizers);
aoqi@0 365
aoqi@0 366 VM_ThreadDump(ThreadDumpResult* result,
aoqi@0 367 GrowableArray<instanceHandle>* threads,
aoqi@0 368 int num_threads, // -1 indicates entire stack
aoqi@0 369 int max_depth,
aoqi@0 370 bool with_locked_monitors,
aoqi@0 371 bool with_locked_synchronizers);
aoqi@0 372
aoqi@0 373 VMOp_Type type() const { return VMOp_ThreadDump; }
aoqi@0 374 void doit();
aoqi@0 375 bool doit_prologue();
aoqi@0 376 void doit_epilogue();
aoqi@0 377 };
aoqi@0 378
aoqi@0 379
aoqi@0 380 class VM_Exit: public VM_Operation {
aoqi@0 381 private:
aoqi@0 382 int _exit_code;
aoqi@0 383 static volatile bool _vm_exited;
aoqi@0 384 static Thread * _shutdown_thread;
aoqi@0 385 static void wait_if_vm_exited();
aoqi@0 386 public:
aoqi@0 387 VM_Exit(int exit_code) {
aoqi@0 388 _exit_code = exit_code;
aoqi@0 389 }
aoqi@0 390 static int wait_for_threads_in_native_to_block();
aoqi@0 391 static int set_vm_exited();
aoqi@0 392 static bool vm_exited() { return _vm_exited; }
aoqi@0 393 static void block_if_vm_exited() {
aoqi@0 394 if (_vm_exited) {
aoqi@0 395 wait_if_vm_exited();
aoqi@0 396 }
aoqi@0 397 }
aoqi@0 398 VMOp_Type type() const { return VMOp_Exit; }
aoqi@0 399 void doit();
aoqi@0 400 };
aoqi@0 401
aoqi@0 402
aoqi@0 403 class VM_RotateGCLog: public VM_Operation {
aoqi@0 404 private:
aoqi@0 405 outputStream* _out;
aoqi@0 406
aoqi@0 407 public:
aoqi@0 408 VM_RotateGCLog(outputStream* st) : _out(st) {}
aoqi@0 409 VMOp_Type type() const { return VMOp_RotateGCLog; }
aoqi@0 410 void doit() { gclog_or_tty->rotate_log(true, _out); }
aoqi@0 411 };
aoqi@0 412
aoqi@0 413 #endif // SHARE_VM_RUNTIME_VM_OPERATIONS_HPP

mercurial