void JNICALL callbackVMInit(prms_VMINIT)
{
    check_VMINIT;

    jvmtiStartFunction proc = function;
    const char* name = "Tested Monitor";

    result = jvmti_env->CreateRawMonitor(name, &mntr);
    fprintf(stderr, "\tnative: CreateRawMonitor result = %d\n", result);
    fprintf(stderr, "\tnative: monitor name   is %s \n", name);
    fprintf(stderr, "\tnative: monitor        is %p \n", mntr);
    fflush(stderr);

    result = jvmti_env->RunAgentThread(create_not_alive_thread(jni_env, jvmti_env),
            proc, "a", JVMTI_THREAD_NORM_PRIORITY);
    if (result != JVMTI_ERROR_NONE) return;

    result = jvmti_env->RunAgentThread(create_not_alive_thread(jni_env, jvmti_env),
            proc, "b", JVMTI_THREAD_NORM_PRIORITY);
    if (result != JVMTI_ERROR_NONE) return;

    result = jvmti_env->RunAgentThread(create_not_alive_thread(jni_env, jvmti_env),
            proc, "c", JVMTI_THREAD_NORM_PRIORITY);
    if (result != JVMTI_ERROR_NONE) return;

    result = jvmti_env->RunAgentThread(create_not_alive_thread(jni_env, jvmti_env),
            proc, "d", JVMTI_THREAD_NORM_PRIORITY);
    if (result != JVMTI_ERROR_NONE) return;

    result = jvmti_env->RunAgentThread(create_not_alive_thread(jni_env, jvmti_env),
            proc, "t", JVMTI_THREAD_NORM_PRIORITY);
    if (result != JVMTI_ERROR_NONE) return;

    while (!finish)
    {
#ifndef LINUX
        Sleep(1000);
#else
        usleep(1);
#endif
    }

    util = true;
}
void JNICALL callbackException(prms_EXCPT)
{
    check_EXCPT;

    if (flag) return;

    char* name;
    char* signature;
    char* generic;
    jint tcount;
    jthread* threads;
    jthread my_thread;
    jvmtiError result;
    jvmtiThreadInfo tinfo;

    /*
     * Function separate all other exceptions in all other method
     */
    if (!check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
                "special_method", DEBUG_OUT))
    {
        if (check_phase_and_method_debug(jvmti_env, method, SPP_LIVE_ONLY,
                    "sub_special", DEBUG_OUT)) test = false;
        return;
    }

    flag = true;
    util = true;

    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++ )
        if (jvmti_env->GetThreadInfo(threads[i], &tinfo) == JVMTI_ERROR_NONE)
            if (!strcmp(tinfo.name, "agent"))
            {
                fprintf(stderr, "\tnative: tested thread was found\n");
                my_thread = threads[i];
                break;
            }

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

    result = jvmti_env->PopFrame(create_not_alive_thread(jni_env, jvmti_env));
    fprintf(stderr, "\tnative: PopFrame result = %d (must be JVMTI_ERROR_THREAD_NOT_ALIVE (15)) \n", result);
    fprintf(stderr, "\tnative: thread is %p (must be NON-zero) \n", thread);
    fflush(stderr);
    if (result == JVMTI_ERROR_THREAD_NOT_ALIVE) test = true;

    result = jvmti_env->ResumeThread(my_thread);
    fprintf(stderr, "\tnative: ResumeThread result = %d (must be zero) \n", result);
    if (result != JVMTI_ERROR_NONE) return;
}
Exemple #3
0
void JNICALL callbackException(prms_EXCPT)
{
    if (flag) return;

    check_EXCPT;

    jint depth = 0;
    jint varnum;
    jint slot = 0;
    jint value;
    jvmtiError result;
    jvmtiLocalVariableEntry* table;

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

    flag = true;
    util = true;

    result = jvmti_env->GetLocalVariableTable(method, &varnum, &table);
    fprintf(stderr, "\tnative: GetLocalVariableTable result = %d (must be zero) \n", result);
    fprintf(stderr, "\tnative: method ID is %p (must be NON-zero) \n", method);
    fprintf(stderr, "\tnative: variables number is %d (must be 6) \n", varnum);
    fprintf(stderr, "\tnative: table is %p (must be NON-zero)\n", table);
    fflush(stderr);

    if (result != JVMTI_ERROR_NONE) return;

    for (int i = 0; i < varnum; i++)
        if (!strcmp(table[i].name, "_INT"))
            slot = table[i].slot;

    result = jvmti_env->GetLocalInt(create_not_alive_thread(jni_env,
                jvmti_env), depth, slot, &value);

    fprintf(stderr, "\tnative: GetLocalInt result = %d (must be JVMTI_ERROR_THREAD_NOT_ALIVE (15)) \n", result);

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