1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529
|
/*
* Copyright (c) 2020, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/**
* @test
* @bug 8227745
* @summary Collection of test cases that check if optimizations based on escape analysis are reverted just before non-escaping objects escape through JVMTI.
* @author Richard Reingruber richard DOT reingruber AT sap DOT com
*
* @requires ((vm.compMode == "Xmixed") & vm.compiler2.enabled)
* @library /test/lib /test/hotspot/jtreg
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run compile -g EATests.java
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=1
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:-EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=1
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=1
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=1
*
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:-EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
*
* @comment Excercise -XX:+DeoptimizeObjectsALot. Mostly to prevent bit-rot because the option is meant to stress object deoptimization
* with non-synthetic workloads.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:-DoEscapeAnalysis -XX:-EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:+IgnoreUnrecognizedVMOptions -XX:+DeoptimizeObjectsALot
*
* @bug 8324881
* @comment Regression test for using the wrong thread when logging during re-locking from deoptimization.
*
* @comment DiagnoseSyncOnValueBasedClasses=2 will cause logging when locking on \@ValueBased objects.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=1
* -XX:DiagnoseSyncOnValueBasedClasses=2
*
* @comment Re-lock may inflate monitors when re-locking, which cause monitorinflation trace logging.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* -Xlog:monitorinflation=trace:file=monitorinflation.log
*
* @comment Re-lock may race with deflation.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=0
* -XX:GuaranteedAsyncDeflationInterval=1000
*
* @bug 8341819
* @comment Regression test for re-locking racing with deflation with LM_LIGHTWEIGHT.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+DoEscapeAnalysis -XX:+EliminateAllocations -XX:+EliminateLocks -XX:+EliminateNestedLocks
* -XX:LockingMode=2
* -XX:GuaranteedAsyncDeflationInterval=1
*/
/**
* @test
* @bug 8227745
*
* @summary This is another configuration of EATests.java to test Graal. Some testcases are expected
* to fail because Graal does not provide all information about non-escaping objects in
* scope. These are skipped.
*
* @author Richard Reingruber richard DOT reingruber AT sap DOT com
*
* @requires ((vm.compMode == "Xmixed") & vm.graal.enabled)
*
* @library /test/lib /test/hotspot/jtreg
*
* @run build TestScaffold VMConnection TargetListener TargetAdapter jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run compile -g EATests.java
*
* @comment Test with Graal. Some testcases are expected to fail because Graal does not provide all information about non-escaping
* objects in scope. These are skipped.
* @run driver EATests
* -XX:+UnlockDiagnosticVMOptions
* -Xms256m -Xmx256m
* -Xbootclasspath/a:.
* -XX:CompileCommand=dontinline,*::dontinline_*
* -XX:+WhiteBoxAPI
* -Xbatch
* -XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler
*/
import com.sun.jdi.*;
import com.sun.jdi.event.*;
import compiler.testlibrary.CompilerUtils;
import compiler.whitebox.CompilerWhiteBoxTest;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import jdk.test.lib.Asserts;
import jdk.test.whitebox.WhiteBox;
import jdk.test.whitebox.gc.GC;
//
// ANALYZING TEST FAILURES
//
// - Executing just a single test case with the property EATests.onlytestcase.
//
// Example: java -DEATests.onlytestcase=<test case name> ... EATests
//
// - Interactive execution allows for attaching a native debugger, e.g. gdb
//
// Example: java -DEATests.interactive=true ... EATests
//
// - Java arguments to the test are passed as vm options to the debuggee:
//
// Example: java ... EATests -XX:+UseNewCode
//
/////////////////////////////////////////////////////////////////////////////
//
// Shared base class for test cases for both, debugger and debuggee.
//
/////////////////////////////////////////////////////////////////////////////
class EATestCaseBaseShared {
// In interactive mode we wait for a keypress before every test case.
public static final boolean INTERACTIVE =
System.getProperty("EATests.interactive") != null &&
System.getProperty("EATests.interactive").equals("true");
// If the property is given, then just the test case it refers to is executed.
// Use it to diagnose test failures.
public static final String RUN_ONLY_TEST_CASE_PROPERTY = "EATests.onlytestcase";
public static final String RUN_ONLY_TEST_CASE = System.getProperty(RUN_ONLY_TEST_CASE_PROPERTY);
public final String testCaseName;
public EATestCaseBaseShared() {
String clName = getClass().getName();
int tidx = clName.lastIndexOf("Target");
testCaseName = tidx > 0 ? clName.substring(0, tidx) : clName;
}
public boolean shouldSkip() {
return EATestCaseBaseShared.RUN_ONLY_TEST_CASE != null &&
EATestCaseBaseShared.RUN_ONLY_TEST_CASE.length() > 0 &&
!testCaseName.equals(EATestCaseBaseShared.RUN_ONLY_TEST_CASE);
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Target main class, i.e. the program to be debugged.
//
/////////////////////////////////////////////////////////////////////////////
class EATestsTarget {
public static void main(String[] args) {
EATestCaseBaseTarget.staticSetUp();
EATestCaseBaseTarget.staticSetUpDone();
// Materializing test cases, i.e. reallocating objects on the heap
new EAMaterializeLocalVariableUponGetTarget() .run();
new EAGetWithoutMaterializeTarget() .run();
new EAMaterializeLocalAtObjectReturnTarget() .run();
new EAMaterializeLocalAtObjectPollReturnReturnTarget() .run();
new EAMaterializeIntArrayTarget() .run();
new EAMaterializeLongArrayTarget() .run();
new EAMaterializeFloatArrayTarget() .run();
new EAMaterializeDoubleArrayTarget() .run();
new EAMaterializeObjectArrayTarget() .run();
new EAMaterializeObjectWithConstantAndNotConstantValuesTarget() .run();
new EAMaterializeObjReferencedBy2LocalsTarget() .run();
new EAMaterializeObjReferencedBy2LocalsAndModifyTarget() .run();
new EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesTarget() .run();
new EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesAndModifyTarget() .run();
new EAMaterializeObjReferencedFromOperandStackTarget() .run();
new EAMaterializeLocalVariableUponGetAfterSetIntegerTarget() .run();
// Relocking test cases
new EARelockingSimpleTarget() .run();
new EARelockingWithManyLightweightLocksTarget() .run();
new EARelockingSimpleWithAccessInOtherThreadTarget() .run();
new EARelockingSimpleWithAccessInOtherThread_02_DynamicCall_Target() .run();
new EARelockingRecursiveTarget() .run();
new EARelockingNestedInflatedTarget() .run();
new EARelockingNestedInflated_02Target() .run();
new EARelockingNestedInflated_03Target() .run();
new EARelockingArgEscapeLWLockedInCalleeFrameTarget() .run();
new EARelockingArgEscapeLWLockedInCalleeFrame_2Target() .run();
new EARelockingArgEscapeLWLockedInCalleeFrameNoRecursiveTarget() .run();
new EAGetOwnedMonitorsTarget() .run();
new EAEntryCountTarget() .run();
new EARelockingObjectCurrentlyWaitingOnTarget() .run();
new EARelockingValueBasedTarget() .run();
// Test cases that require deoptimization even though neither
// locks nor allocations are eliminated at the point where
// escape state is changed.
new EADeoptFrameAfterReadLocalObject_01Target() .run();
new EADeoptFrameAfterReadLocalObject_01BTarget() .run();
new EADeoptFrameAfterReadLocalObject_02Target() .run();
new EADeoptFrameAfterReadLocalObject_02BTarget() .run();
new EADeoptFrameAfterReadLocalObject_02CTarget() .run();
new EADeoptFrameAfterReadLocalObject_03Target() .run();
// PopFrame test cases
new EAPopFrameNotInlinedTarget() .run();
new EAPopFrameNotInlinedReallocFailureTarget() .run();
new EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget() .run();
// ForceEarlyReturn test cases
new EAForceEarlyReturnNotInlinedTarget() .run();
new EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsTarget() .run();
new EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailureTarget().run();
// Instances of ReferenceType
new EAGetInstancesOfReferenceTypeTarget() .run();
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Debugger main class
//
/////////////////////////////////////////////////////////////////////////////
public class EATests extends TestScaffold {
public TargetVMOptions targetVMOptions;
public ThreadReference targetMainThread;
EATests(String args[]) {
super(args);
}
public static void main(String[] args) throws Exception {
if (EATestCaseBaseShared.RUN_ONLY_TEST_CASE != null) {
args = Arrays.copyOf(args, args.length + 1);
args[args.length - 1] = "-D" + EATestCaseBaseShared.RUN_ONLY_TEST_CASE_PROPERTY + "=" + EATestCaseBaseShared.RUN_ONLY_TEST_CASE;
}
new EATests(args).startTests();
}
public static class TargetVMOptions {
public final boolean UseJVMCICompiler;
public final boolean EliminateAllocations;
public final boolean DeoptimizeObjectsALot;
public final boolean DoEscapeAnalysis;
public final boolean ZGCIsSelected;
public final boolean ShenandoahGCIsSelected;
public final boolean StressReflectiveCode;
public TargetVMOptions(EATests env, ClassType testCaseBaseTargetClass) {
Value val;
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("DoEscapeAnalysis"));
DoEscapeAnalysis = ((PrimitiveValue) val).booleanValue();
// Escape analysis is a prerequisite for scalar replacement (EliminateAllocations)
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("EliminateAllocations"));
EliminateAllocations = DoEscapeAnalysis && ((PrimitiveValue) val).booleanValue();
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("DeoptimizeObjectsALot"));
DeoptimizeObjectsALot = ((PrimitiveValue) val).booleanValue();
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("UseJVMCICompiler"));
UseJVMCICompiler = ((PrimitiveValue) val).booleanValue();
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("ZGCIsSelected"));
ZGCIsSelected = ((PrimitiveValue) val).booleanValue();
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("ShenandoahGCIsSelected"));
ShenandoahGCIsSelected = ((PrimitiveValue) val).booleanValue();
val = testCaseBaseTargetClass.getValue(testCaseBaseTargetClass.fieldByName("StressReflectiveCode"));
StressReflectiveCode = ((PrimitiveValue) val).booleanValue();
}
}
// Execute known test cases
protected void runTests() throws Exception {
String targetProgName = EATestsTarget.class.getName();
msg("starting to main method in class " + targetProgName);
startToMain(targetProgName);
msg("resuming to EATestCaseBaseTarget.staticSetUpDone()V");
targetMainThread = resumeTo("EATestCaseBaseTarget", "staticSetUpDone", "()V").thread();
Location loc = targetMainThread.frame(0).location();
Asserts.assertEQ("staticSetUpDone", loc.method().name());
targetVMOptions = new TargetVMOptions(this, (ClassType) loc.declaringType());
// Materializing test cases, i.e. reallocating objects on the heap
new EAMaterializeLocalVariableUponGet() .run(this);
new EAGetWithoutMaterialize() .run(this);
new EAMaterializeLocalAtObjectReturn() .run(this);
new EAMaterializeLocalAtObjectPollReturnReturn() .run(this);
new EAMaterializeIntArray() .run(this);
new EAMaterializeLongArray() .run(this);
new EAMaterializeFloatArray() .run(this);
new EAMaterializeDoubleArray() .run(this);
new EAMaterializeObjectArray() .run(this);
new EAMaterializeObjectWithConstantAndNotConstantValues() .run(this);
new EAMaterializeObjReferencedBy2Locals() .run(this);
new EAMaterializeObjReferencedBy2LocalsAndModify() .run(this);
new EAMaterializeObjReferencedBy2LocalsInDifferentVirtFrames() .run(this);
new EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesAndModify() .run(this);
new EAMaterializeObjReferencedFromOperandStack() .run(this);
new EAMaterializeLocalVariableUponGetAfterSetInteger() .run(this);
// Relocking test cases
new EARelockingSimple() .run(this);
new EARelockingWithManyLightweightLocks() .run(this);
new EARelockingSimpleWithAccessInOtherThread() .run(this);
new EARelockingSimpleWithAccessInOtherThread_02_DynamicCall() .run(this);
new EARelockingRecursive() .run(this);
new EARelockingNestedInflated() .run(this);
new EARelockingNestedInflated_02() .run(this);
new EARelockingNestedInflated_03() .run(this);
new EARelockingArgEscapeLWLockedInCalleeFrame() .run(this);
new EARelockingArgEscapeLWLockedInCalleeFrame_2() .run(this);
new EARelockingArgEscapeLWLockedInCalleeFrameNoRecursive() .run(this);
new EAGetOwnedMonitors() .run(this);
new EAEntryCount() .run(this);
new EARelockingObjectCurrentlyWaitingOn() .run(this);
new EARelockingValueBased() .run(this);
// Test cases that require deoptimization even though neither
// locks nor allocations are eliminated at the point where
// escape state is changed.
new EADeoptFrameAfterReadLocalObject_01() .run(this);
new EADeoptFrameAfterReadLocalObject_01B() .run(this);
new EADeoptFrameAfterReadLocalObject_02() .run(this);
new EADeoptFrameAfterReadLocalObject_02B() .run(this);
new EADeoptFrameAfterReadLocalObject_02C() .run(this);
new EADeoptFrameAfterReadLocalObject_03() .run(this);
// PopFrame test cases
new EAPopFrameNotInlined() .run(this);
new EAPopFrameNotInlinedReallocFailure() .run(this);
new EAPopInlinedMethodWithScalarReplacedObjectsReallocFailure() .run(this);
// ForceEarlyReturn test cases
new EAForceEarlyReturnNotInlined() .run(this);
new EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjects() .run(this);
new EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailure().run(this);
// Instances of ReferenceType
new EAGetInstancesOfReferenceType() .run(this);
// resume the target listening for events
listenUntilVMDisconnect();
}
// Print a Message
public void msg(String m) {
System.out.println();
System.out.println("###(Debugger) " + m);
System.out.println();
}
// Highlighted message.
public void msgHL(String m) {
System.out.println();
System.out.println();
System.out.println("##########################################################");
System.out.println("### " + m);
System.out.println("### ");
System.out.println();
System.out.println();
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Base class for debugger side of test cases.
//
/////////////////////////////////////////////////////////////////////////////
abstract class EATestCaseBaseDebugger extends EATestCaseBaseShared {
protected EATests env;
public ObjectReference testCase;
public static final String TARGET_TESTCASE_BASE_NAME = EATestCaseBaseTarget.class.getName();
public static final String XYVAL_NAME = XYVal.class.getName();
public abstract void runTestCase() throws Exception;
@Override
public boolean shouldSkip() {
// Skip if StressReflectiveCode because it effectively disables escape analysis
return super.shouldSkip() || env.targetVMOptions.StressReflectiveCode;
}
public void run(EATests env) {
this.env = env;
if (shouldSkip()) {
msg("skipping " + testCaseName);
return;
}
try {
msgHL("Executing test case " + getClass().getName());
env.testFailed = false;
if (INTERACTIVE)
env.waitForInput();
resumeToWarmupDone();
runTestCase();
Asserts.assertTrue(env.targetMainThread.isSuspended(), "must be suspended after the testcase");
resumeToTestCaseDone();
checkPostConditions();
} catch (Exception e) {
Asserts.fail("Unexpected exception in test case " + getClass().getName(), e);
}
}
/**
* Set a breakpoint in the given method and resume all threads. The
* breakpoint is configured to suspend just the thread that reaches it
* instead of all threads. This is important when running with graal.
*/
public BreakpointEvent resumeTo(String clsName, String methodName, String signature) {
boolean suspendThreadOnly = true;
return env.resumeTo(clsName, methodName, signature, suspendThreadOnly);
}
public void resumeToWarmupDone() throws Exception {
msg("resuming to " + TARGET_TESTCASE_BASE_NAME + ".warmupDone()V");
resumeTo(TARGET_TESTCASE_BASE_NAME, "warmupDone", "()V");
testCase = env.targetMainThread.frame(0).thisObject();
}
public void resumeToTestCaseDone() {
msg("resuming to " + TARGET_TESTCASE_BASE_NAME + ".testCaseDone()V");
resumeTo(TARGET_TESTCASE_BASE_NAME, "testCaseDone", "()V");
}
public void checkPostConditions() throws Exception {
Asserts.assertFalse(env.getExceptionCaught(), "Uncaught exception in Debuggee");
String testName = getClass().getName();
if (!env.testFailed) {
env.println(testName + ": passed");
} else {
throw new Exception(testName + ": failed");
}
}
public void printStack(ThreadReference thread) throws Exception {
msg("Debuggee Stack:");
List<StackFrame> stack_frames = thread.frames();
int i = 0;
for (StackFrame ff : stack_frames) {
System.out.println("frame[" + i++ +"]: " + ff.location().method() + " (bci:" + ff.location().codeIndex() + ")");
}
}
public void msg(String m) {
env.msg(m);
}
public void msgHL(String m) {
env.msgHL(m);
}
// See Field Descriptors in The Java Virtual Machine Specification
// (https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.3.2)
enum FD {
I, // int
J, // long
F, // float
D, // double
}
// Map field descriptor to jdi type string
public static final Map<FD, String> FD2JDIArrType = Map.of(FD.I, "int[]", FD.J, "long[]", FD.F, "float[]", FD.D, "double[]");
// Map field descriptor to PrimitiveValue getter
public static final Function<PrimitiveValue, Integer> v2I = PrimitiveValue::intValue;
public static final Function<PrimitiveValue, Long> v2J = PrimitiveValue::longValue;
public static final Function<PrimitiveValue, Float> v2F = PrimitiveValue::floatValue;
public static final Function<PrimitiveValue, Double> v2D = PrimitiveValue::doubleValue;
Map<FD, Function<PrimitiveValue, ?>> FD2getter = Map.of(FD.I, v2I, FD.J, v2J, FD.F, v2F, FD.D, v2D);
/**
* Retrieve array of primitive values referenced by a local variable in target and compare with
* an array of expected values.
* @param frame Frame in the target holding the local variable
* @param lName Name of the local variable referencing the array to be retrieved
* @param desc Array element type given as field descriptor.
* @param expVals Array of expected values.
* @throws Exception
*/
protected void checkLocalPrimitiveArray(StackFrame frame, String lName, FD desc, Object expVals) throws Exception {
String lType = FD2JDIArrType.get(desc);
Asserts.assertNotNull(lType, "jdi type not found");
Asserts.assertEQ(EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME, frame .location().method().name());
List<LocalVariable> localVars = frame.visibleVariables();
msg("Check if the local array variable '" + lName + "' in " + EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME + " has the expected elements: ");
boolean found = false;
for (LocalVariable lv : localVars) {
if (lv.name().equals(lName)) {
found = true;
Value lVal = frame.getValue(lv);
Asserts.assertNotNull(lVal);
Asserts.assertEQ(lVal.type().name(), lType);
ArrayReference aRef = (ArrayReference) lVal;
Asserts.assertEQ(3, aRef.length());
// now check the elements
for (int i = 0; i < aRef.length(); i++) {
Object actVal = FD2getter.get(desc).apply((PrimitiveValue)aRef.getValue(i));
Object expVal = Array.get(expVals, i);
Asserts.assertEQ(expVal, actVal, "checking element at index " + i);
}
}
}
Asserts.assertTrue(found);
msg("OK.");
}
/**
* Retrieve array of objects referenced by a local variable in target and compare with an array
* of expected values.
* @param frame Frame in the target holding the local variable
* @param lName Name of the local variable referencing the array to be retrieved
* @param lType Local type, e.g. java.lang.Long[]
* @param expVals Array of expected values.
* @throws Exception
*/
protected void checkLocalObjectArray(StackFrame frame, String lName, String lType, ObjectReference[] expVals) throws Exception {
Asserts.assertEQ(EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME, frame .location().method().name());
List<LocalVariable> localVars = frame.visibleVariables();
msg("Check if the local array variable '" + lName + "' in " + EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME + " has the expected elements: ");
boolean found = false;
for (LocalVariable lv : localVars) {
if (lv.name().equals(lName)) {
found = true;
Value lVal = frame.getValue(lv);
Asserts.assertNotNull(lVal);
Asserts.assertEQ(lType, lVal.type().name());
ArrayReference aRef = (ArrayReference) lVal;
Asserts.assertEQ(3, aRef.length());
// now check the elements
for (int i = 0; i < aRef.length(); i++) {
ObjectReference actVal = (ObjectReference)aRef.getValue(i);
Asserts.assertSame(expVals[i], actVal, "checking element at index " + i);
}
}
}
Asserts.assertTrue(found);
msg("OK.");
}
/**
* Retrieve a reference held by a local variable in the given frame. Check if the frame's method
* is the expected method if the retrieved local value has the expected type and is not null.
* @param frame The frame to retrieve the local variable value from.
* @param expectedMethodName The name of the frames method should match the expectedMethodName.
* @param lName The name of the local variable which is read.
* @param expectedType Is the expected type of the object referenced by the local variable.
* @return
* @throws Exception
*/
protected ObjectReference getLocalRef(StackFrame frame, String expectedMethodName, String lName, String expectedType) throws Exception {
Asserts.assertEQ(expectedMethodName, frame.location().method().name());
List<LocalVariable> localVars = frame.visibleVariables();
msg("Get and check local variable '" + lName + "' in " + expectedMethodName);
ObjectReference lRef = null;
for (LocalVariable lv : localVars) {
if (lv.name().equals(lName)) {
Value lVal = frame.getValue(lv);
Asserts.assertNotNull(lVal);
Asserts.assertEQ(expectedType, lVal.type().name());
lRef = (ObjectReference) lVal;
break;
}
}
Asserts.assertNotNull(lRef, "Local variable '" + lName + "' not found");
msg("OK.");
return lRef;
}
/**
* Retrieve a reference held by a local variable in the given frame. Check if the frame's method
* matches {@link EATestCaseBaseTarget#TESTMETHOD_DEFAULT_NAME} if the retrieved local value has
* the expected type and is not null.
* @param frame The frame to retrieve the local variable value from.
* @param expectedMethodName The name of the frames method should match the expectedMethodName.
* @param lName The name of the local variable which is read.
* @param expectedType Is the expected type of the object referenced by the local variable.
* @return
* @throws Exception
*/
protected ObjectReference getLocalRef(StackFrame frame, String lType, String lName) throws Exception {
return getLocalRef(frame, EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME, lName, lType);
}
/**
* Set the value of a local variable in the given frame. Check if the frame's method is the expected method.
* @param frame The frame holding the local variable.
* @param expectedMethodName The expected name of the frame's method.
* @param lName The name of the local variable to change.
* @param val The new value of the local variable.
* @throws Exception
*/
public void setLocal(StackFrame frame, String expectedMethodName, String lName, Value val) throws Exception {
Asserts.assertEQ(expectedMethodName, frame.location().method().name());
List<LocalVariable> localVars = frame.visibleVariables();
msg("Set local variable '" + lName + "' = " + val + " in " + expectedMethodName);
for (LocalVariable lv : localVars) {
if (lv.name().equals(lName)) {
frame.setValue(lv, val);
break;
}
}
msg("OK.");
}
/**
* Set the value of a local variable in the given frame. Check if the frame's method matches
* {@link EATestCaseBaseTarget#TESTMETHOD_DEFAULT_NAME}.
* @param frame The frame holding the local variable.
* @param expectedMethodName The expected name of the frame's method.
* @param lName The name of the local variable to change.
* @param val The new value of the local variable.
* @throws Exception
*/
public void setLocal(StackFrame frame, String lName, Value val) throws Exception {
setLocal(frame, EATestCaseBaseTarget.TESTMETHOD_DEFAULT_NAME, lName, val);
}
/**
* Check if a field has the expected primitive value.
* @param o Object holding the field.
* @param desc Field descriptor.
* @param fName Field name
* @param expVal Expected primitive value
* @throws Exception
*/
protected void checkPrimitiveField(ObjectReference o, FD desc, String fName, Object expVal) throws Exception {
msg("check field " + fName);
ReferenceType rt = o.referenceType();
Field fld = rt.fieldByName(fName);
Value val = o.getValue(fld);
Object actVal = FD2getter.get(desc).apply((PrimitiveValue) val);
Asserts.assertEQ(expVal, actVal, "field '" + fName + "' has unexpected value.");
msg("ok");
}
/**
* Check if a field references the expected object.
* @param obj Object holding the field.
* @param fName Field name
* @param expVal Object expected to be referenced by the field
* @throws Exception
*/
protected void checkObjField(ObjectReference obj, String fName, ObjectReference expVal) throws Exception {
msg("check field " + fName);
ReferenceType rt = obj.referenceType();
Field fld = rt.fieldByName(fName);
Value actVal = obj.getValue(fld);
Asserts.assertEQ(expVal, actVal, "field '" + fName + "' has unexpected value.");
msg("ok");
}
protected void setField(ObjectReference obj, String fName, Value val) throws Exception {
msg("set field " + fName + " = " + val);
ReferenceType rt = obj.referenceType();
Field fld = rt.fieldByName(fName);
obj.setValue(fld, val);
msg("ok");
}
protected Value getField(ObjectReference obj, String fName) throws Exception {
msg("get field " + fName);
ReferenceType rt = obj.referenceType();
Field fld = rt.fieldByName(fName);
Value val = obj.getValue(fld);
msg("result : " + val);
return val;
}
/**
* Free the memory consumed in the target by {@link EATestCaseBaseTarget#consumedMemory}
* @throws Exception
*/
public void freeAllMemory() throws Exception {
msg("free consumed memory");
setField(testCase, "consumedMemory", null);
}
/**
* @return The value of {@link EATestCaseBaseTarget#targetIsInLoop}. The target must set that field to true as soon as it
* enters the endless loop.
* @throws Exception
*/
public boolean targetHasEnteredEndlessLoop() throws Exception {
Value v = getField(testCase, "targetIsInLoop");
return ((PrimitiveValue) v).booleanValue();
}
/**
* Poll {@link EATestCaseBaseTarget#targetIsInLoop} and return if it is found to be true.
* @throws Exception
*/
public void waitUntilTargetHasEnteredEndlessLoop() throws Exception {
while(!targetHasEnteredEndlessLoop()) {
msg("Target has not yet entered the loop. Sleep 200ms.");
try { Thread.sleep(200); } catch (InterruptedException e) { /*ignore */ }
}
}
/**
* Set {@link EATestCaseBaseTarget#doLoop} to <code>false</code>. This will allow the target to
* leave the endless loop.
* @throws Exception
*/
public void terminateEndlessLoop() throws Exception {
msg("terminate loop");
setField(testCase, "doLoop", env.vm().mirrorOf(false));
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Base class for debuggee side of test cases.
//
/////////////////////////////////////////////////////////////////////////////
abstract class EATestCaseBaseTarget extends EATestCaseBaseShared implements Runnable {
/**
* The target must set that field to true as soon as it enters the endless loop.
*/
public volatile boolean targetIsInLoop;
/**
* Used for busy loops. See {@link #dontinline_endlessLoop()}.
*/
public volatile long loopCount;
/**
* Used in {@link EATestCaseBaseDebugger#terminateEndlessLoop()} to signal target to leave the endless loop.
*/
public volatile boolean doLoop;
public long checkSum;
public static final String TESTMETHOD_DEFAULT_NAME = "dontinline_testMethod";
public static final WhiteBox WB = WhiteBox.getWhiteBox();
public static boolean unbox(Boolean value, boolean dflt) {
return value == null ? dflt : value;
}
// Some of the fields are only read by the debugger
public static final boolean UseJVMCICompiler = unbox(WB.getBooleanVMFlag("UseJVMCICompiler"), false);
public static final boolean DoEscapeAnalysis = unbox(WB.getBooleanVMFlag("DoEscapeAnalysis"), UseJVMCICompiler);
public static final boolean EliminateAllocations = unbox(WB.getBooleanVMFlag("EliminateAllocations"), UseJVMCICompiler);
public static final boolean DeoptimizeObjectsALot = WB.getBooleanVMFlag("DeoptimizeObjectsALot");
public static final boolean ZGCIsSelected = GC.Z.isSelected();
public static final boolean ShenandoahGCIsSelected = GC.Shenandoah.isSelected();
public static final boolean StressReflectiveCode = unbox(WB.getBooleanVMFlag("StressReflectiveCode"), false);
public String testMethodName;
public int testMethodDepth;
// Results produced by dontinline_testMethod()
public int iResult;
public long lResult;
public float fResult;
public double dResult;
public boolean warmupDone;
// an object with an inflated monitor
public static XYVal inflatedLock;
public static Thread inflatorThread;
public static boolean inflatedLockIsPermanentlyInflated;
public static int NOT_CONST_1I = 1;
public static long NOT_CONST_1L = 1L;
public static float NOT_CONST_1F = 1.1F;
public static double NOT_CONST_1D = 1.1D;
public static Long NOT_CONST_1_OBJ = Long.valueOf(1);
public static final Long CONST_2_OBJ = Long.valueOf(2);
public static final Long CONST_3_OBJ = Long.valueOf(3);
@Override
public boolean shouldSkip() {
// Skip if StressReflectiveCode because it effectively disables escape analysis
return super.shouldSkip() || StressReflectiveCode;
}
/**
* Main driver of a test case.
* <ul>
* <li> Skips test case if not selected (see {@link EATestCaseBaseShared#RUN_ONLY_TEST_CASE}
* <li> Call {@link #setUp()}
* <li> warm-up and compile {@link #dontinline_testMethod()} (see {@link #compileTestMethod()}
* <li> calling {@link #dontinline_testMethod()}
* <li> checking the result (see {@link #checkResult()}
* <ul>
*/
public void run() {
try {
if (shouldSkip()) {
msg("skipping " + testCaseName);
return;
}
setUp();
msg(testCaseName + " is up and running.");
compileTestMethod();
msg(testCaseName + " warmup done.");
warmupDone();
checkCompLevel();
dontinline_testMethod();
checkResult();
msg(testCaseName + " done.");
testCaseDone();
} catch (Exception e) {
Asserts.fail("Caught unexpected exception", e);
}
}
public static void staticSetUp() {
inflatedLock = new XYVal(1, 1);
synchronized (inflatedLock) {
inflatorThread = DebuggeeWrapper.newThread(() -> {
synchronized (inflatedLock) {
inflatedLockIsPermanentlyInflated = true;
inflatedLock.notify(); // main thread
while (true) {
try {
// calling wait() on a monitor will cause inflation into a heavy monitor
inflatedLock.wait();
} catch (InterruptedException e) { /* ignored */ }
}
}
}, "Lock Inflator (test thread)");
inflatorThread.setDaemon(true);
inflatorThread.start();
// wait until the lock is permanently inflated by the inflatorThread
while(!inflatedLockIsPermanentlyInflated) {
try {
inflatedLock.wait(); // until inflated
} catch (InterruptedException e1) { /* ignored */ }
}
}
}
// Debugger will set breakpoint here to sync with target.
public static void staticSetUpDone() {
}
public void setUp() {
testMethodDepth = 1;
testMethodName = TESTMETHOD_DEFAULT_NAME;
}
public abstract void dontinline_testMethod() throws Exception;
public int dontinline_brkpt_iret() {
dontinline_brkpt();
return 42;
}
/**
* It is a common protocol to have the debugger set a breakpoint in this method and have {@link
* #dontinline_testMethod()} call it and then perform some test actions on debugger side.
* After that it is checked if a frame of {@link #dontinline_testMethod()} is found at the
* expected depth on stack and if it is (not) marked for deoptimization as expected.
*/
public void dontinline_brkpt() {
// will set breakpoint here after warmup
if (warmupDone) {
// check if test method is at expected depth
StackTraceElement[] frames = Thread.currentThread().getStackTrace();
int stackTraceDepth = testMethodDepth + 1; // ignore java.lang.Thread.getStackTrace()
Asserts.assertEQ(testMethodName, frames[stackTraceDepth].getMethodName(),
testCaseName + ": test method not found at depth " + testMethodDepth);
// check if the frame is (not) deoptimized as expected
if (!DeoptimizeObjectsALot) {
if (testFrameShouldBeDeoptimized()) {
Asserts.assertTrue(WB.isFrameDeoptimized(testMethodDepth+1),
testCaseName + ": expected test method frame at depth " + testMethodDepth + " to be deoptimized");
} else {
Asserts.assertFalse(WB.isFrameDeoptimized(testMethodDepth+1),
testCaseName + ": expected test method frame at depth " + testMethodDepth + " not to be deoptimized");
}
}
}
}
/**
* Some test cases run busy endless loops by initializing {@link #loopCount}
* to {@link Long#MAX_VALUE} after warm-up and then counting down to 0 in their main test method.
* During warm-up {@link #loopCount} is initialized to a small value.
*/
public long dontinline_endlessLoop() {
long cs = checkSum;
doLoop = true;
while (loopCount-- > 0 && doLoop) {
targetIsInLoop = true;
checkSum += checkSum % ++cs;
}
loopCount = 3;
targetIsInLoop = false;
return checkSum;
}
public boolean testFrameShouldBeDeoptimized() {
return DoEscapeAnalysis;
}
public void warmupDone() {
warmupDone = true;
}
// Debugger will set breakpoint here to sync with target.
public void testCaseDone() {
}
public void compileTestMethod() throws Exception {
int callCount = CompilerWhiteBoxTest.THRESHOLD;
while (callCount-- > 0) {
dontinline_testMethod();
}
}
public void checkCompLevel() {
java.lang.reflect.Method m = null;
try {
m = getClass().getMethod(TESTMETHOD_DEFAULT_NAME);
} catch (NoSuchMethodException | SecurityException e) {
Asserts.fail("could not check compilation level of", e);
}
int highestLevel = CompilerUtils.getMaxCompilationLevel();
int compLevel = WB.getMethodCompilationLevel(m);
if (!UseJVMCICompiler) {
Asserts.assertEQ(highestLevel, compLevel,
m + " not on expected compilation level");
} else {
// Background compilation (-Xbatch) will block a thread with timeout
// (see CompileBroker::wait_for_jvmci_completion()). Therefore it is
// possible to reach here before the main test method is compiled.
// In that case we wait for it to be compiled.
while (compLevel != highestLevel) {
msg(TESTMETHOD_DEFAULT_NAME + " is compiled on level " + compLevel +
". Wait until highes level (" + highestLevel + ") is reached.");
try {
Thread.sleep(200);
} catch (InterruptedException e) { /* ignored */ }
compLevel = WB.getMethodCompilationLevel(m);
}
}
}
// to be overridden as appropriate
public int getExpectedIResult() {
return 0;
}
// to be overridden as appropriate
public long getExpectedLResult() {
return 0;
}
// to be overridden as appropriate
public float getExpectedFResult() {
return 0f;
}
// to be overridden as appropriate
public double getExpectedDResult() {
return 0d;
}
private void checkResult() {
Asserts.assertEQ(getExpectedIResult(), iResult, "checking iResult");
Asserts.assertEQ(getExpectedLResult(), lResult, "checking lResult");
Asserts.assertEQ(getExpectedFResult(), fResult, "checking fResult");
Asserts.assertEQ(getExpectedDResult(), dResult, "checking dResult");
}
public void msg(String m) {
System.out.println();
System.out.println("###(Target) " + m);
System.out.println();
}
// The object passed will be ArgEscape if it was NoEscape before.
public final void dontinline_make_arg_escape(XYVal xy) {
}
/**
* Call a method indirectly using reflection. The indirection is a limit for escape
* analysis in the sense that the VM need not search beyond for frames that might have
* an object being read by an JVMTI agent as ArgEscape.
* @param receiver The receiver object of the call.
* @param methodName The name of the method to be called.
*/
public final void dontinline_call_with_entry_frame(Object receiver, String methodName) {
Asserts.assertTrue(warmupDone, "We want to take the slow path through jni, so don't call in warmup");
Class<?> cls = receiver.getClass();
Class<?>[] none = {};
java.lang.reflect.Method m;
try {
m = cls.getDeclaredMethod(methodName, none);
m.invoke(receiver);
} catch (Exception e) {
Asserts.fail("Call through reflection failed", e);
}
}
static class LinkedList {
LinkedList l;
public long[] array;
public LinkedList(LinkedList l, int size) {
this.array = size > 0 ? new long[size] : null;
this.l = l;
}
}
public LinkedList consumedMemory;
public void consumeAllMemory() {
msg("consume all memory");
int size = 128 * 1024 * 1024;
while(true) {
try {
while(true) {
consumedMemory = new LinkedList(consumedMemory, size);
}
} catch(OutOfMemoryError oom) {
if (size == 0) break;
}
size = size / 2;
}
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Test Cases
//
/////////////////////////////////////////////////////////////////////////////
// make sure a compiled frame is not deoptimized if an escaping local is accessed
class EAGetWithoutMaterializeTarget extends EATestCaseBaseTarget {
public XYVal getAway;
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
getAway = xy; // allocated object escapes
dontinline_brkpt();
iResult = xy.x + xy.y;
}
@Override
public int getExpectedIResult() {
return 4 + 2;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
return false;
}
}
class EAGetWithoutMaterialize extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
checkPrimitiveField(o, FD.I, "x", 4);
checkPrimitiveField(o, FD.I, "y", 2);
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Tests the following:
//
// 1. Debugger can obtain a reference to a scalar replaced object R from java thread J.
// See runTestCase.
//
// 2. Subsequent modifications of R by J are noticed by the debugger.
// See checkPostConditions.
//
class EAMaterializeLocalVariableUponGet extends EATestCaseBaseDebugger {
private ObjectReference o;
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
// check 1.
o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
// o is referenced in checkPostConditions() and must not be gc'ed.
o.disableCollection();
checkPrimitiveField(o, FD.I, "x", 4);
checkPrimitiveField(o, FD.I, "y", 2);
}
@Override
public void checkPostConditions() throws Exception {
super.checkPostConditions();
// check 2.
checkPrimitiveField(o, FD.I, "x", 5);
}
}
class EAMaterializeLocalVariableUponGetTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
dontinline_brkpt(); // Debugger obtains scalar replaced object at this point.
xy.x += 1; // Change scalar replaced object after debugger obtained a reference to it.
iResult = xy.x + xy.y;
}
@Override
public int getExpectedIResult() {
return 4 + 2 + 1;
}
}
/////////////////////////////////////////////////////////////////////////////
// Test if an eliminated object can be reallocated in a frame with an active
// call that will return another object
class EAMaterializeLocalAtObjectReturn extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "xy");
checkPrimitiveField(o, FD.I, "x", 4);
checkPrimitiveField(o, FD.I, "y", 2);
}
}
class EAMaterializeLocalAtObjectReturnTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
Integer io = // Read xy here triggers reallocation
dontinline_brkpt_return_Integer();
iResult = xy.x + xy.y + io;
}
public Integer dontinline_brkpt_return_Integer() {
// We can't break directly in this method, as this results in making
// the test method not entrant caused by an existing dependency
dontinline_brkpt();
return Integer.valueOf(23);
}
@Override
public int getExpectedIResult() {
return 4 + 2 + 23;
}
}
/////////////////////////////////////////////////////////////////////////////
// Test if an eliminated object can be reallocated *just* before a call returns an object.
// (See nmethod::is_at_poll_return())
// Details: the callee method has just one safepoint poll at the return. The other safepoint
// is at the end of an iteration of the endless loop. We can detect if we suspended the target
// there because the local xy is out of scope there.
class EAMaterializeLocalAtObjectPollReturnReturn extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
msg("Resume " + env.targetMainThread);
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
ObjectReference o = null;
int retryCount = 0;
do {
env.targetMainThread.suspend();
printStack(env.targetMainThread);
try {
o = getLocalRef(env.targetMainThread.frame(0), XYVAL_NAME, "xy");
} catch (Exception e) {
++retryCount;
msg("The local variable xy is out of scope because we suspended at the wrong bci. Resume and try again! (" + retryCount + ")");
env.targetMainThread.resume();
if ((retryCount % 10) == 0) {
Thread.sleep(200);
}
}
} while (o == null);
checkPrimitiveField(o, FD.I, "x", 4);
checkPrimitiveField(o, FD.I, "y", 2);
terminateEndlessLoop();
}
}
class EAMaterializeLocalAtObjectPollReturnReturnTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
loopCount = 3;
doLoop = true;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
public void dontinline_testMethod() {
long result = 0;
while (doLoop && loopCount-- > 0) {
targetIsInLoop = true;
XYVal xy = new XYVal(4, 2);
Integer io = // Read xy here triggers reallocation just before the call returns
dontinline_brkpt_return_Integer();
result += xy.x + xy.y + io;
} // Here is a second safepoint. We were suspended here if xy is not in scope.
targetIsInLoop = false;
lResult = result;
}
public Integer dontinline_brkpt_return_Integer() {
return Integer.valueOf(23);
}
@Override
public long getExpectedLResult() {
return (Long.MAX_VALUE - loopCount) * (4+2+23);
}
}
/////////////////////////////////////////////////////////////////////////////
// Test case collection that tests rematerialization of different
// array types where the first element is always not constant and the
// other elements are constants. Not constant values are stored in
// the stack frame for rematerialization whereas constants are kept
// in the debug info of the nmethod.
class EAMaterializeIntArrayTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
int nums[] = {NOT_CONST_1I , 2, 3};
dontinline_brkpt();
iResult = nums[0] + nums[1] + nums[2];
}
@Override
public int getExpectedIResult() {
return NOT_CONST_1I + 2 + 3;
}
}
class EAMaterializeIntArray extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
int[] expectedVals = {1, 2, 3};
checkLocalPrimitiveArray(bpe.thread().frame(1), "nums", FD.I, expectedVals);
}
}
/////////////////////////////////////////////////////////////////////////////
class EAMaterializeLongArrayTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
long nums[] = {NOT_CONST_1L , 2, 3};
dontinline_brkpt();
lResult = nums[0] + nums[1] + nums[2];
}
@Override
public long getExpectedLResult() {
return NOT_CONST_1L + 2 + 3;
}
}
class EAMaterializeLongArray extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
long[] expectedVals = {1, 2, 3};
checkLocalPrimitiveArray(bpe.thread().frame(1), "nums", FD.J, expectedVals);
}
}
/////////////////////////////////////////////////////////////////////////////
class EAMaterializeFloatArrayTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
float nums[] = {NOT_CONST_1F , 2.2f, 3.3f};
dontinline_brkpt();
fResult = nums[0] + nums[1] + nums[2];
}
@Override
public float getExpectedFResult() {
return NOT_CONST_1F + 2.2f + 3.3f;
}
}
class EAMaterializeFloatArray extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
float[] expectedVals = {1.1f, 2.2f, 3.3f};
checkLocalPrimitiveArray(bpe.thread().frame(1), "nums", FD.F, expectedVals);
}
}
/////////////////////////////////////////////////////////////////////////////
class EAMaterializeDoubleArrayTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
double nums[] = {NOT_CONST_1D , 2.2d, 3.3d};
dontinline_brkpt();
dResult = nums[0] + nums[1] + nums[2];
}
@Override
public double getExpectedDResult() {
return NOT_CONST_1D + 2.2d + 3.3d;
}
}
class EAMaterializeDoubleArray extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
double[] expectedVals = {1.1d, 2.2d, 3.3d};
checkLocalPrimitiveArray(bpe.thread().frame(1), "nums", FD.D, expectedVals);
}
}
/////////////////////////////////////////////////////////////////////////////
class EAMaterializeObjectArrayTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
Long nums[] = {NOT_CONST_1_OBJ , CONST_2_OBJ, CONST_3_OBJ};
dontinline_brkpt();
lResult = nums[0] + nums[1] + nums[2];
}
@Override
public long getExpectedLResult() {
return 1 + 2 + 3;
}
}
class EAMaterializeObjectArray extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ReferenceType clazz = bpe.thread().frame(0).location().declaringType();
ObjectReference[] expectedVals = {
(ObjectReference) clazz.getValue(clazz.fieldByName("NOT_CONST_1_OBJ")),
(ObjectReference) clazz.getValue(clazz.fieldByName("CONST_2_OBJ")),
(ObjectReference) clazz.getValue(clazz.fieldByName("CONST_3_OBJ"))
};
checkLocalObjectArray(bpe.thread().frame(1), "nums", "java.lang.Long[]", expectedVals);
}
}
/////////////////////////////////////////////////////////////////////////////
// Materialize an object whose fields have constant and not constant values at
// the point where the object is materialized.
class EAMaterializeObjectWithConstantAndNotConstantValuesTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
ILFDO o = new ILFDO(NOT_CONST_1I, 2,
NOT_CONST_1L, 2L,
NOT_CONST_1F, 2.1F,
NOT_CONST_1D, 2.1D,
NOT_CONST_1_OBJ, CONST_2_OBJ
);
dontinline_brkpt();
dResult =
o.i + o.i2 + o.l + o.l2 + o.f + o.f2 + o.d + o.d2 + o.o + o.o2;
}
@Override
public double getExpectedDResult() {
return NOT_CONST_1I + 2 + NOT_CONST_1L + 2L + NOT_CONST_1F + 2.1F + NOT_CONST_1D + 2.1D + NOT_CONST_1_OBJ + CONST_2_OBJ;
}
}
class EAMaterializeObjectWithConstantAndNotConstantValues extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference o = getLocalRef(bpe.thread().frame(1), "ILFDO", "o");
checkPrimitiveField(o, FD.I, "i", 1);
checkPrimitiveField(o, FD.I, "i2", 2);
checkPrimitiveField(o, FD.J, "l", 1L);
checkPrimitiveField(o, FD.J, "l2", 2L);
checkPrimitiveField(o, FD.F, "f", 1.1f);
checkPrimitiveField(o, FD.F, "f2", 2.1f);
checkPrimitiveField(o, FD.D, "d", 1.1d);
checkPrimitiveField(o, FD.D, "d2", 2.1d);
ReferenceType clazz = bpe.thread().frame(1).location().declaringType();
ObjectReference[] expVals = {
(ObjectReference) clazz.getValue(clazz.fieldByName("NOT_CONST_1_OBJ")),
(ObjectReference) clazz.getValue(clazz.fieldByName("CONST_2_OBJ")),
};
checkObjField(o, "o", expVals[0]);
checkObjField(o, "o2", expVals[1]);
}
}
/////////////////////////////////////////////////////////////////////////////
// Two local variables reference the same object.
// Check if the debugger obtains the same object when reading the two variables
class EAMaterializeObjReferencedBy2LocalsTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(2, 3);
XYVal alias = xy;
dontinline_brkpt();
iResult = xy.x + alias.x;
}
@Override
public int getExpectedIResult() {
return 2 + 2;
}
}
class EAMaterializeObjReferencedBy2Locals extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference xy = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
ObjectReference alias = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "alias");
Asserts.assertSame(xy, alias, "xy and alias are expected to reference the same object");
}
}
/////////////////////////////////////////////////////////////////////////////
// Two local variables reference the same object.
// Check if it has the expected effect in the target if the debugger modifies the object.
class EAMaterializeObjReferencedBy2LocalsAndModifyTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(2, 3);
XYVal alias = xy;
dontinline_brkpt(); // debugger: alias.x = 42
iResult = xy.x + alias.x;
}
@Override
public int getExpectedIResult() {
return 42 + 42;
}
}
class EAMaterializeObjReferencedBy2LocalsAndModify extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference alias = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "alias");
setField(alias, "x", env.vm().mirrorOf(42));
}
}
/////////////////////////////////////////////////////////////////////////////
// Two local variables of the same compiled frame but in different virtual frames reference the same
// object.
// Check if the debugger obtains the same object when reading the two variables
class EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal xy = new XYVal(2, 3);
testMethod_inlined(xy);
iResult += xy.x;
}
public void testMethod_inlined(XYVal xy) {
XYVal alias = xy;
dontinline_brkpt();
iResult = alias.x;
}
@Override
public int getExpectedIResult() {
return 2 + 2;
}
}
class EAMaterializeObjReferencedBy2LocalsInDifferentVirtFrames extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference xy = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "xy");
ObjectReference alias = getLocalRef(bpe.thread().frame(1), "testMethod_inlined", "alias", XYVAL_NAME);
Asserts.assertSame(xy, alias, "xy and alias are expected to reference the same object");
}
}
/////////////////////////////////////////////////////////////////////////////
// Two local variables of the same compiled frame but in different virtual frames reference the same
// object.
// Check if it has the expected effect in the target if the debugger modifies the object.
class EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesAndModifyTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal xy = new XYVal(2, 3);
testMethod_inlined(xy); // debugger: xy.x = 42
iResult += xy.x;
}
public void testMethod_inlined(XYVal xy) {
XYVal alias = xy;
dontinline_brkpt();
iResult = alias.x;
}
@Override
public int getExpectedIResult() {
return 42 + 42;
}
}
class EAMaterializeObjReferencedBy2LocalsInDifferentVirtFramesAndModify extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference alias = getLocalRef(bpe.thread().frame(1), "testMethod_inlined", "alias", XYVAL_NAME);
setField(alias, "x", env.vm().mirrorOf(42));
}
}
/////////////////////////////////////////////////////////////////////////////
// Test materialization of an object referenced only from expression stack
class EAMaterializeObjReferencedFromOperandStackTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
@SuppressWarnings("unused")
XYVal xy1 = new XYVal(2, 3);
// Debugger breaks in call to dontinline_brkpt_ret_100() and reads
// the value of the local 'xy1'. This triggers materialization
// of the object on the operand stack
iResult = testMethodInlined(new XYVal(4, 2), dontinline_brkpt_ret_100());
}
public int testMethodInlined(XYVal xy2, int dontinline_brkpt_ret_100) {
return xy2.x + dontinline_brkpt_ret_100;
}
public int dontinline_brkpt_ret_100() {
dontinline_brkpt();
return 100;
}
@Override
public int getExpectedIResult() {
return 4 + 100;
}
}
class EAMaterializeObjReferencedFromOperandStack extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference xy1 = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "xy1");
checkPrimitiveField(xy1, FD.I, "x", 2);
checkPrimitiveField(xy1, FD.I, "y", 3);
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Tests a regression in the implementation by setting the value of a local int which triggers the
* creation of a deferred update and then getting the reference to a scalar replaced object. The
* issue was that the scalar replaced object was not reallocated. Because of the deferred update it
* was assumed that the reallocation already happened.
*/
class EAMaterializeLocalVariableUponGetAfterSetInteger extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
setLocal(bpe.thread().frame(1), "i", env.vm().mirrorOf(43));
ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
checkPrimitiveField(o, FD.I, "x", 4);
checkPrimitiveField(o, FD.I, "y", 2);
}
}
class EAMaterializeLocalVariableUponGetAfterSetIntegerTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
int i = 42;
dontinline_brkpt();
iResult = xy.x + xy.y + i;
}
@Override
public int getExpectedIResult() {
return 4 + 2 + 43;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
return true; // setting local variable i always triggers deoptimization
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Locking Tests
//
/////////////////////////////////////////////////////////////////////////////
class EARelockingSimple extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "l1");
}
}
class EARelockingSimpleTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized (l1) {
dontinline_brkpt();
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Like {@link EARelockingSimple}. The difference is that there are many
* lightweight locked objects when the relocking is done. With
* <code>-XX:LockingMode=2</code> the lock stack of the thread will be full
* because of this.
*/
class EARelockingWithManyLightweightLocks extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "l1");
}
}
class EARelockingWithManyLightweightLocksTarget extends EATestCaseBaseTarget {
static class Lock {
}
public static Lock L0, L1, L2, L3, L4, L5, L6, L7, L8, L9;
void allocateLocks() {
L0 = new Lock();
L1 = new Lock();
L2 = new Lock();
L3 = new Lock();
L4 = new Lock();
L5 = new Lock();
L6 = new Lock();
L7 = new Lock();
L8 = new Lock();
L9 = new Lock();
}
@Override
public void setUp() {
super.setUp();
allocateLocks();
}
@Override
public void warmupDone() {
super.warmupDone();
allocateLocks(); // get rid of already inflated ones
}
public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized(L0) {
synchronized(L1) {
synchronized(L2) {
synchronized(L3) {
synchronized(L4) {
synchronized(L5) {
synchronized(L6) {
synchronized(L7) {
synchronized(L8) {
synchronized(L9) {
synchronized (l1) {
dontinline_brkpt();
}
}
}
}
}
}
}
}
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// The debugger reads and publishes an object with eliminated locking to an instance field.
// A 2nd thread in the debuggee finds it there and changes its state using a synchronized method.
// Without eager relocking the accesses are unsynchronized which can be observed.
class EARelockingSimpleWithAccessInOtherThread extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
String l1ClassName = EARelockingSimpleWithAccessInOtherThreadTarget.SyncCounter.class.getName();
ObjectReference ctr = getLocalRef(bpe.thread().frame(1), l1ClassName, "l1");
setField(testCase, "sharedCounter", ctr);
terminateEndlessLoop();
}
}
class EARelockingSimpleWithAccessInOtherThreadTarget extends EATestCaseBaseTarget {
public static class SyncCounter {
private int val;
public synchronized int inc() { return val++; }
}
public volatile SyncCounter sharedCounter;
@Override
public void setUp() {
super.setUp();
doLoop = true;
Thread.ofPlatform().daemon().start(() -> {
while (doLoop) {
SyncCounter ctr = sharedCounter;
if (ctr != null) {
ctr.inc();
}
}
});
}
public void dontinline_testMethod() {
SyncCounter l1 = new SyncCounter();
synchronized (l1) { // Eliminated locking
l1.inc();
dontinline_brkpt(); // Debugger publishes l1 to sharedCounter.
iResult = l1.inc(); // Changes by the 2nd thread will be observed if l1
// was not relocked before passing it to the debugger.
}
}
@Override
public int getExpectedIResult() {
return 1;
}
}
/////////////////////////////////////////////////////////////////////////////
// The debugger reads and publishes an object with eliminated locking to an instance field.
// A 2nd thread in the debuggee finds it there and changes its state using a synchronized method.
// Without eager relocking the accesses are unsynchronized which can be observed.
// This is a variant of EARelockingSimpleWithAccessInOtherThread with a dynamic call (not devirtualized).
class EARelockingSimpleWithAccessInOtherThread_02_DynamicCall extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
String l1ClassName = EARelockingSimpleWithAccessInOtherThread_02_DynamicCall_Target.SyncCounter.class.getName();
ObjectReference ctr = getLocalRef(bpe.thread().frame(2), l1ClassName, "l1");
setField(testCase, "sharedCounter", ctr);
terminateEndlessLoop();
}
}
class EARelockingSimpleWithAccessInOtherThread_02_DynamicCall_Target extends EATestCaseBaseTarget {
public static final BrkPtDispatchA[] disp =
{new BrkPtDispatchA(), new BrkPtDispatchB(), new BrkPtDispatchC(), new BrkPtDispatchD()};
public static class BrkPtDispatchA {
public EATestCaseBaseTarget testCase;
public void dontinline_brkpt() { testCase.dontinline_brkpt(); }
}
public static class BrkPtDispatchB extends BrkPtDispatchA {
@Override
public void dontinline_brkpt() { testCase.dontinline_brkpt(); }
}
public static class BrkPtDispatchC extends BrkPtDispatchA {
@Override
public void dontinline_brkpt() { testCase.dontinline_brkpt(); }
}
public static class BrkPtDispatchD extends BrkPtDispatchA {
@Override
public void dontinline_brkpt() {
testCase.dontinline_brkpt();
}
}
public static class SyncCounter {
private int val;
public synchronized int inc() { return val++; }
}
public volatile SyncCounter sharedCounter;
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
for (BrkPtDispatchA d : disp) {
d.testCase = this;
}
doLoop = true;
new Thread(() -> {
while (doLoop) {
SyncCounter ctr = sharedCounter;
if (ctr != null) {
ctr.inc();
}
}
}).start();
}
public int dispCount;
public void dontinline_testMethod() {
SyncCounter l1 = new SyncCounter();
synchronized (l1) { // Eliminated locking
l1.inc();
// Use different types for the subsequent call to prevent devirtualization.
BrkPtDispatchA d = disp[(dispCount++) & 3];
d.dontinline_brkpt(); // Dynamic call. Debugger publishes l1 to sharedCounter.
iResult = l1.inc(); // Changes by the 2nd thread will be observed if l1
// was not relocked before passing it to the debugger.
}
}
@Override
public int getExpectedIResult() {
return 1;
}
}
/////////////////////////////////////////////////////////////////////////////
// Test recursive locking
class EARelockingRecursiveTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized (l1) {
testMethod_inlined(l1);
}
}
public void testMethod_inlined(XYVal l2) {
synchronized (l2) {
dontinline_brkpt();
}
}
}
class EARelockingRecursive extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
/////////////////////////////////////////////////////////////////////////////
// Object ref l1 is retrieved by the debugger at a location where nested locks are omitted. The
// accessed object is globally reachable already before the access, therefore no relocking is done.
class EARelockingNestedInflatedTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
// Access does not trigger deopt., as escape state is already global escape.
return false;
}
public void dontinline_testMethod() {
XYVal l1 = inflatedLock;
synchronized (l1) {
testMethod_inlined(l1);
}
}
public void testMethod_inlined(XYVal l2) {
synchronized (l2) { // eliminated nested locking
dontinline_brkpt();
}
}
}
class EARelockingNestedInflated extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Like {@link EARelockingNestedInflated} with the difference that there is
* a scalar replaced object in the scope from which the object with eliminated nested locking
* is read. This triggers materialization and relocking.
*/
class EARelockingNestedInflated_02 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
class EARelockingNestedInflated_02Target extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
@SuppressWarnings("unused")
XYVal xy = new XYVal(1, 1); // scalar replaced
XYVal l1 = inflatedLock; // read by debugger
synchronized (l1) {
testMethod_inlined(l1);
}
}
public void testMethod_inlined(XYVal l2) {
synchronized (l2) { // eliminated nested locking
dontinline_brkpt();
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Like {@link EARelockingNestedInflated_02} with the difference that the
* inflation of the lock happens because of contention.
*/
class EARelockingNestedInflated_03 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
class EARelockingNestedInflated_03Target extends EATestCaseBaseTarget {
public XYVal lockInflatedByContention;
public boolean doLockNow;
public EATestCaseBaseTarget testCase;
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
lockInflatedByContention = new XYVal(1, 1);
testCase = this;
}
@Override
public void warmupDone() {
super.warmupDone();
// Use new lock. lockInflatedByContention might have been inflated because of recursion.
lockInflatedByContention = new XYVal(1, 1);
// Start thread that tries to enter lockInflatedByContention while the main thread owns it -> inflation
DebuggeeWrapper.newThread(() -> {
while (true) {
synchronized (testCase) {
try {
if (doLockNow) {
doLockNow = false; // reset for main thread
testCase.notify();
break;
}
testCase.wait();
} catch (InterruptedException e) { /* ignored */ }
}
}
synchronized (lockInflatedByContention) { // will block and trigger inflation
msg(Thread.currentThread().getName() + ": acquired lockInflatedByContention");
}
}, testCaseName + ": Lock Contender (test thread)").start();
}
public void dontinline_testMethod() {
@SuppressWarnings("unused")
XYVal xy = new XYVal(1, 1); // scalar replaced
XYVal l1 = lockInflatedByContention; // read by debugger
synchronized (l1) {
testMethod_inlined(l1);
}
}
public void testMethod_inlined(XYVal l2) {
synchronized (l2) { // eliminated nested locking
dontinline_notifyOtherThread();
dontinline_brkpt();
}
}
public void dontinline_notifyOtherThread() {
if (!warmupDone) {
return;
}
synchronized (testCase) {
doLockNow = true;
testCase.notify();
// wait for other thread to reset doLockNow again
while (doLockNow) {
try {
testCase.wait();
} catch (InterruptedException e) { /* ignored */ }
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Checks if an eliminated lock of an ArgEscape object l1 can be relocked if
* l1 is locked in a callee frame.
*/
class EARelockingArgEscapeLWLockedInCalleeFrame extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
class EARelockingArgEscapeLWLockedInCalleeFrameTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal l1 = new XYVal(1, 1); // ArgEscape
synchronized (l1) { // eliminated
l1.dontinline_sync_method(this); // l1 escapes
}
}
@Override
public boolean testFrameShouldBeDeoptimized() {
// Graal does not provide debug info about arg escape objects, therefore the frame is not deoptimized
return !UseJVMCICompiler && super.testFrameShouldBeDeoptimized();
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Similar to {@link EARelockingArgEscapeLWLockedInCalleeFrame}. In addition
* the test method has got a scalar replaced object with eliminated locking.
* This pattern matches a regression in the implementation.
*/
class EARelockingArgEscapeLWLockedInCalleeFrame_2 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
class EARelockingArgEscapeLWLockedInCalleeFrame_2Target extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal l1 = new XYVal(1, 1); // ArgEscape
XYVal l2 = new XYVal(4, 2); // NoEscape, scalar replaced
synchronized (l1) { // eliminated
synchronized (l2) { // eliminated
l1.dontinline_sync_method(this); // l1 escapes
}
}
iResult = l2.x + l2.y;
}
@Override
public int getExpectedIResult() {
return 6;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Similar to {@link EARelockingArgEscapeLWLockedInCalleeFrame_2Target}. It does
* not use recursive locking and exposed a bug in the lightweight-locking implementation.
*/
class EARelockingArgEscapeLWLockedInCalleeFrameNoRecursive extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(2), XYVAL_NAME, "l1");
}
}
class EARelockingArgEscapeLWLockedInCalleeFrameNoRecursiveTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal l1 = new XYVal(1, 1); // NoEscape, scalar replaced
XYVal l2 = new XYVal(4, 2); // NoEscape, scalar replaced
XYVal l3 = new XYVal(5, 3); // ArgEscape
synchronized (l1) { // eliminated
synchronized (l2) { // eliminated
l3.dontinline_sync_method(this); // l3 escapes
}
}
iResult = l2.x + l2.y;
}
@Override
public int getExpectedIResult() {
return 6;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Test relocking eliminated (nested) locks of an object on which the
* target thread currently waits.
*/
class EARelockingObjectCurrentlyWaitingOn extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
env.vm().resume();
boolean inWait = false;
do {
Thread.sleep(100);
env.targetMainThread.suspend();
printStack(env.targetMainThread);
inWait = env.targetMainThread.frame(0).location().method().name().equals("wait0");
if (!inWait) {
msg("Target not yet in java.lang.Object.wait(long).");
env.targetMainThread.resume();
}
} while(!inWait);
StackFrame testMethodFrame = env.targetMainThread.frame(5);
// Access triggers relocking of all eliminated locks, including nested locks of l1 which references
// the object on which the target main thread is currently waiting.
ObjectReference l0 = getLocalRef(testMethodFrame, EARelockingObjectCurrentlyWaitingOnTarget.ForLocking.class.getName(), "l0");
Asserts.assertEQ(l0.entryCount(), 1, "wrong entry count");
ObjectReference l1 = getLocalRef(testMethodFrame, EARelockingObjectCurrentlyWaitingOnTarget.ForLocking.class.getName(), "l1");
Asserts.assertEQ(l1.entryCount(), 0, "wrong entry count");
setField(testCase, "objToNotifyOn", l1);
}
}
class EARelockingObjectCurrentlyWaitingOnTarget extends EATestCaseBaseTarget {
public static class ForLocking {
}
public volatile Object objToNotifyOn; // debugger assigns value when notify thread should call objToNotifyOn.notifyAll()
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
@Override
public void warmupDone() {
super.warmupDone();
Thread t = new Thread(() -> doNotify());
t.start();
}
public void doNotify() {
while (objToNotifyOn == null) {
try {
msg("objToNotifyOn is still null");
Thread.sleep(100);
} catch (InterruptedException e) { /* ignored */ }
}
synchronized (objToNotifyOn) {
// will be received by the target main thread waiting in dontinline_waitWhenWarmupDone
msg("calling objToNotifyOn.notifyAll()");
objToNotifyOn.notifyAll();
}
}
@Override
public boolean testFrameShouldBeDeoptimized() {
return false;
}
@Override
public void dontinline_testMethod() throws Exception {
ForLocking l0 = new ForLocking(); // will be scalar replaced; access triggers realloc/relock
ForLocking l1 = new ForLocking();
synchronized (l0) {
synchronized (l1) {
testMethod_inlined(l1);
}
}
}
public void testMethod_inlined(ForLocking l2) throws Exception {
synchronized (l2) { // eliminated nested locking
dontinline_waitWhenWarmupDone(l2);
}
}
public void dontinline_waitWhenWarmupDone(ForLocking l2) throws Exception {
if (warmupDone) {
l2.wait();
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Test relocking eliminated @ValueBased object.
*/
class EARelockingValueBased extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference o = getLocalRef(bpe.thread().frame(1), Integer.class.getName(), "l1");
}
}
class EARelockingValueBasedTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
Integer l1 = new Integer(255);
synchronized (l1) {
dontinline_brkpt();
}
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Test cases that require deoptimization even though neither locks
// nor allocations are eliminated at the point where escape state is changed.
//
/////////////////////////////////////////////////////////////////////////////
/**
* Let xy be NoEscape whose allocation cannot be eliminated (simulated by
* -XX:-EliminateAllocations). The holding compiled frame has to be deoptimized when debugger
* accesses xy because afterwards locking on xy is omitted.
* Note: there are no EA based optimizations at the escape point.
*/
class EADeoptFrameAfterReadLocalObject_01 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference xy = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
}
}
class EADeoptFrameAfterReadLocalObject_01Target extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(1, 1);
dontinline_brkpt(); // Debugger reads xy, when there are no virtual objects or eliminated locks in scope
synchronized (xy) { // Locking is eliminated.
xy.x++;
xy.y++;
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Similar to {@link EADeoptFrameAfterReadLocalObject_01} with the difference that the debugger
* reads xy from an inlined callee. So xy is NoEscape instead of ArgEscape.
*/
class EADeoptFrameAfterReadLocalObject_01BTarget extends EATestCaseBaseTarget {
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public void dontinline_testMethod() {
XYVal xy = new XYVal(1, 1);
callee(xy); // Debugger acquires ref to xy from inlined callee
// xy is NoEscape, nevertheless the object is not replaced
// by scalars if running with -XX:-EliminateAllocations.
// In that case there are no EA based optimizations were
// the debugger reads the NoEscape object.
synchronized (xy) { // Locking is eliminated.
xy.x++;
xy.y++;
}
}
public void callee(XYVal xy) {
dontinline_brkpt(); // Debugger reads xy.
// There are no virtual objects or eliminated locks.
}
}
class EADeoptFrameAfterReadLocalObject_01B extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference xy = getLocalRef(bpe.thread().frame(1), "callee", "xy", XYVAL_NAME);
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Let xy be ArgEscape. The frame dontinline_testMethod() has to be deoptimized when debugger
* acquires xy from dontinline_callee() because afterwards locking on xy is omitted.
* Note: there are no EA based optimizations at the escape point.
*/
class EADeoptFrameAfterReadLocalObject_02 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference xy = getLocalRef(bpe.thread().frame(1), "dontinline_callee", "xy", XYVAL_NAME);
}
}
class EADeoptFrameAfterReadLocalObject_02Target extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(1, 1);
dontinline_callee(xy); // xy is ArgEscape, debugger acquires ref to xy from callee
synchronized (xy) { // Locking is eliminated.
xy.x++;
xy.y++;
}
}
public void dontinline_callee(XYVal xy) {
dontinline_brkpt(); // Debugger reads xy.
// There are no virtual objects or eliminated locks.
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
// Graal does not provide debug info about arg escape objects, therefore the frame is not deoptimized
return !UseJVMCICompiler && super.testFrameShouldBeDeoptimized();
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Similar to {@link EADeoptFrameAfterReadLocalObject_02} there is an ArgEscape object xy, but in
* contrast it is not in the parameter list of a call when the debugger reads an object.
* Therefore the frame of the test method should not be deoptimized
*/
class EADeoptFrameAfterReadLocalObject_02B extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference xy = getLocalRef(bpe.thread().frame(1), "dontinline_callee", "xy", XYVAL_NAME);
}
}
class EADeoptFrameAfterReadLocalObject_02BTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(1, 1);
dontinline_make_arg_escape(xy); // because of this call xy is ArgEscape
dontinline_callee(); // xy is ArgEscape, but not a parameter of this call
synchronized (xy) { // Locking is eliminated.
xy.x++;
xy.y++;
}
}
public void dontinline_callee() {
@SuppressWarnings("unused")
XYVal xy = new XYVal(2, 2);
dontinline_brkpt(); // Debugger reads xy.
// No need to deoptimize the caller frame
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
return false;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Similar to {@link EADeoptFrameAfterReadLocalObject_02} there is an ArgEscape object xy in
* dontinline_testMethod() which is being passed as parameter when the debugger accesses a local object.
* Nevertheless dontinline_testMethod must not be deoptimized because there is an entry frame
* between it and the frame accessed by the debugger.
*/
class EADeoptFrameAfterReadLocalObject_02C extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
@SuppressWarnings("unused")
ObjectReference xy = getLocalRef(bpe.thread().frame(1), "dontinline_callee_accessed_by_debugger", "xy", XYVAL_NAME);
}
}
class EADeoptFrameAfterReadLocalObject_02CTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(1, 1);
dontinline_callee(xy); // xy is ArgEscape and being passed as parameter
synchronized (xy) { // Locking is eliminated.
xy.x++;
xy.y++;
}
}
public void dontinline_callee(XYVal xy) {
if (warmupDone) {
dontinline_call_with_entry_frame(this, "dontinline_callee_accessed_by_debugger");
}
}
public void dontinline_callee_accessed_by_debugger() {
@SuppressWarnings("unused")
XYVal xy = new XYVal(2, 2);
dontinline_brkpt(); // Debugger reads xy.
// No need to deoptimize the caller frame
}
@Override
public void setUp() {
super.setUp();
// the method depth in debuggee is 11 as it includes all hidden frames
// the expected method depth is 6 excluding 5 hidden frames
testMethodDepth = 11-5;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
return false;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Let xy be NoEscape whose allocation cannot be eliminated (e.g. because of
* -XX:-EliminateAllocations). The holding compiled frame has to be deoptimized when debugger
* accesses xy because the following field accesses get eliminated. Note: there are no EA based
* optimizations at the escape point.
*/
class EADeoptFrameAfterReadLocalObject_03 extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
ObjectReference xy = getLocalRef(bpe.thread().frame(1), XYVAL_NAME, "xy");
setField(xy, "x", env.vm().mirrorOf(1));
}
}
class EADeoptFrameAfterReadLocalObject_03Target extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(0, 1);
dontinline_brkpt(); // Debugger reads xy, when there are no virtual objects or
// eliminated locks in scope and modifies xy.x
iResult = xy.x + xy.y; // Loads are replaced by constants 0 and 1.
}
@Override
public int getExpectedIResult() {
return 1 + 1;
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Monitor info tests
//
/////////////////////////////////////////////////////////////////////////////
class EAGetOwnedMonitorsTarget extends EATestCaseBaseTarget {
public long checkSum;
public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized (l1) {
dontinline_endlessLoop();
}
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
}
class EAGetOwnedMonitors extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
msg("resume");
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
// In contrast to JVMTI, JDWP requires a target thread to be suspended, before the owned monitors can be queried
msg("suspend target");
env.targetMainThread.suspend();
msg("Get owned monitors");
List<ObjectReference> monitors = env.targetMainThread.ownedMonitors();
Asserts.assertEQ(monitors.size(), 1, "unexpected number of owned monitors");
terminateEndlessLoop();
}
}
/////////////////////////////////////////////////////////////////////////////
class EAEntryCountTarget extends EATestCaseBaseTarget {
public long checkSum;
public void dontinline_testMethod() {
XYVal l1 = new XYVal(4, 2);
synchronized (l1) {
inline_testMethod2(l1);
}
}
public void inline_testMethod2(XYVal l1) {
synchronized (l1) {
dontinline_endlessLoop();
}
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
}
class EAEntryCount extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
msg("resume");
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
// In contrast to JVMTI, JDWP requires a target thread to be suspended, before the owned monitors can be queried
msg("suspend target");
env.targetMainThread.suspend();
msg("Get owned monitors");
List<ObjectReference> monitors = env.targetMainThread.ownedMonitors();
Asserts.assertEQ(monitors.size(), 1, "unexpected number of owned monitors");
msg("Get entry count");
int entryCount = monitors.get(0).entryCount();
Asserts.assertEQ(entryCount, 2, "wrong entry count");
terminateEndlessLoop();
}
}
/////////////////////////////////////////////////////////////////////////////
//
// PopFrame tests
//
/////////////////////////////////////////////////////////////////////////////
/**
* PopFrame into caller frame with scalar replaced objects.
*/
class EAPopFrameNotInlined extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
printStack(bpe.thread());
msg("PopFrame");
bpe.thread().popFrames(bpe.thread().frame(0));
msg("PopFrame DONE");
}
@Override
public boolean shouldSkip() {
// And Graal currently doesn't support PopFrame
return super.shouldSkip() || env.targetVMOptions.UseJVMCICompiler;
}
}
class EAPopFrameNotInlinedTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
dontinline_brkpt();
iResult = xy.x + xy.y;
}
@Override
public boolean testFrameShouldBeDeoptimized() {
// Test is only performed after the frame pop.
// Then dontinline_testMethod is interpreted.
return false;
}
@Override
public int getExpectedIResult() {
return 4 + 2;
}
@Override
public boolean shouldSkip() {
// And Graal currently doesn't support PopFrame
return super.shouldSkip() || UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Pop frames into {@link EAPopFrameNotInlinedReallocFailureTarget#dontinline_testMethod()} which
* holds scalar replaced objects. In preparation of the pop frame operations the vm eagerly
* reallocates scalar replaced objects to avoid failures when actually popping the frames. We provoke
* a reallocation failures and expect {@link VMOutOfMemoryException}.
*/
class EAPopFrameNotInlinedReallocFailure extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
ThreadReference thread = bpe.thread();
printStack(thread);
// frame[0]: EATestCaseBaseTarget.dontinline_brkpt()
// frame[1]: EAPopFrameNotInlinedReallocFailureTarget.dontinline_consume_all_memory_brkpt()
// frame[2]: EAPopFrameNotInlinedReallocFailureTarget.dontinline_testMethod()
// frame[3]: EATestCaseBaseTarget.run()
// frame[4]: EATestsTarget.main(java.lang.String[])
msg("PopFrame");
boolean coughtOom = false;
try {
// try to pop dontinline_consume_all_memory_brkpt
thread.popFrames(thread.frame(1));
} catch (VMOutOfMemoryException oom) {
// as expected
msg("cought OOM");
coughtOom = true;
}
freeAllMemory();
// We succeeded to pop just one frame. When we continue, we will call dontinline_brkpt() again.
Asserts.assertTrue(coughtOom, "PopFrame should have triggered an OOM exception in target");
String expectedTopFrame = "dontinline_consume_all_memory_brkpt";
Asserts.assertEQ(expectedTopFrame, thread.frame(0).location().method().name());
printStack(thread);
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't provide all information about non-escaping objects in debug info
return super.shouldSkip() ||
!env.targetVMOptions.EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
env.targetVMOptions.ZGCIsSelected ||
env.targetVMOptions.ShenandoahGCIsSelected ||
env.targetVMOptions.DeoptimizeObjectsALot ||
env.targetVMOptions.UseJVMCICompiler;
}
}
class EAPopFrameNotInlinedReallocFailureTarget extends EATestCaseBaseTarget {
public boolean doneAlready;
public void dontinline_testMethod() {
long a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // scalar replaced
Vector10 v = new Vector10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // scalar replaced
dontinline_consume_all_memory_brkpt();
lResult = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9]
+ v.i0 + v.i1 + v.i2 + v.i3 + v.i4 + v.i5 + v.i6 + v.i7 + v.i8 + v.i9;
}
public void dontinline_consume_all_memory_brkpt() {
if (warmupDone && !doneAlready) {
doneAlready = true;
consumeAllMemory(); // provoke reallocation failure
dontinline_brkpt();
}
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
@Override
public long getExpectedLResult() {
long n = 10;
return 2*n*(n+1)/2;
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't provide all information about non-escaping objects in debug info
return super.shouldSkip() ||
!EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
ZGCIsSelected ||
ShenandoahGCIsSelected ||
DeoptimizeObjectsALot ||
UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Pop inlined top frame dropping into method with scalar replaced opjects.
*/
class EAPopInlinedMethodWithScalarReplacedObjectsReallocFailure extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
ThreadReference thread = env.targetMainThread;
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
thread.suspend();
printStack(thread);
// frame[0]: EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.inlinedCallForcedToReturn()
// frame[1]: EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.dontinline_testMethod()
// frame[2]: EATestCaseBaseTarget.run()
msg("Pop Frames");
boolean coughtOom = false;
try {
thread.popFrames(thread.frame(0)); // Request pop frame of inlinedCallForcedToReturn()
// reallocation is triggered here
} catch (VMOutOfMemoryException oom) {
// as expected
msg("cought OOM");
coughtOom = true;
}
printStack(thread);
// frame[0]: EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.inlinedCallForcedToReturn()
// frame[1]: EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.dontinline_testMethod()
// frame[2]: EATestCaseBaseTarget.run()
freeAllMemory();
setField(testCase, "loopCount", env.vm().mirrorOf(0)); // terminate loop
Asserts.assertTrue(coughtOom, "PopFrame should have triggered an OOM exception in target");
String expectedTopFrame = "inlinedCallForcedToReturn";
Asserts.assertEQ(expectedTopFrame, thread.frame(0).location().method().name());
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't provide all information about non-escaping objects in debug info
return super.shouldSkip() ||
!env.targetVMOptions.EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
env.targetVMOptions.ZGCIsSelected ||
env.targetVMOptions.ShenandoahGCIsSelected ||
env.targetVMOptions.DeoptimizeObjectsALot ||
env.targetVMOptions.UseJVMCICompiler;
}
}
class EAPopInlinedMethodWithScalarReplacedObjectsReallocFailureTarget extends EATestCaseBaseTarget {
public long checkSum;
public void dontinline_testMethod() {
long a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // scalar replaced
Vector10 v = new Vector10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // scalar replaced
long l = inlinedCallForcedToReturn();
lResult = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9]
+ v.i0 + v.i1 + v.i2 + v.i3 + v.i4 + v.i5 + v.i6 + v.i7 + v.i8 + v.i9;
}
public long inlinedCallForcedToReturn() {
long cs = checkSum;
dontinline_consumeAllMemory();
while (loopCount-- > 0) {
targetIsInLoop = true;
checkSum += checkSum % ++cs;
}
loopCount = 3;
targetIsInLoop = false;
return checkSum;
}
public void dontinline_consumeAllMemory() {
if (warmupDone && (loopCount > 3)) {
consumeAllMemory();
}
}
@Override
public long getExpectedLResult() {
long n = 10;
return 2*n*(n+1)/2;
}
@Override
public void setUp() {
super.setUp();
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't provide all information about non-escaping objects in debug info
return super.shouldSkip() ||
!EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
ZGCIsSelected ||
ShenandoahGCIsSelected ||
DeoptimizeObjectsALot ||
UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
//
// ForceEarlyReturn tests
//
/////////////////////////////////////////////////////////////////////////////
/**
* ForceEarlyReturn into caller frame with scalar replaced objects.
*/
class EAForceEarlyReturnNotInlined extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
BreakpointEvent bpe = resumeTo(TARGET_TESTCASE_BASE_NAME, "dontinline_brkpt", "()V");
ThreadReference thread = bpe.thread();
printStack(thread);
// frame[0]: EATestCaseBaseTarget.dontinline_brkpt()
// frame[1]: EATestCaseBaseTarget.dontinline_brkpt_iret()
// frame[2]: EAForceEarlyReturnNotInlinedTarget.dontinline_testMethod()
// frame[3]: EATestCaseBaseTarget.run()
// frame[4]: EATestsTarget.main(java.lang.String[])
msg("Step out");
env.stepOut(thread); // return from dontinline_brkpt
printStack(thread);
msg("ForceEarlyReturn");
thread.forceEarlyReturn(env.vm().mirrorOf(43)); // return from dontinline_brkpt_iret,
// does not trigger reallocation in contrast to PopFrame
msg("Step over line");
env.stepOverLine(thread); // reallocation is triggered here
printStack(thread);
msg("ForceEarlyReturn DONE");
}
@Override
public boolean shouldSkip() {
// Graal currently doesn't support Force Early Return
return super.shouldSkip() || env.targetVMOptions.UseJVMCICompiler;
}
}
class EAForceEarlyReturnNotInlinedTarget extends EATestCaseBaseTarget {
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
int i = dontinline_brkpt_iret();
iResult = xy.x + xy.y + i;
}
@Override
public int getExpectedIResult() {
return 4 + 2 + 43;
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
}
public boolean testFrameShouldBeDeoptimized() {
return true; // because of stepping
}
@Override
public boolean shouldSkip() {
// Graal currently doesn't support Force Early Return
return super.shouldSkip() || UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* ForceEarlyReturn at safepoint in frame with scalar replaced objects.
*/
class EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjects extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
ThreadReference thread = env.targetMainThread;
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
thread.suspend();
printStack(thread);
// frame[0]: EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsTarget.inlinedCallForcedToReturn()
// frame[1]: EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsTarget.dontinline_testMethod()
// frame[2]: EATestCaseBaseTarget.run()
msg("ForceEarlyReturn");
thread.forceEarlyReturn(env.vm().mirrorOf(43)); // Request force return 43 from inlinedCallForcedToReturn()
// reallocation is triggered here
msg("Step over instruction to do the forced return");
env.stepOverInstruction(thread);
printStack(thread);
msg("ForceEarlyReturn DONE");
}
@Override
public boolean shouldSkip() {
// Graal currently doesn't support Force Early Return
return super.shouldSkip() || env.targetVMOptions.UseJVMCICompiler;
}
}
class EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsTarget extends EATestCaseBaseTarget {
public int checkSum;
public void dontinline_testMethod() {
XYVal xy = new XYVal(4, 2);
int i = inlinedCallForcedToReturn();
iResult = xy.x + xy.y + i;
}
public int inlinedCallForcedToReturn() { // forced to return 43
int i = checkSum;
while (loopCount-- > 0) {
targetIsInLoop = true;
checkSum += checkSum % ++i;
}
loopCount = 3;
targetIsInLoop = false;
return checkSum;
}
@Override
public int getExpectedIResult() {
return 4 + 2 + 43;
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
public boolean testFrameShouldBeDeoptimized() {
return true; // because of stepping
}
@Override
public boolean shouldSkip() {
// Graal currently doesn't support Force Early Return
return super.shouldSkip() || UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* ForceEarlyReturn with reallocation failure.
*/
class EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailure extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
ThreadReference thread = env.targetMainThread;
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
thread.suspend();
printStack(thread);
// frame[0]: EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.inlinedCallForcedToReturn()
// frame[1]: EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailureTarget.dontinline_testMethod()
// frame[2]: EATestCaseBaseTarget.run()
msg("ForceEarlyReturn");
boolean coughtOom = false;
try {
thread.forceEarlyReturn(env.vm().mirrorOf(43)); // Request force return 43 from inlinedCallForcedToReturn()
// reallocation is triggered here
} catch (VMOutOfMemoryException oom) {
// as expected
msg("cought OOM");
coughtOom = true;
}
freeAllMemory();
Asserts.assertTrue(coughtOom, "ForceEarlyReturn should have triggered an OOM exception in target");
printStack(thread);
msg("ForceEarlyReturn(2)");
thread.forceEarlyReturn(env.vm().mirrorOf(43));
msg("Step over instruction to do the forced return");
env.stepOverInstruction(thread);
printStack(thread);
msg("ForceEarlyReturn DONE");
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't support Force Early Return
return super.shouldSkip() ||
!env.targetVMOptions.EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
env.targetVMOptions.ZGCIsSelected ||
env.targetVMOptions.ShenandoahGCIsSelected ||
env.targetVMOptions.DeoptimizeObjectsALot ||
env.targetVMOptions.UseJVMCICompiler;
}
}
class EAForceEarlyReturnOfInlinedMethodWithScalarReplacedObjectsReallocFailureTarget extends EATestCaseBaseTarget {
public int checkSum;
public void dontinline_testMethod() {
long a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // scalar replaced
Vector10 v = new Vector10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // scalar replaced
long l = inlinedCallForcedToReturn();
lResult = a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7] + a[8] + a[9]
+ v.i0 + v.i1 + v.i2 + v.i3 + v.i4 + v.i5 + v.i6 + v.i7 + v.i8 + v.i9 + l;
}
public long inlinedCallForcedToReturn() { // forced to return 43
long cs = checkSum;
dontinline_consumeAllMemory();
while (loopCount-- > 0) {
targetIsInLoop = true;
checkSum += checkSum % ++cs;
}
loopCount = 3;
targetIsInLoop = false;
return checkSum;
}
public void dontinline_consumeAllMemory() {
if (warmupDone) {
consumeAllMemory();
}
}
@Override
public long getExpectedLResult() {
long n = 10;
return 2*n*(n+1)/2 + 43;
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
@Override
public boolean shouldSkip() {
// OOMEs because of realloc failures with DeoptimizeObjectsALot are too random.
// And Graal currently doesn't support Force Early Return
return super.shouldSkip() ||
!EliminateAllocations ||
// With ZGC or Shenandoah the OOME is not always thrown as expected
ZGCIsSelected ||
ShenandoahGCIsSelected ||
DeoptimizeObjectsALot ||
UseJVMCICompiler;
}
}
/////////////////////////////////////////////////////////////////////////////
//
// Get Instances of ReferenceType
//
/////////////////////////////////////////////////////////////////////////////
/**
* Check if instances of a type are found even if they are scalar replaced. To stress the
* implementation a little more, the instances should be retrieved while the target is running.
*/
class EAGetInstancesOfReferenceType extends EATestCaseBaseDebugger {
public void runTestCase() throws Exception {
printStack(env.targetMainThread);
ReferenceType cls = ((ClassObjectReference)getField(testCase, "cls")).reflectedType();
msg("reflected type is " + cls);
msg("resume");
env.vm().resume();
waitUntilTargetHasEnteredEndlessLoop();
// do this while thread is running!
msg("Retrieve instances of " + cls.name());
List<ObjectReference> instances = cls.instances(10);
Asserts.assertEQ(instances.size(), 3, "unexpected number of instances of " + cls.name());
// invariant: main thread is suspended at the end of the test case
msg("suspend");
env.targetMainThread.suspend();
terminateEndlessLoop();
}
}
class EAGetInstancesOfReferenceTypeTarget extends EATestCaseBaseTarget {
public long checkSum;
public static Class<LocalXYVal> cls = LocalXYVal.class;
public static class LocalXYVal {
public int x, y;
public LocalXYVal(int x, int y) {
this.x = x; this.y = y;
}
}
@Override
public void dontinline_testMethod() {
LocalXYVal p1 = new LocalXYVal(4, 2);
LocalXYVal p2 = new LocalXYVal(5, 3);
LocalXYVal p3 = new LocalXYVal(6, 4);
dontinline_endlessLoop();
iResult = p1.x+p1.y + p2.x+p2.y + p3.x+p3.y;
}
@Override
public int getExpectedIResult() {
return 6+8+10;
}
@Override
public void setUp() {
super.setUp();
testMethodDepth = 2;
loopCount = 3;
}
public void warmupDone() {
super.warmupDone();
msg("enter 'endless' loop by setting loopCount = Long.MAX_VALUE");
loopCount = Long.MAX_VALUE; // endless loop
}
}
// End of test case collection
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Helper classes
class XYVal {
public int x, y;
public XYVal(int x, int y) {
this.x = x;
this.y = y;
}
/**
* Note that we don't use a sync block here because javac would generate an synthetic exception
* handler for the synchronized block that catches Throwable E, unlocks and throws E
* again. The throw bytecode causes the BCEscapeAnalyzer to set the escape state to GlobalEscape
* (see comment on exception handlers in BCEscapeAnalyzer::iterate_blocks())
*/
public synchronized void dontinline_sync_method(EATestCaseBaseTarget target) {
target.dontinline_brkpt();
}
/**
* Just like {@link #dontinline_sync_method(EATestCaseBaseTarget)} but without the call to
* {@link EATestCaseBaseTarget#dontinline_brkpt()}.
*/
public synchronized void dontinline_sync_method_no_brkpt(EATestCaseBaseTarget target) {
}
}
class Vector10 {
int i0, i1, i2, i3, i4, i5, i6, i7, i8, i9;
public Vector10(int j0, int j1, int j2, int j3, int j4, int j5, int j6, int j7, int j8, int j9) {
i0=j0; i1=j1; i2=j2; i3=j3; i4=j4; i5=j5; i6=j6; i7=j7; i8=j8; i9=j9;
}
}
class ILFDO {
public int i;
public int i2;
public long l;
public long l2;
public float f;
public float f2;
public double d;
public double d2;
public Long o;
public Long o2;
public ILFDO(int i,
int i2,
long l,
long l2,
float f,
float f2,
double d,
double d2,
Long o,
Long o2) {
this.i = i;
this.i2 = i2;
this.l = l;
this.l2 = l2;
this.f = f;
this.f2 = f2;
this.d = d;
this.d2 = d2;
this.o = o;
this.o2 = o2;
}
}
|