Wed, 17 Jun 2020 11:43:05 +0300
8220293: Deadlock in JFR string pool
Reviewed-by: rehn, egahlin
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #ifndef SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |
apetushkov@9858 | 26 | #define SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |
apetushkov@9858 | 27 | |
apetushkov@9858 | 28 | #include "jfr/recorder/storage/jfrBuffer.hpp" |
apetushkov@9858 | 29 | #include "jfr/recorder/repository/jfrChunkWriter.hpp" |
apetushkov@9858 | 30 | #include "jfr/utilities/jfrAllocation.hpp" |
apetushkov@9858 | 31 | #include "jfr/utilities/jfrTypes.hpp" |
apetushkov@9858 | 32 | #include "runtime/thread.hpp" |
apetushkov@9858 | 33 | |
apetushkov@9858 | 34 | template <typename Operation, typename NextOperation> |
apetushkov@9858 | 35 | class CompositeOperation { |
apetushkov@9858 | 36 | private: |
apetushkov@9858 | 37 | Operation* _op; |
apetushkov@9858 | 38 | NextOperation* _next; |
apetushkov@9858 | 39 | public: |
apetushkov@9858 | 40 | CompositeOperation(Operation* op, NextOperation* next) : _op(op), _next(next) { |
apetushkov@9858 | 41 | assert(_op != NULL, "invariant"); |
apetushkov@9858 | 42 | } |
apetushkov@9858 | 43 | typedef typename Operation::Type Type; |
apetushkov@9858 | 44 | bool process(Type* t = NULL) { |
apetushkov@9858 | 45 | return _next == NULL ? _op->process(t) : _op->process(t) && _next->process(t); |
apetushkov@9858 | 46 | } |
apetushkov@9858 | 47 | size_t processed() const { |
apetushkov@9858 | 48 | return _next == NULL ? _op->processed() : _op->processed() + _next->processed(); |
apetushkov@9858 | 49 | } |
apetushkov@9858 | 50 | }; |
apetushkov@9858 | 51 | |
apetushkov@9858 | 52 | template <typename T> |
apetushkov@9858 | 53 | class UnBufferedWriteToChunk { |
apetushkov@9858 | 54 | private: |
apetushkov@9858 | 55 | JfrChunkWriter& _writer; |
apetushkov@9858 | 56 | size_t _processed; |
apetushkov@9858 | 57 | public: |
apetushkov@9858 | 58 | typedef T Type; |
apetushkov@9858 | 59 | UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _processed(0) {} |
apetushkov@9858 | 60 | bool write(Type* t, const u1* data, size_t size); |
apetushkov@9858 | 61 | size_t processed() { return _processed; } |
apetushkov@9858 | 62 | }; |
apetushkov@9858 | 63 | |
apetushkov@9858 | 64 | template <typename T> |
apetushkov@9858 | 65 | class DefaultDiscarder { |
apetushkov@9858 | 66 | private: |
apetushkov@9858 | 67 | size_t _processed; |
apetushkov@9858 | 68 | public: |
apetushkov@9858 | 69 | typedef T Type; |
apetushkov@9858 | 70 | DefaultDiscarder() : _processed() {} |
apetushkov@9858 | 71 | bool discard(Type* t, const u1* data, size_t size); |
apetushkov@9858 | 72 | size_t processed() const { return _processed; } |
apetushkov@9858 | 73 | }; |
apetushkov@9858 | 74 | |
apetushkov@9858 | 75 | template <typename Operation> |
apetushkov@9858 | 76 | class ConcurrentWriteOp { |
apetushkov@9858 | 77 | private: |
apetushkov@9858 | 78 | Operation& _operation; |
apetushkov@9858 | 79 | public: |
apetushkov@9858 | 80 | typedef typename Operation::Type Type; |
apetushkov@9858 | 81 | ConcurrentWriteOp(Operation& operation) : _operation(operation) {} |
apetushkov@9858 | 82 | bool process(Type* t); |
apetushkov@9858 | 83 | size_t processed() const { return _operation.processed(); } |
apetushkov@9858 | 84 | }; |
apetushkov@9858 | 85 | |
apetushkov@9858 | 86 | template <typename Operation> |
apetushkov@9858 | 87 | class ConcurrentWriteOpExcludeRetired : private ConcurrentWriteOp<Operation> { |
apetushkov@9858 | 88 | public: |
apetushkov@9858 | 89 | typedef typename Operation::Type Type; |
apetushkov@9858 | 90 | ConcurrentWriteOpExcludeRetired(Operation& operation) : ConcurrentWriteOp<Operation>(operation) {} |
apetushkov@9858 | 91 | bool process(Type* t); |
apetushkov@9858 | 92 | size_t processed() const { return ConcurrentWriteOp<Operation>::processed(); } |
apetushkov@9858 | 93 | }; |
apetushkov@9858 | 94 | |
apetushkov@9858 | 95 | template <typename Operation> |
apetushkov@9858 | 96 | class MutexedWriteOp { |
apetushkov@9858 | 97 | private: |
apetushkov@9858 | 98 | Operation& _operation; |
apetushkov@9858 | 99 | public: |
apetushkov@9858 | 100 | typedef typename Operation::Type Type; |
apetushkov@9858 | 101 | MutexedWriteOp(Operation& operation) : _operation(operation) {} |
apetushkov@9858 | 102 | bool process(Type* t); |
apetushkov@9858 | 103 | size_t processed() const { return _operation.processed(); } |
apetushkov@9858 | 104 | }; |
apetushkov@9858 | 105 | |
apetushkov@9928 | 106 | template <typename Operation> |
apetushkov@9928 | 107 | class ExclusiveOp : private MutexedWriteOp<Operation> { |
apetushkov@9928 | 108 | public: |
apetushkov@9928 | 109 | typedef typename Operation::Type Type; |
apetushkov@9928 | 110 | ExclusiveOp(Operation& operation) : MutexedWriteOp<Operation>(operation) {} |
apetushkov@9928 | 111 | bool process(Type* t); |
apetushkov@9928 | 112 | size_t processed() const { return MutexedWriteOp<Operation>::processed(); } |
apetushkov@9928 | 113 | }; |
apetushkov@9928 | 114 | |
apetushkov@9858 | 115 | enum jfr_operation_mode { |
apetushkov@9858 | 116 | mutexed = 1, |
apetushkov@9858 | 117 | concurrent |
apetushkov@9858 | 118 | }; |
apetushkov@9858 | 119 | |
apetushkov@9858 | 120 | template <typename Operation> |
apetushkov@9858 | 121 | class DiscardOp { |
apetushkov@9858 | 122 | private: |
apetushkov@9858 | 123 | Operation _operation; |
apetushkov@9858 | 124 | jfr_operation_mode _mode; |
apetushkov@9858 | 125 | public: |
apetushkov@9858 | 126 | typedef typename Operation::Type Type; |
apetushkov@9858 | 127 | DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {} |
apetushkov@9858 | 128 | bool process(Type* t); |
apetushkov@9858 | 129 | size_t processed() const { return _operation.processed(); } |
apetushkov@9858 | 130 | }; |
apetushkov@9858 | 131 | |
apetushkov@9858 | 132 | #endif // SHARE_VM_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP |