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 * Agent tries to get all potential capabilities 35 * (capabilities returned by the JVMTI function GetPotentialCapabilities) 36 */ 37 38 #ifdef STATIC_BUILD 39 JNIEXPORT jint JNI_OnLoad_attach012Agent00(JavaVM *jvm, char *options, void *reserved) { 40 return JNI_VERSION_1_8; 41 } 42 #endif 43 44 JNIEXPORT jint JNICALL 45 #ifdef STATIC_BUILD 46 Agent_OnAttach_attach012Agent00(JavaVM *vm, char *optionsString, void *reserved) 47 #else 48 Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) 49 #endif 50 { 51 jvmtiEnv* jvmti; 52 JNIEnv* jni = NULL; 53 Options* options = NULL; 54 const char* agentName; 55 jvmtiCapabilities caps; 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 NSK_FALSE; 64 65 if (!NSK_VERIFY((jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved)) != NULL)) 66 return JNI_ERR; 67 68 if (!NSK_JVMTI_VERIFY(jvmti->GetPotentialCapabilities(&caps)) ) { 69 return JNI_ERR; 70 } 71 72 NSK_DISPLAY1("%s: potential capabilities:\n", agentName); 73 74 printCapabilities(caps); 75 76 NSK_DISPLAY1("%s: trying to get all potential capabilities:\n", agentName); 77 78 if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps)) ) { 79 return JNI_ERR; 80 } 81 82 NSK_DISPLAY1("%s: initialization was done\n", agentName); 83 84 if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName))) 85 return JNI_ERR; 86 87 nsk_aod_agentFinished(jni, agentName, 1); 88 89 return JNI_OK; 90 } 91 92 }