diff --git a/src/hotspot/share/logging/logAsyncWriter.hpp b/src/hotspot/share/logging/logAsyncWriter.hpp index 97bae2a5817..5f439b1957e 100644 --- a/src/hotspot/share/logging/logAsyncWriter.hpp +++ b/src/hotspot/share/logging/logAsyncWriter.hpp @@ -59,6 +59,7 @@ class LogFileStreamOutput; class AsyncLogWriter : public NonJavaThread { friend class AsyncLogTest; friend class AsyncLogTest_logBuffer_vm_Test; + friend class AsyncLogTest_bufferUpdater_vm_Test; class AsyncLogLocker; // account for dropped messages diff --git a/test/hotspot/gtest/logging/test_asynclog.cpp b/test/hotspot/gtest/logging/test_asynclog.cpp index 89a1d6fef8a..88ff727c257 100644 --- a/test/hotspot/gtest/logging/test_asynclog.cpp +++ b/test/hotspot/gtest/logging/test_asynclog.cpp @@ -308,3 +308,41 @@ TEST_VM_F(AsyncLogTest, stderrOutput) { EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging")); } } + +TEST_VM_F(AsyncLogTest, bufferUpdater) { + auto writer = AsyncLogWriter::instance(); + if (writer == nullptr) return; + + set_log_config(TestLogFileName, "logging=debug"); + constexpr int N = 10000; + const char* lines[N * 3 + 1]; + lines[3 * N] = nullptr; + + char buf[1024]; + for (int i=0; i< N; ++i) { + snprintf(buf, sizeof(buf), "%d Log first", i); + lines[i * 3 + 0] = os::strdup(buf, mtTest); + snprintf(buf, sizeof(buf), "%d Log second", i); + lines[i * 3 + 1] = os::strdup(buf, mtTest); + snprintf(buf, sizeof(buf), "%d Log third", i); + lines[i * 3 + 2] = os::strdup(buf, mtTest); + + log_debug(logging)("%s", lines[i*3]); + log_debug(logging)("%s", lines[i*3+1]); + { + AsyncLogWriter::BufferUpdater saver(1024); + } + + log_debug(logging)("%s", lines[i*3+2]); + { + AsyncLogWriter::BufferUpdater saver(1024); + } + } + + AsyncLogWriter::flush(); + EXPECT_TRUE(file_contains_substrings_in_order(TestLogFileName, lines)); + + for (int j=0; j(lines[j])); + } +}