1 /* 2 * Copyright (c) 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 package compiler.valhalla.valuetypes; 26 27 import java.lang.invoke.*; 28 import java.lang.reflect.Method; 29 import java.util.Arrays; 30 31 import jdk.experimental.value.MethodHandleBuilder; 32 import jdk.test.lib.Asserts; 33 34 /* 35 * @test 36 * @summary Various tests that are specific for C1. 37 * @modules java.base/jdk.experimental.value 38 * @library /testlibrary /test/lib /compiler/whitebox / 39 * @requires os.simpleArch == "x64" 40 * @compile -XDallowWithFieldOperator TestC1.java 41 * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform 42 * @run main/othervm/timeout=300 -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions 43 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI 44 * compiler.valhalla.valuetypes.ValueTypeTest 45 * compiler.valhalla.valuetypes.TestC1 46 */ 47 public class TestC1 extends ValueTypeTest { 48 public static final int C1 = COMP_LEVEL_SIMPLE; 49 public static final int C2 = COMP_LEVEL_FULL_OPTIMIZATION; 50 51 public static void main(String[] args) throws Throwable { 52 TestC1 test = new TestC1(); 53 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, MyValue3.class, MyValue3Inline.class); 54 } 55 56 @Override 57 public int getNumScenarios() { 58 return 5; 59 } 60 61 @Override 62 public String[] getVMParameters(int scenario) { 63 switch (scenario) { 64 case 0: return new String[] { // C1 only 65 "-XX:TieredStopAtLevel=1", 66 "-XX:+TieredCompilation", 67 }; 68 case 1: return new String[] { // C2 only. (Make sure the tests are correctly written) 69 "-XX:TieredStopAtLevel=4", 70 "-XX:-TieredCompilation", 71 }; 72 case 2: return new String[] { // interpreter only 73 "-Xint", 74 }; 75 case 3: return new String[] { 76 // Xcomp Only C1. 77 "-XX:TieredStopAtLevel=1", 78 "-XX:+TieredCompilation", 79 "-Xcomp", 80 }; 81 case 4: return new String[] { 82 // Xcomp Only C2. 83 "-XX:TieredStopAtLevel=4", 84 "-XX:-TieredCompilation", 85 "-Xcomp", 86 }; 87 } 88 return null; 89 } 90 91 // JDK-8229799 92 @Test(compLevel=C1) 93 public long test1(Object a, Object b, long n) { 94 long r; 95 n += (a == b) ? 0x5678123456781234L : 0x1234567812345678L; 96 n -= 1; 97 return n; 98 } 99 100 @DontCompile 101 public void test1_verifier(boolean warmup) { 102 MyValue1 v1 = MyValue1.createWithFieldsInline(rI, rL); 103 MyValue1 v2 = MyValue1.createWithFieldsInline(rI, rL+1); 104 long r1 = test1(v1, v1, 1); 105 long r2 = test1(v1, v2, 1); 106 Asserts.assertEQ(r1, 0x5678123456781234L); 107 Asserts.assertEQ(r2, 0x1234567812345678L); 108 } 109 }