src/hotspot/share/prims/jvmtiRawMonitor.hpp
changeset 58488 165b193b30dd
parent 53244 9807daeb47c4
child 58509 7b41c88f8432
equal deleted inserted replaced
58487:43f63f904bbc 58488:165b193b30dd
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_PRIMS_JVMTIRAWMONITOR_HPP
    25 #ifndef SHARE_PRIMS_JVMTIRAWMONITOR_HPP
    26 #define SHARE_PRIMS_JVMTIRAWMONITOR_HPP
    26 #define SHARE_PRIMS_JVMTIRAWMONITOR_HPP
    27 
    27 
    28 #include "runtime/objectMonitor.hpp"
    28 #include "memory/allocation.hpp"
       
    29 #include "runtime/park.hpp"
    29 #include "utilities/growableArray.hpp"
    30 #include "utilities/growableArray.hpp"
    30 
    31 
    31 //
    32 //
    32 // class JvmtiRawMonitor
    33 // class JvmtiRawMonitor
    33 //
    34 //
    34 // Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
    35 // Used by JVMTI methods: All RawMonitor methods (CreateRawMonitor, EnterRawMonitor, etc.)
    35 //
    36 //
    36 // Wrapper for ObjectMonitor class that saves the Monitor's name
    37 // A simplified version of the ObjectMonitor code.
    37 //
    38 //
    38 
    39 
    39 class JvmtiRawMonitor : public ObjectMonitor  {
    40 class JvmtiRawMonitor : public CHeapObj<mtSynchronizer>  {
    40 private:
    41 
       
    42   // Helper class to allow Threads to be linked into queues.
       
    43   // This is a stripped down version of ObjectWaiter.
       
    44   class QNode : public StackObj {
       
    45     friend class JvmtiRawMonitor;
       
    46     enum TStates { TS_READY, TS_RUN, TS_WAIT, TS_ENTER };
       
    47     QNode* volatile _next;
       
    48     QNode* volatile _prev;
       
    49     ParkEvent *   _event;
       
    50     volatile int  _notified;
       
    51     volatile TStates TState;
       
    52 
       
    53     QNode(Thread* thread);
       
    54   };
       
    55 
       
    56   Thread* volatile _owner;          // pointer to owning thread
       
    57   volatile int _recursions;         // recursion count, 0 for first entry
       
    58   QNode* volatile _EntryList;       // Threads blocked on entry or reentry.
       
    59                                     // The list is actually composed of nodes,
       
    60                                     // acting as proxies for Threads.
       
    61   QNode* volatile _WaitSet;         // Threads wait()ing on the monitor
       
    62   volatile jint  _waiters;          // number of waiting threads
    41   int           _magic;
    63   int           _magic;
    42   char *        _name;
    64   char *        _name;
    43   // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
    65   // JVMTI_RM_MAGIC is set in contructor and unset in destructor.
    44   enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
    66   enum { JVMTI_RM_MAGIC = (int)(('T' << 24) | ('I' << 16) | ('R' << 8) | 'M') };
    45 
    67 
    46   int       SimpleEnter (Thread * Self) ;
    68   void      SimpleEnter (Thread * Self) ;
    47   int       SimpleExit  (Thread * Self) ;
    69   void      SimpleExit  (Thread * Self) ;
    48   int       SimpleWait  (Thread * Self, jlong millis) ;
    70   int       SimpleWait  (Thread * Self, jlong millis) ;
    49   int       SimpleNotify (Thread * Self, bool All) ;
    71   void      SimpleNotify(Thread * Self, bool All) ;
    50 
    72 
    51 public:
    73 public:
       
    74 
       
    75   // return codes
       
    76   enum {
       
    77     M_OK,                    // no error
       
    78     M_ILLEGAL_MONITOR_STATE, // IllegalMonitorStateException
       
    79     M_INTERRUPTED            // Thread.interrupt()
       
    80   };
       
    81 
       
    82   // Non-aborting operator new
       
    83   void* operator new(size_t size) throw() {
       
    84     return CHeapObj::operator new(size, std::nothrow);
       
    85   }
       
    86 
    52   JvmtiRawMonitor(const char *name);
    87   JvmtiRawMonitor(const char *name);
    53   ~JvmtiRawMonitor();
    88   ~JvmtiRawMonitor();
    54   int       raw_enter(TRAPS);
    89 
    55   int       raw_exit(TRAPS);
    90   Thread *  owner() const { return _owner; }
    56   int       raw_wait(jlong millis, bool interruptable, TRAPS);
    91   void      set_owner(Thread * owner) { _owner = owner; }
    57   int       raw_notify(TRAPS);
    92   int       recursions() const { return _recursions; }
    58   int       raw_notifyAll(TRAPS);
    93   void      raw_enter(Thread * Self);
    59   int            magic()   { return _magic;  }
    94   int       raw_exit(Thread * Self);
    60   const char *get_name()   { return _name; }
    95   int       raw_wait(jlong millis, bool interruptable, Thread * Self);
       
    96   int       raw_notify(Thread * Self);
       
    97   int       raw_notifyAll(Thread * Self);
       
    98   int       magic() const { return _magic;  }
       
    99   const char *get_name() const { return _name; }
    61   bool        is_valid();
   100   bool        is_valid();
    62 };
   101 };
    63 
   102 
    64 // Onload pending raw monitors
   103 // Onload pending raw monitors
    65 // Class is used to cache onload or onstart monitor enter
   104 // Class is used to cache onload or onstart monitor enter