Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/framework/TestProcessLauncher.java
41155 views
1/*2* Copyright (c) 2019, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324import nsk.share.*;25import nsk.share.jpda.*;26import nsk.share.jdi.*;2728import java.nio.file.FileSystems;29import java.nio.file.Path;3031/**32* Launches a new Java process that uses a communication pipe to interact33* with the test.34*/3536public class TestProcessLauncher {3738protected static final Path USER_DIR = FileSystems.getDefault().getPath(System.getProperty("user.dir", "."));39protected static final Path TEST_CLASSES_DIR = FileSystems.getDefault().getPath(System.getProperty("test.classes"));4041protected final String className;42private final ArgumentHandler argHandler;4344private IOPipe pipe;4546public TestProcessLauncher(String className, ArgumentHandler argHandler) {47this.className = className;48this.argHandler = argHandler;49}5051public TestProcessLauncher(String className) {52this(className, new ArgumentHandler(new String[0]));53}5455public Process launch() {5657String java = argHandler.getLaunchExecPath();5859Log log = new Log(System.out, argHandler);60Binder binder = new Binder(argHandler, log);61binder.prepareForPipeConnection(argHandler);6263String cmd = prepareLaunch(java, argHandler.getPipePort());6465Debugee debuggee = binder.startLocalDebugee(cmd);66debuggee.redirectOutput(log);6768pipe = new IOPipe(debuggee);6970String line = pipe.readln();71if (!"ready".equals(line)) {72System.out.println("Wrong reply received:" + line);73}74return debuggee.getProcess();75}7677public void quit() {78if (pipe != null) {79pipe.println("quit");80}81}8283protected String prepareLaunch(String javaExec, String pipePort) {84return javaExec + " " + className + " -pipe.port=" + pipePort;85}8687}888990