Skip to content

Commit cb02158

Browse files
author
Alex Menkov
committed
8354461: Update tests to disable streaming output for attach tools
Reviewed-by: sspitsyn, cjplummer
1 parent 28e6b7c commit cb02158

19 files changed

+103
-115
lines changed

test/hotspot/jtreg/runtime/CommandLine/PrintClasses.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
23
* Copyright (c) 2022, Alibaba Group Holding Limited. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
@@ -39,20 +40,19 @@
3940
* @run main/othervm -XX:StartFlightRecording PrintClasses
4041
*/
4142

43+
import jdk.test.lib.dcmd.PidJcmdExecutor;
4244
import jdk.test.lib.process.OutputAnalyzer;
43-
import jdk.test.lib.JDKToolFinder;
4445

4546
public class PrintClasses {
4647
public static void main(String args[]) throws Exception {
47-
var pid = Long.toString(ProcessHandle.current().pid());
4848
var pb = new ProcessBuilder();
4949

50-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.classes"});
50+
pb.command(new PidJcmdExecutor().getCommandLine("VM.classes"));
5151
var output = new OutputAnalyzer(pb.start());
5252
output.shouldNotContain("instance size");
5353
output.shouldContain(PrintClasses.class.getSimpleName());
5454

55-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.classes", "-verbose"});
55+
pb.command(new PidJcmdExecutor().getCommandLine("VM.classes", "-verbose"));
5656
output = new OutputAnalyzer(pb.start());
5757
output.shouldContain("instance size");
5858
output.shouldContain(PrintClasses.class.getSimpleName());

test/hotspot/jtreg/runtime/ElfDecoder/TestElfDirectRead.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -57,9 +57,8 @@
5757
-XX:NativeMemoryTracking=detail TestElfDirectRead
5858
*/
5959

60-
import jdk.test.lib.process.ProcessTools;
60+
import jdk.test.lib.dcmd.PidJcmdExecutor;
6161
import jdk.test.lib.process.OutputAnalyzer;
62-
import jdk.test.lib.JDKToolFinder;
6362
import jdk.test.whitebox.WhiteBox;
6463

6564
public class TestElfDirectRead {
@@ -68,10 +67,8 @@ public static void main(String args[]) throws Exception {
6867
wb.disableElfSectionCache();
6968
ProcessBuilder pb = new ProcessBuilder();
7069
OutputAnalyzer output;
71-
// Grab my own PID
72-
String pid = Long.toString(ProcessTools.getProcessId());
7370

74-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"});
71+
pb.command(new PidJcmdExecutor().getCommandLine("VM.native_memory", "detail"));
7572
output = new OutputAnalyzer(pb.start());
7673
// This is a pre-populated stack frame, should always exist if can decode
7774
output.shouldContain("MallocSiteTable::new_entry");

test/hotspot/jtreg/runtime/Metaspace/PrintMetaspaceDcmd.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2018, SAP and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -22,9 +22,8 @@
2222
* questions.
2323
*/
2424

25-
import jdk.test.lib.process.ProcessTools;
25+
import jdk.test.lib.dcmd.PidJcmdExecutor;
2626
import jdk.test.lib.process.OutputAnalyzer;
27-
import jdk.test.lib.JDKToolFinder;
2827

2928
/*
3029
* @test id=test-64bit-ccs
@@ -71,10 +70,8 @@ public class PrintMetaspaceDcmd {
7170
private static void doTheNoSpecifiedPropTest() throws Exception {
7271
ProcessBuilder pb = new ProcessBuilder();
7372
OutputAnalyzer output;
74-
// Grab my own PID
75-
String pid = Long.toString(ProcessTools.getProcessId());
7673

77-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"});
74+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "basic"));
7875
output = new OutputAnalyzer(pb.start());
7976
output.shouldHaveExitValue(0);
8077
output.shouldMatch("MaxMetaspaceSize: unlimited");
@@ -83,10 +80,8 @@ private static void doTheNoSpecifiedPropTest() throws Exception {
8380
private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Exception {
8481
ProcessBuilder pb = new ProcessBuilder();
8582
OutputAnalyzer output;
86-
// Grab my own PID
87-
String pid = Long.toString(ProcessTools.getProcessId());
8883

89-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "basic"});
84+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "basic"));
9085
output = new OutputAnalyzer(pb.start());
9186
output.shouldHaveExitValue(0);
9287
if (usesCompressedClassSpace) {
@@ -97,7 +92,7 @@ private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Ex
9792
output.shouldContain("Chunk freelists:");
9893
output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB");
9994

100-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace"});
95+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace"));
10196
output = new OutputAnalyzer(pb.start());
10297
output.shouldHaveExitValue(0);
10398
if (usesCompressedClassSpace) {
@@ -109,12 +104,12 @@ private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Ex
109104
output.shouldContain("Waste");
110105
output.shouldMatch("MaxMetaspaceSize:.*201.00.*MB");
111106

112-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "show-loaders"});
107+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "show-loaders"));
113108
output = new OutputAnalyzer(pb.start());
114109
output.shouldHaveExitValue(0);
115110
output.shouldMatch("CLD.*<bootstrap>");
116111

117-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "by-chunktype"});
112+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "by-chunktype"));
118113
output = new OutputAnalyzer(pb.start());
119114
output.shouldHaveExitValue(0);
120115
output.shouldContain("1k:");
@@ -131,13 +126,13 @@ private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Ex
131126
output.shouldContain("2m:");
132127
output.shouldContain("4m:");
133128

134-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "vslist"});
129+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "vslist"));
135130
output = new OutputAnalyzer(pb.start());
136131
output.shouldHaveExitValue(0);
137132
output.shouldContain("Virtual space list");
138133
output.shouldMatch("node.*reserved.*committed.*used.*");
139134

140-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "chunkfreelist"});
135+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "chunkfreelist"));
141136
// Output should look somewhat like this...
142137
// vvvvvvvvvvvvvvvv
143138
// Chunk freelist details:
@@ -161,17 +156,17 @@ private static void doTheCCSPropTest(boolean usesCompressedClassSpace) throws Ex
161156
output.shouldMatch(".*total chunks.*total word size.*");
162157

163158
// Test with different scales
164-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=G"});
159+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "scale=G"));
165160
output = new OutputAnalyzer(pb.start());
166161
output.shouldHaveExitValue(0);
167162
output.shouldMatch("MaxMetaspaceSize:.*0.2.*GB");
168163

169-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=K"});
164+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "scale=K"));
170165
output = new OutputAnalyzer(pb.start());
171166
output.shouldHaveExitValue(0);
172167
output.shouldMatch("MaxMetaspaceSize:.*205824.00 KB");
173168

174-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.metaspace", "scale=1"});
169+
pb.command(new PidJcmdExecutor().getCommandLine("VM.metaspace", "scale=1"));
175170
output = new OutputAnalyzer(pb.start());
176171
output.shouldHaveExitValue(0);
177172
output.shouldMatch("MaxMetaspaceSize:.*210763776 bytes");

test/hotspot/jtreg/runtime/NMT/CommitOverlappingRegions.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,9 +32,8 @@
3232
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail CommitOverlappingRegions
3333
*/
3434

35-
import jdk.test.lib.process.ProcessTools;
35+
import jdk.test.lib.dcmd.PidJcmdExecutor;
3636
import jdk.test.lib.process.OutputAnalyzer;
37-
import jdk.test.lib.JDKToolFinder;
3837
import jdk.test.whitebox.WhiteBox;
3938

4039
public class CommitOverlappingRegions {
@@ -49,10 +48,9 @@ public static void main(String args[]) throws Exception {
4948

5049
long addr = wb.NMTReserveMemory(8*size);
5150

52-
String pid = Long.toString(ProcessTools.getProcessId());
5351
ProcessBuilder pb = new ProcessBuilder();
5452

55-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"});
53+
pb.command(new PidJcmdExecutor().getCommandLine("VM.native_memory", "detail"));
5654
System.out.println("Address is " + Long.toHexString(addr));
5755

5856
// Start: . . . . . . . .

test/hotspot/jtreg/runtime/NMT/JcmdDetailDiff.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,9 +32,7 @@
3232
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail JcmdDetailDiff
3333
*/
3434

35-
import jdk.test.lib.process.ProcessTools;
3635
import jdk.test.lib.process.OutputAnalyzer;
37-
import jdk.test.lib.JDKToolFinder;
3836

3937
import jdk.test.whitebox.WhiteBox;
4038

@@ -43,43 +41,30 @@ public class JcmdDetailDiff {
4341
public static WhiteBox wb = WhiteBox.getWhiteBox();
4442

4543
public static void main(String args[]) throws Exception {
46-
ProcessBuilder pb = new ProcessBuilder();
4744
OutputAnalyzer output;
48-
// Grab my own PID
49-
String pid = Long.toString(ProcessTools.getProcessId());
5045

5146
long commitSize = 128 * 1024;
5247
long reserveSize = 256 * 1024;
5348
long addr;
5449

5550
// Run 'jcmd <pid> VM.native_memory baseline=true'
56-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline=true"});
57-
58-
output = new OutputAnalyzer(pb.start());
51+
output = NMTTestUtils.startJcmdVMNativeMemory("baseline=true");
5952
output.shouldContain("Baseline taken");
6053

6154
addr = wb.NMTReserveMemory(reserveSize);
62-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff", "scale=KB"});
63-
64-
output = new OutputAnalyzer(pb.start());
55+
output = NMTTestUtils.startJcmdVMNativeMemory("detail.diff", "scale=KB");
6556
output.shouldContain("Test (reserved=256KB +256KB, committed=0KB)");
6657

6758
wb.NMTCommitMemory(addr, commitSize);
68-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff", "scale=KB"});
69-
70-
output = new OutputAnalyzer(pb.start());
59+
output = NMTTestUtils.startJcmdVMNativeMemory("detail.diff", "scale=KB");
7160
output.shouldContain("Test (reserved=256KB +256KB, committed=128KB +128KB)");
7261

7362
wb.NMTUncommitMemory(addr, commitSize);
74-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff", "scale=KB"});
75-
76-
output = new OutputAnalyzer(pb.start());
63+
output = NMTTestUtils.startJcmdVMNativeMemory("detail.diff", "scale=KB");
7764
output.shouldContain("Test (reserved=256KB +256KB, committed=0KB)");
7865

7966
wb.NMTReleaseMemory(addr, reserveSize);
80-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff", "scale=KB"});
81-
82-
output = new OutputAnalyzer(pb.start());
67+
output = NMTTestUtils.startJcmdVMNativeMemory("detail.diff", "scale=KB");
8368
output.shouldNotContain("Test (reserved=");
8469
}
8570
}

test/hotspot/jtreg/runtime/NMT/MallocSiteTypeChange.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
23
* Copyright (c) 2019, Red Hat, Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
@@ -32,8 +33,6 @@
3233
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:NativeMemoryTracking=detail MallocSiteTypeChange
3334
*/
3435

35-
import jdk.test.lib.JDKToolFinder;
36-
import jdk.test.lib.process.ProcessTools;
3736
import jdk.test.lib.process.OutputAnalyzer;
3837
import jdk.test.whitebox.WhiteBox;
3938

@@ -42,26 +41,19 @@ public static void main(String args[]) throws Exception {
4241
OutputAnalyzer output;
4342
WhiteBox wb = WhiteBox.getWhiteBox();
4443

45-
// Grab my own PID
46-
String pid = Long.toString(ProcessTools.getProcessId());
47-
ProcessBuilder pb = new ProcessBuilder();
48-
4944
int pc = 1;
5045
long addr = wb.NMTMallocWithPseudoStack(4 * 1024, pc);
5146

5247
// Verify that current tracking level is "detail"
53-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail"});
54-
output = new OutputAnalyzer(pb.start());
48+
output = NMTTestUtils.startJcmdVMNativeMemory("detail");
5549
output.shouldContain("Test (reserved=4KB, committed=4KB)");
5650

57-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "baseline"});
58-
output = new OutputAnalyzer(pb.start());
51+
output = NMTTestUtils.startJcmdVMNativeMemory("baseline");
5952
output.shouldContain("Baseline taken");
6053

6154
wb.NMTFree(addr);
6255
addr = wb.NMTMallocWithPseudoStackAndType(2 * 1024, pc, 9 /* mtInternal */ );
63-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "detail.diff"});
64-
output = new OutputAnalyzer(pb.start());
56+
output = NMTTestUtils.startJcmdVMNativeMemory("detail.diff");
6557
output.shouldContain("(malloc=0KB type=Test -4KB)");
6658
output.shouldContain("(malloc=2KB type=Internal +2KB #1 +1)");
6759
output.shouldHaveExitValue(0);

test/hotspot/jtreg/runtime/NMT/NMTTestUtils.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2023 Red Hat, Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -22,23 +22,19 @@
2222
* questions.
2323
*/
2424

25-
import jdk.test.lib.JDKToolFinder;
25+
import jdk.test.lib.StringArrayUtils;
26+
import jdk.test.lib.dcmd.PidJcmdExecutor;
2627
import jdk.test.lib.process.OutputAnalyzer;
27-
import jdk.test.lib.process.ProcessTools;
2828

2929
public class NMTTestUtils {
3030

3131
public static OutputAnalyzer startJcmdVMNativeMemory(String... additional_args) throws Exception {
3232
if (additional_args == null) {
3333
additional_args = new String[] {};
3434
}
35-
String fullargs[] = new String[3 + additional_args.length];
36-
fullargs[0] = JDKToolFinder.getJDKTool("jcmd");
37-
fullargs[1] = Long.toString(ProcessTools.getProcessId());
38-
fullargs[2] = "VM.native_memory";
39-
System.arraycopy(additional_args, 0, fullargs, 3, additional_args.length);
35+
String fullargs[] = StringArrayUtils.concat("VM.native_memory", additional_args);
4036
ProcessBuilder pb = new ProcessBuilder();
41-
pb.command(fullargs);
37+
pb.command(new PidJcmdExecutor().getCommandLine(fullargs));
4238
OutputAnalyzer output = new OutputAnalyzer(pb.start());
4339
return output;
4440
}

test/hotspot/jtreg/runtime/NMT/VirtualAllocAttemptReserveMemoryAt.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,9 +33,8 @@
3333
*
3434
*/
3535

36-
import jdk.test.lib.process.ProcessTools;
36+
import jdk.test.lib.dcmd.PidJcmdExecutor;
3737
import jdk.test.lib.process.OutputAnalyzer;
38-
import jdk.test.lib.JDKToolFinder;
3938

4039
import jdk.test.whitebox.WhiteBox;
4140

@@ -48,7 +47,6 @@ public class VirtualAllocAttemptReserveMemoryAt {
4847
public static void main(String args[]) throws Exception {
4948
long reserveSize = 4 * 1024 * 1024; // 4096KB
5049

51-
String pid = Long.toString(ProcessTools.getProcessId());
5250
ProcessBuilder pb = new ProcessBuilder();
5351

5452
// Find an address
@@ -67,8 +65,7 @@ public static void main(String args[]) throws Exception {
6765

6866
assertEQ(addr, attempt_addr);
6967

70-
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid,
71-
"VM.native_memory", "detail" });
68+
pb.command(new PidJcmdExecutor().getCommandLine("VM.native_memory", "detail"));
7269

7370
OutputAnalyzer output = new OutputAnalyzer(pb.start());
7471

test/hotspot/jtreg/runtime/Thread/TestThreadDumpClassInitMonitor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,6 +43,8 @@ public class TestThreadDumpClassInitMonitor {
4343
// so use getTestJDKTool() instead of getCompileJDKTool() or even
4444
// getJDKTool() which can fall back to "compile.jdk".
4545
final static String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
46+
// jstack output may be lengthy, disable streaming output to avoid deadlocks
47+
final static String DISABLE_STREAMING_OUTPUT = "-J-Djdk.attach.allowStreamingOutput=false";
4648
final static String PID = "" + ProcessHandle.current().pid();
4749

4850
final static Thread current = Thread.currentThread();
@@ -111,7 +113,7 @@ public void run() {
111113

112114
// Now run jstack
113115
try {
114-
ProcessBuilder pb = new ProcessBuilder(JSTACK, PID);
116+
ProcessBuilder pb = new ProcessBuilder(JSTACK, DISABLE_STREAMING_OUTPUT, PID);
115117
OutputAnalyzer output = new OutputAnalyzer(pb.start());
116118
output.shouldHaveExitValue(0);
117119
stackDump = output.asLines();

0 commit comments

Comments
 (0)