author | egahlin |
Fri, 17 May 2019 16:02:27 +0200 | |
branch | JEP-349-branch |
changeset 57360 | 5d043a159d5c |
parent 53244 | 9807daeb47c4 |
child 58154 | 060d9d139109 |
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 |
||
34 |
template <typename Operation, typename NextOperation> |
|
35 |
class CompositeOperation { |
|
36 |
private: |
|
37 |
Operation* _op; |
|
38 |
NextOperation* _next; |
|
39 |
public: |
|
40 |
CompositeOperation(Operation* op, NextOperation* next) : _op(op), _next(next) { |
|
41 |
assert(_op != NULL, "invariant"); |
|
42 |
} |
|
43 |
typedef typename Operation::Type Type; |
|
44 |
bool process(Type* t = NULL) { |
|
45 |
return _next == NULL ? _op->process(t) : _op->process(t) && _next->process(t); |
|
46 |
} |
|
57360 | 47 |
size_t elements() const { |
48 |
return _next == NULL ? _op->elements() : _op->elements() + _next->elements(); |
|
49 |
} |
|
50 |
size_t size() const { |
|
51 |
return _next == NULL ? _op->size() : _op->size() + _next->size(); |
|
50113 | 52 |
} |
53 |
}; |
|
54 |
||
55 |
template <typename T> |
|
56 |
class UnBufferedWriteToChunk { |
|
57 |
private: |
|
58 |
JfrChunkWriter& _writer; |
|
57360 | 59 |
size_t _elements; |
60 |
size_t _size; |
|
50113 | 61 |
public: |
62 |
typedef T Type; |
|
57360 | 63 |
UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _elements(0), _size(0) {} |
50113 | 64 |
bool write(Type* t, const u1* data, size_t size); |
57360 | 65 |
size_t elements() const { return _elements; } |
66 |
size_t size() const { return _size; } |
|
50113 | 67 |
}; |
68 |
||
69 |
template <typename T> |
|
70 |
class DefaultDiscarder { |
|
71 |
private: |
|
57360 | 72 |
size_t _elements; |
73 |
size_t _size; |
|
50113 | 74 |
public: |
75 |
typedef T Type; |
|
57360 | 76 |
DefaultDiscarder() : _elements(0), _size(0) {} |
50113 | 77 |
bool discard(Type* t, const u1* data, size_t size); |
57360 | 78 |
size_t elements() const { return _elements; } |
79 |
size_t size() const { return _size; } |
|
50113 | 80 |
}; |
81 |
||
82 |
template <typename Operation> |
|
83 |
class ConcurrentWriteOp { |
|
84 |
private: |
|
85 |
Operation& _operation; |
|
86 |
public: |
|
87 |
typedef typename Operation::Type Type; |
|
88 |
ConcurrentWriteOp(Operation& operation) : _operation(operation) {} |
|
89 |
bool process(Type* t); |
|
57360 | 90 |
size_t elements() const { return _operation.elements(); } |
91 |
size_t size() const { return _operation.size(); } |
|
50113 | 92 |
}; |
93 |
||
94 |
template <typename Operation> |
|
95 |
class ConcurrentWriteOpExcludeRetired : private ConcurrentWriteOp<Operation> { |
|
96 |
public: |
|
97 |
typedef typename Operation::Type Type; |
|
98 |
ConcurrentWriteOpExcludeRetired(Operation& operation) : ConcurrentWriteOp<Operation>(operation) {} |
|
99 |
bool process(Type* t); |
|
57360 | 100 |
size_t elements() const { return ConcurrentWriteOp<Operation>::elements();} |
101 |
size_t size() const { return ConcurrentWriteOp<Operation>::size(); } |
|
50113 | 102 |
}; |
103 |
||
104 |
template <typename Operation> |
|
105 |
class MutexedWriteOp { |
|
106 |
private: |
|
107 |
Operation& _operation; |
|
108 |
public: |
|
109 |
typedef typename Operation::Type Type; |
|
110 |
MutexedWriteOp(Operation& operation) : _operation(operation) {} |
|
111 |
bool process(Type* t); |
|
57360 | 112 |
size_t elements() const { return _operation.elements(); } |
113 |
size_t size() const { return _operation.size(); } |
|
114 |
}; |
|
115 |
||
116 |
template <typename Operation> |
|
117 |
class ExclusiveOp : public MutexedWriteOp<Operation> { |
|
118 |
public: |
|
119 |
typedef typename Operation::Type Type; |
|
120 |
ExclusiveOp(Operation& operation) : MutexedWriteOp<Operation>(operation) {} |
|
121 |
bool process(Type* t); |
|
122 |
size_t size() const { return MutexedWriteOp<Operation>::size(); } |
|
50113 | 123 |
}; |
124 |
||
125 |
enum jfr_operation_mode { |
|
126 |
mutexed = 1, |
|
127 |
concurrent |
|
128 |
}; |
|
129 |
||
130 |
template <typename Operation> |
|
131 |
class DiscardOp { |
|
132 |
private: |
|
133 |
Operation _operation; |
|
134 |
jfr_operation_mode _mode; |
|
135 |
public: |
|
136 |
typedef typename Operation::Type Type; |
|
137 |
DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {} |
|
138 |
bool process(Type* t); |
|
57360 | 139 |
size_t elements() const { return _operation.elements(); } |
140 |
size_t size() const { return _operation.size(); } |
|
50113 | 141 |
}; |
142 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50113
diff
changeset
|
143 |
#endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |