8254102: use ProcessHandle::pid instead of ManagementFactory::getRuntimeMXBean to get pid in tests
Reviewed-by: rriggs, shade
This commit is contained in:
parent
38159d52d4
commit
5a9bd41e79
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -21,10 +21,6 @@
|
|||||||
* questions.
|
* questions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Suicide test
|
* @summary Suicide test
|
||||||
@ -34,13 +30,12 @@ public class Suicide {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String cmd = null;
|
String cmd = null;
|
||||||
try {
|
try {
|
||||||
String pidStr = ManagementFactory.getRuntimeMXBean().getName()
|
long pid = ProcessHandle.current().pid();
|
||||||
.split("@")[0];
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
if (osName.contains("Windows")) {
|
if (osName.contains("Windows")) {
|
||||||
cmd = "taskkill.exe /F /PID " + pidStr;
|
cmd = "taskkill.exe /F /PID " + pid;
|
||||||
} else {
|
} else {
|
||||||
cmd = "kill -9 " + pidStr;
|
cmd = "kill -9 " + pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("executing `%s'%n", cmd);
|
System.out.printf("executing `%s'%n", cmd);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,7 +29,6 @@
|
|||||||
* @modules java.base/jdk.internal.org.objectweb.asm
|
* @modules java.base/jdk.internal.org.objectweb.asm
|
||||||
* java.compiler
|
* java.compiler
|
||||||
* java.instrument
|
* java.instrument
|
||||||
* java.management
|
|
||||||
* jdk.attach
|
* jdk.attach
|
||||||
* @requires vm.jvmti
|
* @requires vm.jvmti
|
||||||
*
|
*
|
||||||
@ -53,7 +52,6 @@ import java.lang.instrument.Instrumentation;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.invoke.MethodHandles;
|
import java.lang.invoke.MethodHandles;
|
||||||
import java.lang.invoke.MethodHandles.Lookup;
|
import java.lang.invoke.MethodHandles.Lookup;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -128,10 +126,7 @@ public class RedefineMethodUsedByMultipleMethodHandles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void runAgent(Path agent) throws Exception {
|
public static void runAgent(Path agent) throws Exception {
|
||||||
String vmName = ManagementFactory.getRuntimeMXBean().getName();
|
String pid = Long.toString(ProcessHandle.current().pid());
|
||||||
int p = vmName.indexOf('@');
|
|
||||||
assert p != -1 : "VM name not in <pid>@<host> format: " + vmName;
|
|
||||||
String pid = vmName.substring(0, p);
|
|
||||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||||
Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl);
|
Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl);
|
||||||
Method attach = c.getDeclaredMethod("attach", String.class);
|
Method attach = c.getDeclaredMethod("attach", String.class);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -45,7 +45,6 @@ import java.io.InputStream;
|
|||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.IllegalClassFormatException;
|
import java.lang.instrument.IllegalClassFormatException;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -134,10 +133,7 @@ public class RedefineClassTest extends TypeUniverse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAgent(Path agent) throws Exception {
|
public static void loadAgent(Path agent) throws Exception {
|
||||||
String vmName = ManagementFactory.getRuntimeMXBean().getName();
|
String pid = Long.toString(ProcessHandle.current().pid());
|
||||||
int p = vmName.indexOf('@');
|
|
||||||
assumeTrue(p != -1);
|
|
||||||
String pid = vmName.substring(0, p);
|
|
||||||
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
ClassLoader cl = ClassLoader.getSystemClassLoader();
|
||||||
Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl);
|
Class<?> c = Class.forName("com.sun.tools.attach.VirtualMachine", true, cl);
|
||||||
Method attach = c.getDeclaredMethod("attach", String.class);
|
Method attach = c.getDeclaredMethod("attach", String.class);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -28,7 +28,6 @@ import jdk.test.lib.Utils;
|
|||||||
|
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
@ -84,9 +83,7 @@ public class Agent implements ClassFileTransformer {
|
|||||||
// Create speculative trap entries
|
// Create speculative trap entries
|
||||||
Test.m();
|
Test.m();
|
||||||
|
|
||||||
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
|
String pid = Long.toString(ProcessHandle.current().pid());
|
||||||
int p = nameOfRunningVM.indexOf('@');
|
|
||||||
String pid = nameOfRunningVM.substring(0, p);
|
|
||||||
|
|
||||||
// Make the nmethod go away
|
// Make the nmethod go away
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,7 +27,6 @@
|
|||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.instrument
|
* java.instrument
|
||||||
* java.management
|
|
||||||
* @requires vm.jvmti
|
* @requires vm.jvmti
|
||||||
* @build compiler.profiling.spectrapredefineclass.Agent
|
* @build compiler.profiling.spectrapredefineclass.Agent
|
||||||
* @run driver ClassFileInstaller compiler.profiling.spectrapredefineclass.Agent
|
* @run driver ClassFileInstaller compiler.profiling.spectrapredefineclass.Agent
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -28,7 +28,6 @@ import jdk.test.lib.Utils;
|
|||||||
|
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -66,9 +65,7 @@ public class Agent implements ClassFileTransformer {
|
|||||||
// references m4() (loaded by loader2).
|
// references m4() (loaded by loader2).
|
||||||
m3.invoke(Test_class.newInstance(), loader1);
|
m3.invoke(Test_class.newInstance(), loader1);
|
||||||
|
|
||||||
String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
|
String pid = Long.toString(ProcessHandle.current().pid());
|
||||||
int p = nameOfRunningVM.indexOf('@');
|
|
||||||
String pid = nameOfRunningVM.substring(0, p);
|
|
||||||
|
|
||||||
// Make the nmethod go away
|
// Make the nmethod go away
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -27,7 +27,6 @@
|
|||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.instrument
|
* java.instrument
|
||||||
* java.management
|
|
||||||
* @requires vm.jvmti
|
* @requires vm.jvmti
|
||||||
* @build compiler.profiling.spectrapredefineclass_classloaders.Agent
|
* @build compiler.profiling.spectrapredefineclass_classloaders.Agent
|
||||||
* compiler.profiling.spectrapredefineclass_classloaders.Test
|
* compiler.profiling.spectrapredefineclass_classloaders.Test
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -30,14 +30,11 @@
|
|||||||
*
|
*
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @modules java.base/jdk.internal.misc
|
* @modules java.base/jdk.internal.misc
|
||||||
* java.management
|
|
||||||
* @run main/othervm TestThreadDumpMonitorContention
|
* @run main/othervm TestThreadDumpMonitorContention
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.management.RuntimeMXBean;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -52,7 +49,7 @@ public class TestThreadDumpMonitorContention {
|
|||||||
// so use getTestJDKTool() instead of getCompileJDKTool() or even
|
// so use getTestJDKTool() instead of getCompileJDKTool() or even
|
||||||
// getJDKTool() which can fall back to "compile.jdk".
|
// getJDKTool() which can fall back to "compile.jdk".
|
||||||
final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
|
final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
|
||||||
final static String PID = getPid();
|
final static String PID = Long.toString(ProcessHandle.current().pid());
|
||||||
|
|
||||||
// looking for header lines with these patterns:
|
// looking for header lines with these patterns:
|
||||||
// "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000]
|
// "ContendingThread-1" #19 prio=5 os_prio=64 tid=0x000000000079c000 nid=0x23 runnable [0xffff80ffb8b87000]
|
||||||
@ -514,22 +511,6 @@ public class TestThreadDumpMonitorContention {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This helper relies on RuntimeMXBean.getName() returning a string
|
|
||||||
// that looks like this: 5436@mt-haku
|
|
||||||
//
|
|
||||||
// The testlibrary has tryFindJvmPid(), but that uses a separate
|
|
||||||
// process which is much more expensive for finding out your own PID.
|
|
||||||
//
|
|
||||||
static String getPid() {
|
|
||||||
RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
|
|
||||||
String vmname = runtimebean.getName();
|
|
||||||
int i = vmname.indexOf('@');
|
|
||||||
if (i != -1) {
|
|
||||||
vmname = vmname.substring(0, i);
|
|
||||||
}
|
|
||||||
return vmname;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void usage() {
|
static void usage() {
|
||||||
System.err.println("Usage: " +
|
System.err.println("Usage: " +
|
||||||
"java TestThreadDumpMonitorContention [-v] [n_samples]");
|
"java TestThreadDumpMonitorContention [-v] [n_samples]");
|
||||||
|
Loading…
Reference in New Issue
Block a user