Mercurial > hg > truffle
diff src/share/vm/gc_interface/gcCause.hpp @ 6064:9d679effd28c
7166894: Add gc cause to GC logging for all collectors
Reviewed-by: mgerdin, johnc
author | brutisso |
---|---|
date | Tue, 15 May 2012 10:25:06 +0200 |
parents | 9509c20bba28 |
children | da91efe96a93 |
line wrap: on
line diff
--- a/src/share/vm/gc_interface/gcCause.hpp Tue May 15 22:26:37 2012 +0200 +++ b/src/share/vm/gc_interface/gcCause.hpp Tue May 15 10:25:06 2012 +0200 @@ -88,4 +88,36 @@ static const char* to_string(GCCause::Cause cause); }; +// Helper class for doing logging that includes the GC Cause +// as a string. +class GCCauseString : StackObj { + private: + static const int _length = 128; + char _buffer[_length]; + int _position; + + public: + GCCauseString(const char* prefix, GCCause::Cause cause) { + if (PrintGCCause) { + _position = jio_snprintf(_buffer, _length, "%s (%s)", prefix, GCCause::to_string(cause)); + } else { + _position = jio_snprintf(_buffer, _length, "%s", prefix); + } + assert(_position >= 0 && _position <= _length, + err_msg("Need to increase the buffer size in GCCauseString? %d", _position)); + } + + GCCauseString& append(const char* str) { + int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str); + _position += res; + assert(res >= 0 && _position <= _length, + err_msg("Need to increase the buffer size in GCCauseString? %d", res)); + return *this; + } + + operator const char*() { + return _buffer; + } +}; + #endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP