Skip to content

Commit 18c06bb

Browse files
committed
8279662: serviceability/sa/ClhsdbScanOops.java can fail due to unexpected GC
Backport-of: fe0118f8040ce7e5e3d605942443e3a5d442fa92
1 parent cf58d59 commit 18c06bb

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

test/hotspot/jtreg/serviceability/sa/ClhsdbScanOops.java

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, 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
@@ -36,6 +36,7 @@
3636
import java.util.ArrayList;
3737
import jdk.test.lib.Utils;
3838
import jdk.test.lib.apps.LingeredApp;
39+
import jdk.test.lib.process.OutputAnalyzer;
3940
import jtreg.SkippedException;
4041

4142
public class ClhsdbScanOops {
@@ -62,35 +63,54 @@ private static void testWithGcType(String gc) throws Exception {
6263
Map<String, List<String>> expStrMap = new HashMap<>();
6364
Map<String, List<String>> unExpStrMap = new HashMap<>();
6465

65-
String startAddress = null;
66-
String endAddress = null;
67-
String[] snippets = null;
66+
String startAddress;
67+
String endAddress;
68+
String[] snippets;
69+
String[] words;
70+
String cmd;
6871

72+
// Run scanoops on the old gen
73+
if (gc.contains("UseParallelGC")) {
74+
snippets = universeOutput.split("PSOldGen \\[ ");
75+
} else {
76+
snippets = universeOutput.split("old \\[");
77+
}
78+
words = snippets[1].split(",");
79+
// Get the addresses for Old gen
80+
startAddress = words[0].replace("[", "");
81+
endAddress = words[1];
82+
cmd = "scanoops " + startAddress + " " + endAddress;
83+
String output1 = test.run(theApp.getPid(), List.of(cmd), null, null);
84+
85+
// Run scanoops on the eden gen
6986
if (gc.contains("UseParallelGC")) {
7087
snippets = universeOutput.split("eden = ");
7188
} else {
7289
snippets = universeOutput.split("eden \\[");
7390
}
74-
String[] words = snippets[1].split(",");
75-
// Get the addresses from Eden
91+
words = snippets[1].split(",");
92+
// Get the addresses for Eden gen
7693
startAddress = words[0].replace("[", "");
7794
endAddress = words[1];
78-
String cmd = "scanoops " + startAddress + " " + endAddress;
79-
cmds.add(cmd);
80-
81-
expStrMap.put(cmd, List.of
82-
("java/lang/Object", "java/lang/Class", "java/lang/Thread",
83-
"java/lang/String", "\\[B", "\\[I"));
95+
cmd = "scanoops " + startAddress + " " + endAddress;
96+
String output2 = test.run(theApp.getPid(), List.of(cmd), null, null);
97+
98+
// Look for expected types in the combined eden and old gens
99+
OutputAnalyzer out = new OutputAnalyzer(output1 + output2);
100+
List<String> expectStrs = List.of(
101+
"java/lang/Object", "java/lang/Class", "java/lang/Thread",
102+
"java/lang/String", "\\[B", "\\[I");
103+
for (String expectStr : expectStrs) {
104+
out.shouldMatch(expectStr);
105+
}
84106

85-
// Test the 'type' option also
86-
// scanoops <start addr> <end addr> java/lang/String
107+
// Test the 'type' option also:
108+
// scanoops <start addr> <end addr> java/lang/String
87109
// Ensure that only the java/lang/String oops are printed.
88110
cmd = cmd + " java/lang/String";
89-
cmds.add(cmd);
90111
expStrMap.put(cmd, List.of("java/lang/String"));
91-
unExpStrMap.put(cmd, List.of("java/lang/Thread"));
92-
93-
test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap);
112+
unExpStrMap.put(cmd, List.of("java/lang/Thread", "java/lang/Class", "java/lang/Object"));
113+
test.run(theApp.getPid(), List.of(cmd), expStrMap, unExpStrMap);
94114
} catch (SkippedException e) {
95115
throw e;
96116
} catch (Exception ex) {

0 commit comments

Comments
 (0)