annotate test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep002/singlestep002.cpp @ 51870:cdfabab3413f

8210689: Remove the multi-line old C style for string literals Summary: Remove the multi-line old C style and prefer C++ multi-line Reviewed-by: amenkov, cjplummer
author jcbeyler
date Tue, 25 Sep 2018 09:34:51 -0700
parents 79dc492c00ab
children 0b0ba3a2fec9
rev   line source
iignatyev@50260 1 /*
iignatyev@50260 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
iignatyev@50260 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iignatyev@50260 4 *
iignatyev@50260 5 * This code is free software; you can redistribute it and/or modify it
iignatyev@50260 6 * under the terms of the GNU General Public License version 2 only, as
iignatyev@50260 7 * published by the Free Software Foundation.
iignatyev@50260 8 *
iignatyev@50260 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iignatyev@50260 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iignatyev@50260 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iignatyev@50260 12 * version 2 for more details (a copy is included in the LICENSE file that
iignatyev@50260 13 * accompanied this code).
iignatyev@50260 14 *
iignatyev@50260 15 * You should have received a copy of the GNU General Public License version
iignatyev@50260 16 * 2 along with this work; if not, write to the Free Software Foundation,
iignatyev@50260 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iignatyev@50260 18 *
iignatyev@50260 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iignatyev@50260 20 * or visit www.oracle.com if you need additional information or have any
iignatyev@50260 21 * questions.
iignatyev@50260 22 */
iignatyev@50260 23
iignatyev@50260 24 #include <stdio.h>
iignatyev@50260 25 #include <stdlib.h>
iignatyev@50260 26 #include <string.h>
iignatyev@50260 27 #include <jvmti.h>
iignatyev@50260 28 #include "agent_common.h"
iignatyev@50260 29
iignatyev@50260 30 #include "nsk_tools.h"
iignatyev@50260 31 #include "JVMTITools.h"
iignatyev@50260 32 #include "jvmti_tools.h"
iignatyev@50260 33 #include "jni_tools.h"
iignatyev@50260 34
iignatyev@50260 35 extern "C" {
iignatyev@50260 36
iignatyev@50260 37 #define STATUS_FAILED 2
iignatyev@50260 38 #define PASSED 0
iignatyev@50260 39
iignatyev@50260 40 static volatile jint result = PASSED;
iignatyev@50260 41 static volatile long wrongStepEv = 0;
iignatyev@50260 42
iignatyev@50260 43 static jvmtiEnv *jvmti = NULL;
iignatyev@50260 44 static jvmtiEventCallbacks callbacks;
iignatyev@50260 45 static jvmtiCapabilities caps;
iignatyev@50260 46
iignatyev@50260 47 /** callback functions **/
iignatyev@50260 48 void JNICALL
iignatyev@50260 49 SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
iignatyev@50260 50 jmethodID method, jlocation location) {
iignatyev@50260 51 jvmtiPhase phase;
iignatyev@50260 52
iignatyev@50260 53 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase,
iignatyev@50260 54 jvmti_env, &phase))) {
iignatyev@50260 55 result = STATUS_FAILED;
iignatyev@50260 56 NSK_COMPLAIN0("TEST FAILED: unable to obtain phase of the VM execution during SingleStep callback\n\n");
iignatyev@50260 57 }
iignatyev@50260 58 else {
iignatyev@50260 59 if (phase != JVMTI_PHASE_LIVE) {
iignatyev@50260 60 wrongStepEv++;
iignatyev@50260 61 result = STATUS_FAILED;
iignatyev@50260 62 NSK_COMPLAIN1("TEST FAILED: SingleStep event received during non-live phase %s\n",
iignatyev@50260 63 TranslatePhase(phase));
iignatyev@50260 64 }
iignatyev@50260 65 }
iignatyev@50260 66 }
iignatyev@50260 67
iignatyev@50260 68 void JNICALL
iignatyev@50260 69 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
iignatyev@50260 70 NSK_DISPLAY0("VMDeath event received\n");
iignatyev@50260 71
jcbeyler@51870 72 if (wrongStepEv != 0) {
jcbeyler@51870 73 NSK_COMPLAIN1(
jcbeyler@51870 74 "TEST FAILED: there are %d SingleStep events\n"
jcbeyler@51870 75 "sent during non-live phase of the VM execution\n",
iignatyev@50260 76 wrongStepEv);
jcbeyler@51870 77 }
iignatyev@50260 78
iignatyev@50260 79 if (result == STATUS_FAILED)
iignatyev@50260 80 exit(95 + STATUS_FAILED);
iignatyev@50260 81 }
iignatyev@50260 82 /************************/
iignatyev@50260 83
iignatyev@50260 84 #ifdef STATIC_BUILD
iignatyev@50260 85 JNIEXPORT jint JNICALL Agent_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 86 return Agent_Initialize(jvm, options, reserved);
iignatyev@50260 87 }
iignatyev@50260 88 JNIEXPORT jint JNICALL Agent_OnAttach_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 89 return Agent_Initialize(jvm, options, reserved);
iignatyev@50260 90 }
iignatyev@50260 91 JNIEXPORT jint JNI_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 92 return JNI_VERSION_1_8;
iignatyev@50260 93 }
iignatyev@50260 94 #endif
iignatyev@50260 95 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 96 /* init framework and parse options */
iignatyev@50260 97 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
iignatyev@50260 98 return JNI_ERR;
iignatyev@50260 99
iignatyev@50260 100 /* create JVMTI environment */
iignatyev@50260 101 if (!NSK_VERIFY((jvmti =
iignatyev@50260 102 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
iignatyev@50260 103 return JNI_ERR;
iignatyev@50260 104
iignatyev@50260 105 /* add capability to generate compiled method events */
iignatyev@50260 106 memset(&caps, 0, sizeof(jvmtiCapabilities));
iignatyev@50260 107 caps.can_generate_single_step_events = 1;
iignatyev@50260 108 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities,
iignatyev@50260 109 jvmti, &caps)))
iignatyev@50260 110 return JNI_ERR;
iignatyev@50260 111
iignatyev@50260 112 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities,
iignatyev@50260 113 jvmti, &caps)))
iignatyev@50260 114 return JNI_ERR;
iignatyev@50260 115
iignatyev@50260 116 if (!caps.can_generate_single_step_events)
iignatyev@50260 117 NSK_DISPLAY0("Warning: generation of single step events is not implemented\n");
iignatyev@50260 118
iignatyev@50260 119 /* set event callback */
iignatyev@50260 120 NSK_DISPLAY0("setting event callbacks ...\n");
iignatyev@50260 121 (void) memset(&callbacks, 0, sizeof(callbacks));
iignatyev@50260 122 callbacks.SingleStep = &SingleStep;
iignatyev@50260 123 callbacks.VMDeath = &VMDeath;
iignatyev@50260 124 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
iignatyev@50260 125 jvmti, &callbacks, sizeof(callbacks))))
iignatyev@50260 126 return JNI_ERR;
iignatyev@50260 127
iignatyev@50260 128 NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
iignatyev@50260 129 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
iignatyev@50260 130 jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)))
iignatyev@50260 131 return JNI_ERR;
iignatyev@50260 132 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
iignatyev@50260 133 jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
iignatyev@50260 134 return JNI_ERR;
iignatyev@50260 135 NSK_DISPLAY0("enabling the events done\n\n");
iignatyev@50260 136
iignatyev@50260 137 return JNI_OK;
iignatyev@50260 138 }
iignatyev@50260 139
iignatyev@50260 140 }