author | mgronlun |
Wed, 30 Oct 2019 19:43:52 +0100 | |
changeset 58863 | c16ac7a2eba4 |
parent 54964 | ec7d6d8effc7 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
2 |
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
25 |
#ifndef SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
26 |
#define SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP |
50113 | 27 |
|
28 |
#include "jfr/recorder/storage/jfrStorageUtils.hpp" |
|
54964 | 29 |
#include "runtime/thread.inline.hpp" |
50113 | 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); |
|
58863 | 34 |
++_elements; |
35 |
_size += size; |
|
50113 | 36 |
return true; |
37 |
} |
|
38 |
||
39 |
template <typename T> |
|
40 |
inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) { |
|
58863 | 41 |
++_elements; |
42 |
_size += size; |
|
50113 | 43 |
return true; |
44 |
} |
|
45 |
||
46 |
template <typename Operation> |
|
47 |
inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) { |
|
48 |
const u1* const current_top = t->concurrent_top(); |
|
49 |
const size_t unflushed_size = t->pos() - current_top; |
|
50 |
if (unflushed_size == 0) { |
|
51 |
t->set_concurrent_top(current_top); |
|
52 |
return true; |
|
53 |
} |
|
54 |
const bool result = _operation.write(t, current_top, unflushed_size); |
|
55 |
t->set_concurrent_top(current_top + unflushed_size); |
|
56 |
return result; |
|
57 |
} |
|
58 |
||
59 |
template <typename Operation> |
|
60 |
inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) { |
|
61 |
assert(t != NULL, "invariant"); |
|
62 |
const u1* const current_top = t->top(); |
|
63 |
const size_t unflushed_size = t->pos() - current_top; |
|
64 |
if (unflushed_size == 0) { |
|
65 |
return true; |
|
66 |
} |
|
67 |
const bool result = _operation.write(t, current_top, unflushed_size); |
|
68 |
t->set_top(current_top + unflushed_size); |
|
69 |
return result; |
|
70 |
} |
|
71 |
||
54964 | 72 |
template <typename Type> |
73 |
static void retired_sensitive_acquire(Type* t) { |
|
74 |
assert(t != NULL, "invariant"); |
|
75 |
if (t->retired()) { |
|
76 |
return; |
|
77 |
} |
|
78 |
Thread* const thread = Thread::current(); |
|
79 |
while (!t->try_acquire(thread)) { |
|
80 |
if (t->retired()) { |
|
81 |
return; |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
||
86 |
template <typename Operation> |
|
87 |
inline bool ExclusiveOp<Operation>::process(typename Operation::Type* t) { |
|
88 |
retired_sensitive_acquire(t); |
|
89 |
assert(t->acquired_by_self() || t->retired(), "invariant"); |
|
90 |
// User is required to ensure proper release of the acquisition |
|
91 |
return MutexedWriteOp<Operation>::process(t); |
|
92 |
} |
|
93 |
||
50113 | 94 |
template <typename Operation> |
95 |
inline bool DiscardOp<Operation>::process(typename Operation::Type* t) { |
|
96 |
assert(t != NULL, "invariant"); |
|
97 |
const u1* const current_top = _mode == concurrent ? t->concurrent_top() : t->top(); |
|
98 |
const size_t unflushed_size = t->pos() - current_top; |
|
99 |
if (unflushed_size == 0) { |
|
100 |
if (_mode == concurrent) { |
|
101 |
t->set_concurrent_top(current_top); |
|
102 |
} |
|
103 |
return true; |
|
104 |
} |
|
105 |
const bool result = _operation.discard(t, current_top, unflushed_size); |
|
106 |
if (_mode == concurrent) { |
|
107 |
t->set_concurrent_top(current_top + unflushed_size); |
|
108 |
} else { |
|
109 |
t->set_top(current_top + unflushed_size); |
|
110 |
} |
|
111 |
return result; |
|
112 |
} |
|
113 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
114 |
#endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP |