22 * 23 */ 24 25 26 #include "precompiled.hpp" 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp" 29 #include "gc_implementation/g1/g1Log.hpp" 30 #include "gc_implementation/g1/g1StringDedup.hpp" 31 32 // Helper class for avoiding interleaved logging 33 class LineBuffer: public StackObj { 34 35 private: 36 static const int BUFFER_LEN = 1024; 37 static const int INDENT_CHARS = 3; 38 char _buffer[BUFFER_LEN]; 39 int _indent_level; 40 int _cur; 41 42 void vappend(const char* format, va_list ap) { 43 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap); 44 if (res != -1) { 45 _cur += res; 46 } else { 47 DEBUG_ONLY(warning("buffer too small in LineBuffer");) 48 _buffer[BUFFER_LEN -1] = 0; 49 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again 50 } 51 } 52 53 public: 54 explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) { 55 for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) { 56 _buffer[_cur] = ' '; 57 } 58 } 59 60 #ifndef PRODUCT 61 ~LineBuffer() { 62 assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?"); 63 } 64 #endif 65 66 void append(const char* format, ...) { 67 va_list ap; 68 va_start(ap, format); 69 vappend(format, ap); 70 va_end(ap); 71 } | 22 * 23 */ 24 25 26 #include "precompiled.hpp" 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp" 29 #include "gc_implementation/g1/g1Log.hpp" 30 #include "gc_implementation/g1/g1StringDedup.hpp" 31 32 // Helper class for avoiding interleaved logging 33 class LineBuffer: public StackObj { 34 35 private: 36 static const int BUFFER_LEN = 1024; 37 static const int INDENT_CHARS = 3; 38 char _buffer[BUFFER_LEN]; 39 int _indent_level; 40 int _cur; 41 42 PRAGMA_DIAG_PUSH 43 PRAGMA_FORMAT_NONLITERAL_IGNORED 44 void vappend(const char* format, va_list ap) { 45 int res = vsnprintf(&_buffer[_cur], BUFFER_LEN - _cur, format, ap); 46 if (res != -1) { 47 _cur += res; 48 } else { 49 DEBUG_ONLY(warning("buffer too small in LineBuffer");) 50 _buffer[BUFFER_LEN -1] = 0; 51 _cur = BUFFER_LEN; // vsnprintf above should not add to _buffer if we are called again 52 } 53 } 54 PRAGMA_DIAG_POP 55 56 public: 57 explicit LineBuffer(int indent_level): _indent_level(indent_level), _cur(0) { 58 for (; (_cur < BUFFER_LEN && _cur < (_indent_level * INDENT_CHARS)); _cur++) { 59 _buffer[_cur] = ' '; 60 } 61 } 62 63 #ifndef PRODUCT 64 ~LineBuffer() { 65 assert(_cur == _indent_level * INDENT_CHARS, "pending data in buffer - append_and_print_cr() not called?"); 66 } 67 #endif 68 69 void append(const char* format, ...) { 70 va_list ap; 71 va_start(ap, format); 72 vappend(format, ap); 73 va_end(ap); 74 } |