src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.inline.hpp
branchJEP-349-branch
changeset 57360 5d043a159d5c
parent 53244 9807daeb47c4
child 58154 060d9d139109
--- a/src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.inline.hpp	Fri May 17 15:53:21 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/storage/jfrStorageUtils.inline.hpp	Fri May 17 16:02:27 2019 +0200
@@ -26,17 +26,20 @@
 #define SHARE_JFR_RECORDER_STORAGE_JFRSTORAGEUTILS_INLINE_HPP
 
 #include "jfr/recorder/storage/jfrStorageUtils.hpp"
+#include "runtime/thread.inline.hpp"
 
 template <typename T>
 inline bool UnBufferedWriteToChunk<T>::write(T* t, const u1* data, size_t size) {
   _writer.write_unbuffered(data, size);
-  _processed += size;
+  ++_elements;
+  _size += size;
   return true;
 }
 
 template <typename T>
 inline bool DefaultDiscarder<T>::discard(T* t, const u1* data, size_t size) {
-  _processed += size;
+  ++_elements;
+  _size += size;
   return true;
 }
 
@@ -44,7 +47,7 @@
 inline bool ConcurrentWriteOp<Operation>::process(typename Operation::Type* t) {
   const u1* const current_top = t->concurrent_top();
   const size_t unflushed_size = t->pos() - current_top;
-  if (unflushed_size == 0) {
+  if (unflushed_size == 0 || t->excluded()) {
     t->set_concurrent_top(current_top);
     return true;
   }
@@ -67,7 +70,7 @@
   assert(t != NULL, "invariant");
   const u1* const current_top = t->top();
   const size_t unflushed_size = t->pos() - current_top;
-  if (unflushed_size == 0) {
+  if (unflushed_size == 0 || t->excluded()) {
     return true;
   }
   const bool result = _operation.write(t, current_top, unflushed_size);
@@ -75,6 +78,28 @@
   return result;
 }
 
+template <typename Type>
+static void retired_sensitive_acquire(Type* t) {
+  assert(t != NULL, "invariant");
+  if (t->retired()) {
+    return;
+  }
+  Thread* const thread = Thread::current();
+  while (!t->try_acquire(thread)) {
+    if (t->retired()) {
+      return;
+    }
+  }
+}
+
+template <typename Operation>
+inline bool ExclusiveOp<Operation>::process(typename Operation::Type* t) {
+  retired_sensitive_acquire(t);
+  assert(t->acquired_by_self() || t->retired(), "invariant");
+  // User is required to ensure proper release of the acquisition
+  return MutexedWriteOp<Operation>::process(t);
+}
+
 template <typename Operation>
 inline bool DiscardOp<Operation>::process(typename Operation::Type* t) {
   assert(t != NULL, "invariant");