diff --git a/jdk/test/java/util/logging/TestLoggerWeakRefLeak.java b/jdk/test/java/util/logging/TestLoggerWeakRefLeak.java index 06c048d991f..3a14e74074c 100644 --- a/jdk/test/java/util/logging/TestLoggerWeakRefLeak.java +++ b/jdk/test/java/util/logging/TestLoggerWeakRefLeak.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -128,7 +128,7 @@ public class TestLoggerWeakRefLeak { int instanceCount = 0; HotSpotVirtualMachine vm = (HotSpotVirtualMachine) VirtualMachine - .attach(Integer.toString(ProcessTools.getProcessId())); + .attach(Long.toString(ProcessTools.getProcessId())); try { try (InputStream heapHistoStream = vm.heapHisto("-live"); BufferedReader in = new BufferedReader(new InputStreamReader(heapHistoStream))) { diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/JcmdBase.java b/jdk/test/lib/testlibrary/jdk/testlibrary/JcmdBase.java index c4bbedccfc0..ac66cf431a2 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/JcmdBase.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/JcmdBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -99,7 +99,7 @@ public final class JcmdBase { } } if (requestToCurrentProcess) { - launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); + launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); } if (jcmdArgs != null) { for (String toolArg : jcmdArgs) { diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java index b861cf60778..9556f22f15f 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/ProcessTools.java @@ -27,8 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; @@ -253,11 +251,8 @@ public final class ProcessTools { * * @return Process id */ - public static int getProcessId() throws Exception { - RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); - int pid = Integer.parseInt(runtime.getName().split("@")[0]); - - return pid; + public static long getProcessId() { + return ProcessHandle.current().getPid(); } /** diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/TestThread.java b/jdk/test/lib/testlibrary/jdk/testlibrary/TestThread.java index 26b06040de5..fb217db73f1 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/TestThread.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/TestThread.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,9 +23,6 @@ package jdk.testlibrary; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; import java.util.concurrent.TimeoutException; /** @@ -204,46 +201,4 @@ public class TestThread extends Thread { } return null; } - - /** - * Waits until {@link TestThread} is in the certain {@link State} - * and blocking on {@code object}. - * - * @param state The thread state - * @param object The object to block on - */ - public void waitUntilBlockingOnObject(Thread.State state, Object object) { - String want = object == null ? null : object.getClass().getName() + '@' - + Integer.toHexString(System.identityHashCode(object)); - ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); - while (isAlive()) { - ThreadInfo ti = tmx.getThreadInfo(getId()); - if (ti.getThreadState() == state - && (want == null || want.equals(ti.getLockName()))) { - return; - } - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } - } - } - - /** - * Waits until {@link TestThread} is in native. - */ - public void waitUntilInNative() { - ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); - while (isAlive()) { - ThreadInfo ti = tmx.getThreadInfo(getId()); - if (ti.isInNative()) { - return; - } - try { - Thread.sleep(1); - } catch (InterruptedException e) { - } - } - } - } diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/InputArguments.java b/jdk/test/lib/testlibrary/jdk/testlibrary/management/InputArguments.java similarity index 94% rename from jdk/test/lib/testlibrary/jdk/testlibrary/InputArguments.java rename to jdk/test/lib/testlibrary/jdk/testlibrary/management/InputArguments.java index a2f0f3fa085..7fc2f678490 100644 --- a/jdk/test/lib/testlibrary/jdk/testlibrary/InputArguments.java +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/management/InputArguments.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,7 +21,7 @@ * questions. */ -package jdk.testlibrary; +package jdk.testlibrary.management; import java.lang.management.RuntimeMXBean; import java.lang.management.ManagementFactory; @@ -65,7 +65,7 @@ public class InputArguments { * @return {@code true} if the given argument is the start of an input * argument, otherwise {@code false}. */ - public static boolean containsPrefix(String prefix) { + public static boolean hasArgStartingWith(String prefix) { for (String arg : args) { if (arg.startsWith(prefix)) { return true; diff --git a/jdk/test/lib/testlibrary/jdk/testlibrary/management/ThreadMXBeanTool.java b/jdk/test/lib/testlibrary/jdk/testlibrary/management/ThreadMXBeanTool.java new file mode 100644 index 00000000000..b3f4417a898 --- /dev/null +++ b/jdk/test/lib/testlibrary/jdk/testlibrary/management/ThreadMXBeanTool.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.testlibrary.management; + +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; +import java.util.concurrent.TimeoutException; + +/** + * A few utility methods to use ThreadMXBean. + */ +public final class ThreadMXBeanTool { + + /** + * Waits until {@link Thread} is in the certain {@link State} + * and blocking on {@code object}. + * + * @param state The thread state + * @param object The object to block on + */ + public static void waitUntilBlockingOnObject(Thread thread, Thread.State state, Object object) + throws InterruptedException { + String want = object == null ? null : object.getClass().getName() + '@' + + Integer.toHexString(System.identityHashCode(object)); + ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); + while (thread.isAlive()) { + ThreadInfo ti = tmx.getThreadInfo(thread.getId()); + if (ti.getThreadState() == state + && (want == null || want.equals(ti.getLockName()))) { + return; + } + Thread.sleep(1); + } + } + + /** + * Waits until {@link Thread} is in native. + */ + public static void waitUntilInNative(Thread thread) throws InterruptedException { + ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); + while (thread.isAlive()) { + ThreadInfo ti = tmx.getThreadInfo(thread.getId()); + if (ti.isInNative()) { + return; + } + Thread.sleep(1); + } + } + +} diff --git a/jdk/test/sun/tools/jcmd/TestJcmdSanity.java b/jdk/test/sun/tools/jcmd/TestJcmdSanity.java index be8f1c7b71a..c36c9e895b2 100644 --- a/jdk/test/sun/tools/jcmd/TestJcmdSanity.java +++ b/jdk/test/sun/tools/jcmd/TestJcmdSanity.java @@ -71,7 +71,7 @@ public class TestJcmdSanity { output.shouldHaveExitValue(0); output.shouldNotContain("Exception"); - output.shouldContain(Integer.toString(ProcessTools.getProcessId()) + ":"); + output.shouldContain(Long.toString(ProcessTools.getProcessId()) + ":"); matchJcmdCommands(output); output.shouldContain("For more information about a specific command use 'help '."); } diff --git a/jdk/test/sun/tools/jinfo/JInfoHelper.java b/jdk/test/sun/tools/jinfo/JInfoHelper.java index abbc862c2c8..7f945136b4f 100644 --- a/jdk/test/sun/tools/jinfo/JInfoHelper.java +++ b/jdk/test/sun/tools/jinfo/JInfoHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -60,7 +60,7 @@ public final class JInfoHelper { } } if (toPid) { - launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); + launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); } ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand()); diff --git a/jdk/test/sun/tools/jmap/BasicJMapTest.java b/jdk/test/sun/tools/jmap/BasicJMapTest.java index 1ddb903a099..75c80a2eec3 100644 --- a/jdk/test/sun/tools/jmap/BasicJMapTest.java +++ b/jdk/test/sun/tools/jmap/BasicJMapTest.java @@ -111,7 +111,7 @@ public class BasicJMapTest { launcher.addToolArg(toolArg); } } - launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); + launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); processBuilder.command(launcher.getCommand()); System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); diff --git a/jdk/test/sun/tools/jps/JpsBase.java b/jdk/test/sun/tools/jps/JpsBase.java index a1835c20b26..f119f613951 100644 --- a/jdk/test/sun/tools/jps/JpsBase.java +++ b/jdk/test/sun/tools/jps/JpsBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -59,7 +59,7 @@ public final class JpsBase { } public static void main(String[] args) throws Exception { - int pid = ProcessTools.getProcessId(); + long pid = ProcessTools.getProcessId(); List> combinations = JpsHelper.JpsArg.generateCombinations(); for (List combination : combinations) { @@ -76,7 +76,7 @@ public final class JpsBase { // 30673 isQuiet = true; JpsHelper.verifyJpsOutput(output, "^\\d+$"); - output.shouldContain(Integer.toString(pid)); + output.shouldContain(Long.toString(pid)); break; case l: // If '-l' is specified output should contain the full package name for the application's main class diff --git a/jdk/test/sun/tools/jstack/BasicJStackTest.java b/jdk/test/sun/tools/jstack/BasicJStackTest.java index ba35054b8eb..9fd0b66b578 100644 --- a/jdk/test/sun/tools/jstack/BasicJStackTest.java +++ b/jdk/test/sun/tools/jstack/BasicJStackTest.java @@ -63,7 +63,7 @@ public class BasicJStackTest { launcher.addToolArg(toolArg); } } - launcher.addToolArg(Integer.toString(ProcessTools.getProcessId())); + launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); processBuilder.command(launcher.getCommand()); System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));