Skip to content

Commit 7b255b8

Browse files
committed
8361397: Rework CompileLog list synchronization
Reviewed-by: kvn, chagedorn
1 parent 310ef85 commit 7b255b8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/hotspot/share/compiler/compileLog.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
#include "jvm.h"
2929
#include "memory/allocation.inline.hpp"
3030
#include "oops/method.hpp"
31+
#include "runtime/atomic.hpp"
3132
#include "runtime/mutexLocker.hpp"
3233
#include "runtime/os.hpp"
3334

34-
CompileLog* CompileLog::_first = nullptr;
35+
CompileLog* volatile CompileLog::_list_head = nullptr;
3536

3637
// ------------------------------------------------------------------
3738
// CompileLog::CompileLog
@@ -49,9 +50,12 @@ CompileLog::CompileLog(const char* file_name, FILE* fp, intx thread_id)
4950
strcpy((char*)_file, file_name);
5051

5152
// link into the global list
52-
{ MutexLocker locker(CompileTaskAlloc_lock);
53-
_next = _first;
54-
_first = this;
53+
while (true) {
54+
CompileLog* head = Atomic::load_acquire(&_list_head);
55+
_next = head;
56+
if (Atomic::cmpxchg(&_list_head, head, this) == head) {
57+
break;
58+
}
5559
}
5660
}
5761

@@ -202,7 +206,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
202206
if (called_exit) return;
203207
called_exit = true;
204208

205-
CompileLog* log = _first;
209+
CompileLog* log = Atomic::load_acquire(&_list_head);
206210
while (log != nullptr) {
207211
log->flush();
208212
const char* partial_file = log->file();
@@ -290,7 +294,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
290294
delete log; // Removes partial file
291295
log = next_log;
292296
}
293-
_first = nullptr;
297+
Atomic::store(&_list_head, (CompileLog*)nullptr);
294298
}
295299

296300
// ------------------------------------------------------------------

src/hotspot/share/compiler/compileLog.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class CompileLog : public xmlStream {
5353

5454
CompileLog* _next; // static chain of all logs
5555

56-
static CompileLog* _first; // head of static chain
56+
static CompileLog* volatile _list_head; // head of static chain
5757

5858
void va_tag(bool push, const char* format, va_list ap) ATTRIBUTE_PRINTF(3, 0);
5959

0 commit comments

Comments
 (0)