JavaThread name JEP-349-branch
authormgronlun
Mon, 09 Sep 2019 13:26:35 +0200
branchJEP-349-branch
changeset 58049 10ecdb5d3574
parent 58020 f082177c5023
child 58068 22dab580786c
JavaThread name
src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp
src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp
src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.cpp
src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.hpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.hpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.cpp
src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.hpp
src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdMacros.hpp
src/hotspot/share/runtime/thread.hpp
--- a/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/leakprofiler/checkpoint/objectSampleCheckpoint.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -26,6 +26,7 @@
 #define SHARE_JFR_LEAKPROFILER_CHECKPOINT_OBJECTSAMPLECHECKPOINT_HPP
 
 #include "memory/allocation.hpp"
+#include "jfr/utilities/jfrTypes.hpp"
 
 class EdgeStore;
 class JavaThread;
--- a/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -91,18 +91,22 @@
 static const size_t checkpoint_buffer_cache_count = 2;
 static const size_t checkpoint_buffer_size = 512 * K;
 
-static JfrCheckpointMspace* allocate_mspace(size_t size, size_t limit, size_t cache_count, JfrCheckpointManager* mgr) {
-  return create_mspace<JfrCheckpointMspace, JfrCheckpointManager>(size, limit, cache_count, mgr);
+static JfrCheckpointMspace* create_mspace(size_t buffer_size, size_t limit, size_t cache_count, JfrCheckpointManager* system) {
+  JfrCheckpointMspace* mspace = new JfrCheckpointMspace(buffer_size, limit, cache_count, system);
+  if (mspace != NULL) {
+    mspace->initialize();
+  }
+  return mspace;
 }
 
 bool JfrCheckpointManager::initialize() {
   assert(_free_list_mspace == NULL, "invariant");
-  _free_list_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this);
+  _free_list_mspace = create_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this);
   if (_free_list_mspace == NULL) {
     return false;
   }
   assert(_epoch_transition_mspace == NULL, "invariant");
-  _epoch_transition_mspace = allocate_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this);
+  _epoch_transition_mspace = create_mspace(checkpoint_buffer_size, unlimited_mspace_size, checkpoint_buffer_cache_count, this);
   if (_epoch_transition_mspace == NULL) {
     return false;
   }
@@ -335,7 +339,6 @@
   _checkpoint_epoch_state = JfrTraceIdEpoch::epoch();
 }
 
-
 size_t JfrCheckpointManager::write() {
   const size_t processed = write_mspace<MutexedWriteOp, CompositeOperation>(_free_list_mspace, _chunkwriter);
   synchronize_epoch();
--- a/src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -29,21 +29,11 @@
 #include "oops/klass.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/typeArrayOop.inline.hpp"
-#include "runtime/semaphore.hpp"
 #include "runtime/thread.inline.hpp"
 
 static jbyteArray _metadata_blob = NULL;
 static u8 metadata_id = 0;
 static u8 last_written_metadata_id = 0;
-static Semaphore metadata_mutex_semaphore(1);
-
-void JfrMetadataEvent::lock() {
-  metadata_mutex_semaphore.wait();
-}
-
-void JfrMetadataEvent::unlock() {
-  metadata_mutex_semaphore.signal();
-}
 
 static void write_metadata_blob(JfrChunkWriter& chunkwriter, jbyteArray metadata_blob) {
   if (metadata_blob != NULL) {
--- a/src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/jfrMetadataEvent.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -37,8 +37,6 @@
 //
 class JfrMetadataEvent : AllStatic {
  public:
-  static void lock();
-  static void unlock();
   static void write(JfrChunkWriter& writer);
   static void update(jbyteArray metadata);
 };
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -23,6 +23,7 @@
 */
 
 #include "precompiled.hpp"
+#include "classfile/javaClasses.inline.hpp"
 #include "jfr/recorder/checkpoint/types/jfrThreadState.hpp"
 #include "jfr/recorder/checkpoint/jfrCheckpointWriter.hpp"
 #include "jfr/support/jfrThreadLocal.hpp"
@@ -83,16 +84,6 @@
   }
 }
 
-const char* JfrThreadName::name(const Thread* t) {
-  assert(t != NULL, "invariant");
-  if (!t->is_Java_thread()) {
-    return t->name();
-  }
-  assert(t->is_Java_thread(), "invariant");
-  const JavaThread* const jt = (JavaThread*)t;
-  return jt->get_thread_name_string();
-}
-
 traceid JfrThreadId::id(const Thread* t) {
   assert(t != NULL, "invariant");
   if (!t->is_Java_thread()) {
@@ -113,3 +104,27 @@
   assert(t != NULL, "invariant");
   return t->jfr_thread_local()->thread_id();
 }
+
+// caller needs ResourceMark
+const char* get_java_thread_name(const Thread* t) {
+  assert(t != NULL, "invariant");
+  assert(t->is_Java_thread(), "invariant");
+  const JavaThread* const jt = ((JavaThread*)t);
+  const char* name_str = "<no-name - thread name unresolved>";
+  const oop thread_obj = jt->threadObj();
+  if (thread_obj != NULL) {
+    const oop name = java_lang_Thread::name(thread_obj);
+    if (name != NULL) {
+      name_str = java_lang_String::as_utf8_string(name);
+    }
+  } else if (jt->is_attaching_via_jni()) { // workaround for 6412693 - see 6404306
+    name_str = "<no-name - thread is attaching>";
+  }
+  assert(name_str != NULL, "unexpected NULL thread name");
+  return name_str;
+}
+
+const char* JfrThreadName::name(const Thread* t) {
+  assert(t != NULL, "invariant");
+  return t->is_Java_thread() ? get_java_thread_name(t) : t->name();
+}
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrThreadState.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -35,17 +35,17 @@
   static void serialize(JfrCheckpointWriter& writer);
 };
 
+class JfrThreadId : public AllStatic {
+public:
+  static traceid id(const Thread* t);
+  static traceid os_id(const Thread* t);
+  static traceid jfr_id(const Thread* t);
+};
+
 class JfrThreadName : public AllStatic {
  public:
   // Requires a ResourceMark for get_thread_name/as_utf8
   static const char* name(const Thread* t);
 };
 
-class JfrThreadId : public AllStatic {
- public:
-  static traceid id(const Thread* t);
-  static traceid os_id(const Thread* t);
-  static traceid jfr_id(const Thread* t);
-};
-
 #endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_JFRTHREADSTATE_HPP
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -93,13 +93,13 @@
   ++_count;
   _writer.write_key(JfrThreadId::jfr_id(t));
   const char* const name = JfrThreadName::name(t);
+  assert(name != NULL, "invariant");
   _writer.write(name);
   _writer.write<traceid>(JfrThreadId::os_id(t));
   if (t->is_Java_thread()) {
     _writer.write(name);
     _writer.write(JfrThreadId::id(t));
-    JavaThread* const jt = (JavaThread*)t;
-    _writer.write(JfrThreadGroup::thread_group_id(jt, _curthread));
+    _writer.write(JfrThreadGroup::thread_group_id((JavaThread*)t, _curthread));
     return;
   }
   _writer.write((const char*)NULL); // java name
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSet.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -91,6 +91,10 @@
   return symbol != NULL ? create_symbol_id(_artifacts->mark(symbol, leakp)) : 0;
 }
 
+static traceid get_bootstrap_name(bool leakp) {
+  return create_symbol_id(_artifacts->bootstrap_name(leakp));
+}
+
 template <typename T>
 static traceid artifact_id(const T* ptr) {
   assert(ptr != NULL, "invariant");
@@ -492,7 +496,7 @@
     // (primordial) boot class loader
     writer->write(artifact_id(cld)); // class loader instance id
     writer->write((traceid)0);  // class loader type id (absence of)
-    writer->write(create_symbol_id(1)); // 1 maps to synthetic name -> "bootstrap"
+    writer->write(get_bootstrap_name(leakp)); // maps to synthetic name -> "bootstrap"
   } else {
     writer->write(artifact_id(cld)); // class loader instance id
     writer->write(artifact_id(class_loader_klass)); // class loader type id
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.cpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.cpp	Mon Sep 09 13:26:35 2019 +0200
@@ -28,21 +28,28 @@
 #include "oops/oop.inline.hpp"
 #include "oops/symbol.hpp"
 
+static JfrSymbolId::CStringEntry* bootstrap = NULL;
+
 JfrSymbolId::JfrSymbolId() :
   _sym_table(new SymbolTable(this)),
   _cstring_table(new CStringTable(this)),
   _sym_list(NULL),
   _cstring_list(NULL),
-  _symbol_id_counter(0),
+  _symbol_id_counter(1),
   _class_unload(false) {
   assert(_sym_table != NULL, "invariant");
   assert(_cstring_table != NULL, "invariant");
+  bootstrap = new CStringEntry(0, (const char*)&BOOTSTRAP_LOADER_NAME);
+  assert(bootstrap != NULL, "invariant");
+  bootstrap->set_id(1);
+  _cstring_list = bootstrap;
 }
 
 JfrSymbolId::~JfrSymbolId() {
   clear();
   delete _sym_table;
   delete _cstring_table;
+  delete bootstrap;
 }
 
 void JfrSymbolId::clear() {
@@ -60,7 +67,11 @@
 
   _sym_list = NULL;
   _cstring_list = NULL;
-  _symbol_id_counter = 0;
+  _symbol_id_counter = 1;
+
+  assert(bootstrap != NULL, "invariant");
+  bootstrap->reset();
+  _cstring_list = bootstrap;
 }
 
 void JfrSymbolId::set_class_unload(bool class_unload) {
@@ -104,9 +115,15 @@
 
 void JfrSymbolId::unlink(const CStringEntry* entry) {
   assert(entry != NULL, "invariant");
-  if (entry->id() != 1) {
-    JfrCHeapObj::free(const_cast<char*>(entry->literal()), strlen(entry->literal() + 1));
+  JfrCHeapObj::free(const_cast<char*>(entry->literal()), strlen(entry->literal() + 1));
+}
+
+traceid JfrSymbolId::bootstrap_name(bool leakp) {
+  assert(bootstrap != NULL, "invariant");
+  if (leakp) {
+    bootstrap->set_leakp();
   }
+  return 1;
 }
 
 traceid JfrSymbolId::mark(const Symbol* symbol, bool leakp) {
@@ -232,12 +249,6 @@
   return symbol_id;
 }
 
-static void preload_bootstrap_loader_name(JfrSymbolId* symbol_id) {
-  assert(symbol_id != NULL, "invariant");
-  assert(!symbol_id->has_entries(), "invariant");
-  symbol_id->mark(1, (const char*)&BOOTSTRAP_LOADER_NAME, false); // pre-load "bootstrap" into id 1
-}
-
 static void reset_symbol_caches() {
   last_anonymous_hash = 0;
   last_symbol_hash = 0;
@@ -247,7 +258,6 @@
 JfrArtifactSet::JfrArtifactSet(bool class_unload) : _symbol_id(new JfrSymbolId()),
                                                      _klass_list(NULL),
                                                      _total_count(0) {
-  preload_bootstrap_loader_name(_symbol_id);
   initialize(class_unload);
   assert(_klass_list != NULL, "invariant");
 }
@@ -270,10 +280,13 @@
 void JfrArtifactSet::clear() {
   reset_symbol_caches();
   _symbol_id->clear();
-  preload_bootstrap_loader_name(_symbol_id);
   // _klass_list will be cleared by a ResourceMark
 }
 
+traceid JfrArtifactSet::bootstrap_name(bool leakp) {
+  return _symbol_id->bootstrap_name(leakp);
+}
+
 traceid JfrArtifactSet::mark_unsafe_anonymous_klass_name(const Klass* klass, bool leakp) {
   assert(klass->is_instance_klass(), "invariant");
   return _symbol_id->mark_unsafe_anonymous_klass_name((const InstanceKlass*)klass, leakp);
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/jfrTypeSetUtils.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -191,6 +191,9 @@
   ListEntry(uintptr_t hash, const T& data) : JfrHashtableEntry<T, IdType>(hash, data),
     _list_next(NULL), _serialized(false), _unloading(false), _leakp(false) {}
   const ListEntry<T, IdType>* list_next() const { return _list_next; }
+  void reset() const {
+    _list_next = NULL; _serialized = false; _unloading = false; _leakp = false;
+  }
   void set_list_next(const ListEntry<T, IdType>* next) const { _list_next = next; }
   bool is_serialized() const { return _serialized; }
   void set_serialized() const { _serialized = true; }
@@ -255,6 +258,7 @@
   traceid mark(const Klass* k, bool leakp);
   traceid mark(const Symbol* symbol, bool leakp);
   traceid mark(uintptr_t hash, const char* str, bool leakp);
+  traceid bootstrap_name(bool leakp);
 
   template <typename Functor>
   void iterate_symbols(Functor& functor) {
@@ -305,6 +309,7 @@
   traceid mark(const Symbol* symbol, bool leakp);
   traceid mark(uintptr_t hash, const char* const str, bool leakp);
   traceid mark_unsafe_anonymous_klass_name(const Klass* klass, bool leakp);
+  traceid bootstrap_name(bool leakp);
 
   const JfrSymbolId::SymbolEntry* map_symbol(const Symbol* symbol) const;
   const JfrSymbolId::SymbolEntry* map_symbol(uintptr_t hash) const;
--- a/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdMacros.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdMacros.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -83,7 +83,7 @@
 #define METHOD_FLAG_TAG(method, bits)             (set_bits(bits, (method)->trace_flags_addr()))
 #define METHOD_META_TAG(method, bits)             (set_meta_bits(bits, (method)->trace_meta_addr()))
 #define METHOD_FLAG_CLEAR(method, bits)           (clear_bits_cas(bits, (method)->trace_flags_addr()))
-#define METHOD_META_CLEAR(method, bits)           (clear_meta_bits(bits, (method)->trace_meta_addr()))
+#define METHOD_META_CLEAR(method, bits)           (set_meta_mask(bits, (method)->trace_meta_addr()))
 
 // predicates
 #define USED_THIS_EPOCH(ptr)                      (TRACE_ID_PREDICATE(ptr, (TRANSIENT_BIT | IN_USE_THIS_EPOCH_BIT)))
@@ -120,6 +120,7 @@
 #define EVENT_KLASS_MASK(kls)                     (TRACE_ID_RAW(kls) & EVENT_BITS)
 
 // meta
+#define META_MASK                                 (~(SERIALIZED_META_BIT | TRANSIENT_META_BIT | LEAKP_META_BIT))
 #define SET_LEAKP(ptr)                            (TRACE_ID_META_TAG(ptr, LEAKP_META_BIT))
 #define IS_LEAKP(ptr)                             (TRACE_ID_PREDICATE(ptr, LEAKP_BIT))
 #define SET_TRANSIENT(ptr)                        (TRACE_ID_META_TAG(ptr, TRANSIENT_META_BIT))
@@ -128,13 +129,13 @@
 #define SHOULD_TAG(ptr)                           (NOT_USED_THIS_EPOCH(ptr))
 #define SHOULD_TAG_KLASS_METHOD(ptr)              (METHOD_NOT_USED_THIS_EPOCH(ptr))
 #define SET_SERIALIZED(ptr)                       (TRACE_ID_META_TAG(ptr, SERIALIZED_META_BIT))
-#define CLEAR_SERIALIZED(ptr)                     (TRACE_ID_META_CLEAR(ptr, (~(SERIALIZED_META_BIT | TRANSIENT_META_BIT | LEAKP_META_BIT))))
+#define CLEAR_SERIALIZED(ptr)                     (TRACE_ID_META_CLEAR(ptr, META_MASK))
 #define IS_METHOD_SERIALIZED(method)              (METHOD_FLAG_PREDICATE(method, SERIALIZED_BIT))
 #define IS_METHOD_LEAKP_USED(method)              (METHOD_FLAG_PREDICATE(method, LEAKP_BIT))
 #define METHOD_NOT_SERIALIZED(method)             (!(IS_METHOD_SERIALIZED(method)))
 #define SET_METHOD_LEAKP(method)                  (METHOD_META_TAG(method, LEAKP_META_BIT))
 #define SET_METHOD_SERIALIZED(method)             (METHOD_META_TAG(method, SERIALIZED_META_BIT))
-#define CLEAR_METHOD_SERIALIZED(method)           (METHOD_META_CLEAR(method, (SERIALIZED_META_BIT | LEAKP_META_BIT)))
+#define CLEAR_METHOD_SERIALIZED(method)           (METHOD_META_CLEAR(method, META_MASK))
 #define CLEAR_LEAKP(ptr)                          (TRACE_ID_META_CLEAR(ptr, (~(LEAKP_META_BIT))))
 
 #endif // SHARE_JFR_RECORDER_CHECKPOINT_TYPES_TRACEID_JFRTRACEIDMACROS_HPP
--- a/src/hotspot/share/runtime/thread.hpp	Thu Sep 05 16:46:50 2019 +0200
+++ b/src/hotspot/share/runtime/thread.hpp	Mon Sep 09 13:26:35 2019 +0200
@@ -979,7 +979,6 @@
 typedef void (*ThreadFunction)(JavaThread*, TRAPS);
 
 class JavaThread: public Thread {
-  friend class JfrThreadName;
   friend class VMStructs;
   friend class JVMCIVMStructs;
   friend class WhiteBox;