test/hotspot/jtreg/runtime/cds/appcds/TestCommon.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58528 d0519b8bd8d9
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     1
/*
53636
962ed57b29c9 8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents: 52631
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     4
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     8
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    13
 * accompanied this code).
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    14
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    18
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    21
 * questions.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    22
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    23
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    24
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    25
import jdk.test.lib.Utils;
48516
7d286141598c 8193664: AppCDS tests should use -XX:+UnlockCommercialFeatures when running with commercial JDK
iklam
parents: 48155
diff changeset
    26
import jdk.test.lib.BuildHelper;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    27
import jdk.test.lib.JDKToolFinder;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    28
import jdk.test.lib.Platform;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    29
import jdk.test.lib.cds.CDSOptions;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    30
import jdk.test.lib.cds.CDSTestUtils;
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
    31
import jdk.test.lib.cds.CDSTestUtils.Result;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    32
import jdk.test.lib.process.ProcessTools;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    33
import jdk.test.lib.process.OutputAnalyzer;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    34
import java.io.File;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    35
import java.io.FileInputStream;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    36
import java.io.FileOutputStream;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    37
import java.io.InputStream;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    38
import java.net.URI;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    39
import java.nio.file.DirectoryStream;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    40
import java.nio.file.Files;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    41
import java.nio.file.FileSystem;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    42
import java.nio.file.FileSystems;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    43
import java.nio.file.Path;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    44
import java.text.SimpleDateFormat;
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
    45
import java.util.Arrays;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    46
import java.util.ArrayList;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    47
import java.util.Date;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    48
import java.util.Enumeration;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    49
import java.util.regex.Matcher;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    50
import java.util.regex.Pattern;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    51
import java.util.zip.ZipEntry;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    52
import java.util.zip.ZipFile;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    53
import java.util.zip.ZipOutputStream;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    54
import jtreg.SkippedException;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    55
import cdsutils.DynamicDumpHelper;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    56
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    57
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    58
/**
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    59
 * This is a test utility class for common AppCDS test functionality.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    60
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    61
 * Various methods use (String ...) for passing VM options. Note that the order
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    62
 * of the VM options are important in certain cases. Many methods take arguments like
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    63
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    64
 *    (String prefix[], String suffix[], String... opts)
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    65
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    66
 * Note that the order of the VM options is:
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    67
 *
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    68
 *    prefix + opts + suffix
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    69
 */
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    70
public class TestCommon extends CDSTestUtils {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    71
    private static final String JSA_FILE_PREFIX = System.getProperty("user.dir") +
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    72
        File.separator;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    73
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    74
    private static final SimpleDateFormat timeStampFormat =
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    75
        new SimpleDateFormat("HH'h'mm'm'ss's'SSS");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    76
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    77
    private static final String timeoutFactor =
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    78
        System.getProperty("test.timeout.factor", "1.0");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    79
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    80
    private static String currentArchiveName;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    81
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    82
    // Call this method to start new archive with new unique name
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    83
    public static void startNewArchiveName() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    84
        deletePriorArchives();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    85
        currentArchiveName = getNewArchiveName();
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    86
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    87
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    88
    // Call this method to get current archive name
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    89
    public static String getCurrentArchiveName() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    90
        return currentArchiveName;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    91
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
    92
55694
7b7df2be6219 8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents: 54927
diff changeset
    93
    public static void setCurrentArchiveName(String archiveName) {
7b7df2be6219 8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents: 54927
diff changeset
    94
        currentArchiveName = archiveName;
7b7df2be6219 8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents: 54927
diff changeset
    95
    }
7b7df2be6219 8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents: 54927
diff changeset
    96
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    97
    public static String getNewArchiveName() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    98
        return getNewArchiveName(null);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
    99
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   100
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   101
    public static String getNewArchiveName(String stem) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   102
        if (stem == null) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   103
            stem = "appcds";
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   104
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   105
        return JSA_FILE_PREFIX + stem + "-" +
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   106
            timeStampFormat.format(new Date()) + ".jsa";
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   107
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   108
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   109
    // Attempt to clean old archives to preserve space
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   110
    // Archives are large artifacts (20Mb or more), and much larger than
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   111
    // most other artifacts created in jtreg testing.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   112
    // Therefore it is a good idea to clean the old archives when they are not needed.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   113
    // In most cases the deletion attempt will succeed; on rare occasion the
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   114
    // delete operation will fail since the system or VM process still holds a handle
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   115
    // to the file; in such cases the File.delete() operation will silently fail, w/o
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   116
    // throwing an exception, thus allowing testing to continue.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   117
    public static void deletePriorArchives() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   118
        File dir = new File(System.getProperty("user.dir"));
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   119
        String files[] = dir.list();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   120
        for (String name : files) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   121
            if (name.startsWith("appcds-") && name.endsWith(".jsa")) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   122
                if (!(new File(dir, name)).delete())
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   123
                    System.out.println("deletePriorArchives(): delete failed for file " + name);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   124
            }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   125
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   126
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   127
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   128
    // Create AppCDS archive using most common args - convenience method
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   129
    // Legacy name preserved for compatibility
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   130
    public static OutputAnalyzer dump(String appJar, String classList[],
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   131
                                               String... suffix) throws Exception {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   132
        return createArchive(appJar, classList, suffix);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   133
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   134
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   135
    public static OutputAnalyzer dump(String appJarDir, String appJar, String classList[],
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   136
                                               String... suffix) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   137
        return createArchive(appJarDir, appJar, classList, suffix);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   138
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   139
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   140
    // Create AppCDS archive using most common args - convenience method
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   141
    public static OutputAnalyzer createArchive(String appJar, String classList[],
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   142
                                               String... suffix) throws Exception {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   143
        AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   144
        opts.setClassList(classList);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   145
        opts.addSuffix(suffix);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   146
        return createArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   147
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   148
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   149
    public static OutputAnalyzer createArchive(String appJarDir, String appJar, String classList[],
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   150
                                               String... suffix) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   151
        AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   152
        opts.setAppJarDir(appJarDir);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   153
        opts.setClassList(classList);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   154
        opts.addSuffix(suffix);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   155
        return createArchive(opts);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   156
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   157
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   158
    // Simulate -Xshare:dump with -XX:ArchiveClassesAtExit. See comments around patchJarForDynamicDump()
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   159
    private static final Class tmp = DynamicDumpHelper.class;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   160
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   161
    // Create AppCDS archive using appcds options
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   162
    public static OutputAnalyzer createArchive(AppCDSOptions opts)
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   163
        throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   164
        ArrayList<String> cmd = new ArrayList<String>();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   165
        startNewArchiveName();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   166
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   167
        for (String p : opts.prefix) cmd.add(p);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   168
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   169
        if (opts.appJar != null) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   170
            cmd.add("-cp");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   171
            cmd.add(opts.appJar);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   172
            File jf = new File(opts.appJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   173
            if (DYNAMIC_DUMP && !jf.isDirectory()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   174
                patchJarForDynamicDump(opts.appJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   175
            }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   176
        } else {
53636
962ed57b29c9 8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents: 52631
diff changeset
   177
            cmd.add("-Djava.class.path=");
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   178
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   179
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   180
        if (opts.archiveName == null) {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   181
            opts.archiveName = getCurrentArchiveName();
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   182
        }
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   183
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   184
        if (DYNAMIC_DUMP) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   185
            cmd.add("-Xshare:on");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   186
            cmd.add("-XX:ArchiveClassesAtExit=" + opts.archiveName);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   187
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   188
            cmd.add("-Xlog:cds");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   189
            cmd.add("-Xlog:cds+dynamic");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   190
            boolean mainModuleSpecified = false;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   191
            boolean patchModuleSpecified = false;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   192
            for (String s : opts.suffix) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   193
                if (s.length() == 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   194
                    continue;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   195
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   196
                if (s.equals("-m")) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   197
                    mainModuleSpecified = true;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   198
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   199
                if (s.startsWith("--patch-module=")) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   200
                    patchModuleSpecified = true;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   201
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   202
                cmd.add(s);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   203
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   204
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   205
            if (opts.appJar != null) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   206
                // classlist is supported only when we have a Jar file to patch (to insert
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   207
                // cdsutils.DynamicDumpHelper)
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   208
                if (opts.classList == null) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   209
                    throw new RuntimeException("test.dynamic.dump requires classList file");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   210
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   211
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   212
                if (!mainModuleSpecified && !patchModuleSpecified) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   213
                    cmd.add("cdsutils.DynamicDumpHelper");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   214
                    File classListFile = makeClassList(opts.classList);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   215
                    cmd.add(classListFile.getPath());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   216
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   217
            } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   218
                if (!mainModuleSpecified && !patchModuleSpecified) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   219
                    // If you have an empty classpath, you cannot specify a classlist!
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   220
                    if (opts.classList != null && opts.classList.length > 0) {
58300
c3b93d6603f5 8231367: [TESTBUG] ParallelLoadTest.java fails with "test.dynamic.dump not supported"
iklam
parents: 57567
diff changeset
   221
                        throw new RuntimeException("test.dynamic.dump is not supported with an empty classpath while the classlist is not empty");
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   222
                    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   223
                    cmd.add("-version");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   224
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   225
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   226
        } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   227
            // static dump
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   228
            cmd.add("-Xshare:dump");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   229
            cmd.add("-XX:SharedArchiveFile=" + opts.archiveName);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   230
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   231
            if (opts.classList != null) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   232
                File classListFile = makeClassList(opts.classList);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   233
                cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   234
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   235
            for (String s : opts.suffix) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   236
                cmd.add(s);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   237
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   238
        }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   239
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   240
        String[] cmdLine = cmd.toArray(new String[cmd.size()]);
51894
1e7353bd1499 8202282: [TESTBUG] appcds TestCommon.makeCommandLineForAppCDS() can be removed
ccheung
parents: 51370
diff changeset
   241
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   242
        if (opts.appJarDir != null) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   243
            pb.directory(new File(opts.appJarDir));
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   244
        }
58310
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   245
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   246
        OutputAnalyzer output = executeAndLog(pb, "dump");
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   247
        if (DYNAMIC_DUMP && isUnableToMap(output)) {
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   248
            throw new SkippedException(UnableToMapMsg);
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   249
        }
81134def991d 8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents: 58300
diff changeset
   250
        return output;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   251
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   252
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   253
    // This allows you to run the AppCDS tests with JFR enabled at runtime (though not at
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   254
    // dump time, as that's uncommon for typical AppCDS users).
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   255
    //
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   256
    // To run in this special mode, add the following to your jtreg command-line
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   257
    //    -Dtest.cds.run.with.jfr=true
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   258
    //
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   259
    // Some AppCDS tests are not compatible with this mode. See the group
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   260
    // hotspot_appcds_with_jfr in ../../TEST.ROOT for details.
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   261
    private static final boolean RUN_WITH_JFR = Boolean.getBoolean("test.cds.run.with.jfr");
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   262
    // This method simulates -Xshare:dump with -XX:ArchiveClassesAtExit. This way, we
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   263
    // can re-use many tests (outside of the ./dynamicArchive directory) for testing
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   264
    // general features of JDK-8215311 (JEP 350: Dynamic CDS Archives).
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   265
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   266
    // We insert the cdsutils/DynamicDumpHelper.class into the first Jar file in
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   267
    // the classpath. We use this class to load all the classes specified in the classlist.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   268
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   269
    // There's no need to change the run-time command-line: in this special mode, two
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   270
    // archives are involved. The command-line specifies only the top archive. However,
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   271
    // the location of the base archive is recorded in the top archive, so it can be
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   272
    // determined by the JVM at runtime start-up.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   273
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   274
    // To run in this special mode, specify the following in your jtreg command-line
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   275
    //    -Dtest.dynamic.cds.archive=true
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   276
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   277
    // Note that some tests are not compatible with this special mode, including
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   278
    //    + Tests in ./dynamicArchive: these tests are specifically written for
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   279
    //      dynamic archive, and do not use TestCommon.createArchive(), which works
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   280
    //      together with patchJarForDynamicDump().
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   281
    //    + Tests related to cached objects and shared strings: dynamic dumping
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   282
    //      does not support these.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   283
    //    + Custom loader tests: DynamicDumpHelper doesn't support the required
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   284
    //      classlist syntax. (FIXME).
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   285
    //    + Extra symbols and extra strings.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   286
    // See the hotspot_appcds_dynamic in ../../TEST.ROOT for details.
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   287
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   288
    // To run all tests that are compatible with this mode:
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   289
    //    cd test/hotspot/jtreg
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   290
    //    jtreg -Dtest.dynamic.cds.archive=true :hotspot_appcds_dynamic
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   291
    //
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   292
    private static void patchJarForDynamicDump(String cp) throws Exception {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   293
        System.out.println("patchJarForDynamicDump: classpath = " + cp);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   294
        String firstJar = cp;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   295
        int n = firstJar.indexOf(File.pathSeparator);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   296
        if (n > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   297
            firstJar = firstJar.substring(0, n);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   298
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   299
        String classDir = System.getProperty("test.classes");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   300
        String expected1 = classDir + File.separator;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   301
        String expected2 = System.getProperty("user.dir") + File.separator;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   302
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   303
        if (!firstJar.startsWith(expected1) && !firstJar.startsWith(expected2)) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   304
            throw new RuntimeException("FIXME: jar file not at a supported location ('"
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   305
                                       + expected1 + "', or '" + expected2 + "'): " + firstJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   306
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   307
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   308
        String replaceJar = firstJar + ".tmp";
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   309
        String patchClass = "cdsutils/DynamicDumpHelper.class";
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   310
        ZipFile zipFile = new ZipFile(firstJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   311
        byte[] buf = new byte[1024];
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   312
        int len;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   313
        if (zipFile.getEntry(patchClass) == null) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   314
            FileOutputStream fout = new FileOutputStream(replaceJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   315
            final ZipOutputStream zos = new ZipOutputStream(fout);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   316
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   317
            zos.putNextEntry(new ZipEntry(patchClass));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   318
            InputStream is = new FileInputStream(classDir + File.separator + patchClass);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   319
            while ((len = (is.read(buf))) > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   320
                zos.write(buf, 0, len);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   321
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   322
            zos.closeEntry();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   323
            is.close();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   324
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   325
            for (Enumeration e = zipFile.entries(); e.hasMoreElements(); ) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   326
                ZipEntry entryIn = (ZipEntry) e.nextElement();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   327
                zos.putNextEntry(entryIn);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   328
                is = zipFile.getInputStream(entryIn);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   329
                while ((len = is.read(buf)) > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   330
                    zos.write(buf, 0, len);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   331
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   332
                zos.closeEntry();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   333
                is.close();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   334
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   335
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   336
            zos.close();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   337
            fout.close();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   338
            zipFile.close();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   339
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   340
            File oldFile = new File(firstJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   341
            File newFile = new File(replaceJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   342
            oldFile.delete();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   343
            newFile.renameTo(oldFile);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   344
            System.out.println("firstJar = " + firstJar + " Modified");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   345
        } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   346
            System.out.println("firstJar = " + firstJar);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   347
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   348
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   349
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   350
    // Execute JVM using AppCDS archive with specified AppCDSOptions
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   351
    public static OutputAnalyzer runWithArchive(AppCDSOptions opts)
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   352
        throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   353
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   354
        ArrayList<String> cmd = new ArrayList<String>();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   355
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   356
        for (String p : opts.prefix) cmd.add(p);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   357
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   358
        cmd.add("-Xshare:" + opts.xShareMode);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   359
        cmd.add("-showversion");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   360
        cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   361
        cmd.add("-Dtest.timeout.factor=" + timeoutFactor);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   362
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   363
        if (opts.appJar != null) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   364
            cmd.add("-cp");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   365
            cmd.add(opts.appJar);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   366
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   367
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   368
        for (String s : opts.suffix) cmd.add(s);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   369
54340
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   370
        if (RUN_WITH_JFR) {
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   371
            boolean usesJFR = false;
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   372
            for (String s : cmd) {
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   373
                if (s.startsWith("-XX:StartFlightRecording=") || s.startsWith("-XX:FlightRecorderOptions")) {
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   374
                    System.out.println("JFR option might have been specified. Don't interfere: " + s);
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   375
                    usesJFR = true;
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   376
                    break;
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   377
                }
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   378
            }
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   379
            if (!usesJFR) {
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   380
                System.out.println("JFR option not specified. Enabling JFR ...");
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   381
                cmd.add(0, "-XX:StartFlightRecording=dumponexit=true");
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   382
                System.out.println(cmd);
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   383
            }
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   384
        }
2221f042556d 8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents: 53636
diff changeset
   385
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   386
        String[] cmdLine = cmd.toArray(new String[cmd.size()]);
51894
1e7353bd1499 8202282: [TESTBUG] appcds TestCommon.makeCommandLineForAppCDS() can be removed
ccheung
parents: 51370
diff changeset
   387
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine);
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   388
        if (opts.appJarDir != null) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   389
            pb.directory(new File(opts.appJarDir));
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   390
        }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   391
        return executeAndLog(pb, "exec");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   392
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   393
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   394
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   395
    public static OutputAnalyzer execCommon(String... suffix) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   396
        AppCDSOptions opts = (new AppCDSOptions());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   397
        opts.addSuffix(suffix);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   398
        return runWithArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   399
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   400
48979
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   401
    // This is the new API for running a Java process with CDS enabled.
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   402
    // See comments in the CDSTestUtils.Result class for how to use this method.
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   403
    public static Result run(String... suffix) throws Exception {
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   404
        AppCDSOptions opts = (new AppCDSOptions());
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   405
        opts.addSuffix(suffix);
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   406
        return new Result(opts, runWithArchive(opts));
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   407
    }
514c73a1955b 8179249: Improve process output analysis in CDS tests
iklam
parents: 48516
diff changeset
   408
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   409
    public static Result runWithRelativePath(String jarDir, String... suffix) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   410
        AppCDSOptions opts = (new AppCDSOptions());
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   411
        opts.setAppJarDir(jarDir);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   412
        opts.addSuffix(suffix);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   413
        return new Result(opts, runWithArchive(opts));
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   414
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   415
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   416
    public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   417
        AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   418
        opts.addSuffix(suffix);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   419
        return runWithArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   420
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   421
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   422
    public static Result runWithModules(String prefix[], String upgrademodulepath, String modulepath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   423
                                            String mid, String... testClassArgs) throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   424
        AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   425
                                               mid, testClassArgs);
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   426
        return new Result(opts, runWithArchive(opts));
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   427
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   428
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   429
    public static OutputAnalyzer execAuto(String... suffix) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   430
        AppCDSOptions opts = (new AppCDSOptions());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   431
        opts.addSuffix(suffix).setXShareMode("auto");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   432
        return runWithArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   433
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   434
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   435
    public static OutputAnalyzer execOff(String... suffix) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   436
        AppCDSOptions opts = (new AppCDSOptions());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   437
        opts.addSuffix(suffix).setXShareMode("off");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   438
        return runWithArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   439
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   440
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   441
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   442
    private static AppCDSOptions makeModuleOptions(String prefix[], String upgrademodulepath, String modulepath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   443
                                            String mid, String testClassArgs[]) {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   444
        AppCDSOptions opts = (new AppCDSOptions());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   445
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   446
        opts.addPrefix(prefix);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   447
        if (upgrademodulepath == null) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   448
            opts.addSuffix("-p", modulepath, "-m", mid);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   449
        } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   450
            opts.addSuffix("--upgrade-module-path", upgrademodulepath,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   451
                           "-p", modulepath, "-m", mid);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   452
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   453
        opts.addSuffix(testClassArgs);
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   454
        return opts;
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   455
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   456
49739
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   457
    public static OutputAnalyzer execModule(String prefix[], String upgrademodulepath, String modulepath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   458
                                            String mid, String... testClassArgs)
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   459
        throws Exception {
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   460
        AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath,
00805b129186 8194812: Extend class-data sharing to support the module path
ccheung
parents: 48979
diff changeset
   461
                                               mid, testClassArgs);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   462
        return runWithArchive(opts);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   463
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   464
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   465
    // A common operation: dump, then check results
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   466
    public static OutputAnalyzer testDump(String appJar, String classList[],
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   467
                                          String... suffix) throws Exception {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   468
        OutputAnalyzer output = dump(appJar, classList, suffix);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   469
        if (DYNAMIC_DUMP) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   470
            output.shouldContain("Written dynamic archive");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   471
        } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   472
            output.shouldContain("Loading classes to share");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   473
        }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   474
        output.shouldHaveExitValue(0);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   475
        return output;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   476
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   477
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   478
    public static OutputAnalyzer testDump(String appJarDir, String appJar, String classList[],
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   479
                                          String... suffix) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   480
        OutputAnalyzer output = dump(appJarDir, appJar, classList, suffix);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   481
        if (DYNAMIC_DUMP) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   482
            output.shouldContain("Written dynamic archive");
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   483
        } else {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   484
            output.shouldContain("Loading classes to share");
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   485
        }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   486
        output.shouldHaveExitValue(0);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   487
        return output;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   488
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   489
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   490
    /**
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   491
     * Simple test -- dump and execute appJar with the given classList in classlist.
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   492
     */
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   493
    public static OutputAnalyzer test(String appJar, String classList[], String... args)
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   494
        throws Exception {
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 51894
diff changeset
   495
        testDump(appJar, classList);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   496
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   497
        OutputAnalyzer output = exec(appJar, args);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   498
        return checkExec(output);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   499
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   500
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   501
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   502
    public static OutputAnalyzer checkExecReturn(OutputAnalyzer output, int ret,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   503
                           boolean checkContain, String... matches) throws Exception {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   504
        try {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   505
            for (String s : matches) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   506
                if (checkContain) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   507
                    output.shouldContain(s);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   508
                } else {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   509
                    output.shouldNotContain(s);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   510
                }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   511
            }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   512
            output.shouldHaveExitValue(ret);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   513
        } catch (Exception e) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   514
            checkCommonExecExceptions(output, e);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   515
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   516
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   517
        return output;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   518
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   519
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   520
    // Convenience concatenation utils
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   521
    public static String[] list(String ...args) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   522
        return args;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   523
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   524
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   525
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   526
    public static String[] list(String arg, int count) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   527
        ArrayList<String> stringList = new ArrayList<String>();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   528
        for (int i = 0; i < count; i++) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   529
            stringList.add(arg);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   530
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   531
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   532
        String outputArray[] = stringList.toArray(new String[stringList.size()]);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   533
        return outputArray;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   534
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   535
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   536
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   537
    public static String[] concat(String... args) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   538
        return list(args);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   539
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   540
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   541
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   542
    public static String[] concat(String prefix[], String... extra) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   543
        ArrayList<String> list = new ArrayList<String>();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   544
        for (String s : prefix) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   545
            list.add(s);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   546
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   547
        for (String s : extra) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   548
            list.add(s);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   549
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   550
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   551
        return list.toArray(new String[list.size()]);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   552
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   553
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   554
    public static String[] concat(String prefix, String[] extra) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   555
        ArrayList<String> list = new ArrayList<String>();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   556
        list.add(prefix);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   557
        for (String s : extra) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   558
            list.add(s);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   559
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   560
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   561
        return list.toArray(new String[list.size()]);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   562
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   563
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   564
    // ===================== Concatenate paths
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   565
    public static String concatPaths(String... paths) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   566
        String prefix = "";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   567
        String s = "";
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   568
        for (String p : paths) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   569
            s += prefix;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   570
            s += p;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   571
            prefix = File.pathSeparator;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   572
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   573
        return s;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   574
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   575
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   576
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   577
    public static String getTestJar(String jar) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   578
        File jarFile = CDSTestUtils.getTestArtifact(jar, true);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   579
        if (!jarFile.isFile()) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   580
            throw new RuntimeException("Not a regular file: " + jarFile.getPath());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   581
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   582
        return jarFile.getPath();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   583
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   584
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   585
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   586
    public static String getTestDir(String d) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   587
        File dirFile = CDSTestUtils.getTestArtifact(d, true);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   588
        if (!dirFile.isDirectory()) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   589
            throw new RuntimeException("Not a directory: " + dirFile.getPath());
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   590
        }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   591
        return dirFile.getPath();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   592
    }
50951
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   593
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   594
    public static boolean checkOutputStrings(String outputString1,
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   595
                                             String outputString2,
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   596
                                             String split_regex) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   597
        String[] sa1 = outputString1.split(split_regex);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   598
        String[] sa2 = outputString2.split(split_regex);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   599
        Arrays.sort(sa1);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   600
        Arrays.sort(sa2);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   601
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   602
        int i = 0;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   603
        for (String s : sa1) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   604
            if (!s.equals(sa2[i])) {
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   605
                throw new RuntimeException(s + " is different from " + sa2[i]);
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   606
            }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   607
            i ++;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   608
        }
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   609
        return true;
b96466cdfc45 8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents: 49931
diff changeset
   610
    }
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   611
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   612
    static Pattern pattern;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   613
58528
d0519b8bd8d9 8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents: 58310
diff changeset
   614
    static void findAllClasses(ArrayList<String> list) throws Exception {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   615
        // Find all the classes in the jrt file system
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   616
        pattern = Pattern.compile("/modules/[a-z.]*[a-z]+/([^-]*)[.]class");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   617
        FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   618
        Path base = fs.getPath("/modules/");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   619
        findAllClassesAtPath(base, list);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   620
    }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   621
58528
d0519b8bd8d9 8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents: 58310
diff changeset
   622
    private static void findAllClassesAtPath(Path p, ArrayList<String> list) throws Exception {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   623
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   624
            for (Path entry: stream) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   625
                Matcher matcher = pattern.matcher(entry.toString());
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   626
                if (matcher.find()) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   627
                    String className = matcher.group(1);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   628
                    list.add(className);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   629
                }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   630
                try {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   631
                    findAllClassesAtPath(entry, list);
58528
d0519b8bd8d9 8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents: 58310
diff changeset
   632
                } catch (Exception ex) {}
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   633
            }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   634
        }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54340
diff changeset
   635
    }
55524
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   636
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   637
    public static String composeRelPath(String appJar) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   638
         int idx = appJar.lastIndexOf(File.separator);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   639
         String jarName = appJar.substring(idx + 1);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   640
         String jarDir = appJar.substring(0, idx);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   641
         String lastDir = jarDir.substring(jarDir.lastIndexOf(File.separator));
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   642
         String relPath = jarDir + File.separator + ".." + File.separator + lastDir;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   643
         String newJar = relPath + File.separator + jarName;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   644
         return newJar;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   645
    }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   646
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   647
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   648
    public static File createSymLink(String appJar) throws Exception {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   649
         int idx = appJar.lastIndexOf(File.separator);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   650
         String jarName = appJar.substring(idx + 1);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   651
         String jarDir = appJar.substring(0, idx);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   652
         File origJar = new File(jarDir, jarName);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   653
         String linkedJarName = "linked_" + jarName;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   654
         File linkedJar = null;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   655
         if (!Platform.isWindows()) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   656
             linkedJar = new File(jarDir, linkedJarName);
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   657
             if (linkedJar.exists()) {
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   658
                 linkedJar.delete();
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   659
             }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   660
             Files.createSymbolicLink(linkedJar.toPath(), origJar.toPath());
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   661
         }
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   662
         return linkedJar;
b279ae9843b8 8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents: 54927
diff changeset
   663
    }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents:
diff changeset
   664
}