< prev index next >

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

Print this page


1371     public boolean cmpAlwaysUnEqual2(Object a, Object b) {
1372         return a != b;
1373     }
1374 
1375     public boolean cmpAlwaysUnEqual3(Object a) {
1376         return a == a;
1377     }
1378 
1379     public boolean cmpAlwaysUnEqual4(Object a) {
1380         return a != a;
1381     }
1382 
1383     public boolean cmpSometimesEqual1(Object a) {
1384         return a == a;
1385     }
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) {


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     }
1544 
1545     private static String[] addOptions(String prefix[], String... extra) {
1546         ArrayList<String> list = new ArrayList<String>();
1547         if (prefix != null) {
1548             for (String s : prefix) {
1549                 list.add(s);
1550             }
1551         }
1552         if (extra != null) {
1553             for (String s : extra) {
1554                 System.out.println("    " + s);
1555                 list.add(s);


1564             "-Xbootclasspath/a:.",
1565             "-XX:+UnlockDiagnosticVMOptions",
1566             "-XX:+WhiteBoxAPI",
1567             "-Xbatch",
1568             "-XX:+EnableValhalla",
1569             "-XX:TypeProfileLevel=222",
1570             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::test*",
1571             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::cmp*"};
1572 
1573         String SCENARIOS = System.getProperty("Scenarios", "");
1574         List<String> scenarios = null;
1575         if (!SCENARIOS.isEmpty()) {
1576            scenarios = Arrays.asList(SCENARIOS.split(","));
1577         }
1578 
1579         int scenario = -1;
1580         for (int nullMode = 0; nullMode <= 2; nullMode++) {              // null mode
1581             for (int onVal = 0; onVal < 2; onVal++) {                    // 0 = default, 1 = -XX:ACmpOnValues=3
1582                 for (int incrInline = 0; incrInline < 2; incrInline++) { // 0 = default, 1 = -XX:+AlwaysIncrementalInline
1583                     scenario++;
1584                     if (scenarios != null && !scenarios.contains(Integer.toString(scenario))) {
1585                         System.out.println("Scenario #" + scenario + " is skipped due to -Dscenarios=" + SCENARIOS);
1586                         continue;
1587                     } else {
1588                         System.out.println("Scenario #" + scenario + " -------------------");
1589                     }
1590                     

1591                     String[] cmds = baseOptions;
1592                     if (incrInline != 0) {
1593                         cmds = addOptions(cmds, "-XX:+AlwaysIncrementalInline");
1594                     }
1595                     if (onVal != 0) {
1596                         cmds = addOptions(cmds, "-XX:+UnlockExperimentalVMOptions", "-XX:ACmpOnValues=3");
1597                     }






1598                     cmds = addOptions(cmds, "compiler.valhalla.valuetypes.TestNewAcmp");
1599                     cmds = addOptions(cmds, Integer.toString(nullMode));








1600 
1601                     OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
1602                     String output = oa.getOutput();
1603                     oa.shouldHaveExitValue(0);
1604                     System.out.println(output);
1605                 }
1606             }
1607         }
1608     }
1609 }


1371     public boolean cmpAlwaysUnEqual2(Object a, Object b) {
1372         return a != b;
1373     }
1374 
1375     public boolean cmpAlwaysUnEqual3(Object a) {
1376         return a == a;
1377     }
1378 
1379     public boolean cmpAlwaysUnEqual4(Object a) {
1380         return a != a;
1381     }
1382 
1383     public boolean cmpSometimesEqual1(Object a) {
1384         return a == a;
1385     }
1386 
1387     public boolean cmpSometimesEqual2(Object a) {
1388         return a != a;
1389     }
1390 
1391     static int get_full_opt_level() {
1392         int n = (int)TieredStopAtLevel;
1393         if (n >= 4) {
1394             n = 4;
1395         }
1396         return n;
1397     }
1398     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1399     protected static final long TieredStopAtLevel = (Long)WHITE_BOX.getVMFlag("TieredStopAtLevel");
1400     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = get_full_opt_level();
1401     protected static final long ACmpOnValues = (Long)WHITE_BOX.getVMFlag("ACmpOnValues");
1402 
1403     // FIXME: temp -- special handling for C1 testing.
1404     protected static final boolean EnableValhallaC1 = (Boolean)WHITE_BOX.getVMFlag("EnableValhallaC1");
1405 
1406     public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception {
1407         Class<?>[] parameterTypes = m.getParameterTypes();
1408         int parameterCount = parameterTypes.length;
1409         // Nullness mode for first argument
1410         // 0: default, 1: never null, 2: always null
1411         int start = (nullMode != 1) ? 0 : 1;
1412         int end = (nullMode != 2) ? args.length : 1;
1413         for (int i = start; i < end; ++i) {
1414             if (args[i] != null && !parameterTypes[0].isInstance(args[i])) {
1415                 continue;
1416             }
1417             if (args[i] == null && parameterTypes[0] == MyValue1.class.asValueType()) {
1418                 continue;
1419             }
1420             if (parameterCount == 1) {
1421                 // Null checks
1422                 System.out.print("Testing " + m.getName() + "(" + args[i] + ")");
1423                 // Avoid acmp in the computation of the expected result!
1424                 boolean expected = isNegated(m) ? (i != 0) : (i == 0);
1425                 for (int run = 0; run < warmup; ++run) {


1522 
1523             int idx = i % args.length;
1524             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual1_m, false);
1525             res = cmpSometimesEqual1(args[idx]);
1526             if (ACmpOnValues != 3) {
1527                 Asserts.assertEQ(res, args[idx] == null || !args[idx].getClass().isValue());
1528             } else if (compiled) {
1529                 Asserts.assertTrue(res);
1530             }
1531             compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual2_m, false);
1532             res = cmpSometimesEqual2(args[idx]);
1533             if (ACmpOnValues != 3) {
1534                 Asserts.assertNE(res, args[idx] == null || !args[idx].getClass().isValue());
1535             } else if (compiled) {
1536                 Asserts.assertFalse(res);
1537             }
1538         }
1539     }
1540 
1541     public static void main(String[] args) throws Exception {





1542         if (args.length == 0) {
1543             enumerateVMOptions();
1544         } else {
1545             int nullMode = Integer.valueOf(args[0]);
1546             TestNewAcmp t = new TestNewAcmp();
1547             t.run(nullMode);
1548         }
1549     }
1550 
1551     private static String[] addOptions(String prefix[], String... extra) {
1552         ArrayList<String> list = new ArrayList<String>();
1553         if (prefix != null) {
1554             for (String s : prefix) {
1555                 list.add(s);
1556             }
1557         }
1558         if (extra != null) {
1559             for (String s : extra) {
1560                 System.out.println("    " + s);
1561                 list.add(s);


1570             "-Xbootclasspath/a:.",
1571             "-XX:+UnlockDiagnosticVMOptions",
1572             "-XX:+WhiteBoxAPI",
1573             "-Xbatch",
1574             "-XX:+EnableValhalla",
1575             "-XX:TypeProfileLevel=222",
1576             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::test*",
1577             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::cmp*"};
1578 
1579         String SCENARIOS = System.getProperty("Scenarios", "");
1580         List<String> scenarios = null;
1581         if (!SCENARIOS.isEmpty()) {
1582            scenarios = Arrays.asList(SCENARIOS.split(","));
1583         }
1584 
1585         int scenario = -1;
1586         for (int nullMode = 0; nullMode <= 2; nullMode++) {              // null mode
1587             for (int onVal = 0; onVal < 2; onVal++) {                    // 0 = default, 1 = -XX:ACmpOnValues=3
1588                 for (int incrInline = 0; incrInline < 2; incrInline++) { // 0 = default, 1 = -XX:+AlwaysIncrementalInline
1589                     scenario++;






1590 
1591                     System.out.println("\nScenario #" + scenario + " -------------------");
1592                     String[] cmds = baseOptions;
1593                     if (incrInline != 0) {
1594                         cmds = addOptions(cmds, "-XX:+AlwaysIncrementalInline");
1595                     }
1596                     if (onVal != 0) {
1597                         cmds = addOptions(cmds, "-XX:+UnlockExperimentalVMOptions", "-XX:ACmpOnValues=3");
1598                     }
1599 
1600                     if (EnableValhallaC1) {
1601                         // FIXME: C1 runs into problems when these methods are compiled
1602                         cmds = addOptions(cmds, "-XX:CompileCommand=exclude,java.lang.ClassValue::*");
1603                     }
1604 
1605                     cmds = addOptions(cmds, "compiler.valhalla.valuetypes.TestNewAcmp");
1606                     cmds = addOptions(cmds, Integer.toString(nullMode));
1607 
1608                     if (scenarios != null && !scenarios.contains(Integer.toString(scenario))) {
1609                         System.out.println("Scenario #" + scenario + " is skipped due to -Dscenarios=" + SCENARIOS);
1610                         continue;
1611                     } else if (EnableValhallaC1 && onVal == 0) {
1612                         System.out.println("Scenario #" + scenario + " is skipped because C1 requires -XX:ACmpOnValues=3");
1613                         continue;
1614                     }
1615 
1616                     OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
1617                     String output = oa.getOutput();
1618                     oa.shouldHaveExitValue(0);
1619                     System.out.println(output);
1620                 }
1621             }
1622         }
1623     }
1624 }
< prev index next >