test/hotspot/jtreg/runtime/appcds/LotsOfClasses.java
changeset 54927 1512d88b24c6
parent 52811 ff04b71bf6f1
equal deleted inserted replaced
54926:d4e7ccaf1445 54927:1512d88b24c6
     1 /*
     1 /*
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
     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.
     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.
    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 java.net.URI;
       
    26 import java.nio.file.DirectoryStream;
       
    27 import java.nio.file.Files;
       
    28 import java.nio.file.FileSystem;
       
    29 import java.nio.file.FileSystems;
       
    30 import java.nio.file.Path;
       
    31 import java.util.ArrayList;
    25 import java.util.ArrayList;
    32 import java.util.regex.Matcher;
       
    33 import java.util.regex.Pattern;
       
    34 
    26 
    35 import jdk.test.lib.cds.CDSTestUtils;
    27 import jdk.test.lib.cds.CDSTestUtils;
    36 import jdk.test.lib.cds.CDSOptions;
    28 import jdk.test.lib.cds.CDSOptions;
    37 import jdk.test.lib.process.OutputAnalyzer;
    29 import jdk.test.lib.process.OutputAnalyzer;
    38 
    30 
    39 /*
    31 /*
    40  * @test
    32  * @test
    41  * @summary Try to archive lots of classes by searching for classes from the jrt:/ file system. With JDK 12
    33  * @summary Try to archive lots of classes by searching for classes from the jrt:/ file system. With JDK 12
    42  *          this will produce an archive with over 30,000 classes.
    34  *          this will produce an archive with over 30,000 classes.
    43  * @requires vm.cds
    35  * @requires vm.cds
    44  * @library /test/lib
    36  * @library /test/lib /test/hotspot/jtreg/runtime/appcds
    45  * @run driver/timeout=500 LotsOfClasses
    37  * @run driver/timeout=500 LotsOfClasses
    46  */
    38  */
    47 
    39 
    48 public class LotsOfClasses {
    40 public class LotsOfClasses {
    49     static Pattern pattern;
       
    50 
    41 
    51     public static void main(String[] args) throws Throwable {
    42     public static void main(String[] args) throws Throwable {
    52         ArrayList<String> list = new ArrayList<>();
    43         ArrayList<String> list = new ArrayList<>();
    53         findAllClasses(list);
    44         TestCommon.findAllClasses(list);
    54 
    45 
    55         CDSOptions opts = new CDSOptions();
    46         CDSOptions opts = new CDSOptions();
    56         opts.setClassList(list);
    47         opts.setClassList(list);
    57         opts.addSuffix("--add-modules");
    48         opts.addSuffix("--add-modules");
    58         opts.addSuffix("ALL-SYSTEM");
    49         opts.addSuffix("ALL-SYSTEM");
    62         opts.addSuffix("-Xlog:gc+region=trace");
    53         opts.addSuffix("-Xlog:gc+region=trace");
    63 
    54 
    64         OutputAnalyzer out = CDSTestUtils.createArchive(opts);
    55         OutputAnalyzer out = CDSTestUtils.createArchive(opts);
    65         CDSTestUtils.checkDump(out);
    56         CDSTestUtils.checkDump(out);
    66     }
    57     }
    67 
       
    68     static void findAllClasses(ArrayList<String> list) throws Throwable {
       
    69         // Find all the classes in the jrt file system
       
    70         pattern = Pattern.compile("/modules/[a-z.]*[a-z]+/([^-]*)[.]class");
       
    71         FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
       
    72         Path base = fs.getPath("/modules/");
       
    73         find(base, list);
       
    74     }
       
    75 
       
    76     static void find(Path p, ArrayList<String> list) throws Throwable {
       
    77         try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
       
    78                 for (Path entry: stream) {
       
    79                     Matcher matcher = pattern.matcher(entry.toString());
       
    80                     if (matcher.find()) {
       
    81                         String className = matcher.group(1);
       
    82                         list.add(className);
       
    83                         //System.out.println(className);
       
    84                     }
       
    85                     try {
       
    86                         find(entry, list);
       
    87                     } catch (Throwable t) {}
       
    88                 }
       
    89             }
       
    90     }
       
    91 }
    58 }