hotspot/test/compiler/whitebox/GetNMethodTest.java
changeset 27642 8c9eff693145
parent 27146 06664440c7a3
child 27915 4edeee146240
equal deleted inserted replaced
27641:fca9ac607ebc 27642:8c9eff693145
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
       
    25 import sun.hotspot.code.BlobType;
    25 import sun.hotspot.code.NMethod;
    26 import sun.hotspot.code.NMethod;
       
    27 import com.oracle.java.testlibrary.Asserts;
    26 
    28 
    27 /*
    29 /*
    28  * @test GetNMethodTest
    30  * @test GetNMethodTest
    29  * @bug 8038240
    31  * @bug 8038240
    30  * @library /testlibrary /testlibrary/whitebox
    32  * @library /testlibrary /testlibrary/whitebox
    50     protected void test() throws Exception {
    52     protected void test() throws Exception {
    51         checkNotCompiled();
    53         checkNotCompiled();
    52 
    54 
    53         compile();
    55         compile();
    54         checkCompiled();
    56         checkCompiled();
       
    57 
    55         NMethod nmethod = NMethod.get(method, testCase.isOsr());
    58         NMethod nmethod = NMethod.get(method, testCase.isOsr());
    56         if (IS_VERBOSE) {
    59         if (IS_VERBOSE) {
    57             System.out.println("nmethod = " + nmethod);
    60             System.out.println("nmethod = " + nmethod);
    58         }
    61         }
    59         if (nmethod == null) {
    62         Asserts.assertNotNull(nmethod,
    60             throw new RuntimeException("nmethod of compiled method is null");
    63                 "nmethod of compiled method is null");
       
    64         Asserts.assertNotNull(nmethod.insts,
       
    65                 "nmethod.insts of compiled method is null");
       
    66         Asserts.assertGT(nmethod.insts.length, 0,
       
    67                 "compiled method's instructions is empty");
       
    68         Asserts.assertNotNull(nmethod.code_blob_type, "blob type is null");
       
    69         if (WHITE_BOX.getBooleanVMFlag("SegmentedCodeCache")) {
       
    70             Asserts.assertNE(nmethod.code_blob_type, BlobType.All);
       
    71             switch (nmethod.comp_level) {
       
    72             case 1:
       
    73             case 4:
       
    74                 checkBlockType(nmethod, BlobType.MethodNonProfiled);
       
    75                 break;
       
    76             case 2:
       
    77             case 3:
       
    78                 checkBlockType(nmethod, BlobType.MethodNonProfiled);
       
    79                 break;
       
    80             default:
       
    81                 throw new Error("unexpected comp level " + nmethod);
       
    82             }
       
    83         } else {
       
    84             Asserts.assertEQ(nmethod.code_blob_type, BlobType.All);
    61         }
    85         }
    62         if (nmethod.insts.length == 0) {
    86 
    63             throw new RuntimeException("compiled method's instructions is empty");
       
    64         }
       
    65         deoptimize();
    87         deoptimize();
    66         checkNotCompiled();
    88         checkNotCompiled();
    67         nmethod = NMethod.get(method, testCase.isOsr());
    89         nmethod = NMethod.get(method, testCase.isOsr());
    68         if (nmethod != null) {
    90         Asserts.assertNull(nmethod,
    69             throw new RuntimeException("nmethod of non-compiled method isn't null");
    91                 "nmethod of non-compiled method isn't null");
    70         }
    92     }
       
    93 
       
    94     private void checkBlockType(NMethod nmethod, BlobType expectedType) {
       
    95         Asserts.assertEQ(nmethod.code_blob_type, expectedType,
       
    96                 String.format("blob_type[%s] for %d level isn't %s",
       
    97                         nmethod.code_blob_type, nmethod.comp_level, expectedType));
    71     }
    98     }
    72 }
    99 }