changeset 4625:991f51db80db

7132199: sun/management/jmxremote/bootstrap/JvmstatCountersTest.java failing on all platforms Summary: Make sure HotSpot and JDK looks for well-known files in the same location Reviewed-by: dholmes, dsamersoff
author sla
date Wed, 01 Feb 2012 10:46:14 +0100
parents 778aec779d4c
children 0d26f3ccaad7
files src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java
diffstat 2 files changed, 18 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java	Tue Jan 31 11:53:23 2012 -0800
+++ b/src/solaris/classes/sun/tools/attach/LinuxVirtualMachine.java	Wed Feb 01 10:46:14 2012 +0100
@@ -37,8 +37,12 @@
  * Linux implementation of HotSpotVirtualMachine
  */
 public class LinuxVirtualMachine extends HotSpotVirtualMachine {
-    // temp directory for socket file
-    private static final String tmpdir = System.getProperty("java.io.tmpdir");
+    // "/tmp" is used as a global well-known location for the files
+    // .java_pid<pid>. and .attach_pid<pid>. It is important that this
+    // location is the same for all processes, otherwise the tools
+    // will not be able to find all Hotspot processes.
+    // Any changes to this needs to be synchronized with HotSpot.
+    private static final String tmpdir = "/tmp";
 
     // Indicates if this machine uses the old LinuxThreads
     static boolean isLinuxThreads;
@@ -261,20 +265,12 @@
     }
 
     // Return the socket file for the given process.
-    // Checks working directory of process for .java_pid<pid>. If not
-    // found it looks in temp directory.
     private String findSocketFile(int pid) {
-        // First check for a .java_pid<pid> file in the working directory
-        // of the target process
-        String fn = ".java_pid" + pid;
-        String path = "/proc/" + pid + "/cwd/" + fn;
-        File f = new File(path);
+        File f = new File(tmpdir, ".java_pid" + pid);
         if (!f.exists()) {
-            // Not found, so try temp directory
-            f = new File(tmpdir, fn);
-            path = f.exists() ? f.getPath() : null;
+            return null;
         }
-        return path;
+        return f.getPath();
     }
 
     // On Solaris/Linux a simple handshake is used to start the attach mechanism
--- a/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java	Tue Jan 31 11:53:23 2012 -0800
+++ b/src/solaris/classes/sun/tools/attach/SolarisVirtualMachine.java	Wed Feb 01 10:46:14 2012 +0100
@@ -38,11 +38,12 @@
  * Solaris implementation of HotSpotVirtualMachine.
  */
 public class SolarisVirtualMachine extends HotSpotVirtualMachine {
-    // Use /tmp instead of /var/tmp on Solaris as /tmp is the default used by
-    // HotSpot when the property is not set on the command line.
-    private static final String tmpdir1 = System.getProperty("java.io.tmpdir");
-    private static final String tmpdir =
-        (tmpdir1.equals("/var/tmp") || tmpdir1.equals("/var/tmp/")) ? "/tmp" : tmpdir1;
+    // "/tmp" is used as a global well-known location for the files
+    // .java_pid<pid>. and .attach_pid<pid>. It is important that this
+    // location is the same for all processes, otherwise the tools
+    // will not be able to find all Hotspot processes.
+    // Any changes to this needs to be synchronized with HotSpot.
+    private static final String tmpdir = "/tmp";
 
     // door descriptor;
     private int fd = -1;
@@ -191,19 +192,10 @@
         }
     }
 
-    // The door is attached to .java_pid<pid> in the target VM's working
-    // directory or temporary directory.
+    // The door is attached to .java_pid<pid> in the temporary directory.
     private int openDoor(int pid) throws IOException {
-        // First check for a .java_pid<pid> file in the working directory
-        // of the target process
-        String fn = ".java_pid" + pid;
-        String path = "/proc/" + pid + "/cwd/" + fn;
-        try {
-            fd = open(path);
-        } catch (FileNotFoundException fnf) {
-            path = tmpdir + "/" + fn;
-            fd = open(path);
-        }
+        String path = tmpdir + "/.java_pid" + pid;;
+        fd = open(path);
 
         // Check that the file owner/permission to avoid attaching to
         // bogus process