annotate test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.c @ 50270:46c67f5e27c2

8199383: [TESTBUG] Open source VM testbase JVMTI tests Reviewed-by: sspitsyn, erikj
author iignatyev
date Thu, 24 May 2018 17:12:15 -0700
parents
children
rev   line source
iignatyev@50270 1 /*
iignatyev@50270 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
iignatyev@50270 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
iignatyev@50270 4 *
iignatyev@50270 5 * This code is free software; you can redistribute it and/or modify it
iignatyev@50270 6 * under the terms of the GNU General Public License version 2 only, as
iignatyev@50270 7 * published by the Free Software Foundation.
iignatyev@50270 8 *
iignatyev@50270 9 * This code is distributed in the hope that it will be useful, but WITHOUT
iignatyev@50270 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
iignatyev@50270 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
iignatyev@50270 12 * version 2 for more details (a copy is included in the LICENSE file that
iignatyev@50270 13 * accompanied this code).
iignatyev@50270 14 *
iignatyev@50270 15 * You should have received a copy of the GNU General Public License version
iignatyev@50270 16 * 2 along with this work; if not, write to the Free Software Foundation,
iignatyev@50270 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
iignatyev@50270 18 *
iignatyev@50270 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
iignatyev@50270 20 * or visit www.oracle.com if you need additional information or have any
iignatyev@50270 21 * questions.
iignatyev@50270 22 */
iignatyev@50270 23
iignatyev@50270 24 #include <stdlib.h>
iignatyev@50270 25 #include <string.h>
iignatyev@50270 26 #include "jvmti.h"
iignatyev@50270 27 #include "agent_common.h"
iignatyev@50270 28 #include "jni_tools.h"
iignatyev@50270 29 #include "jvmti_tools.h"
iignatyev@50270 30
iignatyev@50270 31 #ifdef __cplusplus
iignatyev@50270 32 extern "C" {
iignatyev@50270 33 #endif
iignatyev@50270 34
iignatyev@50270 35 /* ============================================================================= */
iignatyev@50270 36
iignatyev@50270 37 #define STATUS_FAIL 97
iignatyev@50270 38
iignatyev@50270 39 /* ============================================================================= */
iignatyev@50270 40
iignatyev@50270 41 /**
iignatyev@50270 42 * Callback for VM_DEATH event.
iignatyev@50270 43 */
iignatyev@50270 44 JNIEXPORT void JNICALL
iignatyev@50270 45 callbackVMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {
iignatyev@50270 46 int success = NSK_TRUE;
iignatyev@50270 47
iignatyev@50270 48 NSK_DISPLAY0("Disable VM_DEATH event in VM_DEATH callback\n");
iignatyev@50270 49 if (!NSK_JVMTI_VERIFY(
iignatyev@50270 50 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_DISABLE,
iignatyev@50270 51 JVMTI_EVENT_VM_DEATH, NULL))) {
iignatyev@50270 52 success = NSK_FALSE;
iignatyev@50270 53 } else {
iignatyev@50270 54 NSK_DISPLAY0(" ... disabled\n");
iignatyev@50270 55 }
iignatyev@50270 56
iignatyev@50270 57 NSK_DISPLAY0(">>> Testcase #1: Dispose JVMTI environment in VM_DEATH callback\n");
iignatyev@50270 58 if (!NSK_JVMTI_VERIFY(
iignatyev@50270 59 NSK_CPP_STUB1(DisposeEnvironment, jvmti))) {
iignatyev@50270 60 success = NSK_FALSE;
iignatyev@50270 61 } else {
iignatyev@50270 62 NSK_DISPLAY0(" ... disposed\n");
iignatyev@50270 63 }
iignatyev@50270 64
iignatyev@50270 65 if (!success) {
iignatyev@50270 66 NSK_DISPLAY1("Exit with FAIL exit status: %d\n", STATUS_FAIL);
iignatyev@50270 67 NSK_BEFORE_TRACE(exit(STATUS_FAIL));
iignatyev@50270 68 }
iignatyev@50270 69 }
iignatyev@50270 70
iignatyev@50270 71 /* ============================================================================= */
iignatyev@50270 72
iignatyev@50270 73 /** Agent library initialization. */
iignatyev@50270 74 #ifdef STATIC_BUILD
iignatyev@50270 75 JNIEXPORT jint JNICALL Agent_OnLoad_disposeenv002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50270 76 return Agent_Initialize(jvm, options, reserved);
iignatyev@50270 77 }
iignatyev@50270 78 JNIEXPORT jint JNICALL Agent_OnAttach_disposeenv002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50270 79 return Agent_Initialize(jvm, options, reserved);
iignatyev@50270 80 }
iignatyev@50270 81 JNIEXPORT jint JNI_OnLoad_disposeenv002(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50270 82 return JNI_VERSION_1_8;
iignatyev@50270 83 }
iignatyev@50270 84 #endif
iignatyev@50270 85 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
iignatyev@50270 86 jvmtiEnv* jvmti = NULL;
iignatyev@50270 87
iignatyev@50270 88 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
iignatyev@50270 89 return JNI_ERR;
iignatyev@50270 90
iignatyev@50270 91 if (!NSK_VERIFY((jvmti =
iignatyev@50270 92 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
iignatyev@50270 93 return JNI_ERR;
iignatyev@50270 94
iignatyev@50270 95 {
iignatyev@50270 96 jvmtiEventCallbacks eventCallbacks;
iignatyev@50270 97
iignatyev@50270 98 memset(&eventCallbacks, 0, sizeof(eventCallbacks));
iignatyev@50270 99 eventCallbacks.VMDeath = callbackVMDeath;
iignatyev@50270 100 if (!NSK_JVMTI_VERIFY(
iignatyev@50270 101 NSK_CPP_STUB3(SetEventCallbacks, jvmti,
iignatyev@50270 102 &eventCallbacks, sizeof(eventCallbacks)))) {
iignatyev@50270 103 return JNI_ERR;
iignatyev@50270 104 }
iignatyev@50270 105
iignatyev@50270 106 NSK_DISPLAY0("Enable VM_DEATH event in JVM_OnLoad()\n");
iignatyev@50270 107 if (!NSK_JVMTI_VERIFY(
iignatyev@50270 108 NSK_CPP_STUB4(SetEventNotificationMode, jvmti, JVMTI_ENABLE,
iignatyev@50270 109 JVMTI_EVENT_VM_DEATH, NULL))) {
iignatyev@50270 110 return JNI_ERR;
iignatyev@50270 111 }
iignatyev@50270 112 NSK_DISPLAY0(" ... enabled\n");
iignatyev@50270 113 }
iignatyev@50270 114
iignatyev@50270 115 return JNI_OK;
iignatyev@50270 116 }
iignatyev@50270 117
iignatyev@50270 118 /* ============================================================================= */
iignatyev@50270 119
iignatyev@50270 120 #ifdef __cplusplus
iignatyev@50270 121 }
iignatyev@50270 122 #endif