< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jvmti/unit/ForceEarlyReturn/earlyretvoid/earlyretvoid.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 static jvmtiEnv *jvmti = NULL;
  52 static jvmtiCapabilities caps;
  53 static jvmtiEventCallbacks callbacks;
  54 static jint errCode = PASSED;
  55 static jboolean printdump = JNI_TRUE;
  56 static jmethodID midCheckPoint = NULL;
  57 static jmethodID midRun = NULL;
  58 
  59 static jint framesExpected = 0;
  60 static jint framesCount = 0;
  61 
  62 static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretvoid$earlyretThread;";
  63 static const char *name_exp = "countDown";
  64 static const char *sig_exp = "(I)V";


 243 JNIEXPORT jint JNICALL Agent_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 244     return Agent_Initialize(jvm, options, reserved);
 245 }
 246 JNIEXPORT jint JNICALL Agent_OnAttach_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 247     return Agent_Initialize(jvm, options, reserved);
 248 }
 249 JNIEXPORT jint JNI_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 250     return JNI_VERSION_1_8;
 251 }
 252 #endif
 253 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 254     jvmtiError err;
 255     jint res;
 256 
 257     if (options != NULL && strcmp(options, "printdump") == 0) {
 258         printf("Printdump is turned on!\n");
 259 
 260         printdump = JNI_TRUE;
 261     }
 262 
 263     res = JNI_ENV_PTR(jvm)->GetEnv(JNI_ENV_ARG(jvm, (void **) &jvmti),
 264         JVMTI_VERSION_1_1);
 265     if (res != JNI_OK || jvmti == NULL) {
 266         printf("Wrong error code from a valid call to GetEnv!\n");
 267         return JNI_ERR;
 268     }
 269 
 270     err = jvmti->GetPotentialCapabilities(&caps);
 271     if (err != JVMTI_ERROR_NONE) {
 272         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
 273                TranslateError(err), err);
 274         return JNI_ERR;
 275     }
 276 
 277     err = jvmti->AddCapabilities(&caps);
 278     if (err != JVMTI_ERROR_NONE) {
 279         printf("(AddCapabilities) unexpected error: %s (%d)\n",
 280                TranslateError(err), err);
 281         return JNI_ERR;
 282     }
 283 
 284     err = jvmti->GetCapabilities(&caps);


 308 
 309     return JNI_OK;
 310 }
 311 
 312 JNIEXPORT void JNICALL
 313 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_getReady(
 314     JNIEnv *env, jclass c, jclass cls, jint depth) {
 315     jvmtiError err;
 316 
 317     if (jvmti == NULL) {
 318         printf("JVMTI client was not properly loaded!\n");
 319         RETURN_FAILED;
 320     }
 321 
 322     if (!caps.can_force_early_return ||
 323             !caps.can_generate_breakpoint_events ||
 324             !caps.can_generate_single_step_events) {
 325         return;
 326     }
 327 
 328     midRun = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 329          "run", "()V");
 330     if (midRun == NULL) {
 331         printf("Cannot find Method ID for method run\n");
 332         RETURN_FAILED;
 333     }
 334 
 335     midCheckPoint = JNI_ENV_PTR(env)->GetMethodID(JNI_ENV_ARG(env, cls),
 336          "checkPoint", "()V");
 337     if (midCheckPoint == NULL) {
 338         printf("Cannot find Method ID for method checkPoint\n");
 339         RETURN_FAILED;
 340     }
 341 
 342     err = jvmti->SetBreakpoint(midCheckPoint, 0);
 343     if (err != JVMTI_ERROR_NONE) {
 344         printf("(SetBreakpoint) unexpected error: %s (%d)\n",
 345                TranslateError(err), err);
 346         RETURN_FAILED;
 347     }
 348 
 349     err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
 350         JVMTI_EVENT_BREAKPOINT, NULL);
 351     if (err != JVMTI_ERROR_NONE) {
 352         printf("Failed to enable BREAKPOINT event: %s (%d)\n",
 353                TranslateError(err), err);
 354         RETURN_FAILED;
 355     } else {
 356         framesExpected = depth;
 357     }
 358     fflush(0);
 359 }
 360 
 361 JNIEXPORT jint JNICALL
 362 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_check(JNIEnv *env, jclass cls) {
 363     if (framesCount != framesExpected) {
 364         printf("Wrong number of returned early frames: %d, expected: %d\n",
 365             framesCount, framesExpected);
 366         errCode = STATUS_FAILED;
 367     }
 368     fflush(0);
 369     return errCode;
 370 }
 371 
 372 #ifdef __cplusplus
 373 }
 374 #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 static jvmtiEnv *jvmti = NULL;
  39 static jvmtiCapabilities caps;
  40 static jvmtiEventCallbacks callbacks;
  41 static jint errCode = PASSED;
  42 static jboolean printdump = JNI_TRUE;
  43 static jmethodID midCheckPoint = NULL;
  44 static jmethodID midRun = NULL;
  45 
  46 static jint framesExpected = 0;
  47 static jint framesCount = 0;
  48 
  49 static const char *cls_exp = "Lnsk/jvmti/unit/ForceEarlyReturn/earlyretvoid$earlyretThread;";
  50 static const char *name_exp = "countDown";
  51 static const char *sig_exp = "(I)V";


 230 JNIEXPORT jint JNICALL Agent_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 231     return Agent_Initialize(jvm, options, reserved);
 232 }
 233 JNIEXPORT jint JNICALL Agent_OnAttach_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 234     return Agent_Initialize(jvm, options, reserved);
 235 }
 236 JNIEXPORT jint JNI_OnLoad_earlyretvoid(JavaVM *jvm, char *options, void *reserved) {
 237     return JNI_VERSION_1_8;
 238 }
 239 #endif
 240 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 241     jvmtiError err;
 242     jint res;
 243 
 244     if (options != NULL && strcmp(options, "printdump") == 0) {
 245         printf("Printdump is turned on!\n");
 246 
 247         printdump = JNI_TRUE;
 248     }
 249 
 250     res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);

 251     if (res != JNI_OK || jvmti == NULL) {
 252         printf("Wrong error code from a valid call to GetEnv!\n");
 253         return JNI_ERR;
 254     }
 255 
 256     err = jvmti->GetPotentialCapabilities(&caps);
 257     if (err != JVMTI_ERROR_NONE) {
 258         printf("(GetPotentialCapabilities) unexpected error: %s (%d)\n",
 259                TranslateError(err), err);
 260         return JNI_ERR;
 261     }
 262 
 263     err = jvmti->AddCapabilities(&caps);
 264     if (err != JVMTI_ERROR_NONE) {
 265         printf("(AddCapabilities) unexpected error: %s (%d)\n",
 266                TranslateError(err), err);
 267         return JNI_ERR;
 268     }
 269 
 270     err = jvmti->GetCapabilities(&caps);


 294 
 295     return JNI_OK;
 296 }
 297 
 298 JNIEXPORT void JNICALL
 299 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_getReady(
 300     JNIEnv *env, jclass c, jclass cls, jint depth) {
 301     jvmtiError err;
 302 
 303     if (jvmti == NULL) {
 304         printf("JVMTI client was not properly loaded!\n");
 305         RETURN_FAILED;
 306     }
 307 
 308     if (!caps.can_force_early_return ||
 309             !caps.can_generate_breakpoint_events ||
 310             !caps.can_generate_single_step_events) {
 311         return;
 312     }
 313 
 314     midRun = env->GetMethodID(cls, "run", "()V");

 315     if (midRun == NULL) {
 316         printf("Cannot find Method ID for method run\n");
 317         RETURN_FAILED;
 318     }
 319 
 320     midCheckPoint = env->GetMethodID(cls, "checkPoint", "()V");

 321     if (midCheckPoint == NULL) {
 322         printf("Cannot find Method ID for method checkPoint\n");
 323         RETURN_FAILED;
 324     }
 325 
 326     err = jvmti->SetBreakpoint(midCheckPoint, 0);
 327     if (err != JVMTI_ERROR_NONE) {
 328         printf("(SetBreakpoint) unexpected error: %s (%d)\n",
 329                TranslateError(err), err);
 330         RETURN_FAILED;
 331     }
 332 
 333     err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
 334         JVMTI_EVENT_BREAKPOINT, NULL);
 335     if (err != JVMTI_ERROR_NONE) {
 336         printf("Failed to enable BREAKPOINT event: %s (%d)\n",
 337                TranslateError(err), err);
 338         RETURN_FAILED;
 339     } else {
 340         framesExpected = depth;
 341     }
 342     fflush(0);
 343 }
 344 
 345 JNIEXPORT jint JNICALL
 346 Java_nsk_jvmti_unit_ForceEarlyReturn_earlyretvoid_check(JNIEnv *env, jclass cls) {
 347     if (framesCount != framesExpected) {
 348         printf("Wrong number of returned early frames: %d, expected: %d\n",
 349             framesCount, framesExpected);
 350         errCode = STATUS_FAILED;
 351     }
 352     fflush(0);
 353     return errCode;
 354 }
 355 

 356 }

< prev index next >