Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/gcbarriers/TestMembarDependencies.java
41152 views
1
/*
2
* Copyright (c) 2017, 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
/*
25
* @test TestMembarDependencies
26
* @bug 8172850
27
* @summary Tests correct scheduling of memory loads around MembarVolatile emitted by GC barriers.
28
* @library /test/lib /
29
* @modules java.base/jdk.internal.misc
30
* java.management
31
* @run driver compiler.membars.TestMembarDependencies
32
*/
33
34
package compiler.membars;
35
36
import jdk.test.lib.process.OutputAnalyzer;
37
import jdk.test.lib.process.ProcessTools;
38
39
public class TestMembarDependencies {
40
private static TestMembarDependencies f1;
41
private static TestMembarDependencies f2;
42
43
public static void main(String args[]) throws Exception {
44
if (args.length == 0) {
45
// For debugging, add "-XX:+TraceOptoPipelining"
46
OutputAnalyzer oa = ProcessTools.executeTestJvm("-XX:+IgnoreUnrecognizedVMOptions",
47
"-XX:-TieredCompilation", "-XX:-BackgroundCompilation", "-XX:+PrintOpto",
48
"-XX:CompileCommand=compileonly,compiler.membars.TestMembarDependencies::test*",
49
"-XX:CompileCommand=dontinline,compiler.membars.TestMembarDependencies::test_m1",
50
TestMembarDependencies.class.getName(), "run");
51
// C2 should not crash or bail out from compilation
52
oa.shouldHaveExitValue(0);
53
oa.shouldNotMatch("Bailout: Recompile without subsuming loads");
54
System.out.println(oa.getOutput());
55
} else {
56
f2 = new TestMembarDependencies();
57
// Trigger compilation of test1 and test2
58
for (int i = 0; i < 10_000; ++i) {
59
f2.test1(f2);
60
f2.test2(f2);
61
}
62
}
63
}
64
65
public void test_m1() { }
66
public void test_m2() { }
67
68
public void test1(TestMembarDependencies obj) {
69
// Try/catch/finally is used to create a CFG block without a test + jmpCon
70
// allowing GCM to schedule the testN_mem_reg0 instruction into that block.
71
try {
72
// Method call defines memory state that is then
73
// used by subsequent instructions/blocks (see below).
74
test_m1();
75
} catch (Exception e) {
76
77
} finally {
78
// Oop write to field emits a GC post-barrier with a MembarVolatile
79
// which has a wide memory effect (kills all memory). This creates an
80
// anti-dependency on all surrounding memory loads.
81
f1 = obj;
82
}
83
// The empty method m2 is inlined but the null check of f2 remains. It is encoded
84
// as CmpN(LoadN(MEM), NULL) where MEM is the memory after the call to test_m1().
85
// This is matched to testN_mem_reg0 on x86 which is scheduled before the barrier
86
// in the try/catch block due to the anti-dependency on the MembarVolatile.
87
// C2 crashes in the register allocator when trying to spill the flag register
88
// to keep the result of the testN instruction live from the try/catch block
89
// until it is here.
90
f2.test_m2();
91
}
92
93
public void test2(TestMembarDependencies obj) {
94
// Same as test1 but without try/catch/finally.
95
// This causes C2 to bail out in block local scheduling because testN_mem_reg0 is
96
// scheduled into a block that already contains another test + jmpCon instruction.
97
test_m1();
98
f1 = obj;
99
f2.test_m2();
100
}
101
}
102
103