Path: blob/master/test/hotspot/jtreg/serviceability/attach/ShMemLongName.java
41149 views
/*1* Copyright (c) 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*/2223/*24* @test25* @bug 804969526* @summary Ensure shmem transport works with long names27* @requires os.family == "windows"28* @library /test/lib29* @run main/othervm ShMemLongName30*/3132import java.io.BufferedReader;33import java.io.IOException;34import java.io.InputStreamReader;35import java.io.InputStream;36import java.util.Collections;37import java.util.Map;3839import com.sun.jdi.Bootstrap;40import com.sun.jdi.VirtualMachine;41import com.sun.jdi.connect.AttachingConnector;42import com.sun.jdi.connect.Connector;43import jdk.test.lib.process.ProcessTools;444546public class ShMemLongName {4748private static final int maxShMemLength = 49;4950private static final String transport = "dt_shmem";5152public static void main(String[] args) throws Exception {53// test with the maximum supported shmem name length54String shmemName = ("ShMemLongName" + ProcessHandle.current().pid()55+ String.join("", Collections.nCopies(maxShMemLength, "x"))56).substring(0, maxShMemLength);57Process target = getTarget(shmemName).start();58try {59waitForReady(target);6061log("attaching to the VM...");62AttachingConnector ac = Bootstrap.virtualMachineManager().attachingConnectors()63.stream()64.filter(c -> transport.equals(c.transport().name()))65.findFirst()66.orElseThrow(() -> new RuntimeException("Failed to find transport " + transport));67Map<String, Connector.Argument> acArgs = ac.defaultArguments();68acArgs.get("name").setValue(shmemName);6970VirtualMachine vm = ac.attach(acArgs);7172log("attached. test(1) PASSED.");7374vm.dispose();75} finally {76target.destroy();77target.waitFor();78}7980// extra test: ensure using of too-long name fails gracefully81// (shmemName + "X") is expected to be "too long".82ProcessTools.executeProcess(getTarget(shmemName + "X"))83.shouldContain("address strings longer than")84.shouldHaveExitValue(2);85log("test(2) PASSED.");86}8788private static void log(String s) {89System.out.println(s);90System.out.flush();91}9293// creates target process builder for the specified shmem transport name94private static ProcessBuilder getTarget(String shmemName) throws IOException {95log("starting target with shmem name: '" + shmemName + "'...");96return ProcessTools.createJavaProcessBuilder(97"-Xdebug",98"-Xrunjdwp:transport=" + transport + ",server=y,suspend=n,address=" + shmemName,99"ShMemLongName$Target");100}101102private static void waitForReady(Process target) throws Exception {103InputStream os = target.getInputStream();104try (BufferedReader reader = new BufferedReader(new InputStreamReader(os))) {105String line;106while ((line = reader.readLine()) != null) {107if (line.equals(Target.readyString)) {108return;109}110}111}112}113114public static class Target {115public static final String readyString = "Ready";116public static void main(String[] args) throws Exception {117log(readyString);118while (true) {119Thread.sleep(1000);120}121}122}123}124125126