20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * Note 1: JITDebug.java is no longer a standalone regression test, |
25 * Note: What seems to be an excessive use of System.xxx.flush(); |
26 * due to chronic test failures on win32 platforms. When testing, |
26 * is actually necessary to combat lost output on win32 systems. |
27 * use the wrapper script (JITDebug.sh) instead, which will in turn |
|
28 * invoke this program. |
|
29 * |
27 * |
30 * The problems are related to inconsistent use of "SystemRoot" |
28 * @test |
31 * versus "SYSTEMROOT" environment variables in different win32 O/S |
29 * @bug 4291701 4376819 4422312 4522770 |
32 * installations. Refer to the Comments and Evaluation on bugs |
30 * @summary Test JIT debugging - |
33 * 4522770 and 4461673 for more information. |
31 * assure that launching on uncaught exception works |
34 * |
32 * |
35 * Undefined SystemRoot in a win32 environment causes the O/S socket() |
33 * @library /test/lib |
36 * layer to fail with WSAEPROVIDERFAILEDINIT. The workaround used by |
|
37 * JITDebug.sh and JITDebug.java is to select the dt_shmem transport |
|
38 * on any win32 platform where SystemRoot is not found. |
|
39 * |
34 * |
40 * Note 2: What seems to be an excessive use of System.xxx.flush(); |
35 * @author Robert Field |
41 * is actually necessary to combat lost output on win32 systems. |
36 * @run main/othervm JITDebug |
42 * |
|
43 * @t e s t |
|
44 * @bug 4291701 4376819 4422312 4522770 |
|
45 * @summary Test JIT debugging - |
|
46 * assure that launching on uncaught exception works |
|
47 * |
|
48 * @author Robert Field |
|
49 * @run driver JITDebug |
|
50 */ |
37 */ |
51 |
38 |
52 import com.sun.jdi.*; |
39 import com.sun.jdi.*; |
53 import com.sun.jdi.connect.*; |
40 import com.sun.jdi.connect.*; |
|
41 import jdk.test.lib.JDKToolFinder; |
|
42 import jdk.test.lib.Utils; |
|
43 import jdk.test.lib.process.ProcessTools; |
|
44 |
54 import java.util.*; |
45 import java.util.*; |
55 import java.io.*; |
|
56 |
46 |
57 /* |
47 /* |
58 * This class implements three separate small programs, each |
48 * This class implements three separate small programs, each |
59 * of which (directly or indirectly) invokes the next. These |
49 * of which (directly or indirectly) invokes the next. These |
60 * programs are: |
50 * programs are: |
95 } else { |
85 } else { |
96 return false; |
86 return false; |
97 } |
87 } |
98 case 3: |
88 case 3: |
99 if (args[0].equals("DEBUGGER")) { |
89 if (args[0].equals("DEBUGGER")) { |
100 trivialDebugger(args[2]); |
90 // launched by using "-agentlib:" "launch" sub-option: |
|
91 // The following strings are appended to the string given in this argument (space-delimited). |
|
92 // They can aid the launched debugger in establishing a connection with this VM. |
|
93 // The resulting string is executed. |
|
94 // - The value of the transport sub-option. |
|
95 // - The value of the address sub-option (or the generated address if one is not given) |
|
96 trivialDebugger(args[1], args[2]); |
101 return true; |
97 return true; |
102 } else { |
98 } else { |
103 return false; |
99 return false; |
104 } |
100 } |
105 default: |
101 default: |
106 return false; |
102 return false; |
107 } |
103 } |
108 } |
104 } |
109 |
105 |
110 void testLaunch() { |
106 void testLaunch() { |
111 class DisplayOutput extends Thread { |
107 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true); |
112 InputStream in; |
108 List largs = pb.command(); |
113 |
109 largs.add("-classpath"); |
114 DisplayOutput(InputStream in) { |
110 largs.add(Utils.TEST_CLASSES); |
115 this.in = in; |
111 String javaExe = JDKToolFinder.getJDKTool("java"); |
116 } |
112 largs.add("-agentlib:jdwp=transport=dt_socket,server=y,onuncaught=y," + |
117 |
113 "launch=" + javaExe + " " + this.getClass().getName() + " DEBUGGER "); |
118 public void run() { |
114 largs.add(this.getClass().getName()); |
119 try { |
|
120 transfer(); |
|
121 } catch (IOException exc) { |
|
122 new RuntimeException("Unexpected exception: " + exc); |
|
123 } |
|
124 } |
|
125 |
|
126 void transfer() throws IOException { |
|
127 int ch; |
|
128 while ((ch = in.read()) != -1) { |
|
129 System.out.print((char)ch); |
|
130 } |
|
131 in.close(); |
|
132 } |
|
133 } |
|
134 String transportMethod = System.getProperty("TRANSPORT_METHOD"); |
|
135 if (transportMethod == null) { |
|
136 transportMethod = "dt_socket"; //Default to socket transport. |
|
137 } |
|
138 String javaExe = System.getProperty("java.home") + |
|
139 File.separator + "bin" + File.separator +"java"; |
|
140 List largs = new ArrayList(); |
|
141 largs.add(javaExe); |
|
142 largs.add("-agentlib:jdwp=transport=" + transportMethod + ",server=y,onuncaught=y," + |
|
143 "launch=" + |
|
144 javaExe + " -DTRANSPORT_METHOD=" + transportMethod + " " + |
|
145 this.getClass().getName() + " DEBUGGER "); |
|
146 largs.add("JITDebug"); |
|
147 largs.add("TARGET"); |
115 largs.add("TARGET"); |
148 System.out.println("Launching: " + largs); |
|
149 String[] sargs = (String[])largs.toArray(new String[largs.size()]); |
|
150 Runtime rt = Runtime.getRuntime(); |
|
151 try { |
116 try { |
152 Process proc = rt.exec(VMConnection.insertDebuggeeVMOptions(sargs)); |
117 ProcessTools.executeCommand(pb) |
153 DisplayOutput inThread = new DisplayOutput(proc.getInputStream()); |
118 .shouldHaveExitValue(0); |
154 DisplayOutput erThread = new DisplayOutput(proc.getErrorStream()); |
119 } catch (Throwable exc) { |
155 inThread.start(); // transfer all in&err |
|
156 erThread.start(); |
|
157 inThread.join(); // make sure they are done |
|
158 erThread.join(); |
|
159 int exitValue = proc.waitFor(); |
|
160 if (exitValue != 0) { |
|
161 throw new RuntimeException("Failure exit status: " + |
|
162 exitValue); |
|
163 } |
|
164 } catch (Exception exc) { |
|
165 throw new RuntimeException("Unexpected exception: " + exc); |
120 throw new RuntimeException("Unexpected exception: " + exc); |
166 } |
121 } |
167 System.out.println("JIT Debugging test PASSED"); |
122 System.out.println("JIT Debugging test PASSED"); |
168 } |
123 } |
169 |
|
170 void displayOutput(InputStream in) throws IOException { |
|
171 |
|
172 } |
|
173 |
|
174 |
124 |
175 // Target VM code |
125 // Target VM code |
176 void debugTarget() { |
126 void debugTarget() { |
177 System.out.flush(); |
127 System.out.flush(); |
178 System.out.println("trigger onuncaught launch"); |
128 System.out.println("trigger onuncaught launch"); |
179 System.out.flush(); |
129 System.out.flush(); |
180 throw new RuntimeException("Start-up onuncaught handling"); |
130 throw new RuntimeException("Start-up onuncaught handling"); |
181 } |
131 } |
182 |
132 |
183 void trivialDebugger(String transportAddress) { |
133 void trivialDebugger(String transportMethod, String transportAddress) { |
184 System.out.println("trivial debugger started"); |
134 System.out.println("trivial debugger started"); |
185 String transportMethod = System.getProperty("TRANSPORT_METHOD"); |
|
186 String connectorName = null; |
135 String connectorName = null; |
187 if ("dt_shmem".equals(transportMethod)) { |
136 if ("dt_shmem".equals(transportMethod)) { |
188 connectorName = "com.sun.jdi.SharedMemoryAttach"; |
137 connectorName = "com.sun.jdi.SharedMemoryAttach"; |
189 } else if ("dt_socket".equals(transportMethod)) { |
138 } else if ("dt_socket".equals(transportMethod)) { |
190 connectorName = "com.sun.jdi.SocketAttach"; |
139 connectorName = "com.sun.jdi.SocketAttach"; |