|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 ir_framework.tests; |
| 25 | + |
| 26 | +import compiler.lib.ir_framework.*; |
| 27 | +import compiler.lib.ir_framework.driver.IRViolationException; |
| 28 | +import jdk.test.lib.Asserts; |
| 29 | + |
| 30 | +/* |
| 31 | + * @test |
| 32 | + * @bug 8276546 |
| 33 | + * @requires vm.debug == true & vm.compMode != "Xint" & vm.compMode != "Xcomp" & vm.compiler1.enabled & vm.compiler2.enabled & vm.flagless |
| 34 | + * @summary Test that CompileThreshold flag is ignored when passed as Java/VM option to the framework. |
| 35 | + * Normally, the framework should be called with driver. |
| 36 | + * @library /test/lib /testlibrary_tests / |
| 37 | + * @run main/othervm -XX:CompileThreshold=12 -XX:+UseG1GC ir_framework.tests.TestCompileThreshold |
| 38 | + */ |
| 39 | + |
| 40 | +public class TestCompileThreshold { |
| 41 | + public int iFld = 0; |
| 42 | + |
| 43 | + public static void main(String[] args) throws Exception { |
| 44 | + try { |
| 45 | + // CompileThreshold=12 passed to the JTreg test is ignored even though we prefer command line flags. |
| 46 | + // CompileThreshold=10 is user defined and passed directly to the framework and thus not ignored. |
| 47 | + // InterpreterProfilePercentage=0 ensures that we compile exactly after 10 invocations. |
| 48 | + TestFramework.runWithFlags("-XX:CompileThreshold=10", "-XX:InterpreterProfilePercentage=0", |
| 49 | + "-XX:-TieredCompilation", "-DTest=testWithCompileThreshold", |
| 50 | + "-DPreferCommandLineFlags=true"); |
| 51 | + } catch (IRViolationException e) { |
| 52 | + Asserts.assertTrue(e.getExceptionInfo().contains("Failed IR Rules (1)"), "exactly one rule failed"); |
| 53 | + Asserts.assertTrue(e.getExceptionInfo().contains("testWithCompileThreshold()"), |
| 54 | + "testWithCompileThreshold() failed"); |
| 55 | + } |
| 56 | + |
| 57 | + try { |
| 58 | + TestFramework.runWithFlags("-XX:InterpreterProfilePercentage=0", "-XX:-TieredCompilation", |
| 59 | + "-DTest=testWithoutCompileThreshold"); |
| 60 | + } catch (IRViolationException e) { |
| 61 | + Asserts.assertTrue(e.getExceptionInfo().contains("Failed IR Rules (1)"), "exactly one rule failed"); |
| 62 | + Asserts.assertTrue(e.getExceptionInfo().contains("testWithoutCompileThreshold()"), |
| 63 | + "testWithoutCompileThreshold() failed"); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + @IR(counts = {IRNode.CALL, "1"}) // fails |
| 69 | + public void testWithCompileThreshold() { |
| 70 | + iFld++; |
| 71 | + } |
| 72 | + |
| 73 | + @Run(test = "testWithCompileThreshold") |
| 74 | + @Warmup(20) |
| 75 | + public void runTestWithCompileThreshold(RunInfo info) { |
| 76 | + if (iFld == 10) { |
| 77 | + TestFramework.assertNotCompiled(info.getTest()); |
| 78 | + } else if (iFld == 11) { |
| 79 | + // CompileThreshold=10 is passed directly as a flag to the framework. |
| 80 | + // Therefore, testWithCompileThreshold() must be compiled by now. |
| 81 | + TestFramework.assertCompiled(info.getTest()); |
| 82 | + } |
| 83 | + testWithCompileThreshold(); |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + @Test |
| 88 | + @IR(counts = {IRNode.CALL, "1"}) // fails |
| 89 | + public void testWithoutCompileThreshold() { |
| 90 | + iFld++; |
| 91 | + } |
| 92 | + |
| 93 | + @Run(test = "testWithoutCompileThreshold") |
| 94 | + @Warmup(20) |
| 95 | + public void runTestWithoutCompileThreshold(RunInfo info) { |
| 96 | + testWithCompileThreshold(); |
| 97 | + if (info.isWarmUp()) { |
| 98 | + // CompileThreshold=12 is passed to the JTreg test but not directly to the framework. |
| 99 | + // Therefore, it is ignored and we do not trigger a compilation until the framework does. |
| 100 | + TestFramework.assertNotCompiled(info.getTest()); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments