Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/sharedAgents/simpleAgent00.cpp
40955 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>2930extern "C" {3132/*33* Simple agent, doesn't perform any specific checks,34* just gets JVMTI environment and calls nsk_aod_agentLoaded and nsk_aod_agentFinished35* from Agent_OnAttach36*/3738#ifdef STATIC_BUILD39JNIEXPORT jint JNI_OnLoad_simpleAgent00(JavaVM *jvm, char *options, void *reserved) {40return JNI_VERSION_1_8;41}42#endif4344JNIEXPORT jint JNICALL45#ifdef STATIC_BUILD46Agent_OnAttach_simpleAgent00(JavaVM *vm, char *optionsString, void *reserved)47#else48Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)49#endif50{51jvmtiEnv* jvmti;52JNIEnv* jni = NULL;53Options* options = NULL;54const char* agentName;5556options = (Options*) nsk_aod_createOptions(optionsString);57if (!NSK_VERIFY(options != NULL))58return JNI_ERR;5960agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);6162jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);63if (jni == NULL)64return JNI_ERR;6566jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);67if (!NSK_VERIFY(jvmti != NULL))68return JNI_ERR;6970NSK_DISPLAY1("%s: initialization was done\n", agentName);7172if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))73return JNI_ERR;7475nsk_aod_agentFinished(jni, agentName, 1);7677return JNI_OK;78}7980}818283