1.1 --- a/src/share/vm/gc_interface/gcCause.hpp Tue May 15 22:26:37 2012 +0200 1.2 +++ b/src/share/vm/gc_interface/gcCause.hpp Tue May 15 10:25:06 2012 +0200 1.3 @@ -88,4 +88,36 @@ 1.4 static const char* to_string(GCCause::Cause cause); 1.5 }; 1.6 1.7 +// Helper class for doing logging that includes the GC Cause 1.8 +// as a string. 1.9 +class GCCauseString : StackObj { 1.10 + private: 1.11 + static const int _length = 128; 1.12 + char _buffer[_length]; 1.13 + int _position; 1.14 + 1.15 + public: 1.16 + GCCauseString(const char* prefix, GCCause::Cause cause) { 1.17 + if (PrintGCCause) { 1.18 + _position = jio_snprintf(_buffer, _length, "%s (%s)", prefix, GCCause::to_string(cause)); 1.19 + } else { 1.20 + _position = jio_snprintf(_buffer, _length, "%s", prefix); 1.21 + } 1.22 + assert(_position >= 0 && _position <= _length, 1.23 + err_msg("Need to increase the buffer size in GCCauseString? %d", _position)); 1.24 + } 1.25 + 1.26 + GCCauseString& append(const char* str) { 1.27 + int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str); 1.28 + _position += res; 1.29 + assert(res >= 0 && _position <= _length, 1.30 + err_msg("Need to increase the buffer size in GCCauseString? %d", res)); 1.31 + return *this; 1.32 + } 1.33 + 1.34 + operator const char*() { 1.35 + return _buffer; 1.36 + } 1.37 +}; 1.38 + 1.39 #endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP