8165860: WorkGroup classes are missing volatile specifiers for lock-free code
Reviewed-by: mgerdin, tschatzl
--- a/hotspot/src/share/vm/gc/shared/workgroup.cpp Tue Sep 20 00:34:54 2016 +0000
+++ b/hotspot/src/share/vm/gc/shared/workgroup.cpp Tue Sep 20 11:41:43 2016 +0200
@@ -472,23 +472,21 @@
}
bool SequentialSubTasksDone::is_task_claimed(uint& t) {
- uint* n_claimed_ptr = &_n_claimed;
- t = *n_claimed_ptr;
+ t = _n_claimed;
while (t < _n_tasks) {
- jint res = Atomic::cmpxchg(t+1, n_claimed_ptr, t);
+ jint res = Atomic::cmpxchg(t+1, &_n_claimed, t);
if (res == (jint)t) {
return false;
}
- t = *n_claimed_ptr;
+ t = res;
}
return true;
}
bool SequentialSubTasksDone::all_tasks_completed() {
- uint* n_completed_ptr = &_n_completed;
- uint complete = *n_completed_ptr;
+ uint complete = _n_completed;
while (true) {
- uint res = Atomic::cmpxchg(complete+1, n_completed_ptr, complete);
+ uint res = Atomic::cmpxchg(complete+1, &_n_completed, complete);
if (res == complete) {
break;
}
--- a/hotspot/src/share/vm/gc/shared/workgroup.hpp Tue Sep 20 00:34:54 2016 +0000
+++ b/hotspot/src/share/vm/gc/shared/workgroup.hpp Tue Sep 20 11:41:43 2016 +0200
@@ -318,9 +318,9 @@
// enumeration type.
class SubTasksDone: public CHeapObj<mtInternal> {
- uint* _tasks;
+ volatile uint* _tasks;
uint _n_tasks;
- uint _threads_completed;
+ volatile uint _threads_completed;
#ifdef ASSERT
volatile uint _claimed;
#endif
@@ -363,11 +363,11 @@
class SequentialSubTasksDone : public StackObj {
protected:
uint _n_tasks; // Total number of tasks available.
- uint _n_claimed; // Number of tasks claimed.
+ volatile uint _n_claimed; // Number of tasks claimed.
// _n_threads is used to determine when a sub task is done.
// See comments on SubTasksDone::_n_threads
uint _n_threads; // Total number of parallel threads.
- uint _n_completed; // Number of completed threads.
+ volatile uint _n_completed; // Number of completed threads.
void clear();