author | naoto |
Tue, 05 Apr 2016 09:13:30 -0700 | |
changeset 36860 | dad1a46b0a88 |
parent 36209 | 8db2a78cbc29 |
child 38152 | 80e5da81fb2c |
permissions | -rw-r--r-- |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
1 |
/* |
36209
8db2a78cbc29
8151156: [TESTBUG] Integrate trivial Hotspot test changes from Jake before Jigsaw M3
ctornqvi
parents:
30604
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
4 |
* |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
8 |
* |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
13 |
* accompanied this code). |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
14 |
* |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
18 |
* |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
21 |
* questions. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
22 |
*/ |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
23 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
24 |
/* |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
25 |
* @test |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
26 |
* @bug 7162400 |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
27 |
* @key regression |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
28 |
* @summary Regression test for attach issue where stale pid files in /tmp lead to connection issues |
36209
8db2a78cbc29
8151156: [TESTBUG] Integrate trivial Hotspot test changes from Jake before Jigsaw M3
ctornqvi
parents:
30604
diff
changeset
|
29 |
* @modules jdk.attach/sun.tools.attach |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
30 |
* @library /testlibrary |
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30111
diff
changeset
|
31 |
* @build jdk.test.lib.* AttachWithStalePidFileTarget |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
32 |
* @run main AttachWithStalePidFile |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
33 |
*/ |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
34 |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30111
diff
changeset
|
35 |
import jdk.test.lib.*; |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
36 |
import com.sun.tools.attach.VirtualMachine; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
37 |
import sun.tools.attach.HotSpotVirtualMachine; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
38 |
import java.lang.reflect.Field; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
39 |
import java.nio.file.*; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
40 |
import java.nio.file.attribute.*; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
41 |
import java.io.*; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
42 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
43 |
public class AttachWithStalePidFile { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
44 |
public static void main(String... args) throws Exception { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
45 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
46 |
// this test is only valid on non-Windows platforms |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
47 |
if(Platform.isWindows()) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
48 |
System.out.println("This test is only valid on non-Windows platforms."); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
49 |
return; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
50 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
51 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
52 |
// Since there might be stale pid-files owned by different |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
53 |
// users on the system we may need to retry the test in case we |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
54 |
// are unable to remove the existing file. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
55 |
int retries = 5; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
56 |
while(!runTest() && --retries > 0); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
57 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
58 |
if(retries == 0) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
59 |
throw new RuntimeException("Test failed after 5 retries. " + |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
60 |
"Remove any /tmp/.java_pid* files and retry."); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
61 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
62 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
63 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
64 |
public static boolean runTest() throws Exception { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
65 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
66 |
"-XX:+UnlockDiagnosticVMOptions", "-XX:+PauseAtStartup", "AttachWithStalePidFileTarget"); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
67 |
Process target = pb.start(); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
68 |
Path pidFile = null; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
69 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
70 |
try { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
71 |
int pid = getUnixProcessId(target); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
72 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
73 |
// create the stale .java_pid file. use hard-coded /tmp path as in th VM |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
74 |
pidFile = createJavaPidFile(pid); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
75 |
if(pidFile == null) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
76 |
return false; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
77 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
78 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
79 |
// wait for vm.paused file to be created and delete it once we find it. |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
80 |
waitForAndResumeVM(pid); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
81 |
|
30111
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
82 |
waitForTargetReady(target); |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
83 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
84 |
HotSpotVirtualMachine vm = (HotSpotVirtualMachine)VirtualMachine.attach(((Integer)pid).toString()); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
85 |
BufferedReader remoteDataReader = new BufferedReader(new InputStreamReader(vm.remoteDataDump())); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
86 |
String line = null; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
87 |
while((line = remoteDataReader.readLine()) != null); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
88 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
89 |
vm.detach(); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
90 |
return true; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
91 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
92 |
finally { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
93 |
target.destroy(); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
94 |
target.waitFor(); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
95 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
96 |
if(pidFile != null && Files.exists(pidFile)) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
97 |
Files.delete(pidFile); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
98 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
99 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
100 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
101 |
|
30111
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
102 |
private static void waitForTargetReady(Process target) throws IOException { |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
103 |
BufferedReader br = new BufferedReader(new InputStreamReader(target.getInputStream())); |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
104 |
String line = br.readLine(); |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
105 |
// wait for the ready message having been printed or EOF (line == null) |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
106 |
while (line != null && !line.equals(AttachWithStalePidFileTarget.READY_MSG)) { |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
107 |
line = br.readLine(); |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
108 |
} |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
109 |
// target VM ready |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
110 |
} |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
111 |
|
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
112 |
private static Path createJavaPidFile(int pid) throws Exception { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
113 |
Path pidFile = Paths.get("/tmp/.java_pid" + pid); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
114 |
if(Files.exists(pidFile)) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
115 |
try { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
116 |
Files.delete(pidFile); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
117 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
118 |
catch(FileSystemException e) { |
30111
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
119 |
if(e.getReason().matches("Operation not permitted|Not owner")) { |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
120 |
System.out.println("Unable to remove exisiting stale PID file" + pidFile); |
30111
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
121 |
System.out.println("==================================================="); |
fbba8c368ce0
8024055: serviceability/attach/AttachWithStalePidFile.java createJavaPidFile() fails
jbachorik
parents:
28819
diff
changeset
|
122 |
e.printStackTrace(System.out); |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
123 |
return null; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
124 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
125 |
throw e; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
126 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
127 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
128 |
return Files.createFile(pidFile, |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
129 |
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------"))); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
130 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
131 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
132 |
private static void waitForAndResumeVM(int pid) throws Exception { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
133 |
Path pauseFile = Paths.get("vm.paused." + pid); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
134 |
int retries = 60; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
135 |
while(!Files.exists(pauseFile) && --retries > 0) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
136 |
Thread.sleep(1000); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
137 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
138 |
if(retries == 0) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
139 |
throw new RuntimeException("Timeout waiting for VM to start. " + |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
140 |
"vm.paused file not created within 60 seconds."); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
141 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
142 |
Files.delete(pauseFile); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
143 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
144 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
145 |
private static int getUnixProcessId(Process unixProcess) throws Exception { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
146 |
Field pidField = unixProcess.getClass().getDeclaredField("pid"); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
147 |
pidField.setAccessible(true); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
148 |
return (Integer)pidField.get(unixProcess); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
149 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
diff
changeset
|
150 |
} |