author | mgronlun |
Sun, 22 Sep 2019 14:00:00 +0200 | |
branch | JEP-349-branch |
changeset 58254 | a6ccade6b295 |
parent 58154 | 060d9d139109 |
child 58255 | f9648f8ca4da |
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_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
26 |
#define SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |
50113 | 27 |
|
28 |
#include "jfr/recorder/storage/jfrBuffer.hpp" |
|
29 |
#include "jfr/recorder/repository/jfrChunkWriter.hpp" |
|
30 |
#include "jfr/utilities/jfrAllocation.hpp" |
|
31 |
#include "jfr/utilities/jfrTypes.hpp" |
|
32 |
#include "runtime/thread.hpp" |
|
33 |
||
58254 | 34 |
class Or { |
35 |
public: |
|
36 |
static bool evaluate(bool value) { |
|
37 |
return !value; |
|
38 |
} |
|
39 |
}; |
|
40 |
||
41 |
class And { |
|
42 |
public: |
|
43 |
static bool evaluate(bool value) { |
|
44 |
return value; |
|
45 |
} |
|
46 |
}; |
|
47 |
||
48 |
template <typename Operation, typename NextOperation, typename TruthFunction = And> |
|
50113 | 49 |
class CompositeOperation { |
50 |
private: |
|
51 |
Operation* _op; |
|
52 |
NextOperation* _next; |
|
53 |
public: |
|
54 |
CompositeOperation(Operation* op, NextOperation* next) : _op(op), _next(next) { |
|
55 |
assert(_op != NULL, "invariant"); |
|
56 |
} |
|
57 |
typedef typename Operation::Type Type; |
|
58254 | 58 |
bool process(Type* t) { |
59 |
const bool op_result = _op->process(t); |
|
60 |
return _next == NULL ? op_result : TruthFunction::evaluate(op_result) ? _next->process(t) : op_result; |
|
50113 | 61 |
} |
57360 | 62 |
size_t elements() const { |
63 |
return _next == NULL ? _op->elements() : _op->elements() + _next->elements(); |
|
64 |
} |
|
65 |
size_t size() const { |
|
66 |
return _next == NULL ? _op->size() : _op->size() + _next->size(); |
|
50113 | 67 |
} |
68 |
}; |
|
69 |
||
70 |
template <typename T> |
|
71 |
class UnBufferedWriteToChunk { |
|
72 |
private: |
|
73 |
JfrChunkWriter& _writer; |
|
57360 | 74 |
size_t _elements; |
75 |
size_t _size; |
|
50113 | 76 |
public: |
77 |
typedef T Type; |
|
57360 | 78 |
UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _elements(0), _size(0) {} |
50113 | 79 |
bool write(Type* t, const u1* data, size_t size); |
57360 | 80 |
size_t elements() const { return _elements; } |
81 |
size_t size() const { return _size; } |
|
50113 | 82 |
}; |
83 |
||
84 |
template <typename T> |
|
85 |
class DefaultDiscarder { |
|
86 |
private: |
|
57360 | 87 |
size_t _elements; |
88 |
size_t _size; |
|
50113 | 89 |
public: |
90 |
typedef T Type; |
|
57360 | 91 |
DefaultDiscarder() : _elements(0), _size(0) {} |
50113 | 92 |
bool discard(Type* t, const u1* data, size_t size); |
57360 | 93 |
size_t elements() const { return _elements; } |
94 |
size_t size() const { return _size; } |
|
50113 | 95 |
}; |
96 |
||
58254 | 97 |
template <typename T, bool negation> |
98 |
class Retired { |
|
99 |
public: |
|
100 |
typedef typename T Type; |
|
101 |
bool process(T* t) { |
|
102 |
assert(t != NULL, "invariant"); |
|
103 |
return negation ? !t->retired() : t->retired(); |
|
104 |
} |
|
105 |
}; |
|
106 |
||
107 |
template <typename T, bool negation> |
|
108 |
class Excluded { |
|
109 |
public: |
|
110 |
typedef typename T Type; |
|
111 |
bool process(T* t) { |
|
112 |
assert(t != NULL, "invariant"); |
|
113 |
return negation ? !t->excluded() : t->excluded(); |
|
114 |
} |
|
115 |
}; |
|
116 |
||
117 |
template <typename Operation> |
|
118 |
class MutexedWriteOp { |
|
119 |
private: |
|
120 |
Operation& _operation; |
|
121 |
public: |
|
122 |
typedef typename Operation::Type Type; |
|
123 |
MutexedWriteOp(Operation& operation) : _operation(operation) {} |
|
124 |
bool process(Type* t); |
|
125 |
size_t elements() const { return _operation.elements(); } |
|
126 |
size_t size() const { return _operation.size(); } |
|
127 |
}; |
|
128 |
||
129 |
template <typename Operation, typename Predicate> |
|
130 |
class PredicatedMutexedWriteOp : public MutexedWriteOp<Operation> { |
|
131 |
private: |
|
132 |
Predicate& _predicate; |
|
133 |
public: |
|
134 |
PredicatedMutexedWriteOp(Operation& operation, Predicate& predicate) : |
|
135 |
MutexedWriteOp(operation), _predicate(predicate) {} |
|
136 |
bool process(Type* t) { |
|
137 |
return _predicate.process(t) ? MutexedWriteOp<Operation>::process(t) : true; |
|
138 |
} |
|
139 |
}; |
|
140 |
||
50113 | 141 |
template <typename Operation> |
142 |
class ConcurrentWriteOp { |
|
143 |
private: |
|
144 |
Operation& _operation; |
|
145 |
public: |
|
146 |
typedef typename Operation::Type Type; |
|
147 |
ConcurrentWriteOp(Operation& operation) : _operation(operation) {} |
|
148 |
bool process(Type* t); |
|
57360 | 149 |
size_t elements() const { return _operation.elements(); } |
150 |
size_t size() const { return _operation.size(); } |
|
50113 | 151 |
}; |
152 |
||
58254 | 153 |
template <typename Operation, typename Predicate> |
154 |
class PredicatedConcurrentWriteOp : public ConcurrentWriteOp<Operation> { |
|
155 |
private: |
|
156 |
Predicate& _predicate; |
|
50113 | 157 |
public: |
58254 | 158 |
PredicatedConcurrentWriteOp(Operation& operation, Predicate& predicate) : |
159 |
ConcurrentWriteOp(operation), _predicate(predicate) {} |
|
160 |
bool process(Type* t) { |
|
161 |
return _predicate.process(t) ? ConcurrentWriteOp<Operation>::process(t) : true; |
|
162 |
} |
|
50113 | 163 |
}; |
164 |
||
54964 | 165 |
template <typename Operation> |
166 |
class ExclusiveOp : private MutexedWriteOp<Operation> { |
|
167 |
public: |
|
168 |
typedef typename Operation::Type Type; |
|
169 |
ExclusiveOp(Operation& operation) : MutexedWriteOp<Operation>(operation) {} |
|
170 |
bool process(Type* t); |
|
171 |
size_t processed() const { return MutexedWriteOp<Operation>::processed(); } |
|
172 |
}; |
|
173 |
||
50113 | 174 |
enum jfr_operation_mode { |
175 |
mutexed = 1, |
|
176 |
concurrent |
|
177 |
}; |
|
178 |
||
179 |
template <typename Operation> |
|
180 |
class DiscardOp { |
|
181 |
private: |
|
182 |
Operation _operation; |
|
183 |
jfr_operation_mode _mode; |
|
184 |
public: |
|
185 |
typedef typename Operation::Type Type; |
|
186 |
DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {} |
|
187 |
bool process(Type* t); |
|
57360 | 188 |
size_t elements() const { return _operation.elements(); } |
189 |
size_t size() const { return _operation.size(); } |
|
50113 | 190 |
}; |
191 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
192 |
#endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |