Skip to content

Commit

Permalink
Better comment and no accidental assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
jdksjolen committed Feb 7, 2025
1 parent 7eaee59 commit 43c9756
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/hotspot/share/logging/logAsyncWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AsyncLogWriter::AsyncLogLocker : public StackObj {
}

~AsyncLogLocker() {
assert(_holder = Thread::current_or_null(), "must be");
assert(_holder == Thread::current_or_null(), "must be");
_holder = nullptr;
_instance->_lock.unlock();
}
Expand Down Expand Up @@ -92,17 +92,18 @@ void AsyncLogWriter::enqueue_locked(LogFileStreamOutput* output, const LogDecora
_lock.notify();
}

// Check for degenerate cases of logging.
// This function checks for cases where continuing with asynchronous logging may lead to stability issues, such as a deadlock.
// If this returns true then we give up on logging asynchronously and do so synchronously instead.
bool AsyncLogWriter::resort_to_synchronous_logging() {
AsyncLogWriter* alw = AsyncLogWriter::instance();
Thread* holding_thread = AsyncLogWriter::AsyncLogLocker::current_holder();
Thread* this_thread = Thread::current_or_null();
bool is_async_log_thread = this_thread != nullptr && alw == this_thread;
bool is_recursively_logging = this_thread != nullptr && holding_thread == this_thread;
return is_async_log_thread // The async log producer is attempting to log, leading to recursive logging.
|| is_recursively_logging // A thread enqueuing a message has attempted to log something.
|| alw == nullptr; // There is no AsyncLogWriter instance yet.
return is_async_log_thread || // The async log producer is attempting to log, leading to recursive logging.
is_recursively_logging || // A thread enqueuing a message has attempted to log something.
alw == nullptr || // There is no AsyncLogWriter instance yet.
this_thread == nullptr; // The current thread is unattached.
}

bool AsyncLogWriter::enqueue(LogFileStreamOutput& output, const LogDecorations& decorations, const char* msg) {
Expand Down

0 comments on commit 43c9756

Please sign in to comment.