40 #define MAIN_CLASS "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002"
41
42 static jvmtiEnv * jvmti;
43 static jthread testAgentThread;
44
45 JNIEXPORT void JNICALL doRedefineInNativeThread(jvmtiEnv * jvmti,
46 JNIEnv * jni, void * arg) {
47 jclass cla;
48 int i = 0;
49 int redefineNumber = 0;
50 char fileName[512];
51
52 jclass testClass;
53
54 jmethodID setRedefinitionDone;
55 jmethodID setRedefinitionFailed;
56
57 testClass = jni->FindClass(MAIN_CLASS);
58
59 if (!NSK_JNI_VERIFY(jni, (
60 setRedefinitionFailed = NSK_CPP_STUB4(GetStaticMethodID, jni,
61 testClass, "setRedefinitionFailed", "()V")) != NULL))
62 {
63 NSK_CPP_STUB2(FatalError, jni,
64 "TEST FAILED: while getting setRedefinitionFailed()\n");
65 }
66
67 if (!NSK_JNI_VERIFY(jni, (
68 setRedefinitionDone = NSK_CPP_STUB4(GetStaticMethodID, jni,
69 testClass, "setRedefinitionDone", "()V")) != NULL))
70 {
71 NSK_CPP_STUB2(FatalError, jni,
72 "TEST FAILED: while getting setRedefinitionDone()\n");
73 }
74
75 nsk_printf("doRedefineInNativeThread\n");
76 cla = jni->FindClass(SEARCH_NAME);
77 nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char));
78 for(i = 0; i < 30; i++) {
79 nsk_printf(" Inside the redefine method..\n");
80 if ( nsk_jvmti_redefineClass(jvmti, cla,fileName) == NSK_TRUE) {
81 nsk_printf("\nMyClass :: Successfully redefined..\n");
82 } else {
83 nsk_printf("\nMyClass :: Failed to redefine ..\n");
84
85 if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni,
86 testClass, setRedefinitionFailed)))
87 {
88 NSK_CPP_STUB2(FatalError, jni,
89 "TEST FAILED: while calling setRedefinitionFailed()\n");
90 }
91 }
92 }
93
94 if (!NSK_JNI_VERIFY_VOID(jni, NSK_CPP_STUB3(CallStaticVoidMethod, jni,
95 testClass, setRedefinitionDone)))
96 {
97 NSK_CPP_STUB2(FatalError, jni,
98 "TEST FAILED: while calling setRedefinitionDone()\n");
99 }
100
101 nsk_printf(" All 30 redefinitions are done..\n");
102 }
103
104
105 #ifdef STATIC_BUILD
106 JNIEXPORT jint JNICALL Agent_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) {
107 return Agent_Initialize(jvm, options, reserved);
108 }
109 JNIEXPORT jint JNICALL Agent_OnAttach_hs103t002(JavaVM *jvm, char *options, void *reserved) {
110 return Agent_Initialize(jvm, options, reserved);
111 }
112 JNIEXPORT jint JNI_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) {
113 return JNI_VERSION_1_8;
114 }
115 #endif
116
117 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
118 jint rc;
133 caps.can_redefine_classes = 1;
134 jvmti->AddCapabilities(&caps);
135 }
136 return JNI_OK;
137 }
138
139 JNIEXPORT jboolean JNICALL
140 Java_nsk_jvmti_scenarios_hotswap_HS103_hs103t002_hs103t002_startAgentThread(JNIEnv * jni, jclass cls) {
141 jvmtiError err ;
142 jthread thread;
143 jclass clas;
144 jmethodID method;
145 const char * threadName = "Agent Thread";
146 jobject name;
147
148 nsk_printf("hs103t002_startAgentThread\n");
149
150 name = jni->NewStringUTF(threadName);
151 clas = jni->FindClass("java/lang/Thread");
152
153 if (!NSK_JNI_VERIFY(jni, (method = NSK_CPP_STUB4(GetMethodID,
154 jni, clas, "<init>","(Ljava/lang/String;)V")) != NULL)) {
155 NSK_CPP_STUB2(FatalError, jni,
156 "failed to get ID for the java method\n");
157 }
158
159 thread = (jthread) jni->NewObject(clas,method,name);
160 testAgentThread = jni->NewGlobalRef(thread);
161 err = JVMTI_ERROR_NONE;
162 err = jvmti->RunAgentThread(testAgentThread, &doRedefineInNativeThread, NULL,
163 JVMTI_THREAD_NORM_PRIORITY);
164 if (err == JVMTI_ERROR_INVALID_PRIORITY) {
165 nsk_printf(" JVMTI_ERROR_INVALID_PRIORITY ..\n");
166 return JNI_ERR;
167 } else if ( err == JVMTI_ERROR_INVALID_THREAD) {
168 nsk_printf(" JVMTI_ERROR_INVALID_THREAD ..\n");
169 return JNI_ERR;
170 } else if (err == JVMTI_ERROR_NULL_POINTER) {
171 nsk_printf(" JVMTI_ERROR_NULL_POINTER ..\n");
172 return JNI_ERR;
173 } else {
174 nsk_printf(" Agent Thread Created.. \n");
175 }
176 return JNI_OK;
|
40 #define MAIN_CLASS "nsk/jvmti/scenarios/hotswap/HS103/hs103t002/hs103t002"
41
42 static jvmtiEnv * jvmti;
43 static jthread testAgentThread;
44
45 JNIEXPORT void JNICALL doRedefineInNativeThread(jvmtiEnv * jvmti,
46 JNIEnv * jni, void * arg) {
47 jclass cla;
48 int i = 0;
49 int redefineNumber = 0;
50 char fileName[512];
51
52 jclass testClass;
53
54 jmethodID setRedefinitionDone;
55 jmethodID setRedefinitionFailed;
56
57 testClass = jni->FindClass(MAIN_CLASS);
58
59 if (!NSK_JNI_VERIFY(jni, (
60 setRedefinitionFailed = jni->GetStaticMethodID(testClass, "setRedefinitionFailed", "()V")) != NULL))
61 {
62 jni->FatalError("TEST FAILED: while getting setRedefinitionFailed()\n");
63 }
64
65 if (!NSK_JNI_VERIFY(jni, (
66 setRedefinitionDone = jni->GetStaticMethodID(testClass, "setRedefinitionDone", "()V")) != NULL))
67 {
68 jni->FatalError("TEST FAILED: while getting setRedefinitionDone()\n");
69 }
70
71 nsk_printf("doRedefineInNativeThread\n");
72 cla = jni->FindClass(SEARCH_NAME);
73 nsk_jvmti_getFileName(redefineNumber, FILE_NAME, fileName, sizeof(fileName)/sizeof(char));
74 for(i = 0; i < 30; i++) {
75 nsk_printf(" Inside the redefine method..\n");
76 if ( nsk_jvmti_redefineClass(jvmti, cla,fileName) == NSK_TRUE) {
77 nsk_printf("\nMyClass :: Successfully redefined..\n");
78 } else {
79 nsk_printf("\nMyClass :: Failed to redefine ..\n");
80
81 if (!NSK_JNI_VERIFY_VOID(jni, jni->CallStaticVoidMethod(testClass, setRedefinitionFailed)))
82 {
83 jni->FatalError("TEST FAILED: while calling setRedefinitionFailed()\n");
84 }
85 }
86 }
87
88 if (!NSK_JNI_VERIFY_VOID(jni, jni->CallStaticVoidMethod(testClass, setRedefinitionDone)))
89 {
90 jni->FatalError("TEST FAILED: while calling setRedefinitionDone()\n");
91 }
92
93 nsk_printf(" All 30 redefinitions are done..\n");
94 }
95
96
97 #ifdef STATIC_BUILD
98 JNIEXPORT jint JNICALL Agent_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) {
99 return Agent_Initialize(jvm, options, reserved);
100 }
101 JNIEXPORT jint JNICALL Agent_OnAttach_hs103t002(JavaVM *jvm, char *options, void *reserved) {
102 return Agent_Initialize(jvm, options, reserved);
103 }
104 JNIEXPORT jint JNI_OnLoad_hs103t002(JavaVM *jvm, char *options, void *reserved) {
105 return JNI_VERSION_1_8;
106 }
107 #endif
108
109 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved) {
110 jint rc;
125 caps.can_redefine_classes = 1;
126 jvmti->AddCapabilities(&caps);
127 }
128 return JNI_OK;
129 }
130
131 JNIEXPORT jboolean JNICALL
132 Java_nsk_jvmti_scenarios_hotswap_HS103_hs103t002_hs103t002_startAgentThread(JNIEnv * jni, jclass cls) {
133 jvmtiError err ;
134 jthread thread;
135 jclass clas;
136 jmethodID method;
137 const char * threadName = "Agent Thread";
138 jobject name;
139
140 nsk_printf("hs103t002_startAgentThread\n");
141
142 name = jni->NewStringUTF(threadName);
143 clas = jni->FindClass("java/lang/Thread");
144
145 if (!NSK_JNI_VERIFY(jni, (method = jni->GetMethodID(clas, "<init>", "(Ljava/lang/String;)V")) != NULL)) {
146 jni->FatalError("failed to get ID for the java method\n");
147 }
148
149 thread = (jthread) jni->NewObject(clas,method,name);
150 testAgentThread = jni->NewGlobalRef(thread);
151 err = JVMTI_ERROR_NONE;
152 err = jvmti->RunAgentThread(testAgentThread, &doRedefineInNativeThread, NULL,
153 JVMTI_THREAD_NORM_PRIORITY);
154 if (err == JVMTI_ERROR_INVALID_PRIORITY) {
155 nsk_printf(" JVMTI_ERROR_INVALID_PRIORITY ..\n");
156 return JNI_ERR;
157 } else if ( err == JVMTI_ERROR_INVALID_THREAD) {
158 nsk_printf(" JVMTI_ERROR_INVALID_THREAD ..\n");
159 return JNI_ERR;
160 } else if (err == JVMTI_ERROR_NULL_POINTER) {
161 nsk_printf(" JVMTI_ERROR_NULL_POINTER ..\n");
162 return JNI_ERR;
163 } else {
164 nsk_printf(" Agent Thread Created.. \n");
165 }
166 return JNI_OK;
|