src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.hpp
changeset 58863 c16ac7a2eba4
parent 54964 ec7d6d8effc7
equal deleted inserted replaced
58861:2c3cc4b01880 58863:c16ac7a2eba4
    29 #include "jfr/recorder/repository/jfrChunkWriter.hpp"
    29 #include "jfr/recorder/repository/jfrChunkWriter.hpp"
    30 #include "jfr/utilities/jfrAllocation.hpp"
    30 #include "jfr/utilities/jfrAllocation.hpp"
    31 #include "jfr/utilities/jfrTypes.hpp"
    31 #include "jfr/utilities/jfrTypes.hpp"
    32 #include "runtime/thread.hpp"
    32 #include "runtime/thread.hpp"
    33 
    33 
    34 template <typename Operation, typename NextOperation>
    34 class CompositeOperationOr {
       
    35  public:
       
    36   static bool evaluate(bool value) {
       
    37     return !value;
       
    38   }
       
    39 };
       
    40 
       
    41 class CompositeOperationAnd {
       
    42  public:
       
    43   static bool evaluate(bool value) {
       
    44     return value;
       
    45   }
       
    46 };
       
    47 
       
    48 template <typename Operation, typename NextOperation, typename TruthFunction = CompositeOperationAnd>
    35 class CompositeOperation {
    49 class CompositeOperation {
    36  private:
    50  private:
    37   Operation* _op;
    51   Operation* _op;
    38   NextOperation* _next;
    52   NextOperation* _next;
    39  public:
    53  public:
    40   CompositeOperation(Operation* op, NextOperation* next) : _op(op), _next(next) {
    54   CompositeOperation(Operation* op, NextOperation* next) : _op(op), _next(next) {
    41     assert(_op != NULL, "invariant");
    55     assert(_op != NULL, "invariant");
    42   }
    56   }
    43   typedef typename Operation::Type Type;
    57   typedef typename Operation::Type Type;
    44   bool process(Type* t = NULL) {
    58   bool process(Type* t) {
    45     return _next == NULL ? _op->process(t) : _op->process(t) && _next->process(t);
    59     const bool op_result = _op->process(t);
       
    60     return _next == NULL ? op_result : TruthFunction::evaluate(op_result) ? _next->process(t) : op_result;
    46   }
    61   }
    47   size_t processed() const {
    62   size_t elements() const {
    48     return _next == NULL ? _op->processed() : _op->processed() + _next->processed();
    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();
    49   }
    67   }
    50 };
    68 };
    51 
    69 
    52 template <typename T>
    70 template <typename T>
    53 class UnBufferedWriteToChunk {
    71 class UnBufferedWriteToChunk {
    54  private:
    72  private:
    55   JfrChunkWriter& _writer;
    73   JfrChunkWriter& _writer;
    56   size_t _processed;
    74   size_t _elements;
       
    75   size_t _size;
    57  public:
    76  public:
    58   typedef T Type;
    77   typedef T Type;
    59   UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _processed(0) {}
    78   UnBufferedWriteToChunk(JfrChunkWriter& writer) : _writer(writer), _elements(0), _size(0) {}
    60   bool write(Type* t, const u1* data, size_t size);
    79   bool write(Type* t, const u1* data, size_t size);
    61   size_t processed() { return _processed; }
    80   size_t elements() const { return _elements; }
       
    81   size_t size() const { return _size; }
    62 };
    82 };
    63 
    83 
    64 template <typename T>
    84 template <typename T>
    65 class DefaultDiscarder {
    85 class DefaultDiscarder {
    66  private:
    86  private:
    67   size_t _processed;
    87   size_t _elements;
       
    88   size_t _size;
    68  public:
    89  public:
    69   typedef T Type;
    90   typedef T Type;
    70   DefaultDiscarder() : _processed() {}
    91   DefaultDiscarder() : _elements(0), _size(0) {}
    71   bool discard(Type* t, const u1* data, size_t size);
    92   bool discard(Type* t, const u1* data, size_t size);
    72   size_t processed() const { return _processed; }
    93   size_t elements() const { return _elements; }
       
    94   size_t size() const { return _size; }
       
    95 };
       
    96 
       
    97 template <typename T, bool negation>
       
    98 class Retired {
       
    99  public:
       
   100   typedef T Type;
       
   101   bool process(Type* 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 T Type;
       
   111   bool process(Type* 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>(operation), _predicate(predicate) {}
       
   136   bool process(typename Operation::Type* t) {
       
   137     return _predicate.process(t) ? MutexedWriteOp<Operation>::process(t) : true;
       
   138   }
    73 };
   139 };
    74 
   140 
    75 template <typename Operation>
   141 template <typename Operation>
    76 class ConcurrentWriteOp {
   142 class ConcurrentWriteOp {
    77  private:
   143  private:
    78   Operation& _operation;
   144   Operation& _operation;
    79  public:
   145  public:
    80   typedef typename Operation::Type Type;
   146   typedef typename Operation::Type Type;
    81   ConcurrentWriteOp(Operation& operation) : _operation(operation) {}
   147   ConcurrentWriteOp(Operation& operation) : _operation(operation) {}
    82   bool process(Type* t);
   148   bool process(Type* t);
    83   size_t processed() const { return _operation.processed(); }
   149   size_t elements() const { return _operation.elements(); }
       
   150   size_t size() const { return _operation.size(); }
    84 };
   151 };
    85 
   152 
    86 template <typename Operation>
   153 template <typename Operation, typename Predicate>
    87 class ConcurrentWriteOpExcludeRetired : private ConcurrentWriteOp<Operation> {
   154 class PredicatedConcurrentWriteOp : public ConcurrentWriteOp<Operation> {
       
   155  private:
       
   156   Predicate& _predicate;
    88  public:
   157  public:
    89   typedef typename Operation::Type Type;
   158   PredicatedConcurrentWriteOp(Operation& operation, Predicate& predicate) :
    90   ConcurrentWriteOpExcludeRetired(Operation& operation) : ConcurrentWriteOp<Operation>(operation) {}
   159     ConcurrentWriteOp<Operation>(operation), _predicate(predicate) {}
    91   bool process(Type* t);
   160   bool process(typename Operation::Type* t) {
    92   size_t processed() const { return ConcurrentWriteOp<Operation>::processed(); }
   161     return _predicate.process(t) ? ConcurrentWriteOp<Operation>::process(t) : true;
    93 };
   162   }
    94 
       
    95 template <typename Operation>
       
    96 class MutexedWriteOp {
       
    97  private:
       
    98   Operation& _operation;
       
    99  public:
       
   100   typedef typename Operation::Type Type;
       
   101   MutexedWriteOp(Operation& operation) : _operation(operation) {}
       
   102   bool process(Type* t);
       
   103   size_t processed() const { return _operation.processed(); }
       
   104 };
   163 };
   105 
   164 
   106 template <typename Operation>
   165 template <typename Operation>
   107 class ExclusiveOp : private MutexedWriteOp<Operation> {
   166 class ExclusiveOp : private MutexedWriteOp<Operation> {
   108  public:
   167  public:
   124   jfr_operation_mode _mode;
   183   jfr_operation_mode _mode;
   125  public:
   184  public:
   126   typedef typename Operation::Type Type;
   185   typedef typename Operation::Type Type;
   127   DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {}
   186   DiscardOp(jfr_operation_mode mode = concurrent) : _operation(), _mode(mode) {}
   128   bool process(Type* t);
   187   bool process(Type* t);
   129   size_t processed() const { return _operation.processed(); }
   188   size_t elements() const { return _operation.elements(); }
       
   189   size_t size() const { return _operation.size(); }
   130 };
   190 };
   131 
   191 
   132 #endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP
   192 #endif // SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_HPP