test/hotspot/jtreg/runtime/cds/appcds/cacheObject/ArchivedIntegerCacheTest.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 52811 ff04b71bf6f1
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
       
     1 /*
       
     2  * Copyright (c) 2018, 2019, 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 
       
    25 /*
       
    26  * @test
       
    27  * @summary Test primitive box caches integrity in various scenarios (IntegerCache etc)
       
    28  * @requires vm.cds.archived.java.heap
       
    29  * @library /test/jdk/lib/testlibrary /test/lib /test/hotspot/jtreg/runtime/cds/appcds
       
    30  * @build sun.hotspot.WhiteBox
       
    31  * @compile CheckIntegerCacheApp.java
       
    32  * @run driver ClassFileInstaller -jar boxCache.jar CheckIntegerCacheApp
       
    33  * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
       
    34  * @run driver ArchivedIntegerCacheTest
       
    35  */
       
    36 
       
    37 import java.nio.file.Files;
       
    38 import java.nio.file.Path;
       
    39 import java.nio.file.Paths;
       
    40 import jdk.test.lib.process.OutputAnalyzer;
       
    41 
       
    42 public class ArchivedIntegerCacheTest {
       
    43 
       
    44     public static void main(String[] args) throws Exception {
       
    45         String wbJar = ClassFileInstaller.getJarPath("WhiteBox.jar");
       
    46         String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
       
    47         String appJar = ClassFileInstaller.getJarPath("boxCache.jar");
       
    48 
       
    49         Path userDir = Paths.get(System.getProperty("user.dir"));
       
    50         Path moduleDir = Files.createTempDirectory(userDir, "mods");
       
    51 
       
    52         //
       
    53         // Dump default archive
       
    54         //
       
    55         OutputAnalyzer output = TestCommon.dump(appJar,
       
    56                 TestCommon.list("CheckIntegerCacheApp"),
       
    57                 use_whitebox_jar);
       
    58         TestCommon.checkDump(output);
       
    59 
       
    60         // Test case 1)
       
    61         // - Default options
       
    62         System.out.println("----------------------- Test case 1 ----------------------");
       
    63         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    64                 "-XX:+UnlockDiagnosticVMOptions",
       
    65                 "-XX:+WhiteBoxAPI",
       
    66                 "CheckIntegerCacheApp",
       
    67                 "127",
       
    68                 "true");
       
    69         TestCommon.checkExec(output);
       
    70 
       
    71         // Test case 2)
       
    72         // - Default archive
       
    73         // - Larger -XX:AutoBoxCacheMax
       
    74         System.out.println("----------------------- Test case 2 ----------------------");
       
    75         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    76                 "-XX:+UnlockDiagnosticVMOptions",
       
    77                 "-XX:+WhiteBoxAPI",
       
    78                 "-XX:AutoBoxCacheMax=20000",
       
    79                 "CheckIntegerCacheApp",
       
    80                 "20000",
       
    81                 "false");
       
    82         TestCommon.checkExec(output);
       
    83 
       
    84         //
       
    85         // Dump with -XX:AutoBoxCacheMax specified
       
    86         //
       
    87         output = TestCommon.dump(appJar,
       
    88                 TestCommon.list("CheckIntegerCacheApp"),
       
    89                 "-XX:AutoBoxCacheMax=20000",
       
    90                 use_whitebox_jar);
       
    91         TestCommon.checkDump(output);
       
    92 
       
    93         // Test case 3)
       
    94         // - Large archived cache
       
    95         // - Default options
       
    96         System.out.println("----------------------- Test case 3 ----------------------");
       
    97         output = TestCommon.exec(appJar, use_whitebox_jar,
       
    98                 "--module-path",
       
    99                 moduleDir.toString(),
       
   100                 "-XX:+UnlockDiagnosticVMOptions",
       
   101                 "-XX:+WhiteBoxAPI",
       
   102                 "CheckIntegerCacheApp",
       
   103                 "127",
       
   104                 "true");
       
   105         TestCommon.checkExec(output);
       
   106 
       
   107 
       
   108         // Test case 4)
       
   109         // - Large archived cache
       
   110         // - Matching options
       
   111         System.out.println("----------------------- Test case 4 ----------------------");
       
   112         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   113                 "--module-path",
       
   114                 moduleDir.toString(),
       
   115                 "-XX:+UnlockDiagnosticVMOptions",
       
   116                 "-XX:+WhiteBoxAPI",
       
   117                 "-XX:AutoBoxCacheMax=20000",
       
   118                 "CheckIntegerCacheApp",
       
   119                 "20000",
       
   120                 "true");
       
   121         TestCommon.checkExec(output);
       
   122 
       
   123         // Test case 5)
       
   124         // - Large archived cache
       
   125         // - Larger requested cache
       
   126         System.out.println("----------------------- Test case 5 ----------------------");
       
   127         output = TestCommon.exec(appJar, use_whitebox_jar,
       
   128                 "--module-path",
       
   129                 moduleDir.toString(),
       
   130                 "-XX:+UnlockDiagnosticVMOptions",
       
   131                 "-XX:+WhiteBoxAPI",
       
   132                 "-XX:AutoBoxCacheMax=30000",
       
   133                 "CheckIntegerCacheApp",
       
   134                 "30000",
       
   135                 "false");
       
   136         TestCommon.checkExec(output);
       
   137 
       
   138         // Test case 6)
       
   139         // - Cache is too large to archive
       
   140         output = TestCommon.dump(appJar,
       
   141                 TestCommon.list("CheckIntegerCacheApp"),
       
   142                 "-XX:AutoBoxCacheMax=2000000",
       
   143                 "-Xmx1g",
       
   144                 "-XX:NewSize=1g",
       
   145                 "-Xlog:cds+heap=info",
       
   146                 "-Xlog:gc+region+cds",
       
   147                 "-Xlog:gc+region=trace",
       
   148                 use_whitebox_jar);
       
   149         TestCommon.checkDump(output,
       
   150             "Cannot archive the sub-graph referenced from [Ljava.lang.Integer; object",
       
   151             "humongous regions have been found and may lead to fragmentation");
       
   152     }
       
   153 }