annotate test/hotspot/jtreg/vmTestbase/nsk/jvmti/SingleStep/singlestep002/singlestep002.cpp @ 57435:eefd0a71c160

8234697: Generate sun.security.util.math.intpoly classes during build Reviewed-by: erikj, mullan
author weijun
date Sat, 14 Dec 2019 13:50:34 +0800
parents cdfabab3413f
children
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
jcbeyler@52215 53 if (!NSK_JVMTI_VERIFY(jvmti_env->GetPhase(&phase))) {
iignatyev@50260 54 result = STATUS_FAILED;
iignatyev@50260 55 NSK_COMPLAIN0("TEST FAILED: unable to obtain phase of the VM execution during SingleStep callback\n\n");
iignatyev@50260 56 }
iignatyev@50260 57 else {
iignatyev@50260 58 if (phase != JVMTI_PHASE_LIVE) {
iignatyev@50260 59 wrongStepEv++;
iignatyev@50260 60 result = STATUS_FAILED;
iignatyev@50260 61 NSK_COMPLAIN1("TEST FAILED: SingleStep event received during non-live phase %s\n",
iignatyev@50260 62 TranslatePhase(phase));
iignatyev@50260 63 }
iignatyev@50260 64 }
iignatyev@50260 65 }
iignatyev@50260 66
iignatyev@50260 67 void JNICALL
iignatyev@50260 68 VMDeath(jvmtiEnv *jvmti_env, JNIEnv *env) {
iignatyev@50260 69 NSK_DISPLAY0("VMDeath event received\n");
iignatyev@50260 70
jcbeyler@51870 71 if (wrongStepEv != 0) {
jcbeyler@51870 72 NSK_COMPLAIN1(
jcbeyler@51870 73 "TEST FAILED: there are %d SingleStep events\n"
jcbeyler@51870 74 "sent during non-live phase of the VM execution\n",
iignatyev@50260 75 wrongStepEv);
jcbeyler@51870 76 }
iignatyev@50260 77
iignatyev@50260 78 if (result == STATUS_FAILED)
iignatyev@50260 79 exit(95 + STATUS_FAILED);
iignatyev@50260 80 }
iignatyev@50260 81 /************************/
iignatyev@50260 82
iignatyev@50260 83 #ifdef STATIC_BUILD
iignatyev@50260 84 JNIEXPORT jint JNICALL Agent_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 85 return Agent_Initialize(jvm, options, reserved);
iignatyev@50260 86 }
iignatyev@50260 87 JNIEXPORT jint JNICALL Agent_OnAttach_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 88 return Agent_Initialize(jvm, options, reserved);
iignatyev@50260 89 }
iignatyev@50260 90 JNIEXPORT jint JNI_OnLoad_singlestep002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 91 return JNI_VERSION_1_8;
iignatyev@50260 92 }
iignatyev@50260 93 #endif
iignatyev@50260 94 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50260 95 /* init framework and parse options */
iignatyev@50260 96 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
iignatyev@50260 97 return JNI_ERR;
iignatyev@50260 98
iignatyev@50260 99 /* create JVMTI environment */
iignatyev@50260 100 if (!NSK_VERIFY((jvmti =
iignatyev@50260 101 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
iignatyev@50260 102 return JNI_ERR;
iignatyev@50260 103
iignatyev@50260 104 /* add capability to generate compiled method events */
iignatyev@50260 105 memset(&caps, 0, sizeof(jvmtiCapabilities));
iignatyev@50260 106 caps.can_generate_single_step_events = 1;
jcbeyler@52215 107 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)))
iignatyev@50260 108 return JNI_ERR;
iignatyev@50260 109
jcbeyler@52215 110 if (!NSK_JVMTI_VERIFY(jvmti->GetCapabilities(&caps)))
iignatyev@50260 111 return JNI_ERR;
iignatyev@50260 112
iignatyev@50260 113 if (!caps.can_generate_single_step_events)
iignatyev@50260 114 NSK_DISPLAY0("Warning: generation of single step events is not implemented\n");
iignatyev@50260 115
iignatyev@50260 116 /* set event callback */
iignatyev@50260 117 NSK_DISPLAY0("setting event callbacks ...\n");
iignatyev@50260 118 (void) memset(&callbacks, 0, sizeof(callbacks));
iignatyev@50260 119 callbacks.SingleStep = &SingleStep;
iignatyev@50260 120 callbacks.VMDeath = &VMDeath;
jcbeyler@52215 121 if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&callbacks, sizeof(callbacks))))
iignatyev@50260 122 return JNI_ERR;
iignatyev@50260 123
iignatyev@50260 124 NSK_DISPLAY0("setting event callbacks done\nenabling JVMTI events ...\n");
jcbeyler@52215 125 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_SINGLE_STEP, NULL)))
iignatyev@50260 126 return JNI_ERR;
jcbeyler@52215 127 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL)))
iignatyev@50260 128 return JNI_ERR;
iignatyev@50260 129 NSK_DISPLAY0("enabling the events done\n\n");
iignatyev@50260 130
iignatyev@50260 131 return JNI_OK;
iignatyev@50260 132 }
iignatyev@50260 133
iignatyev@50260 134 }