1 /* 2 * Copyright (c) 2016, 2019, 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 the intrinsic flag enabled during dump and disabled during use of the archive. 29 * @requires vm.cds 30 * @comment the test disables intrinsics, so it can't be run w/ AOT'ed java module 31 * @requires !vm.aot.enabled 32 * @library /test/lib 33 * @modules java.base/jdk.internal.misc 34 * java.management 35 * @run driver TestInterpreterMethodEntries true false 36 */ 37 38 /** 39 * @test InterpreterMethodEntries 40 * @bug 8169711 41 * @summary Test interpreter method entries for intrinsics with CDS (class data sharing) 42 * and the intrinsic flag disabled during dump and enabled during use of the archive. 43 * @requires vm.cds 44 * @library /test/lib 45 * @modules java.base/jdk.internal.misc 46 * java.management 47 * @run driver TestInterpreterMethodEntries false true 48 */ 49 50 import java.lang.Math; 51 import java.util.zip.CRC32; 52 import java.util.zip.CRC32C; 53 import jdk.test.lib.cds.CDSOptions; 54 import jdk.test.lib.cds.CDSTestUtils; 55 import jdk.test.lib.process.OutputAnalyzer; 56 57 public class TestInterpreterMethodEntries { 58 59 public static void main(String[] args) throws Exception { 60 if (args.length > 1) { 61 boolean dump = Boolean.parseBoolean(args[0]); 62 boolean use = Boolean.parseBoolean(args[1]); 63 64 // Dump and use shared archive with different flag combinations 65 dumpAndUseSharedArchive(dump ? "+" : "-", use ? "+" : "-"); 66 } else { 67 // Call intrinsified java.lang.Math::fma() 68 Math.fma(1.0, 2.0, 3.0); 69 70 byte[] buffer = new byte[256]; 71 // Call intrinsified java.util.zip.CRC32::update() 72 CRC32 crc32 = new CRC32(); 73 crc32.update(buffer, 0, 256); 74 75 // Call intrinsified java.util.zip.CRC32C::updateBytes(..) 76 CRC32C crc32c = new CRC32C(); 77 crc32c.update(buffer, 0, 256); 78 } 79 } 80 81 private static void dumpAndUseSharedArchive(String dump, String use) throws Exception { 82 String unlock = "-XX:+UnlockDiagnosticVMOptions"; 83 84 String dumpFMA = "-XX:" + dump + "UseFMA"; 85 String dumpCRC32 = "-XX:" + dump + "UseCRC32Intrinsics"; 86 String dumpCRC32C = "-XX:" + dump + "UseCRC32CIntrinsics"; 87 String useFMA = "-XX:" + use + "UseFMA"; 88 String useCRC32 = "-XX:" + use + "UseCRC32Intrinsics"; 89 String useCRC32C = "-XX:" + use + "UseCRC32CIntrinsics"; 90 91 CDSTestUtils.createArchiveAndCheck(unlock, dumpFMA, dumpCRC32, dumpCRC32C); 92 93 CDSOptions opts = (new CDSOptions()) 94 .addPrefix(unlock, useFMA, useCRC32, useCRC32C, "-showversion") 95 .addSuffix("TestInterpreterMethodEntries", "run") 96 .setUseVersion(false); 97 CDSTestUtils.runWithArchiveAndCheck(opts); 98 } 99 } 100