11/*
2- * Copyright (c) 2003, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2003, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2929
3030extern " C" {
3131
32- #define STATUS_FAILED 2
33- #define PASSED 0
34-
35- static volatile jint result = PASSED;
36- static volatile long wrongStepEv = 0 ;
3732
3833static jvmtiEnv *jvmti = nullptr ;
3934
@@ -44,31 +39,25 @@ SingleStep(jvmtiEnv *jvmti, JNIEnv *jni, jthread thread, jmethodID method, jloca
4439 jvmtiError err;
4540
4641 err = jvmti->GetPhase (&phase);
47- if (err != JVMTI_ERROR_NONE) {
48- result = STATUS_FAILED;
49- COMPLAIN (" TEST FAILED: unable to obtain phase of the VM execution during SingleStep callback\n\n " );
50- } else {
51- if (phase != JVMTI_PHASE_LIVE) {
52- wrongStepEv++;
53- result = STATUS_FAILED;
54- COMPLAIN (" TEST FAILED: SingleStep event received during non-live phase %s\n " , TranslatePhase (phase));
55- }
42+ check_jvmti_status (jni, err, " Error in GetPhase" );
43+ if (phase != JVMTI_PHASE_LIVE) {
44+ COMPLAIN (" TEST FAILED: SingleStep event received during non-live phase %s\n " , TranslatePhase (phase));
45+ jni->FatalError (" Event SingleStep event received during non-live phase." );
5646 }
5747}
5848
49+ /*
50+ * The ClassLoad event is not used. This is thread filtered event that should
51+ * be sent during start phase. It is enabled to trigger creation of jvmti thread state
52+ * in the START phase. So test ensures that even jvmti state for thread is created
53+ * before live phase the SingleStep event is sent only during live phase.
54+ */
5955void JNICALL
60- VMDeath (jvmtiEnv *jvmti, JNIEnv *jni) {
61- LOG (" VMDeath event received\n " );
62-
63- if (wrongStepEv != 0 ) {
64- LOG (" TEST FAILED: there are %ld SingleStep events\n "
65- " sent during non-live phase of the VM execution\n " , wrongStepEv);
66- jni->FatalError (" Test Failed." );
67- }
56+ ClassLoad (jvmtiEnv *jvmti_env,
57+ JNIEnv* jni_env,
58+ jthread thread,
59+ jclass klass) {
6860
69- if (result == STATUS_FAILED) {
70- jni->FatalError (" Test Failed." );
71- }
7261}
7362
7463jint Agent_Initialize (JavaVM *jvm, char *options, void *reserved) {
@@ -105,19 +94,20 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
10594 /* set event callback */
10695 LOG (" setting event callbacks ...\n " );
10796 (void ) memset (&callbacks, 0 , sizeof (callbacks));
97+ callbacks.ClassLoad = &ClassLoad;
10898 callbacks.SingleStep = &SingleStep;
109- callbacks.VMDeath = &VMDeath;
11099 err = jvmti->SetEventCallbacks (&callbacks, sizeof (callbacks));
111100 if (err != JVMTI_ERROR_NONE) {
112101 return JNI_ERR;
113102 }
114103
115104 LOG (" setting event callbacks done\n enabling JVMTI events ...\n " );
116- err = jvmti->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, nullptr );
105+
106+ err = jvmti->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_CLASS_LOAD, nullptr );
117107 if (err != JVMTI_ERROR_NONE) {
118108 return JNI_ERR;
119109 }
120- err = jvmti->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH , nullptr );
110+ err = jvmti->SetEventNotificationMode (JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP , nullptr );
121111 if (err != JVMTI_ERROR_NONE) {
122112 return JNI_ERR;
123113 }
0 commit comments