1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @summary Check to make sure that shared strings in the bootstrap CDS archive
  27  *          are actually shared
  28  * Feature support: G1GC only, compressed oops/kptrs, 64-bit os, not on windows
  29  * @requires (sun.arch.data.model != "32") & (os.family != "windows")
  30  * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
  31  * @requires (vm.gc=="G1" | vm.gc=="null")
  32  * @library /testlibrary /test/lib
  33  * @modules java.base/sun.misc
  34  *          java.management
  35  * @build SharedStringsWb SharedStrings BasicJarBuilder sun.hotspot.WhiteBox
  36  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  37  * @run main SharedStrings
  38  */
  39 import jdk.test.lib.*;
  40 
  41 public class SharedStrings {
  42     public static void main(String[] args) throws Exception {
  43         BasicJarBuilder.build("whitebox", "sun/hotspot/WhiteBox");
  44 
  45         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  46             "-XX:+UnlockDiagnosticVMOptions",
  47             "-XX:SharedArchiveFile=./SharedStrings.jsa",
  48             "-XX:+PrintSharedSpaces",
  49             // Needed for bootclasspath match, for CDS to work with WhiteBox API
  50             "-Xbootclasspath/a:" + BasicJarBuilder.getTestJar("whitebox.jar"),
  51             "-Xshare:dump");
  52 
  53         new OutputAnalyzer(pb.start())
  54             .shouldContain("Loading classes to share")
  55             .shouldContain("Shared string table stats")
  56             .shouldHaveExitValue(0);
  57 
  58         pb = ProcessTools.createJavaProcessBuilder(
  59             "-XX:+UnlockDiagnosticVMOptions",
  60             "-XX:SharedArchiveFile=./SharedStrings.jsa",
  61             // these are required modes for shared strings
  62             "-XX:+UseCompressedOops", "-XX:+UseG1GC",
  63             // needed for access to white box test API
  64             "-Xbootclasspath/a:" + BasicJarBuilder.getTestJar("whitebox.jar"),
  65             "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
  66             "-Xshare:on", "-showversion", "SharedStringsWb");
  67 
  68         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  69 
  70         try {
  71             output.shouldContain("sharing");
  72             output.shouldHaveExitValue(0);
  73         } catch (RuntimeException e) {
  74             output.shouldContain("Unable to use shared archive");
  75             output.shouldHaveExitValue(1);
  76         }
  77     }
  78 }