src/share/vm/runtime/vm_operations.hpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 2260
ce6848d0666d
child 2497
3582bf76420e
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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

mercurial