Ejemplo n.º 1
0
/**
 * Returns the <code>thread</code>'s state according
 * to JVMTI specification. See <a href=http://java.sun.com/j2se/1.5.0/docs/guide/jvmti/jvmti.html#GetThreadState> 
 * JVMTI Specification </a> for more details.
 *
 * @param[in] java_thread thread those state is to be queried
 * @param[out] state resulting thread state
 * 
 */
IDATA VMCALL jthread_get_jvmti_state(jthread java_thread, jint * state)
{
    assert(state);
    assert(java_thread);

    hythread_t native_thread = jthread_get_native_thread(java_thread);
    vm_thread_t vm_thread = jthread_get_vm_thread(native_thread);
    *state = 0;
    if (!native_thread) {
        // Not started yet
        return TM_ERROR_NONE;
    }

    if (hythread_is_alive(native_thread)) {
        *state |= JVMTI_THREAD_STATE_ALIVE;
    }
    if (hythread_is_runnable(native_thread)) {
        *state |= JVMTI_THREAD_STATE_RUNNABLE;
    }
    if (hythread_is_blocked_on_monitor_enter(native_thread)) {
        *state |= JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
    }
    if (hythread_is_waiting(native_thread)) {
        *state |= JVMTI_THREAD_STATE_WAITING;
    }
    if (hythread_is_waiting_indefinitely(native_thread)) {
        *state |= JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
    }
    if (hythread_is_waiting_with_timeout(native_thread)) {
        *state |= JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
    }
    if (hythread_is_sleeping(native_thread)) {
        *state |= JVMTI_THREAD_STATE_SLEEPING;
    }
    if (hythread_is_in_monitor_wait(native_thread)) {
        *state |= JVMTI_THREAD_STATE_IN_OBJECT_WAIT;
    }
    if (hythread_is_parked(native_thread)) {
        *state |= JVMTI_THREAD_STATE_PARKED;
    }
    if (hythread_interrupted(native_thread)) {
        *state |= JVMTI_THREAD_STATE_INTERRUPTED;
    }
    if (hythread_is_in_native(native_thread)) {
        *state |= JVMTI_THREAD_STATE_IN_NATIVE;
    }
    if (hythread_is_terminated(native_thread)) {
        *state |= JVMTI_THREAD_STATE_TERMINATED;
    }
    if (vm_thread && vm_thread->suspend_flag) {
        *state |= JVMTI_THREAD_STATE_SUSPENDED;
    }

    return TM_ERROR_NONE;
} // jthread_get_jvmti_state
Ejemplo n.º 2
0
static bool ncai_thread_is_alive(hythread_t hythread)
{
    if (!hythread)
        return false;

    vm_thread_t vm_thread = jthread_get_vm_thread(hythread);

    if (!vm_thread || !vm_thread->java_thread)
        return false;

    return hythread_is_alive(hythread);
}
void test_thread_join(hythread_t native_thread, int index) {
    int i = 0;
    do {
        hythread_sleep(SLEEP_TIME);
        if(!hythread_is_alive(native_thread)) {
            break;
        }
        if (!i && (i % (MAX_TIME_TO_WAIT / SLEEP_TIME)) == 0) {
            printf("Thread %i isn't dead after %i milliseconds",
                index, (++i * SLEEP_TIME));
        }
    } while(1);
}
Ejemplo n.º 4
0
/**
 * Yield the processor for another thread.
 *
 * @return none
 */
void VMCALL hythread_yield_other(hythread_t thread) {
    assert(thread);
    if (hythread_is_alive(thread)) {
        port_thread_yield_other(thread->os_handle);
    }
}