1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/gcbarriers/TestMembarDependencies.java Mon Oct 15 11:00:27 2018 +0200 1.3 @@ -0,0 +1,98 @@ 1.4 +/* 1.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test TestMembarDependencies 1.29 + * @bug 8172850 1.30 + * @summary Tests correct scheduling of memory loads around MembarVolatile emitted by GC barriers. 1.31 + * @library /testlibrary 1.32 + * @run driver compiler.membars.TestMembarDependencies 1.33 + */ 1.34 + 1.35 +package compiler.membars; 1.36 + 1.37 +import com.oracle.java.testlibrary.*; 1.38 + 1.39 +public class TestMembarDependencies { 1.40 + private static TestMembarDependencies f1; 1.41 + private static TestMembarDependencies f2; 1.42 + 1.43 + public static void main(String args[]) throws Throwable { 1.44 + if (args.length == 0) { 1.45 + // For debugging, add "-XX:+TraceOptoPipelining" 1.46 + OutputAnalyzer oa = ProcessTools.executeTestJvm("-XX:+IgnoreUnrecognizedVMOptions", 1.47 + "-XX:-TieredCompilation", "-XX:-BackgroundCompilation", "-XX:+PrintOpto", 1.48 + "-XX:CompileCommand=compileonly,compiler.membars.TestMembarDependencies::test*", 1.49 + "-XX:CompileCommand=dontinline,compiler.membars.TestMembarDependencies::test_m1", 1.50 + TestMembarDependencies.class.getName(), "run"); 1.51 + // C2 should not crash or bail out from compilation 1.52 + oa.shouldHaveExitValue(0); 1.53 + oa.shouldNotMatch("Bailout: Recompile without subsuming loads"); 1.54 + System.out.println(oa.getOutput()); 1.55 + } else { 1.56 + f2 = new TestMembarDependencies(); 1.57 + // Trigger compilation of test1 and test2 1.58 + for (int i = 0; i < 10_000; ++i) { 1.59 + f2.test1(f2); 1.60 + f2.test2(f2); 1.61 + } 1.62 + } 1.63 + } 1.64 + 1.65 + public void test_m1() { } 1.66 + public void test_m2() { } 1.67 + 1.68 + public void test1(TestMembarDependencies obj) { 1.69 + // Try/catch/finally is used to create a CFG block without a test + jmpCon 1.70 + // allowing GCM to schedule the testN_mem_reg0 instruction into that block. 1.71 + try { 1.72 + // Method call defines memory state that is then 1.73 + // used by subsequent instructions/blocks (see below). 1.74 + test_m1(); 1.75 + } catch (Exception e) { 1.76 + 1.77 + } finally { 1.78 + // Oop write to field emits a GC post-barrier with a MembarVolatile 1.79 + // which has a wide memory effect (kills all memory). This creates an 1.80 + // anti-dependency on all surrounding memory loads. 1.81 + f1 = obj; 1.82 + } 1.83 + // The empty method m2 is inlined but the null check of f2 remains. It is encoded 1.84 + // as CmpN(LoadN(MEM), NULL) where MEM is the memory after the call to test_m1(). 1.85 + // This is matched to testN_mem_reg0 on x86 which is scheduled before the barrier 1.86 + // in the try/catch block due to the anti-dependency on the MembarVolatile. 1.87 + // C2 crashes in the register allocator when trying to spill the flag register 1.88 + // to keep the result of the testN instruction live from the try/catch block 1.89 + // until it is here. 1.90 + f2.test_m2(); 1.91 + } 1.92 + 1.93 + public void test2(TestMembarDependencies obj) { 1.94 + // Same as test1 but without try/catch/finally. 1.95 + // This causes C2 to bail out in block local scheduling because testN_mem_reg0 is 1.96 + // scheduled into a block that already contains another test + jmpCon instruction. 1.97 + test_m1(); 1.98 + f1 = obj; 1.99 + f2.test_m2(); 1.100 + } 1.101 +}