< prev index next >
src/share/vm/utilities/events.hpp
Print this page
@@ -166,11 +166,58 @@
va_end(ap);
}
};
+class GCLogMessage {
+ friend class EventLogBase<GCLogMessage>;
+ const static size_t GCLOG_MAX_BUFSIZE = 128;
+ char buf[GCLOG_MAX_BUFSIZE];
+ size_t size;
+ public:
+ void write(const char* s, size_t len) {
+ size = MIN2(len, GCLOG_MAX_BUFSIZE - 1);
+ memcpy(buf, s, size);
+ }
+};
+
+class GCLogEvent: public EventLogBase<GCLogMessage> {
+ private:
+ static uint _buffer_overflow_count;
+
+ public:
+ GCLogEvent(const char* name, int count = LogEventsBufferEntries)
+ : EventLogBase<GCLogMessage> (name, count) {}
+
+ void log(Thread* thread, const char* s, size_t len) {
+ if (!should_log()) return;
+ if (full()) {
+ _buffer_overflow_count++;
+ }
+
+ double timestamp = fetch_timestamp();
+ int index = compute_log_index();
+ _records[index].thread = thread;
+ _records[index].timestamp = timestamp;
+ _records[index].data.write(s, len);
+ }
+
+ bool full() const {
+ return _count >= _length;
+ }
+
+ bool empty() const {
+ return 0 == _count;
+ }
+
+ void reset() {
+ _index = _count = 0;
+ }
+
+ static uint buffer_overflow_count() { return _buffer_overflow_count; }
+};
class Events : AllStatic {
friend class EventLog;
private:
@@ -287,10 +334,37 @@
inline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
out->print_raw(lm);
out->cr();
}
+template<>
+inline void EventLogBase<GCLogMessage>::print(outputStream* out, GCLogMessage& lm) {
+ gcLogFileStream* gclog = static_cast<gcLogFileStream* >(out);
+ gclog->write_blocking(lm.buf, lm.size);
+}
+
+template <>
+inline void EventLogBase<GCLogMessage>::print_log_impl(outputStream* out) {
+ if (_count == 0) {
+ return;
+ }
+
+ if (_count < _length) {
+ for (int i = 0; i < _count; i++) {
+ print(out, _records[i].data);
+ }
+ } else {
+ for (int i = _index; i < _length; i++) {
+ print(out, _records[i].data);
+ }
+ for (int i = 0; i < _index; i++) {
+ print(out, _records[i].data);
+ }
+ }
+}
+
+
// Place markers for the beginning and end up of a set of events.
// These end up in the default log.
class EventMark : public StackObj {
StringLogMessage _buffer;
< prev index next >