MCPcopy Create free account
hub / github.com/async-profiler/async-profiler / initThreadBridge

Method initThreadBridge

src/vmStructs.cpp:592–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592void VMStructs::initThreadBridge() {
593 jthread thread;
594 if (VM::jvmti()->GetCurrentThread(&thread) != 0) {
595 return;
596 }
597
598 JNIEnv* env = VM::jni();
599 jclass thread_class = env->FindClass("java/lang/Thread");
600 if (thread_class == NULL || (_tid = env->GetFieldID(thread_class, "tid", "J")) == NULL) {
601 env->ExceptionClear();
602 return;
603 }
604
605 if (VM::isOpenJ9()) {
606 void* j9thread = J9Ext::j9thread_self();
607 if (j9thread != NULL) {
608 initTLS(j9thread);
609 }
610 } else {
611 // Get eetop field - a bridge from Java Thread to VMThread
612 if ((_eetop = env->GetFieldID(thread_class, "eetop", "J")) == NULL) {
613 // No such field - probably not a HotSpot JVM
614 env->ExceptionClear();
615 return;
616 }
617
618 VMThread* vm_thread = VMThread::fromJavaThread(env, thread);
619 if (vm_thread != NULL) {
620 initTLS(vm_thread);
621 if (!VM::isZing()) {
622 _has_native_thread_id = _thread_osthread_offset >= 0 && _osthread_id_offset >= 0;
623 _env_offset = (intptr_t)env - (intptr_t)vm_thread;
624 memcpy(_java_thread_vtbl, vm_thread->vtable(), sizeof(_java_thread_vtbl));
625 }
626 }
627 }
628}
629
630VMThread* VMThread::current() {
631 return _tls_index >= 0 ? (VMThread*)pthread_getspecific((pthread_key_t)_tls_index) : NULL;

Callers

nothing calls this directly

Calls 1

vtableMethod · 0.80

Tested by

no test coverage detected