Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine09/VirtualMachine09.java
41160 views
/*1* Copyright (c) 2008, 2020, 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/*24* @test25*26* @summary converted from VM Testbase nsk/aod/VirtualMachine/VirtualMachine09.27* VM Testbase keywords: [feature_282, jdk]28* VM Testbase readme:29* Description :30* Test checks work of Attach API (com.sun.tools.attach).31* Test is based on the nsk.share.aod framework.32* This test checks method VirtualMachine.loadAgentLibrary(String agent).33* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded34* prior to invoking this method". In this test the same agent library first loaded via VM command line35* option 'agentlib:', then it is loaded using method 'System.loadLibrary' and than dynamically attached.36*37* @library /vmTestbase /test/hotspot/jtreg/vmTestbase38* /test/lib39* @build nsk.aod.VirtualMachine.VirtualMachine09.VM09Target40* @run main/othervm/native41* -XX:+UsePerfData42* nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine0943* -jdk ${test.jdk}44* -javaOpts="-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"45* -target nsk.aod.VirtualMachine.VirtualMachine09.VM09Target46* -na VirtualMachine09agent0047* -testedMethod loadAgentLibrary48*/4950package nsk.aod.VirtualMachine.VirtualMachine09;5152import com.sun.tools.attach.VirtualMachine;53import nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07;54import nsk.share.TestBug;55import nsk.share.aod.AgentInformation;5657import java.util.List;5859/*60* Test checks methods VirtualMachine.loadAgentLib and VirtualMachineloadAgentPath.61*62* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded63* prior to invoking this method"64*/65public class VirtualMachine09 extends VirtualMachine07 {6667public VirtualMachine09(String[] args) {68super(args);69}7071public void doTestActions(String targetVMId) throws Throwable {72// check that all required parameters were passed to the test73List<AgentInformation> agents = argParser.getAgents();74if (agents.size() != 1) {75throw new TestBug("Test requires 1 agent, actually " + agents.size() + " were specified");76}77for (AgentInformation agent : agents) {78if (agent.jarAgent) {79throw new TestBug("Non native agent was specified");80}81}8283VirtualMachine vm = VirtualMachine.attach(targetVMId);8485try {86AgentInformation agent;87agent = agents.get(0);88loadAgent(vm, agent.pathToAgent, agent.agentOptions);89} finally {90vm.detach();91}92}9394public static void main(String[] args) {95new VirtualMachine09(args).runTest();96}97}9899100