Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/sde/SDEDebuggee.java
41162 views
/*1* Copyright (c) 2007, 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*/22package nsk.share.jdi.sde;2324import java.lang.reflect.Method;25import nsk.share.TestBug;26import nsk.share.jdi.*;2728public class SDEDebuggee extends AbstractJDIDebuggee {29public static String mainThreadName = "SDEDebuggee_mainThread";3031// command:class_name32public static String COMMAND_EXECUTE_TEST_METHODS = "executeTestMethods";3334public static void main(String args[]) {35new SDEDebuggee().doTest(args);36}3738protected String[] doInit(String[] args) {39args = super.doInit(args);4041if (classpath == null)42throw new TestBug("Debuggee requires '-testClassPath' parameter");4344Thread.currentThread().setName(mainThreadName);4546return args;47}4849public boolean parseCommand(String command) {50if (super.parseCommand(command))51return true;5253if (command.startsWith(COMMAND_EXECUTE_TEST_METHODS)) {54// extract class name55String split[] = command.split(":");5657if ((split.length != 2) || (split[1].length() == 0))58throw new TestBug("");5960executeTestMethods(split[1]);61breakpointMethod();6263return true;64}6566return false;67}6869// Keep class loader alive to avoid ObjectCollectedException70// on the debugger side, in case the GC unloads the class and71// invalidates code locations.72private TestClassLoader classLoader;7374// create instance of given class and execute all methods which names start75// with 'sde_testMethod'76private void executeTestMethods(String className) {77classLoader = new TestClassLoader();78classLoader.setClassPath(classpath);7980try {81Class<?> klass = classLoader.loadClass(className);82Object testObject = klass.newInstance();8384for (Method method : klass.getDeclaredMethods()) {85if (method.getName().startsWith("sde_testMethod"))86method.invoke(testObject, new Object[] {});87}88} catch (Exception e) {89setSuccess(false);90log.complain("Unexpected exception: " + e);91e.printStackTrace(log.getOutStream());9293throw new TestBug("Unexpected exception: " + e);94}95}9697}9899100