< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/SetNativeMethodPrefix/SetNativeMethodPrefix001/SetNativeMethodPrefix001.cpp

Print this page
rev 52100 : 8212082: Remove the NSK_CPP_STUB macros for remaining vmTestbase/jvmti/[sS]*
Summary:
Reviewed-by:


 106     (void *) &wrapped_foo,
 107 };
 108 
 109 /* ============================================================================= */
 110 
 111 static jvmtiEnv *jvmti = NULL;
 112 
 113 /* ============================================================================= */
 114 
 115 JNIEXPORT jboolean JNICALL
 116 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMethodPrefix (
 117         JNIEnv *jni
 118         , jclass klass
 119         , jstring prefix
 120         )
 121 {
 122     jboolean result = JNI_TRUE;
 123     char *str = NULL;
 124 
 125     if (prefix != NULL) {
 126         if (!NSK_VERIFY(
 127                 (str = (char *) NSK_CPP_STUB3(
 128                               GetStringUTFChars
 129                               , jni
 130                               , prefix
 131                               , 0
 132                          )
 133                     ) != NULL
 134                 )
 135            )
 136         { result = JNI_FALSE; goto finally; }
 137     }
 138 
 139     if (!NSK_JVMTI_VERIFY(
 140                 NSK_CPP_STUB2(
 141                     SetNativeMethodPrefix
 142                     , jvmti
 143                     , str
 144                     )
 145                 )
 146        )
 147     { result = JNI_FALSE; goto finally; }
 148 
 149     if (str != NULL) {
 150         NSK_DISPLAY1("New PREFIX is set: %s\n"
 151                 , str
 152                 );
 153     } else {
 154         NSK_DISPLAY0("Old PREFIX is reset\n");
 155     }
 156 
 157 finally:
 158     if (str != NULL) {
 159         jni->ReleaseStringUTFChars(prefix, str);
 160     }
 161 
 162     return JNI_TRUE;
 163 }
 164 
 165 /* ============================================================================= */
 166 
 167 JNIEXPORT jboolean JNICALL
 168 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMultiplePrefixes (
 169         JNIEnv *jni
 170         , jclass klass
 171         , jstring prefix
 172         )
 173 {
 174     jboolean result = JNI_TRUE;
 175     char *str = NULL;
 176 
 177     if (prefix != NULL) {
 178         if (!NSK_VERIFY(
 179                 (str = (char *) NSK_CPP_STUB3(
 180                               GetStringUTFChars
 181                               , jni
 182                               , prefix
 183                               , 0
 184                          )
 185                     ) != NULL
 186                 )
 187            )
 188         { result = JNI_FALSE; goto finally; }
 189 
 190         if (!NSK_JVMTI_VERIFY(
 191                     NSK_CPP_STUB3(
 192                         SetNativeMethodPrefixes
 193                         , jvmti
 194                         , 1
 195                         , (char **) &str
 196                         )
 197                     )
 198            )
 199         { result = JNI_FALSE; goto finally; }
 200 
 201         NSK_DISPLAY1("MultiplePrefixes: New PREFIX is set: %s\n"
 202                 , str
 203                 );
 204     } else {
 205         char* prefixes[1];
 206         prefixes[0] = NULL;
 207 
 208         if (!NSK_JVMTI_VERIFY(
 209                     NSK_CPP_STUB3(
 210                         SetNativeMethodPrefixes
 211                         , jvmti
 212                         , 0
 213                         , (char **)&prefixes
 214                         )
 215                     )
 216            )
 217         { result = JNI_FALSE; goto finally; }
 218 
 219         NSK_DISPLAY0("Old PREFIX is reset\n");
 220     }
 221 
 222 finally:
 223     if (str != NULL) {
 224         jni->ReleaseStringUTFChars(prefix, str);
 225     }
 226 
 227     return JNI_TRUE;
 228 }
 229 
 230 /* ============================================================================= */
 231 
 232 JNIEXPORT jboolean JNICALL
 233 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_registerMethod (
 234         JNIEnv *jni
 235         , jclass klass
 236         , jclass bound_klass
 237         , jstring method_name_obj
 238         , jstring method_sig_obj
 239         , jint native_method_number
 240         )
 241 {
 242     JNINativeMethod method;
 243     jboolean result = JNI_FALSE;
 244 
 245     if (native_method_number < 0 || native_method_number >= METHODS_COUNT) {
 246         NSK_DISPLAY2("Method index is out of the bound: %d of %d"
 247                 , native_method_number
 248                 , METHODS_COUNT
 249                 );
 250         return JNI_FALSE;
 251     }
 252 
 253     if (!NSK_VERIFY(
 254             (method.name =
 255                 (char *) NSK_CPP_STUB3(
 256                      GetStringUTFChars
 257                      , jni
 258                      , method_name_obj
 259                      , 0
 260                     )
 261             ) != NULL
 262             )
 263        )
 264     {
 265         goto finally;
 266     }
 267 
 268     if (!NSK_VERIFY(
 269             (method.signature =
 270                     (char *) NSK_CPP_STUB3(
 271                          GetStringUTFChars
 272                          , jni
 273                          , method_sig_obj
 274                          , 0
 275                     )
 276             ) != NULL
 277             )
 278        )
 279     {
 280         goto finally;
 281     }
 282 
 283     method.fnPtr = (void *) METHODS[native_method_number];
 284 
 285     NSK_DISPLAY2(">>>> Register native method: %s %s\n"
 286             , method.name
 287             , method.signature
 288             );
 289 
 290     if (jni->RegisterNatives(bound_klass, (const JNINativeMethod*) &method, 1) != 0)
 291     {
 292         if (jni->ExceptionOccurred() != NULL) {
 293             jni->ExceptionClear();
 294         }
 295 
 296         goto finally;
 297     }
 298 
 299     NSK_DISPLAY0("<<<< Finished native method registration\n");


 324 JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) {
 325     return JNI_VERSION_1_8;
 326 }
 327 #endif
 328 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved)
 329 {
 330     jvmtiCapabilities caps;
 331 
 332     if (!NSK_VERIFY(
 333                 nsk_jvmti_parseOptions(options)
 334                 )
 335        )
 336         return JNI_ERR;
 337 
 338     if (!NSK_VERIFY(
 339                 (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL
 340                 )
 341        )
 342         return JNI_ERR;
 343 
 344     if (!NSK_JVMTI_VERIFY(
 345                 NSK_CPP_STUB2(
 346                     GetCapabilities
 347                     , jvmti
 348                     , &caps)
 349                 )
 350        )
 351         return JNI_ERR;
 352 
 353     // Register all necessary JVM capabilities
 354     caps.can_set_native_method_prefix = 1;
 355 
 356     if (!NSK_JVMTI_VERIFY(
 357                 NSK_CPP_STUB2(
 358                     AddCapabilities
 359                     , jvmti
 360                     , &caps)
 361                 )
 362        )
 363         return JNI_ERR;
 364 
 365     return JNI_OK;
 366 }
 367 
 368 }


 106     (void *) &wrapped_foo,
 107 };
 108 
 109 /* ============================================================================= */
 110 
 111 static jvmtiEnv *jvmti = NULL;
 112 
 113 /* ============================================================================= */
 114 
 115 JNIEXPORT jboolean JNICALL
 116 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMethodPrefix (
 117         JNIEnv *jni
 118         , jclass klass
 119         , jstring prefix
 120         )
 121 {
 122     jboolean result = JNI_TRUE;
 123     char *str = NULL;
 124 
 125     if (prefix != NULL) {
 126         if (!NSK_VERIFY((str = (char *) jni->GetStringUTFChars(prefix, 0)) != NULL))









 127         { result = JNI_FALSE; goto finally; }
 128     }
 129 
 130     if (!NSK_JVMTI_VERIFY(jvmti->SetNativeMethodPrefix(str)))







 131     { result = JNI_FALSE; goto finally; }
 132 
 133     if (str != NULL) {
 134         NSK_DISPLAY1("New PREFIX is set: %s\n"
 135                 , str
 136                 );
 137     } else {
 138         NSK_DISPLAY0("Old PREFIX is reset\n");
 139     }
 140 
 141 finally:
 142     if (str != NULL) {
 143         jni->ReleaseStringUTFChars(prefix, str);
 144     }
 145 
 146     return JNI_TRUE;
 147 }
 148 
 149 /* ============================================================================= */
 150 
 151 JNIEXPORT jboolean JNICALL
 152 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_setMultiplePrefixes (
 153         JNIEnv *jni
 154         , jclass klass
 155         , jstring prefix
 156         )
 157 {
 158     jboolean result = JNI_TRUE;
 159     char *str = NULL;
 160 
 161     if (prefix != NULL) {
 162         if (!NSK_VERIFY((str = (char *) jni->GetStringUTFChars(prefix, 0)) != NULL))









 163         { result = JNI_FALSE; goto finally; }
 164 
 165         if (!NSK_JVMTI_VERIFY(jvmti->SetNativeMethodPrefixes(1, (char **) &str)))








 166         { result = JNI_FALSE; goto finally; }
 167 
 168         NSK_DISPLAY1("MultiplePrefixes: New PREFIX is set: %s\n"
 169                 , str
 170                 );
 171     } else {
 172         char* prefixes[1];
 173         prefixes[0] = NULL;
 174 
 175         if (!NSK_JVMTI_VERIFY(jvmti->SetNativeMethodPrefixes(0, (char **)&prefixes)))








 176         { result = JNI_FALSE; goto finally; }
 177 
 178         NSK_DISPLAY0("Old PREFIX is reset\n");
 179     }
 180 
 181 finally:
 182     if (str != NULL) {
 183         jni->ReleaseStringUTFChars(prefix, str);
 184     }
 185 
 186     return JNI_TRUE;
 187 }
 188 
 189 /* ============================================================================= */
 190 
 191 JNIEXPORT jboolean JNICALL
 192 Java_nsk_jvmti_SetNativeMethodPrefix_Binder_registerMethod (
 193         JNIEnv *jni
 194         , jclass klass
 195         , jclass bound_klass
 196         , jstring method_name_obj
 197         , jstring method_sig_obj
 198         , jint native_method_number
 199         )
 200 {
 201     JNINativeMethod method;
 202     jboolean result = JNI_FALSE;
 203 
 204     if (native_method_number < 0 || native_method_number >= METHODS_COUNT) {
 205         NSK_DISPLAY2("Method index is out of the bound: %d of %d"
 206                 , native_method_number
 207                 , METHODS_COUNT
 208                 );
 209         return JNI_FALSE;
 210     }
 211 
 212     if (!NSK_VERIFY((method.name = (char *) jni->GetStringUTFChars(method_name_obj, 0)) != NULL)) {











 213         goto finally;
 214     }
 215 
 216     if (!NSK_VERIFY((method.signature = (char *) jni->GetStringUTFChars(method_sig_obj, 0)) != NULL)) {











 217         goto finally;
 218     }
 219 
 220     method.fnPtr = (void *) METHODS[native_method_number];
 221 
 222     NSK_DISPLAY2(">>>> Register native method: %s %s\n"
 223             , method.name
 224             , method.signature
 225             );
 226 
 227     if (jni->RegisterNatives(bound_klass, (const JNINativeMethod*) &method, 1) != 0)
 228     {
 229         if (jni->ExceptionOccurred() != NULL) {
 230             jni->ExceptionClear();
 231         }
 232 
 233         goto finally;
 234     }
 235 
 236     NSK_DISPLAY0("<<<< Finished native method registration\n");


 261 JNIEXPORT jint JNI_OnLoad_SetNativeMethodPrefix001(JavaVM *jvm, char *options, void *reserved) {
 262     return JNI_VERSION_1_8;
 263 }
 264 #endif
 265 jint Agent_Initialize(JavaVM *vm, char *options, void *reserved)
 266 {
 267     jvmtiCapabilities caps;
 268 
 269     if (!NSK_VERIFY(
 270                 nsk_jvmti_parseOptions(options)
 271                 )
 272        )
 273         return JNI_ERR;
 274 
 275     if (!NSK_VERIFY(
 276                 (jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL
 277                 )
 278        )
 279         return JNI_ERR;
 280 
 281     if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))






 282         return JNI_ERR;
 283 
 284     // Register all necessary JVM capabilities
 285     caps.can_set_native_method_prefix = 1;
 286 
 287     if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))






 288         return JNI_ERR;
 289 
 290     return JNI_OK;
 291 }
 292 
 293 }
< prev index next >