示例#1
0
void JNICALL callbackThreadStart(prms_THRD_START)
{
    check_THRD_START;

    if (flag) return;

    jvmtiPhase phase;
    jvmtiThreadInfo tinfo;
    jvmtiError result;
    jint tcount;
    jthread* threads;
    jthread my_thread = (jthread)jvmti_env;
    jint state = 0;
    long ethalon = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_INTERRUPTED;

    /*
     * Function separate all other exceptions in all other method
     */
    if (!check_phase_and_thread_debug(jvmti_env, thread, SPP_LIVE_ONLY,
                "agent", DEBUG_OUT)) return;

    fprintf(stderr, "\tnative: test started\n");
    flag = true;

    if (!util) return;

    result = jvmti_env->StopThread(my_thread, stored_exception);

    fprintf(stderr, "\tnative: StopThread result = %d (must be JVMTI_ERROR_INVALID_THREAD (10)) \n", result);

    if (result == JVMTI_ERROR_INVALID_THREAD) test = true;
}
void JNICALL callbackThreadStart(prms_THRD_START)
{
    check_THRD_START;

    if (flag) return;

    jvmtiPhase phase;
    jvmtiThreadInfo tinfo;
    jvmtiError result;
    jint tcount;
    jthread* threads;
    jthread my_thread = NULL;
    jint state = 0;
    long ethalon = JVMTI_THREAD_STATE_ALIVE | JVMTI_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_INTERRUPTED;

    /*
     * Function separate all other exceptions in all other method
     */
    if (!check_phase_and_thread_debug(jvmti_env, thread, SPP_LIVE_ONLY,
                "agent", DEBUG_OUT)) return;

    fprintf(stderr, "\tnative: test started\n");
    flag = true;

    if (!util) return;

    result = jvmti_env->GetAllThreads(&tcount, &threads);
    fprintf(stderr, "\tnative: GetAllThreads result = %d (must be zero) \n", result);
    if (result != JVMTI_ERROR_NONE) return;

    for ( int i = 0; i < tcount; i++ )
    {
        result = jvmti_env->GetThreadInfo(threads[i], &tinfo);
        if (DEBUG_OUT) {
            fprintf(stderr, "\tnative: GetThreadInfo result = %d (must be zero) \n", result);
            fprintf(stderr, "\tnative: current thread name is %s (must be zero) \n", tinfo.name);
        }
        if (result != JVMTI_ERROR_NONE) continue;
        if (strcmp(tinfo.name, "SuperPuperTest")) continue;
        my_thread = threads[i];
        fprintf(stderr, "\tnative: tested thread was found = %p\n", my_thread);
        break;
    }

    if (!my_thread) return;

    CAPABILITY_TURN_OFF_VOID(can_signal_thread);

    result = jvmti_env->StopThread(my_thread, stored_exception);

    fprintf(stderr, "\tnative: StopThread result = %d (must be JVMTI_ERROR_MUST_POSSESS_CAPABILITY (99)) \n", result);

    if (result == JVMTI_ERROR_MUST_POSSESS_CAPABILITY) test = true;
}