@@ -746,18 +746,21 @@ class JavaThread: public Thread {
746
746
// elided card-marks for performance along the fast-path.
747
747
MemRegion _deferred_card_mark;
748
748
749
- ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread is waiting to lock
749
+ ObjectMonitor* volatile _current_pending_monitor; // ObjectMonitor this thread is waiting to lock
750
750
bool _current_pending_monitor_is_from_java; // locking is from Java code
751
- ObjectMonitor* _current_waiting_monitor; // ObjectMonitor on which this thread called Object.wait()
751
+ ObjectMonitor* volatile _current_waiting_monitor; // ObjectMonitor on which this thread called Object.wait()
752
752
public:
753
753
volatile intptr_t _Stalled;
754
754
755
755
// For tracking the heavyweight monitor the thread is pending on.
756
756
ObjectMonitor* current_pending_monitor () {
757
- return _current_pending_monitor;
757
+ // Use Atomic::load() to prevent data race between concurrent modification and
758
+ // concurrent readers, e.g. ThreadService::get_current_contended_monitor().
759
+ // Especially, reloading pointer from thread after NULL check must be prevented.
760
+ return Atomic::load (&_current_pending_monitor);
758
761
}
759
762
void set_current_pending_monitor (ObjectMonitor* monitor) {
760
- _current_pending_monitor = monitor;
763
+ Atomic::store (& _current_pending_monitor, monitor) ;
761
764
}
762
765
void set_current_pending_monitor_is_from_java (bool from_java) {
763
766
_current_pending_monitor_is_from_java = from_java;
@@ -766,10 +769,11 @@ class JavaThread: public Thread {
766
769
return _current_pending_monitor_is_from_java;
767
770
}
768
771
ObjectMonitor* current_waiting_monitor () {
769
- return _current_waiting_monitor;
772
+ // See the comment in current_pending_monitor() above.
773
+ return Atomic::load (&_current_waiting_monitor);
770
774
}
771
775
void set_current_waiting_monitor (ObjectMonitor* monitor) {
772
- _current_waiting_monitor = monitor;
776
+ Atomic::store (& _current_waiting_monitor, monitor) ;
773
777
}
774
778
775
779
private:
0 commit comments