Skip to content

Commit 426ebf4

Browse files
committed
8308475: Make the thread dump files generated by jcmd Thread.dump_to_file jtreg failure handler action easily accessible
Reviewed-by: lmesnik
1 parent 8d8153e commit 426ebf4

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

test/failure_handler/src/share/classes/jdk/test/failurehandler/HtmlSection.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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
@@ -150,6 +150,17 @@ public void link(HtmlSection section, String child, String name) {
150150
path, name);
151151
}
152152

153+
/**
154+
* Creates a {@code <a href></a>} link with {@code targetAddress} being the value for {@code href}
155+
* and the {@code linkText} being the text for the link.
156+
*
157+
* @param targetAddress the target address
158+
* @param linkText the text for the link
159+
*/
160+
public void createLink(String targetAddress, String linkText) {
161+
pw.printf("<a href=\"%1$s\">%2$s</a>%n", targetAddress, linkText);
162+
}
163+
153164
public HtmlSection createChildren(String[] sections) {
154165
int i = 0;
155166
int n = sections.length;

test/failure_handler/src/share/classes/jdk/test/failurehandler/action/ActionHelper.java

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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
@@ -47,6 +47,7 @@
4747
import java.util.Date;
4848
import java.util.List;
4949
import java.util.Properties;
50+
import java.util.StringTokenizer;
5051
import java.util.Timer;
5152
import java.util.TimerTask;
5253
import java.util.concurrent.TimeUnit;
@@ -76,9 +77,10 @@ public ActionHelper(Path workDir, String prefix, Properties properties,
7677
public List<Long> getChildren(HtmlSection section, long pid) {
7778
String pidStr = "" + pid;
7879
ProcessBuilder pb = getChildren.prepareProcess(section, this, pidStr);
79-
PrintWriter log = getChildren.getSection(section).getWriter();
80+
HtmlSection childrenSection = getChildren.getSection(section);
81+
PrintWriter log = childrenSection.getWriter();
8082
CharArrayWriter writer = new CharArrayWriter();
81-
ExitCode code = run(log, writer, pb, getChildren.getParameters());
83+
ExitCode code = run(childrenSection, log, writer, pb, getChildren.getParameters());
8284
Reader output = new CharArrayReader(writer.toCharArray());
8385

8486
if (!ExitCode.OK.equals(code)) {
@@ -154,8 +156,8 @@ private void addJdks(Path[] jdkPaths) {
154156
}
155157
}
156158

157-
private ExitCode run(PrintWriter log, Writer out, ProcessBuilder pb,
158-
ActionParameters params) {
159+
private ExitCode run(HtmlSection section, PrintWriter log, Writer out, ProcessBuilder pb,
160+
ActionParameters params) {
159161
char[] lineChars = new char[40];
160162
Arrays.fill(lineChars, '-');
161163
String line = new String(lineChars);
@@ -199,6 +201,19 @@ private ExitCode run(PrintWriter log, Writer out, ProcessBuilder pb,
199201
log.printf("%s%n[%tF %<tT] exit code: %d time: %d ms%n%1$s%n",
200202
line, new Date(), result.value,
201203
TimeUnit.NANOSECONDS.toMillis(stopwatch.getElapsedTimeNs()));
204+
// upon successful completion of the action, generate links to any successArtifacts
205+
// that have been declared for this action
206+
if (ExitCode.OK.equals(result) && params.successArtifacts != null) {
207+
final StringTokenizer t = new StringTokenizer(params.successArtifacts, ",");
208+
while (t.hasMoreTokens()) {
209+
final String artifactPath = t.nextToken().trim();
210+
if (artifactPath.isEmpty()) {
211+
continue;
212+
}
213+
// create a link to the artifact
214+
section.createLink(artifactPath, artifactPath);
215+
}
216+
}
202217
return result;
203218
}
204219

@@ -286,11 +301,21 @@ private void exec(HtmlSection section, ProcessBuilder process,
286301
}
287302
PrintWriter sectionWriter = section.getWriter();
288303
if (params.repeat > 1) {
304+
// hold on to the original command and successArtifacts values which potentially
305+
// contain the %iterCount token, since we need to replace it with different value
306+
// on each iteration
307+
String originalSuccessArtifacts = params.successArtifacts;
308+
List<String> originalCommand = process.command();
289309
for (int i = 0, n = params.repeat; i < n; ++i) {
290310
HtmlSection iteration = section.createChildren(
291311
String.format("iteration_%d", i));
292312
PrintWriter writer = iteration.getWriter();
293-
ExitCode exitCode = run(writer, writer, process, params);
313+
// use the original values with the token (if any)
314+
params.successArtifacts = originalSuccessArtifacts;
315+
process.command(originalCommand);
316+
// replace the %iterCount token (if any)
317+
prepareIteration(i, process, params);
318+
ExitCode exitCode = run(section, writer, writer, process, params);
294319
if (params.stopOnError && !ExitCode.OK.equals(exitCode)) {
295320
sectionWriter.printf(
296321
"ERROR: non zero exit code[%d] -- break.",
@@ -309,7 +334,26 @@ private void exec(HtmlSection section, ProcessBuilder process,
309334
}
310335
}
311336
} else {
312-
run(section.getWriter(), section.getWriter(), process, params);
337+
prepareIteration(0, process, params);
338+
run(section, section.getWriter(), section.getWriter(), process, params);
339+
}
340+
}
341+
342+
// replaces the occurrences of %iterCount from the process builder command/arguments
343+
// and the action params' "successArtifacts" paths, with the iteration count
344+
private void prepareIteration(int iterationCount, ProcessBuilder pb,
345+
ActionParameters actionParams) {
346+
List<String> command = new ArrayList<>();
347+
for (String arg : pb.command()) {
348+
arg = arg.replaceAll("%iterCount", String.valueOf(iterationCount)) ;
349+
command.add(arg);
350+
}
351+
pb.command(command);
352+
353+
String successArtifacts = actionParams.successArtifacts;
354+
if (successArtifacts != null) {
355+
actionParams.successArtifacts = successArtifacts.replaceAll("%iterCount",
356+
String.valueOf(iterationCount));
313357
}
314358
}
315359

test/failure_handler/src/share/classes/jdk/test/failurehandler/action/ActionParameters.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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,5 +43,9 @@ public class ActionParameters {
4343
@DefaultValue (value = "" + 20_000L)
4444
public long timeout = -1L;
4545

46+
@Value (name = "successArtifacts")
47+
@DefaultValue (value = "")
48+
public String successArtifacts = "";
49+
4650
public ActionParameters() { }
4751
}

test/failure_handler/src/share/classes/jdk/test/failurehandler/action/PatternAction.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2023, 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
@@ -62,6 +62,11 @@ public ProcessBuilder prepareProcess(HtmlSection section,
6262
for (int i = 0, n = args.length; i < n; ++i) {
6363
args[i] = args[i].replace("%java", helper.findApp("java").getAbsolutePath());
6464
}
65+
// replace occurrences of the pattern in the "successArtifacts" param
66+
String successArtifacts = action.getParameters().successArtifacts;
67+
if (successArtifacts != null) {
68+
action.getParameters().successArtifacts = successArtifacts.replaceAll(pattern, value);
69+
}
6570
return action.prepareProcess(section.getWriter(), helper);
6671
}
6772

test/failure_handler/src/share/conf/common.properties

Lines changed: 4 additions & 2 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, 2023, 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,7 +57,9 @@ jcmd.gc.class_histogram.args=%p GC.class_histogram
5757
jcmd.gc.finalizer_info.args=%p GC.finalizer_info
5858
jcmd.gc.heap_info.args=%p GC.heap_info
5959

60-
jcmd.thread.dump_to_file.args=%p Thread.dump_to_file JavaThread.dump.%p
60+
jcmd.thread.dump_to_file.args=%p Thread.dump_to_file -format=json JavaThread.dump.%p.%iterCount
61+
jcmd.thread.dump_to_file.params.repeat=6
62+
jcmd.thread.dump_to_file.params.successArtifacts=JavaThread.dump.%p.%iterCount
6163

6264
jstack.app=jstack
6365
jstack.args=-e -l %p

0 commit comments

Comments
 (0)