Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/DisposeEnvironment/disposeenv002/disposeenv002.cpp
40951 views
/*1* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <stdlib.h>24#include <string.h>25#include "jvmti.h"26#include "agent_common.h"27#include "jni_tools.h"28#include "jvmti_tools.h"2930extern "C" {3132/* ============================================================================= */3334#define STATUS_FAIL 973536/* ============================================================================= */3738/**39* Callback for VM_DEATH event.40*/41JNIEXPORT void JNICALL42callbackVMDeath(jvmtiEnv* jvmti, JNIEnv* jni) {43int success = NSK_TRUE;4445NSK_DISPLAY0("Disable VM_DEATH event in VM_DEATH callback\n");46if (!NSK_JVMTI_VERIFY(47jvmti->SetEventNotificationMode(JVMTI_DISABLE, JVMTI_EVENT_VM_DEATH, NULL))) {48success = NSK_FALSE;49} else {50NSK_DISPLAY0(" ... disabled\n");51}5253NSK_DISPLAY0(">>> Testcase #1: Dispose JVMTI environment in VM_DEATH callback\n");54if (!NSK_JVMTI_VERIFY(jvmti->DisposeEnvironment())) {55success = NSK_FALSE;56} else {57NSK_DISPLAY0(" ... disposed\n");58}5960if (!success) {61NSK_DISPLAY1("Exit with FAIL exit status: %d\n", STATUS_FAIL);62NSK_BEFORE_TRACE(exit(STATUS_FAIL));63}64}6566/* ============================================================================= */6768/** Agent library initialization. */69#ifdef STATIC_BUILD70JNIEXPORT jint JNICALL Agent_OnLoad_disposeenv002(JavaVM *jvm, char *options, void *reserved) {71return Agent_Initialize(jvm, options, reserved);72}73JNIEXPORT jint JNICALL Agent_OnAttach_disposeenv002(JavaVM *jvm, char *options, void *reserved) {74return Agent_Initialize(jvm, options, reserved);75}76JNIEXPORT jint JNI_OnLoad_disposeenv002(JavaVM *jvm, char *options, void *reserved) {77return JNI_VERSION_1_8;78}79#endif80jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {81jvmtiEnv* jvmti = NULL;8283if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))84return JNI_ERR;8586if (!NSK_VERIFY((jvmti =87nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))88return JNI_ERR;8990{91jvmtiEventCallbacks eventCallbacks;9293memset(&eventCallbacks, 0, sizeof(eventCallbacks));94eventCallbacks.VMDeath = callbackVMDeath;95if (!NSK_JVMTI_VERIFY(jvmti->SetEventCallbacks(&eventCallbacks, sizeof(eventCallbacks)))) {96return JNI_ERR;97}9899NSK_DISPLAY0("Enable VM_DEATH event in JVM_OnLoad()\n");100if (!NSK_JVMTI_VERIFY(101jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_DEATH, NULL))) {102return JNI_ERR;103}104NSK_DISPLAY0(" ... enabled\n");105}106107return JNI_OK;108}109110/* ============================================================================= */111112}113114115