Exemplo n.º 1
0
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);
  }
}
Exemplo n.º 2
0
void VTThrd_createMutex(VTThrdMutex** mutex)
{
  jvmtiError error;

  vt_assert(mutexInitMutex != NULL);

  error = (*jvmti)->RawMonitorEnter(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorEnter");
  if (*mutex == NULL)
  {
    static uint8_t rawmon_id = 0;
    char rawmon_name[10];

    *mutex = (VTThrdMutex*)malloc(sizeof(VTThrdMutex));
    if (*mutex == NULL)
      vt_error();

    snprintf(rawmon_name, sizeof(rawmon_name) - 1, "rawmon%d", rawmon_id++);

    error = (*jvmti)->CreateRawMonitor(jvmti, rawmon_name,
                                       &((*mutex)->m));
    vt_java_check_error(jvmti, error, "CreateRawMonitor");
  }
  error = (*jvmti)->RawMonitorExit(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorExit");
}
Exemplo n.º 3
0
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);
  }
}
Exemplo n.º 4
0
void VTThrd_unlock(VTThrdMutex** mutex)
{
  jvmtiError error;

  vt_assert(*mutex != NULL);

  error = (*jvmti)->RawMonitorExit(jvmti, (*mutex)->m);
  vt_java_check_error(jvmti, error, "RawMonitorExit");
}
Exemplo n.º 5
0
void VTThrd_deleteMutex(VTThrdMutex** mutex)
{
  jvmtiError error;

  if (*mutex == NULL) return;

  error = (*jvmti)->RawMonitorEnter(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorEnter");
  if (*mutex != NULL )
  {
    error = (*jvmti)->DestroyRawMonitor(jvmti, (*mutex)->m);
    vt_java_check_error(jvmti, error, "DestroyRawMonitor");
    free(*mutex);
    *mutex = NULL;
  }
  error = (*jvmti)->RawMonitorExit(jvmti, mutexInitMutex);
  vt_java_check_error(jvmti, error, "RawMonitorExit");
}
Exemplo n.º 6
0
void VTThrd_lock(VTThrdMutex** mutex)
{
  jvmtiError error;

  if (*mutex == NULL)
    VTThrd_createMutex(mutex);

  error = (*jvmti)->RawMonitorEnter(jvmti, (*mutex)->m);
  vt_java_check_error(jvmti, error, "RawMonitorEnter");
}
Exemplo n.º 7
0
uint8_t VTThrd_is_alive()
{
  jvmtiError error;
  uint32_t *tid;

  /* get thread-ID from thread-specific data */
  error = (*jvmti)->GetThreadLocalStorage(jvmti, NULL, (void**)&tid);
  vt_java_check_error(jvmti, error, "GetThreadLocalStorage");

  if (tid || vt_jvmti_agent->vm_is_dead)
    return 1;
  else
    return 0;
}
Exemplo n.º 8
0
uint32_t VTThrd_getThreadId()
{
  jvmtiError error;
  uint32_t *tid;

  /* get thread-ID from thread-specific data */
  error = (*jvmti)->GetThreadLocalStorage(jvmti, NULL, (void**)&tid);
  vt_java_check_error(jvmti, error, "GetThreadLocalStorage");

  if (tid == NULL && vt_jvmti_agent->vm_is_dead)
    return 0;
  else
    vt_assert(tid != NULL);

  return *tid;
}