void VTThrd_registerThread(jthread thread, const char* tname) { jvmtiError error; uint32_t *tid; /* check whether an ID is already created for this thread */ error = (*jvmti)->GetThreadLocalStorage(jvmti, thread, (void**)&tid); vt_java_check_error(jvmti, error, "GetThreadLocalStorage"); if (tid == NULL) { /* create new thread-ID */ tid = (uint32_t*)malloc(sizeof(uint32_t)); if (tid == NULL) vt_error(); /* increment number of threads */ *tid = VTThrd_createNewThreadId(); /* put new ID to thread-specific data */ error = (*jvmti)->SetThreadLocalStorage(jvmti, thread, (void*)tid); vt_java_check_error(jvmti, error, "SetThreadLocalStorage"); /* create new thread object */ vt_cntl_msg(2, "Dynamic thread creation. Thread #%d (%s)", *tid, tname ? tname : "unnamed"); VTThrd_create(*tid, 0, tname, 0); VTThrd_open(*tid); } }
void VTThrd_init() { /* get the maximum number of threads */ VTThrdMaxNum = (uint32_t)vt_env_max_threads(); /* create vector of the thread objects */ VTThrdv = (VTThrd**)calloc(VTThrdMaxNum, sizeof(VTThrd*)); if ( VTThrdv == NULL ) vt_error(); #if (defined(VT_MT) || defined (VT_HYB) || defined(VT_JAVA)) /* initialize thread-type specifics */ # if defined(VT_THRD_PTHREAD) VTThrd_initPthread(); # elif defined(VT_THRD_OMP) VTThrd_initOmp(); # elif defined(VT_JAVA) VTThrd_initJava(); # endif /* VT_THRD_[PTHREAD|OMP] || VT_JAVA */ /* create mutexes for locking */ VTThrd_createMutex(&VTThrdMutexEnv); VTThrd_createMutex(&VTThrdMutexIds); #endif /* VT_MT || VT_HYB || VT_JAVA */ /* create object for master thread (for Java this will be done in VTThrd_initJava(), 'cause it gets the read thread name) */ #if !defined(VT_JAVA) VTThrd_create(0, 0, NULL, 0); VTThrd_open(0); #endif /* VT_JAVA */ }
void VTThrd_registerThread(uint32_t ptid) { uint32_t *tid; uint8_t tid_reuse = 0; if (!vt_is_alive) return; /* check whether an ID is already created for this thread */ tid = (uint32_t*)pthread_getspecific(pthreadKey); if (tid == NULL) { tid = (uint32_t*)malloc(sizeof(uint32_t)); if (tid == NULL) vt_error(); /* try to get idle thread-ID for reuse, if desired */ if (reuseThreadIds) { pthread_mutex_lock(&threadReuseMutex); if (idle_tid_list_size(ptid) > 0) { *tid = idle_tid_list_pop_front(ptid); tid_reuse = 1; } pthread_mutex_unlock(&threadReuseMutex); } /* create new thread-ID, if not reusing */ if (!tid_reuse) *tid = VTThrd_create(NULL, ptid, 0); /* put (new) thread-ID to thread-specific data */ pthread_setspecific(pthreadKey, tid); /* open thread associated trace file, if new thread object was created */ if (!tid_reuse ) { VTThrd_open(*tid); } /* otherwise, re-create metrics for reused thread object */ else { #if defined(VT_METR) if (vt_metric_num() > 0 && !VTThrdv[*tid]->metv) VTThrdv[*tid]->metv = vt_metric_create(); #endif /* VT_METR */ #if defined(VT_PLUGIN_CNTR) /* if we really use plugins and this thread also uses some */ if (vt_plugin_cntr_used && VTThrdv[*tid]->plugin_cntr_defines) vt_plugin_cntr_thread_enable_counters(VTThrdv[*tid]); #endif /* VT_PLUGIN_CNTR */ } } }
void VTThrd_registerThread(uint32_t ptid) { if (!vt_is_alive) return; /* create new thread-ID, if necessary */ if (threadId == VT_NO_ID) { threadId = VTThrd_create(NULL, ptid, 0); VTThrd_open(threadId); } }
void VTThrd_initJava() { static uint8_t initflag = 1; if (initflag) { jvmtiError error; char tname[VT_MAX_THREAD_NAME_LEN]; uint32_t* tid; initflag = 0; /* store pointer to JVMTI's environment */ jvmti = vt_jvmti_agent->jvmti; /* create ID for first thread (=0) */ tid = (uint32_t*)malloc(sizeof(uint32_t)); if (tid == NULL) vt_error(); *tid = 0; /* put thread-ID to thread-specific data */ error = (*jvmti)->SetThreadLocalStorage(jvmti, NULL, (void*)tid); vt_java_check_error(jvmti, error, "SetThreadLocalStorage"); /* create raw monitor for thread count */ error = (*jvmti)->CreateRawMonitor(jvmti, "thread count", &threadCountMutex); vt_java_check_error(jvmti, error, "CreateRawMonitor[thread count]"); /* create raw monitor for mutex init */ error = (*jvmti)->CreateRawMonitor(jvmti, "mutex init", &mutexInitMutex); vt_java_check_error(jvmti, error, "CreateRawMonitor[mutex init]"); #if defined(VT_METR) /* if (vt_metric_num() > 0) vt_metric_thread_init((long (*)(void))(pthread_self));*/ #endif /* VT_METR */ /* get name of current thread */ vt_java_get_thread_name(NULL, NULL, tname, sizeof(tname)); /* create thread object for master thread */ VTThrdv[0] = VTThrd_create(0, 0, tname); VTThrd_open(VTThrdv[0], 0); } }