diff --git a/src/hotspot/share/compiler/compileLog.cpp b/src/hotspot/share/compiler/compileLog.cpp index 85b8cbdf5921a..9641e99c33a21 100644 --- a/src/hotspot/share/compiler/compileLog.cpp +++ b/src/hotspot/share/compiler/compileLog.cpp @@ -28,10 +28,11 @@ #include "jvm.h" #include "memory/allocation.inline.hpp" #include "oops/method.hpp" +#include "runtime/atomic.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/os.hpp" -CompileLog* CompileLog::_first = nullptr; +CompileLog* volatile CompileLog::_list_head = nullptr; // ------------------------------------------------------------------ // CompileLog::CompileLog @@ -49,9 +50,12 @@ CompileLog::CompileLog(const char* file_name, FILE* fp, intx thread_id) strcpy((char*)_file, file_name); // link into the global list - { MutexLocker locker(CompileTaskAlloc_lock); - _next = _first; - _first = this; + while (true) { + CompileLog* head = Atomic::load_acquire(&_list_head); + _next = head; + if (Atomic::cmpxchg(&_list_head, head, this) == head) { + break; + } } } @@ -202,7 +206,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen) if (called_exit) return; called_exit = true; - CompileLog* log = _first; + CompileLog* log = Atomic::load_acquire(&_list_head); while (log != nullptr) { log->flush(); const char* partial_file = log->file(); @@ -290,7 +294,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen) delete log; // Removes partial file log = next_log; } - _first = nullptr; + Atomic::store(&_list_head, (CompileLog*)nullptr); } // ------------------------------------------------------------------ diff --git a/src/hotspot/share/compiler/compileLog.hpp b/src/hotspot/share/compiler/compileLog.hpp index d91819104a5d6..10698b3c13b25 100644 --- a/src/hotspot/share/compiler/compileLog.hpp +++ b/src/hotspot/share/compiler/compileLog.hpp @@ -53,7 +53,7 @@ class CompileLog : public xmlStream { CompileLog* _next; // static chain of all logs - static CompileLog* _first; // head of static chain + static CompileLog* volatile _list_head; // head of static chain void va_tag(bool push, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0);