Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach050/attach050Agent00.cpp
40951 views
/*1* Copyright (c) 2008, 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*/22#include <stdio.h>23#include <stdlib.h>24#include <string.h>25#include <jni.h>26#include <jvmti.h>27#include <aod.h>28#include <jvmti_aod.h>2930#define ON_UNLOAD_MARKER "attach050.on_unload"3132extern "C" {3334/*35* This agent gets JVMTI environment and calls nsk_aod_agentLoaded and36* nsk_aod_agentFinished from Agent_OnAttach. It also has37* Agent_OnUnload function that prints marker string to the stdout,38* providing a means for the test runner to check whether39* Agent_OnUnload is called on agent unload during VM shutdown.40*/4142#ifdef STATIC_BUILD43JNIEXPORT jint JNI_OnLoad_attach050Agent00(JavaVM *jvm, char *options, void *reserved) {44return JNI_VERSION_1_8;45}46#endif4748JNIEXPORT jint JNICALL49#ifdef STATIC_BUILD50Agent_OnAttach_attach050Agent00(JavaVM *vm, char *optionsString, void *reserved)51#else52Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)53#endif54{55jvmtiEnv* jvmti;56JNIEnv* jni = NULL;57Options* options = NULL;58const char* agentName;5960options = (Options*) nsk_aod_createOptions(optionsString);61if (!NSK_VERIFY(options != NULL))62return JNI_ERR;6364agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);6566jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);67if (jni == NULL)68return JNI_ERR;6970jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);71if (!NSK_VERIFY(jvmti != NULL))72return JNI_ERR;7374NSK_DISPLAY1("%s: initialization was done\n", agentName);7576if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))77return JNI_ERR;7879nsk_aod_agentFinished(jni, agentName, 1);8081return JNI_OK;82}838485/* agent library shutdown */86JNIEXPORT void JNICALL87#ifdef STATIC_BUILD88Agent_OnUnload_attach050Agent00(JavaVM *jvm)89#else90Agent_OnUnload(JavaVM *jvm)91#endif92{93fprintf(stdout, "%s%s", ON_UNLOAD_MARKER, "\n");94fflush(stdout);95}9697}9899100