< prev index next >

test/hotspot/jtreg/compiler/valhalla/valuetypes/TestNewAcmp.java

Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd


  21  * questions.
  22  */
  23 
  24 /**
  25  * @test TestNewAcmp
  26  * @summary Verifies correctness of the new acmp bytecode.
  27  * @library /testlibrary /test/lib /compiler/whitebox /
  28  * @compile TestNewAcmp.java
  29  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  30  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  31  *             compiler.valhalla.valuetypes.TestNewAcmp
  32  */
  33 
  34 package compiler.valhalla.valuetypes;
  35 
  36 import jdk.test.lib.Asserts;
  37 import jdk.test.lib.process.ProcessTools;
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 import java.lang.annotation.Retention;
  40 import java.lang.annotation.RetentionPolicy;
  41 import java.lang.invoke.*;
  42 import java.lang.reflect.Method;
  43 import java.util.regex.Pattern;
  44 import java.util.regex.Matcher;
  45 import java.util.ArrayList;
  46 import java.util.Arrays;
  47 import java.util.List;
  48 import sun.hotspot.WhiteBox;
  49 
  50 
  51 interface MyInterface {
  52 
  53 }
  54 
  55 inline class MyValue1 implements MyInterface {
  56     final int x;
  57 
  58     MyValue1(int x) {
  59         this.x = x;
  60     }
  61 
  62     static MyValue1 createDefault() {
  63         return MyValue1.default;
  64     }


1386 
1387     public boolean cmpSometimesEqual2(Object a) {
1388         return a != a;
1389     }
1390 
1391     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1392     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
1393     protected static final long ACmpOnValues = (Long)WHITE_BOX.getVMFlag("ACmpOnValues");
1394 
1395     public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception {
1396         Class<?>[] parameterTypes = m.getParameterTypes();
1397         int parameterCount = parameterTypes.length;
1398         // Nullness mode for first argument
1399         // 0: default, 1: never null, 2: always null
1400         int start = (nullMode != 1) ? 0 : 1;
1401         int end = (nullMode != 2) ? args.length : 1;
1402         for (int i = start; i < end; ++i) {
1403             if (args[i] != null && !parameterTypes[0].isInstance(args[i])) {
1404                 continue;
1405             }
1406             if (args[i] == null && parameterTypes[0] == MyValue1.class.asValueType()) {
1407                 continue;
1408             }
1409             if (parameterCount == 1) {
1410                 // Null checks
1411                 System.out.print("Testing " + m.getName() + "(" + args[i] + ")");
1412                 // Avoid acmp in the computation of the expected result!
1413                 boolean expected = isNegated(m) ? (i != 0) : (i == 0);
1414                 for (int run = 0; run < warmup; ++run) {
1415                     Boolean result = (Boolean)m.invoke(this, args[i]);
1416                     if (result != expected && WHITE_BOX.isMethodCompiled(m, false)) {
1417                         System.out.println(" = " + result);
1418                         throw new RuntimeException("Test failed: should return " + expected);
1419                     }
1420                 }
1421                 System.out.println(" = " + expected);
1422             } else {
1423                 // Equality checks
1424                 for (int j = 0; j < args.length; ++j) {
1425                     if (args[j] != null && !parameterTypes[1].isInstance(args[j])) {
1426                         continue;
1427                     }
1428                     if (args[j] == null && parameterTypes[1] == MyValue1.class.asValueType()) {
1429                         continue;
1430                     }
1431                     System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")");
1432                     // Avoid acmp in the computation of the expected result!
1433                     boolean equal = equalities[i][j];
1434                     equal = isNegated(m) ? !equal : equal;
1435                     boolean expected = alwaysTrue(m) || ((i == 0 || j == 0) && trueIfNull(m)) || (!alwaysFalse(m) && equal && !(i == 0 && falseIfNull(m)));
1436                     for (int run = 0; run < warmup; ++run) {
1437                         Boolean result = (Boolean)m.invoke(this, args[i], args[j]);
1438                         if (result != expected && WHITE_BOX.isMethodCompiled(m, false) && warmup == 1) {
1439                             System.out.println(" = " + result);
1440                             throw new RuntimeException("Test failed: should return " + expected);
1441                         }
1442                     }
1443                     System.out.println(" = " + expected);
1444                 }
1445             }
1446         }
1447     }
1448 


1496             Asserts.assertTrue(cmpAlwaysUnEqual2(args[1], args[2]));
1497             boolean compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual3_m, false);
1498             boolean res = cmpAlwaysUnEqual3(args[3]);
1499             if (ACmpOnValues != 3) {
1500                 Asserts.assertFalse(res);
1501             } else if (compiled) {
1502                 Asserts.assertTrue(res);
1503             }
1504             compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual4_m, false);
1505             res = cmpAlwaysUnEqual4(args[3]);
1506             if (ACmpOnValues != 3) {
1507                 Asserts.assertTrue(res);
1508             } else if (compiled) {
1509                 Asserts.assertFalse(res);
1510             }
1511 
1512             int idx = i % args.length;
1513             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual1_m, false);
1514             res = cmpSometimesEqual1(args[idx]);
1515             if (ACmpOnValues != 3) {
1516                 Asserts.assertEQ(res, args[idx] == null || !args[idx].getClass().isValue());
1517             } else if (compiled) {
1518                 Asserts.assertTrue(res);
1519             }
1520             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual2_m, false);
1521             res = cmpSometimesEqual2(args[idx]);
1522             if (ACmpOnValues != 3) {
1523                 Asserts.assertNE(res, args[idx] == null || !args[idx].getClass().isValue());
1524             } else if (compiled) {
1525                 Asserts.assertFalse(res);
1526             }
1527         }
1528     }
1529 
1530     public static void main(String[] args) throws Exception {
1531         if (Boolean.getBoolean("test.c1")) {
1532             System.out.println("new acmp is not implemented for C1"); // TMP
1533             return;
1534         }
1535 
1536         if (args.length == 0) {
1537             enumerateVMOptions();
1538         } else {
1539             int nullMode = Integer.valueOf(args[0]);
1540             TestNewAcmp t = new TestNewAcmp();
1541             t.run(nullMode);
1542         }
1543     }




  21  * questions.
  22  */
  23 
  24 /**
  25  * @test TestNewAcmp
  26  * @summary Verifies correctness of the new acmp bytecode.
  27  * @library /testlibrary /test/lib /compiler/whitebox /
  28  * @compile TestNewAcmp.java
  29  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  30  * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  31  *             compiler.valhalla.valuetypes.TestNewAcmp
  32  */
  33 
  34 package compiler.valhalla.valuetypes;
  35 
  36 import jdk.test.lib.Asserts;
  37 import jdk.test.lib.process.ProcessTools;
  38 import jdk.test.lib.process.OutputAnalyzer;
  39 import java.lang.annotation.Retention;
  40 import java.lang.annotation.RetentionPolicy;

  41 import java.lang.reflect.Method;


  42 import java.util.ArrayList;
  43 import java.util.Arrays;
  44 import java.util.List;
  45 import sun.hotspot.WhiteBox;
  46 
  47 
  48 interface MyInterface {
  49 
  50 }
  51 
  52 inline class MyValue1 implements MyInterface {
  53     final int x;
  54 
  55     MyValue1(int x) {
  56         this.x = x;
  57     }
  58 
  59     static MyValue1 createDefault() {
  60         return MyValue1.default;
  61     }


1383 
1384     public boolean cmpSometimesEqual2(Object a) {
1385         return a != a;
1386     }
1387 
1388     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1389     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4;
1390     protected static final long ACmpOnValues = (Long)WHITE_BOX.getVMFlag("ACmpOnValues");
1391 
1392     public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception {
1393         Class<?>[] parameterTypes = m.getParameterTypes();
1394         int parameterCount = parameterTypes.length;
1395         // Nullness mode for first argument
1396         // 0: default, 1: never null, 2: always null
1397         int start = (nullMode != 1) ? 0 : 1;
1398         int end = (nullMode != 2) ? args.length : 1;
1399         for (int i = start; i < end; ++i) {
1400             if (args[i] != null && !parameterTypes[0].isInstance(args[i])) {
1401                 continue;
1402             }
1403             if (args[i] == null && parameterTypes[0] == MyValue1.class.asPrimaryType()) {
1404                 continue;
1405             }
1406             if (parameterCount == 1) {
1407                 // Null checks
1408                 System.out.print("Testing " + m.getName() + "(" + args[i] + ")");
1409                 // Avoid acmp in the computation of the expected result!
1410                 boolean expected = isNegated(m) ? (i != 0) : (i == 0);
1411                 for (int run = 0; run < warmup; ++run) {
1412                     Boolean result = (Boolean)m.invoke(this, args[i]);
1413                     if (result != expected && WHITE_BOX.isMethodCompiled(m, false)) {
1414                         System.out.println(" = " + result);
1415                         throw new RuntimeException("Test failed: should return " + expected);
1416                     }
1417                 }
1418                 System.out.println(" = " + expected);
1419             } else {
1420                 // Equality checks
1421                 for (int j = 0; j < args.length; ++j) {
1422                     if (args[j] != null && !parameterTypes[1].isInstance(args[j])) {
1423                         continue;
1424                     }
1425                     if (args[j] == null && parameterTypes[1] == MyValue1.class.asPrimaryType()) {
1426                         continue;
1427                     }
1428                     System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")");
1429                     // Avoid acmp in the computation of the expected result!
1430                     boolean equal = equalities[i][j];
1431                     equal = isNegated(m) ? !equal : equal;
1432                     boolean expected = alwaysTrue(m) || ((i == 0 || j == 0) && trueIfNull(m)) || (!alwaysFalse(m) && equal && !(i == 0 && falseIfNull(m)));
1433                     for (int run = 0; run < warmup; ++run) {
1434                         Boolean result = (Boolean)m.invoke(this, args[i], args[j]);
1435                         if (result != expected && WHITE_BOX.isMethodCompiled(m, false) && warmup == 1) {
1436                             System.out.println(" = " + result);
1437                             throw new RuntimeException("Test failed: should return " + expected);
1438                         }
1439                     }
1440                     System.out.println(" = " + expected);
1441                 }
1442             }
1443         }
1444     }
1445 


1493             Asserts.assertTrue(cmpAlwaysUnEqual2(args[1], args[2]));
1494             boolean compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual3_m, false);
1495             boolean res = cmpAlwaysUnEqual3(args[3]);
1496             if (ACmpOnValues != 3) {
1497                 Asserts.assertFalse(res);
1498             } else if (compiled) {
1499                 Asserts.assertTrue(res);
1500             }
1501             compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual4_m, false);
1502             res = cmpAlwaysUnEqual4(args[3]);
1503             if (ACmpOnValues != 3) {
1504                 Asserts.assertTrue(res);
1505             } else if (compiled) {
1506                 Asserts.assertFalse(res);
1507             }
1508 
1509             int idx = i % args.length;
1510             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual1_m, false);
1511             res = cmpSometimesEqual1(args[idx]);
1512             if (ACmpOnValues != 3) {
1513                 Asserts.assertEQ(res, args[idx] == null || !args[idx].getClass().isInlineClass());
1514             } else if (compiled) {
1515                 Asserts.assertTrue(res);
1516             }
1517             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual2_m, false);
1518             res = cmpSometimesEqual2(args[idx]);
1519             if (ACmpOnValues != 3) {
1520                 Asserts.assertNE(res, args[idx] == null || !args[idx].getClass().isInlineClass());
1521             } else if (compiled) {
1522                 Asserts.assertFalse(res);
1523             }
1524         }
1525     }
1526 
1527     public static void main(String[] args) throws Exception {
1528         if (Boolean.getBoolean("test.c1")) {
1529             System.out.println("new acmp is not implemented for C1"); // TMP
1530             return;
1531         }
1532 
1533         if (args.length == 0) {
1534             enumerateVMOptions();
1535         } else {
1536             int nullMode = Integer.valueOf(args[0]);
1537             TestNewAcmp t = new TestNewAcmp();
1538             t.run(nullMode);
1539         }
1540     }


< prev index next >