< prev index next >

open/src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2015 SAP SE. 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

@@ -44,13 +44,11 @@
     // .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";
-
-    // The patch to the socket file created by the target VM
-    String path;
+    String socket_name;
 
     /**
      * Attaches to the target VM
      */
     VirtualMachineImpl(AttachProvider provider, String vmid)

@@ -67,12 +65,13 @@
         }
 
         // Find the socket file. If not found then we attempt to start the
         // attach mechanism in the target VM by sending it a QUIT signal.
         // Then we attempt to find the socket file again.
-        path = findSocketFile(pid);
-        if (path == null) {
+        File path = new File(tmpdir, ".java_pid" + pid);
+        socket_name = path.getPath();
+        if (!path.exists()) {
             File f = createAttachFile(pid);
             try {
                 sendQuitTo(pid);
 
                 // give the target VM time to start the attach mechanism

@@ -84,39 +83,39 @@
                     // Increase timeout on each attempt to reduce polling
                     delay += delay_step;
                     try {
                         Thread.sleep(delay);
                     } catch (InterruptedException x) { }
-                    path = findSocketFile(pid);
 
                     time_spend += delay;
-                    if (time_spend > timeout/2 && path == null) {
+                    if (time_spend > timeout/2 && !path.exists()) {
                         // Send QUIT again to give target VM the last chance to react
                         sendQuitTo(pid);
                     }
-                } while (time_spend <= timeout && path == null);
-                if (path == null) {
+                } while (time_spend <= timeout && !path.exists());
+                if (!path.exists()) {
                     throw new AttachNotSupportedException(
                         String.format("Unable to open socket file %s: " +
                           "target process %d doesn't respond within %dms " +
-                          "or HotSpot VM not loaded", f.getPath(), pid, time_spend));
+                           "or HotSpot VM not loaded", socket_name, pid,
+                                      time_spend));
                 }
             } finally {
                 f.delete();
             }
         }
 
         // Check that the file owner/permission to avoid attaching to
         // bogus process
-        checkPermissions(path);
+        checkPermissions(socket_name);
 
         // Check that we can connect to the process
         // - this ensures we throw the permission denied error now rather than
         // later when we attempt to enqueue a command.
         int s = socket();
         try {
-            connect(s, path);
+            connect(s, socket_name);
         } finally {
             close(s);
         }
     }
 

@@ -262,19 +261,10 @@
         public void close() throws IOException {
             VirtualMachineImpl.close(s);
         }
     }
 
-    // Return the socket file for the given process.
-    private String findSocketFile(int pid) {
-        File f = new File(tmpdir, ".java_pid" + pid);
-        if (!f.exists()) {
-            return null;
-        }
-        return f.getPath();
-    }
-
     // On Solaris/Linux/Aix a simple handshake is used to start the attach mechanism
     // if not already started. The client creates a .attach_pid<pid> file in the
     // target VM's working directory (or temp directory), and the SIGQUIT handler
     // checks for the file.
     private File createAttachFile(int pid) throws IOException {
< prev index next >