--- old/src/share/vm/gc_interface/gcCause.hpp 2012-05-08 16:12:34.852398600 +0200 +++ new/src/share/vm/gc_interface/gcCause.hpp 2012-05-08 16:12:32.906287300 +0200 @@ -88,4 +88,35 @@ 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) { + position += jio_snprintf(buffer + position, length - position, "%", str); + assert(position > 0 && position <= length, + err_msg("Need to increase the buffer size in GCCauseString? %d", position)); + return *this; + } + + operator const char*() { + return buffer; + } +}; + #endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP