< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretfp/earlyretfp.cpp

Print this page
rev 51722 : 8210700: Clean up JNI_ENV_ARG and factorize the macros for vmTestbase/jvmti/unit tests
Summary:
Reviewed-by:


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 #include "jvmti.h"
  27 #include "agent_common.h"
  28 #include "JVMTITools.h"
  29 
  30 #ifdef __cplusplus
  31 extern "C" {
  32 #endif
  33 
  34 #ifndef JNI_ENV_ARG
  35 
  36 #ifdef __cplusplus
  37 #define JNI_ENV_ARG(x, y) y
  38 #define JNI_ENV_PTR(x) x
  39 #else
  40 #define JNI_ENV_ARG(x,y) x, y
  41 #define JNI_ENV_PTR(x) (*x)
  42 #endif
  43 
  44 #endif
  45 
  46 #define PASSED 0
  47 #define STATUS_FAILED 2
  48 
  49 #define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return
  50 
  51 #define METHCNT 2
  52 static jvmtiEnv *jvmti = NULL;
  53 static jvmtiCapabilities caps;
  54 static jvmtiEventCallbacks callbacks;
  55 static jint errCode = PASSED;
  56 static jboolean printdump = JNI_TRUE;
  57 static jmethodID midCheckPoint      = NULL;
  58 static jmethodID midRun             = NULL;
  59 static jmethodID midCountDownFloat  = NULL;
  60 static jmethodID midCountDownDouble = NULL;
  61 
  62 /* There is no synchronization for the counters because
  63  * they are incremented in single threaded mode.
  64  */


 309 JNIEXPORT jint JNICALL Agent_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 310     return Agent_Initialize(jvm, options, reserved);
 311 }
 312 JNIEXPORT jint JNICALL Agent_OnAttach_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 313     return Agent_Initialize(jvm, options, reserved);
 314 }
 315 JNIEXPORT jint JNI_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 316     return JNI_VERSION_1_8;
 317 }
 318 #endif
 319 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 320     jvmtiError err;
 321     jint res;
 322 
 323     if (options != NULL && strcmp(options, "printdump") == 0) {
 324         printf("Printdump is turned on!\n");
 325 
 326         printdump = JNI_TRUE;
 327     }
 328 
 329     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
 330         JVMTI_VERSION_1_1);
 331     if (res != JNI_OK || jvmti == NULL) {
 332         printf("Wrong error code from a valid call to GetEnv!\n");
 333         return JNI_ERR;
 334     }
 335 
 336     err = jvmti->GetPotentialCapabilities(&caps);
 337     if (err != JVMTI_ERROR_NONE) {
 338         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
 339                TranslateError(err), err);
 340         return JNI_ERR;
 341     }
 342 
 343     err = jvmti->AddCapabilities(&caps);
 344     if (err != JVMTI_ERROR_NONE) {
 345         printf("(AddCapabilities) unexpected error: %s (%d)\n",
 346                TranslateError(err), err);
 347         return JNI_ERR;
 348     }
 349 
 350     err = jvmti->GetCapabilities(&caps);


 379     return JNI_OK;
 380 }
 381 
 382 JNIEXPORT void JNICALL
 383 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_getReady(
 384     JNIEnv *env, jclass c, jclass cls, jint depth, jdouble retval) {
 385     jvmtiError err;
 386 
 387     if (jvmti == NULL) {
 388         printf("JVMTI client was not properly loaded!\n");
 389         RETURN_FAILED;
 390     }
 391 
 392     if (!caps.can_force_early_return ||
 393         !caps.can_generate_breakpoint_events ||
 394         !caps.can_generate_method_exit_events ||
 395         !caps.can_generate_single_step_events) {
 396         return;
 397     }
 398 
 399     midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 400          "run", "()V");
 401     if (midRun == NULL) {
 402         printf("Cannot find Method ID for method run\n");
 403         RETURN_FAILED;
 404     }
 405 
 406     midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 407          "checkPoint", "()V");
 408     if (midCheckPoint == NULL) {
 409         printf("Cannot find Method ID for method checkPoint\n");
 410         RETURN_FAILED;
 411     }
 412 
 413     midCountDownFloat = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 414          "countDownFloat", "(I)F");
 415     if (midCountDownFloat == NULL) {
 416         printf("Cannot find Method ID for method countDownFloat\n");
 417         RETURN_FAILED;
 418     }
 419 
 420     midCountDownDouble = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 421          "countDownDouble", "(I)D");
 422     if (midCountDownDouble == NULL) {
 423         printf("Cannot find Method ID for method countDownDouble\n");
 424         RETURN_FAILED;
 425     }
 426 
 427     err = jvmti->SetBreakpoint(midCheckPoint, 0);
 428     if (err != JVMTI_ERROR_NONE) {
 429         printf("(SetBreakpoint) unexpected error: %s (%d)\n",
 430                TranslateError(err), err);
 431         RETURN_FAILED;
 432     }
 433 
 434     err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
 435         JVMTI_EVENT_BREAKPOINT, NULL);
 436     if (err != JVMTI_ERROR_NONE) {
 437         printf("Failed to enable BREAKPOINT event: %s (%d)\n",
 438                TranslateError(err), err);
 439         RETURN_FAILED;
 440     } else {
 441         framesExpected = depth;


 456 JNIEXPORT void JNICALL
 457 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printDouble(
 458       JNIEnv *env, jclass cls, jdouble val) {
 459 
 460     printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val);
 461     fflush(0);
 462     return;
 463 }
 464 
 465 JNIEXPORT jint JNICALL
 466 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_check(JNIEnv *env, jclass cls) {
 467     if (framesCount != framesExpected) {
 468         printf("Wrong number of returned early frames: %d, expected: %d\n",
 469             framesCount, framesExpected);
 470         errCode = STATUS_FAILED;
 471     }
 472     fflush(0);
 473     return errCode;
 474 }
 475 
 476 #ifdef __cplusplus
 477 }
 478 #endif


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 #include <stdio.h>
  25 #include <string.h>
  26 #include "jvmti.h"
  27 #include "agent_common.h"
  28 #include "JVMTITools.h"
  29 

  30 extern "C" {











  31 

  32 
  33 #define PASSED 0
  34 #define STATUS_FAILED 2
  35 
  36 #define RETURN_FAILED errCode = STATUS_FAILED; fflush(0); return
  37 
  38 #define METHCNT 2
  39 static jvmtiEnv *jvmti = NULL;
  40 static jvmtiCapabilities caps;
  41 static jvmtiEventCallbacks callbacks;
  42 static jint errCode = PASSED;
  43 static jboolean printdump = JNI_TRUE;
  44 static jmethodID midCheckPoint      = NULL;
  45 static jmethodID midRun             = NULL;
  46 static jmethodID midCountDownFloat  = NULL;
  47 static jmethodID midCountDownDouble = NULL;
  48 
  49 /* There is no synchronization for the counters because
  50  * they are incremented in single threaded mode.
  51  */


 296 JNIEXPORT jint JNICALL Agent_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 297     return Agent_Initialize(jvm, options, reserved);
 298 }
 299 JNIEXPORT jint JNICALL Agent_OnAttach_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 300     return Agent_Initialize(jvm, options, reserved);
 301 }
 302 JNIEXPORT jint JNI_OnLoad_earlyretfp(JavaVM *jvm, char *options, void *reserved) {
 303     return JNI_VERSION_1_8;
 304 }
 305 #endif
 306 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 307     jvmtiError err;
 308     jint res;
 309 
 310     if (options != NULL && strcmp(options, "printdump") == 0) {
 311         printf("Printdump is turned on!\n");
 312 
 313         printdump = JNI_TRUE;
 314     }
 315 
 316     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

 317     if (res != JNI_OK || jvmti == NULL) {
 318         printf("Wrong error code from a valid call to GetEnv!\n");
 319         return JNI_ERR;
 320     }
 321 
 322     err = jvmti->GetPotentialCapabilities(&caps);
 323     if (err != JVMTI_ERROR_NONE) {
 324         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
 325                TranslateError(err), err);
 326         return JNI_ERR;
 327     }
 328 
 329     err = jvmti->AddCapabilities(&caps);
 330     if (err != JVMTI_ERROR_NONE) {
 331         printf("(AddCapabilities) unexpected error: %s (%d)\n",
 332                TranslateError(err), err);
 333         return JNI_ERR;
 334     }
 335 
 336     err = jvmti->GetCapabilities(&caps);


 365     return JNI_OK;
 366 }
 367 
 368 JNIEXPORT void JNICALL
 369 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_getReady(
 370     JNIEnv *env, jclass c, jclass cls, jint depth, jdouble retval) {
 371     jvmtiError err;
 372 
 373     if (jvmti == NULL) {
 374         printf("JVMTI client was not properly loaded!\n");
 375         RETURN_FAILED;
 376     }
 377 
 378     if (!caps.can_force_early_return ||
 379         !caps.can_generate_breakpoint_events ||
 380         !caps.can_generate_method_exit_events ||
 381         !caps.can_generate_single_step_events) {
 382         return;
 383     }
 384 
 385     midRun = env->GetMethodID(cls, "run", "()V");

 386     if (midRun == NULL) {
 387         printf("Cannot find Method ID for method run\n");
 388         RETURN_FAILED;
 389     }
 390 
 391     midCheckPoint = env->GetMethodID(cls, "checkPoint", "()V");

 392     if (midCheckPoint == NULL) {
 393         printf("Cannot find Method ID for method checkPoint\n");
 394         RETURN_FAILED;
 395     }
 396 
 397     midCountDownFloat = env->GetMethodID(cls, "countDownFloat", "(I)F");

 398     if (midCountDownFloat == NULL) {
 399         printf("Cannot find Method ID for method countDownFloat\n");
 400         RETURN_FAILED;
 401     }
 402 
 403     midCountDownDouble = env->GetMethodID(cls, "countDownDouble", "(I)D");

 404     if (midCountDownDouble == NULL) {
 405         printf("Cannot find Method ID for method countDownDouble\n");
 406         RETURN_FAILED;
 407     }
 408 
 409     err = jvmti->SetBreakpoint(midCheckPoint, 0);
 410     if (err != JVMTI_ERROR_NONE) {
 411         printf("(SetBreakpoint) unexpected error: %s (%d)\n",
 412                TranslateError(err), err);
 413         RETURN_FAILED;
 414     }
 415 
 416     err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
 417         JVMTI_EVENT_BREAKPOINT, NULL);
 418     if (err != JVMTI_ERROR_NONE) {
 419         printf("Failed to enable BREAKPOINT event: %s (%d)\n",
 420                TranslateError(err), err);
 421         RETURN_FAILED;
 422     } else {
 423         framesExpected = depth;


 438 JNIEXPORT void JNICALL
 439 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_printDouble(
 440       JNIEnv *env, jclass cls, jdouble val) {
 441 
 442     printf("\n>>> Returned value is %8.4f, hex: %#a\n", val, val);
 443     fflush(0);
 444     return;
 445 }
 446 
 447 JNIEXPORT jint JNICALL
 448 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretfp_check(JNIEnv *env, jclass cls) {
 449     if (framesCount != framesExpected) {
 450         printf("Wrong number of returned early frames: %d, expected: %d\n",
 451             framesCount, framesExpected);
 452         errCode = STATUS_FAILED;
 453     }
 454     fflush(0);
 455     return errCode;
 456 }
 457 

 458 }

< prev index next >