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 * @test 26 * @bug 8209687 27 * @summary Verify that Parse::optimize_cmp_with_klass() works with value types. 28 * @library /test/lib 29 * @compile -XDemitQtypes -XDenableValueTypes TestOptimizeKlassCmp.java 30 * @run main/othervm -XX:+EnableValhalla -Xbatch 31 * compiler.valhalla.valuetypes.TestOptimizeKlassCmp 32 */ 33 34 package compiler.valhalla.valuetypes; 35 36 import jdk.test.lib.Asserts; 37 38 value class MyValue { 39 public final int x; 40 41 public MyValue(int x) { 42 this.x = x; 43 } 44 } 45 46 public class TestOptimizeKlassCmp { 47 48 public static boolean test1(MyValue v1, MyValue v2) { 49 return v1.equals(v2); 50 } 51 52 public static boolean test2(MyValue v1, MyValue v2) { 53 return v1.getClass().equals(v2.getClass()); 54 } 55 56 public static boolean test3(Object o1, Object o2) { 57 return o1.getClass().equals(o2.getClass()); 58 } 59 60 public static void main(String[] args) { 61 MyValue v1 = new MyValue(0); 62 MyValue v2 = new MyValue(1); 63 for (int i = 0; i < 10_000; ++i) { 64 Asserts.assertFalse(test1(v1, v2)); 65 Asserts.assertTrue(test1(v1, v1)); 66 Asserts.assertTrue(test2(v1, v2)); 67 Asserts.assertTrue(test2(v1, v1)); 68 Asserts.assertTrue(test3(v1, v2)); 69 Asserts.assertTrue(test3(v1, v1)); 70 } 71 } 72 }