< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp

Print this page
rev 52432 : 8213501: Deploy ExceptionJniWrapper for a few tests
Summary:
Reviewed-by:

*** 23,33 **** #include <stdio.h> #include <string.h> #include <jvmti.h> #include "agent_common.h" ! #include "nsk_tools.h" #include "jni_tools.h" #include "JVMTITools.h" #include "jvmti_tools.h" --- 23,33 ---- #include <stdio.h> #include <string.h> #include <jvmti.h> #include "agent_common.h" ! #include "ExceptionCheckingJniEnv.hpp" #include "nsk_tools.h" #include "jni_tools.h" #include "JVMTITools.h" #include "jvmti_tools.h"
*** 303,313 **** NSK_DISPLAY0("Agent thread: finished.\n"); } /***********************************************************************/ ! static int startThread(JNIEnv* jni, jthread threadObj) { int success = NSK_TRUE; /* enter startLock */ if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(startLock))) { nsk_jvmti_setFailStatus(); --- 303,313 ---- NSK_DISPLAY0("Agent thread: finished.\n"); } /***********************************************************************/ ! static int startThread(jthread threadObj) { int success = NSK_TRUE; /* enter startLock */ if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(startLock))) { nsk_jvmti_setFailStatus();
*** 332,371 **** return success; } /** Create thread object for new agent thread. */ ! static jthread newThreadObj(JNIEnv* jni) { jclass thrClass; jmethodID cid; jthread result = NULL; ! thrClass = jni->FindClass("java/lang/Thread"); ! if (!NSK_JNI_VERIFY(jni, thrClass != NULL)) { nsk_jvmti_setFailStatus(); return result; } ! cid = jni->GetMethodID(thrClass, "<init>", "()V"); ! if (!NSK_JNI_VERIFY(jni, cid != NULL)) { nsk_jvmti_setFailStatus(); return result; } ! result = jni->NewObject(thrClass, cid); ! if (!NSK_JNI_VERIFY(jni, result != NULL)) { nsk_jvmti_setFailStatus(); return result; } return result; } /***********************************************************************/ /** Clean counters and start new agent thread with agent_start() body. */ ! static int prepareToIteration (JNIEnv* jni) { jthread threadObj = NULL; setCounter(&iterationCount, 0); setCounter(&objectCount, 0); --- 332,372 ---- return success; } /** Create thread object for new agent thread. */ ! static jthread newThreadObj(JNIEnv* jni_env) { ! ExceptionCheckingJniEnvPtr jni(jni_env); jclass thrClass; jmethodID cid; jthread result = NULL; ! thrClass = jni->FindClass("java/lang/Thread", TRACE_JNI_CALL); ! if (thrClass == NULL) { nsk_jvmti_setFailStatus(); return result; } ! cid = jni->GetMethodID(thrClass, "<init>", "()V", TRACE_JNI_CALL); ! if (cid == NULL) { nsk_jvmti_setFailStatus(); return result; } ! result = jni->NewObject(thrClass, cid, TRACE_JNI_CALL); ! if (result == NULL) { nsk_jvmti_setFailStatus(); return result; } return result; } /***********************************************************************/ /** Clean counters and start new agent thread with agent_start() body. */ ! static int prepareToIteration(JNIEnv* jni) { jthread threadObj = NULL; setCounter(&iterationCount, 0); setCounter(&objectCount, 0);
*** 379,393 **** if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("Starting new agent thread...\n"); ! return startThread(jni, threadObj); } /** Wait for new agent thread to complete. */ ! static void afterIteration (JNIEnv* jni) { /* notify new agent thread (in case if not yet notified) */ notifyThread(); NSK_DISPLAY0("Wait for new agent thread to complete\n"); --- 380,394 ---- if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("Starting new agent thread...\n"); ! return startThread(threadObj); } /** Wait for new agent thread to complete. */ ! static void afterIteration() { /* notify new agent thread (in case if not yet notified) */ notifyThread(); NSK_DISPLAY0("Wait for new agent thread to complete\n");
*** 431,441 **** NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverHeap finished.\n"); ! afterIteration(jni); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found; --- 432,442 ---- NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverHeap finished.\n"); ! afterIteration(); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found;
*** 462,472 **** NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); ! afterIteration(jni); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found; --- 463,473 ---- NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverReachableObjects finished.\n"); ! afterIteration(); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found;
*** 493,503 **** NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); ! afterIteration(jni); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found; --- 494,504 ---- NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n"); ! afterIteration(); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found;
*** 507,541 **** nsk_jvmti_setFailStatus(); } } JNIEXPORT void JNICALL ! Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni, jclass klass) { jobject root = NULL; int modified = 0; int found = 0; ! root = jni->GetStaticObjectField(debugeeClass, rootFieldID); ! if (!NSK_JNI_VERIFY(jni, root != NULL)) { NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); nsk_jvmti_setFailStatus(); return; } ! if (!prepareToIteration(jni)) return; NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(root, objectReferenceCallback, NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); ! afterIteration(jni); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found; --- 508,543 ---- nsk_jvmti_setFailStatus(); } } JNIEXPORT void JNICALL ! Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni_env, jclass klass) { + ExceptionCheckingJniEnvPtr jni(jni_env); jobject root = NULL; int modified = 0; int found = 0; ! root = jni->GetStaticObjectField(debugeeClass, rootFieldID, TRACE_JNI_CALL); ! if (root == NULL) { NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n"); nsk_jvmti_setFailStatus(); return; } ! if (!prepareToIteration(jni_env)) return; NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n"); if (!NSK_JVMTI_VERIFY(jvmti->IterateOverObjectsReachableFromObject(root, objectReferenceCallback, NULL /*user_data*/))) { nsk_jvmti_setFailStatus(); } NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n"); ! afterIteration(); found = getCounter(&objectCount); NSK_DISPLAY1("Found tagged objects: %d\n", found); modified = OBJ_MAX_COUNT - found;
*** 545,556 **** nsk_jvmti_setFailStatus(); } } static void JNICALL ! agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) { ! NSK_DISPLAY0("Wait for debugee start\n\n"); if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) return; NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE); --- 547,558 ---- nsk_jvmti_setFailStatus(); } } static void JNICALL ! agentProc(jvmtiEnv* jvmti, JNIEnv* jni_env, void* arg) { ! ExceptionCheckingJniEnvPtr jni(jni_env); NSK_DISPLAY0("Wait for debugee start\n\n"); if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) return; NSK_DISPLAY1("Find debugee class: %s\n", DEBUGEE_SIGNATURE);
*** 558,574 **** if (debugeeClass == NULL) { nsk_jvmti_setFailStatus(); return; } ! debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass); ! if (!NSK_JNI_VERIFY(jni, debugeeClass != NULL)) return; NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); ! rootFieldID = jni->GetStaticFieldID(debugeeClass, "root", ROOT_SIGNATURE); ! if (!NSK_JNI_VERIFY(jni, rootFieldID != NULL)) { nsk_jvmti_setFailStatus(); return; } NSK_DISPLAY0("Let debugee to run test cases\n"); --- 560,578 ---- if (debugeeClass == NULL) { nsk_jvmti_setFailStatus(); return; } ! debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass, TRACE_JNI_CALL); ! if (debugeeClass == NULL) { return; + } NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE); ! rootFieldID = jni->GetStaticFieldID(debugeeClass, "root", ! ROOT_SIGNATURE, TRACE_JNI_CALL); ! if (rootFieldID == NULL) { nsk_jvmti_setFailStatus(); return; } NSK_DISPLAY0("Let debugee to run test cases\n");
*** 577,587 **** NSK_DISPLAY0("Wait for completion of test cases\n\n"); if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) return; ! NSK_TRACE(jni->DeleteGlobalRef(debugeeClass)); NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr)); NSK_TRACE(jvmti->DestroyRawMonitor(startLock)); NSK_TRACE(jvmti->DestroyRawMonitor(runLock)); NSK_TRACE(jvmti->DestroyRawMonitor(endLock)); --- 581,591 ---- NSK_DISPLAY0("Wait for completion of test cases\n\n"); if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout))) return; ! jni->DeleteGlobalRef(debugeeClass, TRACE_JNI_CALL); NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr)); NSK_TRACE(jvmti->DestroyRawMonitor(startLock)); NSK_TRACE(jvmti->DestroyRawMonitor(runLock)); NSK_TRACE(jvmti->DestroyRawMonitor(endLock));
< prev index next >