< prev index next >

src/hotspot/share/utilities/events.hpp

Print this page




 118   // Print the contents of the log
 119   void print_log_on(outputStream* out);
 120 
 121  private:
 122   void print_log_impl(outputStream* out);
 123 
 124   // Print a single element.  A templated implementation might need to
 125   // be declared by subclasses.
 126   void print(outputStream* out, T& e);
 127 
 128   void print(outputStream* out, EventRecord<T>& e) {
 129     out->print("Event: %.3f ", e.timestamp);
 130     if (e.thread != NULL) {
 131       out->print("Thread " INTPTR_FORMAT " ", p2i(e.thread));
 132     }
 133     print(out, e.data);
 134   }
 135 };
 136 
 137 // A simple wrapper class for fixed size text messages.
 138 class StringLogMessage : public FormatBuffer<256> {

 139  public:
 140   // Wrap this buffer in a stringStream.
 141   stringStream stream() {
 142     return stringStream(_buf, size());
 143   }
 144 };


 145 
 146 // A simple ring buffer of fixed size text messages.
 147 class StringEventLog : public EventLogBase<StringLogMessage> {

 148  public:
 149   StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 150 
 151   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 152     if (!should_log()) return;
 153 
 154     double timestamp = fetch_timestamp();
 155     MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
 156     int index = compute_log_index();
 157     _records[index].thread = thread;
 158     _records[index].timestamp = timestamp;
 159     _records[index].data.printv(format, ap);
 160   }
 161 
 162   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 163     va_list ap;
 164     va_start(ap, format);
 165     logv(thread, format, ap);
 166     va_end(ap);
 167   }
 168 };


 169 
 170 class InstanceKlass;
 171 
 172 // Event log for class unloading events to materialize the class name in place in the log stream.
 173 class UnloadingEventLog : public EventLogBase<StringLogMessage> {
 174  public:
 175   UnloadingEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 176 
 177   void log(Thread* thread, InstanceKlass* ik);
 178 };
 179 
 180 
 181 class Events : AllStatic {
 182   friend class EventLog;
 183 
 184  private:
 185   static EventLog* _logs;
 186 
 187   // A log for generic messages that aren't well categorized.
 188   static StringEventLog* _messages;
 189 
 190   // A log for internal exception related messages, like internal
 191   // throws and implicit exceptions.
 192   static StringEventLog* _exceptions;
 193 
 194   // Deoptization related messages
 195   static StringEventLog* _deopt_messages;
 196 
 197   // Redefinition related messages
 198   static StringEventLog* _redefinitions;
 199 
 200   // Class unloading events
 201   static UnloadingEventLog* _class_unloading;
 202  public:
 203   static void print_all(outputStream* out);
 204 
 205   // Dump all events to the tty
 206   static void print();
 207 
 208   // Logs a generic message with timestamp and format as printf.
 209   static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 210 
 211   // Log exception related message
 212   static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);


 286   }
 287 
 288   if (_count < _length) {
 289     for (int i = 0; i < _count; i++) {
 290       print(out, _records[i]);
 291     }
 292   } else {
 293     for (int i = _index; i < _length; i++) {
 294       print(out, _records[i]);
 295     }
 296     for (int i = 0; i < _index; i++) {
 297       print(out, _records[i]);
 298     }
 299   }
 300   out->cr();
 301 }
 302 
 303 // Implement a printing routine for the StringLogMessage
 304 template <>
 305 inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {







 306   out->print_raw(lm);
 307   out->cr();
 308 }
 309 
 310 // Place markers for the beginning and end up of a set of events.
 311 // These end up in the default log.
 312 class EventMark : public StackObj {
 313   StringLogMessage _buffer;
 314 
 315  public:
 316   // log a begin event, format as printf
 317   EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 318   // log an end event
 319   ~EventMark();
 320 };
 321 
 322 #endif // SHARE_UTILITIES_EVENTS_HPP


 118   // Print the contents of the log
 119   void print_log_on(outputStream* out);
 120 
 121  private:
 122   void print_log_impl(outputStream* out);
 123 
 124   // Print a single element.  A templated implementation might need to
 125   // be declared by subclasses.
 126   void print(outputStream* out, T& e);
 127 
 128   void print(outputStream* out, EventRecord<T>& e) {
 129     out->print("Event: %.3f ", e.timestamp);
 130     if (e.thread != NULL) {
 131       out->print("Thread " INTPTR_FORMAT " ", p2i(e.thread));
 132     }
 133     print(out, e.data);
 134   }
 135 };
 136 
 137 // A simple wrapper class for fixed size text messages.
 138 template <size_t bufsz>
 139 class TemplatedStringLogMessage : public FormatBuffer<bufsz> {
 140  public:
 141   // Wrap this buffer in a stringStream.
 142   stringStream stream() {
 143     return stringStream(this->_buf, this->size());
 144   }
 145 };
 146 typedef TemplatedStringLogMessage<256> StringLogMessage;
 147 typedef TemplatedStringLogMessage<512> ExtendedStringLogMessage;
 148 
 149 // A simple ring buffer of fixed size text messages.
 150 template <size_t bufsz>
 151 class TemplatedStringEventLog : public EventLogBase< TemplatedStringLogMessage<bufsz> > {
 152  public:
 153   TemplatedStringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase< TemplatedStringLogMessage<bufsz> >(name, count) {}
 154 
 155   void logv(Thread* thread, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) {
 156     if (!this->should_log()) return;
 157 
 158     double timestamp = this->fetch_timestamp();
 159     MutexLockerEx ml(&this->_mutex, Mutex::_no_safepoint_check_flag);
 160     int index = this->compute_log_index();
 161     this->_records[index].thread = thread;
 162     this->_records[index].timestamp = timestamp;
 163     this->_records[index].data.printv(format, ap);
 164   }
 165 
 166   void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(3, 4) {
 167     va_list ap;
 168     va_start(ap, format);
 169     this->logv(thread, format, ap);
 170     va_end(ap);
 171   }
 172 };
 173 typedef TemplatedStringEventLog<256> StringEventLog;
 174 typedef TemplatedStringEventLog<512> ExtendedStringEventLog;
 175 
 176 class InstanceKlass;
 177 
 178 // Event log for class unloading events to materialize the class name in place in the log stream.
 179 class UnloadingEventLog : public EventLogBase<StringLogMessage> {
 180  public:
 181   UnloadingEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
 182 
 183   void log(Thread* thread, InstanceKlass* ik);
 184 };
 185 
 186 
 187 class Events : AllStatic {
 188   friend class EventLog;
 189 
 190  private:
 191   static EventLog* _logs;
 192 
 193   // A log for generic messages that aren't well categorized.
 194   static StringEventLog* _messages;
 195 
 196   // A log for internal exception related messages, like internal
 197   // throws and implicit exceptions.
 198   static ExtendedStringEventLog* _exceptions;
 199 
 200   // Deoptization related messages
 201   static StringEventLog* _deopt_messages;
 202 
 203   // Redefinition related messages
 204   static StringEventLog* _redefinitions;
 205 
 206   // Class unloading events
 207   static UnloadingEventLog* _class_unloading;
 208  public:
 209   static void print_all(outputStream* out);
 210 
 211   // Dump all events to the tty
 212   static void print();
 213 
 214   // Logs a generic message with timestamp and format as printf.
 215   static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 216 
 217   // Log exception related message
 218   static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);


 292   }
 293 
 294   if (_count < _length) {
 295     for (int i = 0; i < _count; i++) {
 296       print(out, _records[i]);
 297     }
 298   } else {
 299     for (int i = _index; i < _length; i++) {
 300       print(out, _records[i]);
 301     }
 302     for (int i = 0; i < _index; i++) {
 303       print(out, _records[i]);
 304     }
 305   }
 306   out->cr();
 307 }
 308 
 309 // Implement a printing routine for the StringLogMessage
 310 template <>
 311 inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
 312   out->print_raw(lm);
 313   out->cr();
 314 }
 315 
 316 // Implement a printing routine for the ExtendedStringLogMessage
 317 template <>
 318 inline void EventLogBase<ExtendedStringLogMessage>::print(outputStream* out, ExtendedStringLogMessage& lm) {
 319   out->print_raw(lm);
 320   out->cr();
 321 }
 322 
 323 // Place markers for the beginning and end up of a set of events.
 324 // These end up in the default log.
 325 class EventMark : public StackObj {
 326   StringLogMessage _buffer;
 327 
 328  public:
 329   // log a begin event, format as printf
 330   EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
 331   // log an end event
 332   ~EventMark();
 333 };
 334 
 335 #endif // SHARE_UTILITIES_EVENTS_HPP
< prev index next >