33 #include "jni_tools.h"
34
35 extern "C" {
36
37 #define STATUS_FAILED 2
38 #define PASSED 0
39
40 static volatile jint result = PASSED;
41 static volatile long wrongStepEv = 0;
42
43 static jvmtiEnv *jvmti = NULL;
44 static jvmtiEventCallbacks callbacks;
45 static jvmtiCapabilities caps;
46
47 /** callback functions **/
48 void JNICALL
49 SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
50 jmethodID method, jlocation location) {
51 jvmtiPhase phase;
52
53 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetPhase,
54 jvmti_env, &phase))) {
55 result = STATUS_FAILED;
56 NSK_COMPLAIN0("TEST FAILED: unable to obtain phase of the VM execution during SingleStep callback\n\n");
57 }
58 else {
59 if (phase != JVMTI_PHASE_LIVE) {
60 wrongStepEv++;
61 result = STATUS_FAILED;
62 NSK_COMPLAIN1("TEST FAILED: SingleStep event received during non-live phase %s\n",
63 TranslatePhase(phase));
64 }
65 }
66 }
67
68 void JNICALL
69 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
70 NSK_DISPLAY0("VMDeath event received\n");
71
72 if (wrongStepEv != 0) {
73 NSK_COMPLAIN1(
74 "TEST FAILED: there are %d SingleStep events\n"
88 JNIEXPORT jint JNICALL Agent_OnAttach_singlestep002(JavaVM *jvm, char *options, void *reserved) {
89 return Agent_Initialize(jvm, options, reserved);
90 }
91 JNIEXPORT jint JNI_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
92 return JNI_VERSION_1_8;
93 }
94 #endif
95 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
96 /* init framework and parse options */
97 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
98 return JNI_ERR;
99
100 /* create JVMTI environment */
101 if (!NSK_VERIFY((jvmti =
102 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
103 return JNI_ERR;
104
105 /* add capability to generate compiled method events */
106 memset(&caps, 0, sizeof(jvmtiCapabilities));
107 caps.can_generate_single_step_events = 1;
108 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(AddCapabilities,
109 jvmti, &caps)))
110 return JNI_ERR;
111
112 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB2(GetCapabilities,
113 jvmti, &caps)))
114 return JNI_ERR;
115
116 if (!caps.can_generate_single_step_events)
117 NSK_DISPLAY0("Warning: generation of single step events is not implemented\n");
118
119 /* set event callback */
120 NSK_DISPLAY0("setting event callbacks ...\n");
121 (void) memset(&callbacks, 0, sizeof(callbacks));
122 callbacks.SingleStep = &SingleStep;
123 callbacks.VMDeath = &VMDeath;
124 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(SetEventCallbacks,
125 jvmti, &callbacks, sizeof(callbacks))))
126 return JNI_ERR;
127
128 NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
129 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
130 jvmti, JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)))
131 return JNI_ERR;
132 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
133 jvmti, JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
134 return JNI_ERR;
135 NSK_DISPLAY0("enabling the events done\n\n");
136
137 return JNI_OK;
138 }
139
140 }
|
33 #include "jni_tools.h"
34
35 extern "C" {
36
37 #define STATUS_FAILED 2
38 #define PASSED 0
39
40 static volatile jint result = PASSED;
41 static volatile long wrongStepEv = 0;
42
43 static jvmtiEnv *jvmti = NULL;
44 static jvmtiEventCallbacks callbacks;
45 static jvmtiCapabilities caps;
46
47 /** callback functions **/
48 void JNICALL
49 SingleStep(jvmtiEnv *jvmti_env, JNIEnv* jni_env, jthread thread,
50 jmethodID method, jlocation location) {
51 jvmtiPhase phase;
52
53 if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
54 result = STATUS_FAILED;
55 NSK_COMPLAIN0("TEST FAILED: unable to obtain phase of the VM execution during SingleStep callback\n\n");
56 }
57 else {
58 if (phase != JVMTI_PHASE_LIVE) {
59 wrongStepEv++;
60 result = STATUS_FAILED;
61 NSK_COMPLAIN1("TEST FAILED: SingleStep event received during non-live phase %s\n",
62 TranslatePhase(phase));
63 }
64 }
65 }
66
67 void JNICALL
68 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
69 NSK_DISPLAY0("VMDeath event received\n");
70
71 if (wrongStepEv != 0) {
72 NSK_COMPLAIN1(
73 "TEST FAILED: there are %d SingleStep events\n"
87 JNIEXPORT jint JNICALL Agent_OnAttach_singlestep002(JavaVM *jvm, char *options, void *reserved) {
88 return Agent_Initialize(jvm, options, reserved);
89 }
90 JNIEXPORT jint JNI_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
91 return JNI_VERSION_1_8;
92 }
93 #endif
94 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
95 /* init framework and parse options */
96 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
97 return JNI_ERR;
98
99 /* create JVMTI environment */
100 if (!NSK_VERIFY((jvmti =
101 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
102 return JNI_ERR;
103
104 /* add capability to generate compiled method events */
105 memset(&caps, 0, sizeof(jvmtiCapabilities));
106 caps.can_generate_single_step_events = 1;
107 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
108 return JNI_ERR;
109
110 if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
111 return JNI_ERR;
112
113 if (!caps.can_generate_single_step_events)
114 NSK_DISPLAY0("Warning: generation of single step events is not implemented\n");
115
116 /* set event callback */
117 NSK_DISPLAY0("setting event callbacks ...\n");
118 (void) memset(&callbacks, 0, sizeof(callbacks));
119 callbacks.SingleStep = &SingleStep;
120 callbacks.VMDeath = &VMDeath;
121 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
122 return JNI_ERR;
123
124 NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
125 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)))
126 return JNI_ERR;
127 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
128 return JNI_ERR;
129 NSK_DISPLAY0("enabling the events done\n\n");
130
131 return JNI_OK;
132 }
133
134 }
|