22 * |
22 * |
23 */ |
23 */ |
24 |
24 |
25 #include "precompiled.hpp" |
25 #include "precompiled.hpp" |
26 #include "jfr/recorder/stringpool/jfrStringPoolBuffer.hpp" |
26 #include "jfr/recorder/stringpool/jfrStringPoolBuffer.hpp" |
27 #include "runtime/atomic.hpp" |
|
28 #include "runtime/orderAccess.hpp" |
|
29 #include "runtime/thread.inline.hpp" |
|
30 |
27 |
31 JfrStringPoolBuffer::JfrStringPoolBuffer() : JfrBuffer(), _string_count_pos(0), _string_count_top(0) {} |
28 JfrStringPoolBuffer::JfrStringPoolBuffer() : JfrBuffer(), _string_count_pos(0), _string_count_top(0) {} |
32 |
29 |
33 void JfrStringPoolBuffer::reinitialize() { |
30 void JfrStringPoolBuffer::reinitialize() { |
|
31 assert(acquired_by_self() || retired(), "invariant"); |
34 concurrent_top(); |
32 concurrent_top(); |
35 set_pos((start())); |
33 set_pos((start())); |
36 set_string_pos(0); |
34 set_string_pos(0); |
37 set_string_top(0); |
35 set_string_top(0); |
38 set_concurrent_top(start()); |
36 set_concurrent_top(start()); |
39 } |
37 } |
40 |
38 |
41 uint64_t JfrStringPoolBuffer::string_pos() const { |
39 uint64_t JfrStringPoolBuffer::string_pos() const { |
42 return OrderAccess::load_acquire(&_string_count_pos); |
40 assert(acquired_by_self() || retired(), "invariant"); |
|
41 return _string_count_pos; |
43 } |
42 } |
44 |
43 |
45 uint64_t JfrStringPoolBuffer::string_top() const { |
44 uint64_t JfrStringPoolBuffer::string_top() const { |
46 return OrderAccess::load_acquire(&_string_count_top); |
45 assert(acquired_by_self() || retired(), "invariant"); |
|
46 return _string_count_top; |
47 } |
47 } |
48 |
48 |
49 uint64_t JfrStringPoolBuffer::string_count() const { |
49 uint64_t JfrStringPoolBuffer::string_count() const { |
|
50 assert(acquired_by_self() || retired(), "invariant"); |
50 return string_pos() - string_top(); |
51 return string_pos() - string_top(); |
51 } |
52 } |
52 |
53 |
53 void JfrStringPoolBuffer::set_string_pos(uint64_t value) { |
54 void JfrStringPoolBuffer::set_string_pos(uint64_t value) { |
54 Atomic::store(value, &_string_count_pos); |
55 assert(acquired_by_self() || retired(), "invariant"); |
|
56 _string_count_pos = value; |
55 } |
57 } |
56 |
58 |
57 void JfrStringPoolBuffer::increment(uint64_t value) { |
59 void JfrStringPoolBuffer::increment(uint64_t value) { |
58 #if !(defined(ARM) || defined(IA32)) |
60 assert(acquired_by_self() || retired(), "invariant"); |
59 Atomic::add(value, &_string_count_pos); |
61 ++_string_count_pos; |
60 #else |
|
61 // TODO: This should be fixed in Atomic::add handling for 32-bit platforms, |
|
62 // see JDK-8203283. We workaround the absence of support right here. |
|
63 uint64_t cur, val; |
|
64 do { |
|
65 cur = Atomic::load(&_string_count_top); |
|
66 val = cur + value; |
|
67 } while (Atomic::cmpxchg(val, &_string_count_pos, cur) != cur); |
|
68 #endif |
|
69 } |
62 } |
70 |
63 |
71 void JfrStringPoolBuffer::set_string_top(uint64_t value) { |
64 void JfrStringPoolBuffer::set_string_top(uint64_t value) { |
72 Atomic::store(value, &_string_count_top); |
65 assert(acquired_by_self() || retired(), "invariant"); |
|
66 _string_count_top = value; |
73 } |
67 } |