1 /* |
1 /* |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
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 import java.util.Arrays; |
24 import java.util.Arrays; |
|
25 import java.nio.charset.Charset; |
|
26 import java.nio.charset.StandardCharsets; |
25 |
27 |
26 import jdk.test.lib.process.OutputAnalyzer; |
28 import jdk.test.lib.process.OutputAnalyzer; |
27 import jdk.test.lib.process.ProcessTools; |
29 import jdk.test.lib.process.ProcessTools; |
28 import jdk.test.lib.JDKToolLauncher; |
30 import jdk.test.lib.JDKToolLauncher; |
29 |
31 |
38 private static ProcessBuilder processBuilder = new ProcessBuilder(); |
40 private static ProcessBuilder processBuilder = new ProcessBuilder(); |
39 |
41 |
40 public static void main(String[] args) throws Exception { |
42 public static void main(String[] args) throws Exception { |
41 testJstackNoArgs(); |
43 testJstackNoArgs(); |
42 testJstack_l(); |
44 testJstack_l(); |
|
45 testJstackUTF8Encoding(); |
43 } |
46 } |
44 |
47 |
45 private static void testJstackNoArgs() throws Exception { |
48 private static void testJstackNoArgs() throws Exception { |
46 OutputAnalyzer output = jstack(); |
49 String marker = "testJstackNoArgs"; |
|
50 OutputAnalyzer output = jstack(marker); |
47 output.shouldHaveExitValue(0); |
51 output.shouldHaveExitValue(0); |
|
52 output.shouldContain(marker); |
48 } |
53 } |
49 |
54 |
50 private static void testJstack_l() throws Exception { |
55 private static void testJstack_l() throws Exception { |
51 OutputAnalyzer output = jstack("-l"); |
56 String marker = "testJstack_l"; |
|
57 OutputAnalyzer output = jstack(marker, "-l"); |
52 output.shouldHaveExitValue(0); |
58 output.shouldHaveExitValue(0); |
|
59 output.shouldContain(marker); |
53 } |
60 } |
54 |
61 |
55 private static OutputAnalyzer jstack(String... toolArgs) throws Exception { |
62 private static void testJstackUTF8Encoding() throws Exception { |
|
63 String marker = "markerName" + "\u00e4\u0bb5".repeat(60); |
|
64 OutputAnalyzer output = jstack(marker); |
|
65 output.shouldHaveExitValue(0); |
|
66 output.shouldContain(marker); |
|
67 } |
|
68 |
|
69 private static OutputAnalyzer jstack(String marker, String... toolArgs) throws Exception { |
|
70 Charset cs = StandardCharsets.UTF_8; |
|
71 Thread.currentThread().setName(marker); |
56 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack"); |
72 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack"); |
57 launcher.addVMArg("-XX:+UsePerfData"); |
73 launcher.addVMArg("-XX:+UsePerfData"); |
|
74 launcher.addVMArg("-Dfile.encoding=" + cs); |
58 if (toolArgs != null) { |
75 if (toolArgs != null) { |
59 for (String toolArg : toolArgs) { |
76 for (String toolArg : toolArgs) { |
60 launcher.addToolArg(toolArg); |
77 launcher.addToolArg(toolArg); |
61 } |
78 } |
62 } |
79 } |
63 launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); |
80 launcher.addToolArg(Long.toString(ProcessTools.getProcessId())); |
64 |
81 |
65 processBuilder.command(launcher.getCommand()); |
82 processBuilder.command(launcher.getCommand()); |
66 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
83 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", "")); |
67 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder); |
84 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder, null, cs); |
68 System.out.println(output.getOutput()); |
85 System.out.println(output.getOutput()); |
69 |
86 |
70 return output; |
87 return output; |
71 } |
88 } |
72 |
89 |