Skip to content

Commit 199f253

Browse files
author
Xin Liu
committed
Revert back to the basic bugfix and remove AsyncLogGtest.java from ProblemList.
1 parent 07a7905 commit 199f253

File tree

9 files changed

+17
-162
lines changed

9 files changed

+17
-162
lines changed

src/hotspot/share/logging/logAsyncWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class AsyncLogMapIterator {
102102
using none = LogTagSetMapping<LogTag::__NO_TAG>;
103103

104104
if (*counter > 0) {
105-
LogDecorations decorations(LogLevel::Warning, none::tagset(), LogDecorators::All);
105+
LogDecorations decorations(LogLevel::Warning, none::tagset(), output->decorators());
106106
stringStream ss;
107107
ss.print(UINT32_FORMAT_W(6) " messages dropped due to async logging", *counter);
108108
AsyncLogMessage msg(*output, decorations, ss.as_string(true /*c_heap*/));

src/hotspot/share/logging/logConfiguration.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,41 +253,19 @@ void LogConfiguration::configure_output(size_t idx, const LogSelectionList& sele
253253
on_level[level]++;
254254
}
255255

256-
// MT-Safety
257-
// ConfigurationLock can only guarantee that only one thread is executing reconfiguration. This function still must
258-
// be MT-safe because logsites in other threads may be executing in parallel.
259-
//
260-
// Reconfiguration: Unified logging allows users to dynamically change tags and decorators of a log output.
261-
//
262-
// A synchronization 'wait_until_no_readers()' is imposed inside of 'ts->set_output_level(output, level)' above
263-
// if setting has changed. It guarantees that all logs either synchronous writing or enqueuing to the async buffer
264-
// see the new tags and decorators. It's worth noting that the synchronization happens even level doesn't change.
265-
//
266-
// LogDecorator is a set of decorators represented in a uint. sizeof(uint) is not greater than a machine word,
267-
// so store of it is atomic on the mainstream processors. I.e. readers see either its older value or new value.
268-
// ts->update_decorators(decorators) above is a union operation of the existing decorators at different levels.
269-
// It's safe to do output->set_decorators(decorators) because decorators is a subset of relevant Tagsets' decorators.
270-
// After updating output's decorators, it's still safe to shrink all decorators of tagsets.
271-
//
272-
// There are 2 hazards in async logging. A flush operation guarantees to all pending messages in buffer are written
273-
// before returning. Therefore, the hardards won't appear. It's a nop if async logging is not set.
274-
// 1. asynclog buffer may be holding some log messages with previous decorators.
275-
// 2. asynclog buffer may be holding some log messages targeting to the output 'idx'. It has been disabled by new setting,
276-
// eg. all=off and is about to be purged in delete_output(idx).
277-
//
278-
AsyncLogWriter::flush();
279-
280256
// It is now safe to set the new decorators for the actual output
281257
output->set_decorators(decorators);
282258

283-
OrderAccess::storestore();
284-
285259
// Update the decorators on all tagsets to get rid of unused decorators
286260
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
287261
ts->update_decorators();
288262
}
289263

290264
if (!enabled && idx > 1) {
265+
// User may disable a logOuput like this:
266+
// LogConfiguration::parse_log_arguments(filename, "all=off", "", "", &stream);
267+
// Just be conservative. Flush them all before deleting idx.
268+
AsyncLogWriter::flush();
291269
// Output is unused and should be removed, unless it is stdout/stderr (idx < 2)
292270
delete_output(idx);
293271
return;

src/hotspot/share/logging/logDecorators.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@
2525
#include "logging/logDecorators.hpp"
2626
#include "runtime/os.hpp"
2727

28-
template <LogDecorators::Decorator d>
29-
struct AllBitmask {
30-
// Use recursive template deduction to calculate the bitmask of all decorations.
31-
static const uint _value = (1 << d) | AllBitmask<static_cast<LogDecorators::Decorator>(d + 1)>::_value;
32-
};
33-
34-
template<>
35-
struct AllBitmask<LogDecorators::Count> {
36-
static const uint _value = 0;
37-
};
38-
3928
const LogDecorators LogDecorators::None = LogDecorators(0);
40-
const LogDecorators LogDecorators::All = LogDecorators(AllBitmask<time_decorator>::_value);
4129

4230
const char* LogDecorators::_name[][2] = {
4331
#define DECORATOR(n, a) {#n, #a},

src/hotspot/share/logging/logDecorators.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class LogDecorators {
8282

8383
public:
8484
static const LogDecorators None;
85-
static const LogDecorators All;
8685

8786
LogDecorators() : _decorators(DefaultDecoratorsMask) {
8887
}

src/hotspot/share/logging/logFileOutput.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@
3333
#include "utilities/globalDefinitions.hpp"
3434
#include "utilities/defaultStream.hpp"
3535

36-
class RotationLocker : public StackObj {
37-
Semaphore& _sem;
38-
39-
public:
40-
RotationLocker(Semaphore& sem) : _sem(sem) {
41-
sem.wait();
42-
}
43-
44-
~RotationLocker() {
45-
_sem.signal();
46-
}
47-
};
48-
4936
const char* const LogFileOutput::Prefix = "file=";
5037
const char* const LogFileOutput::FileOpenMode = "a";
5138
const char* const LogFileOutput::PidFilenamePlaceholder = "%p";
@@ -299,12 +286,7 @@ bool LogFileOutput::initialize(const char* options, outputStream* errstream) {
299286
}
300287

301288
int LogFileOutput::write_blocking(const LogDecorations& decorations, const char* msg) {
302-
RotationLocker lock(_rotation_semaphore);
303-
if (_stream == NULL) {
304-
// An error has occurred with this output, avoid writing to it.
305-
return 0;
306-
}
307-
289+
_rotation_semaphore.wait();
308290
int written = LogFileStreamOutput::write(decorations, msg);
309291
if (written > 0) {
310292
_current_size += written;
@@ -313,6 +295,7 @@ int LogFileOutput::write_blocking(const LogDecorations& decorations, const char*
313295
rotate();
314296
}
315297
}
298+
_rotation_semaphore.signal();
316299

317300
return written;
318301
}
@@ -344,7 +327,7 @@ int LogFileOutput::write(LogMessageBuffer::Iterator msg_iterator) {
344327
return 0;
345328
}
346329

347-
RotationLocker lock(_rotation_semaphore);
330+
_rotation_semaphore.wait();
348331
int written = LogFileStreamOutput::write(msg_iterator);
349332
if (written > 0) {
350333
_current_size += written;
@@ -353,6 +336,7 @@ int LogFileOutput::write(LogMessageBuffer::Iterator msg_iterator) {
353336
rotate();
354337
}
355338
}
339+
_rotation_semaphore.signal();
356340

357341
return written;
358342
}
@@ -379,11 +363,13 @@ void LogFileOutput::force_rotate() {
379363
// Rotation not possible
380364
return;
381365
}
382-
RotationLocker lock(_rotation_semaphore);
366+
_rotation_semaphore.wait();
383367
rotate();
368+
_rotation_semaphore.signal();
384369
}
385370

386371
void LogFileOutput::rotate() {
372+
387373
if (fclose(_stream)) {
388374
jio_fprintf(defaultStream::error_stream(), "Error closing file '%s' during log rotation (%s).\n",
389375
_file_name, os::strerror(errno));

src/hotspot/share/logging/logTagSet.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,15 @@ bool LogTagSet::has_output(const LogOutput* output) {
7373
}
7474

7575
void LogTagSet::log(LogLevelType level, const char* msg) {
76-
LogOutputList::Iterator it = _output_list.iterator(level);
7776
LogDecorations decorations(level, *this, _decorators);
78-
79-
for (; it != _output_list.end(); it++) {
77+
for (LogOutputList::Iterator it = _output_list.iterator(level); it != _output_list.end(); it++) {
8078
(*it)->write(decorations, msg);
8179
}
8280
}
8381

8482
void LogTagSet::log(const LogMessageBuffer& msg) {
85-
LogOutputList::Iterator it = _output_list.iterator(msg.least_detailed_level());
8683
LogDecorations decorations(LogLevel::Invalid, *this, _decorators);
87-
88-
for (; it != _output_list.end(); it++) {
84+
for (LogOutputList::Iterator it = _output_list.iterator(msg.least_detailed_level()); it != _output_list.end(); it++) {
8985
(*it)->write(msg.iterator(it.level(), decorations));
9086
}
9187
}

test/hotspot/gtest/logging/logTestFixture.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ LogTestFixture::LogTestFixture() : _n_snapshots(0), _configuration_snapshot(NULL
4646
}
4747

4848
LogTestFixture::~LogTestFixture() {
49+
AsyncLogWriter::flush();
4950
restore_config();
5051
clear_snapshot();
5152
delete_file(TestLogFileName);

test/hotspot/gtest/logging/test_logConfiguration.cpp

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,6 @@
2323

2424
#include "precompiled.hpp"
2525
#include "jvm.h"
26-
#include "concurrentTestRunner.inline.hpp"
2726
#include "logTestFixture.hpp"
2827
#include "logTestUtils.inline.hpp"
2928
#include "logging/logConfiguration.hpp"
@@ -229,91 +228,6 @@ TEST_VM_F(LogConfigurationTest, reconfigure_decorators) {
229228
EXPECT_TRUE(is_described("#1: stderr all=off none (reconfigured)\n")) << "Expecting no decorators";
230229
}
231230

232-
class ConcurrentLogsite : public TestRunnable {
233-
int _id;
234-
235-
public:
236-
ConcurrentLogsite(int id) : _id(id) {}
237-
void runUnitTest() const override {
238-
log_debug(logging)("ConcurrentLogsite %d emits a log", _id);
239-
}
240-
};
241-
242-
// Dynamically change decorators while loggings are emitting.
243-
TEST_VM_F(LogConfigurationTest, reconfigure_decorators_MT) {
244-
const int nrOfThreads = 2;
245-
ConcurrentLogsite logsites[nrOfThreads] = {0, 1};
246-
Semaphore done(0);
247-
const long testDurationMillis = 1000;
248-
UnitTestThread* t[nrOfThreads];
249-
250-
set_log_config(TestLogFileName, "logging=debug", "none", "filecount=0");
251-
set_log_config("stdout", "all=off", "none");
252-
set_log_config("stderr", "all=off", "none");
253-
for (int i = 0; i < nrOfThreads; ++i) {
254-
t[i] = new UnitTestThread(&logsites[i], &done, testDurationMillis);
255-
}
256-
257-
for (int i = 0; i < nrOfThreads; i++) {
258-
t[i]->doit();
259-
}
260-
261-
jlong time_start = os::elapsed_counter();
262-
while (true) {
263-
jlong elapsed = (jlong)TimeHelper::counter_to_millis(os::elapsed_counter() - time_start);
264-
if (elapsed > testDurationMillis) {
265-
break;
266-
}
267-
268-
// Take turn logging with different decorators, either None or All.
269-
set_log_config(TestLogFileName, "logging=debug", "none");
270-
set_log_config(TestLogFileName, "logging=debug", _all_decorators);
271-
}
272-
273-
for (int i = 0; i < nrOfThreads; ++i) {
274-
done.wait();
275-
}
276-
}
277-
278-
// Dynamically change tags while loggings are emitting.
279-
TEST_VM_F(LogConfigurationTest, reconfigure_tags_MT) {
280-
const int nrOfThreads = 4;
281-
ConcurrentLogsite logsites[nrOfThreads] = {0, 1, 2, 3};
282-
Semaphore done(0);
283-
const long testDurationMillis = 1000;
284-
UnitTestThread* t[nrOfThreads];
285-
286-
set_log_config(TestLogFileName, "logging=debug", "", "filecount=0");
287-
set_log_config("stdout", "all=off", "none");
288-
set_log_config("stderr", "all=off", "none");
289-
290-
for (int i = 0; i < nrOfThreads; ++i) {
291-
t[i] = new UnitTestThread(&logsites[i], &done, testDurationMillis);
292-
}
293-
294-
for (int i = 0; i < nrOfThreads; i++) {
295-
t[i]->doit();
296-
}
297-
298-
jlong time_start = os::elapsed_counter();
299-
while (true) {
300-
jlong elapsed = (jlong)TimeHelper::counter_to_millis(os::elapsed_counter() - time_start);
301-
if (elapsed > testDurationMillis) {
302-
break;
303-
}
304-
305-
// turn on/off the tagset 'logging'.
306-
set_log_config(TestLogFileName, "logging=off");
307-
set_log_config(TestLogFileName, "logging=debug", "", "filecount=0");
308-
// sleep a prime number milliseconds to allow concurrent logsites write logs
309-
os::naked_short_nanosleep(137);
310-
}
311-
312-
for (int i = 0; i < nrOfThreads; ++i) {
313-
done.wait();
314-
}
315-
}
316-
317231
// Test that invalid options cause configuration errors
318232
TEST_VM_F(LogConfigurationTest, invalid_configure_options) {
319233
LogConfiguration::disable_logging();

test/hotspot/gtest/logging/test_logDecorators.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -210,13 +210,6 @@ TEST(LogDecorators, none) {
210210
}
211211
}
212212

213-
TEST(LogDecorators, all) {
214-
LogDecorators dec = LogDecorators::All;
215-
for (size_t i = 0; i < LogDecorators::Count; i++) {
216-
EXPECT_TRUE(dec.is_decorator(decorator_array[i]));
217-
}
218-
}
219-
220213
TEST(LogDecorators, is_empty) {
221214
LogDecorators def, none = LogDecorators::None;
222215
EXPECT_FALSE(def.is_empty());

0 commit comments

Comments
 (0)