8041979: sun/jvmstat/monitor/MonitoredVm/CR6672135.java failing on all platforms
Reviewed-by: kamg, mgronlun
This commit is contained in:
parent
b597db519c
commit
8ad7b17ffd
@ -273,7 +273,8 @@ SUNWprivate_1.1 {
|
|||||||
Java_sun_misc_VM_isSetUID;
|
Java_sun_misc_VM_isSetUID;
|
||||||
Java_sun_misc_VM_initialize;
|
Java_sun_misc_VM_initialize;
|
||||||
Java_sun_misc_VMSupport_initAgentProperties;
|
Java_sun_misc_VMSupport_initAgentProperties;
|
||||||
|
Java_sun_misc_VMSupport_getVMTemporaryDirectory;
|
||||||
|
|
||||||
# ZipFile.c needs this one
|
# ZipFile.c needs this one
|
||||||
throwFileNotFoundException;
|
throwFileNotFoundException;
|
||||||
|
|
||||||
|
@ -233,8 +233,6 @@ public class PerfDataFile {
|
|||||||
* does not conform to the expected pattern
|
* does not conform to the expected pattern
|
||||||
*/
|
*/
|
||||||
public static int getLocalVmId(File file) {
|
public static int getLocalVmId(File file) {
|
||||||
int lvmid = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// try 1.4.2 and later format first
|
// try 1.4.2 and later format first
|
||||||
return Integer.parseInt(file.getName());
|
return Integer.parseInt(file.getName());
|
||||||
@ -287,31 +285,13 @@ public class PerfDataFile {
|
|||||||
return tmpDirName + dirNamePrefix + user + File.separator;
|
return tmpDirName + dirNamePrefix + user + File.separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* this static initializer would not be necessary if the
|
|
||||||
* Solaris java.io.tmpdir property were set to /tmp by default
|
|
||||||
*/
|
|
||||||
static {
|
static {
|
||||||
/*
|
/*
|
||||||
* Why is java.io.tmpdir on Solaris set to "/var/tmp/" when the
|
* For this to work, the target VM and this code need to use
|
||||||
* HotSpot JVM os:get_temp_path() method returns "/tmp/"
|
* the same directory. Instead of guessing which directory the
|
||||||
*
|
* VM is using, we will ask.
|
||||||
* Why do Solaris and Windows return a string with a trailing
|
|
||||||
* file separator character where as Linix does not? (this change
|
|
||||||
* seems to have occurred sometime during hopper beta)
|
|
||||||
*/
|
*/
|
||||||
String tmpdir = System.getProperty("java.io.tmpdir");
|
String tmpdir = sun.misc.VMSupport.getVMTemporaryDirectory();
|
||||||
|
|
||||||
if (tmpdir.compareTo("/var/tmp/") == 0) {
|
|
||||||
/*
|
|
||||||
* shared memory files are created in /tmp. Interestingly,
|
|
||||||
* java.io.tmpdir is set to "/var/tmp/" on Solaris and Linux,
|
|
||||||
* but os::get_temp_directory() is set to "/tmp/" on these
|
|
||||||
* platforms. the java.io.logging packages also makes reference
|
|
||||||
* to java.io.tmpdir.
|
|
||||||
*/
|
|
||||||
tmpdir = "/tmp/";
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Assure that the string returned has a trailing File.separator
|
* Assure that the string returned has a trailing File.separator
|
||||||
|
@ -97,4 +97,14 @@ public class VMSupport {
|
|||||||
throw new RuntimeException(ioe.getMessage());
|
throw new RuntimeException(ioe.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the temporary directory that the VM uses for the attach
|
||||||
|
* and perf data files.
|
||||||
|
*
|
||||||
|
* It is important that this directory is well-known and the
|
||||||
|
* same for all VM instances. It cannot be affected by configuration
|
||||||
|
* variables such as java.io.tmpdir.
|
||||||
|
*/
|
||||||
|
public static native String getVMTemporaryDirectory();
|
||||||
}
|
}
|
||||||
|
@ -1331,6 +1331,9 @@ JVM_GetManagement(jint version);
|
|||||||
JNIEXPORT jobject JNICALL
|
JNIEXPORT jobject JNICALL
|
||||||
JVM_InitAgentProperties(JNIEnv *env, jobject agent_props);
|
JVM_InitAgentProperties(JNIEnv *env, jobject agent_props);
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
|
JVM_GetTemporaryDirectory(JNIEnv *env);
|
||||||
|
|
||||||
/* Generics reflection support.
|
/* Generics reflection support.
|
||||||
*
|
*
|
||||||
* Returns information about the given class's EnclosingMethod
|
* Returns information about the given class's EnclosingMethod
|
||||||
|
@ -53,3 +53,9 @@ Java_sun_misc_VMSupport_initAgentProperties(JNIEnv *env, jclass cls, jobject pro
|
|||||||
}
|
}
|
||||||
return (*InitAgentProperties_fp)(env, props);
|
return (*InitAgentProperties_fp)(env, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jstring JNICALL
|
||||||
|
Java_sun_misc_VMSupport_getVMTemporaryDirectory(JNIEnv *env, jclass cls)
|
||||||
|
{
|
||||||
|
return JVM_GetTemporaryDirectory(env);
|
||||||
|
}
|
||||||
|
@ -38,7 +38,7 @@ import jdk.testlibrary.ProcessThread;
|
|||||||
* @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
|
* @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
|
||||||
* @summary Basic unit tests for the VM attach mechanism.
|
* @summary Basic unit tests for the VM attach mechanism.
|
||||||
* @library /lib/testlibrary
|
* @library /lib/testlibrary
|
||||||
* @run build Agent BadAgent RedefineAgent Application Shutdown RedefineDummy
|
* @run build Agent BadAgent RedefineAgent Application Shutdown RedefineDummy RunnerUtil
|
||||||
* @run main BasicTests
|
* @run main BasicTests
|
||||||
*
|
*
|
||||||
* This test will perform a number of basic attach tests.
|
* This test will perform a number of basic attach tests.
|
||||||
@ -238,20 +238,18 @@ public class BasicTests {
|
|||||||
// Test 6 - list method should list the target VM
|
// Test 6 - list method should list the target VM
|
||||||
System.out.println(" - Test: VirtualMachine.list");
|
System.out.println(" - Test: VirtualMachine.list");
|
||||||
List<VirtualMachineDescriptor> l = VirtualMachine.list();
|
List<VirtualMachineDescriptor> l = VirtualMachine.list();
|
||||||
if (!l.isEmpty()) {
|
boolean found = false;
|
||||||
boolean found = false;
|
for (VirtualMachineDescriptor vmd: l) {
|
||||||
for (VirtualMachineDescriptor vmd: l) {
|
if (vmd.id().equals(pid)) {
|
||||||
if (vmd.id().equals(pid)) {
|
found = true;
|
||||||
found = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
System.out.println(" - " + pid + " found.");
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException(pid + " not found in VM list");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (found) {
|
||||||
|
System.out.println(" - " + pid + " found.");
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(pid + " not found in VM list");
|
||||||
|
}
|
||||||
|
|
||||||
// test 7 - basic hashCode/equals tests
|
// test 7 - basic hashCode/equals tests
|
||||||
System.out.println(" - Test: hashCode/equals");
|
System.out.println(" - Test: hashCode/equals");
|
||||||
|
@ -24,12 +24,11 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
||||||
import jdk.testlibrary.OutputAnalyzer;
|
import jdk.testlibrary.OutputAnalyzer;
|
||||||
import jdk.testlibrary.JDKToolLauncher;
|
|
||||||
import jdk.testlibrary.ProcessTools;
|
import jdk.testlibrary.ProcessTools;
|
||||||
import jdk.testlibrary.Utils;
|
import jdk.testlibrary.Utils;
|
||||||
import jdk.testlibrary.ProcessThread;
|
import jdk.testlibrary.ProcessThread;
|
||||||
@ -39,6 +38,7 @@ import jdk.testlibrary.ProcessThread;
|
|||||||
* (Test runner = class that launch a test)
|
* (Test runner = class that launch a test)
|
||||||
*/
|
*/
|
||||||
public class RunnerUtil {
|
public class RunnerUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Application process must be run concurrently with our tests since
|
* The Application process must be run concurrently with our tests since
|
||||||
* the tests will attach to the Application.
|
* the tests will attach to the Application.
|
||||||
@ -49,16 +49,31 @@ public class RunnerUtil {
|
|||||||
*
|
*
|
||||||
* The Application will write its pid and shutdownPort in the given outFile.
|
* The Application will write its pid and shutdownPort in the given outFile.
|
||||||
*/
|
*/
|
||||||
public static ProcessThread startApplication(String outFile) throws Throwable {
|
public static ProcessThread startApplication(String outFile, String... additionalOpts) throws Throwable {
|
||||||
String classpath = System.getProperty("test.class.path", ".");
|
String classpath = System.getProperty("test.class.path", ".");
|
||||||
String[] args = Utils.addTestJavaOpts(
|
String[] myArgs = concat(additionalOpts, new String [] { "-Dattach.test=true", "-classpath", classpath, "Application", outFile });
|
||||||
"-Dattach.test=true", "-classpath", classpath, "Application", outFile);
|
String[] args = Utils.addTestJavaOpts(myArgs);
|
||||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(args);
|
||||||
ProcessThread pt = new ProcessThread("runApplication", pb);
|
ProcessThread pt = new ProcessThread("runApplication", pb);
|
||||||
pt.start();
|
pt.start();
|
||||||
return pt;
|
return pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] concat(String[] a, String[] b) {
|
||||||
|
if (a == null) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
if (b == null) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
int aLen = a.length;
|
||||||
|
int bLen = b.length;
|
||||||
|
String[] c = new String[aLen + bLen];
|
||||||
|
System.arraycopy(a, 0, c, 0, aLen);
|
||||||
|
System.arraycopy(b, 0, c, aLen, bLen);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will stop the running Application.
|
* Will stop the running Application.
|
||||||
* First tries to shutdown nicely by connecting to the shut down port.
|
* First tries to shutdown nicely by connecting to the shut down port.
|
||||||
|
169
jdk/test/com/sun/tools/attach/TempDirTest.java
Normal file
169
jdk/test/com/sun/tools/attach/TempDirTest.java
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.sun.tools.attach.*;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import jdk.testlibrary.OutputAnalyzer;
|
||||||
|
import jdk.testlibrary.ProcessTools;
|
||||||
|
import jdk.testlibrary.ProcessThread;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 8033104
|
||||||
|
* @summary Test to make sure attach and jvmstat works correctly when java.io.tmpdir is set
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @run build Application Shutdown RunnerUtil
|
||||||
|
* @run main/timeout=10 TempDirTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TempDirTest {
|
||||||
|
|
||||||
|
public static void main(String args[]) throws Throwable {
|
||||||
|
|
||||||
|
Path clientTmpDir = Files.createTempDirectory("TempDirTest-client");
|
||||||
|
clientTmpDir.toFile().deleteOnExit();
|
||||||
|
Path targetTmpDir = Files.createTempDirectory("TempDirTest-target");
|
||||||
|
targetTmpDir.toFile().deleteOnExit();
|
||||||
|
|
||||||
|
// run the test with all possible combinations of setting java.io.tmpdir
|
||||||
|
runExperiment(null, null);
|
||||||
|
runExperiment(clientTmpDir, null);
|
||||||
|
runExperiment(clientTmpDir, targetTmpDir);
|
||||||
|
runExperiment(null, targetTmpDir);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int counter = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The actual test is in the nested class TestMain.
|
||||||
|
* The responsibility of this class is to:
|
||||||
|
* 1. Start the Application class in a separate process.
|
||||||
|
* 2. Find the pid and shutdown port of the running Application.
|
||||||
|
* 3. Launches the tests in nested class TestMain that will attach to the Application.
|
||||||
|
* 4. Shut down the Application.
|
||||||
|
*/
|
||||||
|
public static void runExperiment(Path clientTmpDir, Path targetTmpDir) throws Throwable {
|
||||||
|
|
||||||
|
System.out.print("### Running tests with overridden tmpdir for");
|
||||||
|
System.out.print(" client: " + (clientTmpDir == null ? "no" : "yes"));
|
||||||
|
System.out.print(" target: " + (targetTmpDir == null ? "no" : "yes"));
|
||||||
|
System.out.println(" ###");
|
||||||
|
|
||||||
|
final String pidFile = "TempDirTest.Application.pid-" + counter++;
|
||||||
|
ProcessThread processThread = null;
|
||||||
|
RunnerUtil.ProcessInfo info = null;
|
||||||
|
try {
|
||||||
|
String[] tmpDirArg = null;
|
||||||
|
if (targetTmpDir != null) {
|
||||||
|
tmpDirArg = new String[] {"-Djava.io.tmpdir=" + targetTmpDir};
|
||||||
|
}
|
||||||
|
processThread = RunnerUtil.startApplication(pidFile, tmpDirArg);
|
||||||
|
info = RunnerUtil.readProcessInfo(pidFile);
|
||||||
|
launchTests(info.pid, clientTmpDir);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
System.out.println("TempDirTest got unexpected exception: " + t);
|
||||||
|
t.printStackTrace();
|
||||||
|
throw t;
|
||||||
|
} finally {
|
||||||
|
// Make sure the Application process is stopped.
|
||||||
|
RunnerUtil.stopApplication(info.shutdownPort, processThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the actual tests in nested class TestMain.
|
||||||
|
* The reason for running the tests in a separate process
|
||||||
|
* is that we need to modify the class path and
|
||||||
|
* the -Djava.io.tmpdir property.
|
||||||
|
*/
|
||||||
|
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
|
||||||
|
final String sep = File.separator;
|
||||||
|
|
||||||
|
// Need to add jdk/lib/tools.jar to classpath.
|
||||||
|
String classpath =
|
||||||
|
System.getProperty("test.class.path", "") + File.pathSeparator +
|
||||||
|
System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
|
||||||
|
|
||||||
|
String[] tmpDirArg = null;
|
||||||
|
if (clientTmpDir != null) {
|
||||||
|
tmpDirArg = new String [] {"-Djava.io.tmpdir=" + clientTmpDir};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
|
||||||
|
String[] args = RunnerUtil.concat(
|
||||||
|
tmpDirArg,
|
||||||
|
new String[] {
|
||||||
|
"-classpath",
|
||||||
|
classpath,
|
||||||
|
"TempDirTest$TestMain",
|
||||||
|
Integer.toString(pid) });
|
||||||
|
OutputAnalyzer output = ProcessTools.executeTestJvm(args);
|
||||||
|
output.shouldHaveExitValue(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the actual test. It will attach to the running Application
|
||||||
|
* and perform a number of basic attach tests.
|
||||||
|
*/
|
||||||
|
public static class TestMain {
|
||||||
|
public static void main(String args[]) throws Exception {
|
||||||
|
String pid = args[0];
|
||||||
|
|
||||||
|
// Test 1 - list method should list the target VM
|
||||||
|
System.out.println(" - Test: VirtualMachine.list");
|
||||||
|
List<VirtualMachineDescriptor> l = VirtualMachine.list();
|
||||||
|
boolean found = false;
|
||||||
|
for (VirtualMachineDescriptor vmd: l) {
|
||||||
|
if (vmd.id().equals(pid)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
System.out.println(" - " + pid + " found.");
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(pid + " not found in VM list");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test 2 - try to attach and verify connection
|
||||||
|
|
||||||
|
System.out.println(" - Attaching to application ...");
|
||||||
|
VirtualMachine vm = VirtualMachine.attach(pid);
|
||||||
|
|
||||||
|
System.out.println(" - Test: system properties in target VM");
|
||||||
|
Properties props = vm.getSystemProperties();
|
||||||
|
String value = props.getProperty("attach.test");
|
||||||
|
if (value == null || !value.equals("true")) {
|
||||||
|
throw new RuntimeException("attach.test property not set");
|
||||||
|
}
|
||||||
|
System.out.println(" - attach.test property set as expected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,6 @@ grant {
|
|||||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmstat.monitor";
|
permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmstat.monitor";
|
||||||
permission java.lang.RuntimePermission "loadLibrary.attach";
|
permission java.lang.RuntimePermission "loadLibrary.attach";
|
||||||
permission java.util.PropertyPermission "sun.jvmstat.*", "read";
|
permission java.util.PropertyPermission "sun.jvmstat.*", "read";
|
||||||
permission java.util.PropertyPermission "java.io.tmpdir", "read";
|
|
||||||
|
|
||||||
/* to read configuration file in META-INF/services, and write/delete .attach_pid<pid> */
|
/* to read configuration file in META-INF/services, and write/delete .attach_pid<pid> */
|
||||||
permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
|
permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
|
||||||
|
@ -11,7 +11,6 @@ grant {
|
|||||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.tools.attach";
|
permission java.lang.RuntimePermission "accessClassInPackage.sun.tools.attach";
|
||||||
permission java.lang.RuntimePermission "loadLibrary.attach";
|
permission java.lang.RuntimePermission "loadLibrary.attach";
|
||||||
permission java.util.PropertyPermission "sun.jvmstat.*", "read";
|
permission java.util.PropertyPermission "sun.jvmstat.*", "read";
|
||||||
permission java.util.PropertyPermission "java.io.tmpdir", "read";
|
|
||||||
|
|
||||||
/* to read configuration file in META-INF/services, and write/delete .attach_pid<pid> */
|
/* to read configuration file in META-INF/services, and write/delete .attach_pid<pid> */
|
||||||
permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
|
permission java.io.FilePermission "<<ALL FILES>>", "read,write,delete";
|
||||||
|
Loading…
Reference in New Issue
Block a user