test/compiler/whitebox/MakeMethodNotCompilableTest.java

Wed, 27 Aug 2014 08:19:12 -0400

author
zgu
date
Wed, 27 Aug 2014 08:19:12 -0400
changeset 7074
833b0f92429a
parent 6353
d559dbbded7a
child 6876
710a3c8b516e
child 7318
c88a4554854c
permissions
-rw-r--r--

8046598: Scalable Native memory tracking development
Summary: Enhance scalability of native memory tracking
Reviewed-by: coleenp, ctornqvi, gtriantafill

     1 /*
     2  * Copyright (c) 2013, 2014, 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  */
    24 /*
    25  * @test MakeMethodNotCompilableTest
    26  * @bug 8012322 8006683 8007288 8022832
    27  * @library /testlibrary /testlibrary/whitebox
    28  * @build MakeMethodNotCompilableTest
    29  * @run main ClassFileInstaller sun.hotspot.WhiteBox
    30  * @run main/othervm/timeout=2400 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,SimpleTestCase$Helper::* MakeMethodNotCompilableTest
    31  * @summary testing of WB::makeMethodNotCompilable()
    32  * @author igor.ignatyev@oracle.com
    33  */
    34 public class MakeMethodNotCompilableTest extends CompilerWhiteBoxTest {
    35     private int bci;
    36     public static void main(String[] args) throws Exception {
    37         CompilerWhiteBoxTest.main(MakeMethodNotCompilableTest::new, args);
    38     }
    40     private MakeMethodNotCompilableTest(TestCase testCase) {
    41         super(testCase);
    42         // to prevent inlining of #method
    43         WHITE_BOX.testSetDontInlineMethod(method, true);
    44     }
    46     /**
    47      * Tests {@code WB::makeMethodNotCompilable()} by calling it before
    48      * compilation and checking that method isn't compiled. Also
    49      * checks that WB::clearMethodState() clears no-compilable flags. For
    50      * tiered, additional checks for all available levels are conducted.
    51      *
    52      * @throws Exception if one of the checks fails.
    53      */
    54     @Override
    55     protected void test() throws Exception {
    56         if (skipXcompOSR()) {
    57             return;
    58         }
    59         checkNotCompiled();
    60         if (!isCompilable()) {
    61             throw new RuntimeException(method + " must be compilable");
    62         }
    64         bci = getBci();
    66         if (TIERED_COMPILATION) {
    67             final int tierLimit = TIERED_STOP_AT_LEVEL + 1;
    68             for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
    69                 testTier(testedTier);
    70             }
    71             for (int testedTier = 1; testedTier < tierLimit; ++testedTier) {
    72                 makeNotCompilable(testedTier);
    73                 if (isCompilable(testedTier)) {
    74                     throw new RuntimeException(method
    75                             + " must be not compilable at level" + testedTier);
    76                 }
    77                 WHITE_BOX.enqueueMethodForCompilation(method, testedTier, bci);
    78                 checkNotCompiled();
    80                 if (!isCompilable()) {
    81                     System.out.println(method
    82                             + " is not compilable after level " + testedTier);
    83                 }
    84             }
    85         } else {
    86             compile();
    87             checkCompiled();
    88             int compLevel = getCompLevel();
    89             deoptimize();
    90             makeNotCompilable(compLevel);
    91             if (isCompilable(COMP_LEVEL_ANY)) {
    92                 throw new RuntimeException(method
    93                         + " must be not compilable at CompLevel::CompLevel_any,"
    94                         + " after it is not compilable at " + compLevel);
    95             }
    97             WHITE_BOX.clearMethodState(method);
    98             if (!isCompilable()) {
    99                 throw new RuntimeException(method
   100                         + " is not compilable after clearMethodState()");
   101             }
   103             // nocompilable at opposite level must make no sense
   104             int oppositeLevel;
   105             if (isC1Compile(compLevel)) {
   106               oppositeLevel = COMP_LEVEL_FULL_OPTIMIZATION;
   107             } else {
   108               oppositeLevel = COMP_LEVEL_SIMPLE;
   109             }
   110             makeNotCompilable(oppositeLevel);
   112             if (!isCompilable(COMP_LEVEL_ANY)) {
   113                   throw new RuntimeException(method
   114                         + " must be compilable at CompLevel::CompLevel_any,"
   115                         + " even it is not compilable at opposite level ["
   116                         + compLevel + "]");
   117             }
   119             if (!isCompilable(compLevel)) {
   120                   throw new RuntimeException(method
   121                         + " must be compilable at level " + compLevel
   122                         + ", even it is not compilable at opposite level ["
   123                         + compLevel + "]");
   124             }
   125         }
   127         // clearing after tiered/non-tiered tests
   128         // WB.clearMethodState() must reset no-compilable flags
   129         WHITE_BOX.clearMethodState(method);
   130         if (!isCompilable()) {
   131             throw new RuntimeException(method
   132                     + " is not compilable after clearMethodState()");
   133         }
   135         makeNotCompilable();
   136         if (isCompilable()) {
   137             throw new RuntimeException(method + " must be not compilable");
   138         }
   140         compile();
   141         checkNotCompiled();
   142         if (isCompilable()) {
   143             throw new RuntimeException(method + " must be not compilable");
   144         }
   145         // WB.clearMethodState() must reset no-compilable flags
   146         WHITE_BOX.clearMethodState(method);
   147         if (!isCompilable()) {
   148             throw new RuntimeException(method
   149                     + " is not compilable after clearMethodState()");
   150         }
   151         compile();
   152         checkCompiled();
   153     }
   155     // separately tests each tier
   156     private void testTier(int testedTier) {
   157         if (!isCompilable(testedTier)) {
   158             throw new RuntimeException(method
   159                     + " is not compilable on start");
   160         }
   161         makeNotCompilable(testedTier);
   163         // tests for all other tiers
   164         for (int anotherTier = 1, tierLimit = TIERED_STOP_AT_LEVEL + 1;
   165                     anotherTier < tierLimit; ++anotherTier) {
   166             boolean isCompilable = isCompilable(anotherTier);
   167             if (sameCompile(testedTier, anotherTier)) {
   168                 if (isCompilable) {
   169                     throw new RuntimeException(method
   170                             + " must be not compilable at level " + anotherTier
   171                             + ", if it is not compilable at " + testedTier);
   172                 }
   173                 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
   174                 checkNotCompiled();
   175             } else {
   176                 if (!isCompilable) {
   177                     throw new RuntimeException(method
   178                             + " must be compilable at level " + anotherTier
   179                             + ", even if it is not compilable at "
   180                             + testedTier);
   181                 }
   182                 WHITE_BOX.enqueueMethodForCompilation(method, anotherTier, bci);
   183                 checkCompiled();
   184                 deoptimize();
   185             }
   187             if (!isCompilable(COMP_LEVEL_ANY)) {
   188                 throw new RuntimeException(method
   189                         + " must be compilable at 'CompLevel::CompLevel_any'"
   190                         + ", if it is not compilable only at " + testedTier);
   191             }
   192         }
   194         // clear state after test
   195         WHITE_BOX.clearMethodState(method);
   196         if (!isCompilable(testedTier)) {
   197             throw new RuntimeException(method
   198                     + " is not compilable after clearMethodState()");
   199         }
   200     }
   202     private boolean sameCompile(int level1, int level2) {
   203         if (level1 == level2) {
   204             return true;
   205         }
   206         if (isC1Compile(level1) && isC1Compile(level2)) {
   207             return true;
   208         }
   209         if (isC2Compile(level1) && isC2Compile(level2)) {
   210             return true;
   211         }
   212         return false;
   213     }
   215     private int getBci() {
   216         compile();
   217         checkCompiled();
   218         int result = WHITE_BOX.getMethodEntryBci(method);
   219         deoptimize();
   220         WHITE_BOX.clearMethodState(method);
   221         return result;
   222     }
   223 }

mercurial