1 /* 2 * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #include <jni.h> 27 #include <jvmti.h> 28 #include <aod.h> 29 #include <jvmti_aod.h> 30 31 extern "C" { 32 33 /* 34 * Simple agent, doesn't perform any specific checks, 35 * just gets JVMTI environment and calls nsk_aod_agentLoaded and nsk_aod_agentFinished 36 * from Agent_OnAttach 37 */ 38 39 #ifdef STATIC_BUILD 40 JNIEXPORT jint JNI_OnLoad_simpleAgent00(JavaVM *jvm, char *options, void *reserved) { 41 return JNI_VERSION_1_8; 42 } 43 #endif 44 45 JNIEXPORT jint JNICALL 46 #ifdef STATIC_BUILD 47 Agent_OnAttach_simpleAgent00(JavaVM *vm, char *optionsString, void *reserved) 48 #else 49 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) 50 #endif 51 { 52 jvmtiEnv* jvmti; 53 JNIEnv* jni = NULL; 54 Options* options = NULL; 55 const char* agentName; 56 57 if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL)) 58 return JNI_ERR; 59 60 agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION); 61 62 if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL) 63 return JNI_ERR; 64 65 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) 66 return JNI_ERR; 67 68 NSK_DISPLAY1("%s: initialization was done\n", agentName); 69 70 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) 71 return JNI_ERR; 72 73 nsk_aod_agentFinished(jni, agentName, 1); 74 75 return JNI_OK; 76 } 77 78 }