< prev index next >

src/hotspot/share/jfr/support/jfrThreadLocal.cpp

Print this page

378   AccessThreadTraceId::set_epoch(vthread, epoch);
379   JfrCheckpointManager::write_checkpoint(const_cast<JavaThread*>(jt), tid, vthread);
380 }
381 
382 traceid JfrThreadLocal::vthread_id(const Thread* t) {
383   assert(t != nullptr, "invariant");
384   return Atomic::load(&t->jfr_thread_local()->_vthread_id);
385 }
386 
387 u2 JfrThreadLocal::vthread_epoch(const JavaThread* jt) {
388   assert(jt != nullptr, "invariant");
389   return Atomic::load(&jt->jfr_thread_local()->_vthread_epoch);
390 }
391 
392 traceid JfrThreadLocal::thread_id(const Thread* t) {
393   assert(t != nullptr, "invariant");
394   if (is_impersonating(t)) {
395     return t->jfr_thread_local()->_thread_id_alias;
396   }
397   JfrThreadLocal* const tl = t->jfr_thread_local();
398   if (!t->is_Java_thread() || !Atomic::load_acquire(&tl->_vthread)) {
399     return jvm_thread_id(t, tl);
400   }
401   // virtual thread
402   const JavaThread* jt = JavaThread::cast(t);




403   const traceid tid = vthread_id(jt);
404   assert(tid != 0, "invariant");
405   if (!tl->is_vthread_excluded()) {
406     const u2 current_epoch = AccessThreadTraceId::current_epoch();
407     if (vthread_epoch(jt) != current_epoch) {
408       set_vthread_epoch(jt, tid, current_epoch);
409     }
410   }
411   return tid;
412 }
413 
414 // When not recording, there is no checkpoint system
415 // in place for writing vthread information.
416 traceid JfrThreadLocal::external_thread_id(const Thread* t) {
417   assert(t != nullptr, "invariant");
418   return JfrRecorder::is_recording() ? thread_id(t) : jvm_thread_id(t);
419 }
420 
421 inline traceid load_java_thread_id(const Thread* t) {
422   assert(t != nullptr, "invariant");

439     }
440     tid = static_cast<traceid>(ThreadIdentifier::next());
441     tl->_jvm_thread_id = tid;
442   }
443   return tid;
444 }
445 
446 traceid JfrThreadLocal::jvm_thread_id(const Thread* t, JfrThreadLocal* tl) {
447   assert(t != nullptr, "invariant");
448   assert(tl != nullptr, "invariant");
449   return tl->_jvm_thread_id != 0 ? tl->_jvm_thread_id : JfrThreadLocal::assign_thread_id(t, tl);
450 }
451 
452 traceid JfrThreadLocal::jvm_thread_id(const Thread* t) {
453   assert(t != nullptr, "invariant");
454   return jvm_thread_id(t, t->jfr_thread_local());
455 }
456 
457 bool JfrThreadLocal::is_vthread(const JavaThread* jt) {
458   assert(jt != nullptr, "invariant");
459   return Atomic::load_acquire(&jt->jfr_thread_local()->_vthread);
460 }
461 
462 inline bool is_virtual(const JavaThread* jt, oop thread) {
463   assert(jt != nullptr, "invariant");
464   return thread != jt->threadObj();
465 }
466 
467 void JfrThreadLocal::on_set_current_thread(JavaThread* jt, oop thread) {
468   assert(jt != nullptr, "invariant");
469   assert(thread != nullptr, "invariant");
470   JfrThreadLocal* const tl = jt->jfr_thread_local();
471   if (!is_virtual(jt, thread)) {
472     Atomic::release_store(&tl->_vthread, false);
473     return;
474   }
475   Atomic::store(&tl->_vthread_id, AccessThreadTraceId::id(thread));
476   const u2 epoch_raw = AccessThreadTraceId::epoch(thread);
477   const bool excluded = epoch_raw & excluded_bit;
478   Atomic::store(&tl->_vthread_excluded, excluded);
479   if (!excluded) {

378   AccessThreadTraceId::set_epoch(vthread, epoch);
379   JfrCheckpointManager::write_checkpoint(const_cast<JavaThread*>(jt), tid, vthread);
380 }
381 
382 traceid JfrThreadLocal::vthread_id(const Thread* t) {
383   assert(t != nullptr, "invariant");
384   return Atomic::load(&t->jfr_thread_local()->_vthread_id);
385 }
386 
387 u2 JfrThreadLocal::vthread_epoch(const JavaThread* jt) {
388   assert(jt != nullptr, "invariant");
389   return Atomic::load(&jt->jfr_thread_local()->_vthread_epoch);
390 }
391 
392 traceid JfrThreadLocal::thread_id(const Thread* t) {
393   assert(t != nullptr, "invariant");
394   if (is_impersonating(t)) {
395     return t->jfr_thread_local()->_thread_id_alias;
396   }
397   JfrThreadLocal* const tl = t->jfr_thread_local();
398   if (!t->is_Java_thread()) {
399     return jvm_thread_id(t, tl);
400   }

401   const JavaThread* jt = JavaThread::cast(t);
402   if (!is_vthread(jt)) {
403     return jvm_thread_id(t, tl);
404   }
405   // virtual thread
406   const traceid tid = vthread_id(jt);
407   assert(tid != 0, "invariant");
408   if (!tl->is_vthread_excluded()) {
409     const u2 current_epoch = AccessThreadTraceId::current_epoch();
410     if (vthread_epoch(jt) != current_epoch) {
411       set_vthread_epoch(jt, tid, current_epoch);
412     }
413   }
414   return tid;
415 }
416 
417 // When not recording, there is no checkpoint system
418 // in place for writing vthread information.
419 traceid JfrThreadLocal::external_thread_id(const Thread* t) {
420   assert(t != nullptr, "invariant");
421   return JfrRecorder::is_recording() ? thread_id(t) : jvm_thread_id(t);
422 }
423 
424 inline traceid load_java_thread_id(const Thread* t) {
425   assert(t != nullptr, "invariant");

442     }
443     tid = static_cast<traceid>(ThreadIdentifier::next());
444     tl->_jvm_thread_id = tid;
445   }
446   return tid;
447 }
448 
449 traceid JfrThreadLocal::jvm_thread_id(const Thread* t, JfrThreadLocal* tl) {
450   assert(t != nullptr, "invariant");
451   assert(tl != nullptr, "invariant");
452   return tl->_jvm_thread_id != 0 ? tl->_jvm_thread_id : JfrThreadLocal::assign_thread_id(t, tl);
453 }
454 
455 traceid JfrThreadLocal::jvm_thread_id(const Thread* t) {
456   assert(t != nullptr, "invariant");
457   return jvm_thread_id(t, t->jfr_thread_local());
458 }
459 
460 bool JfrThreadLocal::is_vthread(const JavaThread* jt) {
461   assert(jt != nullptr, "invariant");
462   return Atomic::load_acquire(&jt->jfr_thread_local()->_vthread) && jt->last_continuation() != nullptr;
463 }
464 
465 inline bool is_virtual(const JavaThread* jt, oop thread) {
466   assert(jt != nullptr, "invariant");
467   return thread != jt->threadObj();
468 }
469 
470 void JfrThreadLocal::on_set_current_thread(JavaThread* jt, oop thread) {
471   assert(jt != nullptr, "invariant");
472   assert(thread != nullptr, "invariant");
473   JfrThreadLocal* const tl = jt->jfr_thread_local();
474   if (!is_virtual(jt, thread)) {
475     Atomic::release_store(&tl->_vthread, false);
476     return;
477   }
478   Atomic::store(&tl->_vthread_id, AccessThreadTraceId::id(thread));
479   const u2 epoch_raw = AccessThreadTraceId::epoch(thread);
480   const bool excluded = epoch_raw & excluded_bit;
481   Atomic::store(&tl->_vthread_excluded, excluded);
482   if (!excluded) {
< prev index next >