1 /*
   2  * Copyright (c) 2016, 2017, 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  * @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true)
  30  * @library /test/lib
  31  * @modules java.base/jdk.internal.misc
  32  *          java.management
  33  * @run main TestInterpreterMethodEntries
  34  */
  35 
  36 import java.lang.Math;
  37 import java.util.zip.CRC32;
  38 import java.util.zip.CRC32C;
  39 import jdk.test.lib.cds.CDSOptions;
  40 import jdk.test.lib.cds.CDSTestUtils;
  41 import jdk.test.lib.process.OutputAnalyzer;
  42 
  43 public class TestInterpreterMethodEntries {
  44 
  45     public static void main(String[] args) throws Exception {
  46         if (args.length == 0) {
  47           // Dump and use shared archive with different flag combinations
  48           dumpAndUseSharedArchive("+", "-");
  49           dumpAndUseSharedArchive("-", "+");
  50         } else {
  51           // Call intrinsified java.lang.Math::fma()
  52           Math.fma(1.0, 2.0, 3.0);
  53 
  54           byte[] buffer = new byte[256];
  55           // Call intrinsified java.util.zip.CRC32::update()
  56           CRC32 crc32 = new CRC32();
  57           crc32.update(buffer, 0, 256);
  58 
  59           // Call intrinsified java.util.zip.CRC32C::updateBytes(..)
  60           CRC32C crc32c = new CRC32C();
  61           crc32c.update(buffer, 0, 256);
  62         }
  63     }
  64 
  65     private static void dumpAndUseSharedArchive(String dump, String use) throws Exception {
  66         String unlock     = "-XX:+UnlockDiagnosticVMOptions";
  67 
  68         String dumpFMA    = "-XX:" + dump + "UseFMA";
  69         String dumpCRC32  = "-XX:" + dump + "UseCRC32Intrinsics";
  70         String dumpCRC32C = "-XX:" + dump + "UseCRC32CIntrinsics";
  71         String useFMA     = "-XX:" + use  + "UseFMA";
  72         String useCRC32   = "-XX:" + use  + "UseCRC32Intrinsics";
  73         String useCRC32C  = "-XX:" + use  + "UseCRC32CIntrinsics";
  74 
  75         CDSTestUtils.createArchiveAndCheck(unlock, dumpFMA, dumpCRC32, dumpCRC32C);
  76 
  77         CDSOptions opts = (new CDSOptions())
  78             .addPrefix(unlock, useFMA, useCRC32, useCRC32C, "-showversion")
  79             .addSuffix("TestInterpreterMethodEntries", "run")
  80             .setUseVersion(false);
  81         CDSTestUtils.runWithArchiveAndCheck(opts);
  82     }
  83 }
  84