Skip to content

Commit b8f2a8d

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

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, 2020, 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
@@ -47,6 +47,7 @@
4747
import java.util.ArrayList;
4848
import jdk.test.lib.Utils;
4949
import jdk.test.lib.apps.LingeredApp;
50+
import jdk.test.lib.process.OutputAnalyzer;
5051
import jtreg.SkippedException;
5152

5253
public class ClhsdbScanOops {
@@ -71,35 +72,54 @@ private static void testWithGcType(String gc) throws Exception {
7172
Map<String, List<String>> expStrMap = new HashMap<>();
7273
Map<String, List<String>> unExpStrMap = new HashMap<>();
7374

74-
String startAddress = null;
75-
String endAddress = null;
76-
String[] snippets = null;
75+
String startAddress;
76+
String endAddress;
77+
String[] snippets;
78+
String[] words;
79+
String cmd;
7780

81+
// Run scanoops on the old gen
82+
if (gc.contains("UseParallelGC")) {
83+
snippets = universeOutput.split("PSOldGen \\[ ");
84+
} else {
85+
snippets = universeOutput.split("old \\[");
86+
}
87+
words = snippets[1].split(",");
88+
// Get the addresses for Old gen
89+
startAddress = words[0].replace("[", "");
90+
endAddress = words[1];
91+
cmd = "scanoops " + startAddress + " " + endAddress;
92+
String output1 = test.run(theApp.getPid(), List.of(cmd), null, null);
93+
94+
// Run scanoops on the eden gen
7895
if (gc.contains("UseParallelGC")) {
7996
snippets = universeOutput.split("eden = ");
8097
} else {
8198
snippets = universeOutput.split("eden \\[");
8299
}
83-
String[] words = snippets[1].split(",");
84-
// Get the addresses from Eden
100+
words = snippets[1].split(",");
101+
// Get the addresses for Eden gen
85102
startAddress = words[0].replace("[", "");
86103
endAddress = words[1];
87-
String cmd = "scanoops " + startAddress + " " + endAddress;
88-
cmds.add(cmd);
89-
90-
expStrMap.put(cmd, List.of
91-
("java/lang/Object", "java/lang/Class", "java/lang/Thread",
92-
"java/lang/String", "\\[B", "\\[I"));
104+
cmd = "scanoops " + startAddress + " " + endAddress;
105+
String output2 = test.run(theApp.getPid(), List.of(cmd), null, null);
106+
107+
// Look for expected types in the combined eden and old gens
108+
OutputAnalyzer out = new OutputAnalyzer(output1 + output2);
109+
List<String> expectStrs = List.of(
110+
"java/lang/Object", "java/lang/Class", "java/lang/Thread",
111+
"java/lang/String", "\\[B", "\\[I");
112+
for (String expectStr : expectStrs) {
113+
out.shouldMatch(expectStr);
114+
}
93115

94-
// Test the 'type' option also
95-
// scanoops <start addr> <end addr> java/lang/String
116+
// Test the 'type' option also:
117+
// scanoops <start addr> <end addr> java/lang/String
96118
// Ensure that only the java/lang/String oops are printed.
97119
cmd = cmd + " java/lang/String";
98-
cmds.add(cmd);
99120
expStrMap.put(cmd, List.of("java/lang/String"));
100-
unExpStrMap.put(cmd, List.of("java/lang/Thread"));
101-
102-
test.run(theApp.getPid(), cmds, expStrMap, unExpStrMap);
121+
unExpStrMap.put(cmd, List.of("java/lang/Thread", "java/lang/Class", "java/lang/Object"));
122+
test.run(theApp.getPid(), List.of(cmd), expStrMap, unExpStrMap);
103123
} catch (SkippedException e) {
104124
throw e;
105125
} catch (Exception ex) {

0 commit comments

Comments
 (0)