Esempio n. 1
0
/*
 * Test test_jthread_set_and_get_local_storage
 */
int test_jthread_set_and_get_local_storage(void)
{
    void * data;
    hythread_t hythread;
    tested_thread_sturct_t *tts;

    // Initialize tts structures and run all tested threads
    tested_threads_run(default_run_for_test);
    
    reset_tested_thread_iterator(&tts);
    while (next_tested_thread(&tts)) {
        hythread = jthread_get_native_thread(tts->java_thread);
        tf_assert(hythread);
        tf_assert_same(hythread_tls_set(hythread, TEST_TLS_KEY, tts),
                       TM_ERROR_NONE);
    }
    reset_tested_thread_iterator(&tts);
    while (next_tested_thread(&tts)) {
        hythread = jthread_get_native_thread(tts->java_thread);
        tf_assert(hythread);
        data = hythread_tls_get(hythread, TEST_TLS_KEY);
        tf_assert_same(data, tts);
    }

    // Terminate all threads and clear tts structures
    tested_threads_destroy();

    return TEST_PASSED;
}
Esempio n. 2
0
/**
 * Unparks the given thread.
 *
 * If the thread is parked, it will return from park.
 * If the thread is not parked, its 'UNPARKED' flag will be set, and it will
 * return immediately the next time it is parked.
 *
 * Note that unparks are not counted. Unparking a thread once is the same as
 * unparking it n times.
 *
 * @param[in] java_thread thread that needs to be unparked
 * @sa java.util.concurrent.locks.LockSupport.unpark() 
 */
IDATA VMCALL jthread_unpark(jthread java_thread)
{
    assert(java_thread);
    hythread_t native_thread = jthread_get_native_thread(java_thread);
    hythread_unpark(native_thread);
    return TM_ERROR_NONE;
} // jthread_unpark
Esempio n. 3
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
void tested_threads_run_common(jvmtiStartFunction run_method_param){
    tested_thread_sturct_t *tts;
    JNIEnv * jni_env = jthread_get_JNI_env(jthread_self());

    reset_tested_thread_iterator(&tts);
    while(next_tested_thread(&tts)){
        tts->attrs.proc = run_method_param;
        tts->attrs.arg = tts;
        tf_assert_same_v(jthread_create_with_function(jni_env, tts->java_thread, &tts->attrs), TM_ERROR_NONE);
        tested_thread_wait_started(tts);
        tts->native_thread = jthread_get_native_thread(tts->java_thread);
    }
}
Esempio n. 5
0
/**
 * Returns the number of times given thread have entered given monitor;
 *
 * If the given monitor is not owned by this thread, 0 is returned.
 *
 * @param[in] monitor monitor those owner needs to be determined
 * @param[in] owner thread which owns the monitor
 */
IDATA VMCALL jthread_get_lock_recursion(jobject monitor, jthread owner)
{
    assert(monitor);

    hythread_t given_thread = owner ? jthread_get_native_thread(owner) : NULL;

    hythread_suspend_disable();
    hythread_thin_monitor_t *lockword = vm_object_get_lockword_addr(monitor);
    hythread_t lock_owner = hythread_thin_monitor_get_owner(lockword);

    IDATA recursion = 0;
    if (lock_owner
        && (!given_thread
            || hythread_get_id(lock_owner) == hythread_get_id(given_thread)))
    {
        recursion = hythread_thin_monitor_get_recursion(lockword);
    }
    hythread_suspend_enable();

    return recursion;
} // jthread_get_lock_recursion
Esempio n. 6
0
/**
 * Detaches current thread from VM.
 */
jint vm_detach(jobject java_thread)
{
    assert(hythread_is_suspend_enabled());

    hythread_t native_thread = jthread_get_native_thread(java_thread);
    assert(native_thread);
    vm_thread_t p_vm_thread = jthread_get_vm_thread(native_thread);
    assert(p_vm_thread);

    // Send Thread End event
    if(jvmti_should_report_event(JVMTI_EVENT_THREAD_END)) {
        jvmti_send_thread_start_end_event(p_vm_thread, 0);
    }

    // change java_status for native thread
    native_thread->java_status = TM_STATUS_ALLOCATED;

    if (native_thread == hythread_self()) {
        // Notify GC about thread detaching.
        // FIXME - GC notify detach thread works for current thread only
        gc_thread_kill(&p_vm_thread->_gc_private_information);
    }

    if (ti_is_enabled())
    {
        apr_status_t UNREF status;
        status = port_vmem_free(
            p_vm_thread->jvmti_thread.jvmti_jit_breakpoints_handling_buffer,
            TM_JVMTI_MAX_BUFFER_SIZE);
        assert(status == APR_SUCCESS);
    }

    // Destroy current VM_thread pool and zero VM_thread structure
    jthread_deallocate_vm_thread_pool(p_vm_thread);

    return JNI_OK;
}
Esempio n. 7
0
ncaiError JNICALL
ncaiGetThreadHandle(ncaiEnv *env, jthread thread, ncaiThread *thread_ptr)
{
    TRACE2("ncai.thread", "GetThreadHandle called");
    SuspendEnabledChecker sec;

    if (env == NULL)
        return NCAI_ERROR_INVALID_ENVIRONMENT;

    if (thread_ptr == NULL)
        return NCAI_ERROR_NULL_POINTER;

    if (thread == NULL)
        return NCAI_ERROR_INVALID_THREAD;

    hythread_t hythread = jthread_get_native_thread(thread);

    if (hythread == NULL)
        return NCAI_ERROR_INVALID_THREAD;

    *thread_ptr = reinterpret_cast<ncaiThread>(hythread);

    return NCAI_ERROR_NONE;
}
Esempio n. 8
0
vm_thread_t jthread_get_vm_thread_ptr_safe(jobject thread_obj)
{
    hythread_t native = jthread_get_native_thread(thread_obj);
    return jthread_get_vm_thread(native);
}
Esempio n. 9
0
/**
 * Clears the interruption flag for the specific <code>thread</code>.
 *
 * @param[in] java_thread where to clear interrupt flag
 * @sa java.lang.Thread.interrupted()
 */
IDATA VMCALL jthread_clear_interrupted(jthread java_thread)
{
    hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
    return hythread_clear_interrupted_other(tm_native_thread);
} // jthread_clear_interrupted
Esempio n. 10
0
/**
 * Returns <code>true</code> if the thread <code>thread</code> is interrupted.
 *
 * Otherwise returns <code>false</code>.
 *
 * @param[in] java_thread thread to be checked
 * @return <code>true</code> if the thread <code>thread</code>
 * is interrupted; <code>false</code> otherwise.
 * @sa java.lang.Thread.isInterrupted()
 */
jboolean jthread_is_interrupted(jthread java_thread)
{
    hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
    return hythread_interrupted(tm_native_thread) > 0;
} // jthread_is_interrupted
Esempio n. 11
0
/**
 * Interrupt a <code>thread</code>.
 *
 * If the <code>thread</code>is currently blocked (i.e. waiting on a monitor_wait or sleeping)
 * resume the <code>thread</code>and cause it to return from the blocking function with
 * TM_THREAD_INTERRUPTED.
 *
 * @param[in] java_thread a thread to be interrupted
 * @sa java.lang.Thread.interrupt()
 */
IDATA VMCALL jthread_interrupt(jthread java_thread)
{
    hythread_t tm_native_thread = jthread_get_native_thread(java_thread);
    hythread_interrupt(tm_native_thread);
    return TM_ERROR_NONE;
} // jthread_interrupt