src/share/vm/runtime/vm_operations.hpp

Wed, 02 Jul 2008 12:55:16 -0700

author
xdono
date
Wed, 02 Jul 2008 12:55:16 -0700
changeset 631
d1605aabd0a1
parent 574
c0492d52d55b
child 791
1ee8caae33af
permissions
-rw-r--r--

6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell

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

mercurial