hotspot/test/runtime/SharedArchiveFile/NonBootLoaderClasses.java
author ccheung
Mon, 28 Aug 2017 15:34:04 -0700
changeset 47103 a993ec29ec75
permissions -rw-r--r--
8186842: Use Java class loaders for creating the CDS archive Reviewed-by: coleenp, jiangli, iklam, mseledtsov Contributed-by: calvin.cheung@oracle.com, ioi.lam@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47103
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     1
/*
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     4
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     8
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    13
 * accompanied this code).
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    14
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    18
 *
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    21
 * questions.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    22
 */
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    23
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    24
/*
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    25
 * @test NonBootLoaderClasses
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    26
 * @summary Test to ensure platform and app classes are not being archived
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    27
 * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    28
 * @library /test/lib
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    30
 *          java.management
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    31
 * @run main NonBootLoaderClasses
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    32
 */
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    33
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    34
import jdk.test.lib.cds.CDSOptions;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    35
import jdk.test.lib.cds.CDSTestUtils;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    38
import java.io.File;
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    39
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    40
public class NonBootLoaderClasses {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    41
    public static void main(String[] args) throws Exception {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    42
        final String PLATFORM_CLASS = "jdk/dynalink/DynamicLinker";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    43
        final String APP_CLASS = "com/sun/tools/javac/Main";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    44
        String[] classes = {PLATFORM_CLASS, APP_CLASS};
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    45
        String classList =
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    46
            CDSTestUtils.makeClassList(classes).getPath();
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    47
        String archiveName = "NonBootLoaderClasses.jsa";
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    48
        CDSOptions opts = (new CDSOptions())
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    49
            .addPrefix("-XX:ExtraSharedClassListFile=" + classList)
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    50
            .setArchiveName(archiveName);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    51
        CDSTestUtils.createArchiveAndCheck(opts);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    52
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    53
        // Print the shared dictionary and inspect the output
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    54
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    55
                "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + archiveName,
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    56
                "-XX:+PrintSharedArchiveAndExit", "-XX:+PrintSharedDictionary");
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    57
        OutputAnalyzer out = CDSTestUtils.executeAndLog(pb, "print-shared-archive");
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    58
        if (!CDSTestUtils.isUnableToMap(out)) {
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    59
            out.shouldContain("archive is valid")
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    60
               .shouldHaveExitValue(0)               // Should report success in error code.
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    61
               .shouldNotContain(PLATFORM_CLASS)
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    62
               .shouldNotContain(APP_CLASS);
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    63
        }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    64
   }
a993ec29ec75 8186842: Use Java class loaders for creating the CDS archive
ccheung
parents:
diff changeset
    65
}