9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
26 #define SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
27
28 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
29
30 template <typename T>
31 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
32 _writer.write_unbuffered(data, size);
33 _processed += size;
34 return true;
35 }
36
37 template <typename T>
38 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
39 _processed += size;
40 return true;
41 }
42
43 template <typename Operation>
44 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
45 const u1* const current_top = t->concurrent_top();
46 const size_t unflushed_size = t->pos() - current_top;
47 if (unflushed_size == 0) {
48 t->set_concurrent_top(current_top);
56 template <typename Operation>
57 inline bool ConcurrentWriteOpExcludeRetired<Operation>::process(typename Operation::Type* t) {
58 if (t->retired()) {
59 assert(t->empty(), "invariant");
60 return true;
61 }
62 return ConcurrentWriteOp<Operation>::process(t);
63 }
64
65 template <typename Operation>
66 inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) {
67 assert(t != NULL, "invariant");
68 const u1* const current_top = t->top();
69 const size_t unflushed_size = t->pos() - current_top;
70 if (unflushed_size == 0) {
71 return true;
72 }
73 const bool result = _operation.write(t, current_top, unflushed_size);
74 t->set_top(current_top + unflushed_size);
75 return result;
76 }
77
78 template <typename Operation>
79 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
80 assert(t != NULL, "invariant");
81 const u1* const current_top = _mode == concurrent ? t->concurrent_top() : t->top();
82 const size_t unflushed_size = t->pos() - current_top;
83 if (unflushed_size == 0) {
84 if (_mode == concurrent) {
85 t->set_concurrent_top(current_top);
86 }
87 return true;
88 }
89 const bool result = _operation.discard(t, current_top, unflushed_size);
90 if (_mode == concurrent) {
91 t->set_concurrent_top(current_top + unflushed_size);
92 } else {
93 t->set_top(current_top + unflushed_size);
94 }
95 return result;
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
26 #define SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
27
28 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
29 #include "runtime/thread.inline.hpp"
30
31 template <typename T>
32 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
33 _writer.write_unbuffered(data, size);
34 _processed += size;
35 return true;
36 }
37
38 template <typename T>
39 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
40 _processed += size;
41 return true;
42 }
43
44 template <typename Operation>
45 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
46 const u1* const current_top = t->concurrent_top();
47 const size_t unflushed_size = t->pos() - current_top;
48 if (unflushed_size == 0) {
49 t->set_concurrent_top(current_top);
57 template <typename Operation>
58 inline bool ConcurrentWriteOpExcludeRetired<Operation>::process(typename Operation::Type* t) {
59 if (t->retired()) {
60 assert(t->empty(), "invariant");
61 return true;
62 }
63 return ConcurrentWriteOp<Operation>::process(t);
64 }
65
66 template <typename Operation>
67 inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) {
68 assert(t != NULL, "invariant");
69 const u1* const current_top = t->top();
70 const size_t unflushed_size = t->pos() - current_top;
71 if (unflushed_size == 0) {
72 return true;
73 }
74 const bool result = _operation.write(t, current_top, unflushed_size);
75 t->set_top(current_top + unflushed_size);
76 return result;
77 }
78
79 template <typename Type>
80 static void retired_sensitive_acquire(Type* t) {
81 assert(t != NULL, "invariant");
82 if (t->retired()) {
83 return;
84 }
85 Thread* const thread = Thread::current();
86 while (!t->try_acquire(thread)) {
87 if (t->retired()) {
88 return;
89 }
90 }
91 }
92
93 template <typename Operation>
94 inline bool ExclusiveOp<Operation>::process(typename Operation::Type* t) {
95 retired_sensitive_acquire(t);
96 assert(t->acquired_by_self() || t->retired(), "invariant");
97 // User is required to ensure proper release of the acquisition
98 return MutexedWriteOp<Operation>::process(t);
99 }
100
101 template <typename Operation>
102 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
103 assert(t != NULL, "invariant");
104 const u1* const current_top = _mode == concurrent ? t->concurrent_top() : t->top();
105 const size_t unflushed_size = t->pos() - current_top;
106 if (unflushed_size == 0) {
107 if (_mode == concurrent) {
108 t->set_concurrent_top(current_top);
109 }
110 return true;
111 }
112 const bool result = _operation.discard(t, current_top, unflushed_size);
113 if (_mode == concurrent) {
114 t->set_concurrent_top(current_top + unflushed_size);
115 } else {
116 t->set_top(current_top + unflushed_size);
117 }
118 return result;
|