src/share/vm/runtime/vm_operations.hpp

Tue, 01 Apr 2008 15:13:47 +0400

author
apetrusenko
date
Tue, 01 Apr 2008 15:13:47 +0400
changeset 574
c0492d52d55b
parent 435
a61af66fc99e
child 631
d1605aabd0a1
child 777
37f87013dfd8
permissions
-rw-r--r--

6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
Reviewed-by: ysr, jmasa

duke@435 1 /*
duke@435 2 * Copyright 1997-2007 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // The following classes are used for operations
duke@435 26 // initiated by a Java thread but that must
duke@435 27 // take place in the VMThread.
duke@435 28
duke@435 29 #define VM_OP_ENUM(type) VMOp_##type,
duke@435 30
duke@435 31 // Note: When new VM_XXX comes up, add 'XXX' to the template table.
duke@435 32 #define VM_OPS_DO(template) \
duke@435 33 template(Dummy) \
duke@435 34 template(ThreadStop) \
duke@435 35 template(ThreadDump) \
duke@435 36 template(PrintThreads) \
duke@435 37 template(FindDeadlocks) \
duke@435 38 template(ForceSafepoint) \
duke@435 39 template(ForceAsyncSafepoint) \
duke@435 40 template(Deoptimize) \
duke@435 41 template(DeoptimizeFrame) \
duke@435 42 template(DeoptimizeAll) \
duke@435 43 template(ZombieAll) \
duke@435 44 template(Verify) \
duke@435 45 template(PrintJNI) \
duke@435 46 template(HeapDumper) \
duke@435 47 template(DeoptimizeTheWorld) \
duke@435 48 template(GC_HeapInspection) \
duke@435 49 template(GenCollectFull) \
duke@435 50 template(GenCollectFullConcurrent) \
duke@435 51 template(GenCollectForAllocation) \
apetrusenko@574 52 template(GenCollectForPermanentAllocation) \
duke@435 53 template(ParallelGCFailedAllocation) \
duke@435 54 template(ParallelGCFailedPermanentAllocation) \
duke@435 55 template(ParallelGCSystemGC) \
duke@435 56 template(CMS_Initial_Mark) \
duke@435 57 template(CMS_Final_Remark) \
duke@435 58 template(EnableBiasedLocking) \
duke@435 59 template(RevokeBias) \
duke@435 60 template(BulkRevokeBias) \
duke@435 61 template(PopulateDumpSharedSpace) \
duke@435 62 template(JNIFunctionTableCopier) \
duke@435 63 template(RedefineClasses) \
duke@435 64 template(GetOwnedMonitorInfo) \
duke@435 65 template(GetObjectMonitorUsage) \
duke@435 66 template(GetCurrentContendedMonitor) \
duke@435 67 template(GetStackTrace) \
duke@435 68 template(GetMultipleStackTraces) \
duke@435 69 template(GetAllStackTraces) \
duke@435 70 template(GetThreadListStackTraces) \
duke@435 71 template(GetFrameCount) \
duke@435 72 template(GetFrameLocation) \
duke@435 73 template(ChangeBreakpoints) \
duke@435 74 template(GetOrSetLocal) \
duke@435 75 template(GetCurrentLocation) \
duke@435 76 template(EnterInterpOnlyMode) \
duke@435 77 template(ChangeSingleStep) \
duke@435 78 template(HeapWalkOperation) \
duke@435 79 template(HeapIterateOperation) \
duke@435 80 template(ReportJavaOutOfMemory) \
duke@435 81 template(Exit) \
duke@435 82
duke@435 83 class VM_Operation: public CHeapObj {
duke@435 84 public:
duke@435 85 enum Mode {
duke@435 86 _safepoint, // blocking, safepoint, vm_op C-heap allocated
duke@435 87 _no_safepoint, // blocking, no safepoint, vm_op C-Heap allocated
duke@435 88 _concurrent, // non-blocking, no safepoint, vm_op C-Heap allocated
duke@435 89 _async_safepoint // non-blocking, safepoint, vm_op C-Heap allocated
duke@435 90 };
duke@435 91
duke@435 92 enum VMOp_Type {
duke@435 93 VM_OPS_DO(VM_OP_ENUM)
duke@435 94 VMOp_Terminating
duke@435 95 };
duke@435 96
duke@435 97 private:
duke@435 98 Thread* _calling_thread;
duke@435 99 ThreadPriority _priority;
duke@435 100 long _timestamp;
duke@435 101 VM_Operation* _next;
duke@435 102 VM_Operation* _prev;
duke@435 103
duke@435 104 // The VM operation name array
duke@435 105 static const char* _names[];
duke@435 106
duke@435 107 public:
duke@435 108 VM_Operation() { _calling_thread = NULL; _next = NULL; _prev = NULL; }
duke@435 109 virtual ~VM_Operation() {}
duke@435 110
duke@435 111 // VM operation support (used by VM thread)
duke@435 112 Thread* calling_thread() const { return _calling_thread; }
duke@435 113 ThreadPriority priority() { return _priority; }
duke@435 114 void set_calling_thread(Thread* thread, ThreadPriority priority);
duke@435 115
duke@435 116 long timestamp() const { return _timestamp; }
duke@435 117 void set_timestamp(long timestamp) { _timestamp = timestamp; }
duke@435 118
duke@435 119 // Called by VM thread - does in turn invoke doit(). Do not override this
duke@435 120 void evaluate();
duke@435 121
duke@435 122 // evaluate() is called by the VMThread and in turn calls doit().
duke@435 123 // If the thread invoking VMThread::execute((VM_Operation*) is a JavaThread,
duke@435 124 // doit_prologue() is called in that thread before transferring control to
duke@435 125 // the VMThread.
duke@435 126 // If doit_prologue() returns true the VM operation will proceed, and
duke@435 127 // doit_epilogue() will be called by the JavaThread once the VM operation
duke@435 128 // completes. If doit_prologue() returns false the VM operation is cancelled.
duke@435 129 virtual void doit() = 0;
duke@435 130 virtual bool doit_prologue() { return true; };
duke@435 131 virtual void doit_epilogue() {}; // Note: Not called if mode is: _concurrent
duke@435 132
duke@435 133 // Type test
duke@435 134 virtual bool is_methodCompiler() const { return false; }
duke@435 135
duke@435 136 // Linking
duke@435 137 VM_Operation *next() const { return _next; }
duke@435 138 VM_Operation *prev() const { return _prev; }
duke@435 139 void set_next(VM_Operation *next) { _next = next; }
duke@435 140 void set_prev(VM_Operation *prev) { _prev = prev; }
duke@435 141
duke@435 142 // Configuration. Override these appropriatly in subclasses.
duke@435 143 virtual VMOp_Type type() const = 0;
duke@435 144 virtual Mode evaluation_mode() const { return _safepoint; }
duke@435 145 virtual bool allow_nested_vm_operations() const { return false; }
duke@435 146 virtual bool is_cheap_allocated() const { return false; }
duke@435 147 virtual void oops_do(OopClosure* f) { /* do nothing */ };
duke@435 148
duke@435 149 // CAUTION: <don't hang yourself with following rope>
duke@435 150 // If you override these methods, make sure that the evaluation
duke@435 151 // of these methods is race-free and non-blocking, since these
duke@435 152 // methods may be evaluated either by the mutators or by the
duke@435 153 // vm thread, either concurrently with mutators or with the mutators
duke@435 154 // stopped. In other words, taking locks is verboten, and if there
duke@435 155 // are any races in evaluating the conditions, they'd better be benign.
duke@435 156 virtual bool evaluate_at_safepoint() const {
duke@435 157 return evaluation_mode() == _safepoint ||
duke@435 158 evaluation_mode() == _async_safepoint;
duke@435 159 }
duke@435 160 virtual bool evaluate_concurrently() const {
duke@435 161 return evaluation_mode() == _concurrent ||
duke@435 162 evaluation_mode() == _async_safepoint;
duke@435 163 }
duke@435 164
duke@435 165 // Debugging
duke@435 166 void print_on_error(outputStream* st) const;
duke@435 167 const char* name() const { return _names[type()]; }
duke@435 168 static const char* name(int type) {
duke@435 169 assert(type >= 0 && type < VMOp_Terminating, "invalid VM operation type");
duke@435 170 return _names[type];
duke@435 171 }
duke@435 172 #ifndef PRODUCT
duke@435 173 void print_on(outputStream* st) const { print_on_error(st); }
duke@435 174 #endif
duke@435 175 };
duke@435 176
duke@435 177 class VM_ThreadStop: public VM_Operation {
duke@435 178 private:
duke@435 179 oop _thread; // The Thread that the Throwable is thrown against
duke@435 180 oop _throwable; // The Throwable thrown at the target Thread
duke@435 181 public:
duke@435 182 // All oops are passed as JNI handles, since there is no guarantee that a GC might happen before the
duke@435 183 // VM operation is executed.
duke@435 184 VM_ThreadStop(oop thread, oop throwable) {
duke@435 185 _thread = thread;
duke@435 186 _throwable = throwable;
duke@435 187 }
duke@435 188 VMOp_Type type() const { return VMOp_ThreadStop; }
duke@435 189 oop target_thread() const { return _thread; }
duke@435 190 oop throwable() const { return _throwable;}
duke@435 191 void doit();
duke@435 192 // We deoptimize if top-most frame is compiled - this might require a C2I adapter to be generated
duke@435 193 bool allow_nested_vm_operations() const { return true; }
duke@435 194 Mode evaluation_mode() const { return _async_safepoint; }
duke@435 195 bool is_cheap_allocated() const { return true; }
duke@435 196
duke@435 197 // GC support
duke@435 198 void oops_do(OopClosure* f) {
duke@435 199 f->do_oop(&_thread); f->do_oop(&_throwable);
duke@435 200 }
duke@435 201 };
duke@435 202
duke@435 203 // dummy vm op, evaluated just to force a safepoint
duke@435 204 class VM_ForceSafepoint: public VM_Operation {
duke@435 205 public:
duke@435 206 VM_ForceSafepoint() {}
duke@435 207 void doit() {}
duke@435 208 VMOp_Type type() const { return VMOp_ForceSafepoint; }
duke@435 209 };
duke@435 210
duke@435 211 // dummy vm op, evaluated just to force a safepoint
duke@435 212 class VM_ForceAsyncSafepoint: public VM_Operation {
duke@435 213 public:
duke@435 214 VM_ForceAsyncSafepoint() {}
duke@435 215 void doit() {}
duke@435 216 VMOp_Type type() const { return VMOp_ForceAsyncSafepoint; }
duke@435 217 Mode evaluation_mode() const { return _async_safepoint; }
duke@435 218 bool is_cheap_allocated() const { return true; }
duke@435 219 };
duke@435 220
duke@435 221 class VM_Deoptimize: public VM_Operation {
duke@435 222 public:
duke@435 223 VM_Deoptimize() {}
duke@435 224 VMOp_Type type() const { return VMOp_Deoptimize; }
duke@435 225 void doit();
duke@435 226 bool allow_nested_vm_operations() const { return true; }
duke@435 227 };
duke@435 228
duke@435 229 class VM_DeoptimizeFrame: public VM_Operation {
duke@435 230 private:
duke@435 231 JavaThread* _thread;
duke@435 232 intptr_t* _id;
duke@435 233 public:
duke@435 234 VM_DeoptimizeFrame(JavaThread* thread, intptr_t* id);
duke@435 235 VMOp_Type type() const { return VMOp_DeoptimizeFrame; }
duke@435 236 void doit();
duke@435 237 bool allow_nested_vm_operations() const { return true; }
duke@435 238 };
duke@435 239
duke@435 240 #ifndef PRODUCT
duke@435 241 class VM_DeoptimizeAll: public VM_Operation {
duke@435 242 private:
duke@435 243 KlassHandle _dependee;
duke@435 244 public:
duke@435 245 VM_DeoptimizeAll() {}
duke@435 246 VMOp_Type type() const { return VMOp_DeoptimizeAll; }
duke@435 247 void doit();
duke@435 248 bool allow_nested_vm_operations() const { return true; }
duke@435 249 };
duke@435 250
duke@435 251
duke@435 252 class VM_ZombieAll: public VM_Operation {
duke@435 253 public:
duke@435 254 VM_ZombieAll() {}
duke@435 255 VMOp_Type type() const { return VMOp_ZombieAll; }
duke@435 256 void doit();
duke@435 257 bool allow_nested_vm_operations() const { return true; }
duke@435 258 };
duke@435 259 #endif // PRODUCT
duke@435 260
duke@435 261 class VM_Verify: public VM_Operation {
duke@435 262 private:
duke@435 263 KlassHandle _dependee;
duke@435 264 public:
duke@435 265 VM_Verify() {}
duke@435 266 VMOp_Type type() const { return VMOp_Verify; }
duke@435 267 void doit();
duke@435 268 };
duke@435 269
duke@435 270
duke@435 271 class VM_PrintThreads: public VM_Operation {
duke@435 272 private:
duke@435 273 outputStream* _out;
duke@435 274 bool _print_concurrent_locks;
duke@435 275 public:
duke@435 276 VM_PrintThreads() { _out = tty; _print_concurrent_locks = PrintConcurrentLocks; }
duke@435 277 VM_PrintThreads(outputStream* out, bool print_concurrent_locks) { _out = out; _print_concurrent_locks = print_concurrent_locks; }
duke@435 278 VMOp_Type type() const { return VMOp_PrintThreads; }
duke@435 279 void doit();
duke@435 280 bool doit_prologue();
duke@435 281 void doit_epilogue();
duke@435 282 };
duke@435 283
duke@435 284 class VM_PrintJNI: public VM_Operation {
duke@435 285 private:
duke@435 286 outputStream* _out;
duke@435 287 public:
duke@435 288 VM_PrintJNI() { _out = tty; }
duke@435 289 VM_PrintJNI(outputStream* out) { _out = out; }
duke@435 290 VMOp_Type type() const { return VMOp_PrintJNI; }
duke@435 291 void doit();
duke@435 292 };
duke@435 293
duke@435 294 class DeadlockCycle;
duke@435 295 class VM_FindDeadlocks: public VM_Operation {
duke@435 296 private:
duke@435 297 bool _concurrent_locks;
duke@435 298 DeadlockCycle* _deadlocks;
duke@435 299 outputStream* _out;
duke@435 300
duke@435 301 public:
duke@435 302 VM_FindDeadlocks(bool concurrent_locks) : _concurrent_locks(concurrent_locks), _out(NULL), _deadlocks(NULL) {};
duke@435 303 VM_FindDeadlocks(outputStream* st) : _concurrent_locks(true), _out(st), _deadlocks(NULL) {};
duke@435 304 ~VM_FindDeadlocks();
duke@435 305
duke@435 306 DeadlockCycle* result() { return _deadlocks; };
duke@435 307 VMOp_Type type() const { return VMOp_FindDeadlocks; }
duke@435 308 void doit();
duke@435 309 bool doit_prologue();
duke@435 310 };
duke@435 311
duke@435 312 class ThreadDumpResult;
duke@435 313 class ThreadSnapshot;
duke@435 314 class ThreadConcurrentLocks;
duke@435 315
duke@435 316 class VM_ThreadDump : public VM_Operation {
duke@435 317 private:
duke@435 318 ThreadDumpResult* _result;
duke@435 319 int _num_threads;
duke@435 320 GrowableArray<instanceHandle>* _threads;
duke@435 321 int _max_depth;
duke@435 322 bool _with_locked_monitors;
duke@435 323 bool _with_locked_synchronizers;
duke@435 324
duke@435 325 ThreadSnapshot* snapshot_thread(JavaThread* java_thread, ThreadConcurrentLocks* tcl);
duke@435 326
duke@435 327 public:
duke@435 328 VM_ThreadDump(ThreadDumpResult* result,
duke@435 329 int max_depth, // -1 indicates entire stack
duke@435 330 bool with_locked_monitors,
duke@435 331 bool with_locked_synchronizers);
duke@435 332
duke@435 333 VM_ThreadDump(ThreadDumpResult* result,
duke@435 334 GrowableArray<instanceHandle>* threads,
duke@435 335 int num_threads, // -1 indicates entire stack
duke@435 336 int max_depth,
duke@435 337 bool with_locked_monitors,
duke@435 338 bool with_locked_synchronizers);
duke@435 339
duke@435 340 VMOp_Type type() const { return VMOp_ThreadDump; }
duke@435 341 void doit();
duke@435 342 bool doit_prologue();
duke@435 343 void doit_epilogue();
duke@435 344 };
duke@435 345
duke@435 346
duke@435 347 class VM_Exit: public VM_Operation {
duke@435 348 private:
duke@435 349 int _exit_code;
duke@435 350 static volatile bool _vm_exited;
duke@435 351 static Thread * _shutdown_thread;
duke@435 352 static void wait_if_vm_exited();
duke@435 353 public:
duke@435 354 VM_Exit(int exit_code) {
duke@435 355 _exit_code = exit_code;
duke@435 356 }
duke@435 357 static int wait_for_threads_in_native_to_block();
duke@435 358 static int set_vm_exited();
duke@435 359 static bool vm_exited() { return _vm_exited; }
duke@435 360 static void block_if_vm_exited() {
duke@435 361 if (_vm_exited) {
duke@435 362 wait_if_vm_exited();
duke@435 363 }
duke@435 364 }
duke@435 365 VMOp_Type type() const { return VMOp_Exit; }
duke@435 366 void doit();
duke@435 367 };

mercurial