22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "runtime/interfaceSupport.inline.hpp" |
26 #include "runtime/interfaceSupport.inline.hpp" |
27 #include "runtime/orderAccess.hpp" |
27 #include "runtime/atomic.hpp" |
28 #include "runtime/os.hpp" |
28 #include "runtime/os.hpp" |
29 #include "runtime/thread.hpp" |
29 #include "runtime/thread.hpp" |
30 #include "utilities/debug.hpp" |
30 #include "utilities/debug.hpp" |
31 #include "utilities/globalCounter.inline.hpp" |
31 #include "utilities/globalCounter.inline.hpp" |
32 #include "utilities/globalDefinitions.hpp" |
32 #include "utilities/globalDefinitions.hpp" |
54 {} |
54 {} |
55 |
55 |
56 virtual void main_run() { |
56 virtual void main_run() { |
57 size_t iterations = 0; |
57 size_t iterations = 0; |
58 size_t values_changed = 0; |
58 size_t values_changed = 0; |
59 while (OrderAccess::load_acquire(_continue_running) != 0) { |
59 while (Atomic::load_acquire(_continue_running) != 0) { |
60 { ThreadBlockInVM tbiv(this); } // Safepoint check outside critical section. |
60 { ThreadBlockInVM tbiv(this); } // Safepoint check outside critical section. |
61 ++iterations; |
61 ++iterations; |
62 SingleWriterSynchronizer::CriticalSection cs(_synchronizer); |
62 SingleWriterSynchronizer::CriticalSection cs(_synchronizer); |
63 uintx value = OrderAccess::load_acquire(_synchronized_value); |
63 uintx value = Atomic::load_acquire(_synchronized_value); |
64 uintx new_value = value; |
64 uintx new_value = value; |
65 for (uint i = 0; i < reader_iterations; ++i) { |
65 for (uint i = 0; i < reader_iterations; ++i) { |
66 new_value = OrderAccess::load_acquire(_synchronized_value); |
66 new_value = Atomic::load_acquire(_synchronized_value); |
67 // A reader can see either the value it first read after |
67 // A reader can see either the value it first read after |
68 // entering the critical section, or that value + 1. No other |
68 // entering the critical section, or that value + 1. No other |
69 // values are possible. |
69 // values are possible. |
70 if (value != new_value) { |
70 if (value != new_value) { |
71 ASSERT_EQ((value + 1), new_value); |
71 ASSERT_EQ((value + 1), new_value); |
95 _synchronized_value(synchronized_value), |
95 _synchronized_value(synchronized_value), |
96 _continue_running(continue_running) |
96 _continue_running(continue_running) |
97 {} |
97 {} |
98 |
98 |
99 virtual void main_run() { |
99 virtual void main_run() { |
100 while (OrderAccess::load_acquire(_continue_running) != 0) { |
100 while (Atomic::load_acquire(_continue_running) != 0) { |
101 ++*_synchronized_value; |
101 ++*_synchronized_value; |
102 _synchronizer->synchronize(); |
102 _synchronizer->synchronize(); |
103 { ThreadBlockInVM tbiv(this); } // Safepoint check. |
103 { ThreadBlockInVM tbiv(this); } // Safepoint check. |
104 } |
104 } |
105 tty->print_cr("writer iterations: " UINTX_FORMAT, *_synchronized_value); |
105 tty->print_cr("writer iterations: " UINTX_FORMAT, *_synchronized_value); |