Skip to content

Commit 4fb0648

Browse files
committed
8267893: Improve jtreg test failure handler do get native/mixed stack traces for cores and live processes
Backport-of: 8c8422e0f8886d9bbfca29fd228368f88bf46f2c
1 parent 3c6b45b commit 4fb0648

File tree

12 files changed

+150
-27
lines changed

12 files changed

+150
-27
lines changed

test/failure_handler/Makefile

Lines changed: 2 additions & 3 deletions
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, 2021, 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
@@ -38,7 +38,7 @@ SOURCES := ${SRC_DIR}/jdk/test/failurehandler/*.java \
3838

3939
CONF_DIR = src/share/conf
4040

41-
JAVA_RELEASE = 7
41+
JAVA_RELEASE = 15
4242

4343
TARGET_JAR = ${IMAGE_DIR}/lib/jtregFailureHandler.jar
4444

@@ -107,4 +107,3 @@ build: classes
107107

108108
.PHONY: all build classes test require_env clean
109109
.DEFAULT: all
110-

test/failure_handler/README

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
1+
Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
22
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33

44
This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,7 @@ The library uses JTHarness Observer and jtreg TimeoutHandler extensions points.
3232

3333
DEPENDENCES
3434

35-
The library requires jtreg 4b13+ and JDK 7+.
35+
The library requires jtreg 4b13+ and JDK 15+.
3636

3737
BUILDING
3838

@@ -102,4 +102,3 @@ $ ${JTREG_HOME}/bin/jtreg -jdk:${JAVA_HOME} \
102102
-timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler\
103103
-observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \
104104
${WS}/hotspot/test/
105-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
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
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package jdk.test.failurehandler;
25+
26+
import java.nio.file.Path;
27+
28+
public interface CoreInfoGatherer {
29+
void gatherCoreInfo(HtmlSection section, Path core);
30+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -51,6 +51,10 @@ public ProcessInfoGatherer getProcessInfoGatherer() {
5151
return create();
5252
}
5353

54+
public CoreInfoGatherer getCoreInfoGatherer() {
55+
return create();
56+
}
57+
5458
private ToolKit create() {
5559
Properties osProperty = Utils.getProperties(osName);
5660
try {

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

Lines changed: 29 additions & 2 deletions
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, 2021, 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
@@ -26,19 +26,25 @@
2626
import jdk.test.failurehandler.action.ActionSet;
2727
import jdk.test.failurehandler.action.ActionHelper;
2828

29+
import java.io.IOException;
2930
import java.io.PrintWriter;
31+
import java.nio.file.Files;
32+
import java.nio.file.Path;
3033
import java.util.ArrayList;
3134
import java.util.LinkedList;
3235
import java.util.List;
3336
import java.util.Queue;
3437
import java.util.Deque;
38+
import java.util.zip.GZIPInputStream;
3539

36-
public class ToolKit implements EnvironmentInfoGatherer, ProcessInfoGatherer {
40+
public class ToolKit implements EnvironmentInfoGatherer, ProcessInfoGatherer, CoreInfoGatherer {
3741
private final List<ActionSet> actions = new ArrayList<>();
3842
private final ActionHelper helper;
43+
private final PrintWriter log;
3944

4045
public ToolKit(ActionHelper helper, PrintWriter log, String... names) {
4146
this.helper = helper;
47+
this.log = log;
4248
for (String name : names) {
4349
actions.add(new ActionSet(helper, log, name));
4450
}
@@ -51,6 +57,27 @@ public void gatherEnvironmentInfo(HtmlSection section) {
5157
}
5258
}
5359

60+
@Override
61+
public void gatherCoreInfo(HtmlSection section, Path core) {
62+
if (core.getFileName().toString().endsWith(".gz")) {
63+
Path unpackedCore = Path.of(core.toString().replace(".gz", ""));
64+
try (GZIPInputStream gzis = new GZIPInputStream(Files.newInputStream(core))) {
65+
Files.copy(gzis, unpackedCore);
66+
for (ActionSet set : actions) {
67+
set.gatherCoreInfo(section, unpackedCore);
68+
}
69+
Files.delete(unpackedCore);
70+
} catch (IOException ioe) {
71+
log.printf("Unexpected exception whilc opening %s", core.getFileName().toString());
72+
ioe.printStackTrace(log);
73+
}
74+
} else {
75+
for (ActionSet set : actions) {
76+
set.gatherCoreInfo(section, core);
77+
}
78+
}
79+
}
80+
5481
@Override
5582
public void gatherProcessInfo(HtmlSection section, long pid) {
5683
// as some of actions can kill a process, we need to get children of all

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -23,8 +23,6 @@
2323

2424
package jdk.test.failurehandler.action;
2525

26-
import com.sun.tools.attach.VirtualMachine;
27-
import com.sun.tools.attach.VirtualMachineDescriptor;
2826
import jdk.test.failurehandler.value.InvalidValueException;
2927
import jdk.test.failurehandler.value.Value;
3028
import jdk.test.failurehandler.value.ValueHandler;
@@ -134,7 +132,7 @@ public ProcessBuilder prepareProcess(PrintWriter log, String app,
134132
.directory(workDir.toFile());
135133
}
136134

137-
private File findApp(String app) {
135+
public File findApp(String app) {
138136
String name = app + executableSuffix;
139137
for (Path pathElem : paths) {
140138
File result = pathElem.resolve(name).toFile();

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

Lines changed: 18 additions & 2 deletions
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, 2021, 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
@@ -23,19 +23,26 @@
2323

2424
package jdk.test.failurehandler.action;
2525

26+
import jdk.test.failurehandler.CoreInfoGatherer;
2627
import jdk.test.failurehandler.ProcessInfoGatherer;
2728
import jdk.test.failurehandler.EnvironmentInfoGatherer;
2829
import jdk.test.failurehandler.HtmlSection;
2930
import jdk.test.failurehandler.Utils;
3031

32+
import java.io.IOException;
3133
import java.io.PrintWriter;
34+
import java.nio.file.Files;
35+
import java.nio.file.Path;
3236
import java.util.ArrayList;
3337
import java.util.List;
3438
import java.util.Properties;
39+
import java.util.zip.GZIPInputStream;
3540

36-
public class ActionSet implements ProcessInfoGatherer, EnvironmentInfoGatherer {
41+
public class ActionSet implements ProcessInfoGatherer, EnvironmentInfoGatherer, CoreInfoGatherer {
3742
private static final String ENVIRONMENT_PROPERTY = "environment";
3843
private static final String ON_PID_PROPERTY = "onTimeout";
44+
private static final String CORES_PROPERTY = "cores";
45+
3946

4047
private final ActionHelper helper;
4148

@@ -46,6 +53,7 @@ public String getName() {
4653
private final String name;
4754
private final List<SimpleAction> environmentActions;
4855
private final List<PatternAction> processActions;
56+
private final List<PatternAction> coreActions;
4957

5058

5159
public ActionSet(ActionHelper helper, PrintWriter log, String name) {
@@ -55,6 +63,7 @@ public ActionSet(ActionHelper helper, PrintWriter log, String name) {
5563
Properties p = Utils.getProperties(name);
5664
environmentActions = getSimpleActions(log, p, ENVIRONMENT_PROPERTY);
5765
processActions = getPatternActions(log, p, ON_PID_PROPERTY);
66+
coreActions = getPatternActions(log, p, CORES_PROPERTY);
5867
}
5968

6069
private List<SimpleAction> getSimpleActions(PrintWriter log, Properties p,
@@ -123,4 +132,11 @@ public void gatherEnvironmentInfo(HtmlSection section) {
123132
helper.runPatternAction(action, section);
124133
}
125134
}
135+
136+
@Override
137+
public void gatherCoreInfo(HtmlSection section, Path core) {
138+
for (PatternAction action : coreActions) {
139+
helper.runPatternAction(action, section, core.toString());
140+
}
141+
}
126142
}

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

Lines changed: 4 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, 2021, 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
@@ -59,6 +59,9 @@ public ProcessBuilder prepareProcess(HtmlSection section,
5959
for (int i = 0, n = args.length; i < n; ++i) {
6060
args[i] = args[i].replace(pattern, value) ;
6161
}
62+
for (int i = 0, n = args.length; i < n; ++i) {
63+
args[i] = args[i].replace("%java", helper.findApp("java").getAbsolutePath());
64+
}
6265
return action.prepareProcess(section.getWriter(), helper);
6366
}
6467

test/failure_handler/src/share/classes/jdk/test/failurehandler/jtreg/GatherDiagnosticInfoObserver.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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,10 +33,9 @@
3333
import java.io.FileWriter;
3434
import java.io.IOException;
3535
import java.io.PrintWriter;
36+
import java.nio.file.Files;
3637
import java.nio.file.Path;
3738
import java.nio.file.Paths;
38-
import java.util.HashMap;
39-
import java.util.Map;
4039

4140
/**
4241
* The jtreg test execution observer, which gathers info about
@@ -45,6 +44,8 @@
4544
public class GatherDiagnosticInfoObserver implements Harness.Observer {
4645
public static final String LOG_FILENAME = "environment.log";
4746
public static final String ENVIRONMENT_OUTPUT = "environment.html";
47+
public static final String CORES_OUTPUT = "cores.html";
48+
4849

4950
private Path compileJdk;
5051
private Path testJdk;
@@ -64,25 +65,31 @@ public void finishedTest(TestResult tr) {
6465
workDir.toFile().mkdir();
6566

6667
String name = getClass().getName();
67-
PrintWriter log;
68+
PrintWriter log1;
6869
boolean needClose = false;
6970
try {
70-
log = new PrintWriter(new FileWriter(
71+
log1 = new PrintWriter(new FileWriter(
7172
workDir.resolve(LOG_FILENAME).toFile(), true), true);
7273
needClose = true;
7374
} catch (IOException e) {
74-
log = new PrintWriter(System.out);
75-
log.printf("ERROR: %s cannot open log file %s", name,
75+
log1 = new PrintWriter(System.out);
76+
log1.printf("ERROR: %s cannot open log file %s", name,
7677
LOG_FILENAME);
77-
e.printStackTrace(log);
78+
e.printStackTrace(log1);
7879
}
80+
final PrintWriter log = log1;
7981
try {
8082
log.printf("%s ---%n", name);
8183
GathererFactory gathererFactory = new GathererFactory(
8284
OS.current().family, workDir, log,
8385
testJdk, compileJdk);
8486
gatherEnvInfo(workDir, name, log,
8587
gathererFactory.getEnvironmentInfoGatherer());
88+
Files.walk(workDir)
89+
.filter(Files::isRegularFile)
90+
.filter(f -> (f.getFileName().toString().contains("core") || f.getFileName().toString().contains("mdmp")))
91+
.forEach(core -> gatherCoreInfo(workDir, name,
92+
core, log, gathererFactory.getCoreInfoGatherer()));
8693
} catch (Throwable e) {
8794
log.printf("ERROR: exception in observer %s:", name);
8895
e.printStackTrace(log);
@@ -96,6 +103,22 @@ public void finishedTest(TestResult tr) {
96103
}
97104
}
98105

106+
private void gatherCoreInfo(Path workDir, String name, Path core, PrintWriter log,
107+
CoreInfoGatherer gatherer) {
108+
File output = workDir.resolve(CORES_OUTPUT).toFile();
109+
try (HtmlPage html = new HtmlPage(new PrintWriter(
110+
new FileWriter(output, true), true))) {
111+
try (ElapsedTimePrinter timePrinter
112+
= new ElapsedTimePrinter(new Stopwatch(), name, log)) {
113+
gatherer.gatherCoreInfo(html.getRootSection(), core);
114+
}
115+
} catch (Throwable e) {
116+
log.printf("ERROR: exception in observer on getting environment "
117+
+ "information %s:", name);
118+
e.printStackTrace(log);
119+
}
120+
}
121+
99122
private void gatherEnvInfo(Path workDir, String name, PrintWriter log,
100123
EnvironmentInfoGatherer gatherer) {
101124
File output = workDir.resolve(ENVIRONMENT_OUTPUT).toFile();

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

Lines changed: 12 additions & 2 deletions
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, 2021, 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
@@ -35,7 +35,7 @@ onTimeout=\
3535
jcmd.vm.symboltable jcmd.vm.uptime jcmd.vm.dynlibs \
3636
jcmd.vm.system_properties jcmd.vm.info \
3737
jcmd.gc.heap_info jcmd.gc.class_histogram jcmd.gc.finalizer_info \
38-
jstack
38+
jstack jhsdb.jstack
3939

4040
jinfo.app=jinfo
4141

@@ -51,6 +51,7 @@ jcmd.vm.symboltable.args=%p VM.symboltable
5151
jcmd.vm.uptime.args=%p VM.uptime
5252
jcmd.vm.dynlibs.args=%p VM.dynlibs
5353
jcmd.vm.system_properties.args=%p VM.system_properties
54+
jcmd.vm.info.args=%p VM.info
5455

5556
jcmd.gc.class_histogram.args=%p GC.class_histogram
5657
jcmd.gc.finalizer_info.args=%p GC.finalizer_info
@@ -60,6 +61,15 @@ jstack.app=jstack
6061
jstack.args=-e -l %p
6162
jstack.params.repeat=6
6263

64+
jhsdb.app=jhsdb
65+
jhsdb.jstack.args=jstack --mixed --pid %p
66+
jhsdb.jstack.params.repeat=6
67+
68+
cores=jhsdb.jstack
69+
jhsdb.jstack.app=jhsdb
70+
# Assume that java standard laucher has been used
71+
jhsdb.jstack.args=jstack --mixed --core %p --exe %java
72+
6373
################################################################################
6474
# environment info to gather
6575
################################################################################

0 commit comments

Comments
 (0)