src/share/vm/trace/traceEvent.hpp

Print this page
rev 7560 : 8066814: Reduce accessibility in TraceEvent
Reviewed-by:


  45   bool _started;
  46 #ifdef ASSERT
  47   bool _committed;
  48   bool _cancelled;
  49  protected:
  50   bool _ignore_check;
  51 #endif
  52 
  53  protected:
  54   jlong _startTime;
  55   jlong _endTime;
  56 
  57   void set_starttime(const TracingTime& time) {
  58     _startTime = time;
  59   }
  60 
  61   void set_endtime(const TracingTime& time) {
  62     _endTime = time;
  63   }
  64 
  65  public:
  66   TraceEvent(EventStartTime timing=TIMED) :
  67     _startTime(0),
  68     _endTime(0),
  69     _started(false)
  70 #ifdef ASSERT
  71     ,
  72     _committed(false),
  73     _cancelled(false),
  74     _ignore_check(false)
  75 #endif
  76   {
  77     if (T::is_enabled()) {
  78       _started = true;
  79       if (timing == TIMED && !T::isInstant) {
  80         static_cast<T *>(this)->set_starttime(Tracing::time());
  81       }
  82     }
  83   }
  84 

  85   static bool is_enabled() {
  86     return Tracing::is_event_enabled(T::eventId);
  87   }
  88 
  89   bool should_commit() {
  90     return _started;
  91   }
  92 
  93   void ignoreCheck() {
  94     DEBUG_ONLY(_ignore_check = true);




  95   }
  96 
  97   void commit() {
  98     if (!should_commit()) {
  99         cancel();
 100         return;
 101     }

 102     if (_endTime == 0) {
 103       static_cast<T*>(this)->set_endtime(Tracing::time());
 104     }
 105     if (static_cast<T*>(this)->should_write()) {
 106       static_cast<T*>(this)->writeEvent();
 107     }
 108     set_commited();
 109   }
 110 
 111   void set_starttime(const Ticks& time) {
 112     _startTime = time.value();
 113   }
 114 
 115   void set_endtime(const Ticks& time) {
 116     _endTime = time.value();
 117   }
 118 
 119   TraceEventId id() const {
 120     return T::eventId;

 121   }
 122 
 123   bool is_instant() const {
 124     return T::isInstant;
 125   }
 126 
 127   bool is_requestable() const {
 128     return T::isRequestable;
 129   }
 130 
 131   bool has_thread() const {
 132     return T::hasThread;
 133   }
 134 
 135   bool has_stacktrace() const {
 136     return T::hasStackTrace;
 137   }
 138 
 139   void cancel() {
 140     assert(!_committed && !_cancelled, "event was already committed/cancelled");
 141     DEBUG_ONLY(_cancelled = true);

 142   }
 143 








 144   void set_commited() {
 145     assert(!_committed, "event has already been committed");
 146     DEBUG_ONLY(_committed = true);
 147   }
 148 
 149   ~TraceEvent() {
 150     if (_started) {
 151       assert(_ignore_check || _committed || _cancelled, "event was not committed/cancelled");
 152     }
 153   }
 154 };
 155 
 156 #endif // INCLUDE_TRACE
 157 #endif // SHARE_VM_TRACE_TRACEEVENT_HPP


  45   bool _started;
  46 #ifdef ASSERT
  47   bool _committed;
  48   bool _cancelled;
  49  protected:
  50   bool _ignore_check;
  51 #endif
  52 
  53  protected:
  54   jlong _startTime;
  55   jlong _endTime;
  56 
  57   void set_starttime(const TracingTime& time) {
  58     _startTime = time;
  59   }
  60 
  61   void set_endtime(const TracingTime& time) {
  62     _endTime = time;
  63   }
  64 

  65   TraceEvent(EventStartTime timing=TIMED) :
  66     _startTime(0),
  67     _endTime(0),
  68     _started(false)
  69 #ifdef ASSERT
  70     ,
  71     _committed(false),
  72     _cancelled(false),
  73     _ignore_check(false)
  74 #endif
  75   {
  76     if (T::is_enabled()) {
  77       _started = true;
  78       if (timing == TIMED && !T::isInstant) {
  79         static_cast<T*>(this)->set_starttime(Tracing::time());
  80       }
  81     }
  82   }
  83 
  84  public:
  85   static bool is_enabled() {
  86     return Tracing::is_event_enabled(T::eventId);
  87   }
  88 
  89   void set_starttime(const Ticks& time) {
  90     _startTime = time.value();
  91   }
  92 
  93   void set_endtime(const Ticks& time) {
  94     _endTime = time.value();
  95   }
  96 
  97   bool should_commit() {
  98     return _started;
  99   }
 100 
 101   void commit() {
 102     if (!should_commit()) {
 103       DEBUG_ONLY(cancel());
 104       return;
 105     }
 106     assert(!_cancelled, "Committing an event that has already been cancelled");
 107     if (_endTime == 0) {
 108       static_cast<T*>(this)->set_endtime(Tracing::time());
 109     }
 110     if (static_cast<T*>(this)->should_write()) {
 111       static_cast<T*>(this)->writeEvent();
 112     }
 113     DEBUG_ONLY(set_commited());








 114   }
 115 
 116   void cancel() {
 117     assert(!_committed && !_cancelled, "event was already committed/cancelled");
 118     DEBUG_ONLY(_cancelled = true);
 119   }
 120 
 121   static bool is_instant() {
 122     return T::isInstant;
 123   }
 124 
 125   static bool is_requestable() {
 126     return T::isRequestable;
 127   }
 128 
 129   static bool has_thread() {
 130     return T::hasThread;
 131   }
 132 
 133   static bool has_stacktrace() {
 134     return T::hasStackTrace;
 135   }
 136 
 137   ~TraceEvent() {
 138     if (_started) {
 139       assert(_ignore_check || _committed || _cancelled, "event was not committed/cancelled");
 140     }
 141   }
 142 
 143 #ifdef ASSERT
 144 
 145  protected:
 146   void ignoreCheck() {
 147     _ignore_check = true;
 148   }
 149 
 150  private:
 151   void set_commited() {
 152     assert(!_committed, "event has already been committed");
 153     _committed = true;
 154   }
 155 
 156 #endif // ASSERT




 157 };
 158 
 159 #endif // INCLUDE_TRACE
 160 #endif // SHARE_VM_TRACE_TRACEEVENT_HPP