mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-11 19:08:23 +00:00
8139430: Refactor test library to decrease module dependencies of tests
Reviewed-by: mchung, alanb
This commit is contained in:
parent
f9fa8afa11
commit
fb7027bca9
@ -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))) {
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 <command>'.");
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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(",", ""));
|
||||
|
||||
@ -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<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
|
||||
for (List<JpsHelper.JpsArg> 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
|
||||
|
||||
@ -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(",", ""));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user