1 /*
   2  * Copyright (c) 2016, 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 InterpreterMethodEntries
  26  * @bug 8169711
  27  * @summary Test interpreter method entries for intrinsics with CDS (class data sharing)
  28  *          and different settings of the intrinsic flag during dump/use of the archive.
  29  * @library /test/lib
  30  * @modules java.base/jdk.internal.misc
  31  *          java.management
  32  * @run main TestInterpreterMethodEntries
  33  */
  34 
  35 import java.lang.Math;
  36 import java.util.zip.CRC32;
  37 import java.util.zip.CRC32C;
  38 import jdk.test.lib.process.ProcessTools;
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 
  41 public class TestInterpreterMethodEntries {
  42 
  43     public static void main(String[] args) throws Exception {
  44         if (args.length == 0) {
  45           // Dump and use shared archive with different flag combinations
  46           dumpAndUseSharedArchive("+", "-");
  47           dumpAndUseSharedArchive("-", "+");
  48         } else {
  49           // Call intrinsified java.lang.Math::fma()
  50           Math.fma(1.0, 2.0, 3.0);
  51 
  52           byte[] buffer = new byte[256];
  53           // Call intrinsified java.util.zip.CRC32::update()
  54           CRC32 crc32 = new CRC32();
  55           crc32.update(buffer, 0, 256);
  56 
  57           // Call intrinsified java.util.zip.CRC32C::updateBytes(..)
  58           CRC32C crc32c = new CRC32C();
  59           crc32c.update(buffer, 0, 256);
  60         }
  61     }
  62 
  63     private static void dumpAndUseSharedArchive(String dump, String use) throws Exception {
  64         String dumpFMA    = "-XX:" + dump + "UseFMA";
  65         String dumpCRC32  = "-XX:" + dump + "UseCRC32Intrinsics";
  66         String dumpCRC32C = "-XX:" + dump + "UseCRC32CIntrinsics";
  67         String useFMA     = "-XX:" + use  + "UseFMA";
  68         String useCRC32   = "-XX:" + use  + "UseCRC32Intrinsics";
  69         String useCRC32C  = "-XX:" + use  + "UseCRC32CIntrinsics";
  70 
  71         // Dump shared archive
  72         String filename = "./TestInterpreterMethodEntries" + dump + ".jsa";
  73         ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
  74             "-XX:+UnlockDiagnosticVMOptions",
  75             "-XX:SharedArchiveFile=" + filename,
  76             "-Xshare:dump",
  77             dumpFMA, dumpCRC32, dumpCRC32C);
  78         OutputAnalyzer output = new OutputAnalyzer(pb.start());
  79         CDSTestUtils.checkDump(output);
  80 
  81         // Use shared archive
  82         pb = ProcessTools.createJavaProcessBuilder(
  83             "-XX:+UnlockDiagnosticVMOptions",
  84             "-XX:SharedArchiveFile=" + filename,
  85             "-Xshare:on",
  86             useFMA, useCRC32, useCRC32C,
  87             "TestInterpreterMethodEntries", "run");
  88         output = new OutputAnalyzer(pb.start());
  89         if (CDSTestUtils.isUnableToMap(output)) {
  90           System.out.println("Unable to map shared archive: test did not complete; assumed PASS");
  91           return;
  92         }
  93         output.shouldHaveExitValue(0);
  94     }
  95 }
  96