test/hotspot/jtreg/runtime/appcds/VerifierTest.java
changeset 53853 7ca9e625d6b2
parent 52361 cefc50af3ee7
child 54607 b6db97903b69
equal deleted inserted replaced
53851:cc4f5bf6b26b 53853:7ca9e625d6b2
     1 /*
     1 /*
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    36  */
    36  */
    37 public class VerifierTest implements Opcodes {
    37 public class VerifierTest implements Opcodes {
    38     // Test verification settings for dumping & runtime
    38     // Test verification settings for dumping & runtime
    39     static final String VFY_ALL = "-Xverify:all";
    39     static final String VFY_ALL = "-Xverify:all";
    40     static final String VFY_REMOTE = "-Xverify:remote"; // default
    40     static final String VFY_REMOTE = "-Xverify:remote"; // default
    41     static final String VFY_NONE = "-Xverify:none";
    41     static final String VFY_NONE = "-XX:-BytecodeVerificationRemote, -XX:-BytecodeVerificationLocal";
    42 
    42 
    43     static final String ERR =
    43     static final String ERR =
    44         "ERROR: class VerifierTestC was loaded unexpectedly";
    44         "ERROR: class VerifierTestC was loaded unexpectedly";
    45     static final String MAP_FAIL =
    45     static final String MAP_FAIL =
    46         "shared archive file was created with less restrictive verification setting";
    46         "shared archive file was created with less restrictive verification setting";
   138             {"app",   VFY_REMOTE, VFY_NONE,   ERR },
   138             {"app",   VFY_REMOTE, VFY_NONE,   ERR },
   139             // Dump app/ext with -Xverify:all
   139             // Dump app/ext with -Xverify:all
   140             {"app",   VFY_ALL,    VFY_REMOTE, VFY_ERR },
   140             {"app",   VFY_ALL,    VFY_REMOTE, VFY_ERR },
   141             {"app",   VFY_ALL,    VFY_ALL,    VFY_ERR },
   141             {"app",   VFY_ALL,    VFY_ALL,    VFY_ERR },
   142             {"app",   VFY_ALL,    VFY_NONE,   ERR },
   142             {"app",   VFY_ALL,    VFY_NONE,   ERR },
   143             // Dump app/ext with -Xverify:none
   143             // Dump app/ext with verifier turned off
   144             {"app",   VFY_NONE,   VFY_REMOTE, VFY_ERR},
   144             {"app",   VFY_NONE,   VFY_REMOTE, VFY_ERR},
   145             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
   145             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
   146             {"app",   VFY_NONE,   VFY_NONE,   ERR },
   146             {"app",   VFY_NONE,   VFY_NONE,   ERR },
   147             // Dump sys only with -Xverify:remote
   147             // Dump sys only with -Xverify:remote
   148             {"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
   148             {"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
   150             {"noApp", VFY_REMOTE, VFY_NONE,   ERR},
   150             {"noApp", VFY_REMOTE, VFY_NONE,   ERR},
   151             // Dump sys only with -Xverify:all
   151             // Dump sys only with -Xverify:all
   152             {"noApp", VFY_ALL, VFY_REMOTE,    VFY_ERR},
   152             {"noApp", VFY_ALL, VFY_REMOTE,    VFY_ERR},
   153             {"noApp", VFY_ALL, VFY_ALL,       VFY_ERR},
   153             {"noApp", VFY_ALL, VFY_ALL,       VFY_ERR},
   154             {"noApp", VFY_ALL, VFY_NONE,      ERR},
   154             {"noApp", VFY_ALL, VFY_NONE,      ERR},
   155             // Dump sys only with -Xverify:none
   155             // Dump sys only with verifier turned off
   156             {"noApp", VFY_NONE, VFY_REMOTE,   VFY_ERR},
   156             {"noApp", VFY_NONE, VFY_REMOTE,   VFY_ERR},
   157             {"noApp", VFY_NONE, VFY_ALL,      VFY_ERR},
   157             {"noApp", VFY_NONE, VFY_ALL,      VFY_ERR},
   158             {"noApp", VFY_NONE, VFY_NONE,     ERR},
   158             {"noApp", VFY_NONE, VFY_NONE,     ERR},
   159         };
   159         };
   160 
   160 
   184             String expected_output_str = config[i][3];
   184             String expected_output_str = config[i][3];
   185             System.out.println("Test case [" + i + "]: dumping " + config[i][0] +
   185             System.out.println("Test case [" + i + "]: dumping " + config[i][0] +
   186                                " with " + dump_setting +
   186                                " with " + dump_setting +
   187                                ", run with " + runtime_setting);
   187                                ", run with " + runtime_setting);
   188             if (!dump_setting.equals(prev_dump_setting)) {
   188             if (!dump_setting.equals(prev_dump_setting)) {
       
   189                 String dump_arg1;
       
   190                 String dump_arg2;
       
   191                 // Need to break this into two separate arguments.
       
   192                 if (dump_setting.equals(VFY_NONE)) {
       
   193                     dump_arg1 = "-XX:-BytecodeVerificationRemote";
       
   194                     dump_arg2 = "-XX:-BytecodeVerificationLocal";
       
   195                 } else {
       
   196                     // Redundant args should be harmless.
       
   197                     dump_arg1 = dump_arg2 = dump_setting;
       
   198                 }
       
   199 
   189                 OutputAnalyzer dumpOutput = TestCommon.dump(
   200                 OutputAnalyzer dumpOutput = TestCommon.dump(
   190                                                             jar, dump_list, dump_setting,
   201                                                             jar, dump_list, dump_arg1, dump_arg2,
   191                                                             CDS_LOGGING,
   202                                                             CDS_LOGGING,
   192                                                             // FIXME: the following options are for working around a GC
   203                                                             // FIXME: the following options are for working around a GC
   193                                                             // issue - assert failure when dumping archive with the -Xverify:all
   204                                                             // issue - assert failure when dumping archive with the -Xverify:all
   194                                                             "-Xms256m",
   205                                                             "-Xms256m",
   195                                                             "-Xmx256m");
   206                                                             "-Xmx256m");
   196                 if (dump_setting.equals(VFY_NONE) &&
   207                 if (dump_setting.equals(VFY_NONE) &&
   197                     runtime_setting.equals(VFY_REMOTE)) {
   208                     runtime_setting.equals(VFY_REMOTE)) {
   198                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
   209                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
   199                 }
   210                 }
   200             }
   211             }
       
   212             String runtime_arg1;
       
   213             String runtime_arg2;
       
   214             if (runtime_setting.equals(VFY_NONE)) {
       
   215                 runtime_arg1 = "-XX:-BytecodeVerificationRemote";
       
   216                 runtime_arg2 = "-XX:-BytecodeVerificationLocal";
       
   217             } else {
       
   218                 // Redundant args should be harmless.
       
   219                 runtime_arg1 = runtime_arg2 = runtime_setting;
       
   220             }
   201             TestCommon.run("-cp", jar,
   221             TestCommon.run("-cp", jar,
   202                            runtime_setting,
   222                            runtime_arg1, runtime_arg2,
   203                            "VerifierTest0")
   223                            "VerifierTest0")
   204                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
   224                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
   205             prev_dump_setting = dump_setting;
   225             prev_dump_setting = dump_setting;
   206         }
   226         }
   207     }
   227     }
   227             {"app",   VFY_REMOTE, VFY_NONE,   PASS_RESULT },
   247             {"app",   VFY_REMOTE, VFY_NONE,   PASS_RESULT },
   228             // Dump app/ext with -Xverify:all
   248             // Dump app/ext with -Xverify:all
   229             {"app",   VFY_ALL,    VFY_REMOTE, PASS_RESULT },
   249             {"app",   VFY_ALL,    VFY_REMOTE, PASS_RESULT },
   230             {"app",   VFY_ALL,    VFY_ALL,    PASS_RESULT },
   250             {"app",   VFY_ALL,    VFY_ALL,    PASS_RESULT },
   231             {"app",   VFY_ALL,    VFY_NONE,   PASS_RESULT },
   251             {"app",   VFY_ALL,    VFY_NONE,   PASS_RESULT },
   232             // Dump app/ext with -Xverify:none
   252             // Dump app/ext with verifier turned off
   233             {"app",   VFY_NONE,   VFY_REMOTE, PASS_RESULT},
   253             {"app",   VFY_NONE,   VFY_REMOTE, PASS_RESULT},
   234             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
   254             {"app",   VFY_NONE,   VFY_ALL,    MAP_FAIL},
   235             {"app",   VFY_NONE,   VFY_NONE,   PASS_RESULT },
   255             {"app",   VFY_NONE,   VFY_NONE,   PASS_RESULT },
   236         };
   256         };
   237         String prev_dump_setting = "";
   257         String prev_dump_setting = "";
   242             String expected_output_str = config2[i][3];
   262             String expected_output_str = config2[i][3];
   243             System.out.println("Test case [" + i + "]: dumping " + config2[i][0] +
   263             System.out.println("Test case [" + i + "]: dumping " + config2[i][0] +
   244                                " with " + dump_setting +
   264                                " with " + dump_setting +
   245                                ", run with " + runtime_setting);
   265                                ", run with " + runtime_setting);
   246             if (!dump_setting.equals(prev_dump_setting)) {
   266             if (!dump_setting.equals(prev_dump_setting)) {
       
   267                 String dump_arg1;
       
   268                 String dump_arg2;
       
   269                 if (dump_setting.equals(VFY_NONE)) {
       
   270                     dump_arg1 = "-XX:-BytecodeVerificationRemote";
       
   271                     dump_arg2 = "-XX:-BytecodeVerificationLocal";
       
   272                 } else {
       
   273                     // Redundant args should be harmless.
       
   274                     dump_arg1 = dump_arg2 = dump_setting;
       
   275                 }
   247                 OutputAnalyzer dumpOutput = TestCommon.dump(
   276                 OutputAnalyzer dumpOutput = TestCommon.dump(
   248                                                             jar, appClasses, dump_setting,
   277                                                             jar, appClasses, dump_arg1, dump_arg2,
   249                                                             CDS_LOGGING,
   278                                                             CDS_LOGGING,
   250                                                             // FIXME: the following options are for working around a GC
   279                                                             // FIXME: the following options are for working around a GC
   251                                                             // issue - assert failure when dumping archive with the -Xverify:all
   280                                                             // issue - assert failure when dumping archive with the -Xverify:all
   252                                                             "-Xms256m",
   281                                                             "-Xms256m",
   253                                                             "-Xmx256m");
   282                                                             "-Xmx256m");
   254                 if (dump_setting.equals(VFY_NONE) &&
   283                 if (dump_setting.equals(VFY_NONE) &&
   255                     runtime_setting.equals(VFY_REMOTE)) {
   284                     runtime_setting.equals(VFY_REMOTE)) {
   256                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
   285                     dumpOutput.shouldContain(VFY_INFO_MESSAGE);
   257                 }
   286                 }
   258             }
   287             }
       
   288             String runtime_arg1;
       
   289             String runtime_arg2;
       
   290             if (runtime_setting.equals(VFY_NONE)) {
       
   291                 runtime_arg1 = "-XX:-BytecodeVerificationRemote";
       
   292                 runtime_arg2 = "-XX:-BytecodeVerificationLocal";
       
   293             } else {
       
   294                 // Redundant args should be harmless.
       
   295                 runtime_arg1 = runtime_arg2 = runtime_setting;
       
   296             }
   259             TestCommon.run("-cp", jar,
   297             TestCommon.run("-cp", jar,
   260                            runtime_setting,
   298                            runtime_arg1, runtime_arg2,
   261                            "Hi")
   299                            "Hi")
   262                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
   300                 .ifNoMappingFailure(output -> checkRuntimeOutput(output, expected_output_str));
   263            prev_dump_setting = dump_setting;
   301            prev_dump_setting = dump_setting;
   264         }
   302         }
   265     }
   303     }