Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/agent00.cpp
41160 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*/2223#include <stdio.h>24#include <string.h>25#include <jni.h>26#include <aod.h>2728extern "C" {2930/*31* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded32* prior to invoking this method"33*34* This agent is loaded as static agent via 'agentlib:' VM option and also dynamically attached, so this agent35* has both Agent_OnLoad and Agent_OnAttach.36*/3738JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *optionsString, void *reserved) {39// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here40printf("Agent_OnLoad: agent is loaded\n");41fflush(stdout);42return JNI_OK;43}4445JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {46JNIEnv* jni = NULL;47Options* options = NULL;48const char* agentName;4950options = (Options*) nsk_aod_createOptions(optionsString);51if (!NSK_VERIFY(options != NULL))52return JNI_ERR;5354agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);5556jni = (JNIEnv*) nsk_aod_createJNIEnv(vm);57if (jni == NULL)58return JNI_ERR;5960NSK_DISPLAY1("%s: initialization was done\n", agentName);6162if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))63return JNI_ERR;6465nsk_aod_agentFinished(jni, agentName, 1);6667return JNI_OK;68}6970}717273