renames and restructuring of JfrCheckpointManager JEP-349-branch
authormgronlun
Tue, 17 Sep 2019 13:32:27 +0200
branchJEP-349-branch
changeset 58187 8994744e221c
parent 58185 ff328fdeca2d
child 58188 78b0d3d2f7b5
renames and restructuring of JfrCheckpointManager
src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp
src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.hpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.cpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.hpp
src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp
--- a/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp	Tue Sep 17 12:41:45 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp	Tue Sep 17 13:32:27 2019 +0200
@@ -364,7 +364,7 @@
   return discarder.elements();
 }
 
-// Optimization for write_types() and write_threads() is to write
+// Optimization for write_static_type_set() and write_threads() is to write
 // directly into the epoch transition mspace because we will immediately
 // serialize and reset this mspace post-write.
 static JfrBuffer* get_epoch_transition_buffer(JfrCheckpointMspace* mspace, Thread* t) {
@@ -377,12 +377,16 @@
   return buffer;
 }
 
-size_t JfrCheckpointManager::write_types() {
+bool JfrCheckpointManager::is_static_type_set_required() {
+  return JfrTypeManager::has_new_static_type();
+}
+
+size_t JfrCheckpointManager::write_static_type_set() {
   Thread* const t = Thread::current();
   ResourceMark rm(t);
   HandleMark hm(t);
   JfrCheckpointWriter writer(t, get_epoch_transition_buffer(_epoch_transition_mspace, t), STATICS);
-  JfrTypeManager::write_types(writer);
+  JfrTypeManager::write_static_types(writer);
   return writer.used_size();
 }
 
@@ -394,29 +398,17 @@
   JfrTypeManager::write_threads(writer);
   return writer.used_size();
 }
-size_t JfrCheckpointManager::write_constants() {
-  write_types();
+
+size_t JfrCheckpointManager::write_static_type_set_and_threads() {
+  write_static_type_set();
   write_threads();
   return write_epoch_transition_mspace();
 }
 
-class JfrNotifyClosure : public ThreadClosure {
- public:
-  void do_thread(Thread* t) {
-    assert(t != NULL, "invariant");
-    assert(t->is_Java_thread(), "invariant");
-    assert_locked_or_safepoint(Threads_lock);
-    JfrJavaEventWriter::notify((JavaThread*)t);
-  }
-};
-
-void JfrCheckpointManager::notify_threads() {
-  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
-  JfrNotifyClosure tc;
-  JfrJavaThreadIterator iter;
-  while (iter.has_next()) {
-    tc.do_thread(iter.next());
-  }
+void JfrCheckpointManager::shift_epoch() {
+  debug_only(const u1 current_epoch = JfrTraceIdEpoch::current();)
+    JfrTraceIdEpoch::shift_epoch();
+  assert(current_epoch != JfrTraceIdEpoch::current(), "invariant");
 }
 
 void JfrCheckpointManager::on_rotation() {
@@ -439,17 +431,13 @@
   return JfrTraceIdEpoch::has_changed_tag_state();
 }
 
-bool JfrCheckpointManager::is_constant_set_required() {
-  return JfrTypeManager::is_new_constant_registered();
-}
-
 size_t JfrCheckpointManager::flush_type_set() {
   const size_t elements = JfrTypeManager::flush_type_set();
   flush();
   return elements;
 }
 
-void JfrCheckpointManager::flush_constant_set() {
+void JfrCheckpointManager::flush_static_type_set() {
   flush();
 }
 
@@ -461,8 +449,21 @@
   JfrTypeManager::write_thread_checkpoint(t);
 }
 
-void JfrCheckpointManager::shift_epoch() {
-  debug_only(const u1 current_epoch = JfrTraceIdEpoch::current();)
-  JfrTraceIdEpoch::shift_epoch();
-  assert(current_epoch != JfrTraceIdEpoch::current(), "invariant");
+class JfrNotifyClosure : public ThreadClosure {
+ public:
+  void do_thread(Thread* t) {
+    assert(t != NULL, "invariant");
+    assert(t->is_Java_thread(), "invariant");
+    assert_locked_or_safepoint(Threads_lock);
+    JfrJavaEventWriter::notify((JavaThread*)t);
+  }
+};
+
+void JfrCheckpointManager::notify_threads() {
+  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
+  JfrNotifyClosure tc;
+  JfrJavaThreadIterator iter;
+  while (iter.has_next()) {
+    tc.do_thread(iter.next());
+  }
 }
--- a/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.hpp	Tue Sep 17 12:41:45 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.hpp	Tue Sep 17 13:32:27 2019 +0200
@@ -69,6 +69,8 @@
   DEBUG_ONLY(bool is_locked() const;)
 
   JfrCheckpointMspace* lookup(Buffer* old) const;
+  bool use_epoch_transition_mspace(const Thread* t) const;
+  size_t write_epoch_transition_mspace();
 
   static Buffer* lease_buffer(Thread* t, size_t size = 0);
   static Buffer* lease_buffer(Buffer* old, Thread* t, size_t size = 0);
@@ -76,20 +78,19 @@
 
   size_t clear();
   size_t write();
-  size_t write_constants();
   size_t flush();
-  size_t write_epoch_transition_mspace();
-  size_t write_types();
+
+  bool is_static_type_set_required();
+  size_t write_static_type_set();
   size_t write_threads();
-  size_t write_metadata_event();
+  size_t write_static_type_set_and_threads();
+  bool is_type_set_required();
   void write_type_set();
+  static void write_type_set_for_unloaded_classes();
+
   void shift_epoch();
   void synchronize_epoch();
-  bool use_epoch_transition_mspace(const Thread* t) const;
   void notify_threads();
-  void on_rotation();
-  bool is_type_set_required();
-  bool is_constant_set_required();
 
   JfrCheckpointManager(JfrChunkWriter& cw);
   ~JfrCheckpointManager();
@@ -97,16 +98,17 @@
   static JfrCheckpointManager& instance();
   static JfrCheckpointManager* create(JfrChunkWriter& cw);
   bool initialize();
+  void on_rotation();
   static void destroy();
 
  public:
-  void register_service_thread(const Thread* t);
   size_t flush_type_set();
-  void flush_constant_set();
-  static void write_type_set_for_unloaded_classes();
+  void flush_static_type_set();
   static void create_thread_blob(Thread* t);
   static void write_thread_checkpoint(Thread* t);
+  void register_service_thread(const Thread* t);
 
+  friend class Jfr;
   friend class JfrRecorder;
   friend class JfrRecorderService;
   friend class JfrCheckpointFlush;
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.cpp	Tue Sep 17 12:41:45 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.cpp	Tue Sep 17 13:32:27 2019 +0200
@@ -75,35 +75,106 @@
     return _id;
   }
 
-  void invoke(JfrCheckpointWriter& writer) const;
+  void on_rotation() const {
+    _serializer->on_rotation();
+  }
 
-  void on_rotation() const;
+  void invoke(JfrCheckpointWriter& writer) const {
+    if (_cache.valid()) {
+      writer.increment();
+      _cache->write(writer);
+      return;
+    }
+    const JfrCheckpointContext ctx = writer.context();
+    // serialize the type id before invoking callback
+    writer.write_type(_id);
+    const intptr_t start = writer.current_offset();
+    // invoke the serializer routine
+    _serializer->serialize(writer);
+    if (start == writer.current_offset()) {
+      // the serializer implementation did nothing, rewind to restore
+      writer.set_context(ctx);
+      return;
+    }
+    if (_permit_cache) {
+      _cache = writer.copy(&ctx);
+    }
+  }
 };
 
-void JfrSerializerRegistration::invoke(JfrCheckpointWriter& writer) const {
-  if (_cache.valid()) {
-    writer.increment();
-    _cache->write(writer);
+static void serialize_threads(JfrCheckpointWriter& writer) {
+  JfrThreadConstantSet thread_set;
+  writer.write_type(TYPE_THREAD);
+  thread_set.serialize(writer);
+}
+
+static void serialize_thread_groups(JfrCheckpointWriter& writer) {
+  JfrThreadGroupConstant thread_group_set;
+  writer.write_type(TYPE_THREADGROUP);
+  thread_group_set.serialize(writer);
+}
+
+void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) {
+  serialize_threads(writer);
+  serialize_thread_groups(writer);
+}
+
+void JfrTypeManager::create_thread_blob(Thread* t) {
+  assert(t != NULL, "invariant");
+  ResourceMark rm(t);
+  HandleMark hm(t);
+  JfrThreadConstant type_thread(t);
+  JfrCheckpointWriter writer(t, true, THREADS);
+  writer.write_type(TYPE_THREAD);
+  type_thread.serialize(writer);
+  // create and install a checkpoint blob
+  t->jfr_thread_local()->set_thread_blob(writer.move());
+  assert(t->jfr_thread_local()->has_thread_blob(), "invariant");
+}
+
+void JfrTypeManager::write_thread_checkpoint(Thread* t) {
+  assert(t != NULL, "invariant");
+  ResourceMark rm(t);
+  HandleMark hm(t);
+  JfrThreadConstant type_thread(t);
+  JfrCheckpointWriter writer(t, true, THREADS);
+  writer.write_type(TYPE_THREAD);
+  type_thread.serialize(writer);
+}
+
+size_t JfrTypeManager::flush_type_set() {
+  JfrCheckpointWriter writer;
+  FlushTypeSet flush;
+  flush.serialize(writer);
+  return flush.elements();
+}
+
+void JfrTypeManager::write_type_set() {
+  if (!LeakProfiler::is_running()) {
+    JfrCheckpointWriter writer;
+    TypeSet set;
+    set.serialize(writer);
     return;
   }
-  const JfrCheckpointContext ctx = writer.context();
-  // serialize the type id before invoking callback
-  writer.write_type(_id);
-  const intptr_t start = writer.current_offset();
-  // invoke the serializer routine
-  _serializer->serialize(writer);
-  if (start == writer.current_offset() ) {
-    // the serializer implementation did nothing, rewind to restore
-    writer.set_context(ctx);
-    return;
-  }
-  if (_permit_cache) {
-    _cache = writer.copy(&ctx);
-  }
+  JfrCheckpointWriter leakp_writer;
+  JfrCheckpointWriter writer;
+  TypeSet set(&leakp_writer);
+  set.serialize(writer);
+  ObjectSampleCheckpoint::on_type_set(leakp_writer);
 }
 
-void JfrSerializerRegistration::on_rotation() const {
-  _serializer->on_rotation();
+void JfrTypeManager::write_type_set_for_unloaded_classes() {
+  JfrCheckpointWriter writer;
+  const JfrCheckpointContext ctx = writer.context();
+  ClassUnloadTypeSet class_unload_set;
+  class_unload_set.serialize(writer);
+  if (LeakProfiler::is_running()) {
+    ObjectSampleCheckpoint::on_type_set_unload(writer);
+  }
+  if (!Jfr::is_recording()) {
+    // discard anything written
+    writer.set_context(ctx);
+  }
 }
 
 class SerializerRegistrationGuard : public StackObj {
@@ -135,34 +206,6 @@
   }
 }
 
-static bool new_registration = false;
-
-void JfrTypeManager::write_types(JfrCheckpointWriter& writer) {
-  SerializerRegistrationGuard guard;
-  const Iterator iter(types);
-  while (iter.has_next()) {
-    iter.next()->invoke(writer);
-  }
-  new_registration = false;
-}
-
-static void serialize_threads(JfrCheckpointWriter& writer) {
-  JfrThreadConstantSet thread_set;
-  writer.write_type(TYPE_THREAD);
-  thread_set.serialize(writer);
-}
-
-static void serialize_thread_groups(JfrCheckpointWriter& writer) {
-  JfrThreadGroupConstant thread_group_set;
-  writer.write_type(TYPE_THREADGROUP);
-  thread_group_set.serialize(writer);
-}
-
-void JfrTypeManager::write_threads(JfrCheckpointWriter& writer) {
-  serialize_threads(writer);
-  serialize_thread_groups(writer);
-}
-
 void JfrTypeManager::on_rotation() {
   const Iterator iter(types);
   while (iter.has_next()) {
@@ -170,64 +213,6 @@
   }
 }
 
-void JfrTypeManager::write_type_set() {
-  if (!LeakProfiler::is_running()) {
-    JfrCheckpointWriter writer;
-    TypeSet set;
-    set.serialize(writer);
-    return;
-  }
-  JfrCheckpointWriter leakp_writer;
-  JfrCheckpointWriter writer;
-  TypeSet set(&leakp_writer);
-  set.serialize(writer);
-  ObjectSampleCheckpoint::on_type_set(leakp_writer);
-}
-
-void JfrTypeManager::write_type_set_for_unloaded_classes() {
-  JfrCheckpointWriter writer;
-  const JfrCheckpointContext ctx = writer.context();
-  ClassUnloadTypeSet class_unload_set;
-  class_unload_set.serialize(writer);
-  if (LeakProfiler::is_running()) {
-    ObjectSampleCheckpoint::on_type_set_unload(writer);
-  }
-  if (!Jfr::is_recording()) {
-    // discard anything written
-    writer.set_context(ctx);
-  }
-}
-
-size_t JfrTypeManager::flush_type_set() {
-  JfrCheckpointWriter writer;
-  FlushTypeSet flush;
-  flush.serialize(writer);
-  return flush.elements();
-}
-
-void JfrTypeManager::create_thread_blob(Thread* t) {
-  assert(t != NULL, "invariant");
-  ResourceMark rm(t);
-  HandleMark hm(t);
-  JfrThreadConstant type_thread(t);
-  JfrCheckpointWriter writer(t, true, THREADS);
-  writer.write_type(TYPE_THREAD);
-  type_thread.serialize(writer);
-  // create and install a checkpoint blob
-  t->jfr_thread_local()->set_thread_blob(writer.move());
-  assert(t->jfr_thread_local()->has_thread_blob(), "invariant");
-}
-
-void JfrTypeManager::write_thread_checkpoint(Thread* t) {
-  assert(t != NULL, "invariant");
-  ResourceMark rm(t);
-  HandleMark hm(t);
-  JfrThreadConstant type_thread(t);
-  JfrCheckpointWriter writer(t, true, THREADS);
-  writer.write_type(TYPE_THREAD);
-  type_thread.serialize(writer);
-}
-
 #ifdef ASSERT
 static void assert_not_registered_twice(JfrTypeId id, List& list) {
   const Iterator iter(list);
@@ -237,14 +222,15 @@
 }
 #endif
 
-static bool register_type(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) {
+static bool new_registration = false;
+
+static bool register_static_type(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) {
   assert(serializer != NULL, "invariant");
   JfrSerializerRegistration* const registration = new JfrSerializerRegistration(id, permit_cache, serializer);
   if (registration == NULL) {
     delete serializer;
     return false;
   }
-
   assert(!types.in_list(registration), "invariant");
   DEBUG_ONLY(assert_not_registered_twice(id, types);)
   if (Jfr::is_recording()) {
@@ -258,30 +244,30 @@
 
 bool JfrTypeManager::initialize() {
   SerializerRegistrationGuard guard;
-  register_type(TYPE_FLAGVALUEORIGIN, true, new FlagValueOriginConstant());
-  register_type(TYPE_INFLATECAUSE, true, new MonitorInflateCauseConstant());
-  register_type(TYPE_GCCAUSE, true, new GCCauseConstant());
-  register_type(TYPE_GCNAME, true, new GCNameConstant());
-  register_type(TYPE_GCWHEN, true, new GCWhenConstant());
-  register_type(TYPE_GCTHRESHOLDUPDATER, true, new GCThresholdUpdaterConstant());
-  register_type(TYPE_METADATATYPE, true, new MetadataTypeConstant());
-  register_type(TYPE_METASPACEOBJECTTYPE, true, new MetaspaceObjectTypeConstant());
-  register_type(TYPE_REFERENCETYPE, true, new ReferenceTypeConstant());
-  register_type(TYPE_NARROWOOPMODE, true, new NarrowOopModeConstant());
-  register_type(TYPE_COMPILERPHASETYPE, true, new CompilerPhaseTypeConstant());
-  register_type(TYPE_CODEBLOBTYPE, true, new CodeBlobTypeConstant());
-  register_type(TYPE_VMOPERATIONTYPE, true, new VMOperationTypeConstant());
-  register_type(TYPE_THREADSTATE, true, new ThreadStateConstant());
+  register_static_type(TYPE_FLAGVALUEORIGIN, true, new FlagValueOriginConstant());
+  register_static_type(TYPE_INFLATECAUSE, true, new MonitorInflateCauseConstant());
+  register_static_type(TYPE_GCCAUSE, true, new GCCauseConstant());
+  register_static_type(TYPE_GCNAME, true, new GCNameConstant());
+  register_static_type(TYPE_GCWHEN, true, new GCWhenConstant());
+  register_static_type(TYPE_GCTHRESHOLDUPDATER, true, new GCThresholdUpdaterConstant());
+  register_static_type(TYPE_METADATATYPE, true, new MetadataTypeConstant());
+  register_static_type(TYPE_METASPACEOBJECTTYPE, true, new MetaspaceObjectTypeConstant());
+  register_static_type(TYPE_REFERENCETYPE, true, new ReferenceTypeConstant());
+  register_static_type(TYPE_NARROWOOPMODE, true, new NarrowOopModeConstant());
+  register_static_type(TYPE_COMPILERPHASETYPE, true, new CompilerPhaseTypeConstant());
+  register_static_type(TYPE_CODEBLOBTYPE, true, new CodeBlobTypeConstant());
+  register_static_type(TYPE_VMOPERATIONTYPE, true, new VMOperationTypeConstant());
+  register_static_type(TYPE_THREADSTATE, true, new ThreadStateConstant());
   return true;
 }
 
 // implementation for the static registration function exposed in the JfrSerializer api
 bool JfrSerializer::register_serializer(JfrTypeId id, bool permit_cache, JfrSerializer* serializer) {
   SerializerRegistrationGuard guard;
-  return register_type(id, permit_cache, serializer);
+  return register_static_type(id, permit_cache, serializer);
 }
 
-bool JfrTypeManager::is_new_constant_registered() {
+bool JfrTypeManager::has_new_static_type() {
   if (new_registration) {
     SerializerRegistrationGuard guard;
     new_registration = false;
@@ -289,3 +275,12 @@
   }
   return false;
 }
+
+void JfrTypeManager::write_static_types(JfrCheckpointWriter& writer) {
+  SerializerRegistrationGuard guard;
+  const Iterator iter(types);
+  while (iter.has_next()) {
+    iter.next()->invoke(writer);
+  }
+  new_registration = false;
+}
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.hpp	Tue Sep 17 12:41:45 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeManager.hpp	Tue Sep 17 13:32:27 2019 +0200
@@ -33,15 +33,15 @@
  public:
   static bool initialize();
   static void clear();
-  static bool is_new_constant_registered();
-  static void write_types(JfrCheckpointWriter& writer);
+  static void on_rotation();
   static void write_threads(JfrCheckpointWriter& writer);
-  static void on_rotation();
+  static void create_thread_blob(Thread* t);
+  static void write_thread_checkpoint(Thread* t);
+  static bool has_new_static_type();
+  static void write_static_types(JfrCheckpointWriter& writer);
+  static size_t flush_type_set();
   static void write_type_set();
   static void write_type_set_for_unloaded_classes();
-  static size_t flush_type_set();
-  static void create_thread_blob(Thread* t);
-  static void write_thread_checkpoint(Thread* t);
 };
 
 #endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_JFRTYPEMANAGER_HPP
--- a/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp	Tue Sep 17 12:41:45 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp	Tue Sep 17 13:32:27 2019 +0200
@@ -488,7 +488,7 @@
   const bool valid_chunk = _repository.open_chunk(vm_error);
   _storage.control().set_to_disk(valid_chunk);
   if (valid_chunk) {
-    _checkpoint_manager.write_constants();
+    _checkpoint_manager.write_static_type_set_and_threads();
   }
 }
 
@@ -664,9 +664,9 @@
   }
   if (_checkpoint_manager.is_type_set_required()) {
     total_elements += flush_typeset(_checkpoint_manager, _chunkwriter);
-  } else if (_checkpoint_manager.is_constant_set_required()) {
+  } else if (_checkpoint_manager.is_static_type_set_required()) {
     // don't tally this, it is only in order to flush the waiting constants
-    _checkpoint_manager.flush_constant_set();
+    _checkpoint_manager.flush_static_type_set();
   }
   return total_elements;
 }