Path: blob/master/test/hotspot/jtreg/compiler/gcbarriers/TestMembarDependencies.java
41152 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test TestMembarDependencies25* @bug 817285026* @summary Tests correct scheduling of memory loads around MembarVolatile emitted by GC barriers.27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.management30* @run driver compiler.membars.TestMembarDependencies31*/3233package compiler.membars;3435import jdk.test.lib.process.OutputAnalyzer;36import jdk.test.lib.process.ProcessTools;3738public class TestMembarDependencies {39private static TestMembarDependencies f1;40private static TestMembarDependencies f2;4142public static void main(String args[]) throws Exception {43if (args.length == 0) {44// For debugging, add "-XX:+TraceOptoPipelining"45OutputAnalyzer oa = ProcessTools.executeTestJvm("-XX:+IgnoreUnrecognizedVMOptions",46"-XX:-TieredCompilation", "-XX:-BackgroundCompilation", "-XX:+PrintOpto",47"-XX:CompileCommand=compileonly,compiler.membars.TestMembarDependencies::test*",48"-XX:CompileCommand=dontinline,compiler.membars.TestMembarDependencies::test_m1",49TestMembarDependencies.class.getName(), "run");50// C2 should not crash or bail out from compilation51oa.shouldHaveExitValue(0);52oa.shouldNotMatch("Bailout: Recompile without subsuming loads");53System.out.println(oa.getOutput());54} else {55f2 = new TestMembarDependencies();56// Trigger compilation of test1 and test257for (int i = 0; i < 10_000; ++i) {58f2.test1(f2);59f2.test2(f2);60}61}62}6364public void test_m1() { }65public void test_m2() { }6667public void test1(TestMembarDependencies obj) {68// Try/catch/finally is used to create a CFG block without a test + jmpCon69// allowing GCM to schedule the testN_mem_reg0 instruction into that block.70try {71// Method call defines memory state that is then72// used by subsequent instructions/blocks (see below).73test_m1();74} catch (Exception e) {7576} finally {77// Oop write to field emits a GC post-barrier with a MembarVolatile78// which has a wide memory effect (kills all memory). This creates an79// anti-dependency on all surrounding memory loads.80f1 = obj;81}82// The empty method m2 is inlined but the null check of f2 remains. It is encoded83// as CmpN(LoadN(MEM), NULL) where MEM is the memory after the call to test_m1().84// This is matched to testN_mem_reg0 on x86 which is scheduled before the barrier85// in the try/catch block due to the anti-dependency on the MembarVolatile.86// C2 crashes in the register allocator when trying to spill the flag register87// to keep the result of the testN instruction live from the try/catch block88// until it is here.89f2.test_m2();90}9192public void test2(TestMembarDependencies obj) {93// Same as test1 but without try/catch/finally.94// This causes C2 to bail out in block local scheduling because testN_mem_reg0 is95// scheduled into a block that already contains another test + jmpCon instruction.96test_m1();97f1 = obj;98f2.test_m2();99}100}101102103