--- old/src/share/vm/logging/logStream.cpp 2017-07-17 12:20:59.488598600 +0200 +++ new/src/share/vm/logging/logStream.cpp 2017-07-17 12:20:58.825393600 +0200 @@ -46,14 +46,20 @@ void LogStream::LineBuffer::try_ensure_cap(size_t atleast) { assert(_cap >= sizeof(_smallbuf), "sanity"); if (_cap < atleast) { + // Cap out at a reasonable max to prevent runaway leaks. const size_t reasonable_max = 1 * M; - size_t newcap = align_size_up(atleast + 64, 64); assert(_cap <= reasonable_max, "sanity"); - // Cap out at a reasonable max to prevent runaway leaks. + if (_cap == reasonable_max) { + return; + } + + size_t newcap = align_up(atleast + 64, 64); if (newcap > reasonable_max) { + log_info(logging)("Suspiciously long log line: \"%.100s%s", + _buf, (_pos >= 100 ? "..." : "")); newcap = reasonable_max; } - + char* const newbuf = (char*) os::malloc(newcap, mtLogging); if (newbuf == NULL) { // OOM. Leave object unchanged. return; --- old/test/native/logging/test_logStream.cpp 2017-07-17 12:21:05.999165700 +0200 +++ new/test/native/logging/test_logStream.cpp 2017-07-17 12:21:05.360176600 +0200 @@ -97,4 +97,6 @@ } const char* const line_buffer = ls._current_line.ptr(); ASSERT_TRUE(strlen(line_buffer) == 1*M - 1); + // reset to prevent assert for unflushed content + ls._current_line.reset(); }