< prev index next >

src/hotspot/share/jfr/recorder/checkpoint/types/jfrType.cpp

Print this page
@@ -86,27 +86,31 @@
    }
  
    void do_thread(Thread* t);
  };
  
+ // only static thread ids, VirtualThread ids are handled dynamically
  void JfrCheckpointThreadClosure::do_thread(Thread* t) {
    assert(t != NULL, "invariant");
    ++_count;
-   _writer.write_key(JfrThreadId::jfr_id(t));
+   const traceid tid = JfrThreadId::jfr_id(t);
+   assert(tid != 0, "invariant");
+   _writer.write_key(tid);
    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()) {
+   if (!t->is_Java_thread()) {
+     _writer.write((const char*)NULL); // java name
+     _writer.write((traceid)0); // java thread id
+     _writer.write((traceid)0); // java thread group
+   } else {
      _writer.write(name);
-     _writer.write(JfrThreadId::id(t));
+     _writer.write(tid);
      _writer.write(JfrThreadGroup::thread_group_id(JavaThread::cast(t), _curthread));
-     return;
    }
-   _writer.write((const char*)NULL); // java name
-   _writer.write((traceid)0); // java thread id
-   _writer.write((traceid)0); // java thread group
+   _writer.write<bool>(false); // isVirtual
  }
  
  void JfrThreadConstantSet::serialize(JfrCheckpointWriter& writer) {
    JfrCheckpointThreadClosure tc(writer);
    JfrJavaThreadIterator javathreads(false); // include not yet live threads (_thread_new)

@@ -265,28 +269,34 @@
    JfrThreadState::serialize(writer);
  }
  
  void JfrThreadConstant::serialize(JfrCheckpointWriter& writer) {
    assert(_thread != NULL, "invariant");
-   assert(_thread == Thread::current(), "invariant");
    writer.write_count(1);
-   writer.write_key(JfrThreadId::jfr_id(_thread));
-   const char* const name = JfrThreadName::name(_thread);
+   writer.write_key(JfrThreadId::jfr_id(_thread, _tid));
+   const char* const name = JfrThreadName::name(_thread, _vthread);
    writer.write(name);
    writer.write(JfrThreadId::os_id(_thread));
-   if (_thread->is_Java_thread()) {
+   if (!_thread->is_Java_thread()) {
+     writer.write((const char*)NULL); // java name
+     writer.write((traceid)0);        // java thread id
+     writer.write((traceid)0);        // java thread group
+     writer.write<bool>(false);       // isVirtual
+   } else {
      writer.write(name);
-     writer.write(JfrThreadId::id(_thread));
-     JavaThread* const jt = JavaThread::cast(_thread);
-     const traceid thread_group_id = JfrThreadGroup::thread_group_id(jt, jt);
+     writer.write(JfrThreadId::id(_thread, _vthread));
+     const bool vthread = _vthread != NULL;
+     // VirtualThread threadgroup reserved id 1
+     const traceid thread_group_id = vthread ? 1 :
+       JfrThreadGroup::thread_group_id(JavaThread::cast(_thread), Thread::current());
      writer.write(thread_group_id);
-     JfrThreadGroup::serialize(&writer, thread_group_id);
-     return;
+     writer.write<bool>(vthread);    // isVirtual
+     // VirtualThread threadgroup already serialized invariant
+     if (!vthread) {
+       JfrThreadGroup::serialize(&writer, thread_group_id);
+     }
    }
-   writer.write((const char*)NULL); // java name
-   writer.write((traceid)0); // java thread id
-   writer.write((traceid)0); // java thread group
  }
  
  void BytecodeConstant::serialize(JfrCheckpointWriter& writer) {
    static const u4 nof_entries = Bytecodes::number_of_codes;
    writer.write_count(nof_entries);
< prev index next >