1 /* 2 * Copyright (c) 2013, 2015, 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 import java.util.function.Function; 25 26 import compiler.whitebox.CompilerWhiteBoxTest; 27 28 /* 29 * @test ClearMethodStateTest 30 * @bug 8006683 8007288 8022832 31 * @library /testlibrary /test/lib / 32 * @modules java.management 33 * @build ClearMethodStateTest 34 * @run main ClassFileInstaller sun.hotspot.WhiteBox 35 * sun.hotspot.WhiteBox$WhiteBoxPermission 36 * @run main/othervm -Xbootclasspath/a:. -Xmixed -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+PrintCompilation ClearMethodStateTest 37 * @summary testing of WB::clearMethodState() 38 * @author igor.ignatyev@oracle.com 39 */ 40 public class ClearMethodStateTest extends CompilerWhiteBoxTest { 41 42 public static void main(String[] args) throws Exception { 43 String directive = 44 "[{ match:\"*SimpleTestCaseHelper.*\", BackgroundCompilation: false }, " + 45 " { match:\"*.*\", inline:\"-*SimpleTestCaseHelper.*\"}]"; 46 if (WHITE_BOX.addCompilerDirective(directive) != 2) { 47 throw new RuntimeException("Could not add directive"); 48 } 49 try { 50 CompilerWhiteBoxTest.main(ClearMethodStateTest::new, args); 51 } finally { 52 WHITE_BOX.removeCompilerDirective(2); 53 } 54 } 55 56 private ClearMethodStateTest(TestCase testCase) { 57 super(testCase); 58 // to prevent inlining of #method 59 WHITE_BOX.testSetDontInlineMethod(method, true); 60 } 61 62 63 /** 64 * Tests {@code WB::clearMethodState()} by calling it before/after 65 * compilation. For non-tiered, checks that counters will be rested after 66 * clearing of method state. 67 * 68 * @throws Exception if one of the checks fails. 69 */ 70 @Override 71 protected void test() throws Exception { 72 73 checkNotCompiled(); 74 compile(); 75 WHITE_BOX.clearMethodState(method); 76 checkCompiled(); 77 WHITE_BOX.clearMethodState(method); 78 deoptimize(); 79 checkNotCompiled(); 80 81 if (testCase.isOsr()) { 82 // part test isn't applicable for OSR test case 83 return; 84 } 85 if (!TIERED_COMPILATION) { 86 WHITE_BOX.clearMethodState(method); 87 compile(COMPILE_THRESHOLD); 88 checkCompiled(); 89 90 deoptimize(); 91 checkNotCompiled(); 92 WHITE_BOX.clearMethodState(method); 93 94 // invoke method one less time than needed to compile 95 if (COMPILE_THRESHOLD > 1) { 96 compile(COMPILE_THRESHOLD - 1); 97 checkNotCompiled(); 98 } else { 99 System.err.println("Warning: 'CompileThreshold' <= 1"); 100 } 101 102 compile(1); 103 checkCompiled(); 104 } else { 105 System.err.println( 106 "Warning: part of test is not applicable in Tiered"); 107 } 108 } 109 }