src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.inline.hpp
branchJEP-349-branch
changeset 57360 5d043a159d5c
parent 53244 9807daeb47c4
child 58154 060d9d139109
equal deleted inserted replaced
57359:4cab5edc2950 57360:5d043a159d5c
    24 
    24 
    25 #ifndef SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
    25 #ifndef SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
    26 #define SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
    26 #define SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
    27 
    27 
    28 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
    28 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
       
    29 #include "runtime/thread.inline.hpp"
    29 
    30 
    30 template <typename T>
    31 template <typename T>
    31 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
    32 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
    32   _writer.write_unbuffered(data, size);
    33   _writer.write_unbuffered(data, size);
    33   _processed += size;
    34   ++_elements;
       
    35   _size += size;
    34   return true;
    36   return true;
    35 }
    37 }
    36 
    38 
    37 template <typename T>
    39 template <typename T>
    38 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
    40 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
    39   _processed += size;
    41   ++_elements;
       
    42   _size += size;
    40   return true;
    43   return true;
    41 }
    44 }
    42 
    45 
    43 template <typename Operation>
    46 template <typename Operation>
    44 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
    47 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
    45   const u1* const current_top = t->concurrent_top();
    48   const u1* const current_top = t->concurrent_top();
    46   const size_t unflushed_size = t->pos() - current_top;
    49   const size_t unflushed_size = t->pos() - current_top;
    47   if (unflushed_size == 0) {
    50   if (unflushed_size == 0 || t->excluded()) {
    48     t->set_concurrent_top(current_top);
    51     t->set_concurrent_top(current_top);
    49     return true;
    52     return true;
    50   }
    53   }
    51   const bool result = _operation.write(t, current_top, unflushed_size);
    54   const bool result = _operation.write(t, current_top, unflushed_size);
    52   t->set_concurrent_top(current_top + unflushed_size);
    55   t->set_concurrent_top(current_top + unflushed_size);
    65 template <typename Operation>
    68 template <typename Operation>
    66 inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) {
    69 inline bool MutexedWriteOp<Operation>::process(typename Operation::Type* t) {
    67   assert(t != NULL, "invariant");
    70   assert(t != NULL, "invariant");
    68   const u1* const current_top = t->top();
    71   const u1* const current_top = t->top();
    69   const size_t unflushed_size = t->pos() - current_top;
    72   const size_t unflushed_size = t->pos() - current_top;
    70   if (unflushed_size == 0) {
    73   if (unflushed_size == 0 || t->excluded()) {
    71     return true;
    74     return true;
    72   }
    75   }
    73   const bool result = _operation.write(t, current_top, unflushed_size);
    76   const bool result = _operation.write(t, current_top, unflushed_size);
    74   t->set_top(current_top + unflushed_size);
    77   t->set_top(current_top + unflushed_size);
    75   return result;
    78   return result;
       
    79 }
       
    80 
       
    81 template <typename Type>
       
    82 static void retired_sensitive_acquire(Type* t) {
       
    83   assert(t != NULL, "invariant");
       
    84   if (t->retired()) {
       
    85     return;
       
    86   }
       
    87   Thread* const thread = Thread::current();
       
    88   while (!t->try_acquire(thread)) {
       
    89     if (t->retired()) {
       
    90       return;
       
    91     }
       
    92   }
       
    93 }
       
    94 
       
    95 template <typename Operation>
       
    96 inline bool ExclusiveOp<Operation>::process(typename Operation::Type* t) {
       
    97   retired_sensitive_acquire(t);
       
    98   assert(t->acquired_by_self() || t->retired(), "invariant");
       
    99   // User is required to ensure proper release of the acquisition
       
   100   return MutexedWriteOp<Operation>::process(t);
    76 }
   101 }
    77 
   102 
    78 template <typename Operation>
   103 template <typename Operation>
    79 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
   104 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
    80   assert(t != NULL, "invariant");
   105   assert(t != NULL, "invariant");