Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach012/attach012Agent00.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>2930extern "C" {3132/*33* Agent tries to get all potential capabilities34* (capabilities returned by the JVMTI function GetPotentialCapabilities)35*/3637#ifdef STATIC_BUILD38JNIEXPORT jint JNI_OnLoad_attach012Agent00(JavaVM *jvm, char *options, void *reserved) {39return JNI_VERSION_1_8;40}41#endif4243JNIEXPORT jint JNICALL44#ifdef STATIC_BUILD45Agent_OnAttach_attach012Agent00(JavaVM *vm, char *optionsString, void *reserved)46#else47Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved)48#endif49{50jvmtiEnv* jvmti;51JNIEnv* jni = NULL;52Options* options = NULL;53const char* agentName;54jvmtiCapabilities caps;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 NSK_FALSE;6566jvmti = nsk_jvmti_createJVMTIEnv(vm, reserved);67if (!NSK_VERIFY(jvmti != NULL))68return JNI_ERR;6970if (!NSK_JVMTI_VERIFY(jvmti->GetPotentialCapabilities(&caps))) {71return JNI_ERR;72}7374NSK_DISPLAY1("%s: potential capabilities:\n", agentName);7576printCapabilities(caps);7778NSK_DISPLAY1("%s: trying to get all potential capabilities:\n", agentName);7980if (!NSK_JVMTI_VERIFY(jvmti->AddCapabilities(&caps))) {81return JNI_ERR;82}8384NSK_DISPLAY1("%s: initialization was done\n", agentName);8586if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))87return JNI_ERR;8889nsk_aod_agentFinished(jni, agentName, 1);9091return JNI_OK;92}9394}959697