Skip to content

Commit 05459df

Browse files
robcaslozTobiHartmann
authored andcommitted
8253765: C2: Control randomization in StressLCM and StressGCM
Use the compilation-local seed in 'StressLCM' and 'StressGCM' rather than the global one. As a consequence, these options use by default a fresh seed in every compilation, unless 'StressSeed=N' is specified, in which case they behave deterministically. Annotate tests that use 'StressLCM' and 'StressGCM' with the 'stress' and 'randomness' keys to reflect this change in default behavior. Reviewed-by: kvn, thartmann
1 parent 6620b61 commit 05459df

18 files changed

+105
-15
lines changed

src/hotspot/share/opto/c2_globals.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"Randomize worklist traversal in IGVN") \
5454
\
5555
product(uint, StressSeed, 0, DIAGNOSTIC, \
56-
"Seed for IGVN stress testing (if unset, a random one is " \
57-
"generated") \
56+
"Seed for randomized stress testing (if unset, a random one is " \
57+
"generated)") \
5858
range(0, max_juint) \
5959
\
6060
develop(bool, StressMethodHandleLinkerInlining, false, \

src/hotspot/share/opto/compile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,9 @@ Compile::Compile( ciEnv* ci_env, ciMethod* target, int osr_bci,
729729
if (failing()) return;
730730
NOT_PRODUCT( verify_graph_edges(); )
731731

732-
// If IGVN is randomized for stress testing, seed random number
733-
// generation and log the seed for repeatability.
734-
if (StressIGVN) {
732+
// If LCM, GCM, or IGVN are randomized for stress testing, seed
733+
// random number generation and log the seed for repeatability.
734+
if (StressLCM || StressGCM || StressIGVN) {
735735
_stress_seed = FLAG_IS_DEFAULT(StressSeed) ?
736736
static_cast<uint>(Ticks::now().nanoseconds()) : StressSeed;
737737
if (_log != NULL) {
@@ -4489,7 +4489,7 @@ int Compile::random() {
44894489
#define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
44904490
bool Compile::randomized_select(int count) {
44914491
assert(count > 0, "only positive");
4492-
return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
4492+
return (random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
44934493
}
44944494

44954495
CloneMap& Compile::clone_map() { return _clone_map; }

src/hotspot/share/opto/compile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ class Compile : public Phase {
11401140

11411141
// Auxiliary methods for randomized fuzzing/stressing
11421142
int random();
1143-
static bool randomized_select(int count);
1143+
bool randomized_select(int count);
11441144

11451145
// supporting clone_map
11461146
CloneMap& clone_map();

src/hotspot/share/opto/gcm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ Block* PhaseCFG::hoist_to_cheaper_block(Block* LCA, Block* early, Node* self) {
11981198
#endif
11991199
cand_cnt++;
12001200
if (LCA_freq < least_freq || // Better Frequency
1201-
(StressGCM && Compile::randomized_select(cand_cnt)) || // Should be randomly accepted in stress mode
1201+
(StressGCM && C->randomized_select(cand_cnt)) || // Should be randomly accepted in stress mode
12021202
(!StressGCM && // Otherwise, choose with latency
12031203
!in_latency && // No block containing latency
12041204
LCA_freq < least_freq * delta && // No worse frequency

src/hotspot/share/opto/lcm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ Node* PhaseCFG::select(
632632
cand_cnt++;
633633
if (choice < n_choice ||
634634
(choice == n_choice &&
635-
((StressLCM && Compile::randomized_select(cand_cnt)) ||
635+
((StressLCM && C->randomized_select(cand_cnt)) ||
636636
(!StressLCM &&
637637
(latency < n_latency ||
638638
(latency == n_latency &&

test/hotspot/jtreg/compiler/arraycopy/TestCloneAccessStressGCM.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/*
2525
* @test
26+
* @key stress randomness
2627
* @bug 8235332 8248226
2728
* @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) fields with StressGCM
2829
* @library /

test/hotspot/jtreg/compiler/arraycopy/TestInitializingACLoadWithBadMem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @key stress randomness
2627
* @bug 8182036
2728
* @summary Load from initializing arraycopy uses wrong memory state
2829
*

test/hotspot/jtreg/compiler/arraycopy/TestLoadBypassACWithWrongMem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @key stress randomness
2627
* @bug 8181742
2728
* @summary Loads that bypass arraycopy ends up with wrong memory state
2829
*

test/hotspot/jtreg/compiler/controldependency/TestEliminatedCastPPAtPhi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @key stress randomness
2627
* @bug 8139771
2728
* @summary Eliminating CastPP nodes at Phis when they all come from a unique input may cause crash
2829
* @requires vm.gc=="Serial" | vm.gc=="Parallel"

test/hotspot/jtreg/compiler/debug/TestGenerateStressSeed.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
* @test
3333
* @bug 8252219
3434
* @requires vm.compiler2.enabled
35-
* @summary Tests that using -XX:+StressIGVN without -XX:StressSeed=N generates
35+
* @summary Tests that using a stress option without -XX:StressSeed=N generates
3636
* and logs a random seed.
3737
* @library /test/lib /
38-
* @run driver compiler.debug.TestGenerateStressSeed
38+
* @run driver compiler.debug.TestGenerateStressSeed StressLCM
39+
* @run driver compiler.debug.TestGenerateStressSeed StressGCM
40+
* @run driver compiler.debug.TestGenerateStressSeed StressIGVN
3941
*/
4042

4143
public class TestGenerateStressSeed {
@@ -47,17 +49,18 @@ static void sum(int n) {
4749
}
4850

4951
public static void main(String[] args) throws Exception {
50-
if (args.length == 0) {
52+
if (args[0].startsWith("Stress")) {
5153
String className = TestGenerateStressSeed.class.getName();
54+
String stressOpt = args[0];
5255
String log = "test.log";
5356
String[] procArgs = {
5457
"-Xcomp", "-XX:-TieredCompilation", "-XX:+UnlockDiagnosticVMOptions",
55-
"-XX:CompileOnly=" + className + "::sum", "-XX:+StressIGVN",
58+
"-XX:CompileOnly=" + className + "::sum", "-XX:+" + stressOpt,
5659
"-XX:+LogCompilation", "-XX:LogFile=" + log, className, "10"};
5760
ProcessTools.createJavaProcessBuilder(procArgs).start().waitFor();
5861
new OutputAnalyzer(Paths.get(log))
5962
.shouldContain("stress_test seed");
60-
} else if (args.length > 0) {
63+
} else {
6164
sum(Integer.parseInt(args[0]));
6265
}
6366
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2020, 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 compiler.debug;
25+
26+
import jdk.test.lib.process.OutputAnalyzer;
27+
import jdk.test.lib.process.ProcessTools;
28+
import jdk.test.lib.Asserts;
29+
30+
/*
31+
* @test
32+
* @bug 8253765
33+
* @requires vm.debug == true & vm.compiler2.enabled
34+
* @summary Tests that, when compiling with StressLCM or StressGCM, using the
35+
* same seed results in the same compilation, and using different seeds
36+
* results in different compilations (the latter does not necessarily
37+
* hold for all pairs of seeds). The output of PrintOptoStatistics is
38+
* used to compare among compilations, instead of the more intuitive
39+
* TraceOptoPipelining which prints non-deterministic memory addresses.
40+
* @library /test/lib /
41+
* @run driver compiler.debug.TestStressCM StressLCM
42+
* @run driver compiler.debug.TestStressCM StressGCM
43+
*/
44+
45+
public class TestStressCM {
46+
47+
static String optoStats(String stressOpt, int stressSeed) throws Exception {
48+
String className = TestStressCM.class.getName();
49+
String[] procArgs = {
50+
"-Xcomp", "-XX:-TieredCompilation",
51+
"-XX:CompileOnly=" + className + "::sum",
52+
"-XX:+PrintOptoStatistics", "-XX:+" + stressOpt,
53+
"-XX:StressSeed=" + stressSeed, className, "10"};
54+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(procArgs);
55+
OutputAnalyzer out = new OutputAnalyzer(pb.start());
56+
return out.getStdout();
57+
}
58+
59+
static void sum(int n) {
60+
int acc = 0;
61+
for (int i = 0; i < n; i++) acc += i;
62+
System.out.println(acc);
63+
}
64+
65+
public static void main(String[] args) throws Exception {
66+
if (args[0].startsWith("Stress")) {
67+
String stressOpt = args[0];
68+
Asserts.assertEQ(optoStats(stressOpt, 10), optoStats(stressOpt, 10),
69+
"got different optimization stats for the same seed");
70+
Asserts.assertNE(optoStats(stressOpt, 10), optoStats(stressOpt, 20),
71+
"got the same optimization stats for different seeds");
72+
} else if (args.length > 0) {
73+
sum(Integer.parseInt(args[0]));
74+
}
75+
}
76+
}

test/hotspot/jtreg/compiler/debug/TestStressIGVN.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
* @requires vm.debug == true & vm.compiler2.enabled
3434
* @summary Tests that compilations with the same seed yield the same IGVN
3535
* trace, and compilations with different seeds yield different IGVN
36-
* traces.
36+
* traces (the latter does not necessarily hold for all pairs of
37+
* seeds).
3738
* @library /test/lib /
3839
* @run driver compiler.debug.TestStressIGVN
3940
*/

test/hotspot/jtreg/compiler/loopopts/TestLoopUnswitchingLostCastDependency.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/*
2525
* @test
26+
* @key stress randomness
2627
* @bug 8241900
2728
* @summary Loop unswitching may cause dependence on null check to be lost
2829
*

test/hotspot/jtreg/compiler/loopopts/TestPredicateLostDependency.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @key stress randomness
2627
* @bug 8069191
2728
* @summary predicate moved out of loops and CastPP removal causes dependency to be lost
2829
*

test/hotspot/jtreg/compiler/loopopts/TestRangeCheckPredicatesControl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/*
2525
* @test
26+
* @key stress randomness
2627
* @requires vm.gc.Z
2728
* @bug 8237859
2829
* @summary A LoadP node has a wrong control input (too early) which results in an out-of-bounds read of an object array with ZGC.

test/hotspot/jtreg/compiler/membars/DekkerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @key stress randomness
2627
* @bug 8007898
2728
* @summary Incorrect optimization of Memory Barriers in Matcher::post_store_load_barrier().
2829
* @run main/othervm -Xbatch -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions

test/hotspot/jtreg/gc/shenandoah/compiler/TestExpandedWBLostNullCheckDep.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test TestExpandedWBLostNullCheckDep
26+
* @key stress randomness
2627
* @summary Logic that moves a null check in the expanded barrier may cause a memory access that doesn't depend on the barrier to bypass the null check
2728
* @requires vm.gc.Shenandoah
2829
* @requires vm.flavor == "server"

test/hotspot/jtreg/gc/shenandoah/compiler/TestWriteBarrierClearControl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test TestWriteBarrierClearControl
26+
* @key stress randomness
2627
* @summary Clearing control during final graph reshape causes memory barrier to loose dependency on null check
2728
* @requires vm.gc.Shenandoah
2829
* @requires vm.flavor == "server"

0 commit comments

Comments
 (0)