src/share/vm/runtime/vm_operations.hpp

Thu, 14 Aug 2014 15:16:07 +0200

author
dsimms
date
Thu, 14 Aug 2014 15:16:07 +0200
changeset 7032
fa62fb12cdca
parent 6610
b127b0d6de7f
child 6876
710a3c8b516e
child 7118
227a9e5e4b4a
permissions
-rw-r--r--

6311046: -Xcheck:jni should support checking of GetPrimitiveArrayCritical.
Summary: Wrapped memory with standard bounds checking "GuardedMemory".
Reviewed-by: zgu, fparain, dcubed

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

mercurial