Skip to content

Commit 7ffad35

Browse files
committed
8352568: Test gtest/AsyncLogGtest.java failed at droppingMessage_vm
Reviewed-by: mbaesken, dholmes
1 parent c6243fc commit 7ffad35

File tree

4 files changed

+34
-46
lines changed

4 files changed

+34
-46
lines changed

src/hotspot/share/logging/logAsyncWriter.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,3 @@ void AsyncLogWriter::flush() {
354354
_instance->_flush_sem.wait();
355355
}
356356
}
357-
358-
AsyncLogWriter::BufferUpdater::BufferUpdater(size_t newsize) {
359-
ConsumerLocker clocker;
360-
auto p = AsyncLogWriter::_instance;
361-
362-
_buf1 = p->_buffer;
363-
_buf2 = p->_buffer_staging;
364-
p->_buffer = new Buffer(newsize);
365-
p->_buffer_staging = new Buffer(newsize);
366-
}
367-
368-
AsyncLogWriter::BufferUpdater::~BufferUpdater() {
369-
AsyncLogWriter::flush();
370-
auto p = AsyncLogWriter::_instance;
371-
372-
{
373-
ConsumerLocker clocker;
374-
375-
delete p->_buffer;
376-
delete p->_buffer_staging;
377-
p->_buffer = _buf1;
378-
p->_buffer_staging = _buf2;
379-
}
380-
}

src/hotspot/share/logging/logAsyncWriter.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,6 @@ class AsyncLogWriter : public NonJavaThread {
199199
st->cr();
200200
}
201201

202-
// for testing-only
203-
class BufferUpdater {
204-
Buffer* _buf1;
205-
Buffer* _buf2;
206-
207-
public:
208-
BufferUpdater(size_t newsize);
209-
~BufferUpdater();
210-
};
211-
212202
static bool is_enqueue_allowed();
213203

214204
public:

test/hotspot/gtest/logging/test_asynclog.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,22 @@ LOG_LEVEL_LIST
6969
log_debug(logging)("log_debug-test");
7070
}
7171

72-
// Caveat: BufferUpdater is not MT-safe. We use it only for testing.
73-
// We would observe missing loglines if we interleaved buffers.
74-
// Emit all logs between constructor and destructor of BufferUpdater.
7572
void test_asynclog_drop_messages() {
76-
const size_t sz = 2000;
73+
const size_t sz = AsyncLogBufferSize / 2;
74+
const char* str = "a lot of log...";
75+
const size_t str_size = strlen(str);
7776

78-
// shrink async buffer.
79-
AsyncLogWriter::BufferUpdater saver(1024);
8077
test_asynclog_ls(); // roughly 200 bytes.
8178
LogMessage(logging) lm;
8279

8380
// write more messages than its capacity in burst
84-
for (size_t i = 0; i < sz; ++i) {
85-
lm.debug("a lot of log...");
81+
for (size_t i = 0; i < (sz / str_size); ++i) {
82+
lm.debug("%s", str);
8683
}
84+
lm.debug("%s", str);
85+
lm.debug("%s", str);
86+
lm.debug("%s", str);
87+
lm.debug("%s", str);
8788
lm.flush();
8889
}
8990

@@ -244,13 +245,34 @@ TEST_VM_F(AsyncLogTest, logBuffer) {
244245
}
245246

246247
TEST_VM_F(AsyncLogTest, droppingMessage) {
247-
if (AsyncLogWriter::instance() == nullptr) {
248+
if (AsyncLogWriter::instance() == nullptr) return;
249+
if (LogConfiguration::async_mode() != LogConfiguration::AsyncMode::Drop) {
250+
FAIL() << "This test must be run in drop mode if async UL is activated";
248251
return;
249252
}
250253

251254
set_log_config(TestLogFileName, "logging=debug");
252255
test_asynclog_drop_messages();
253-
EXPECT_TRUE(file_contains_substring(TestLogFileName, "messages dropped due to async logging"));
256+
bool messages_dropped = file_contains_substring(TestLogFileName, "messages dropped due to async logging");
257+
if (!messages_dropped) {
258+
stringStream content;
259+
FILE* fp = os::fopen(TestLogFileName, "r");
260+
assert(fp != nullptr, "error opening file %s: %s", TestLogFileName, os::strerror(errno));
261+
{
262+
ResourceMark rm;
263+
char* line = read_line(fp);
264+
while (line != nullptr) {
265+
ResourceMark rm;
266+
content.print_raw(line);
267+
line = read_line(fp);
268+
}
269+
}
270+
271+
// The thread is null and deattached.
272+
// That means that UL degrades to synchronous logging for this thread, which means that no messages can be dropped.
273+
EXPECT_NE(nullptr, Thread::current_or_null()) << "Thread was null";
274+
EXPECT_TRUE(messages_dropped) << "Log file content:\n" << content.freeze();
275+
}
254276
}
255277

256278
TEST_VM_F(AsyncLogTest, stdoutOutput) {

test/hotspot/jtreg/gtest/AsyncLogGtest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
* @modules java.base/jdk.internal.misc
3636
* java.xml
3737
* @requires vm.flagless
38-
* @run main/native GTestWrapper --gtest_filter=AsyncLogTest* -Xlog:async
39-
* @run main/native GTestWrapper --gtest_filter=Log*Test* -Xlog:async
38+
* @run main/native GTestWrapper --gtest_filter=AsyncLogTest* -Xlog:async -XX:AsyncLogBufferSize=100K
39+
* @run main/native GTestWrapper --gtest_filter=Log*Test* -Xlog:async -XX:AsyncLogBufferSize=100K
4040
*/

0 commit comments

Comments
 (0)