|
1 /* |
|
2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
|
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 |
|
25 #ifndef SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |
|
26 #define SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |
|
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 } |
|
47 size_t processed() const { |
|
48 return _next == NULL ? _op->processed() : _op->processed() + _next->processed(); |
|
49 } |
|
50 }; |
|
51 |
|
52 template <typename T> |
|
53 class UnBufferedWriteToChunk { |
|
54 private: |
|
55 JfrChunkWriter& _writer; |
|
56 size_t _processed; |
|
57 public: |
|
58 typedef T Type; |
|
59 UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _processed(0) {} |
|
60 bool write(Type* t, const u1* data, size_t size); |
|
61 size_t processed() { return _processed; } |
|
62 }; |
|
63 |
|
64 template <typename T> |
|
65 class DefaultDiscarder { |
|
66 private: |
|
67 size_t _processed; |
|
68 public: |
|
69 typedef T Type; |
|
70 DefaultDiscarder() : _processed() {} |
|
71 bool discard(Type* t, const u1* data, size_t size); |
|
72 size_t processed() const { return _processed; } |
|
73 }; |
|
74 |
|
75 template <typename Operation> |
|
76 class ConcurrentWriteOp { |
|
77 private: |
|
78 Operation& _operation; |
|
79 public: |
|
80 typedef typename Operation::Type Type; |
|
81 ConcurrentWriteOp(Operation& operation) : _operation(operation) {} |
|
82 bool process(Type* t); |
|
83 size_t processed() const { return _operation.processed(); } |
|
84 }; |
|
85 |
|
86 template <typename Operation> |
|
87 class ConcurrentWriteOpExcludeRetired : private ConcurrentWriteOp<Operation> { |
|
88 public: |
|
89 typedef typename Operation::Type Type; |
|
90 ConcurrentWriteOpExcludeRetired(Operation& operation) : ConcurrentWriteOp<Operation>(operation) {} |
|
91 bool process(Type* t); |
|
92 size_t processed() const { return ConcurrentWriteOp<Operation>::processed(); } |
|
93 }; |
|
94 |
|
95 |
|
96 template <typename Operation> |
|
97 class MutexedWriteOp { |
|
98 private: |
|
99 Operation& _operation; |
|
100 public: |
|
101 typedef typename Operation::Type Type; |
|
102 MutexedWriteOp(Operation& operation) : _operation(operation) {} |
|
103 bool process(Type* t); |
|
104 size_t processed() const { return _operation.processed(); } |
|
105 }; |
|
106 |
|
107 enum jfr_operation_mode { |
|
108 mutexed = 1, |
|
109 concurrent |
|
110 }; |
|
111 |
|
112 template <typename Operation> |
|
113 class DiscardOp { |
|
114 private: |
|
115 Operation _operation; |
|
116 jfr_operation_mode _mode; |
|
117 public: |
|
118 typedef typename Operation::Type Type; |
|
119 DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {} |
|
120 bool process(Type* t); |
|
121 size_t processed() const { return _operation.processed(); } |
|
122 }; |
|
123 |
|
124 #endif // SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |