Loading...
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 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 | 2018-11-21 Dominik Infuehr <dinfuehr@igalia.com> Enable JIT on ARM/Linux https://bugs.webkit.org/show_bug.cgi?id=191548 Reviewed by Yusuke Suzuki. * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::startAllocating): 2018-11-01 Jiewen Tan <jiewen_tan@apple.com> Replace CommonRandom SPI with API https://bugs.webkit.org/show_bug.cgi?id=191178 <rdar://problem/45722391> Reviewed by Brent Fulgham. * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::stir): 2018-10-29 Mark Lam <mark.lam@apple.com> Correctly detect string overflow when using the 'Function' constructor. https://bugs.webkit.org/show_bug.cgi?id=184883 <rdar://problem/36320331> Reviewed by Saam Barati. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): (bmalloc::Allocator::tryReallocate): (bmalloc::Allocator::reallocateImpl): * bmalloc/Allocator.h: * bmalloc/Cache.h: (bmalloc::Cache::tryReallocate): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::realloc): * bmalloc/DebugHeap.h: * bmalloc/bmalloc.h: (bmalloc::api::tryRealloc): 2018-10-25 Ross Kirsling <ross.kirsling@sony.com> Cleanup: inline constexpr is redundant as constexpr implies inline https://bugs.webkit.org/show_bug.cgi?id=190819 Reviewed by Mark Lam. * bmalloc/Algorithm.h: (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::isPowerOfTwo): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::log2): * bmalloc/Bits.h: (bmalloc::bitsArrayLength): * bmalloc/Sizes.h: (bmalloc::Sizes::maskSizeClass): 2018-10-24 Alexey Proskuryakov <ap@apple.com> Add BPLATFORM(IOS_FAMILY) https://bugs.webkit.org/show_bug.cgi?id=190878 Reviewed by Saam Barati. * bmalloc/AvailableMemory.cpp: (bmalloc::memorySizeAccordingToKernel): (bmalloc::computeAvailableMemory): * bmalloc/AvailableMemory.h: (bmalloc::isUnderMemoryPressure): * bmalloc/BPlatform.h: * bmalloc/Gigacage.h: * bmalloc/Logging.cpp: (bmalloc::logVMFailure): * bmalloc/VMAllocate.h: (bmalloc::vmPageSizePhysical): * bmalloc/bmalloc.h: * bmalloc/darwin/MemoryStatusSPI.h: 2018-10-12 Ryan Haddad <ryanhaddad@apple.com> Unreviewed, rolling out r237063. Caused layout test fast/dom/Window/window-postmessage-clone- deep-array.html to fail on macOS and iOS Debug bots. Reverted changeset: "[JSC] Remove gcc warnings on mips and armv7" https://bugs.webkit.org/show_bug.cgi?id=188598 https://trac.webkit.org/changeset/237063 2018-10-11 Guillaume Emont <guijemont@igalia.com> [JSC] Remove gcc warnings on mips and armv7 https://bugs.webkit.org/show_bug.cgi?id=188598 Reviewed by Mark Lam. Add bitwise_cast (from WTF) and use it instead of reinterpret_cast in a couple places where reinterpret_cast triggers a warning about alignment even though we know that alignment is correct. * bmalloc/Algorithm.h: (bmalloc::bitwise_cast): Copied from WTF/wtf/StdLibextras.h * bmalloc/IsoDirectoryPageInlines.h: (bmalloc::IsoDirectoryPage<Config>::pageFor): * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::startAllocating): 2018-10-03 Dan Bernstein <mitz@apple.com> bmalloc part of [Xcode] Update some build settings as recommended by Xcode 10 https://bugs.webkit.org/show_bug.cgi?id=190250 Reviewed by Alex Christensen. * Configurations/Base.xcconfig: Enabled CLANG_WARN_COMMA, CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS, and CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF. * bmalloc.xcodeproj/project.pbxproj: Let Xcode update LastUpgradeCheck. 2018-09-25 Alex Christensen <achristensen@webkit.org> Allow for suffixes to com.apple.WebKit.WebContent https://bugs.webkit.org/show_bug.cgi?id=189972 Reviewed by Chris Dumez. * bmalloc/ProcessCheck.mm: (bmalloc::gigacageEnabledForProcess): 2018-09-24 Fujii Hironori <Hironori.Fujii@sony.com> Rename WTF_COMPILER_GCC_OR_CLANG to WTF_COMPILER_GCC_COMPATIBLE https://bugs.webkit.org/show_bug.cgi?id=189733 Reviewed by Michael Catanzaro. * bmalloc/BCompiler.h: 2018-08-27 Keith Rollin <krollin@apple.com> Unreviewed build fix -- disable LTO for production builds * Configurations/Base.xcconfig: 2018-08-27 Keith Rollin <krollin@apple.com> Build system support for LTO https://bugs.webkit.org/show_bug.cgi?id=187785 <rdar://problem/42353132> Reviewed by Dan Bernstein. Update Base.xcconfig and DebugRelease.xcconfig to optionally enable LTO. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2018-08-16 Tomas Popela <tpopela@redhat.com> bmalloc: Coverity scan issues https://bugs.webkit.org/show_bug.cgi?id=186763 Reviewed by Saam Barati. * bmalloc/DebugHeap.h: Initialize the m_pageSize variable. * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::ensureEntries): Check the return value of pthread_key_create return(). * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): Correctly check the return value of sysconf(). 2018-07-27 Mark Lam <mark.lam@apple.com> Initialize bmalloc::DebugHeap::m_pageSize for non-Darwin builds. https://bugs.webkit.org/show_bug.cgi?id=188132 <rdar://problem/40401599> Reviewed by Saam Barati. * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): 2018-07-27 Saam Barati <sbarati@apple.com> Explicitly handle memlimit_active < 0 https://bugs.webkit.org/show_bug.cgi?id=188125 Reviewed by Mark Lam. This may come up during development when someone wants the limit to be "infinite". * bmalloc/AvailableMemory.cpp: (bmalloc::jetsamLimit): 2018-07-27 Saam Barati <sbarati@apple.com> Use SPI to compute the jetsam limit on iOS instead of hardcoding 840MB https://bugs.webkit.org/show_bug.cgi?id=188091 <rdar://problem/42647697> Reviewed by Simon Fraser. We want bmalloc to dynamically adapt to the jetsam limit of the process it's running in. WTF::ramSize() is based off bmalloc's availableMemory, so it will now reflect the result of the real jetsam limit when we can read it. Reading the jetsam limit requires an entitlement, so this patch opts in the WebContent/Storage/Network processes. We fall back to 840MB (the old hard coded value) when the SPI call fails (e.g, when we're in a process without the proper entitlement). * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AvailableMemory.cpp: (bmalloc::jetsamLimit): (bmalloc::computeAvailableMemory): * bmalloc/darwin/MemoryStatusSPI.h: Added. 2018-07-24 Saam Barati <sbarati@apple.com> Revert back to using phys_footprint to calculate isUnderMemoryPressure() https://bugs.webkit.org/show_bug.cgi?id=187919 <rdar://problem/42552888> Reviewed by Simon Fraser. Currently on iOS, bmalloc will run the scavenger more frequently when it detects that the process is under memory pressure. However, it only uses bmalloc's own footprint as a percentage of the HW available memory to determine if the process is under memory pressure. This is a change I recently made in an effort to run the scavenger less when bmalloc wasn't contributing to the dirty footprint in the process. However, this fails to run the scavenger eagerly when the process in question has a heap split between a lot of dirty bmalloc memory as well as a lot of dirty memory from elsewhere. We also have evidence that we may have increased jetsams in the Web Content process. Since my original change was not a measurable speedup, this patch reverts isUnderMemoryPressure() to its previous behavior of using phys_footprint to determine if 75% of the available HW memory is being used. * bmalloc/AvailableMemory.cpp: (bmalloc::memoryStatus): 2019-07-12 Michael Saboff <msaboff@apple.com> Disable IsoHeaps when Gigacage is off https://bugs.webkit.org/show_bug.cgi?id=187160 Reviewed by Saam Barati. Relanding change sets 233547 and 233550 with the added fix that Gigacage is also enabled for DumpRenderTree. Updated determineMallocFallbackState to base enabling of Iso Heaps on Gigacage being enabled. We do this because if Gigacage is disabled, it may be due to lack of address space. To work around a compiler issue uncovered by the change above, I added explicit instantiation of PerThread's static variables. Defined the same explicit instantiated static variables with export scope in the new file PerThread.cpp to eliminate separate variables allocations in each linked framework / library. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::determineMallocFallbackState): * bmalloc/PerThread.cpp: Added. * bmalloc/PerThread.h: * bmalloc/ProcessCheck.mm: (bmalloc::gigacageEnabledForProcess): 2018-07-09 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r233547 and r233550. https://bugs.webkit.org/show_bug.cgi?id=187497 Introduced flakiness for media/fullscreen-* tests on mac-wk1 (Requested by ryanhaddad on #webkit). Reverted changesets: "Disable IsoHeaps when Gigacage is off" https://bugs.webkit.org/show_bug.cgi?id=187160 https://trac.webkit.org/changeset/233547 "Build fix (r233547): Disable IsoHeaps when Gigacage is off" https://bugs.webkit.org/show_bug.cgi?id=187160 https://trac.webkit.org/changeset/233550 2018-07-05 David Kilzer <ddkilzer@apple.com> Build fix (r233547): Disable IsoHeaps when Gigacage is off <https://webkit.org/b/187160> * bmalloc/PerThread.cpp: Add #if !HAVE_PTHREAD_MACHDEP_H/#endif around variables only used when that macro is 0. Include what you use: Cache.h and Heap.h. * bmalloc/PerThread.h: Include <memory> for std::once_flag. 2018-07-05 Michael Saboff <msaboff@apple.com> Disable IsoHeaps when Gigacage is off https://bugs.webkit.org/show_bug.cgi?id=187160 Reviewed by Saam Barati. Updated determineMallocFallbackState to base enabling of Iso Heaps on Gigacage being enabled. We do this because if Gigacage is disabled, it may be due to lack of address space. To work around a compiler issue uncovered by the change above, I added explicit instantiation of PerThread's static variables. Defined the same explicit instantiated static variables with export scope in the new file PerThread.cpp to eliminate separate variables allocations in each linked framework / library. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::determineMallocFallbackState): * bmalloc/PerThread.cpp: Added. * bmalloc/PerThread.h: 2018-07-04 Tim Horton <timothy_horton@apple.com> Introduce PLATFORM(IOSMAC) https://bugs.webkit.org/show_bug.cgi?id=187315 Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2018-06-29 Ryan Haddad <ryanhaddad@apple.com> Unreviewed, rolling out r233347. Causes crashes during WK1 tests. Reverted changeset: "Disable IsoHeaps when Gigacage is off" https://bugs.webkit.org/show_bug.cgi?id=187160 https://trac.webkit.org/changeset/233347 2018-06-28 Michael Saboff <msaboff@apple.com> Disable IsoHeaps when Gigacage is off https://bugs.webkit.org/show_bug.cgi?id=187160 Reviewed by Saam Barati. If Gigacage is disabled, it may be due to lack of address space. Therefore we should also turn off IsoHeaps since it uses more virtual address space as well. * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::determineMallocFallbackState): 2018-06-27 Simon Fraser <simon.fraser@apple.com> https://hackernoon.com/ uses lots of layer backing store https://bugs.webkit.org/show_bug.cgi?id=186909 rdar://problem/40257540 Reviewed by Tim Horton. Drive-by typo fix. * bmalloc/Scavenger.cpp: (bmalloc::dumpStats): 2018-06-26 Saam Barati <sbarati@apple.com> Unreviewed followup. Fix the watchos build after r233192. This patch also correct the changelog entry below to have the correct bug and title info. * bmalloc/ProcessCheck.mm: 2018-06-26 Saam Barati <sbarati@apple.com> Switch to system malloc on iOS when nano malloc is disabled https://bugs.webkit.org/show_bug.cgi?id=186322 <rdar://problem/41140257> Reviewed by Keith Miller. We have evidence showing that processes with small heaps using the JS API are more space efficient when using system malloc. Our main hypothesis as to why this is, is that when dealing with small heaps, one malloc can be more efficient at optimizing memory usage than two mallocs. * bmalloc/BPlatform.h: * bmalloc/Environment.cpp: (bmalloc::isNanoMallocEnabled): (bmalloc::Environment::computeIsDebugHeapEnabled): * bmalloc/ProcessCheck.h: (bmalloc::shouldProcessUnconditionallyUseBmalloc): * bmalloc/ProcessCheck.mm: (bmalloc::shouldProcessUnconditionallyUseBmalloc): 2018-06-24 Yusuke Suzuki <utatane.tea@gmail.com> [bmalloc][Linux] Remove static initializers for PerProcess<>::s_object https://bugs.webkit.org/show_bug.cgi?id=186966 Reviewed by Anders Carlsson. chrome/tools/linux/dump-static-initializers.py can dump static initializers in the binary and we found that PerProcess<>::s_object initialization is done by static initializers in GCC + Linux environments. The example is the following. Scavenger.cpp (initializer offset 0x38c210 size 0x3e) _GLOBAL__sub_I_Scavenger.cpp+0x1e _GLOBAL__sub_I_Scavenger.cpp+0x2d _GLOBAL__sub_I_Scavenger.cpp+0x3c _GLOBAL__sub_I_Scavenger.cpp+0xf guard variable for bmalloc::PerProcess<bmalloc::AllIsoHeaps>::s_object@@Base-0x3f0d8 guard variable for bmalloc::PerProcess<bmalloc::Environment>::s_object@@Base-0x3f0e8 guard variable for bmalloc::PerProcess<bmalloc::PerHeapKind<bmalloc::Heap> >::s_object@@Base-0x3c600 guard variable for bmalloc::PerProcess<bmalloc::Scavenger>::s_object@@Base-0x38ce8 We can remove this by initializing `nullptr`, which leads to constexpr initialization. After this change, Linux JSCOnly libJavaScriptCore.so has no static initializers. * bmalloc/PerProcess.h: 2018-06-09 Dan Bernstein <mitz@apple.com> [Xcode] Clean up and modernize some build setting definitions https://bugs.webkit.org/show_bug.cgi?id=186463 Reviewed by Sam Weinig. * Configurations/Base.xcconfig: Removed definition for macOS 10.11. * Configurations/DebugRelease.xcconfig: Ditto. 2018-06-07 Darin Adler <darin@apple.com> [Cocoa] Turn on ARC for the single Objective-C++ source file in bmalloc https://bugs.webkit.org/show_bug.cgi?id=186398 Reviewed by Saam Barati. * Configurations/Base.xcconfig: Turn on ARC. * bmalloc/ProcessCheck.mm: (bmalloc::gigacageEnabledForProcess): Removed the globals from this function, since it's only called once. If it was called more than once, we could optimize that with a single boolean global rather than two strings and two booleans. 2018-06-07 David Kilzer <ddkilzer@apple.com> bmalloc: Fix 'noreturn' warnings when compiling with -std=gnu++17 <https://webkit.org/b/186400> Reviewed by Saam Barati. Fixes the following warnings when compiling with gnu++17: Source/bmalloc/bmalloc/Scavenger.cpp:363:1: error: function 'threadRunLoop' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn] { ^ Source/bmalloc/bmalloc/Scavenger.cpp:358:1: error: function 'threadEntryPoint' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn] { ^ * bmalloc/BCompiler.h: (BCOMPILER): Add support for the BCOMPILER() macro, then add BCOMPILER(GCC_OR_CLANG). Taken from Source/WTF/wtf/Compiler.h. (BNO_RETURN): Implement 'norerturn' support using the new BCOMPILER() macros. Taken from Source/WTF/wtf/Compiler.h. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): Remove the workaround that tricked older compilers into thinking the while() loop wasn't infinite. * bmalloc/Scavenger.h: (bmalloc::Scavenger::threadEntryPoint): Add BNO_RETURN attribute. (bmalloc::Scavenger::threadRunLoop): Ditto. 2018-05-29 Saam Barati <sbarati@apple.com> JSC should put bmalloc's scavenger into mini mode https://bugs.webkit.org/show_bug.cgi?id=185988 Reviewed by Michael Saboff. We expose an API for putting bmalloc into mini mode. All that means now is that we'll run the scavenger more aggressively. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::enableMiniMode): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/Sizes.h: * bmalloc/bmalloc.cpp: (bmalloc::api::enableMiniMode): * bmalloc/bmalloc.h: 2018-05-29 Geoffrey Garen <ggaren@apple.com> Fixed the bmalloc build https://bugs.webkit.org/show_bug.cgi?id=186025 Reviewed by Sam Weinig. * bmalloc.xcodeproj/project.pbxproj: Link Foundation because the gigacage check needs it. 2018-05-23 Antti Koivisto <antti@apple.com> Increase the simulated memory size on PLATFORM(IOS_SIMULATOR) from 512MB to 1024MB https://bugs.webkit.org/show_bug.cgi?id=185908 Reviewed by Geoffrey Garen. We don't support 512MB devices anymore. This will make the simulator behave more like a real device. * bmalloc/AvailableMemory.cpp: (bmalloc::memorySizeAccordingToKernel): Factor to a function. Don't use availableMemoryGuess for the simulator value as it is not a guess. (bmalloc::computeAvailableMemory): Apply the same adjustments to the simulated value too. 2018-05-22 Ryan Haddad <ryanhaddad@apple.com> Unreviewed, rolling out r232052. Breaks internal builds. Reverted changeset: "Use more C++17" https://bugs.webkit.org/show_bug.cgi?id=185176 https://trac.webkit.org/changeset/232052 2018-05-22 Yusuke Suzuki <utatane.tea@gmail.com> Define GIGACAGE_ALLOCATION_CAN_FAIL on Linux https://bugs.webkit.org/show_bug.cgi?id=183329 Reviewed by Michael Catanzaro. We specify `GIGACAGE_ALLOCATION_CAN_FAIL 1` in Linux since Linux can fail to `mmap` if `vm.overcommit_memory = 2`. Users can enable Gigacage if users enable overcommit_memory. * bmalloc/Gigacage.h: 2018-05-21 Yusuke Suzuki <utatane.tea@gmail.com> Use more C++17 https://bugs.webkit.org/show_bug.cgi?id=185176 Reviewed by JF Bastien. Add BNO_RETURN. * Configurations/Base.xcconfig: * bmalloc/BCompiler.h: * bmalloc/Scavenger.h: 2018-05-06 Yusuke Suzuki <utatane.tea@gmail.com> [JSC] Remove "using namespace std;" from JSC, bmalloc, WTF https://bugs.webkit.org/show_bug.cgi?id=185362 Reviewed by Sam Weinig. * bmalloc/Allocator.cpp: * bmalloc/Deallocator.cpp: 2018-05-03 Filip Pizlo <fpizlo@apple.com> Strings should not be allocated in a gigacage https://bugs.webkit.org/show_bug.cgi?id=185218 Reviewed by Saam Barati. This removes the string gigacage. Putting strings in a gigacage prevents read gadgets. The other things that get to be in gigacages are there to prevent read-write gadgets. Also, putting strings in a gigacage seems to have been a bigger regression than putting other things in gigacages. Therefore, to maximize the benefit/cost ratio of gigacages, we should evict strings from them. If we want to throw away perf for security, there are more beneficial things to sacrifice. * bmalloc/Gigacage.h: (Gigacage::name): (Gigacage::basePtr): (Gigacage::size): (Gigacage::forEachKind): * bmalloc/HeapKind.h: (bmalloc::isGigacage): (bmalloc::gigacageKind): (bmalloc::heapKind): (bmalloc::isActiveHeapKindAfterEnsuringGigacage): (bmalloc::mapToActiveHeapKindAfterEnsuringGigacage): 2018-04-30 Yusuke Suzuki <utatane.tea@gmail.com> Use WordLock instead of std::mutex for Threading https://bugs.webkit.org/show_bug.cgi?id=185121 Reviewed by Geoffrey Garen. Add constexpr to explicitly describe that bmalloc::Mutex constructor is constexpr. * bmalloc/Mutex.h: 2018-04-23 Ting-Wei Lan <lantw44@gmail.com> Include stdio.h before using stderr https://bugs.webkit.org/show_bug.cgi?id=184872 Reviewed by Yusuke Suzuki. * bmalloc/PerProcess.cpp: * bmalloc/Scavenger.cpp: 2018-04-21 Yusuke Suzuki <utatane.tea@gmail.com> Unreviewed, follow-up patch after r230474 https://bugs.webkit.org/show_bug.cgi?id=166684 Add "JavaScriptCore" to Darwin name. And use short name "BMScavenger" for Linux since adding "JavaScriptCore" makes the name too long for Linux. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): 2018-04-18 Jer Noble <jer.noble@apple.com> Don't put build products into WK_ALTERNATE_WEBKIT_SDK_PATH for engineering builds https://bugs.webkit.org/show_bug.cgi?id=184762 Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2018-04-20 Daniel Bates <dabates@apple.com> Remove code for compilers that did not support NSDMI for aggregates https://bugs.webkit.org/show_bug.cgi?id=184599 Reviewed by Per Arne Vollan. Remove workaround for earlier Visual Studio versions that did not support non-static data member initializers (NSDMI) for aggregates. We have since updated all the build.webkit.org and EWS bots to a newer version that supports this feature. * bmalloc/BPlatform.h: * bmalloc/List.h: (bmalloc::ListNode::ListNode): Deleted. (bmalloc::List::iterator::iterator): Deleted. 2018-04-19 David Kilzer <ddkilzer@apple.com> Enable Objective-C weak references <https://webkit.org/b/184789> <rdar://problem/39571716> Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: (CLANG_ENABLE_OBJC_WEAK): Enable. 2018-04-12 Saam Barati <sbarati@apple.com> Lessen partial scavenge interval on x86-64 https://bugs.webkit.org/show_bug.cgi?id=184577 Rubber-stamped by Filip Pizlo. I initially made the scavenge interval longer because I had thought the shorter interval caused a JetStream regression. I was mistaken though. I was looking at the wrong commit range when analyzing perf data. This patch shortens the interval, but still keeps x86-64 50% longer than other architectures. We know that scavenging frequently on Mac is less important to overall system performance than it is on iOS. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): 2018-04-12 Saam Barati <sbarati@apple.com> Raise the partial scavenge interval even more on x86-64 https://bugs.webkit.org/show_bug.cgi?id=184551 Rubber-stamped by Filip Pizlo. The JetStream regression didn't recover from my previous patch. This is another attempt to get it to recover perf. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): 2018-04-11 Saam Barati <sbarati@apple.com> raise partial scavenge interval on x86-64 https://bugs.webkit.org/show_bug.cgi?id=184521 Rubber-stamped by Filip Pizlo. This patch is an attempt to recover the 1-3% JetStream regression my initial partial scavenging patch introduced on some Macs. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): 2018-04-10 Saam Barati <sbarati@apple.com> IsoHeapImpl::scavenge* needs to grab the lock https://bugs.webkit.org/show_bug.cgi?id=184461 Reviewed by Filip Pizlo. Another thread could be modifying the linked list that the scavenge* methods traverse. * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): 2018-04-10 Saam Barati <sbarati@apple.com> bmalloc should do partial scavenges more frequently https://bugs.webkit.org/show_bug.cgi?id=184176 Reviewed by Filip Pizlo. This patch adds the ability for bmalloc to do a partial scavenge. bmalloc will now do a partial scavenge with some frequency even when the heap is growing. For Heap, this means tracking the high water mark of where the Heap has allocated since the last scavenge. Partial scavenging is just decommitting entries in the LargeMap that are past this high water mark. Because we allocate in first fit order out of LargeMap, tracking the high water mark is a good heuristic of how much memory a partial scavenge should decommit. For IsoHeaps, each IsoDirectory also keeps track of its high water mark for the furthest page it allocates into. Similar to Heap, we scavenge pages past that high water mark. IsoHeapImpl then tracks the high water mark for the IsoDirectory it allocates into. We then scavenge all directories including and past the directory high water mark. This includes scavenging the inline directory when its the only thing we allocate out of since the last scavenge. This patch also adds some other capabilities to bmalloc: Heaps and IsoHeaps now track how much memory is freeable. Querying this number is now cheap. Heaps no longer hold the global lock when decommitting large ranges. Instead, that range is just marked as non eligible to be allocated. Then, without the lock held, the scavenger will decommit those ranges. Once this is done, the scavenger will then reacquire the lock and mark these ranges as eligible. This lessens lock contention between the scavenger and the allocation slow path since threads that are taking an allocation slow path can now allocate concurrently to the scavenger's decommits. The main consideration in adding this functionality is that a large allocation may fail while the scavenger is in the process of decommitting memory. When the Heap fails to allocate a large range when the scavenger is in the middle of a decommit, Heap will wait for the Scavenger to finish and then it will try to allocate a large range again. Decommitting from Heap now aggregates the ranges to decommit and tries to merge them together to lower the number of calls to vmDeallocatePhysicalPages. This is analogous to what IsoHeaps already do. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/BulkDecommit.h: Added. (bmalloc::BulkDecommit::addEager): (bmalloc::BulkDecommit::addLazy): (bmalloc::BulkDecommit::processEager): (bmalloc::BulkDecommit::processLazy): (bmalloc::BulkDecommit::add): (bmalloc::BulkDecommit::process): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/Heap.cpp: (bmalloc::Heap::freeableMemory): (bmalloc::Heap::markAllLargeAsEligibile): (bmalloc::Heap::decommitLargeRange): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeToHighWatermark): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::deallocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavengePage): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::scavengeToHighWatermark): (bmalloc::passedNumPages>::freeableMemory): Deleted. * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::scavengeToHighWatermark): (bmalloc::IsoHeapImpl<Config>::freeableMemory): (bmalloc::IsoHeapImpl<Config>::isNowFreeable): (bmalloc::IsoHeapImpl<Config>::isNoLongerFreeable): * bmalloc/LargeMap.cpp: (bmalloc::LargeMap::remove): (bmalloc::LargeMap::markAllAsEligibile): * bmalloc/LargeMap.h: (bmalloc::LargeMap::size): (bmalloc::LargeMap::at): * bmalloc/LargeRange.h: (bmalloc::LargeRange::setEligible): (bmalloc::LargeRange::isEligibile const): (bmalloc::canMerge): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/Scavenger.cpp: (bmalloc::PrintTime::PrintTime): (bmalloc::PrintTime::~PrintTime): (bmalloc::PrintTime::print): (bmalloc::Scavenger::timeSinceLastFullScavenge): (bmalloc::Scavenger::timeSinceLastPartialScavenge): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::partialScavenge): (bmalloc::Scavenger::freeableMemory): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): 2018-04-09 Yusuke Suzuki <utatane.tea@gmail.com> [bmalloc] Name Scavenger thread "bmalloc scavenger" https://bugs.webkit.org/show_bug.cgi?id=166684 Reviewed by Saam Barati. We name the thread for bmalloc Scavenger "bmalloc scavenger". It is useful for debugging. In Linux environment, it will be shown in GDB. * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::threadRunLoop): (bmalloc::Scavenger::setName): * bmalloc/Scavenger.h: 2018-04-09 Michael Catanzaro <mcatanzaro@igalia.com> Rename UNUSED to BUNUSED https://bugs.webkit.org/show_bug.cgi?id=184093 Reviewed by Yusuke Suzuki. * bmalloc/BAssert.h: * bmalloc/VMAllocate.h: (bmalloc::vmValidate): (bmalloc::vmValidatePhysical): 2018-04-08 Yusuke Suzuki <utatane.tea@gmail.com> Use alignas instead of compiler-specific attributes https://bugs.webkit.org/show_bug.cgi?id=183508 Reviewed by Mark Lam. Use alignas for g_gigacageBasePtr. We also add reinterpret_cast to fix compile errors in ARMv7 and MIPS JSCOnly ports. * bmalloc/Gigacage.cpp: * bmalloc/Gigacage.h: (Gigacage::basePtrs): 2018-04-06 Saam Barati <sbarati@apple.com> bmalloc virtual allocation API should not treat memory it vends as dirty with respect to how it drives the scavenger https://bugs.webkit.org/show_bug.cgi?id=184342 Reviewed by Mark Lam. Currently, the only user of this API is Wasm. Ideally, Wasm would tell us exactly which page is dirtied. We should really do that at some point: https://bugs.webkit.org/show_bug.cgi?id=184207 However, until we do that, it's better to treat none of the virtual memory we vend as dirty, versus what we do now, which is treat it all as dirty. This dirty memory tracking helps drive the scavenger, so on iOS, having the scavenger think its under memory pressure because of memory it can't free isn't useful. * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): * bmalloc/bmalloc.h: 2018-04-05 Saam Barati <sbarati@apple.com> IsoHeapImpl not IsoHeapImplBase should add itself to AllIsoHeaps https://bugs.webkit.org/show_bug.cgi?id=184174 Reviewed by Filip Pizlo. Otherwise, another thread may see a non-fully formed IsoHeapImpl. * bmalloc/IsoHeapImpl.cpp: (bmalloc::IsoHeapImplBase::IsoHeapImplBase): (bmalloc::IsoHeapImplBase::addToAllIsoHeaps): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::IsoHeapImpl): 2018-04-05 Yusuke Suzuki <utatane.tea@gmail.com> bmalloc StaticMutex's constructor should be constexpr https://bugs.webkit.org/show_bug.cgi?id=180600 Reviewed by Mark Lam. StaticMutex and Mutex can be unified. This patch changes std::atomic_flag in StaticMutex to std::atomic<bool> to add constexpr constructor to StaticMutex. Then, StaticMutex can be initialized in static storage without calling any static initializers. And we also rename StaticMutex to Mutex simply. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AllIsoHeaps.cpp: (bmalloc::AllIsoHeaps::AllIsoHeaps): * bmalloc/AllIsoHeaps.h: * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/CryptoRandom.cpp: (bmalloc::ARC4RandomNumberGenerator::ARC4RandomNumberGenerator): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): * bmalloc/DebugHeap.h: * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::scavenge): (bmalloc::Heap::deallocateLineCache): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: (bmalloc::Heap::mutex): (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/IsoDeallocator.h: * bmalloc/IsoHeap.h: * bmalloc/IsoTLSDeallocatorEntry.h: * bmalloc/IsoTLSDeallocatorEntryInlines.h: (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::ensureHeap): * bmalloc/IsoTLSLayout.cpp: (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: * bmalloc/Mutex.cpp: Renamed from Source/bmalloc/bmalloc/StaticMutex.cpp. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): (bmalloc::Mutex::Mutex): Deleted. * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/PerProcess.cpp: (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::mutex): (bmalloc::PerProcess::getSlowCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::freeableMemory): * bmalloc/Scavenger.h: * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::refCount): (bmalloc::SmallPage::hasFreeLines const): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): * bmalloc/StaticMutex.h: Removed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::isEnabled): (bmalloc::api::setScavengerThreadQOSClass): * bmalloc/bmalloc.h: 2018-04-04 Konstantin Tokarev <annulen@yandex.ru> Enable Gigacage unconditionally when building JSCOnly on macOS (build fix) https://bugs.webkit.org/show_bug.cgi?id=184301 Reviewed by Yusuke Suzuki. bmalloc/ProcessCheck.mm implements specific behavior for Mac and iOS ports, which is guarded with BPLATFORM(COCOA). if we don't enable BPLATFORM(MAC) or BPLATFORM(IOS) in JSCOnly, then BPLATFORM(COCOA) won't be defined as well, and code path from ProcessCheck.mm will not be taken. * CMakeLists.txt: Exclude ProcessCheck.mm from port-independent file list. * PlatformMac.cmake: Build ProcessCheck.mm for Mac port. * bmalloc/BPlatform.h: Don't enable BPLATFORM(MAC) or BPLATFORM(IOS) when building JSCOnly port. 2018-04-03 Saam Barati <sbarati@apple.com> totalPhysicalSize calculation when splitting a range must account for double rounding effects https://bugs.webkit.org/show_bug.cgi?id=184275 Reviewed by Mark Lam. The rounding error could happen when we split a range where the range's total physical size equals the range's total size. The rounding may cause the left size to lose a byte, and the right size to gain a byte. This caused the right side to be a byte large than its size. * bmalloc/LargeRange.h: (bmalloc::LargeRange::LargeRange): (bmalloc::LargeRange::split const): 2018-04-02 Saam Barati <sbarati@apple.com> bmalloc should compute its own estimate of its footprint https://bugs.webkit.org/show_bug.cgi?id=184121 Reviewed by Filip Pizlo. This patch makes it so that bmalloc keeps track of its own physical footprint. Doing this for IsoHeaps is trivial. It allocates/deallocates fixed page sizes at a time. IsoHeapImpl just updates a count every time a page is committed/decommitted. Making Heap keep its footprint was a bit trickier because of how LargeRange is constructed. Before this patch, LargeRange kept track of the amount of physical memory at the start of its range. This patch extends large range to also keep track of the total physical memory in the range just for footprint bookkeeping. This was needed to make Heap's footprint come close to resembling reality, because as we merge and split large ranges, the start physical size often becomes wildly inaccurate. The total physical size number stored in LargeRange is still just an estimate. It's possible that as ranges are split, that the total physical size split amongst the two ranges doesn't resemble reality. This can happen when the total physical size is really all in one end of the split, but we mark it as being proportionally split amongst the resulting two ranges. In practice, I did not notice this being a problem. The footprint estimate tracks reality very closely (in my testing, within less than 1MB for heaps with sizes upwards of 1GB). The other nice thing about total physical size is that even if it diverges from reality in terms of how memory is using up physical RAM, it stays internally consistent inside bmalloc's own data structures. The main oversight of this patch is how it deals with Wasm memory. All Wasm memory will be viewed by bmalloc as taking up physical space even when it may not be. Wasm memory starts off as taking up purely virtual pages. When a page is first accessed, only then will the OS page it in and cause it to use physical RAM. I opened a bug to come up with a solution to this problem: https://bugs.webkit.org/show_bug.cgi?id=184207 * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AvailableMemory.cpp: (bmalloc::memoryStatus): * bmalloc/BPlatform.h: * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::freeableMemory): (bmalloc::Heap::footprint): (bmalloc::Heap::scavenge): (bmalloc::Heap::deallocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::externalCommit): (bmalloc::Heap::externalDecommit): * bmalloc/Heap.h: * bmalloc/IsoDirectory.h: * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::freeableMemory): * bmalloc/IsoHeapImpl.h: * bmalloc/IsoHeapImplInlines.h: (bmalloc::IsoHeapImpl<Config>::freeableMemory): (bmalloc::IsoHeapImpl<Config>::footprint): (bmalloc::IsoHeapImpl<Config>::didCommit): (bmalloc::IsoHeapImpl<Config>::didDecommit): * bmalloc/LargeRange.h: (bmalloc::LargeRange::LargeRange): (bmalloc::LargeRange::startPhysicalSize const): (bmalloc::LargeRange::setStartPhysicalSize): (bmalloc::LargeRange::totalPhysicalSize const): (bmalloc::LargeRange::setTotalPhysicalSize): (bmalloc::merge): (bmalloc::LargeRange::split const): (bmalloc::LargeRange::physicalSize const): Deleted. (bmalloc::LargeRange::setPhysicalSize): Deleted. * bmalloc/PhysicalPageMap.h: Added. This class is added for debugging purposes. It's useful when hacking on the code that calculates the footprint to use this map as a sanity check. It's just a simple implementation that has a set of all the committed pages. (bmalloc::PhysicalPageMap::commit): (bmalloc::PhysicalPageMap::decommit): (bmalloc::PhysicalPageMap::footprint): (bmalloc::PhysicalPageMap::forEachPhysicalPage): * bmalloc/Scavenger.cpp: (bmalloc::dumpStats): (bmalloc::Scavenger::scavenge): (bmalloc::Scavenger::freeableMemory): This is here just for debugging for now. But we should implement an efficient version of this to use when driving when to run the scavenger. (bmalloc::Scavenger::footprint): (bmalloc::Scavenger::threadRunLoop): * bmalloc/Scavenger.h: * bmalloc/VMAllocate.h: (bmalloc::physicalPageSizeSloppy): * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): * bmalloc/bmalloc.cpp: (bmalloc::api::commitAlignedPhysical): (bmalloc::api::decommitAlignedPhysical): * bmalloc/bmalloc.h: 2018-03-28 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r230005. https://bugs.webkit.org/show_bug.cgi?id=184115 "it caused a huge regression on iOS" (Requested by saamyjoon on #webkit). Reverted changeset: "memoryStatus() is wrong in certain testing scenarios on iOS" https://bugs.webkit.org/show_bug.cgi?id=184050 https://trac.webkit.org/changeset/230005 2018-03-27 Saam Barati <sbarati@apple.com> memoryStatus() is wrong in certain testing scenarios on iOS https://bugs.webkit.org/show_bug.cgi?id=184050 <rdar://problem/37959258> Rubber-stamped by Mark Lam. This switches us from using "phys_footprint" to using "internal + compressed" when computing the dirty memory in the current process. There are iOS testing scenarios where phys_footprint doesn't give us a reliable answer. In my testing, "internal + compressed" tracks phys_footprint closely (when phys_footprint is working). They're usually within much less than 1% of each other. We're making this change to ensure testing in our iOS infrastructure is valid. I opened a bug to move back to phys_footprint when it's feasible: https://bugs.webkit.org/show_bug.cgi?id=184050 * bmalloc/AvailableMemory.cpp: (bmalloc::memoryStatus): 2018-03-20 Tim Horton <timothy_horton@apple.com> Add and adopt WK_PLATFORM_NAME and adjust default feature defines https://bugs.webkit.org/show_bug.cgi?id=183758 <rdar://problem/38017644> Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2018-03-16 Filip Pizlo <fpizlo@apple.com> Put the DOM in IsoHeaps https://bugs.webkit.org/show_bug.cgi?id=183546 Reviewed by Simon Fraser. Make it easy to runtime-disable IsoHeaps. * bmalloc/Allocator.h: * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::determineMallocFallbackState): * bmalloc/IsoTLS.h: * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::allocateSlow): (bmalloc::IsoTLS::deallocateSlow): 2018-03-16 Michael Catanzaro <mcatanzaro@igalia.com> Improve error message when Gigacage cannot allocate virtual memory https://bugs.webkit.org/show_bug.cgi?id=183329 Reviewed by Filip Pizlo. We've discovered that Deja Dup monitor sets a virtual memory limit, breaking Gigacage. Since it runs in the background on a fresh out-of-the-box install of Ubuntu, this is not good. That will have to be fixed by Deja Dup, but there is concern that other applications might try this, or that users will set a virtual memory limit for the entire desktop session. Of particular concern is the possibility that users might have copypasted a ulimit line into a session startup script without understanding it. Let's try to make it slightly easier to understand what's going wrong. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): 2018-03-13 Tim Horton <timothy_horton@apple.com> Add and adopt WK_ALTERNATE_FRAMEWORKS_DIR in WTF and bmalloc https://bugs.webkit.org/show_bug.cgi?id=183576 <rdar://problem/38396766> Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: * Configurations/bmalloc.xcconfig: * Configurations/mbmalloc.xcconfig: 2018-03-10 Filip Pizlo <fpizlo@apple.com> PerProcess<> should be safe by default https://bugs.webkit.org/show_bug.cgi?id=183545 Reviewed by Yusuke Suzuki. This makes PerProcess<> safe by default, so we don't need SafePerProcess<>. The new PerProcess<> design relies on a hash-consing mechanism for PerProcess<> storage based on the __PRETTY_FUNCTION__ from inside PerProcess<>, which captures the instantiated type in the string. Therefore, this can be used to runtime-coalesce PerProcess<> instances based on type. I expect this to be perf-neutral. It's an important prerequisite to more bmalloc work, since I don't want to have more PerProcess<> vs SafePerProcess<> bugs, and SafePerProcess<> can't be used for everything (I don't see how to use it for isoheaps). * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): * bmalloc/PerProcess.cpp: Added. (bmalloc::stringHash): (bmalloc::allocate): (bmalloc::getPerProcessData): * bmalloc/PerProcess.h: (bmalloc::PerProcess::mutex): (bmalloc::PerProcess::coalesce): (bmalloc::PerProcess::getSlowCase): (): Deleted. * bmalloc/Scavenger.cpp: * bmalloc/Scavenger.h: * bmalloc/bmalloc.cpp: (bmalloc::api::scavenge): (bmalloc::api::setScavengerThreadQOSClass): 2018-03-10 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r229436. https://bugs.webkit.org/show_bug.cgi?id=183542 seems to have regressed wasm compile times by 10% (Requested by pizlo-mbp on #webkit). Reverted changeset: "bmalloc mutex should be adaptive" https://bugs.webkit.org/show_bug.cgi?id=177839 https://trac.webkit.org/changeset/229436 2018-03-08 Filip Pizlo <fpizlo@apple.com> bmalloc mutex should be adaptive https://bugs.webkit.org/show_bug.cgi?id=177839 Reviewed by Michael Saboff. This pulls the WordLock algorithm into bmalloc, mostly by copy-pasting the code. We need to copy paste because sometimes we build WTF without bmalloc, so WTF cannot rely on bmalloc for anything other than malloc. Reland after failing to reproduce the WasmBench crash that caused it to get rolled out. Maybe that fixed itself somehow? * bmalloc/Algorithm.h: (bmalloc::compareExchangeWeak): (bmalloc::compareExchangeStrong): * bmalloc/PerThread.h: * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlow): (bmalloc::StaticMutex::unlockSlow): (bmalloc::StaticMutex::lockSlowCase): Deleted. * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::try_lock): (bmalloc::StaticMutex::isLocked const): (bmalloc::StaticMutex::init): (bmalloc::StaticMutex::tryLock): (bmalloc::StaticMutex::lock): (bmalloc::StaticMutex::unlock): (bmalloc::sleep): Deleted. (bmalloc::waitUntilFalse): Deleted. 2018-02-16 Filip Pizlo <fpizlo@apple.com> Unreviewed, roll out r228306 (custom memcpy/memset) because the bots say that it was not a progression. * bmalloc/Algorithm.h: (bmalloc::fastCopy): Deleted. (bmalloc::fastZeroFill): Deleted. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): * bmalloc/Bits.h: (bmalloc::BitsWordOwner::operator=): (bmalloc::BitsWordOwner::clearAll): (bmalloc::BitsWordOwner::set): * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::IsoPage): * bmalloc/Vector.h: (bmalloc::Vector<T>::reallocateBuffer): 2018-02-09 Carlos Alberto Lopez Perez <clopez@igalia.com> Improve of string.h include after r228317. https://bugs.webkit.org/show_bug.cgi?id=182642 Reviewed by Mark Lam. * bmalloc/Algorithm.h: Avoid an architecture-specific #include. 2018-02-09 Carlos Alberto Lopez Perez <clopez@igalia.com> Fix build for !BCPU(X86_64) after r228306 https://bugs.webkit.org/show_bug.cgi?id=182563 Unreviewed build fix. * bmalloc/Algorithm.h: 2018-02-08 Filip Pizlo <fpizlo@apple.com> Experiment with alternative implementation of memcpy/memset https://bugs.webkit.org/show_bug.cgi?id=182563 Reviewed by Michael Saboff and Mark Lam. Add a faster x86_64-specific implementation of memcpy and memset. Ideally, this would just be implemented in WTF, but we have to copy it into bmalloc since bmalloc sits below WTF on the stack. * bmalloc/Algorithm.h: (bmalloc::fastCopy): (bmalloc::fastZeroFill): * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): * bmalloc/Bits.h: (bmalloc::BitsWordOwner::operator=): (bmalloc::BitsWordOwner::clearAll): (bmalloc::BitsWordOwner::set): * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::IsoPage): * bmalloc/Vector.h: (bmalloc::Vector<T>::reallocateBuffer): 2018-02-05 JF Bastien <jfbastien@apple.com> Gigacage: enable only for WebContent process and token executables https://bugs.webkit.org/show_bug.cgi?id=182457 <rdar://problem/35875011> Reviewed by Keith Miller. Gigacage is a solid security improvement, but it's probably best to roll it out incrementally to the most valuable targets first and progressively try out more and more over time rather than outright enabling it everywhere. We've gotten some reports that it has some side-effects that weren't expected, so for now let's enable it for the WebContent process, JSC, and other executables we know, and then later we'll enable more gigacage uses. For now I've chosen the following bundles: - com.apple.WebKit.WebContent.Development - com.apple.WebKit.WebContent - com.apple.WebProcess And the following processes: - jsc - wasm - anything starting with "test", to match the JSC tests I tried a different approach first, where I add a function to turn gigacage on or off and crash if gigacage is initialized without having been told what to do. Doing this in ChildProcess and a bunch of the process initialization methods isn't sufficient. I got MiniBrowser working, but some other builds use static globals which themselves use hash and string which are allocate with bmalloc and therefore which initialize gigacage before main is called and before the process gets a chance to opt in our out. It gets tricky with API calls too, because we have to do the right thing in any entry an API user could plausibly use, even the private ones, so I endend up having to initialize gigacage in e.g. WebPreferencesExperimentalFeatures.cpp.erb. Another approach could be to create a free-for-all gigacage entitlement, and opt-in the processes we want.. As a follow-up we can also check that gigacage allocation always succeeds if it was allowed for that process. With my change I expect it to always succeed. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BPlatform.h: * bmalloc/Gigacage.cpp: (Gigacage::shouldBeEnabled): * bmalloc/ProcessCheck.h: Added. (bmalloc::gigacageEnabledForProcess): * bmalloc/ProcessCheck.mm: Added. (bmalloc::gigacageEnabledForProcess): 2018-02-05 Joseph Pecoraro <pecoraro@apple.com> Multiple bmalloc scavenger threads is unexpected https://bugs.webkit.org/show_bug.cgi?id=182474 <rdar://problem/37175526> Reviewed by Filip Pizlo. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): * bmalloc/IsoDirectoryInlines.h: (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): * bmalloc/bmalloc.cpp: (bmalloc::api::scavenge): (bmalloc::api::setScavengerThreadQOSClass): Switch to SafePerProcess for Scavenger to ensure one instance for the entire process. * bmalloc/PerProcess.h: (bmalloc::PerProcess::get): (bmalloc::PerProcess::getFastCase): (bmalloc::PerProcess::getSlowCase): (bmalloc::SafePerProcess::get): (bmalloc::SafePerProcess::getFastCase): (bmalloc::SafePerProcess::getSlowCase): Duplicate the class with a version that can ensure single instances by requiring exporting symbols that can be created with macros. * bmalloc/Scavenger.cpp: * bmalloc/Scavenger.h: Export symbols to ensure all images get the same instance. 2018-01-31 Saam Barati <sbarati@apple.com> Replace tryLargeMemalignVirtual with tryLargeZeroedMemalignVirtual and use it to allocate large zeroed memory in Wasm https://bugs.webkit.org/show_bug.cgi?id=182064 <rdar://problem/36840132> Reviewed by Geoffrey Garen. This patch replaces the tryLargeMemalignVirtual API with tryLargeZeroedMemalignVirtual. By doing that, we're able to remove the AllocationKind enum. To zero the memory, tryLargeZeroedMemalignVirtual uses mmap(... MAP_ANON ...) over previously mmapped memory. This both purges the any resident memory for the virtual range and ensures that the pages in the range are zeroed. Most OSs should implement this by taking a page fault and zero filling on first access. Therefore, this API is returning pages that will result in page faults on first access. Hence, the name 'virtual' in the API. This API differs from the old API in that users of it need not call madvise themselves. The memory is ready to go. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AllocationKind.h: Removed. * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/Heap.cpp: (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: * bmalloc/IsoPage.cpp: (bmalloc::IsoPageBase::allocatePageMemory): * bmalloc/VMAllocate.h: (bmalloc::vmZeroAndPurge): * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): * bmalloc/VMHeap.h: * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeZeroedMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::tryLargeMemalignVirtual): Deleted. * bmalloc/bmalloc.h: 2018-01-19 Keith Miller <keith_miller@apple.com> HaveInternalSDK includes should be "#include?" https://bugs.webkit.org/show_bug.cgi?id=179670 Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2018-01-18 Dan Bernstein <mitz@apple.com> [Xcode] Streamline and future-proof target-macOS-version-dependent build setting definitions https://bugs.webkit.org/show_bug.cgi?id=181803 Reviewed by Tim Horton. * Configurations/Base.xcconfig: Updated. * Configurations/DebugRelease.xcconfig: Ditto. 2018-01-16 Michael Catanzaro <mcatanzaro@igalia.com> mbmalloc should only be built in developer mode https://bugs.webkit.org/show_bug.cgi?id=181654 Reviewed by Carlos Garcia Campos. * CMakeLists.txt: 2018-01-15 Michael Catanzaro <mcatanzaro@igalia.com> Improve use of ExportMacros https://bugs.webkit.org/show_bug.cgi?id=181652 Reviewed by Konstantin Tokarev. Disable BEXPORT on Linux ports. * bmalloc/BExport.h: Check for BUSE(EXPORT_MACROS). * bmalloc/BPlatform.h: Add BUSE(EXPORT_MACROS) and define it on macOS and iOS. 2017-12-20 Ting-Wei Lan <lantw44@gmail.com> Include stdio.h before using stderr and _IONBF https://bugs.webkit.org/show_bug.cgi?id=181046 Reviewed by Alex Christensen. * bmalloc/IsoTLS.cpp: 2017-12-14 David Kilzer <ddkilzer@apple.com> Enable -Wstrict-prototypes for WebKit <https://webkit.org/b/180757> <rdar://problem/36024132> Rubber-stamped by Joseph Pecoraro. * Configurations/Base.xcconfig: (CLANG_WARN_STRICT_PROTOTYPES): Add. Set to YES. 2017-12-14 Saam Barati <sbarati@apple.com> logVMFailure should not simulate crash on iOS https://bugs.webkit.org/show_bug.cgi?id=180790 Reviewed by JF Bastien. The Gigacage allocation on iOS is expected to fail in certain circumstances. Let's not simulate a crash on failure because since this is expected behavior. * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): 2017-12-11 Tim Horton <timothy_horton@apple.com> Stop using deprecated target conditional for simulator builds https://bugs.webkit.org/show_bug.cgi?id=180662 <rdar://problem/35136156> Reviewed by Simon Fraser. * bmalloc/BPlatform.h: 2017-12-08 Saam Barati <sbarati@apple.com> Enable gigacage on iOS with a 32GB runway and ensure it doesn't break WasmBench https://bugs.webkit.org/show_bug.cgi?id=178557 Reviewed by Mark Lam. * bmalloc/Algorithm.h: (bmalloc::isPowerOfTwo): * bmalloc/Gigacage.cpp: * bmalloc/Gigacage.h: 2017-12-05 Andy Estes <aestes@apple.com> [Darwin] Simplify use of TargetConditionals https://bugs.webkit.org/show_bug.cgi?id=180455 <rdar://problem/35142971> Reviewed by Tim Horton. There's no need to check if TARGET_* macros are defined on Darwin platforms, since TargetConditionals.h always defines them. Also, we can simplify (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) to TARGET_OS_IPHONE. * bmalloc/BPlatform.h: 2017-12-05 Filip Pizlo <fpizlo@apple.com> bmalloc IsoHeap needs to allow a thread to deallocate some size for the first time https://bugs.webkit.org/show_bug.cgi?id=180443 Reviewed by Saam Barati. It's true that we can expect a heap to already be initialized if we try to deallocate in it. But it may not have its deallocator initialized on this thread yet. This is easily fixed by adding a null check on the deallocate path. That's probably not going to change perf at all. But doing that allows me to get rid of a lot of weird stuff I previously did to avoid that null check, like creating a dummy TLS in the DebugHeap case. * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::debugFree): (bmalloc::IsoTLS::deallocateSlow): Deleted. * bmalloc/IsoTLS.h: * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::allocateImpl): (bmalloc::IsoTLS::allocateSlow): (bmalloc::IsoTLS::deallocateImpl): (bmalloc::IsoTLS::deallocateSlow): (bmalloc::IsoTLS::ensureHeapAndEntries): 2017-12-01 Michael Saboff <msaboff@apple.com> Gigacage should not be enabled for ARM64_32 https://bugs.webkit.org/show_bug.cgi?id=180265 Reviewed by Saam Barati. Disabled Gigacage for ARM64_32. In the process, restructured Gigacage::shouldBeEnabled() with GIGACAGE_ENABLED set to 0 to avoid a dead code compiler warning. * bmalloc/Gigacage.cpp: (Gigacage::shouldBeEnabled): * bmalloc/Gigacage.h: 2017-11-29 JF Bastien <jfbastien@apple.com> WTF / bmalloc: don't write to 0xbbadbeef when ASAN is looking https://bugs.webkit.org/show_bug.cgi?id=180175 Reviewed by Mark Lam. ASAN knows that 0xbbadbeef is a bbad aaddress, and tells us so when we write to it, say in an assert. That creates bbad error reports where ASAN thinks we write to an invalid address, instead of thinking that we hit an assertion. In some cases, tooling that use fuzzers aggregate similar issues, and think that we just have the one bug and not a bunch of different asserts. At the same time, bmalloc's version of CRASH just writes to 0xbbadbeef and assumes that's invalid and will crash, which isn't necessarily true on non-Mac platforms. WTF's version then makes sure there's a crash, so bmalloc should do the same. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BAssert.h: * bmalloc/BCompiler.h: Added. * bmalloc/BPlatform.h: 2017-11-27 Filip Pizlo <fpizlo@apple.com> Don't crash in forEachEntry when DebugHeap is enabled. Unreviewed, fixing crashes on leaks bots by removing an assertion. * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::forEachEntry): * test/testbmalloc.cpp: Make this test work with DebugHeap so I can catch this kind of problem in the future. 2017-11-16 Filip Pizlo <fpizlo@apple.com> Isolated Heaps caused an increase in reported leaks on the bots https://bugs.webkit.org/show_bug.cgi?id=179463 Reviewed by Darin Adler. This fixes the way isoheaps interact with system tools: - Opts into the VMHeap API so that the leaks tool can find isoheap memory. - Opts into the DebugHeap/Environment APIs so that we turn off isoheap allocation if memory debugging options are in use. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/DebugHeap.h: * bmalloc/IsoHeap.h: * bmalloc/IsoPage.cpp: Added. (bmalloc::IsoPageBase::allocatePageMemory): * bmalloc/IsoPage.h: * bmalloc/IsoPageInlines.h: (bmalloc::IsoPage<Config>::tryCreate): * bmalloc/IsoTLS.cpp: (bmalloc::IsoTLS::deallocateSlow): (bmalloc::IsoTLS::ensureEntries): (bmalloc::IsoTLS::isUsingDebugHeap): (bmalloc::IsoTLS::debugMalloc): * bmalloc/IsoTLS.h: * bmalloc/IsoTLSInlines.h: (bmalloc::IsoTLS::allocate): (bmalloc::IsoTLS::deallocate): (bmalloc::IsoTLS::allocateImpl): (bmalloc::IsoTLS::allocateFast): (bmalloc::IsoTLS::allocateSlow): (bmalloc::IsoTLS::deallocateImpl): (bmalloc::IsoTLS::deallocateFast): (bmalloc::IsoTLS::ensureHeapAndEntries): (bmalloc::IsoTLS::allocator): Deleted. (bmalloc::IsoTLS::deallocator): Deleted. * bmalloc/bmalloc.cpp: (bmalloc::api::tryLargeMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::scavenge): (bmalloc::api::isEnabled): (bmalloc::api::setScavengerThreadQOSClass): * bmalloc/bmalloc.h: (bmalloc::api::tryLargeMemalignVirtual): Deleted. (bmalloc::api::freeLargeVirtual): Deleted. (bmalloc::api::scavenge): Deleted. (bmalloc::api::isEnabled): Deleted. (bmalloc::api::setScavengerThreadQOSClass): Deleted. 2017-11-14 Saam Barati <sbarati@apple.com> Make the gigacage runway 32GB https://bugs.webkit.org/show_bug.cgi?id=175062 Reviewed by Mark Lam. Making the gigacage runway 32GB defends us against buffer overflows in the cage reaching memory outside the cage assuming indices are 32-bit unsigned integers and the type they're indexing into has size <= 8 bytes. This is exactly the case for many things in JSC. For example, butterfly access in JSC meet this criteria, as does typed array access. The 32GB comes from 8 * 2^32 = 32GB. * bmalloc/Gigacage.cpp: 2017-11-08 Michael Catanzaro <mcatanzaro@igalia.com> Gigacage.cpp:44:46: warning: ‘*’ in boolean context, suggest ‘&&’ instead [-Wint-in-bool-context] https://bugs.webkit.org/show_bug.cgi?id=179427 Reviewed by Saam Barati. Tweak the conditional to suppress the warning. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): 2017-11-07 Saam Barati <sbarati@apple.com> We should PROT_NONE the Gigacage runway so OOB accesses crash https://bugs.webkit.org/show_bug.cgi?id=179392 Reviewed by Mark Lam. If we assume that an attacker will exploit JSC and cause OOB accesses, we should make OOB accesses in the Gigacage runway crash. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): 2017-10-31 Filip Pizlo <fpizlo@apple.com> bmalloc should support strictly type-segregated isolated heaps https://bugs.webkit.org/show_bug.cgi?id=178108 Reviewed by Saam Barati, Simon Fraser, and Ryosuke Niwa. This introduces a new allocation API in bmalloc called IsoHeap. An IsoHeap is templatized by type and created in static storage. When unused, it takes only a few words. When you do use it, each IsoHeap gets a bag of virtual pages unique to it. This prevents use-after-free bugs in one IsoHeap from affecting any other memory. At worst, two pointers of the same type will point to the same object even though they should not have. IsoHeaps allocate using a first-fit discipline that combines ideas from bmalloc and Riptide (the JSC GC): Like Riptide, it uses a bump'n'pop allocator. What Riptide calls blocks, IsoHeaps calls pages. Pages are collected into directories. Directories track pages using bitvectors, so that it's easy to quickly find a completely free page or one that has at least one free object. I think that the bump'n'pop allocator is as fast as the bmalloc Immix-style (page and line) allocator, but is better at allocating in holes. It's guaranteed to follow a first-fit discipline. However, the real reason why I wrote it that was is that this is what I'm more familiar with. This is a part of the design I want to revisit (bug 179278). Like bmalloc, it uses a deallocation log. This means that the internal IsoHeap data structures can be locked with a coarse-grained lock, since the deallocator only grabs it when flushing the log. Similarly, the allocator only grabs it when refilling the bump'n'pop FreeList. This adds a unit test for IsoHeaps. In this change, IsoHeaps are adopted only by WebCore's RenderObject. Note that despite the use of GC concepts, it's not a goal to make this code directly sharable with GC. The GC will probably have to do isolated heaps its own way (likely a special Subspace or something like that). * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Algorithm.h: (bmalloc::findBitInWord): * bmalloc/AllIsoHeaps.cpp: Added. (bmalloc::AllIsoHeaps::AllIsoHeaps): (bmalloc::AllIsoHeaps::add): (bmalloc::AllIsoHeaps::head): * bmalloc/AllIsoHeaps.h: Added. * bmalloc/AllIsoHeapsInlines.h: Added. (bmalloc::AllIsoHeaps::forEach): * bmalloc/BMalloced.h: Added. * bmalloc/Bits.h: Added. (bmalloc::bitsArrayLength): (bmalloc::BitsWordView::BitsWordView): (bmalloc::BitsWordView::numBits const): (bmalloc::BitsWordView::word const): (bmalloc::BitsWordOwner::BitsWordOwner): (bmalloc::BitsWordOwner::view const): (bmalloc::BitsWordOwner::operator=): (bmalloc::BitsWordOwner::setAll): (bmalloc::BitsWordOwner::clearAll): (bmalloc::BitsWordOwner::set): (bmalloc::BitsWordOwner::numBits const): (bmalloc::BitsWordOwner::arrayLength const): (bmalloc::BitsWordOwner::word const): (bmalloc::BitsWordOwner::word): (bmalloc::BitsWordOwner::words const): (bmalloc::BitsWordOwner::words): (bmalloc::BitsAndWords::BitsAndWords): (bmalloc::BitsAndWords::view const): (bmalloc::BitsAndWords::numBits const): (bmalloc::BitsAndWords::word const): (bmalloc::BitsOrWords::BitsOrWords): (bmalloc::BitsOrWords::view const): (bmalloc::BitsOrWords::numBits const): (bmalloc::BitsOrWords::word const): (bmalloc::BitsNotWords::BitsNotWords): (bmalloc::BitsNotWords::view const): (bmalloc::BitsNotWords::numBits const): (bmalloc::BitsNotWords::word const): (bmalloc::BitsImpl::BitsImpl): (bmalloc::BitsImpl::numBits const): (bmalloc::BitsImpl::size const): (bmalloc::BitsImpl::arrayLength const): (bmalloc::BitsImpl::operator== const): (bmalloc::BitsImpl::operator!= const): (bmalloc::BitsImpl::at const): (bmalloc::BitsImpl::operator[] const): (bmalloc::BitsImpl::isEmpty const): (bmalloc::BitsImpl::operator& const): (bmalloc::BitsImpl::operator| const): (bmalloc::BitsImpl::operator~ const): (bmalloc::BitsImpl::forEachSetBit const): (bmalloc::BitsImpl::forEachClearBit const): (bmalloc::BitsImpl::forEachBit const): (bmalloc::BitsImpl::findBit const): (bmalloc::BitsImpl::findSetBit const): (bmalloc::BitsImpl::findClearBit const): (bmalloc::BitsImpl::wordView const): (bmalloc::BitsImpl::atImpl const): (bmalloc::Bits::Bits): (bmalloc::Bits::operator=): (bmalloc::Bits::resize): (bmalloc::Bits::setAll): (bmalloc::Bits::clearAll): (bmalloc::Bits::setAndCheck): (bmalloc::Bits::operator|=): (bmalloc::Bits::operator&=): (bmalloc::Bits::at const): (bmalloc::Bits::operator[] const): (bmalloc::Bits::BitReference::BitReference): (bmalloc::Bits::BitReference::operator bool const): (bmalloc::Bits::BitReference::operator=): (bmalloc::Bits::at): (bmalloc::Bits::operator[]): * bmalloc/CryptoRandom.cpp: Replaced with Source/bmalloc/bmalloc/CryptoRandom.cpp. (bmalloc::cryptoRandom): * bmalloc/CryptoRandom.h: Replaced with Source/bmalloc/bmalloc/CryptoRandom.h. * bmalloc/DeferredDecommit.h: Added. * bmalloc/DeferredDecommitInlines.h: Added. (bmalloc::DeferredDecommit::DeferredDecommit): * bmalloc/DeferredTrigger.h: Added. (bmalloc::DeferredTrigger::DeferredTrigger): * bmalloc/DeferredTriggerInlines.h: Added. (bmalloc::DeferredTrigger<trigger>::didBecome): (bmalloc::DeferredTrigger<trigger>::handleDeferral): * bmalloc/EligibilityResult.h: Added. (bmalloc::EligibilityResult::EligibilityResult): * bmalloc/EligibilityResultInlines.h: Added. (bmalloc::EligibilityResult<Config>::EligibilityResult): * bmalloc/FixedVector.h: * bmalloc/FreeList.cpp: Added. (bmalloc::FreeList::FreeList): (bmalloc::FreeList::~FreeList): (bmalloc::FreeList::clear): (bmalloc::FreeList::initializeList): (bmalloc::FreeList::initializeBump): (bmalloc::FreeList::contains const): * bmalloc/FreeList.h: Added. (bmalloc::FreeCell::scramble): (bmalloc::FreeCell::descramble): (bmalloc::FreeCell::setNext): (bmalloc::FreeCell::next const): (bmalloc::FreeList::allocationWillFail const): (bmalloc::FreeList::allocationWillSucceed const): (bmalloc::FreeList::originalSize const): (bmalloc::FreeList::head const): * bmalloc/FreeListInlines.h: Added. (bmalloc::FreeList::allocate): (bmalloc::FreeList::forEach const): * bmalloc/IsoAllocator.h: Added. * bmalloc/IsoAllocatorInlines.h: Added. (bmalloc::IsoAllocator<Config>::IsoAllocator): (bmalloc::IsoAllocator<Config>::~IsoAllocator): (bmalloc::IsoAllocator<Config>::allocate): (bmalloc::IsoAllocator<Config>::allocateSlow): (bmalloc::IsoAllocator<Config>::scavenge): * bmalloc/IsoConfig.h: Added. * bmalloc/IsoDeallocator.h: Added. * bmalloc/IsoDeallocatorInlines.h: Added. (bmalloc::IsoDeallocator<Config>::IsoDeallocator): (bmalloc::IsoDeallocator<Config>::~IsoDeallocator): (bmalloc::IsoDeallocator<Config>::deallocate): (bmalloc::IsoDeallocator<Config>::scavenge): * bmalloc/IsoDirectory.h: Added. (bmalloc::IsoDirectoryBaseBase::IsoDirectoryBaseBase): (bmalloc::IsoDirectoryBaseBase::~IsoDirectoryBaseBase): (bmalloc::IsoDirectoryBase::heap): * bmalloc/IsoDirectoryInlines.h: Added. (bmalloc::IsoDirectoryBase<Config>::IsoDirectoryBase): (bmalloc::passedNumPages>::IsoDirectory): (bmalloc::passedNumPages>::takeFirstEligible): (bmalloc::passedNumPages>::didBecome): (bmalloc::passedNumPages>::didDecommit): (bmalloc::passedNumPages>::scavenge): (bmalloc::passedNumPages>::forEachCommittedPage): * bmalloc/IsoDirectoryPage.h: Added. (bmalloc::IsoDirectoryPage::index const): * bmalloc/IsoDirectoryPageInlines.h: Added. (bmalloc::IsoDirectoryPage<Config>::IsoDirectoryPage): (bmalloc::IsoDirectoryPage<Config>::pageFor): * bmalloc/IsoHeap.h: Added. (bmalloc::api::IsoHeap::allocatorOffset): (bmalloc::api::IsoHeap::setAllocatorOffset): (bmalloc::api::IsoHeap::deallocatorOffset): (bmalloc::api::IsoHeap::setDeallocatorOffset): * bmalloc/IsoHeapImpl.cpp: Added. (bmalloc::IsoHeapImplBase::IsoHeapImplBase): (bmalloc::IsoHeapImplBase::~IsoHeapImplBase): (bmalloc::IsoHeapImplBase::scavengeNow): (bmalloc::IsoHeapImplBase::finishScavenging): * bmalloc/IsoHeapImpl.h: Added. * bmalloc/IsoHeapImplInlines.h: Added. (bmalloc::IsoHeapImpl<Config>::IsoHeapImpl): (bmalloc::IsoHeapImpl<Config>::takeFirstEligible): (bmalloc::IsoHeapImpl<Config>::didBecomeEligible): (bmalloc::IsoHeapImpl<Config>::scavenge): (bmalloc::IsoHeapImpl<Config>::allocatorOffset): (bmalloc::IsoHeapImpl<Config>::deallocatorOffset): (bmalloc::IsoHeapImpl<Config>::numLiveObjects): (bmalloc::IsoHeapImpl<Config>::numCommittedPages): (bmalloc::IsoHeapImpl<Config>::forEachDirectory): (bmalloc::IsoHeapImpl<Config>::forEachCommittedPage): (bmalloc::IsoHeapImpl<Config>::forEachLiveObject): * bmalloc/IsoHeapInlines.h: Added. (bmalloc::api::IsoHeap<Type>::allocate): (bmalloc::api::IsoHeap<Type>::tryAllocate): (bmalloc::api::IsoHeap<Type>::deallocate): (bmalloc::api::IsoHeap<Type>::scavenge): (bmalloc::api::IsoHeap<Type>::isInitialized): (bmalloc::api::IsoHeap<Type>::impl): * bmalloc/IsoPage.h: Added. (bmalloc::IsoPage::index const): (bmalloc::IsoPage::directory): (bmalloc::IsoPage::isInUseForAllocation const): (bmalloc::IsoPage::indexOfFirstObject): * bmalloc/IsoPageInlines.h: Added. (bmalloc::IsoPage<Config>::tryCreate): (bmalloc::IsoPage<Config>::IsoPage): (bmalloc::IsoPage<Config>::free): (bmalloc::IsoPage<Config>::startAllocating): (bmalloc::IsoPage<Config>::stopAllocating): (bmalloc::IsoPage<Config>::forEachLiveObject): * bmalloc/IsoPageTrigger.h: Added. * bmalloc/IsoTLS.cpp: Added. (bmalloc::IsoTLS::scavenge): (bmalloc::IsoTLS::IsoTLS): (bmalloc::IsoTLS::ensureEntries): (bmalloc::IsoTLS::destructor): (bmalloc::IsoTLS::sizeForCapacity): (bmalloc::IsoTLS::capacityForSize): (bmalloc::IsoTLS::size): (bmalloc::IsoTLS::forEachEntry): * bmalloc/IsoTLS.h: Added. * bmalloc/IsoTLSAllocatorEntry.h: Added. * bmalloc/IsoTLSAllocatorEntryInlines.h: Added. (bmalloc::IsoTLSAllocatorEntry<Config>::IsoTLSAllocatorEntry): (bmalloc::IsoTLSAllocatorEntry<Config>::~IsoTLSAllocatorEntry): (bmalloc::IsoTLSAllocatorEntry<Config>::construct): * bmalloc/IsoTLSDeallocatorEntry.h: Added. * bmalloc/IsoTLSDeallocatorEntryInlines.h: Added. (bmalloc::IsoTLSDeallocatorEntry<Config>::IsoTLSDeallocatorEntry): (bmalloc::IsoTLSDeallocatorEntry<Config>::~IsoTLSDeallocatorEntry): (bmalloc::IsoTLSDeallocatorEntry<Config>::construct): * bmalloc/IsoTLSEntry.cpp: Added. (bmalloc::IsoTLSEntry::IsoTLSEntry): (bmalloc::IsoTLSEntry::~IsoTLSEntry): * bmalloc/IsoTLSEntry.h: Added. (bmalloc::IsoTLSEntry::offset const): (bmalloc::IsoTLSEntry::alignment const): (bmalloc::IsoTLSEntry::size const): (bmalloc::IsoTLSEntry::extent const): * bmalloc/IsoTLSEntryInlines.h: Added. (bmalloc::IsoTLSEntry::walkUpToInclusive): (bmalloc::DefaultIsoTLSEntry<EntryType>::DefaultIsoTLSEntry): (bmalloc::DefaultIsoTLSEntry<EntryType>::~DefaultIsoTLSEntry): (bmalloc::DefaultIsoTLSEntry<EntryType>::move): (bmalloc::DefaultIsoTLSEntry<EntryType>::destruct): (bmalloc::DefaultIsoTLSEntry<EntryType>::scavenge): * bmalloc/IsoTLSInlines.h: Added. (bmalloc::IsoTLS::allocate): (bmalloc::IsoTLS::deallocate): (bmalloc::IsoTLS::scavenge): (bmalloc::IsoTLS::allocator): (bmalloc::IsoTLS::deallocator): (bmalloc::IsoTLS::get): (bmalloc::IsoTLS::set): (bmalloc::IsoTLS::ensureHeap): (bmalloc::IsoTLS::ensureHeapAndEntries): * bmalloc/IsoTLSLayout.cpp: Added. (bmalloc::IsoTLSLayout::IsoTLSLayout): (bmalloc::IsoTLSLayout::add): * bmalloc/IsoTLSLayout.h: Added. (bmalloc::IsoTLSLayout::head const): * bmalloc/PerHeapKind.h: * bmalloc/PerProcess.h: (bmalloc::PerProcess<T>::getFastCase): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::scavenge): * bmalloc/Scavenger.h: * bmalloc/bmalloc.h: (bmalloc::api::scavengeThisThread): * test: Added. * test/testbmalloc.cpp: Added. (hiddenTruthBecauseNoReturnIsStupid): (usage): (assertEmptyPointerSet): (assertHasObjects): (assertHasOnlyObjects): (assertClean): (testIsoSimple): (testIsoSimpleScavengeBeforeDealloc): (testIsoFlipFlopFragmentedPages): (testIsoFlipFlopFragmentedPagesScavengeInMiddle): (BisoMalloced::BisoMalloced): (testBisoMalloced): (BisoMallocedInline::BisoMallocedInline): (testBisoMallocedInline): (run): (main): 2017-10-30 Zan Dobersek <zdobersek@igalia.com> [ARM64][Linux] Re-enable Gigacage https://bugs.webkit.org/show_bug.cgi?id=178130 Reviewed by Michael Catanzaro. * bmalloc/Gigacage.h: Re-enable Gigacage on ARM64 Linux. 2017-10-25 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r222945. https://bugs.webkit.org/show_bug.cgi?id=178818 "It made WasmBench crash" (Requested by saamyjoon on #webkit). Reverted changeset: "bmalloc mutex should be adaptive" https://bugs.webkit.org/show_bug.cgi?id=177839 https://trac.webkit.org/changeset/222945 2017-10-24 Zan Dobersek <zdobersek@igalia.com> [Linux] Enable Gigacage in x64 Linux environment https://bugs.webkit.org/show_bug.cgi?id=177745 <rdar://problem/34773148> Reviewed by Yusuke Suzuki. Re-enable Gigacage on x86_64 Linux platforms after it was disabled in 223877. The cause for the revert was problems with huge coredumps being generated while Gigacage was enabled. The feature virtually allocates about 80GB of memory at the beginning of the process lifetime. This is not a problem in itself since the memory range is marked as not needed through madvise(), but all this memory was still included upon core dump generation on Linux. Since there are reasonable limits enforced upon core dumps, these were being truncated every time, not yielding any useful information. To avoid this, on Linux, invocations of madvise() with the MADV_NORMAL and MADV_DONTNEED advice parameters should be accompanied with respectively matching MADV_DODUMP and MADV_DONTDUMP madvise() calls. This correctly avoids core-dumping any memory that's not yet been physically allocated. * bmalloc/Gigacage.h: * bmalloc/VMAllocate.h: (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): 2017-10-24 David Kilzer <ddkilzer@apple.com> Need to pass non-nil argument to SimulateCrash() in bmalloc::logVMFailure() <https://webkit.org/b/178740> <rdar://problem/35154943> Reviewed by Saam Barati. * bmalloc/BPlatform.h: (BUNUSED_PARAM): Define macro. * bmalloc/Logging.cpp: (SimulateCrash): Change third argument of SimulateCrash() to CFStringRef since it's an NSString * in Objective-C. (bmalloc::logVMFailure): Create a CFStringRef to use as a description string. Use new vmSize parameter to log size. * bmalloc/Logging.h: (bmalloc::logVMFailure): Update function signature to take a size_t parameter representing vmSize. * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): Pass vmSize into logVMFailure(). 2017-10-23 Michael Catanzaro <mcatanzaro@igalia.com> Unreviewed, roll out r222731 https://bugs.webkit.org/show_bug.cgi?id=177745 <rdar://problem/34773148> Unfortunately Gigacage has broken core dump generation. * bmalloc/Gigacage.h: 2017-10-23 Zan Dobersek <zdobersek@igalia.com> bmalloc::api::tryLargeMemalignVirtual() shouldn't assert on a failed allocation https://bugs.webkit.org/show_bug.cgi?id=178654 Reviewed by Geoffrey Garen. * bmalloc/bmalloc.h: (bmalloc::api::tryLargeMemalignVirtual): Call Heap::tryAllocateLarge() instead of Heap::allocateLarge(). The former will return a null pointer upon a failed allocation, allowing the caller to fail gracefully just as the API entrypoint implies, while the latter currently provokes a crash in these circumstances. 2017-10-19 Saam Barati <sbarati@apple.com> Runtime disable gigacage on iOS because it broke WasmBench https://bugs.webkit.org/show_bug.cgi?id=178556 Reviewed by Keith Miller. * bmalloc/Gigacage.cpp: (Gigacage::shouldBeEnabled): 2017-10-17 Filip Pizlo <fpizlo@apple.com> You can't vmDeallocate null <rdar://problem/35038926> Reviewed by Michael Saboff. After failing allocation, we would try to deallocate the thing we failed to allocate. The fix is to not try to deallocate something that is obviously null. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): 2017-09-29 Filip Pizlo <fpizlo@apple.com> Enable gigacage on iOS https://bugs.webkit.org/show_bug.cgi?id=177586 Reviewed by JF Bastien. Introduce the ability to disable gigacage at runtime if allocation fails. If any step of gigacage allocation fails, we free all of the gigacages and turn off gigacage support. Roll this back in after discussion. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): (bmalloc::Cache::reallocate): * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::runway): (Gigacage::totalSize): (Gigacage::shouldBeEnabled): (): Deleted. (Gigacage::Callback::Callback): Deleted. (Gigacage::Callback::function): Deleted. (Gigacage::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): Deleted. * bmalloc/Gigacage.h: (Gigacage::wasEnabled): (Gigacage::isEnabled): (Gigacage::runway): Deleted. (Gigacage::totalSize): Deleted. * bmalloc/HeapKind.cpp: Added. (bmalloc::isActiveHeapKind): (bmalloc::mapToActiveHeapKind): * bmalloc/HeapKind.h: (bmalloc::isActiveHeapKindAfterEnsuringGigacage): (bmalloc::mapToActiveHeapKindAfterEnsuringGigacage): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::scavenge): * bmalloc/bmalloc.h: (bmalloc::api::tryLargeMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::isEnabled): 2017-10-11 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r223113 and r223121. https://bugs.webkit.org/show_bug.cgi?id=178182 Reintroduced 20% regression on Kraken (Requested by rniwa on #webkit). Reverted changesets: "Enable gigacage on iOS" https://bugs.webkit.org/show_bug.cgi?id=177586 https://trac.webkit.org/changeset/223113 "Use one virtual allocation for all gigacages and their runways" https://bugs.webkit.org/show_bug.cgi?id=178050 https://trac.webkit.org/changeset/223121 2017-10-07 Filip Pizlo <fpizlo@apple.com> Use one virtual allocation for all gigacages and their runways https://bugs.webkit.org/show_bug.cgi?id=178050 Reviewed by Saam Barati. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::runway): Deleted. (Gigacage::totalSize): Deleted. * bmalloc/Gigacage.h: 2017-09-29 Filip Pizlo <fpizlo@apple.com> Enable gigacage on iOS https://bugs.webkit.org/show_bug.cgi?id=177586 Reviewed by JF Bastien. Introduce the ability to disable gigacage at runtime if allocation fails. If any step of gigacage allocation fails, we free all of the gigacages and turn off gigacage support. Reland this after confirming that the 20% Kraken regression was a one-bot fluke. Local testing on the same kind of system did not show the regression. Saam and I both tried independently. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): (bmalloc::Cache::reallocate): * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::runway): (Gigacage::totalSize): (Gigacage::shouldBeEnabled): (): Deleted. (Gigacage::Callback::Callback): Deleted. (Gigacage::Callback::function): Deleted. (Gigacage::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): Deleted. * bmalloc/Gigacage.h: (Gigacage::wasEnabled): (Gigacage::isEnabled): (Gigacage::runway): Deleted. (Gigacage::totalSize): Deleted. * bmalloc/HeapKind.cpp: Added. (bmalloc::isActiveHeapKind): (bmalloc::mapToActiveHeapKind): * bmalloc/HeapKind.h: (bmalloc::isActiveHeapKindAfterEnsuringGigacage): (bmalloc::mapToActiveHeapKindAfterEnsuringGigacage): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::scavenge): * bmalloc/bmalloc.h: (bmalloc::api::tryLargeMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::isEnabled): 2017-10-09 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r223015 and r223025. https://bugs.webkit.org/show_bug.cgi?id=178093 Regressed Kraken on iOS by 20% (Requested by keith_mi_ on #webkit). Reverted changesets: "Enable gigacage on iOS" https://bugs.webkit.org/show_bug.cgi?id=177586 http://trac.webkit.org/changeset/223015 "Unreviewed, disable Gigacage on ARM64 Linux" https://bugs.webkit.org/show_bug.cgi?id=177586 http://trac.webkit.org/changeset/223025 2017-10-07 Yusuke Suzuki <utatane.tea@gmail.com> Unreviewed, disable Gigacage on ARM64 Linux https://bugs.webkit.org/show_bug.cgi?id=177586 Gigacage's LLInt change breaks ARM64 Linux. Currently we do not have maintainers for this. Let's simply disable it. * bmalloc/Gigacage.h: 2017-09-29 Filip Pizlo <fpizlo@apple.com> Enable gigacage on iOS https://bugs.webkit.org/show_bug.cgi?id=177586 Reviewed by JF Bastien. Introduce the ability to disable gigacage at runtime if allocation fails. If any step of gigacage allocation fails, we free all of the gigacages and turn off gigacage support. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): (bmalloc::Cache::reallocate): * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::runway): (Gigacage::totalSize): (Gigacage::shouldBeEnabled): (): Deleted. (Gigacage::Callback::Callback): Deleted. (Gigacage::Callback::function): Deleted. (Gigacage::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): Deleted. * bmalloc/Gigacage.h: (Gigacage::wasEnabled): (Gigacage::isEnabled): (Gigacage::runway): Deleted. (Gigacage::totalSize): Deleted. * bmalloc/HeapKind.cpp: Added. (bmalloc::isActiveHeapKind): (bmalloc::mapToActiveHeapKind): * bmalloc/HeapKind.h: (bmalloc::isActiveHeapKindAfterEnsuringGigacage): (bmalloc::mapToActiveHeapKindAfterEnsuringGigacage): * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::scavenge): * bmalloc/bmalloc.h: (bmalloc::api::tryLargeMemalignVirtual): (bmalloc::api::freeLargeVirtual): (bmalloc::api::isEnabled): 2017-10-05 Filip Pizlo <fpizlo@apple.com> Use one Scavenger thread for all Heaps https://bugs.webkit.org/show_bug.cgi?id=174973 Reviewed by JF Bastien. This combines the scavengers from all Heap instances into a single scavenger. It also combines the accounting for deciding when to run. Each Heap still controls what it means to scavenge itself (it's all in Heap::scavenge) but the policy decisions are all controlled by Scavenger. Because Scavenger is also the only thing that needs an AsyncTask, this removes AsyncTask and moves all of AsyncTask's logic into Scavenger. This appears to be a 1% progression on JetStream (with high statistical confidence: p = 0.0049). * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AsyncTask.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::allocateSmallChunk): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): (bmalloc::Heap::concurrentScavenge): Deleted. (bmalloc::Heap::scheduleScavengerIfUnderMemoryPressure): Deleted. (bmalloc::Heap::scheduleScavenger): Deleted. * bmalloc/Heap.h: * bmalloc/Scavenger.cpp: (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::run): (bmalloc::Scavenger::runHoldingLock): (bmalloc::Scavenger::runSoon): (bmalloc::Scavenger::runSoonHoldingLock): (bmalloc::Scavenger::didStartGrowing): (bmalloc::Scavenger::scheduleIfUnderMemoryPressure): (bmalloc::Scavenger::scheduleIfUnderMemoryPressureHoldingLock): (bmalloc::Scavenger::schedule): (bmalloc::Scavenger::threadEntryPoint): (bmalloc::Scavenger::threadRunLoop): (bmalloc::Scavenger::setSelfQOSClass): * bmalloc/Scavenger.h: (bmalloc::Scavenger::willRun): (bmalloc::Scavenger::willRunSoon): 2017-10-04 Filip Pizlo <fpizlo@apple.com> bmalloc mutex should be adaptive https://bugs.webkit.org/show_bug.cgi?id=177839 Reviewed by Michael Saboff. This pulls the WordLock algorithm into bmalloc, mostly by copy-pasting the code. We need to copy paste because sometimes we build WTF without bmalloc, so WTF cannot rely on bmalloc for anything other than malloc. Reland after fixing ancient WordLock bug: the notify_one has to happen with the lock held to ensure it doesn't run after that thread has died. * bmalloc/Algorithm.h: (bmalloc::compareExchangeWeak): (bmalloc::compareExchangeStrong): * bmalloc/PerThread.h: * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlow): (bmalloc::StaticMutex::unlockSlow): (bmalloc::StaticMutex::lockSlowCase): Deleted. * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::try_lock): (bmalloc::StaticMutex::isLocked const): (bmalloc::StaticMutex::init): (bmalloc::StaticMutex::tryLock): (bmalloc::StaticMutex::lock): (bmalloc::StaticMutex::unlock): (bmalloc::sleep): Deleted. (bmalloc::waitUntilFalse): Deleted. 2017-10-05 Matt Lewis <jlewis3@apple.com> Unreviewed, rolling out r222893. This caused multiple API failures. Reverted changeset: "bmalloc mutex should be adaptive" https://bugs.webkit.org/show_bug.cgi?id=177839 http://trac.webkit.org/changeset/222893 2017-10-05 Yusuke Suzuki <utatane.tea@gmail.com> [Linux] Port MallocBench https://bugs.webkit.org/show_bug.cgi?id=177856 Reviewed by Filip Pizlo. * CMakeLists.txt: 2017-10-04 Filip Pizlo <fpizlo@apple.com> bmalloc mutex should be adaptive https://bugs.webkit.org/show_bug.cgi?id=177839 Reviewed by Michael Saboff. This pulls the WordLock algorithm into bmalloc, mostly by copy-pasting the code. We need to copy paste because sometimes we build WTF without bmalloc, so WTF cannot rely on bmalloc for anything other than malloc. * bmalloc/Algorithm.h: (bmalloc::compareExchangeWeak): (bmalloc::compareExchangeStrong): * bmalloc/PerThread.h: * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlow): (bmalloc::StaticMutex::unlockSlow): (bmalloc::StaticMutex::lockSlowCase): Deleted. * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::try_lock): (bmalloc::StaticMutex::isLocked const): (bmalloc::StaticMutex::init): (bmalloc::StaticMutex::tryLock): (bmalloc::StaticMutex::lock): (bmalloc::StaticMutex::unlock): (bmalloc::sleep): Deleted. (bmalloc::waitUntilFalse): Deleted. 2017-10-02 Yusuke Suzuki <utatane.tea@gmail.com> [Linux] Enable Gigacage in x64 Linux environment https://bugs.webkit.org/show_bug.cgi?id=177745 Reviewed by Carlos Garcia Campos. This patch enables Gigacage in x64 Linux environment. Gigacage enforces a caged pointer to reference to the specific memory region. This reduces the effectiveness of some types of attacks setting a pointer to ArrayBuffer and modifying arbitrary memory region. * bmalloc/Gigacage.h: 2017-09-29 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r222625. https://bugs.webkit.org/show_bug.cgi?id=177664 causes crashes on iOS (Requested by pizlo-mbp on #webkit). Reverted changeset: "Enable gigacage on iOS" https://bugs.webkit.org/show_bug.cgi?id=177586 http://trac.webkit.org/changeset/222625 2017-09-28 Filip Pizlo <fpizlo@apple.com> Enable gigacage on iOS https://bugs.webkit.org/show_bug.cgi?id=177586 Reviewed by Michael Saboff. This enables Gigacage on iOS using a much smaller cage size. It's not necessary for it to be so small, but this is a good conservative starting point to start to exercise the code. * bmalloc/Gigacage.h: 2017-09-26 Filip Pizlo <fpizlo@apple.com> Put g_gigacageBasePtr into its own page and make it read-only https://bugs.webkit.org/show_bug.cgi?id=174972 Reviewed by Michael Saboff. This puts the gigacage base pointers into their own page and makes that page read-only. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): * bmalloc/Gigacage.h: (Gigacage::basePtr): (Gigacage::basePtrs): 2017-09-04 Adrian Perez de Castro <aperez@igalia.com> Unreviewed build fix for Clang with libc++ Fixes a build failure when building with Clang, -stdlib=libc++, and gigacage support enabled, which resulted in "stderr" being undefined. * bmalloc/Gigacage.cpp: Add missing <ctsdio> include to pull the definition. 2017-09-03 Yusuke Suzuki <utatane.tea@gmail.com> Large virtual memory region allocation requires MMAP_NORESERVE in Linux https://bugs.webkit.org/show_bug.cgi?id=176211 Reviewed by Geoffrey Garen. In Linux, we cannot allocate very large memory region without MMAP_NORESERVE. Linux kernel needs to reserve swap area for allocated memory region. If the swap area is exhausted, kernel fails to allocate the memory region with ENOMEM. This patch adds MMAP_NORESERVE to mmap flags in Linux. By adding this flag, mmap does not need to reserve swap area for the reserved memory region. This allows us to reserve very large memory region that is necessary for Gigacage. * bmalloc/BPlatform.h: * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): 2017-08-22 Filip Pizlo <fpizlo@apple.com> Strings need to be in some kind of gigacage https://bugs.webkit.org/show_bug.cgi?id=174924 Reviewed by Oliver Hunt. This adds a StringGigacage. * bmalloc/Gigacage.cpp: * bmalloc/Gigacage.h: (Gigacage::name): (Gigacage::basePtr): (Gigacage::forEachKind): * bmalloc/HeapKind.h: (bmalloc::isGigacage): (bmalloc::gigacageKind): (bmalloc::heapKind): 2017-08-30 Matt Lewis <jlewis3@apple.com> Unreviewed, rolling out r221384. This patch caused multiple 32-bit JSC test failures. Reverted changeset: "Strings need to be in some kind of gigacage" https://bugs.webkit.org/show_bug.cgi?id=174924 http://trac.webkit.org/changeset/221384 2017-08-22 Filip Pizlo <fpizlo@apple.com> Strings need to be in some kind of gigacage https://bugs.webkit.org/show_bug.cgi?id=174924 Reviewed by Oliver Hunt. This adds a StringGigacage. * bmalloc/Gigacage.cpp: * bmalloc/Gigacage.h: (Gigacage::name): (Gigacage::basePtr): (Gigacage::forEachKind): * bmalloc/HeapKind.h: (bmalloc::isGigacage): (bmalloc::gigacageKind): (bmalloc::heapKind): 2017-08-25 Daniel Bates <dabates@apple.com> Demarcate code added due to lack of NSDMI for aggregates https://bugs.webkit.org/show_bug.cgi?id=175990 Reviewed by Andy Estes. * bmalloc/BPlatform.h: * bmalloc/List.h: Be explicit when initializing m_node to improve readability. (bmalloc::ListNode::ListNode): 2017-08-23 Filip Pizlo <fpizlo@apple.com> Reduce Gigacage sizes https://bugs.webkit.org/show_bug.cgi?id=175920 Reviewed by Mark Lam. This introduces the ability to have different gigacage sizes for different gigacages, and uses it to reduce the size of both gigacages, but to different extents: Primitive gets 32GB with a 16GB runway and JSValue gets 16GB. This is a ~10% membuster progression on my Mac Pro. * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): * bmalloc/Gigacage.h: (Gigacage::size): (Gigacage::alignment): (Gigacage::mask): (Gigacage::runway): (Gigacage::totalSize): (Gigacage::caged): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::gigacageSize): * bmalloc/Heap.h: 2017-08-08 Filip Pizlo <fpizlo@apple.com> Baseline JIT should do caging https://bugs.webkit.org/show_bug.cgi?id=175037 Reviewed by Mark Lam. This centralizes the notion of permanently enabling the primitive gigacage, which we only do in jsc and WebProcess. This saves the baseline JIT from emitting some code. Otherwise it would always have to emit enabled checks on each typed array access. * bmalloc/Gigacage.cpp: (Gigacage::primitiveGigacageDisabled): (Gigacage::disableDisablingPrimitiveGigacageIfShouldBeEnabled): (Gigacage::isDisablingPrimitiveGigacageDisabled): * bmalloc/Gigacage.h: (Gigacage::isPrimitiveGigacagePermanentlyEnabled): (Gigacage::canPrimitiveGigacageBeDisabled): 2017-08-08 Ryan Haddad <ryanhaddad@apple.com> Unreviewed, rolling out r220368. This change caused WK1 tests to exit early with crashes. Reverted changeset: "Baseline JIT should do caging" https://bugs.webkit.org/show_bug.cgi?id=175037 http://trac.webkit.org/changeset/220368 2017-08-07 Filip Pizlo <fpizlo@apple.com> Baseline JIT should do caging https://bugs.webkit.org/show_bug.cgi?id=175037 Reviewed by Mark Lam. This centralizes the notion of permanently enabling the primitive gigacage, which we only do in jsc and WebProcess. This saves the baseline JIT from emitting some code. Otherwise it would always have to emit enabled checks on each typed array access. * bmalloc/Gigacage.cpp: (Gigacage::primitiveGigacageDisabled): (Gigacage::disableDisablingPrimitiveGigacageIfShouldBeEnabled): (Gigacage::isDisablingPrimitiveGigacageDisabled): * bmalloc/Gigacage.h: (Gigacage::isPrimitiveGigacagePermanentlyEnabled): (Gigacage::canPrimitiveGigacageBeDisabled): 2017-08-06 Filip Pizlo <fpizlo@apple.com> Primitive auxiliaries and JSValue auxiliaries should have separate gigacages https://bugs.webkit.org/show_bug.cgi?id=174919 Reviewed by Keith Miller. This introduces two kinds of Gigacage, Primitive and JSValue. This translates to two kinds of HeapKind, PrimitiveGigacage and JSValueGigacage. The new support functionality required turning Inline.h into BInline.h, and INLINE into BINLINE, and NO_INLINE into BNO_INLINE. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::refillAllocator): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateLogSizeClass): * bmalloc/AsyncTask.h: * bmalloc/BInline.h: Copied from Source/bmalloc/bmalloc/Inline.h. * bmalloc/Cache.cpp: (bmalloc::Cache::tryAllocateSlowCaseNullCache): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCaseNullCache): (bmalloc::Cache::reallocateSlowCaseNullCache): * bmalloc/Deallocator.cpp: * bmalloc/Gigacage.cpp: (Gigacage::PrimitiveDisableCallbacks::PrimitiveDisableCallbacks): (Gigacage::ensureGigacage): (Gigacage::disablePrimitiveGigacage): (Gigacage::addPrimitiveDisableCallback): (Gigacage::removePrimitiveDisableCallback): (Gigacage::Callbacks::Callbacks): Deleted. (Gigacage::disableGigacage): Deleted. (Gigacage::addDisableCallback): Deleted. (Gigacage::removeDisableCallback): Deleted. * bmalloc/Gigacage.h: (Gigacage::name): (Gigacage::basePtr): (Gigacage::forEachKind): (Gigacage::caged): (Gigacage::isCaged): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::usingGigacage): (bmalloc::Heap::gigacageBasePtr): * bmalloc/Heap.h: * bmalloc/HeapKind.h: (bmalloc::isGigacage): (bmalloc::gigacageKind): (bmalloc::heapKind): * bmalloc/Inline.h: Removed. * bmalloc/Map.h: * bmalloc/PerProcess.h: (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: (bmalloc::PerThread<T>::getFastCase): * bmalloc/Vector.h: (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): 2017-08-02 Filip Pizlo <fpizlo@apple.com> If Gigacage is disabled, bmalloc should service large aligned memory allocation requests through vmAllocate https://bugs.webkit.org/show_bug.cgi?id=175085 Reviewed by Saam Barati. This fixes a problem where if we used gmalloc, WebAssembly memory allocations would still use bmalloc's large allocator. We want to use the page allocator for those "large" allocations when the Gigacage is disabled. * bmalloc/DebugHeap.cpp: (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::memalignLarge): (bmalloc::DebugHeap::freeLarge): * bmalloc/DebugHeap.h: * bmalloc/Heap.cpp: (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::deallocateLarge): 2017-08-02 Filip Pizlo <fpizlo@apple.com> We should be OK with the gigacage being disabled on gmalloc https://bugs.webkit.org/show_bug.cgi?id=175082 Reviewed by Michael Saboff. This adds Gigacage::shouldBeEnabled(), which returns false when we're using gmalloc or other things that enable DebugHeap. * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): * bmalloc/Environment.h: * bmalloc/Gigacage.cpp: (Gigacage::ensureGigacage): (Gigacage::shouldBeEnabled): * bmalloc/Gigacage.h: * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): * bmalloc/Heap.h: 2017-08-01 Filip Pizlo <fpizlo@apple.com> Bmalloc and GC should put auxiliaries (butterflies, typed array backing stores) in a gigacage (separate multi-GB VM region) https://bugs.webkit.org/show_bug.cgi?id=174727 Reviewed by Mark Lam. This adds a mechanism for managing multiple isolated heaps in bmalloc. For now, these isoheaps (isolated heaps) have a very simple relationship with each other and with the rest of bmalloc: - You have to choose how many isoheaps you will have statically. See numHeaps in HeapKind.h. - Because numHeaps is static, each isoheap gets fast thread-local allocation. Basically, we have a Cache for each heap kind. - Each isoheap gets its own Heap. - Each Heap gets a scavenger thread. - Some things, like Zone/VMHeap/Scavenger, are per-process. Most of the per-HeapKind functionality is handled by PerHeapKind<>. This approach is ideal for supporting special per-HeapKind behaviors. For now we have two heaps: the Primary heap for normal malloc and the Gigacage. The gigacage is a 64GB-aligned 64GB virtual region that we now use for variable-length random-access allocations. No Primary allocations will go into the Gigacage. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/AllocationKind.h: Added. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): * bmalloc/Allocator.h: * bmalloc/BExport.h: Added. * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): (bmalloc::Cache::Cache): (bmalloc::Cache::tryAllocateSlowCaseNullCache): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCaseNullCache): (bmalloc::Cache::reallocateSlowCaseNullCache): (bmalloc::Cache::operator new): Deleted. (bmalloc::Cache::operator delete): Deleted. * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): (bmalloc::Cache::reallocate): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: * bmalloc/Gigacage.cpp: Added. (Gigacage::Callback::Callback): (Gigacage::Callback::function): (Gigacage::Callbacks::Callbacks): (Gigacage::ensureGigacage): (Gigacage::disableGigacage): (Gigacage::addDisableCallback): (Gigacage::removeDisableCallback): * bmalloc/Gigacage.h: Added. (Gigacage::caged): (Gigacage::isCaged): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::usingGigacage): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: (bmalloc::Heap::mutex): (bmalloc::Heap::kind const): (bmalloc::Heap::setScavengerThreadQOSClass): Deleted. * bmalloc/HeapKind.h: Added. * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: * bmalloc/PerHeapKind.h: Added. (bmalloc::PerHeapKindBase::PerHeapKindBase): (bmalloc::PerHeapKindBase::size): (bmalloc::PerHeapKindBase::at): (bmalloc::PerHeapKindBase::at const): (bmalloc::PerHeapKindBase::operator[]): (bmalloc::PerHeapKindBase::operator[] const): (bmalloc::StaticPerHeapKind::StaticPerHeapKind): (bmalloc::PerHeapKind::PerHeapKind): (bmalloc::PerHeapKind::~PerHeapKind): * bmalloc/PerThread.h: (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): (bmalloc::PerThreadStorage<Cache>::get): Deleted. (bmalloc::PerThreadStorage<Cache>::init): Deleted. * bmalloc/Scavenger.cpp: Added. (bmalloc::Scavenger::Scavenger): (bmalloc::Scavenger::scavenge): * bmalloc/Scavenger.h: Added. (bmalloc::Scavenger::setScavengerThreadQOSClass): (bmalloc::Scavenger::requestedScavengerThreadQOSClass const): * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::tryAllocateLargeChunk): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): * bmalloc/Zone.h: * bmalloc/bmalloc.h: (bmalloc::api::tryMalloc): (bmalloc::api::malloc): (bmalloc::api::tryMemalign): (bmalloc::api::memalign): (bmalloc::api::realloc): (bmalloc::api::tryLargeMemalignVirtual): (bmalloc::api::free): (bmalloc::api::freeLargeVirtual): (bmalloc::api::scavengeThisThread): (bmalloc::api::scavenge): (bmalloc::api::isEnabled): (bmalloc::api::setScavengerThreadQOSClass): * bmalloc/mbmalloc.cpp: 2017-08-01 Daewoong Jang <daewoong.jang@navercorp.com> Implement __builtin_clzl for MSVC https://bugs.webkit.org/show_bug.cgi?id=174232 Reviewed by Geoffrey Garen. * bmalloc/Algorithm.h: (bmalloc::clzl): (bmalloc::clzl<1>): (bmalloc::__builtin_clzl): * bmalloc/BPlatform.h: 2017-07-31 Mark Lam <mark.lam@apple.com> Fixed some comment typos. Not reviewed. * bmalloc/PerProcess.h: 2017-07-14 Filip Pizlo <fpizlo@apple.com> It should be easy to decide how WebKit yields https://bugs.webkit.org/show_bug.cgi?id=174298 Reviewed by Saam Barati. Use sched_yield() explicitly. * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlowCase): 2017-07-20 Chris Dumez <cdumez@apple.com> Replace calls to Vector::resize() with calls to more efficient shrink() / grow() when applicable https://bugs.webkit.org/show_bug.cgi?id=174660 Reviewed by Geoffrey Garen. Replace calls to Vector::resize() with calls to more efficient shrink() / grow() when applicable. This essentially replaces a branch to figure out if the new size is less or greater than the current size by an assertion. * bmalloc/Map.h: (bmalloc::Hash>::rehash): 2017-07-18 Andy Estes <aestes@apple.com> [Xcode] Enable CLANG_WARN_RANGE_LOOP_ANALYSIS https://bugs.webkit.org/show_bug.cgi?id=174631 Reviewed by Tim Horton. * Configurations/Base.xcconfig: 2017-07-18 Andy Estes <aestes@apple.com> [Xcode] Enable CLANG_WARN_OBJC_LITERAL_CONVERSION https://bugs.webkit.org/show_bug.cgi?id=174631 Reviewed by Sam Weinig. * Configurations/Base.xcconfig: 2017-07-18 Andy Estes <aestes@apple.com> [Xcode] Enable CLANG_WARN_NON_LITERAL_NULL_CONVERSION https://bugs.webkit.org/show_bug.cgi?id=174631 Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2017-07-18 Andy Estes <aestes@apple.com> [Xcode] Enable CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING https://bugs.webkit.org/show_bug.cgi?id=174631 Reviewed by Darin Adler. * Configurations/Base.xcconfig: 2017-07-12 Adrian Perez de Castro <aperez@igalia.com> bmalloc: Failure to build when the compiler specifically targets ARMv8-A / defines __ARM_ARCH_8A__ https://bugs.webkit.org/show_bug.cgi?id=174424 Reviewed by Michael Catanzaro. * bmalloc/BPlatform.h: Also check for __ARCH_ARM_8A__ to detect ARMv8. 2017-07-05 Daewoong Jang <daewoong.jang@navercorp.com> reinterpret_cast does not evaluate to constexpr https://bugs.webkit.org/show_bug.cgi?id=173622 Reviewed by Yusuke Suzuki. * bmalloc/Algorithm.h: (bmalloc::mask): (bmalloc::roundUpToMultipleOf): 2017-07-03 Andy Estes <aestes@apple.com> [Xcode] Add an experimental setting to build with ccache https://bugs.webkit.org/show_bug.cgi?id=173875 Reviewed by Tim Horton. * Configurations/DebugRelease.xcconfig: Included ccache.xcconfig. 2017-07-01 Dan Bernstein <mitz@apple.com> [iOS] Remove code only needed when building for iOS 9.x https://bugs.webkit.org/show_bug.cgi?id=174068 Reviewed by Tim Horton. * bmalloc/BPlatform.h: * bmalloc/VMAllocate.h: (bmalloc::vmPageSizePhysical): 2017-07-01 Dan Bernstein <mitz@apple.com> [macOS] Remove code only needed when building for OS X Yosemite https://bugs.webkit.org/show_bug.cgi?id=174067 Reviewed by Tim Horton. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2017-06-30 Ryosuke Niwa <rniwa@webkit.org> Ran sort-Xcode-project-file. * bmalloc.xcodeproj/project.pbxproj: 2017-06-19 Geoffrey Garen <ggaren@apple.com> bmalloc: Add a per-thread line cache https://bugs.webkit.org/show_bug.cgi?id=173552 Reviewed by Darin Adler. Previously, any thread could allocate out of any page with free lines. Now, the first thread to free a line in a page owns that page's free lines until the whole page becomes free. This patch is a big speedup on multi-threaded benchmarks. tree_churn --parallel gets 14% faster on a 2-core (4-hyper-core) MacBook Air and 2.85X faster on 12-core (24-hyper-core) Mac Pro. Other parallel benchmarks show significant but smaller speedups. Thread affinity is a great predictor of object lifetime. The per-thread line cache avoids the pathology of shuffling pages between threads, turning predictable lifetimes into unpredictable lifetimes, increasing fragmentation. On tree_churn --parallel, the per-thread line cache increases free memory found per page scanned by 2.85X. Free line scanning in fragmented pages is pretty expensive relative to other allocate / initialize / free operations. According to Instruments, on tree_churn --parallel, scanning is about 10X more expensive than freeing. This explains why a 2.85X improvement in scanning efficiency translates into a 2.85X overall speedup on tree_churn --parallel. * bmalloc/Allocator.cpp: (bmalloc::Allocator::refillAllocatorSlowCase): Pass through our line cache so the Heap can fill it. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): Scavenge our line cache. (bmalloc::Deallocator::processObjectLog): Deleted. * bmalloc/Deallocator.h: (bmalloc::Deallocator::lineCache): Added a line cache. * bmalloc/Heap.cpp: (bmalloc::Heap::deallocateLineCache): Deallocation function for thread destruction. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): Consult the new per-thread line cache for allocation and deallocation. * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): * bmalloc/List.h: (bmalloc::List::remove): Remove has always been a logically static operation. Declare it static now so that the Heap can remove a page from a thread's line cache without holding a direct pointer to the cache. * bmalloc/SmallPage.h: 2017-06-10 Dan Bernstein <mitz@apple.com> Reverted r218056 because it made the IDE reindex constantly. * Configurations/DebugRelease.xcconfig: 2017-06-10 Dan Bernstein <mitz@apple.com> [Xcode] With Xcode 9 developer beta, everything rebuilds when switching between command-line and IDE https://bugs.webkit.org/show_bug.cgi?id=173223 Reviewed by Sam Weinig. The rebuilds were happening due to a difference in the compiler options that the IDE and xcodebuild were specifying. Only the IDE was passing the -index-store-path option. To make xcodebuild pass that option, too, set CLANG_INDEX_STORE_ENABLE to YES if it is unset, and specify an appropriate path in CLANG_INDEX_STORE_PATH. * Configurations/DebugRelease.xcconfig: 2017-06-07 Geoffrey Garen <ggaren@apple.com> bmalloc: memory APIs don't need to be heap members https://bugs.webkit.org/show_bug.cgi?id=173076 Reviewed by Sam Weinig. Asking the OS about memory use is unrelated to the state of bmalloc's heap, so it's a better separation of concerns if related code is not part of the heap. * bmalloc/AvailableMemory.cpp: (bmalloc::memoryStatus): * bmalloc/AvailableMemory.h: (bmalloc::MemoryStatus::MemoryStatus): (bmalloc::isUnderMemoryPressure): (bmalloc::memoryFootprint): (bmalloc::percentAvailableMemoryInUse): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::updateMemoryInUseParameters): Deleted. * bmalloc/Heap.h: (bmalloc::Heap::isUnderMemoryPressure): Deleted. (bmalloc::Heap::memoryFootprint): Deleted. (bmalloc::Heap::percentAvailableMemoryInUse): Deleted. 2017-06-06 Yusuke Suzuki <utatane.tea@gmail.com> struct does not accept initializer-form if member has initializers in GCC 4.9 https://bugs.webkit.org/show_bug.cgi?id=172974 Reviewed by Carlos Garcia Campos. struct cannot accept initializer-form constructor (like, `ListNode<T> t { ... }`) if the member of the struct has a default initializer. Here is a simple snippet. template<typename T> struct Pair { T* prev { nullptr }; T* next { nullptr }; }; Pair<int> pair { nullptr, nullptr }; // compile erorr in GCC 4.9. Instead, we define a default constructor (to invoke default initializers) and a constructor to accept the above initialization. * bmalloc/List.h: (bmalloc::ListNode::ListNode): (bmalloc::List::iterator::iterator): 2017-06-06 Geoffrey Garen <ggaren@apple.com> Try to fix the GTK build. Unreviewed. * bmalloc/List.h: (bmalloc::List::List): 2017-06-05 Geoffrey Garen <ggaren@apple.com> Try to fix the GTK build. Unreviewed. * bmalloc/List.h: 2017-06-02 Geoffrey Garen <ggaren@apple.com> bmalloc: Small and large objects should share memory https://bugs.webkit.org/show_bug.cgi?id=172880 <rdar://problem/31494732> Reviewed by Sam Weinig. This reduces our high water mark memory usage on JetStream on macOS by 10%-20%. It also has the nice side effect that we can free small object metadata after returning from a high water mark. No change in throughput. Our old algorithm allocated small object chunks and large objects in segregated virtual memory and never recycled addresses between them. This provided a slight security benefit because we could apply guard pages between the segregated ranges and we would never reuse the same virtual address for object and metadata memory. Our new algorithm allocates small object chunks from the large object allocator. This naturally recycles memory between small chunks and large objects, and between small chunks of different page classes. This allows us to shift memory between allocation types as a program moves between different phases of allocation, and to delete small object chunk metadata when a program shrinks back from a high water mark. Two intuitions I had about memory use turned out to be backwards in this context: (1) I thought that this optimization would work because it allowed you to allocate and free a 4MB object and then reuse that large allocation to service small allocations. In practice, the common benefit seems to be the opposite: After you allocate and free many small objects, you can stitch them together to allocate a large object without growing the heap. (2) I thought that it would be more memory-efficient to allocate fine-grained pages from the large object allocator. In practice, giving the large object allocator too many arbitrarily-sized ranges to manage leads to fragmentation. Meanwhile, segregated fit is a powerful memory optimization. So, it's best to return small object memory to the large allocator only when a whole small object chunk is free. * bmalloc/Chunk.h: (bmalloc::Chunk::ref): (bmalloc::Chunk::deref): (bmalloc::Chunk::refCount): (bmalloc::Chunk::freePages): We keep a free list per chunk and refcount each chunk so we can notice when a chunk becomes empty, and return it to the large allocator. (bmalloc::forEachPage): A new helper function for iterating the pages in a Chunk. (bmalloc::Chunk::Chunk): Use forEachPage instead of manual iteration. Use { } initialization because we don't get zero-initialized by the OS anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): Don't bother unlocking while scavenging. I wasn't able to show it to be a consistent speedup. A more promising approach, if we find a motivating example, is for the scavenger to give up and return early if any other client is waiting on the lock. (bmalloc::Heap::allocateSmallChunk): New helper function for allocating a small chunk. It allocates through the large allocator to facilitate sharing. We still allocate a chunk at a time instead of a page at a time. Surprisingly, more precise page-at-a-time allocation is worse for memory use because of fragmentation. Segregated fit is a powerful optimization. (bmalloc::Heap::deallocateSmallChunk): New helper function for deallocating a small chunk. (bmalloc::Heap::allocateSmallPage): Updated for new APIs. (bmalloc::Heap::deallocateSmallLine): Updated for new APIs. Note that we cache one free chunk per page class. This avoids churn in the large allocator when you free(malloc(X)). (bmalloc::Heap::allocateSmallBumpRangesByMetadata): (bmalloc::Heap::allocateSmallBumpRangesByObject): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::scavengeSmallPages): Deleted. (bmalloc::Heap::scavengeLargeObjects): Deleted. * bmalloc/Heap.h: * bmalloc/LargeMap.h: (bmalloc::LargeMap::begin): (bmalloc::LargeMap::end): Added iteration helpers for scavenging. * bmalloc/LargeRange.h: (bmalloc::LargeRange::physicalSize): Added a comment about something that I confused myself about in this patch. * bmalloc/List.h: (bmalloc::List::iterator::operator*): (bmalloc::List::iterator::operator->): (bmalloc::List::iterator::operator!=): (bmalloc::List::iterator::operator++): (bmalloc::List::begin): (bmalloc::List::end): (bmalloc::List::pushFront): (bmalloc::List::remove): (bmalloc::ListNode::ListNode): Deleted. Added iteration helpers for scavenging. Changed the default state of a Node to null pointers instead of self pointers to distinguish the null node from the empty node for easier debugging. * bmalloc/Sizes.h: Changed the chunk size to 1MB to increase the chances of a chunk becoming free and recyclable. * bmalloc/SmallPage.h: (bmalloc::SmallPage::hasPhysicalPages): (bmalloc::SmallPage::setHasPhysicalPages): Track physical state by page instead of implicitly by which list a page is in. It's simpler not to have to move chunks and pages between physical vs virtual lists. (bmalloc::SmallPage::SmallPage): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): Deleted. (bmalloc::VMHeap::deallocateSmallPage): Deleted. Small chunk allocation just forwards to the large allocator now. * bmalloc/bmalloc.h: (bmalloc::api::scavenge): 2017-05-28 Dan Bernstein <mitz@apple.com> [Xcode] ALWAYS_SEARCH_USER_PATHS is set to YES https://bugs.webkit.org/show_bug.cgi?id=172691 Reviewed by Tim Horton. * Configurations/Base.xcconfig: Set ALWAYS_SEARCH_USER_PATHS to NO. 2017-05-25 Geoffrey Garen <ggaren@apple.com> and Michael Saboff <msaboff@apple.com> bmalloc: scavenger runs too much on JetStream https://bugs.webkit.org/show_bug.cgi?id=172373 Reviewed by Geoffrey Garen. Instruments says that JetStream on macOS spends about 3% of its time in madvise. In <https://bugs.webkit.org/show_bug.cgi?id=160098>, Ben saw some evidence that madvise was the reason that switching to bmalloc for DFG::Node allocations was a slowdown the first time around. In <https://bugs.webkit.org/show_bug.cgi?id=172124>, Michael saw that scavening policy can affect JetStream. Intuitively, it seems wrong for the heap to idle shrink during hardcore benchmarking. The strategy here is to back off in response to any heap growth event, and to wait 2s instead of 0.5s for heap growth to take place -- but we scavenge immediately in response to critical memory pressure, to avoid jetsam. One hole in this strategy is that a workload with a perfectly unfragmented heap that allocates and deallocates ~16kB every 2s will never shrink its heap. This doesn't seem to be a problem in practice. This looks like a 2% - 4% speedup on JetStream on Mac Pro and MacBook Air. * bmalloc/AsyncTask.h: (bmalloc::AsyncTask::willRun): (bmalloc::AsyncTask::willRunSoon): (bmalloc::Function>::AsyncTask): (bmalloc::Function>::run): (bmalloc::Function>::runSoon): (bmalloc::Function>::threadRunLoop): (bmalloc::Function>::runSlowCase): Deleted. Added a "run soon" state so that execution delay is modeled directly instead of implicitly through sleep events. This enables the Heap to issue a "run now" event at any moment in response ot memory pressure. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Don't call into our own API -- that's a layering violation. (bmalloc::Heap::updateMemoryInUseParameters): No need for m_scavengeSleepDuration anymore. (bmalloc::Heap::concurrentScavenge): Added a back-off policy when the heap is growing. (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeLargeObjects): Don't try to give up in the middle of a scavenge event. Our new backoff policy supplants that design. Also, it's easier to profile and understand scavenging behavior if it always runs to completion once started. (bmalloc::Heap::scheduleScavenger): (bmalloc::Heap::scheduleScavengerIfUnderMemoryPressure): Added a synchronous amortized check for memory pressure. This check has the benefit that it runs immediately during high rates of heap activity, so we can detect memory pressure right away and wake the scavenger instead of waiting for the scavenger to wake up. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: (bmalloc::Heap::isUnderMemoryPressure): * bmalloc/Sizes.h: * bmalloc/VMHeap.h: (bmalloc::VMHeap::deallocateSmallPage): * bmalloc/bmalloc.h: (bmalloc::api::scavenge): Updated for API changes above. 2017-05-17 Michael Saboff <msaboff@apple.com> [iOS] The Garbage Collector shouldn't rely on the bmalloc scavenger for up to date memory footprint info (172186) https://bugs.webkit.org/show_bug.cgi?id=172186 Reviewed by Geoffrey Garen. The calls memoryFootprint() and percentAvailableMemoryInUse() now make a system call to get the current memory footprint value. * bmalloc/Heap.h: (bmalloc::Heap::memoryFootprint): (bmalloc::Heap::percentAvailableMemoryInUse): 2017-05-16 Michael Saboff <msaboff@apple.com> REGRESSION(r216763): JetStream is 1% slower on Mac https://bugs.webkit.org/show_bug.cgi?id=172124 Reviewed by Filip Pizlo. It appears that changing maxScavengeSleepDuration from 512 to 250ms in r216763 is responsible for the regression. * bmalloc/Sizes.h: 2017-05-15 Geoffrey Garen <ggaren@apple.com> bmalloc: Bump the size of the deallocator log to 512 https://bugs.webkit.org/show_bug.cgi?id=172143 Reviewed by Michael Saboff. This is a speedup on parallel workloads for machines with lots of CPUs. * bmalloc/Sizes.h: 2017-05-12 Michael Saboff <msaboff@apple.com> [iOS] Use memory footprint to dynamically adjust behavior of allocators https://bugs.webkit.org/show_bug.cgi?id=171944 Reviewed by Filip Pizlo. This change is iOS only. After the scavenger thread completes scavenging, it asks the OS for how much total memory the process is using. This information is used to update the sleep delay for the scanvenger thread, as well as to provide memory in use data for other parts of the system. The scavenger sleep time is calculated using the following quadradic equation. scavengerSleep = 1.2*percentFreeMemory^2 - percentFreeMemory + 2 Where percentFreeMemory is between 0 and 100. The result is constrained to the values 2 and 250. This equation empirically works out to providing a 2ms sleep time when we have less than 10% memory available, 30ms when 20% is available and 250ms when 50% or more is available. In testing, this exponentially agressive scavenging delay by itself reduced memory usage and made it much more deterministic when used without the corresponding change in the JSC Heap. Changed the scavenger thread to use the User Initiated QOS priority to ensure it doesn't get starved. Moved the non-Windows functionality of WTF::RAMSize() to new files AvailableMemory.{cpp,h} and implemented in the function availableMemory(). That functions limits the value returned on iOS to a maximum of 840MB as that is the jetsam soft memory limit. Added a new API availableMemory() so that WTF::RAMSize() will use this value. * CMakeLists.txt: * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BPlatform.h: * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::updateMemoryInUseParameters): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): * bmalloc/Heap.h: (bmalloc::Heap::memoryFootprint): (bmalloc::Heap::percentAvailableMemoryInUse): * bmalloc/Sizes.h: * bmalloc/bmalloc.h: (bmalloc::api::availableMemory): (bmalloc::api::memoryFootprint): (bmalloc::api::percentAvailableMemoryInUse): * bmalloc/AvailableMemory.cpp: Added. (bmalloc::computeAvailableMemory): (bmalloc::availableMemory): * bmalloc/AvailableMemory.h: Added. 2017-05-05 Joseph Pecoraro <pecoraro@apple.com> Leaks always reports "WebKit Malloc Memory Pressure Handler" dispatch_queue/source as leaking https://bugs.webkit.org/show_bug.cgi?id=171532 Reviewed by Geoffrey Garen. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): * bmalloc/Heap.h: Store the dispatch_source_t in a member to avoid a false positive leak. 2017-04-27 Michael Saboff <msaboff@apple.com> bmalloc scavenger should know what page classes are allocating https://bugs.webkit.org/show_bug.cgi?id=171384 Reviewed by Geoffrey Garen. This change replaces m_isAllocatingPages with a per page class flag to track which page classes are currently allocating. When scavenging, we skip page classes that are actively allocating and come back to them on a subsequent pass. This reduces the amount of time it takes for scavenger to free up pages as well as the total time it takes to handle all page classes. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeLargeObjects): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: (bmalloc::Heap::takeRequestedScavengerThreadQOSClass): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::deallocateSmallPage): * bmalloc/bmalloc.h: (bmalloc::api::scavenge): 2017-04-25 Michael Saboff <msaboff@apple.com> Call bmalloc scavenger first when handling a memory pressure event https://bugs.webkit.org/show_bug.cgi?id=171289 Reviewed by Geoffrey Garen. Registered a critical memory pressure handler. We add this handler in addition to the call to release bmalloc memory in the WebCore releaseMemory handler for the case of JSC API users that don't use WebCore. When both handlers are in the process, it is basically a race. One will win, but the loser won't do any more work, so it is harmless. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): 2017-04-14 Mark Lam <mark.lam@apple.com> Update architectures in xcconfig files. https://bugs.webkit.org/show_bug.cgi?id=170867 <rdar://problem/31628104> Reviewed by Joseph Pecoraro. * Configurations/Base.xcconfig: 2017-04-12 Dan Bernstein <mitz@apple.com> [Mac] Future-proof .xcconfig files https://bugs.webkit.org/show_bug.cgi?id=170802 Reviewed by Tim Horton. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2017-02-03 Ting-Wei Lan <lantw44@gmail.com> Include cstdlib before using ::malloc and posix_memalign https://bugs.webkit.org/show_bug.cgi?id=167800 Reviewed by Geoffrey Garen. * bmalloc/DebugHeap.cpp: 2017-02-01 Andreas Kling <akling@apple.com> Implement the alwaysRunsAtBackgroundPriority WK2 setting using thread QoS. <https://webkit.org/b/167387> <rdar://problem/29711409> Reviewed by Antti Koivisto. Support changing the QoS level of the scavenger thread asynchronously through a request variable. This is not the most elegant thing in the world, but since threads are only allowed to change their own QoS class, our options are limited. * bmalloc/Heap.cpp: (bmalloc::Heap::concurrentScavenge): * bmalloc/Heap.h: (bmalloc::Heap::takeRequestedScavengerThreadQOSClass): (bmalloc::Heap::setScavengerThreadQOSClass): * bmalloc/bmalloc.h: (bmalloc::api::setScavengerThreadQOSClass): 2017-01-13 Geoffrey Garen <ggaren@apple.com> bmalloc: Use a separate zone when using system malloc https://bugs.webkit.org/show_bug.cgi?id=167014 Reviewed by Filip Pizlo. Harris asked for this so he could separate Safari and WebKit memory use when doing memory analysis. This patch adds an explicit DebugHeap class that contains all our code for specialized allocation with debugging. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Forward to DebugHeap instead of inlining all the code. This is required for our new interface, and it is also a nice simplification that moves some not-very-important code out of the way. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: Ditto. * bmalloc/DebugHeap.cpp: Added. (bmalloc::DebugHeap::DebugHeap): (bmalloc::DebugHeap::malloc): (bmalloc::DebugHeap::memalign): (bmalloc::DebugHeap::realloc): (bmalloc::DebugHeap::free): * bmalloc/DebugHeap.h: Added. New class for overriding normal heap behavior. Right now, it just adds a malloc zone and then forwards to system malloc -- but we can add lots more kinds of debug heaps in the future if we find them useful. * bmalloc/Environment.cpp: (bmalloc::Environment::Environment): (bmalloc::Environment::computeIsDebugHeapEnabled): (bmalloc::Environment::computeIsBmallocEnabled): Deleted. * bmalloc/Environment.h: (bmalloc::Environment::isDebugHeapEnabled): (bmalloc::Environment::isBmallocEnabled): Deleted. Renamed everything to reflect our new use of DebugHeap. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): * bmalloc/Heap.h: (bmalloc::Heap::debugHeap): Updated to use DebugHeap. (bmalloc::Heap::environment): Deleted. * bmalloc/bmalloc.h: (bmalloc::api::isEnabled): Updated to use DebugHeap. 2016-12-15 Myles C. Maxfield <mmaxfield@apple.com> Sort Xcode project files https://bugs.webkit.org/show_bug.cgi?id=165937 Reviewed by Simon Fraser. * bmalloc.xcodeproj/project.pbxproj: 2016-12-08 David Kilzer <ddkilzer@apple.com> Always check the return value of pthread_key_create() <https://webkit.org/b/165274> Reviewed by Darin Adler. * bmalloc/PerThread.h: (bmalloc::PerThreadStorage::init): Call BCRASH() if pthread_key_create() returns an error. The error code will be stored in a register available in a crash log, so no need to log the value explicitly. 2016-12-06 Alexey Proskuryakov <ap@apple.com> Correct SDKROOT values in xcconfig files https://bugs.webkit.org/show_bug.cgi?id=165487 rdar://problem/29539209 Reviewed by Dan Bernstein. Fix suggested by Dan Bernstein. * Configurations/DebugRelease.xcconfig: 2016-11-29 Andy Estes <aestes@apple.com> [Cocoa] Enable two clang warnings recommended by Xcode https://bugs.webkit.org/show_bug.cgi?id=164498 Reviewed by Mark Lam. * Configurations/Base.xcconfig: Enabled CLANG_WARN_INFINITE_RECURSION and CLANG_WARN_SUSPICIOUS_MOVE. 2016-11-10 Geoffrey Garen <ggaren@apple.com> bmalloc threads should have a non-default QoS https://bugs.webkit.org/show_bug.cgi?id=164612 Reviewed by Filip Pizlo. * bmalloc/AsyncTask.h: (bmalloc::Function>::threadEntryPoint): Request user-interactive quality of service because user-interactive tasks use malloc. 2016-10-20 Mark Lam <mark.lam@apple.com> bmalloc api should crash on failure to allocate when !isBmallocEnabled. https://bugs.webkit.org/show_bug.cgi?id=163766 Reviewed by Keith Miller and Filip Pizlo. We want to crash in bmalloc on failure to allocate even when !isBmallocEnabled. This is so that failures to allocate memory will manifest as crashes with a unique signature (i.e. as a SIGTRAP on release builds, or as a write to illegal address 0xbbadbeef on debug builds) and the crash will manifest inside bmalloc. This distinguishes allocation failures from other crashing bugs that manifest as SIGSEGVs due to random pointer dereferences in the clients of bmalloc. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::allocateSlowCase): 2016-09-26 Yoshiaki Jitsukawa <Yoshiaki.Jitsukawa@sony.com> Avoid implicit conversion from iterator to pointer https://bugs.webkit.org/show_bug.cgi?id=162482 Reviewed by Geoffrey Garen. Not every STL supporting such conversion, we should get a pointer explicitly. * bmalloc/Chunk.h: (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/FixedVector.h: (bmalloc::FixedVector::begin): 2016-08-31 Filip Pizlo <fpizlo@apple.com> Butterflies should be allocated in Auxiliary MarkedSpace instead of CopiedSpace and we should rewrite as much of the GC as needed to make this not a regression https://bugs.webkit.org/show_bug.cgi?id=160125 Reviewed by Geoffrey Garen and Keith Miller. I needed to tryMemalign, so I added such a thing. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): * bmalloc/Allocator.h: * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): * bmalloc/bmalloc.h: (bmalloc::api::tryMemalign): 2016-08-30 Yusuke Suzuki <utatane.tea@gmail.com> Unreviewed, build fix for GCC ports std::forward is declared in <utility> header. * bmalloc/ScopeExit.h: 2016-08-30 Geoffrey Garen <ggaren@apple.com> bmalloc: speed up the lock slow path https://bugs.webkit.org/show_bug.cgi?id=161058 Unreviewed roll-in - with regression fixed. Revert to using yield() instead of swtch() because very low priority background tasks can cause priority inversion and deadlock. In the network process, that happened with com.apple.WebKit.Cache.Storage.serialBackground. Still a big speedup on MallocBench. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/ScopeExit.h: Added. (bmalloc::ScopeExit::ScopeExit): (bmalloc::ScopeExit::~ScopeExit): (bmalloc::makeScopeExit): * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlowCase): * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::init): 2016-08-26 Geoffrey Garen <ggaren@apple.com> Unreviewed build fix. Fix the CMake build. * CMakeLists.txt: 2016-08-26 Geoffrey Garen <ggaren@apple.com> Renamed XLarge* => Large* https://bugs.webkit.org/show_bug.cgi?id=161261 Reviewed by Andreas Kling. XLarge is not a thing anymore: We just have Small and Large. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Heap.cpp: (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: * bmalloc/LargeMap.cpp: Copied from Source/bmalloc/bmalloc/XLargeMap.cpp. (bmalloc::LargeMap::remove): (bmalloc::LargeMap::add): (bmalloc::XLargeMap::remove): Deleted. (bmalloc::XLargeMap::add): Deleted. * bmalloc/LargeMap.h: Copied from Source/bmalloc/bmalloc/XLargeMap.h. (bmalloc::LargeMap::ranges): (bmalloc::XLargeMap::ranges): Deleted. * bmalloc/LargeRange.h: Copied from Source/bmalloc/bmalloc/XLargeRange.h. (bmalloc::LargeRange::LargeRange): (bmalloc::LargeRange::operator<): (bmalloc::canMerge): (bmalloc::merge): (bmalloc::LargeRange::split): (bmalloc::XLargeRange::XLargeRange): Deleted. (bmalloc::XLargeRange::operator<): Deleted. (bmalloc::XLargeRange::split): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): * bmalloc/VMHeap.h: * bmalloc/XLargeMap.cpp: Removed. * bmalloc/XLargeMap.h: Removed. * bmalloc/XLargeRange.h: Removed. 2016-08-26 Gavin Barraclough <barraclough@apple.com> bmalloc: speed up the lock slow path https://bugs.webkit.org/show_bug.cgi?id=161058 Unreviewed rollout - this caused regressions <rdar://problem/28026089>. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/ScopeExit.h: Removed. * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlowCase): * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::init): * bmalloc/ThreadSwitch.h: Removed. 2016-08-24 Andreas Kling <akling@apple.com> Add bmalloc::api::isEnabled(). <https://webkit.org/b/160534> Reviewed by Joseph Pecoraro. * bmalloc/bmalloc.h: (bmalloc::api::isEnabled): 2016-08-24 Filip Pizlo <fpizlo@apple.com> Unreviewed, roll out r204901, r204897, r204866, r204856, r204854. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): (bmalloc::Allocator::tryAllocate): Deleted. (bmalloc::Allocator::allocateImpl): Deleted. * bmalloc/Allocator.h: * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): Deleted. * bmalloc/bmalloc.h: (bmalloc::api::tryMemalign): Deleted. 2016-08-12 Filip Pizlo <fpizlo@apple.com> Butterflies should be allocated in Auxiliary MarkedSpace instead of CopiedSpace and we should rewrite as much of the GC as needed to make this not a regression https://bugs.webkit.org/show_bug.cgi?id=160125 Reviewed by Geoffrey Garen. I needed to tryMemalign, so I added such a thing. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocateImpl): (bmalloc::Allocator::reallocate): * bmalloc/Allocator.h: * bmalloc/Cache.h: (bmalloc::Cache::allocate): (bmalloc::Cache::tryAllocate): * bmalloc/bmalloc.h: (bmalloc::api::malloc): (bmalloc::api::tryMemalign): (bmalloc::api::memalign): 2016-08-22 Yusuke Suzuki <utatane.tea@gmail.com> Unreviewed, build fix on GCC environment https://bugs.webkit.org/show_bug.cgi?id=161058 std::forward is declared in <utility> header. * bmalloc/ScopeExit.h: 2016-08-22 Geoffrey Garen <ggaren@apple.com> bmalloc: speed up the lock slow path https://bugs.webkit.org/show_bug.cgi?id=161058 Reviewed by Filip Pizlo. It is generally accepted practice that a lock should yield instead of spinning when a lock acquisition fails, to avoid wasting CPU and power. There are two problems with this generally accepted practice: (1) It's a fallacy that yielding is free. In reality, yielding itself consumes CPU and power -- by performing a syscall, running the OS scheduler, and possibly performing a context switch. (Instruments traces of MallocBench show the cost of yielding.) Therefore, spinning a little to avoid yielding can actually *save* CPU and power. (2) std::this_thread_yield() on Darwin is way too aggressive: It not only yields but also depresses your priority to absolute zero for 10ms. A recent PLT trace showed a few spots where the main thread just gave up on loading and rendering a page for 10ms so an unimportant background task could run. To correct these problems, this patch adds a little bit of spinning to the bmalloc lock slow path. Below are performance results on various CPUs. Mac Pro (12 hyperthreaded cores = 24 threads): Baseline Patch Δ Execution Time: message_one 173ms 173ms message_many 953ms 927ms ^ 1.03x faster churn --parallel 60ms 41ms ^ 1.46x faster list_allocate --parallel 224ms 143ms ^ 1.57x faster tree_allocate --parallel 1,190ms 758ms ^ 1.57x faster tree_churn --parallel 1,517ms 906ms ^ 1.67x faster facebook --parallel 6,519ms 4,580ms ^ 1.42x faster reddit --parallel 5,097ms 3,411ms ^ 1.49x faster flickr --parallel 4,903ms 3,501ms ^ 1.4x faster theverge --parallel 6,641ms 4,505ms ^ 1.47x faster <geometric mean> 1,158ms 832ms ^ 1.39x faster <arithmetic mean> 2,728ms 1,895ms ^ 1.44x faster <harmonic mean> 332ms 240ms ^ 1.38x faster MacBook Air (2 hyperthreaded cores = 4 threads): Baseline Patch Δ Execution Time: message_one 911ms 907ms ^ 1.0x faster message_many 515ms 513ms ^ 1.0x faster churn --parallel 132ms 134ms ! 1.02x slower list_allocate --parallel 104ms 102ms ^ 1.02x faster tree_allocate --parallel 117ms 111ms ^ 1.05x faster tree_churn --parallel 154ms 151ms ^ 1.02x faster facebook --parallel 719ms 687ms ^ 1.05x faster reddit --parallel 382ms 341ms ^ 1.12x faster flickr --parallel 372ms 345ms ^ 1.08x faster theverge --parallel 489ms 444ms ^ 1.1x faster <geometric mean> 299ms 287ms ^ 1.04x faster <arithmetic mean> 390ms 374ms ^ 1.04x faster <harmonic mean> 227ms 220ms ^ 1.03x faster iPad (2 cores = 2 threads): [ Doesn't run Ruby, so no pretty subtest output. ] Baseline Patch Δ Execution Time: 174.14ms 171.5ms ^ 1.02x faster * bmalloc.xcodeproj/project.pbxproj: * bmalloc/ScopeExit.h: Added. A barebones very wimpy version of WTF::ScopeExit. (bmalloc::ScopeExit::ScopeExit): (bmalloc::ScopeExit::~ScopeExit): (bmalloc::makeScopeExit): * bmalloc/StaticMutex.cpp: (bmalloc::StaticMutex::lockSlowCase): Spin before yielding -- that's the speedup. Don't spin if another CPU is already spinning. In theory, more than one spinner accomplishes nothing, and I found that there's a cutoff around 8 or 16 spinners that becomes performance negative on Mac Pro. (Note: Another way to accomplish a similar result, if you don't want to use a bit of state in the lock, is to spin for a random duration between 0 and aLot. I tested a version of WTF::WeakRandom with unsynchronized static state and it worked great. But I ultimately opted for the explicit bit because I thought it was clearer.) * bmalloc/StaticMutex.h: (bmalloc::StaticMutex::init): Initialize our new bit. * bmalloc/ThreadSwitch.h: Added. (bmalloc::threadSwitch): Don't call yield() on Darwin because it's too aggressive. swtch() does what we want: Go run something else, without any other side-effects. 2016-08-03 Geoffrey Garen <ggaren@apple.com> [bmalloc] Merging of XLargeRanges can leak the upper range https://bugs.webkit.org/show_bug.cgi?id=160403 Reviewed by Michael Saboff. * bmalloc/Heap.cpp: (bmalloc::Heap::scavengeLargeObjects): Don't use removePhysical(). Recorded physical size is a performance optimization. It is not the truth. So it might be zero even if a range contains physical pages. Instead, iterate each range in the map unconditionally. The map can shrink when we release the lock, so we must clamp our iterator each time through the loop. The map can grow when we release the lock, but we don't care because growth restarts the scavenger from the beginning. * bmalloc/XLargeMap.cpp: (bmalloc::XLargeMap::removePhysical): Deleted. Not used anymore. * bmalloc/XLargeMap.h: (bmalloc::XLargeMap::ranges): Added direct access for the sake of scavengeLargeObjects. (This violates our naming conventions -- I'll do a rename in a follow-up patch.) 2016-07-13 Enrica Casucci <enrica@apple.com> Update supported platforms in xcconfig files to match the sdk names. https://bugs.webkit.org/show_bug.cgi?id=159728 Reviewed by Tim Horton. * Configurations/Base.xcconfig: 2016-07-11 Geoffrey Garen <ggaren@apple.com> Crash due to abort() calling libc++.1.dylib: std::__1::thread::detach() https://bugs.webkit.org/show_bug.cgi?id=159655 Reviewed by Sam Weinig. It's not entirely clear what was happening in these crashes, but our use of detach() was 100% forward-looking, so we can just remove it for now. This patch removes the ability for the scavenger owner to die before the scavenger thread dies (which was unused) and also removes the ability for the scavenger thread to exit (which was used, but we messed up and did thread joining lazily, so we never got any benefit from thread exit.) We can add these features back when we need them, and make them work then. * bmalloc/AsyncTask.h: (bmalloc::Function>::AsyncTask): We start out in the running state now because we know that starting our thread will run it. (bmalloc::Function>::~AsyncTask): We don't support destruction anymore. (bmalloc::Function>::runSlowCase): I removed the Exited state. (bmalloc::Function>::threadRunLoop): I removed the Exited and ExitRequested states. * bmalloc/Heap.h: * bmalloc/VMHeap.h: 2016-06-12 David Kilzer <ddkilzer@apple.com> Crash in com.apple.WebKit.WebContent at std::__1::__call_once_proxy<std::__1::tuple<CrashReporterSupportLibrary()::$_0&&> > <https://webkit.org/b/158660> <rdar://problem/25652686> Reviewed by Darin Adler. * bmalloc/Logging.cpp: Switch to use BSOFT_LINK_PRIVATE_FRAMEWORK() to link CrashReporterSupport.framework. * bmalloc/darwin/BSoftLinking.h: (BSOFT_LINK_PRIVATE_FRAMEWORK): Rename from BSOFT_LINK_FRAMEWORK. Switch to use /System/Library/PrivateFrameworks/. 2016-06-11 David Kilzer <ddkilzer@apple.com> Implement logging for RELEASE_BASSERT_WITH_MESSAGE() in BAssert.h <http://webkit.org/b/155992> Reviewed by Geoff Garen. * bmalloc/BAssert.h: (BLOG_ERROR): Add method to always log error messages. (RELEASE_BASSERT_WITH_MESSAGE): Use BLOG_ERROR() to implement logging in Debug builds. * bmalloc/BPlatform.h: (BPLATFORM_MAC): Add. (BUSE): Add BUSE() macro. (BATTRIBUTE_PRINTF): Add. (BUSE_OS_LOG): Add. * bmalloc/Logging.cpp: (bmalloc::reportAssertionFailureWithMessage): Add. Logs to stderr. * bmalloc/Logging.h: (bmalloc::reportAssertionFailureWithMessage): Add declaration. 2016-06-07 Pranjal Jumde <pjumde@apple.com> Prevents integer overflow in Vector.h https://bugs.webkit.org/show_bug.cgi?id=158455 <rdar://problem/20235469> Reviewed by Mark Lam. * bmalloc/Vector.h: (bmalloc::Vector<T>::reallocateBuffer): 2016-05-27 Konstantin Tokarev <annulen@yandex.ru> [cmake] Deduplicated bmalloc/Zone.cpp handling. https://bugs.webkit.org/show_bug.cgi?id=158154 Reviewed by Alex Christensen. File bmalloc/Zone.cpp is required on Darwin irrespectively from what port is being built. Also I removed WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS() because it's unlikely that bmalloc will ever need port-specific customizations (as opposed to OS-specific customizations which should be done in CMakeLists.txt). * CMakeLists.txt: Added bmalloc/Zone.cpp for Darwin. * PlatformGTK.cmake: Removed. * PlatformMac.cmake: Removed. 2016-05-22 Brady Eidson <beidson@apple.com> Move to C++14. https://bugs.webkit.org/show_bug.cgi?id=157948 Reviewed by Michael Catanzaro. * Configurations/Base.xcconfig: 2016-05-17 Geoffrey Garen <ggaren@apple.com> REGRESSION: JetStream crashes on some iPhones https://bugs.webkit.org/show_bug.cgi?id=157814 Reviewed by Michael Saboff. * bmalloc/Sizes.h: Reduce smallMax to 32kB. Previous justification for 64kB was: * bmalloc/Sizes.h: Upped smallMax to 64kB. Upping to 32kB is pretty reasonable, since sizes between 16kB and 32kB share page sizes. I went all the way up to 64kB because the GC uses 64kB blocks, and also just for extra padding to ensure that large allocations are indeed rare. It turns out that the bump to 64kB substantially increases our memory high water mark on JetStream, leading to jetsam crashes. Also, there doesn't seem to be a practical performance problem to putting objects in the (32kB - 64kB) range in the large allocator. 2016-05-16 Geoffrey Garen <ggaren@apple.com> REGRESSION (200035): changes in "WebKit Malloc" VM regions are causing 'leaks' to spew "Failed to map remote region" messages https://bugs.webkit.org/show_bug.cgi?id=157764 Reviewed by Gavin Barraclough. We need to allow for guard pages and only report unguarded pages to the leaks tool -- otherwise, it will try to remote map our guarded pages, and crash. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): Adopt the new API for reporting a range instead of a Chunk*, and report the unguarded range. This also fixes a separate bug -- very large allocations would not fully participate in pointer scanning because they would only report 2MB (chunkSize) in size. This could cause false-positive leak reports. * bmalloc/Zone.cpp: (bmalloc::enumerator): Updated to scan ranges instead of fixed-sized Chunk pointers. * bmalloc/Zone.h: (bmalloc::Zone::ranges): (bmalloc::Zone::addRange): Store ranges instead of fixed-sized Chunk pointers because our VM ranges have variable sizes -- both due to guard pages and due to large allocations. (bmalloc::Zone::chunks): Deleted. (bmalloc::Zone::addChunk): Deleted. 2016-05-10 David Kilzer <ddkilzer@apple.com> bmalloc should automatically disable itself when ThreadSanitizer is used <https://webkit.org/b/157527> Reviewed by Michael Catanzaro. * bmalloc/Environment.cpp: (bmalloc::isASanEnabled): Rename to isSanitizerEnabled. (bmalloc::isSanitizerEnabled): Rename from isASanEnabled. Add support for detecting ThreadSanitizer. (bmalloc::Environment::computeIsBmallocEnabled): Switch from isASanEnabled to isSanitizerEnabled. 2016-05-03 Geoffrey Garen <ggaren@apple.com> Assertion failure in bmalloc::vmRevokePermissions(void*, unsigned long). https://bugs.webkit.org/show_bug.cgi?id=157047 Reviewed by Filip Pizlo. Renamed roundUpToMultipleOfSloppy => roundUpToMultipleOfNonPowerOfTwo. * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOfNonPowerOfTwo): (bmalloc::roundUpToMultipleOfSloppy): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): 2016-05-03 Geoffrey Garen <ggaren@apple.com> Assertion failure in bmalloc::vmRevokePermissions(void*, unsigned long). https://bugs.webkit.org/show_bug.cgi?id=157047 Reviewed by Filip Pizlo. The previous fix aligned the guard page sizes correctly but forgot to align the guard page start address correctly. * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOfSloppy): Use a new helper method to round up when not working with a power of two, instead of writing out the math by hand. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): Make sure to round up the guard page start address in addition to its size. Assert at the very end to try to catch more bugs. 2016-04-27 Geoffrey Garen <ggaren@apple.com> Assertion failure in bmalloc::vmRevokePermissions(void*, unsigned long). https://bugs.webkit.org/show_bug.cgi?id=157047 Reviewed by Darin Adler. * bmalloc/Chunk.h: (bmalloc::Chunk::Chunk): (bmalloc::Chunk::get): (bmalloc::Chunk::offset): (bmalloc::Chunk::address): (bmalloc::Object::Object): (bmalloc::Object::address): (bmalloc::Object::line): (bmalloc::Chunk::object): Deleted. (bmalloc::Object::begin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallBumpRangesByObject): * bmalloc/Object.h: (bmalloc::Object::chunk): (bmalloc::Object::offset): Renamed begin() to address() because this is not an iterator. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): Round up pageSize to a vmPageSize multiple because pageSize might be smaller than vmPageSize, but we think the VM system requires vmPageSize-aligned values. 2016-04-25 Geoffrey Garen <ggaren@apple.com> bmalloc: vm allocations should plant guard pages https://bugs.webkit.org/show_bug.cgi?id=156937 Rolling back in r199936 with a fix for the memory regression. 2016-04-23 Gavin Barraclough <barraclough@apple.com> bmalloc: vm allocations should plant guard pages https://bugs.webkit.org/show_bug.cgi?id=156937 Rolling out - looks like this is memory regression. * bmalloc/Object.h: (bmalloc::Object::operator+): (bmalloc::Object::operator<=): (bmalloc::Object::operator-): Deleted. * bmalloc/VMAllocate.h: (bmalloc::vmDeallocate): (bmalloc::vmRevokePermissions): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): 2016-04-22 Geoffrey Garen <ggaren@apple.com> bmalloc: vm allocations should plant guard pages https://bugs.webkit.org/show_bug.cgi?id=156937 Reviewed by Michael Saboff. * bmalloc/Object.h: (bmalloc::Object::operator-): Added a - helper. * bmalloc/VMAllocate.h: (bmalloc::vmRevokePermissions): Added a helper to revoke permissions on a VM region. We use this for guard pages. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): Add guard pages to the start and end of the chunk. Note that we don't guard large chunks becuase we need to be able to merge them. Otherwise, we will run out of virtual addresses. 2016-04-22 Geoffrey Garen <ggaren@apple.com> bmalloc: Constify introspect function pointer table https://bugs.webkit.org/show_bug.cgi?id=156936 Reviewed by Michael Saboff. * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): Declaring this function pointer table const puts it in the read-only section of the binary, providing a little hardening against overwriting the function pointers at runtime. (We have to const_cast when assigning because the API declares a pointer to non-const, but we happen to know it will never try to write through that pointer. This is not my favorite API.) 2016-04-19 Geoffrey Garen <ggaren@apple.com> bmalloc: fix up overflow checks https://bugs.webkit.org/show_bug.cgi?id=156780 Reviewed by Mark Lam. We used to try to avoid overflow in large object math by setting a very high limit on the largest large object. But that's a bit error-prone since the check is far away from the math that might overflow -- and we were missing some cases. This patch removes the limit and instead checks at each math site. * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocate): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::allocateSlowCase): Remove the limit. tryAllocateLarge will check for overflow for us. * bmalloc/Chunk.h: This ASSERT was just totally wrong. * bmalloc/Heap.cpp: (bmalloc::Heap::tryAllocateLarge): Check for overflow when adding. * bmalloc/Sizes.h: * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): Check for overflow when adding. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): Check for overflow when adding. 2016-04-19 Geoffrey Garen <ggaren@apple.com> Unreviewed, try to fix an ASSERT seen on the bots. * bmalloc/Heap.cpp: (bmalloc::Heap::tryAllocateLarge): This ASSERT is supposed to be about alignment, not size. Oops. 2016-04-19 Geoffrey Garen <ggaren@apple.com> bmalloc: Merge the large and xlarge allocators https://bugs.webkit.org/show_bug.cgi?id=156734 Reviewed by Andreas Kling. This give us better defense against worst case memory usage: Baseline Patch Δ Peak Memory: nimlang 198,132kB 181,468kB ^ 1.09x smaller It also eliminates inline metadata for large objects, fixing the regression introduced in r198675, and more: run-malloc-benchmarks Baseline:~/OpenSource/WebKitBuildBaseline/Release/ Patch:~/OpenSource/WebKitBuild/Release/ Baseline Patch Δ Memory at End: big 10,880kB 3,328kB ^ 3.27x smaller facebook 3,112kB 2,868kB ^ 1.09x smaller fragment --parallel 1,848kB 760kB ^ 2.43x smaller fragment_iterate --parallel 4,908kB 776kB ^ 6.32x smaller big --parallel 48,076kB 11,892kB ^ 4.04x smaller Overall memory use looks OK: run-malloc-benchmarks --memory_warning Baseline:~/OpenSource/WebKitBuildBaseline/Release/ Patch:~/OpenSource/WebKitBuild/Release/ Baseline Patch Δ Memory at End: <arithmetic mean> 13,992kB 13,987kB ^ 1.0x smaller Overall throughput looks OK: run-malloc-benchmarks Baseline:~/OpenSource/WebKitBuildBaseline/Release/ Patch:~/OpenSource/WebKitBuild/Release/ Baseline Patch Δ Execution Time: <arithmetic mean> 103ms 104ms ! 1.01x slower We're a bit slower on the "all-out large allocations on all cores" benchmark, but I think that's an OK price to pay: Baseline Patch Δ Execution Time: big --parallel 125ms 136ms ! 1.09x slower This patch net removes 1.5k lines of code. It turns out that large allocations are rare, and free memory fragments are also rare, so the combination is super rare, and a simple O(n) algorithm that ensures good memory behavior is the best option. Fun fact: In practice, the odds that the old code would save memory were *worse* than the odds that it would contain a bug that wasted memory. :) * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): largeMax is the new xLargeMax since xLargeMax is gone now. (bmalloc::Allocator::allocate): I moved the rounding code into allocateLarge, so we don't have to do it here. (bmalloc::Allocator::reallocate): (bmalloc::Allocator::allocateSlowCase): (bmalloc::Allocator::allocateXLarge): Deleted. No more XLarge case. * bmalloc/Allocator.h: * bmalloc/BeginTag.h: Removed. * bmalloc/BoundaryTag.h: Removed. * bmalloc/Chunk.h: (bmalloc::ChunkHash::hash): Added a hash function. The best hash function is a unique and monotonically increasing integer, and that's exactly what we typically get from the high bits of a Chunk, since the OS allocates Chunks at unique and increasing addresses. (bmalloc::Chunk::boundaryTags): Deleted. (bmalloc::Chunk::objectType): Deleted. (bmalloc::Chunk::beginTag): Deleted. (bmalloc::Chunk::endTag): Deleted. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::deallocateSlowCase): We no longer know for sure, by looking at its bit pattern, whether a pointer is small or large. Instead, any pointer with large alignment *might* be large, and when we occasionally encounter such an object, we have to consult a hash table in the Heap to find out for sure. This turns out to be just as cheap in practice. We don't deallocate large objects on the fast path anymore. We can't, because large objects have out-of-line metadata now. (bmalloc::Deallocator::deallocateXLarge): Deleted. * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): See deallocateSlowCase. * bmalloc/EndTag.h: Removed. * bmalloc/FreeList.cpp: Removed. * bmalloc/FreeList.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallPage): Be sure to track each chunk in the object type map, so we can distinguish small vs large objects. (bmalloc::Heap::deallocateSmallLine): No need to check object type because we know object type now by virtue of being on the small object path. (bmalloc::Heap::splitAndAllocate): Be sure to track each chunk in the object type map, so we can distinguish small vs large objects. Large objects can split across chunks, so we need to add each large object's chunk as it is allocated. (bmalloc::Heap::tryAllocateLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::isLarge): (bmalloc::Heap::largeSize): (bmalloc::Heap::shrinkLarge): (bmalloc::Heap::deallocateLarge): Merged in existing XLarge logic for large objects. (bmalloc::Heap::scavengeXLargeObjects): Deleted. (bmalloc::Heap::allocateXLarge): Deleted. (bmalloc::Heap::tryAllocateXLarge): Deleted. (bmalloc::Heap::xLargeSize): Deleted. (bmalloc::Heap::shrinkXLarge): Deleted. (bmalloc::Heap::deallocateXLarge): Deleted. * bmalloc/Heap.h: (bmalloc::Heap::LargeObjectHash::hash): * bmalloc/LargeObject.h: Removed. * bmalloc/Map.h: Added. (bmalloc::Map::size): (bmalloc::Map::capacity): (bmalloc::Map::get): (bmalloc::Map::set): (bmalloc::Map::remove): (bmalloc::Map::shouldGrow): (bmalloc::Map::shouldShrink): (bmalloc::Map::find): (bmalloc::Hash>::rehash): Simple hash table. * bmalloc/Object.h: * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: (bmalloc::mightBeLarge): See deallocateSlowCase. (bmalloc::isXLarge): Deleted. * bmalloc/SegregatedFreeList.cpp: Removed. * bmalloc/SegregatedFreeList.h: Removed. * bmalloc/Sizes.h: Upped smallMax to 64kB. Upping to 32kB is pretty reasonable, since sizes between 16kB and 32kB share page sizes. I went all the way up to 64kB because the GC uses 64kB blocks, and also just for extra padding to ensure that large allocations are indeed rare. * bmalloc/SortedVector.h: Removed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::tryAllocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::VMHeap): Deleted. (bmalloc::VMHeap::allocateChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::allocateLargeObject): Deleted. (bmalloc::VMHeap::deallocateLargeObject): Deleted. Nixed all the boundary tag logic since metadata is out of line now. * bmalloc/VMState.h: Removed. Instead of an abstract state, we track the precise amount of committed physical pages at the head of a VM range. This allows us to merge aggressively without triggering an madvise storm most of the time. * bmalloc/Vector.h: (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::remove): (bmalloc::Vector<T>::resize): Filled out some missing helpers. * bmalloc/XLargeMap.cpp: (bmalloc::XLargeMap::remove): (bmalloc::XLargeMap::add): (bmalloc::XLargeMap::removePhysical): (bmalloc::XLargeMap::takeFree): Deleted. (bmalloc::XLargeMap::addFree): Deleted. (bmalloc::XLargeMap::addAllocated): Deleted. (bmalloc::XLargeMap::getAllocated): Deleted. (bmalloc::XLargeMap::takeAllocated): Deleted. (bmalloc::XLargeMap::shrinkToFit): Deleted. (bmalloc::XLargeMap::takePhysical): Deleted. (bmalloc::XLargeMap::addVirtual): Deleted. * bmalloc/XLargeMap.h: (bmalloc::XLargeMap::Allocation::operator<): Deleted. We don't track object sizes anymore -- just free space. (The Heap tracks object sizes.) We use plain old linear search for free space. (See intro.) * bmalloc/XLargeRange.h: (bmalloc::XLargeRange::physicalSize): (bmalloc::XLargeRange::setPhysicalSize): (bmalloc::merge): (bmalloc::XLargeRange::split): (bmalloc::XLargeRange::vmState): Deleted. (bmalloc::XLargeRange::setVMState): Deleted. See VMState.h. 2016-04-11 Fujii Hironori <Hironori.Fujii@jp.sony.com> [CMake] Make FOLDER property INHERITED https://bugs.webkit.org/show_bug.cgi?id=156460 Reviewed by Brent Fulgham. * CMakeLists.txt: Set FOLDER property as a directory property not a target property 2016-04-08 Geoffrey Garen <ggaren@apple.com> bmalloc: stress_aligned test fails if you increase smallMax https://bugs.webkit.org/show_bug.cgi?id=156414 Reviewed by Oliver Hunt. When size exceeds alignment and is a multiple of alignment and is not a power of two, such as 24kB with 8kB alignment, the small allocator did not always guarantee alignment. Let's fix that. * bmalloc/Algorithm.h: (bmalloc::divideRoundingUp): Math is hard. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): Align to the page size unconditionally. Even if the page size is not a power of two, it might be a multiple of a power of two, and we want alignment to that smaller power of two to be guaranteed. 2016-04-06 Geoffrey Garen <ggaren@apple.com> bmalloc: handle aligned allocations on the fast path https://bugs.webkit.org/show_bug.cgi?id=156302 Reviewed by Michael Saboff. This helps keep the JavaScriptCore GC on the fast path, and it also helps avoid fragmentation on our website stress test: nimlang 209,584kB 198,076kB ^ 1.06x smaller * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): Because we arrange for power-of-two size classes to allocate at power-of-two alignments, we can allocate any small aligned request on the small path. * bmalloc/Chunk.h: (bmalloc::Chunk::bytes): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): (bmalloc::Chunk::boundaryTags): (bmalloc::Chunk::objectType): Moved some code around to provide better API. (bmalloc::Chunk::Chunk): Moved this code to VMHeap. (bmalloc::Chunk::offset): (bmalloc::Chunk::object): Use our new bytes() helper function. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateChunk): Moved code here from Chunk. (bmalloc::VMHeap::allocateSmallChunk): Ensure that power-of-two page sizes always begin allocation at the same alignment. Power-of-two object sizes always request power-of-two page sizes (since that's the least wasteful option), so if we also ensure that power-of-two page sizes get power-of-two alignment, then everything is aligned for all small objects. 2016-04-03 Geoffrey Garen <ggaren@apple.com> bmalloc: segregate small and large objects again, and allocate more objects on the small path https://bugs.webkit.org/show_bug.cgi?id=156152 Reviewed by Sam Weinig. Microbenchmark data suggested that it was a good idea for small and large objects to share memory. But r198675 did not improve memory use in full browser benchmarks. This patch reverts to segregating small and large objects -- but without going back to doubled VM usage -- in order to capture a few benefits: (*) Small pages fragment the large heap. Separating them out saves a lot of memory in our worst case fragmentation recording: nimlang 276,076kB 209,636kB ^ 1.32x smaller (*) Small objects are common enough that even their slow paths benefit from simpler code: Execution Time: ... facebook 234ms 216ms ^ 1.08x faster reddit 114ms 108ms ^ 1.06x faster flickr 118ms 111ms ^ 1.06x faster theverge 146ms 140ms ^ 1.04x faster ... <arithmetic mean> 107ms 102ms ^ 1.04x faster (*) We can use less metadata: Memory at End: ... list_allocate 460kB 384kB ^ 1.2x smaller tree_allocate 492kB 424kB ^ 1.16x smaller tree_churn 480kB 404kB ^ 1.19x smaller fragment 532kB 452kB ^ 1.18x smaller fragment_iterate 712kB 588kB ^ 1.21x smaller medium 15,152kB 11,796kB ^ 1.28x smaller big 15,044kB 10,976kB ^ 1.37x smaller ... <arithmetic mean> 7,724kB 7,190kB ^ 1.07x smaller This patch also takes advantage of our support for varying the page size at runtime by allocating more objects on the small object path: medium 178ms 150ms ^ 1.19x faster Some microbenchmarks report memory use increases from this change -- like they reported memory use decreases from r198675 -- but I'm ignoring them for now because I expect our full browser memory benchmarks to confirm that this patch is fine. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::BumpAllocator): Use a full unsigned because we can allocate objects larger than 16kB - 1, and a full unsigned does not make BumpAllocator any larger on 64bit systems. * bmalloc/Chunk.h: (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::size): (bmalloc::Chunk::objectType): Store ObjectType in the Chunk, since it only varies by Chunk now, and not from page to page within a Chunk. Also, union together small and large object metadata, since we will only use one or the other. This saves memory. (bmalloc::Chunk::Chunk): Conditionalize initialization based on object type, since only one kind of metadata or the other can be used at runtime. (bmalloc::Object::Object): (bmalloc::Object::begin): (bmalloc::SmallPage::end): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::initializeLineMetadata): Save a little space, since we know that lines are only 256 bytes long. (bmalloc::Heap::initializePageMetadata): Store a dynamic page size for each size class. We used to use only one page size (the system page size) but that limited our ability to allocate objects larger than 1kB on the small object path. Now we can handle any object size we want by storing objects of that size in a custom page size. (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): Revert to our old linked list strategy for storing small pages. (bmalloc::Heap::splitAndAllocate): Object type is per Chunk now. (bmalloc::Heap::allocateLarge): Don't nuke the small page list when allocating a large object because the two don't share memory anymore. (bmalloc::Heap::allocateSmallPage): Revert to our old linked list strategy for storing small pages. (bmalloc::Heap::deallocateSmallLine): Don't return early in the case where this is the first free object in the page. In the case of large-ish objects, the first free object might also be the last free object, since there's one object per page. (bmalloc::Heap::allocateSmallBumpRangesByMetadata): Split out some helper lambdas to make this code clearer. (bmalloc::Heap::allocateSmallBumpRangesByObject): Added a fast scan for objects larger than the line size. When multiple objects fit in a single line, it's an optimization to scan a line at a time. But when it's one object per line, or one object per 64 lines, it's better just to scan an object at a time. * bmalloc/Heap.h: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::derefSmallLine): Match the changes above. * bmalloc/LineMetadata.h: We weren't using all those bits. * bmalloc/List.h: (bmalloc::List::remove): Put a removed Node fully back into the default (empty) state it was in before it entered the list. This change is not observable, but it makes things clearer when you're debugging. * bmalloc/Object.h: (bmalloc::Object::Object): (bmalloc::Object::chunk): (bmalloc::Object::offset): (bmalloc::Object::operator+): (bmalloc::Object::operator<=): Added some helpers for iterating by object. * bmalloc/ObjectType.cpp: (bmalloc::objectType): Updated for API change. * bmalloc/Sizes.h: (bmalloc::Sizes::maskObjectSize): (bmalloc::Sizes::objectSize): (bmalloc::Sizes::pageSize): Support more page sizes. * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): (bmalloc::SmallPage::objectType): Deleted. (bmalloc::SmallPage::setObjectType): Deleted. (bmalloc::SmallPage::smallPageCount): Deleted. (bmalloc::SmallPage::setSmallPageCount): Deleted. Object type is per Chunk now, and we can infer page count from size class. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateChunk): (bmalloc::VMHeap::allocateSmallChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::allocateLargeObject): Support our old behavior of storing free pages in linked lists. 2016-03-29 Geoffrey Garen <ggaren@apple.com> bmalloc: support physical page sizes that don't match the virtual page size (take 2) https://bugs.webkit.org/show_bug.cgi?id=156003 Reviewed by Andreas Kling. This is a memory savings on iOS devices where the virtual page size is 16kB but the physical page size is 4kB. Take 1 was a memory regression on 16kB virtual / 16kB physical systems because it used a 4kB page size within a 16kB page size, allowing up to 4 different object types to mix within a physical page. Because objects of the same type tend to deallocate at the same time, mixing objects of different types made pages less likely to become completely empty. (Take 1 also had a bug where it used a platform #ifdef that didn't exist. Oops.) Take 2 allocates units of SmallPages equal to the physical page size. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): * bmalloc/Heap.h: Use the physical page size for our VM operations because we're only concerned with returning physical pages to the OS. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmPageSizePhysical): (bmalloc::vmValidatePhysical): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Use the physical page size. 2016-03-29 Geoffrey Garen <ggaren@apple.com> bmalloc: page size should be configurable at runtime https://bugs.webkit.org/show_bug.cgi?id=155993 Reviewed by Andreas Kling. This is a memory win on 32bit iOS devices, since their page sizes are 4kB and not 16kB. It's also a step toward supporting 64bit iOS devices that have a 16kB/4kB virtual/physical page size split. * bmalloc/Chunk.h: Align to largeAlignment since 2 * smallMax isn't required by the boundary tag allocator. (bmalloc::Chunk::page): Account for the slide when accessing a page. Each SmallPage hashes 4kB of memory. When we want to allocate a region of memory larger than 4kB, we store our metadata in the first SmallPage in the region and we assign a slide to the remaining SmallPages, so they forward to that first SmallPage when accessed. NOTE: We could use a less flexible technique that just hashed by vmPageSize() instead of 4kB at runtime, with no slide, but I think we'll be able to use this slide technique to make even more page sizes dynamically at runtime, which should save some memory and simplify the allocator. (bmalloc::SmallPage::begin): It's invalid to access a SmallPage with a slide, since such SmallPages do not contain meaningful data. (bmalloc::SmallPage::end): Account for smallPageCount when computing the size of a page. (bmalloc::Chunk::pageBegin): Deleted. (bmalloc::Chunk::pageEnd): Deleted. (bmalloc::Object::pageBegin): Deleted. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Cache vmPageSize because computing it might require a syscall. (bmalloc::Heap::initializeLineMetadata): Line metadata is a vector instead of a 2D array because we don't know how much metadata we'll need until we know the page size. (bmalloc::Heap::scavengeSmallPage): Be sure to revert the slide when deallocating a page. Otherwise, the next attempt to allocate the page will slide when initializing it, sliding to nowhere. (bmalloc::Heap::allocateSmallBumpRanges): Account for vector change to line metadata. (bmalloc::Heap::allocateSmallPage): Initialize slide and smallPageCount since they aren't constant anymore. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt dynamic page size. * bmalloc/Heap.h: * bmalloc/Sizes.h: smallPageSize is no longer equal to the VM page size -- it's just the smallest VM page size we're interested in supporting. * bmalloc/SmallPage.h: (bmalloc::SmallPage::slide): (bmalloc::SmallPage::setSlide): (bmalloc::SmallPage::smallPageCount): (bmalloc::SmallPage::setSmallPageCount): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Support slide and small page count as dynamic values. This doesn't increase metadata size since sizeof(SmallPage) rounds up to alignment anyway. * bmalloc/VMAllocate.h: (bmalloc::vmPageSize): (bmalloc::vmPageShift): (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Treat page size as a variable. * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::insert): (bmalloc::Vector<T>::grow): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Treat page size as a variable. 2016-03-29 David Kilzer <ddkilzer@apple.com> bmalloc: add logging for mmap() failures <http://webkit.org/b/155409> <rdar://problem/24568515> Reviewed by Saam Barati. This patch causes additional logging to be generated on internal iOS builds when mmap() fails. We are trying to track down an issue where the WebContent process runs out of VM address space before it is killed by jetsam. * CMakeLists.txt: Add Logging.cpp. * bmalloc.xcodeproj/project.pbxproj: Add new files. * bmalloc/BAssert.h: (RELEASE_BASSERT_WITH_MESSAGE): Add macro. * bmalloc/Logging.cpp: Added. (bmalloc::logVMFailure): Implementation. * bmalloc/Logging.h: Added. (bmalloc::logVMFailure): Declaration. * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): Call logVMFailure() on mmap() failure. * bmalloc/darwin/BSoftLinking.h: Copied from Source/WebCore/platform/mac/SoftLinking.h. 2016-03-26 Geoffrey Garen <ggaren@apple.com> Unreviewed, rolling out r198702, r198704. Caused a memory regression on PLUM. Reverted changeset: bmalloc: fix an ASSERT on iOS https://bugs.webkit.org/show_bug.cgi?id=155911 http://trac.webkit.org/changeset/198704 bmalloc: support physical page sizes that don't match the virtual page size https://bugs.webkit.org/show_bug.cgi?id=155898 http://trac.webkit.org/changeset/198702 2016-03-25 Geoffrey Garen <ggaren@apple.com> bmalloc: fix an ASSERT on iOS https://bugs.webkit.org/show_bug.cgi?id=155911 Reviewed by Gavin Barraclough. * bmalloc/VMAllocate.h: (bmalloc::vmValidatePhysical): Call through to vmValidatePhysical because the vmValidate function validates virtual sizes rather than physical sizes. 2016-03-25 Geoffrey Garen <ggaren@apple.com> bmalloc: support physical page sizes that don't match the virtual page size https://bugs.webkit.org/show_bug.cgi?id=155898 Reviewed by Gavin Barraclough. This is a memory savings on iOS devices where the virtual page size is 16kB but the physical page size is 4kB. * bmalloc/Chunk.h: (bmalloc::Chunk::Chunk): smallPageSize is now unrelated to the OS's page size -- it just reflects the optimal unit of memory to recycle between small objects. We only need to round up to largeAlignment because small objects allocate as subsets of large objects now. (bmalloc::Chunk::page): (bmalloc::Object::pageBegin): (bmalloc::Object::line): Adopt smallPageSize. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::allocateLarge): Adopt smallPageSize. (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::shrinkXLarge): Adopt vmPageSizePhysical(). We want the physical page size because that's the unit at which the hardware MMU will recycle memory. * bmalloc/Sizes.h: Adopt smallPageSize. * bmalloc/VMAllocate.h: (bmalloc::vmPageSizePhysical): (bmalloc::vmPageSize): Distinguish between page size, which is the virtual memory page size advertised by the OS, and physical page size, which the true hardware page size. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmValidatePhysical): (bmalloc::tryVMAllocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Adopt vmPageSize() and vmPageSizePhyiscal(). * bmalloc/Vector.h: (bmalloc::Vector::initialCapacity): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): Adopt vmPageSize(). We'd prefer to use vmPageSizePhysical() but mmap() doesn't support it. * bmalloc/XLargeMap.cpp: #include. 2016-03-25 Geoffrey Garen <ggaren@apple.com> Unreviewed, rolling in r198679. r198679 was just a rename. The regression was caused by r198675 and then fixed in r198693. Restored changeset: "bmalloc: Renamed LargeChunk => Chunk" https://bugs.webkit.org/show_bug.cgi?id=155894 http://trac.webkit.org/changeset/198679 2016-03-25 Geoffrey Garen <ggaren@apple.com> Unreviewed, try to fix a crash seen on the bots. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): We have to take the lock even if we're only reading our own data becuse LargeObject contains validation code that will read our neighbors' data as well. 2016-03-25 Ryan Haddad <ryanhaddad@apple.com> Unreviewed, rolling out r198679. This change caused flaky LayoutTest crashes Reverted changeset: "bmalloc: Renamed LargeChunk => Chunk" https://bugs.webkit.org/show_bug.cgi?id=155894 http://trac.webkit.org/changeset/198679 2016-03-25 Geoffrey Garen <ggaren@apple.com> bmalloc: stress_aligned fails when allocating a zero-sized object with XLarge alignment https://bugs.webkit.org/show_bug.cgi?id=155896 Reviewed by Andreas Kling. We normally filter zero-sized allocations into small allocations, but a zero-sized allocation can sneak through if it requires sufficiently large alignment. * bmalloc/Heap.cpp: (bmalloc::Heap::tryAllocateXLarge): Set a floor on allocation size to catch zero-sized allocations. 2016-03-25 Geoffrey Garen <ggaren@apple.com> bmalloc: Renamed LargeChunk => Chunk https://bugs.webkit.org/show_bug.cgi?id=155894 Reviewed by Michael Saboff. A Chunk can contain both small and large objects now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::isFree): * bmalloc/Chunk.h: Copied from Source/bmalloc/bmalloc/LargeChunk.h. (bmalloc::Chunk::pages): (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::Chunk): (bmalloc::Chunk::get): (bmalloc::Chunk::beginTag): (bmalloc::Chunk::endTag): (bmalloc::Chunk::offset): (bmalloc::Chunk::object): (bmalloc::Chunk::page): (bmalloc::Chunk::line): (bmalloc::SmallLine::begin): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Object::Object): (bmalloc::Object::begin): (bmalloc::LargeChunk::pages): Deleted. (bmalloc::LargeChunk::begin): Deleted. (bmalloc::LargeChunk::end): Deleted. (bmalloc::LargeChunk::LargeChunk): Deleted. (bmalloc::LargeChunk::get): Deleted. (bmalloc::LargeChunk::beginTag): Deleted. (bmalloc::LargeChunk::endTag): Deleted. (bmalloc::LargeChunk::offset): Deleted. (bmalloc::LargeChunk::object): Deleted. (bmalloc::LargeChunk::page): Deleted. (bmalloc::LargeChunk::line): Deleted. * bmalloc/Deallocator.cpp: * bmalloc/FreeList.cpp: * bmalloc/Heap.cpp: (bmalloc::Heap::allocateLarge): * bmalloc/LargeChunk.h: Removed. * bmalloc/LargeObject.h: (bmalloc::LargeObject::LargeObject): (bmalloc::LargeObject::merge): (bmalloc::LargeObject::split): * bmalloc/Object.h: (bmalloc::Object::chunk): * bmalloc/ObjectType.cpp: * bmalloc/Sizes.h: * bmalloc/SmallAllocator.h: Removed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateChunk): (bmalloc::VMHeap::allocateLargeChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeObject): (bmalloc::VMHeap::deallocateLargeObject): * bmalloc/Zone.cpp: (bmalloc::enumerator): * bmalloc/Zone.h: (bmalloc::Zone::chunks): (bmalloc::Zone::addChunk): (bmalloc::Zone::largeChunks): Deleted. (bmalloc::Zone::addLargeChunk): Deleted. 2016-03-24 Geoffrey Garen <ggaren@apple.com> bmalloc: small and large objects should share memory https://bugs.webkit.org/show_bug.cgi?id=155866 Reviewed by Andreas Kling. This patch cuts our VM footprint in half. (VM footprint usually doesn't matter, but on iOS there's an artificial VM limit around 700MB, and if you hit it you jetsam / crash.) It's also a step toward honoring the hardware page size at runtime, which will reduce memory usage on iOS. This patch is a small improvement in peak memory usage because it allows small and large objects to recycle each other's memory. The tradeoff is that we require more metadata, which causes more memory usage after shrinking down from peak memory usage. In the end, we have some memory wins and some losses, and a small win in the mean on our standard memory benchmarks. * bmalloc.xcodeproj/project.pbxproj: Removed SuperChunk. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Adopt a new Heap API for shrinking large objects because it's a little more complicated than it used to be. Don't check for equality in the XLarge case because we don't do it in other cases, and it's unlikely that we'll be called for no reason. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::allocate): Don't ASSERT isSmall because that's an old concept from when small and large objects were in distinct memory regions. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::deallocateSlowCase): Large objects are not segregated anymore. (bmalloc::Deallocator::deallocateLarge): Deleted. * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): Don't ASSERT isSmall(). See above. * bmalloc/Heap.cpp: (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPage): (bmalloc::Heap::scavengeSmallPages): New helpers for returning cached small pages to the large object heap. (bmalloc::Heap::allocateSmallPage): Allocate small pages from the large object heap. This is how we accomplish sharing. (bmalloc::Heap::deallocateSmallLine): Handle large objects since we can encounter them on this code path now. (bmalloc::Heap::splitAndAllocate): Fixed a bug where we would sometimes not split even though we could. Allocating a large object also requires ref'ing its small line so that we can alias memory between small and large objects. (bmalloc::Heap::allocateLarge): Return cached small pages before allocating a large object that would fit in a cached small page. This allows some large allocations to reuse small object memory. (bmalloc::Heap::shrinkLarge): New helper. (bmalloc::Heap::deallocateLarge): Deleted. * bmalloc/Heap.h: * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::pageBegin): (bmalloc::LargeChunk::pageEnd): (bmalloc::LargeChunk::lines): (bmalloc::LargeChunk::pages): (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::LargeChunk): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::endTag): (bmalloc::LargeChunk::offset): (bmalloc::LargeChunk::object): (bmalloc::LargeChunk::page): (bmalloc::LargeChunk::line): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Object::Object): (bmalloc::Object::begin): (bmalloc::Object::pageBegin): (bmalloc::Object::line): (bmalloc::Object::page): I merged all the SmallChunk metadata and code into LargeChunk. Now we use a single class to track both small and large metadata, so we can share memory between small and large objects. I'm going to rename this class to Chunk in a follow-up patch. * bmalloc/Object.h: (bmalloc::Object::chunk): Updated for LargeChunk transition. * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: (bmalloc::isXLarge): (bmalloc::isSmall): Deleted. The difference between small and large objects is now stored in metadata and is not a property of their virtual address range. * bmalloc/SegregatedFreeList.h: One more entry because we cover all of what used to be the super chunk in a large chunk now. * bmalloc/Sizes.h: Removed bit masking helpers because we don't use address masks to distinguish small vs large object type anymore. * bmalloc/SmallChunk.h: Removed. * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): Store object type per page because any given page can be used for large objects or small objects. * bmalloc/SuperChunk.h: Removed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateLargeChunk): (bmalloc::VMHeap::allocateSmallChunk): Deleted. (bmalloc::VMHeap::allocateSuperChunk): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeObject): (bmalloc::VMHeap::deallocateLargeObject): (bmalloc::VMHeap::allocateSmallPage): Deleted. (bmalloc::VMHeap::deallocateSmallPage): Deleted. Removed super chunk and small chunk support. * bmalloc/Zone.cpp: (bmalloc::enumerator): * bmalloc/Zone.h: (bmalloc::Zone::largeChunks): (bmalloc::Zone::addLargeChunk): (bmalloc::Zone::superChunks): Deleted. (bmalloc::Zone::addSuperChunk): Deleted. Removed super chunk and small chunk support. 2016-03-23 Geoffrey Garen <ggaren@apple.com> bmalloc: Added an Object helper class https://bugs.webkit.org/show_bug.cgi?id=155818 Reviewed by Gavin Barraclough. Object is an abstraction that breaks out a void* into its component metadata pointers. This is slightly faster than recomputing them, and it enables a future patch in which Object will tell us whether it is small or large. * bmalloc.xcodeproj/project.pbxproj: Added to the project. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Use Object to compute size. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::deallocateSmallLine): * bmalloc/Heap.h: (bmalloc::Heap::derefSmallLine): Use Object to deallocate. * bmalloc/Object.h: Added. (bmalloc::Object::Object): (bmalloc::Object::chunk): (bmalloc::Object::line): (bmalloc::Object::page): Helper class to break out a void* into its component metadata pointers. * bmalloc/SmallChunk.h: (bmalloc::SmallChunk::SmallChunk): SmallPage::get doesn't exist anymore so we use our new helper functions instead. (bmalloc::SmallChunk::offset): (bmalloc::SmallChunk::object): (bmalloc::SmallChunk::page): (bmalloc::SmallChunk::line): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::begin): New helpers that operate on the data stored in Object. (bmalloc::SmallLine::get): Deleted. (bmalloc::SmallPage::get): Deleted. * bmalloc/SmallLine.h: (bmalloc::SmallLine::refCount): Added a default ref value for convenience. * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): 2016-03-23 Geoffrey Garen <ggaren@apple.com> bmalloc: process the object log before asking for new memory https://bugs.webkit.org/show_bug.cgi?id=155801 Reviewed by Gavin Barraclough. This is a step toward merging large and small objects: In future, if we have large objects in the log, we need to process them right away to avoid pushing up peak memory use. But it also appears to be a speedup and memory use improvement now. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::allocateLarge): Process the log before asking for more memory. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: Provide a public API for processing the object log. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallPage): Pop fragmented pages from the front instead of from the back. This resolves a regression on tree_churn --parallel. Popping from the front gives us the oldest pages. The oldest pages have had the most time to accumulate free lines. They are therefore the least fragmented on average. * bmalloc/List.h: (bmalloc::List::popFront): (bmalloc::List::insertAfter): New API to pop from front. 2016-03-22 Geoffrey Garen <ggaren@apple.com> bmalloc: use a log scale for large-ish size classes https://bugs.webkit.org/show_bug.cgi?id=155770 Reviewed by Michael Saboff. At larger sizes, precise allocation sizes don't save much memory -- and they can cost memory when objects of distinct size classes can't allocate together. This is a small savings up to our current allocation limits, and it may enable changing those limits in the long term. * bmalloc/Algorithm.h: (bmalloc::log2): We use this to compute large-ish size classes. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Iterate by size class instead of by object size so we can change object size limits without breaking stuff. (bmalloc::Allocator::scavenge): Ditto. (bmalloc::Allocator::allocateLogSizeClass): New helper function for allocating based on log size classes. (bmalloc::Allocator::allocateSlowCase): Account for extra size class possibilities. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): We only handle up to 512b on the fastest fast path now. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::validate): Deleted. I noticed that this function had been refactored not to do anything anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): Iterate by size class. (See Allocator::Allocator.) * bmalloc/Heap.h: Use the sizeClassCount constant instead of hard coding things. * bmalloc/Sizes.h: (bmalloc::Sizes::maskSizeClass): (bmalloc::Sizes::maskObjectSize): (bmalloc::Sizes::logSizeClass): (bmalloc::Sizes::logObjectSize): (bmalloc::Sizes::sizeClass): (bmalloc::Sizes::objectSize): Separate size class calculation between simple size classes that can be computed with a mask and are 8-byte-precise and complex size classes that require more math and are less precise. * bmalloc/SmallLine.h: (bmalloc::SmallLine::ref): * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): Cleaned up some ASSERTs that triggered while working on this patch. * bmalloc/Zone.cpp: (bmalloc::statistics): (bmalloc::zoneSize): (bmalloc::Zone::Zone): (bmalloc::size): Deleted. Renamed these symbols to work around an lldb bug that makes it impossible to print out variables named 'size' -- which can be a problem when working on malloc. 2016-03-22 Geoffrey Garen <ggaren@apple.com> bmalloc: shrink largeMax https://bugs.webkit.org/show_bug.cgi?id=155759 Reviewed by Michael Saboff. If a largeChunk contains N bytes and we allocate objects of size N / 2 + 8 bytes, then we waste 50% of physical memory at peak. This patch sets largeMax to N / 2, reducing maximum waste to 25%. * bmalloc/BoundaryTag.h: * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::LargeChunk): * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): Honor largeMax vs largeObjectMax. * bmalloc/Sizes.h: Distinguish between the largest thing we can store in a free list (largeObjectMax) and the largest thing we're willing to allocate (largeMax). 2016-03-20 Dan Bernstein <mitz@apple.com> [Mac] Determine TARGET_MAC_OS_X_VERSION_MAJOR from MACOSX_DEPLOYMENT_TARGET rather than from MAC_OS_X_VERSION_MAJOR https://bugs.webkit.org/show_bug.cgi?id=155707 <rdar://problem/24980691> Reviewed by Darin Adler. * Configurations/Base.xcconfig: Set TARGET_MAC_OS_X_VERSION_MAJOR based on the last component of MACOSX_DEPLOYMENT_TARGET. * Configurations/DebugRelease.xcconfig: For engineering builds, preserve the behavior of TARGET_MAC_OS_X_VERSION_MAJOR being the host’s OS version. 2016-03-20 Dan Bernstein <mitz@apple.com> Update build settings Rubber-stamped by Andy Estes. * Configurations/DebugRelease.xcconfig: 2016-03-14 Geoffrey Garen <ggaren@apple.com> Unreviewed, rolling out r197955. I decided to go in another direction Reverted changeset: "bmalloc: Rename SmallPage to SmallRun" https://bugs.webkit.org/show_bug.cgi?id=155320 http://trac.webkit.org/changeset/197955 2016-03-10 Geoffrey Garen <ggaren@apple.com> bmalloc: Rename SmallPage to SmallRun https://bugs.webkit.org/show_bug.cgi?id=155320 Reviewed by Alex Christensen. A page is a fixed-size set of lines. A run is an variable-sized set of lines. We want to start using runs because: (a) we want to support varying the hardware page size by OS; (b) we want to support allocations larger than our current page size. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::initializeSmallRunMetadata): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallRuns): (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::allocateSmallRun): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::initializeLineMetadata): Deleted. (bmalloc::Heap::scavengeSmallPages): Deleted. (bmalloc::Heap::allocateSmallPage): Deleted. * bmalloc/Heap.h: * bmalloc/LineMetadata.h: * bmalloc/SmallChunk.h: (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::runs): (bmalloc::SmallChunk::SmallChunk): (bmalloc::SmallLine::end): (bmalloc::SmallRun::get): (bmalloc::SmallRun::begin): (bmalloc::SmallRun::end): (bmalloc::SmallChunk::pages): Deleted. (bmalloc::SmallPage::get): Deleted. (bmalloc::SmallPage::begin): Deleted. (bmalloc::SmallPage::end): Deleted. * bmalloc/SmallPage.h: Removed. * bmalloc/SmallRun.h: Copied from Source/bmalloc/bmalloc/SmallPage.h. (bmalloc::SmallRun::SmallRun): (bmalloc::SmallRun::ref): (bmalloc::SmallRun::deref): (bmalloc::SmallPage::SmallPage): Deleted. (bmalloc::SmallPage::ref): Deleted. (bmalloc::SmallPage::deref): Deleted. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallRun): (bmalloc::VMHeap::allocateLargeObject): (bmalloc::VMHeap::deallocateSmallRun): (bmalloc::VMHeap::deallocateLargeObject): (bmalloc::VMHeap::allocateSmallPage): Deleted. (bmalloc::VMHeap::deallocateSmallPage): Deleted. 2016-03-08 Geoffrey Garen <ggaren@apple.com> Unreviewed, rolling in r197722. https://bugs.webkit.org/show_bug.cgi?id=155171 The right calculation for our static_assert is actually: sizeof(SmallChunk) % vmPageSize + 2 * smallMax <= vmPageSize instead of: sizeof(SmallChunk) % vmPageSize + smallMax <= vmPageSize smallMax is not enough because line metadata might require us to begin allocation at an offset as large as smallMax, so we need 2 * smallMax. Once correct, this static_assert fires, and we fix it by increasing the alignment of SmallChunk. Restored changeset: "bmalloc: Use List<T> instead of Vector<T> in some places" https://bugs.webkit.org/show_bug.cgi?id=155150 http://trac.webkit.org/changeset/197722 2016-03-08 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r197722. https://bugs.webkit.org/show_bug.cgi?id=155171 This change caused 800+ JSC test failures (Requested by ryanhaddad on #webkit). Reverted changeset: "bmalloc: Use List<T> instead of Vector<T> in some places" https://bugs.webkit.org/show_bug.cgi?id=155150 http://trac.webkit.org/changeset/197722 2016-03-07 Geoffrey Garen <ggaren@apple.com> bmalloc: Use List<T> instead of Vector<T> in some places https://bugs.webkit.org/show_bug.cgi?id=155150 Reviewed by Andreas Kling. Vector<T> is expensive when you want a lot of them because our minimum allocation size is the system page size. * bmalloc.xcodeproj/project.pbxproj: Added a List<T> class. * bmalloc/Heap.cpp: (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::allocateSmallPage): Use the List<T> API. No need to check for stale entries anymore because List<T> supports O(1) eager removal and we remove eagerly now. (bmalloc::Heap::deallocateSmallLine): Remove eagerly. This simplifies the allocation code and it is also required for correctness since we only have enough metadata to be in one list at a time. * bmalloc/Heap.h: List! * bmalloc/SmallChunk.h: Made this assert a little more precise since this patch triggered the old version in a benign way. (bmalloc::SmallChunk::SmallChunk): This code moved to the SmallPage constructor. * bmalloc/SmallPage.h: (bmalloc::SmallPage::SmallPage): Accomodate the List<T> data structure. This is a net memory savings on Mac for heaps smaller than ~128MB and on iOS for heaps smaller than ~512MB. The maximum memory saved is 512kB on Mac and 2MB on iOS. For larger heaps, there's a memory cost of 0.4% on Mac and 0.1% on iOS. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): Use List<T> API. 2016-03-03 Geoffrey Garen <ggaren@apple.com> Unreviewed, rolling in r197174. https://bugs.webkit.org/show_bug.cgi?id=154762 The right calculation for alignment is actually: vmAlignment - getpagesize() + vmSize instead of: vmAlignment - vmPageSize + vmSize The vmPageSize might be larger than getpagesize(). Restored changeset: "bmalloc: Added a fast XLarge allocator" https://bugs.webkit.org/show_bug.cgi?id=154720 http://trac.webkit.org/changeset/197174 2016-02-26 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r197174. https://bugs.webkit.org/show_bug.cgi?id=154762 This change caused LayoutTests to crash on iOS simulator (Requested by ryanhaddad on #webkit). Reverted changeset: "bmalloc: Added a fast XLarge allocator" https://bugs.webkit.org/show_bug.cgi?id=154720 http://trac.webkit.org/changeset/197174 2016-02-25 Geoffrey Garen <ggaren@apple.com> bmalloc: Added a fast XLarge allocator https://bugs.webkit.org/show_bug.cgi?id=154720 Reviewed by Andreas Kling. This is a big speedup for XLarge allocations because it avoids mmap and page fault churn. It also enables future design changes to handle a smaller size range on the fast path. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): Added a non-constant round down. * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): XLarge no longer requires the caller to align things. (bmalloc::Allocator::allocate): Tweaked the alignment calculation for clarity. When alignment and largeAlignment are equal, no adjustment is necessary since all allocations guarantee largeAlignment. (bmalloc::Allocator::reallocate): Updated for interface change. Note that the new interface fixes some concurrency bugs. The old code kept an iterator into the XLarge allocator across lock drop and acquisition, which is not cool. (bmalloc::Allocator::allocateXLarge): XLarge no longer requires the caller to align things. * bmalloc/Heap.cpp: (bmalloc::Heap::scavengeXLargeObjects): Added scavenging for XLarge. (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::splitAndAllocate): Split XLarge objects to xLargeAlignment. (bmalloc::Heap::tryAllocateXLarge): (bmalloc::Heap::xLargeSize): (bmalloc::Heap::shrinkXLarge): (bmalloc::Heap::deallocateXLarge): Allocate from our map before going to the OS. (bmalloc::Heap::findXLarge): Deleted. * bmalloc/Heap.h: * bmalloc/LargeObject.h: (bmalloc::LargeObject::split): * bmalloc/ObjectType.h: (bmalloc::isXLarge): Give XLarge objects an explicit alignment for clarity. * bmalloc/Range.h: (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator bool): (bmalloc::Range::operator<): (bmalloc::canMerge): (bmalloc::merge): Some helpers that were useful in writing this patch. * bmalloc/Sizes.h: * bmalloc/SortedVector.h: Added. (bmalloc::SortedVector::Bucket::Bucket): (bmalloc::SortedVector::Bucket::operator<): (bmalloc::SortedVector::iterator::iterator): (bmalloc::SortedVector::iterator::operator++): (bmalloc::SortedVector::iterator::operator!=): (bmalloc::SortedVector::iterator::operator*): (bmalloc::SortedVector::iterator::operator->): (bmalloc::SortedVector::iterator::skipDeletedBuckets): (bmalloc::SortedVector::begin): (bmalloc::SortedVector::end): (bmalloc::SortedVector<T>::insert): (bmalloc::SortedVector<T>::find): (bmalloc::SortedVector<T>::get): (bmalloc::SortedVector<T>::take): (bmalloc::SortedVector<T>::shrinkToFit): A simple abstraction for keeping a sorted vector. Insertion is average amortized log(n) because we keep deleted buckets that we can reuse. This is better than a tree because we get better locality, less memory use, and simpler code. Also, trees require a node memory allocator, and implementing a memory allocator in a memory allocator is no fun. Arguably we should use a hash table instead. But that's more code, and sorted vector has other nice properties that we might want to take adavantage of in the future. * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): Fixed an inaccuracy in the alignment calculation here. This code was sort of trying to enforce the alignment that the XLarge allocator enforces -- but it's better to enforce that alignment there. The right calculation is: vmAlignment - vmPageSize + vmSize because the worst case is when you are aligned to 0 + vmPageSize, and you must walk forward vmAlignment - vmPageSize to reach the next vmAlignment. (bmalloc::tryVMExtend): Deleted. No need to go back to the OS for VM since we manage our own. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateLargeChunk): Updated for clarity. When we grow the large heap we know that grown region is where the next allocation will take place, so we return it directly instead of pushing it to the free list. This fixes a subtle bug where an overly conservative aligned allocation algorithm can fail to allocate at all when it grows the heap. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeObject): Ditto. (bmalloc::VMHeap::allocateLargeObject): Ditto. * bmalloc/VMState.h: (bmalloc::merge): Added a helper. * bmalloc/Vector.h: (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): Use a proper iterator API to play nice with std algorithms. (bmalloc::Vector<T>::insert): New function required by SortedVector. (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): Allow for shrinking back all the way to 0 because that's what shrinkToFit wants. (bmalloc::Vector<T>::growCapacity): (bmalloc::Vector<T>::shrinkToFit): * bmalloc/XLargeMap.cpp: Added. Helper data structure for managing XLarge objects. We have enough granularity in our metadata to represent any kind of address range. We store free ranges in a flat vector because most programs have very few individual free XLarge ranges. (They usually merge.) We store allocated ranges in a sorted vector because programs might allocate lots of XLarge ranges. For example, if the XLarge minimum is 128kB, and you have a 1GB process, that's 8192 ranges. Linear scan would examine 8192 items but binary search only 13. Empirically, this is 1.5X faster than our current large allocator if you modify MallocBench/big to allocate XLarge objects and not to initialize objects and you allocate 128kB-256kB objects in a 1GB address space. (bmalloc::XLargeMap::takeFree): Be careful about overflow in this function because we support super huge pointers, alignments, and sizes. (bmalloc::XLargeMap::addFree): Merge eagerly on free because the cost of missing an XLarge opportunity is catastrophic. Also, I discovered by experiment that any allocator that doesn't merge eagerly can create lots of subtle opportunities for snowballing fragmentation, as fragmentation in range A forces you to chop up range B, and so on. We allocate "first fit" (allocating the lowest address) because someone wrote a paper once that said that it's the best algorithm to combat fragmentation (even though worst case fragmentation is unavoidable regardless of algorithm). (bmalloc::XLargeMap::addAllocated): (bmalloc::XLargeMap::getAllocated): (bmalloc::XLargeMap::takeAllocated): (bmalloc::XLargeMap::shrinkToFit): (bmalloc::XLargeMap::takePhysical): (bmalloc::XLargeMap::addVirtual): * bmalloc/XLargeMap.h: Added. (bmalloc::XLargeMap::Allocation::operator<): * bmalloc/XLargeRange.h: Added. (bmalloc::XLargeRange::XLargeRange): (bmalloc::XLargeRange::vmState): (bmalloc::XLargeRange::setVMState): (bmalloc::canMerge): (bmalloc::merge): (bmalloc::XLargeRange::split): Helper for tracking VMState in a range. 2016-02-23 Dan Bernstein <mitz@apple.com> [Xcode] Linker errors display mangled names, but no longer should https://bugs.webkit.org/show_bug.cgi?id=154632 Reviewed by Sam Weinig. * Configurations/Base.xcconfig: Stop setting LINKER_DISPLAYS_MANGLED_NAMES to YES. 2016-02-22 Konstantin Tokarev <annulen@yandex.ru> Fixed compilation of bmalloc with GCC 4.8 after r196873. https://bugs.webkit.org/show_bug.cgi?id=154534 Reviewed by Mark Lam. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55382. * bmalloc/LargeChunk.h: * bmalloc/SmallChunk.h: 2016-02-21 Geoffrey Garen <ggaren@apple.com> bmalloc: Don't use a whole page for metadata https://bugs.webkit.org/show_bug.cgi?id=154510 Reviewed by Andreas Kling. (1) Don't round up metadata to a page boundary. This saves 1.5% dirty memory on iOS and 0.2% on Mac. It also enables a future patch to allocate smaller chunks without wasting memory. (2) Initialize metadata lazily. This saves dirty memory when the program allocates primarily small or large objects (but not both), leaving some metadata uninitialized. * bmalloc.xcodeproj/project.pbxproj: Medium objects are gone now. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::refill): Added an ASSERT to help debug a bug I cause while working on this patch. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallBumpRanges): Ditto. (bmalloc::Heap::splitAndAllocate): (bmalloc::Heap::allocateLarge): Updated for interface change. * bmalloc/LargeChunk.h: Changed the boundaryTagCount calculation to a static_assert. Don't round up to page boundary. (See above.) (bmalloc::LargeChunk::LargeChunk): Moved code here from LargeChunk::init. A constructor is a more natural / automatic way to do this initialization. * bmalloc/LargeObject.h: (bmalloc::LargeObject::init): Deleted. Moved to LargeChunk. * bmalloc/Sizes.h: Chagned largeChunkMetadataSize to a simpler constant because metadata size no longer varies by page size. * bmalloc/SmallChunk.h: (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): Use std::array to make begin/end calculations easier. (bmalloc::SmallChunk::SmallChunk): Treat our metadata like a series of allocated objects. We used to avoid trampling our metadata by starting object memory at the next page. Now we share the first page between metadata and objects, and we account for metadata explicitly. * bmalloc/SuperChunk.h: (bmalloc::SuperChunk::SuperChunk): (bmalloc::SuperChunk::smallChunk): (bmalloc::SuperChunk::largeChunk): (bmalloc::SuperChunk::create): Deleted. Don't eagerly run the SmallChunk and LargeChunk constructors. We'll run them lazily as needed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateLargeChunk): (bmalloc::VMHeap::allocateSuperChunk): (bmalloc::VMHeap::grow): Deleted. Track small and large chunks explicitly so we can initialize them lazily. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateLargeObject): Specify whether we're allocating a small or large chunk since we don't allocate both at once anymore. 2016-02-20 Mark Lam <mark.lam@apple.com> Use of inlined asm statements causes problems for -std=c99 builds. https://bugs.webkit.org/show_bug.cgi?id=154507 Reviewed by Dan Bernstein. * bmalloc/BAssert.h: 2016-02-19 Joonghun Park <jh718.park@samsung.com> Unreviewed. Fix debug build error since r196847 Fix gcc build warning appeared as below by removing BASSERT(refCount <= maxRefCount). error: comparison is always true due to limited range of data type [-Werror=type-limits] * bmalloc/SmallLine.h: (bmalloc::SmallLine::ref): Deleted. 2016-02-19 Geoffrey Garen <ggaren@apple.com> bmalloc: Chunk, Page, and Line don't need to be class templates https://bugs.webkit.org/show_bug.cgi?id=154480 Reviewed by Gavin Barraclough. We needed class templates to distinguish between small and medium, but medium is gone now. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Chunk.h: Removed. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): (bmalloc::Heap::allocateSmallBumpRanges): * bmalloc/Heap.h: * bmalloc/Line.h: Removed. * bmalloc/Page.h: Removed. * bmalloc/Sizes.h: * bmalloc/SmallChunk.h: Replaced with Source/bmalloc/bmalloc/Chunk.h. (bmalloc::SmallChunk::begin): (bmalloc::SmallChunk::end): (bmalloc::SmallChunk::lines): (bmalloc::SmallChunk::pages): (bmalloc::SmallChunk::get): (bmalloc::SmallLine::get): (bmalloc::SmallLine::begin): (bmalloc::SmallLine::end): (bmalloc::SmallPage::get): (bmalloc::SmallPage::begin): (bmalloc::SmallPage::end): (bmalloc::Chunk::begin): Deleted. (bmalloc::Chunk::end): Deleted. (bmalloc::Chunk::lines): Deleted. (bmalloc::Chunk::pages): Deleted. * bmalloc/SmallLine.h: Replaced with Source/bmalloc/bmalloc/Line.h. (bmalloc::SmallLine::ref): (bmalloc::SmallLine::deref): (bmalloc::Line<Traits>::begin): Deleted. (bmalloc::Line<Traits>::end): Deleted. (bmalloc::Line<Traits>::ref): Deleted. (bmalloc::Line<Traits>::deref): Deleted. * bmalloc/SmallPage.h: Replaced with Source/bmalloc/bmalloc/Page.h. (bmalloc::SmallPage::hasFreeLines): (bmalloc::SmallPage::setHasFreeLines): (bmalloc::SmallPage::ref): (bmalloc::SmallPage::deref): (bmalloc::Page::hasFreeLines): Deleted. (bmalloc::Page::setHasFreeLines): Deleted. (bmalloc::Page<Traits>::ref): Deleted. (bmalloc::Page<Traits>::deref): Deleted. * bmalloc/SmallTraits.h: Removed. 2016-02-18 Geoffrey Garen <ggaren@apple.com> bmalloc: Remove the concept of medium objects https://bugs.webkit.org/show_bug.cgi?id=154436 Reviewed by Sam Weinig. There's no need to distinguish medium objects from small: Small object metadata works naturally for both as long as we allow an object to span more than two small lines. (We already allow an object to span more than one small line.) This change reduces memory use because it eliminates the 1kB line size, so we don't have to hold down 1kB lines for individual 264+ byte objects. 1kB lines were always a bit of a compromise. The main point of bump allocation is to take advantage of cache lines. Cache lines are usually 64 bytes, so line sizes above 256 bytes are a bit of a stretch. This change speeds up small object benchmarks because it eliminates the branch to detect medium objects in deallocation log processing. This change reduces virtual memory use from worst cast 4X to worst case 2X because the medium chunk is gone. iOS cares about virtual memory use and terminates apps above ~1GB, so this change gives us more breathing room. This change slows down medium benchmarks a bit because we end up doing more work to recycle fragmented medium objects. Overall, the tradeoff seems justified, since we have a net speedup and a memory use savings. * bmalloc.xcodeproj/project.pbxproj: Removed all the medium files. We can simplify even further in a follow-up patch, removing the base class templates for Chunk, Page, and Line as well. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): (bmalloc::Allocator::allocate): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::scavenge): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::refillAllocator): (bmalloc::Allocator::allocateSlowCase): Medium is gone. Small max is the new medium max. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): Ditto. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::validate): (bmalloc::BumpAllocator::allocate): No more medium. * bmalloc/Chunk.h: No more medium. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): No check for medium. This is a speedup. (bmalloc::Deallocator::deallocateSlowCase): No more medium. * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): Ditto. * bmalloc/Heap.cpp: (bmalloc::Heap::initializeLineMetadata): The algorithm here changed from iterating each line to iterating each object. This helps us accomodate objects that might span more than two lines -- i.e., all objects between (512 bytes, 1024 bytes]. (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeLargeObjects): Medium is gone. (bmalloc::Heap::allocateSmallBumpRanges): Allow for lines that allocate zero objects. This happens when an object spans more than two lines -- the middle lines allocate zero objects. Also set the "has free lines" bit to false if we consume the last free line. This needs to be a bit now because not all pages agree on their maximum refcount anymore, so we need an explicit signal for the transition from maximum to maximum - 1. (bmalloc::Heap::allocateSmallPage): This code didn't change; I just removed the medium code. (bmalloc::Heap::deallocateSmallLine): Changed the algorithm to check hasFreeLines. See allocateSmallBumpRanges. (bmalloc::Heap::scavengeMediumPages): Deleted. (bmalloc::Heap::allocateMediumBumpRanges): Deleted. (bmalloc::Heap::allocateMediumPage): Deleted. (bmalloc::Heap::deallocateMediumLine): Deleted. * bmalloc/Heap.h: (bmalloc::Heap::derefMediumLine): Deleted. * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: No more medium. * bmalloc/MediumChunk.h: Removed. * bmalloc/MediumLine.h: Removed. * bmalloc/MediumPage.h: Removed. * bmalloc/MediumTraits.h: Removed. * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: (bmalloc::isSmall): (bmalloc::isXLarge): (bmalloc::isSmallOrMedium): Deleted. (bmalloc::isMedium): Deleted. No more medium. * bmalloc/Page.h: (bmalloc::Page::sizeClass): (bmalloc::Page::setSizeClass): (bmalloc::Page::hasFreeLines): (bmalloc::Page::setHasFreeLines): Add the free lines bit. You get better codegen if you make it the low bit, since ref / deref can then add / sub 2. So do that. * bmalloc/Sizes.h: (bmalloc::Sizes::sizeClass): Expand the small size class to include the medium size class. * bmalloc/SuperChunk.h: (bmalloc::SuperChunk::SuperChunk): (bmalloc::SuperChunk::smallChunk): (bmalloc::SuperChunk::largeChunk): (bmalloc::SuperChunk::mediumChunk): Deleted. No more medium. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): Set the has free lines bit before returning a Page to the Heap since this is the correct default state when we first allocate a page. (bmalloc::VMHeap::allocateMediumPage): Deleted. (bmalloc::VMHeap::deallocateMediumPage): Deleted. 2016-02-19 Michael Saboff <msaboff@apple.com> bmalloc: Unify VMHeap and Heap LargeObjects free lists to reduce fragmentation https://bugs.webkit.org/show_bug.cgi?id=154192 Reviewed by Geoffrey Garen. Change the operation of Heap and VMHeap LargeObject free lists. Renamed Owner to VMState to track the state of each LargeObject. Physical - The pages have been allocated. Virtual - The pages have not been allocated. Mixed - The object contains a mixture of Physical and Virtual pages. VMState uses one bit each for Physical and Virtual to simplify merging states when merging two adjacent blocks. This change enforces the rule that objects in the Heap free list must have have the Physical bit set in their VMState while objects in the VMHeap free list must have the Physical bit clear. Thie means that the Heap can have LargeObjects in Physical or Mixed VMState, but the VMHeap's free list can only contain Virtual LargeObjects. In both Heap::allocateLarge(), we now allocate physical pages if the LargeObject we pull from the free list has any Virtual pages before we possilby split the object. When we merge objects, the result might be made up of Mixed page allocations. When allocating a Mixed LargeObject, we need to allocate memory for them as well. The scavenger deallocates both Physical and Mixed LargeObjects, placing them back into the VMHeap's free list. When we allocate or deallocate Mixed LargeObjects, there are pages that within these objects that will be redundantly modified. It would require additional metadata to eliminate this redundancy. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::vmState): New helper. (bmalloc::BoundaryTag::setVMState): New helper. (bmalloc::BoundaryTag::owner): Deleted. (bmalloc::BoundaryTag::setOwner): Deleted. * bmalloc/Heap.h: (bmalloc::Heap::splitAndAllocate): New helpers. * bmalloc/LargeObject.h: (bmalloc::LargeObject::vmState): New helper. (bmalloc::LargeObject::setVMState): New helper. * bmalloc/Heap.cpp: (bmalloc::Heap::splitAndAllocate): New helpers. (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocatePhysicalPages): Refactored from VMHeap::deallocateLargeObjectMemory. * bmalloc/FreeList.cpp: (bmalloc::FreeList::takeGreedy): (bmalloc::FreeList::take): (bmalloc::FreeList::removeInvalidAndDuplicateEntries): * bmalloc/FreeList.h: (bmalloc::FreeList::FreeList): (bmalloc::FreeList::push): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::scavengeLargeObjects): * bmalloc/LargeObject.h: (bmalloc::LargeObject::isValidAndFree): (bmalloc::LargeObject::validateSelf): * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::SegregatedFreeList): Changed to initialize our required Physical state. * bmalloc/SegregatedFreeList.h: (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): Replaced Owner parameters and checks with VMState::HasPhysical. * bmalloc/LargeObject.h: (bmalloc::LargeObject::prevCanMerge): Removed owner from tests. (bmalloc::LargeObject::nextCanMerge): Removed owner from tests. (bmalloc::LargeObject::merge): Removed owner from tests. Updated to merge VMStates andset the VMState after the merge. * bmalloc/LargeObject.h: (bmalloc::LargeObject::owner): Deleted. (bmalloc::LargeObject::setOwner): Deleted. * bmalloc/Owner.h: Removed. * bmalloc/VMAllocate.h: (bmalloc::vmAllocatePhysicalPagesSloppy): Changed to round begin down to eliminate the left to right allocation constraint. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): Large space managed like small or medium as a vector of LargeChunks. (bmalloc::VMHeap::VMHeap): Changed to initialize our required Physical state. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeObject): These no longer allocate memory. (bmalloc::VMHeap::deallocateLargeObject): Removed setOwner. Now we set the VMState after any merges. * bmalloc/VMState.h: Copied from Source/bmalloc/bmalloc/Owner.h. (bmalloc::VMState::VMState): (bmalloc::VMState::hasPhysical): (bmalloc::VMState::hasVirtual): (bmalloc::VMState::merge): (bmalloc::VMState::operator ==): (bmalloc::VMState::operator unsigned): New class with various helpers. 2016-02-12 Michael Saboff <msaboff@apple.com> BASSERTs added in r196421 are causing debug test failures https://bugs.webkit.org/show_bug.cgi?id=154113 Reviewed by Geoffrey Garen. In VMHeap::deallocateLargeObject(), we drop the lock to deallocate the physical pages. If the scavenger thread is running at the same time a synchronous call to scavenge() comes in, we could call VMHeap::deallocateLargeObject() for an adjacent object while the lock in the other thread is dropped. We fix this by checking for adjacent objects we can merge with and loop if we have one. * bmalloc/FreeList.h: (bmalloc::FreeList::push): Added BASSERT to catch adding unmerged free objects * bmalloc/Heap.cpp: (bmalloc::Heap::allocateLarge): Changed to use nextCanMerge(). * bmalloc/LargeObject.h: (bmalloc::LargeObject::prevCanMerge): Repurposed prevIsAllocated. (bmalloc::LargeObject::nextCanMerge): Repurposed nextIsAllocated. (bmalloc::LargeObject::prevIsAllocated): Deleted. (bmalloc::LargeObject::nextIsAllocated): Deleted. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeObject): Moved adding the extra object back to the free list to after we set the object we'll return as being allocated. (bmalloc::VMHeap::deallocateLargeObject): 2016-02-12 Mark Lam <mark.lam@apple.com> Make BCRASH() use breakpoint traps too for non-debug OS(DARWIN). https://bugs.webkit.org/show_bug.cgi?id=154184 Reviewed by Saam Barati. This makes it behave consistently with WTFCrash(). * bmalloc/BAssert.h: * bmalloc/BPlatform.h: 2016-02-11 Michael Saboff <msaboff@apple.com> Unreviewed build fix after r196421. Removed BASSERTs that are firing to eliminate Debug build crashes. I'll debug locally and enable or alter after the issue is understood. * bmalloc/LargeObject.h: (bmalloc::LargeObject::merge): Removed BASSERTs that are firing. 2016-02-11 Michael Saboff <msaboff@apple.com> bmalloc: large aligned allocations will put 1 or 2 free object on free list without merging with free neighbors https://bugs.webkit.org/show_bug.cgi?id=154091 Reviewed by Geoffrey Garen. If we split off any unused free object in the aligned version of Heap::allocateLarge(), we merge them with free neighbors before putting them back on the free list. Added helpers to verify that when we add LargeObjects to the free list their neighbors are allocated. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateLarge): Deleted private helper version and rolled it into the two the two public versions of allocateLarge(). * bmalloc/Heap.h: * bmalloc/LargeObject.h: (bmalloc::LargeObject::prevIsAllocated): New helper. (bmalloc::LargeObject::nextIsAllocated): New helper. (bmalloc::LargeObject::merge): Check that the merge object has allocated neighbors. 2016-02-05 Saam barati <sbarati@apple.com> bmalloc: largeMax calculation is wrong on iOS https://bugs.webkit.org/show_bug.cgi?id=153923 Reviewed by Mark Lam. Our number for largeMax was larger than what we had space to actually allocate inside the LargeChunk. This made it so that we would allocate a large object for something that really should be extra large. Previously: largeMax + sizeof(LargeChunk) > 1MB which meant that when we would grow() to accommodate an allocation of a particular size inside a LargeObject despite the fact that the allocation size would be too large to actually fit in the LargeObject. This would manifest when we had an allocation size in the range: 1MB - sizeof(LargeChunk) < allocation size < largeMax We fix this bug by being precise in our calculation of largeMax instead of just assuming largeChunkSize * 99/100 is enough space for the metadata. * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::get): * bmalloc/Sizes.h: 2016-01-31 Dan Bernstein <mitz@apple.com> [Cocoa] Remove unused definition of HAVE_HEADER_DETECTION_H https://bugs.webkit.org/show_bug.cgi?id=153729 Reviewed by Sam Weinig. After r141700, HAVE_HEADER_DETECTION_H is no longer used. * Configurations/Base.xcconfig: 2015-12-19 Dan Bernstein <mitz@apple.com> [Mac] WebKit contains dead source code for OS X Mavericks and earlier https://bugs.webkit.org/show_bug.cgi?id=152462 Reviewed by Alexey Proskuryakov. * Configurations/DebugRelease.xcconfig: Removed definition of MACOSX_DEPLOYMENT_TARGET for OS X 10.9. 2015-12-03 Anders Carlsson <andersca@apple.com> Remove Objective-C GC support https://bugs.webkit.org/show_bug.cgi?id=151819 rdar://problem/23746991 Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2015-12-03 Michael Saboff <msaboff@apple.com> bmalloc: extra large allocations could be more efficient https://bugs.webkit.org/show_bug.cgi?id=151817 Reviewed by Geoffrey Garen. Reduced the super chunk size from 4MB to 2MB. Added path to reallocate() of an extra large object to see if we can extend the allocation. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): * bmalloc/SegregatedFreeList.h: * bmalloc/Sizes.h: * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): (bmalloc::tryVMExtend): (bmalloc::vmAllocate): 2015-11-11 Akos Kiss <akiss@inf.u-szeged.hu> bmalloc: Add libdl dependency https://bugs.webkit.org/show_bug.cgi?id=151140 Reviewed by Csaba Osztrogonác. Make sure that the linker links libdl and finds the references to dlopen, dlsym and dlclose in Environment.cpp. * CMakeLists.txt: 2015-11-02 Andy Estes <aestes@apple.com> [Cocoa] Add tvOS and watchOS to SUPPORTED_PLATFORMS https://bugs.webkit.org/show_bug.cgi?id=150819 Reviewed by Dan Bernstein. This tells Xcode to include these platforms in its Devices dropdown, making it possible to build in the IDE. * Configurations/Base.xcconfig: 2015-11-01 Philip Chimento <philip.chimento@gmail.com> [GTK] Fix combinations of PLATFORM(GTK) and OS(DARWIN) https://bugs.webkit.org/show_bug.cgi?id=144560 Reviewed by Darin Adler. * PlatformGTK.cmake: Added. This adds Zone.cpp to the PlatformGTK build, on Darwin only. Since there was previously nothing for the build system to do that was specific to the GTK platform in bmalloc, we need to create this file. 2015-10-29 Geoffrey Garen <ggaren@apple.com> bmalloc: AsyncTask should handle destruction https://bugs.webkit.org/show_bug.cgi?id=150648 Reviewed by Mark Lam. So we can use it in more places. * bmalloc/AsyncTask.h: Use std::thread instead of pthread because it should be more portable. (bmalloc::Function>::AsyncTask): Renamed Signaled to RunRequested for clarity. Added an ExitRequested state. (bmalloc::Function>::~AsyncTask): Wait for our child thread to exit before destroying ourselves because our child thread will modify our data (and might modify our client's data). Note that we only need to wait for the last child thread since any prior child thread, having reached the Exited condition, is guaranteed not to read or write any data. (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): Updated for interface changes. Also changed to use our WebKit style for condition signal: Hold the lock during the signal and always notify all. Technically, neither is necessary, but it is easier to understand the code this way, and harder to make mistakes. (bmalloc::Function>::threadEntryPoint): (bmalloc::Function>::threadRunLoop): Handle the new ExitRequested state. Technically, this state has no meaningful difference from the Exited state, but it is nice to be explicit. (bmalloc::Function>::join): Deleted. (bmalloc::Function>::pthreadEntryPoint): Deleted. (bmalloc::Function>::entryPoint): Deleted. 2015-10-15 Geoffrey Garen <ggaren@apple.com> bmalloc: per-thread cache data structure should be smaller https://bugs.webkit.org/show_bug.cgi?id=150218 Reviewed by Andreas Kling. Reduce the number of entries in the range cache because it's really big, and the bigness only helps in cases of serious fragmentation, and it only saves us a little bit of lock acquisition time. * bmalloc/Allocator.cpp: (bmalloc::Allocator::scavenge): (bmalloc::Allocator::refillAllocatorSlowCase): (bmalloc::Allocator::refillAllocator): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateSlowCase): (bmalloc::Allocator::allocateBumpRangeSlowCase): Deleted. (bmalloc::Allocator::allocateBumpRange): Deleted. * bmalloc/Allocator.h: Pass through the empty allocator and the range cache when refilling, and refill both. Otherwise, we always immediately pop the last item in the range cache, wasting that slot of capacity. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallBumpRanges): (bmalloc::Heap::allocateMediumBumpRanges): Account for the fact that the range cache is no longer big enough to guarantee that it can hold all the ranges in a page. (bmalloc::Heap::refillSmallBumpRangeCache): Deleted. (bmalloc::Heap::refillMediumBumpRangeCache): Deleted. * bmalloc/Heap.h: Move VMHeap to the end of the object because it contains a lot of unused / wasted space, and we want to pack our data together in memory. * bmalloc/Sizes.h: Make the range cache smaller. 2015-10-13 Chris Dumez <cdumez@apple.com> Avoid useless copies in range-loops that are using 'auto' https://bugs.webkit.org/show_bug.cgi?id=150091 Reviewed by Sam Weinig. Avoid useless copies in range-loops that are using 'auto'. Also use 'auto*' instead of 'auto' when range values are pointers for clarity. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): 2015-10-12 Geoffrey Garen <ggaren@apple.com> bmalloc: Don't ASSERT that all syscalls succeed https://bugs.webkit.org/show_bug.cgi?id=150047 <rdar://problem/22649531> Reviewed by Mark Lam. madvise can fail due to VM behaviors outside of our control: copy-on-write, fork, mprotect, and other stuff. Older darwin kernels sometimes return this error value, and new kernels might again in future. We haven't gained much from this ASSERT so far, so let's remove it. Perhaps in future we can come up with a scheme that makes madvise never fail, or that responds to failure. * bmalloc/Syscall.h: 2015-10-10 Dan Bernstein <mitz@apple.com> [iOS] Remove project support for iOS 8 https://bugs.webkit.org/show_bug.cgi?id=149993 Reviewed by Alexey Proskuryakov. * Configurations/Base.xcconfig: * Configurations/bmalloc.xcconfig: * Configurations/mbmalloc.xcconfig: 2015-08-31 Michael Catanzaro <mcatanzaro@igalia.com> Implement bmalloc::isASanEnabled for generic Unix https://bugs.webkit.org/show_bug.cgi?id=148623 Reviewed by Geoffrey Garen. * bmalloc/BPlatform.h: Add BOS_UNIX to detect whether the OS is a Unix. * bmalloc/Environment.cpp: (bmalloc::isASanEnabled): Implement a runtime check that should work on any Unix. 2015-08-19 Geoffrey Garen <ggaren@apple.com> Crash @ bmalloc::Environment::computeIsBmallocEnabled https://bugs.webkit.org/show_bug.cgi?id=148183 Reviewed by NOBODY Michael Saboff. CrashTracer says we have some crashes beneath computeIsBmallocEnabled dereferencing null in strstr. We null check getenv but not _dyld_get_image_name, so deduction indicates that _dyld_get_image_name must be returning null. _dyld_get_image_name isn't really documented, so let's assume it can return null. * bmalloc/Environment.cpp: (bmalloc::isASanEnabled): Check _dyld_get_image_name's return value for null because we can't prove it won't be null. 2015-07-24 Geoffrey Garen <ggaren@apple.com> vmmap crash at JavaScriptCore: 0x31cd12f6 (the JavaScript malloc zone enumerator) https://bugs.webkit.org/show_bug.cgi?id=147274 Reviewed by Anders Carlsson. It's not really clear why vmmap sometimes fails to read the target process, but we can avoid a crash when it does. This is useful because you'll still get all the non-bmalloc data out of the target process, and bmalloc might not even be relevant to your investigation. * bmalloc/Zone.cpp: (bmalloc::remoteRead): Check for failure. 2015-07-24 Geoffrey Garen <ggaren@apple.com> JavaScriptCore bmalloc should not register its malloc zone more than once https://bugs.webkit.org/show_bug.cgi?id=147273 Reviewed by Andreas Kling. This was a goof: The Zone constructor, by virtue of running automatically, was registering a Zone inside the analysis process. * bmalloc/Zone.cpp: (bmalloc::remoteRead): Clarify that the pointer is remote. (bmalloc::enumerator): (bmalloc::Zone::Zone): * bmalloc/Zone.h: Separate the normal constructor and the remote constructor. The remote constructor skips zone registration since its goal is not to register a zone in the current process or do any allocation but rather to mirror the bytes of the zone from the target process. 2015-07-23 Geoffrey Garen <ggaren@apple.com> bmalloc: Shrink the super chunk size (again) https://bugs.webkit.org/show_bug.cgi?id=147240 Reviewed by Andreas Kling. Shrinking to 8MB reduced VM exhaustion crashes but did not eliminate them. Let's try 4MB. (My previous comment was that the maximum fast object was 2MB. But it was 4MB! Now it's 2MB for realsies.) * bmalloc/Sizes.h: 2015-07-03 Dan Bernstein <mitz@apple.com> [Xcode] Update some build settings as recommended by Xcode 7 https://bugs.webkit.org/show_bug.cgi?id=146597 Reviewed by Sam Weinig. * Configurations/Base.xcconfig: Enabled CLANG_WARN_UNREACHABLE_CODE, GCC_NO_COMMON_BLOCKS, and ENABLE_STRICT_OBJC_MSGSEND. Removed GCC_MODEL_TUNING. * bmalloc.xcodeproj/project.pbxproj: Updated LastUpgradeCheck. 2015-07-02 Geoffrey Garen <ggaren@apple.com> bmalloc: Shrink the super chunk size https://bugs.webkit.org/show_bug.cgi?id=146519 Reviewed by Andreas Kling. We have lots of reports of crashing due to failed VM allocation on iOS. (This VM limit on iOS is usually 1GB-2GB, and has been as low as 256MB.) Shrink the super chunk size in case fragmentation is the reason for VM allocation failure. This has the downside that >= 2MB allocations will now be super slow, but they are also super rare (as in never on most websites), so this is probably an OK tradeoff. * bmalloc/Sizes.h: 2015-07-01 Geoffrey Garen <ggaren@apple.com> bmalloc: realloc of an XLarge range can unmap adjacent VM ranges https://bugs.webkit.org/show_bug.cgi?id=146535 Reviewed by Anders Carlsson. This bug causes a crash when running fast/css/large-list-of-rules-crash.html with the fix applied for https://bugs.webkit.org/show_bug.cgi?id=146519. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Start at object + newSize since starting at object + oldSize means deleting the adjacent VM range. 2015-05-26 Geoffrey Garen <ggaren@apple.com> Integer overflow in XLarge allocation (due to unchecked roundUpToMultipleOf) https://bugs.webkit.org/show_bug.cgi?id=145385 Reviewed by Andreas Kling. Added some checking to verify that round-up operations will not overflow a size_t. The simplest way to do this was to introduce a notion of xLargeMax, like we have for smallMax, mediumMax, and largeMax. It's a bit surprising at first to think that there is an xLargeMax, since xLarge is what we use to handle the biggest things. But computers have limits, so it makes sense. FWIW, TCMalloc used to have an xLargeMax too, which it called kMaxValidPages. No test because this bug was found by code inspection and I don't know of a practical way to convince WebKit to make an allocation this large. * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): (bmalloc::Allocator::allocate): (bmalloc::Allocator::reallocate): (bmalloc::Allocator::allocateSlowCase): Check against xLargeMax to avoid overflow when rounding up. * bmalloc/BAssert.h: Added support for explicit crashing. * bmalloc/Sizes.h: 2015-05-26 Dan Bernstein <mitz@apple.com> <rdar://problem/21104551> Update build settings Reviewed by Anders Carlsson. * Configurations/DebugRelease.xcconfig: 2015-05-23 Dan Bernstein <mitz@apple.com> Remove unused definitions of WEBKIT_VERSION_MIN_REQUIRED https://bugs.webkit.org/show_bug.cgi?id=145345 Reviewed by Sam Weinig. * Configurations/Base.xcconfig: Also changed to use $(inherited). 2015-05-07 Geoffrey Garen <ggaren@apple.com> Release assert in com.apple.WebKit.WebContent under JavaScriptCore: JSC::JSONProtoFuncStringify https://bugs.webkit.org/show_bug.cgi?id=144758 Reviewed by Andreas Kling. This was an out-of-memory error when trying to shrink a string builder. bmalloc was missing the optimization that allowed realloc() to shrink without copying. So, let's add it. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Added Large and XLarge cases for shrinking without copying. This isn't possible for small and medium objects, and probably not very profitable, either. * bmalloc/Heap.cpp: (bmalloc::Heap::findXLarge): (bmalloc::Heap::deallocateXLarge): * bmalloc/Heap.h: Refactored this code to return a reference to an XLarge range. This makes the code reusable, and also makes it easier for realloc() to update metadata. * bmalloc/LargeObject.h: (bmalloc::LargeObject::split): Allow allocated objects to split because that's what realloc() wants to do, and there's nothing intrinsically wrong with it. 2015-05-07 Dan Bernstein <mitz@apple.com> <rdar://problem/19317140> [Xcode] Remove usage of AspenFamily.xcconfig in Source/ https://bugs.webkit.org/show_bug.cgi?id=144727 Reviewed by Darin Adler. * Configurations/Base.xcconfig: Dont’s include AspenFamily.xcconfig, and define INSTALL_PATH_PREFIX for the iOS 8.x Simulator. 2015-04-01 Alex Christensen <achristensen@webkit.org> Progress towards CMake on Windows and Mac. https://bugs.webkit.org/show_bug.cgi?id=143293 Reviewed by Filip Pizlo. * bmalloc/BAssert.h: Removed ellipses from macros to appease Visual Studio. 2015-03-13 Alex Christensen <achristensen@webkit.org> Progress towards CMake on Mac. https://bugs.webkit.org/show_bug.cgi?id=142680 Reviewed by Gyuyoung Kim. * CMakeLists.txt: * PlatformMac.cmake: Added Zone.cpp to Mac CMake builds. 2015-03-12 Geoffrey Garen <ggaren@apple.com> Assertion failure in bmalloc::LargeObject::validateSelf on Mavericks Debug layout test bot https://bugs.webkit.org/show_bug.cgi?id=142642 Reviewed by Michael Saboff. The typical backtrace to this crash shows the main thread trying to realloc a large string while a DFG compiler thread tries to free a large vector buffer. I believe that this is a race condition -- at least in debug builds -- since the main thread will try to validate its object's neighbors without holding a lock, even though those neighbors might be in the midst of changing. In general, there may be sneaky times when it is valid to look at an object's metadata without holding the heap lock, but it is best not to do so unless we have a really really good reason to. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Take a lock before reading the metadata for this object, since we generally require any access to shared heap metadata to take a lock. 2015-03-10 Geoffrey Garen <ggaren@apple.com> bmalloc: tryFastMalloc shouldn't crash https://bugs.webkit.org/show_bug.cgi?id=142443 Reviewed by Sam Weinig. Rolling back in r181307 with a check for whether bmalloc is enabled, to avoid crashes when running with ASan and GuardMalloc. * bmalloc/Allocator.cpp: (bmalloc::Allocator::tryAllocate): * bmalloc/Allocator.h: * bmalloc/Cache.cpp: (bmalloc::Cache::tryAllocateSlowCaseNullCache): * bmalloc/Cache.h: (bmalloc::Cache::tryAllocate): * bmalloc/Heap.cpp: (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::tryAllocateXLarge): * bmalloc/Heap.h: * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): (bmalloc::vmAllocate): * bmalloc/bmalloc.h: (bmalloc::api::tryMalloc): (bmalloc::api::realloc): (bmalloc::api::free): 2015-03-09 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r181307. https://bugs.webkit.org/show_bug.cgi?id=142525 Broke ASan tests (Requested by ap on #webkit). Reverted changeset: "bmalloc: tryFastMalloc shouldn't crash" https://bugs.webkit.org/show_bug.cgi?id=142443 http://trac.webkit.org/changeset/181307 2015-03-09 Geoffrey Garen <ggaren@apple.com> bmalloc: tryFastMalloc shouldn't crash https://bugs.webkit.org/show_bug.cgi?id=142443 Reviewed by Darin Adler. Added support for tryMalloc. We assume that non-x-large allocations always succeed, and we crash otherwise, since normal allocation failure will just cause the next non-try allocation or internal metadata allocation to fail, and it's hard and not really useful to keep limping along after that. But extra-large allocations can meaningfully fail, and we can recover. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::tryAllocateXLarge): * bmalloc/Heap.h: Added support for non-crashy x-large allocation. * bmalloc/VMAllocate.h: (bmalloc::tryVMAllocate): (bmalloc::vmAllocate): Added support for non-crashy VM allocation. * bmalloc/bmalloc.h: (bmalloc::api::tryMalloc): (bmalloc::api::realloc): (bmalloc::api::free): Tried to clarify our behavior with some comments. Unfortunately, calling what we do "malloc" is still not quite right, since malloc returns null on failure and we don't. 2015-03-03 Geoffrey Garen <ggaren@apple.com> bmalloc: Don't branch when setting the owner of a large object https://bugs.webkit.org/show_bug.cgi?id=142241 Reviewed by Andreas Kling. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::owner): (bmalloc::BoundaryTag::setOwner): 2015-03-03 Geoffrey Garen <ggaren@apple.com> bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. Re-enabled this feature on iOS, now that the iOS crash should be fixed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: 2015-03-03 Geoffrey Garen <ggaren@apple.com> bmalloc: Added missing features to the malloc zone introspection API https://bugs.webkit.org/show_bug.cgi?id=142235 Reviewed by Andreas Kling. This should fix the crash we saw on the iOS PLT bot (c.f. http://trac.webkit.org/changeset/180604). * bmalloc/Zone.cpp: (bmalloc::good_size): (bmalloc::check): (bmalloc::print): (bmalloc::log): (bmalloc::force_lock): (bmalloc::force_unlock): (bmalloc::statistics): (bmalloc::size): (bmalloc::enumerator): Provide all of these functions since they are called indiscriminately on all zones. (bmalloc::Zone::Zone): (bmalloc::Zone::size): Deleted. (bmalloc::Zone::enumerator): Deleted. Moved these functions out of the Zone class since they can stand alone. * bmalloc/Zone.h: 2015-03-03 Geoffrey Garen <ggaren@apple.com> bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. Rolling back in but disabled on iOS until I can debug why the iOS PLT crashes. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::size): (bmalloc::Zone::Zone): * bmalloc/Zone.h: 2015-03-03 Geoffrey Garen <ggaren@apple.com> bmalloc: Miscellaneous cleanup https://bugs.webkit.org/show_bug.cgi?id=142231 Reviewed by Andreas Kling. No performance change -- maybe a tiny reduction in memory use. * bmalloc/Heap.cpp: Moved the sleep function into StaticMutex, since it's a helper for working with mutexes. (bmalloc::Heap::scavenge): Make sure to wait before we start any scavenging, since individual scavenging functions now always scavenge at least one page before waiting themselves. (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeObjects): Use the new wait helper to simplify this code. Also, we now require our caller to wait until at least one deallocation is desirable. This simplifies our loop. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::allocateMediumPage): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::allocateLarge): Don't freak out any time the heap does an allocation. Only consider the heap to be growing if it actually needs to allocate new VM. This allows us to shrink the heap back down from a high water mark more reliably even if heap activity continues. (bmalloc::sleep): Deleted. (bmalloc::Heap::scavengeLargeRanges): Renamed to match our use of "LargeObject". * bmalloc/Heap.h: * bmalloc/LargeObject.h: (bmalloc::LargeObject::operator bool): Added to simplify a while loop. * bmalloc/StaticMutex.h: (bmalloc::sleep): (bmalloc::waitUntilFalse): New helper for waiting until a condition becomes reliably false. * bmalloc/Vector.h: (bmalloc::Vector<T>::~Vector): Oops! Don't deallocate the null pointer. We don't actually run any Vector destructors, but an iteration of this patch did, and then crashed. So, let's fix that. 2015-03-02 Geoffrey Garen <ggaren@apple.com> bmalloc: Eagerly remove allocated objects from the free list https://bugs.webkit.org/show_bug.cgi?id=142194 Reviewed by Andreas Kling. This reduces the pressure to garbage collect the free list. Might be a 1% speedup on MallocBench. * bmalloc/FreeList.cpp: Put this comment at the top of the file instead of repeating it inside of each function. Tried to clarify the details. (bmalloc::FreeList::takeGreedy): Matched the other iteration code in this file for consistency -- even though either direction works fine in this function. (bmalloc::FreeList::take): Change to iterate from low to high so that we can maintain an index into the vector that is not disturbed even if we pop from the middle (which invalidates the last index in the vector). Decrement i when popping from the middle to make sure that we don't skip the next item after popping. (bmalloc::FreeList::removeInvalidAndDuplicateEntries): Ditto. 2015-02-27 Ryosuke Niwa <rniwa@webkit.org> Fixed a typo in the previous commit. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::setOwner): 2015-02-27 Ryosuke Niwa <rniwa@webkit.org> EFL build fix after r180797. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::owner): (bmalloc::BoundaryTag::setOwner): 2015-02-27 Geoffrey Garen <ggaren@apple.com> bmalloc: Pathological madvise churn on the free(malloc(x)) benchmark https://bugs.webkit.org/show_bug.cgi?id=142058 Reviewed by Andreas Kling. The churn was caused by repeatedly splitting an object with physical pages from an object without, and then merging them back together again. The merge would conservatively forget that we had physical pages, forcing a new call to madvise on the next allocation. This patch more strictly segregates objects in the heap from objects in the VM heap, with these changes: (1) Objects in the heap are not allowed to merge with objects in the VM heap, and vice versa -- since that would erase our precise knowledge of which physical pages had been allocated. (2) The VM heap is exclusively responsible for allocating and deallocating physical pages. (3) The heap free list must consider entries for objects that are in the VM heap to be invalid, and vice versa. (This condition can arise because the free list does not eagerly remove items.) With these changes, we can know that any valid object in the heap's free list already has physical pages, and does not need to call madvise. Note that the VM heap -- as before -- might sometimes contain ranges or pieces of ranges that have physical pages, since we allow splitting of ranges at granularities smaller than the VM page size. These ranges can eventually merge with ranges in the heap during scavenging. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::owner): (bmalloc::BoundaryTag::setOwner): (bmalloc::BoundaryTag::initSentinel): (bmalloc::BoundaryTag::hasPhysicalPages): Deleted. (bmalloc::BoundaryTag::setHasPhysicalPages): Deleted. Replaced the concept of "has physical pages" with a bit indicating which heap owns the large object. This is a more precise concept, since the old bit was really a Yes / Maybe bit. * bmalloc/Deallocator.cpp: * bmalloc/FreeList.cpp: Adopt (bmalloc::FreeList::takeGreedy): (bmalloc::FreeList::take): (bmalloc::FreeList::removeInvalidAndDuplicateEntries): * bmalloc/FreeList.h: (bmalloc::FreeList::push): Added API for considering the owner when deciding if a free list entry is valid. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): Adopt new API. (bmalloc::Heap::scavengeLargeRanges): Scavenge all ranges with no minimum, since some ranges might be able to merge with ranges in the VM heap, and they won't be allowed to until we scavenge them. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::allocateMediumPage): (bmalloc::Heap::allocateLarge): New VM heap API makes this function simpler, since we always get back physical pages now. * bmalloc/Heap.h: * bmalloc/LargeObject.h: (bmalloc::LargeObject::end): (bmalloc::LargeObject::owner): (bmalloc::LargeObject::setOwner): (bmalloc::LargeObject::isValidAndFree): (bmalloc::LargeObject::merge): Do not merge objects across heaps since that causes madvise churn. (bmalloc::LargeObject::validateSelf): (bmalloc::LargeObject::init): (bmalloc::LargeObject::hasPhysicalPages): Deleted. (bmalloc::LargeObject::setHasPhysicalPages): Deleted. Propogate the Owner API. * bmalloc/Owner.h: Added. * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Propogate the owner API. * bmalloc/VMAllocate.h: (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): Clarified these functions and removed an edge case. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeObject): (bmalloc::VMHeap::deallocateLargeObject): Be sure to give each object a new chance to merge, since it might have been prohibited from merging before by virtue of not being in the VM heap. (bmalloc::VMHeap::allocateLargeRange): Deleted. (bmalloc::VMHeap::deallocateLargeRange): Deleted. 2015-02-26 Geoffrey Garen <ggaren@apple.com> bmalloc: Large object free list can grow infinitely https://bugs.webkit.org/show_bug.cgi?id=142055 Reviewed by Andreas Kling. By design, we don't eagerly remove large objects from the free list. This creates two simple pathologies: (1) If you free and then allocate the same object repeatedly, it will duplicate itself in the free list repeatedly. Since it is never invalid at the time of allocation, it will never be removed. (2) If you split and then merge the same object repeatedly, it will duplicate its split sibling in the free list repeatedly. If its sibling is in a separate free list size class, it will never be consulted at the time of allocation, so it will never be removed. So, a simple "while (1) { free(malloc(x)); }" causes infinite memory use in the free list. The solution in this patch is a simple helper to remove garbage from the free list if it grows too large. This pathology is not common, so the cost is OK. Long-term, perhaps we should rethink the laziness of these free lists. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::isMarked): (bmalloc::BoundaryTag::setMarked): New bit, used by free list GC. * bmalloc/FreeList.cpp: (bmalloc::FreeList::removeInvalidAndDuplicateEntries): The GC algorithm. * bmalloc/FreeList.h: (bmalloc::FreeList::FreeList): (bmalloc::FreeList::push): Invoke the GC if we're getting huge. * bmalloc/LargeObject.h: (bmalloc::LargeObject::isMarked): (bmalloc::LargeObject::setMarked): (bmalloc::LargeObject::validateSelf): Expose the new bit. * bmalloc/Sizes.h: New constant to control GC frequency. 2015-02-26 Csaba Osztrogonác <ossy@webkit.org> URTBF after r180693. * CMakeLists.txt: 2015-02-26 Geoffrey Garen <ggaren@apple.com> Try to fix the Mac build. Unreviewed. * bmalloc.xcodeproj/project.pbxproj: Make FreeList.h available. 2015-02-26 Geoffrey Garen <ggaren@apple.com> bmalloc: Refactored SegregatedFreeList and BoundaryTag::init https://bugs.webkit.org/show_bug.cgi?id=142049 Reviewed by Anders Carlsson. Split out a FreeList class from SegregatedFreeList. This will make it easier to add behaviors on free list insertion and removal -- and it's probably how I should have designed things at the start. Moved BoundaryTag::init into LargeObject, since all the related logic lives in LargeObject now too, and this allows us to remove BoundaryTagInlines.h. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BoundaryTagInlines.h: Removed. * bmalloc/FreeList.cpp: Copied from Source/bmalloc/bmalloc/SegregatedFreeList.cpp. (bmalloc::FreeList::takeGreedy): (bmalloc::FreeList::take): (bmalloc::SegregatedFreeList::SegregatedFreeList): Deleted. (bmalloc::SegregatedFreeList::insert): Deleted. (bmalloc::SegregatedFreeList::takeGreedy): Deleted. (bmalloc::SegregatedFreeList::take): Deleted. * bmalloc/FreeList.h: Copied from Source/bmalloc/bmalloc/SegregatedFreeList.h. (bmalloc::FreeList::push): * bmalloc/LargeObject.h: (bmalloc::LargeObject::init): * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: * bmalloc/Sizes.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): 2015-02-26 Geoffrey Garen <ggaren@apple.com> bmalloc: free up a bit in BoundaryTag https://bugs.webkit.org/show_bug.cgi?id=142048 Reviewed by Brady Eidson. We were wasting a bit by accident, and I need one now. * bmalloc/Algorithm.h: (bmalloc::rightShift): Deleted. Not needed, now that I've simplified the math. * bmalloc/BoundaryTag.h: Since each boundary tag bucket is 1024 bytes long, the maximum offset into a bucket is 1023. You need 5 bits to count up to 1024, but only 4 to count up to 1023. Math is hard. (bmalloc::BoundaryTag::compactBegin): Switched to division because it is simpler, and easier to match up with our ASSERT. The compiler will turn division by constant power of two into a shift for us. (bmalloc::BoundaryTag::setRange): Added an ASSERT for compactBegin because we do encode it, so we should ASSERT that encoding did not lose information. * bmalloc/Sizes.h: Shifting is no longer used since we use division instead. 2015-02-24 Stephanie Lewis <slewis@apple.com> Rolling out http://trac.webkit.org/changeset/180430 as it causes the PLT to crash. <rdar://problem/19948015> Unreviewed. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::Zone): (bmalloc::Zone::size): Deleted. * bmalloc/Zone.h: 2015-02-24 Geoffrey Garen <ggaren@apple.com> bmalloc: Added a little more abstraction for large objects https://bugs.webkit.org/show_bug.cgi?id=141978 Reviewed by Sam Weinig. Previously, each client needed to manage the boundary tags of a large object using free functions. This patch introduces a LargeObject class that does things a little more automatically. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Use the new LargeObject class. * bmalloc/BeginTag.h: (bmalloc::BeginTag::isInFreeList): Deleted. Moved this logic into the LargeObject class. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::isSentinel): (bmalloc::BoundaryTag::compactBegin): (bmalloc::BoundaryTag::setRange): (bmalloc::BoundaryTag::initSentinel): Added an explicit API for sentinels, which we used to create and test for implicitly. * bmalloc/BoundaryTagInlines.h: (bmalloc::BoundaryTag::init): (bmalloc::validate): Deleted. (bmalloc::validatePrev): Deleted. (bmalloc::validateNext): Deleted. (bmalloc::BoundaryTag::mergeLeft): Deleted. (bmalloc::BoundaryTag::mergeRight): Deleted. (bmalloc::BoundaryTag::merge): Deleted. (bmalloc::BoundaryTag::deallocate): Deleted. (bmalloc::BoundaryTag::split): Deleted. (bmalloc::BoundaryTag::allocate): Deleted. Moved this logic into the LargeObject class. * bmalloc/EndTag.h: (bmalloc::EndTag::init): (bmalloc::EndTag::operator=): Deleted. Re-reading this code, I found special behavior in the assignment operator to be a surprising API. So, I replaced the assignment operation with an explicit initializing function. * bmalloc/Heap.cpp: (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::findXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: No behavior changes here -- just adopting the LargeObject interface. * bmalloc/LargeObject.h: Added. (bmalloc::LargeObject::operator!): (bmalloc::LargeObject::begin): (bmalloc::LargeObject::size): (bmalloc::LargeObject::range): (bmalloc::LargeObject::LargeObject): (bmalloc::LargeObject::setFree): (bmalloc::LargeObject::isFree): (bmalloc::LargeObject::hasPhysicalPages): (bmalloc::LargeObject::setHasPhysicalPages): (bmalloc::LargeObject::isValidAndFree): (bmalloc::LargeObject::merge): (bmalloc::LargeObject::split): (bmalloc::LargeObject::validateSelf): (bmalloc::LargeObject::validate): Moved this code into a class, out of BoundaryTag free functions. New to the class are these features: (1) Every reference to an object is validated upon creation and use. (2) There's an explicit API for "This is a reference to an object that might be stale (the DoNotValidate API)". (3) The begin and end tags are kept in sync automatically. * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Adopt the LargeObject interface. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateLargeRange): Adopt the LargeObject interface. 2015-02-20 Geoffrey Garen <ggaren@apple.com> bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. Rolling back in with a fix for a crash seen while using GuardMalloc. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: Re-land the old patch. (bmalloc::Zone::size): Be sure to implement the size() function since it's accessible indirectly via the malloc_zone_from_ptr public API -- and GuardMalloc calls it all the time. (bmalloc::Zone::Zone): * bmalloc/Zone.h: Re-land the old patch. 2015-02-19 Commit Queue <commit-queue@webkit.org> Unreviewed, rolling out r180363. https://bugs.webkit.org/show_bug.cgi?id=141814 Caused >50 crashes when running LayoutTests in GuardMalloc or ASAN modes. (Requested by jernoble on #webkit). Reverted changeset: "bmalloc should implement malloc introspection (to stop false- positive leaks when MallocStackLogging is off)" https://bugs.webkit.org/show_bug.cgi?id=141802 http://trac.webkit.org/changeset/180363 2015-02-19 Geoffrey Garen <ggaren@apple.com> bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. Fixed a last-minute type. The macro is OS, not PLATFORM. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: * bmalloc/Zone.h: 2015-02-19 Geoffrey Garen <ggaren@apple.com> bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. This patch does the bare minimum to stop false positive leaks from being reported by the Darwin leaks tool. We register each super chunk as a single object, and then request that the leaks tool scan it. * bmalloc.xcodeproj/project.pbxproj: Added an abstraction for the malloc zone introspection API. * bmalloc/Algorithm.h: Missing #include. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: Adopt the new abstraction. * bmalloc/Zone.cpp: Added. (bmalloc::remoteRead): Helper for reading an object out of another process. (bmalloc::Zone::enumerator): (bmalloc::Zone::Zone): Register a malloc zone so that we will participate in introspection. * bmalloc/Zone.h: Added. (bmalloc::Zone::superChunks): (bmalloc::Zone::addSuperChunk): Use a non-dynamically-allocated vector since our dynamic allocations will not be scanned by leaks since they will have the malloc VM tag. 2015-02-18 Geoffrey Garen <ggaren@apple.com> bmalloc: VMHeap should keep a record of all of its VM ranges (for malloc introspection) https://bugs.webkit.org/show_bug.cgi?id=141759 Reviewed by Andreas Kling. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/SuperChunk.h: Added. (bmalloc::SuperChunk::create): (bmalloc::SuperChunk::SuperChunk): (bmalloc::SuperChunk::smallChunk): (bmalloc::SuperChunk::mediumChunk): (bmalloc::SuperChunk::largeChunk): Factored out super chunk creation into a separate class, for clarity and type safety. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): (bmalloc::VMHeap::allocateSuperChunk): Renamed "allocateSuperChunk" to "grow" because Andreas found "allocateSuperChunk" to be unclear. * bmalloc/VMHeap.h: Track all our VM ranges. We will use this information for malloc introspection. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): Updated for renames. 2015-02-18 Zan Dobersek <zdobersek@igalia.com> Build bmalloc through CMake as a static library. It's then linked either into the WTF library (if built as a shared library) or into the JSC and WebKit2 libraries. There's no need to build it as a standalone shared library. Rubber-stamped by Carlos Garcia Campos. * CMakeLists.txt: 2015-02-13 Gyuyoung Kim <gyuyoung.kim@samsung.com> [BMalloc] Add a FIXME comment for memory alignas https://bugs.webkit.org/show_bug.cgi?id=141556 Reviewed by Csaba Osztrogonác. * bmalloc/Chunk.h: Add a FIXME comment. * bmalloc/LargeChunk.h: ditto. 2015-02-11 Csaba Osztrogonác <ossy@webkit.org> bmalloc buildfix on 32 bit Linux (x86/ARM) https://bugs.webkit.org/show_bug.cgi?id=141472 Reviewed by Gyuyoung Kim. * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOf): * bmalloc/FixedVector.h: (bmalloc::FixedVector::clear): * bmalloc/Sizes.h: (bmalloc::Sizes::sizeClass): 2015-02-11 Gyuyoung Kim <gyuyoung.kim@samsung.com> [EFL][GTK] Use bmalloc instead of tcmalloc https://bugs.webkit.org/show_bug.cgi?id=140162 Reviewed by Carlos Garcia Campos. Support to use bmalloc on EFL and GTK ports. * CMakeLists.txt: Added. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): Fix unused return value caused by posix_memalign(). * bmalloc/AsyncTask.h: * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::clear): * bmalloc/Chunk.h: Change Traits::Page with Traits::PageType in order to fix -fpermitive build error on EFL and GTK port. * bmalloc/EndTag.h: (bmalloc::EndTag::operator=): * bmalloc/Line.h: ditto. * bmalloc/MediumTraits.h: * bmalloc/Page.h: ditto. * bmalloc/PerThread.h: EFL port doesn't support __has_include definition yet. Define HAVE_PTHREAD_MACHDEP_H according to check if __has_include is supported. * bmalloc/SmallTraits.h: ditto. * bmalloc/VMAllocate.h: (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): * bmalloc/Vector.h: (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::reallocateBuffer): 2015-01-31 Sam Weinig <sam@webkit.org> Remove even more Mountain Lion support https://bugs.webkit.org/show_bug.cgi?id=141124 Reviewed by Alexey Proskuryakov. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2015-01-30 Geoffrey Garen <ggaren@apple.com> GC marking threads should clear malloc caches https://bugs.webkit.org/show_bug.cgi?id=141097 Reviewed by Andreas Kling. Split the scavenging API into per-thread vs global, so that you can request to scavenge your own thread without scavenging the whole heap. * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): * bmalloc/bmalloc.h: (bmalloc::api::scavengeThisThread): (bmalloc::api::scavenge): 2015-01-28 Dana Burkart <dburkart@apple.com> Move ASan flag settings from DebugRelease.xcconfig to Base.xcconfig https://bugs.webkit.org/show_bug.cgi?id=136765 Reviewed by Alexey Proskuryakov. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2015-01-21 Geoffrey Garen <ggaren@apple.com> bmalloc: support aligned allocation https://bugs.webkit.org/show_bug.cgi?id=140732 Reviewed by Andreas Kling. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): New function for aligned allocation. Small and medium requests just allocate and free until they find an aligned pointer. This is slightly inefficient in the worst case, but still constant-time with little-to-no space overhead. Large requests use a new API that requires the client to specify both its ideal size and alignment, and the worst-case size you would have to allocate in order to produce some interior pointer of the requested size and alignment. We put the burden of this calculation on the client because it simplifies things if we guarantee that allocation won't fail. XLarge requests are easy: we just forward them to vmAllocate, which already supported aligned requests. * bmalloc/BoundaryTag.h: * bmalloc/BoundaryTagInlines.h: (bmalloc::BoundaryTag::mergeLeft): (bmalloc::BoundaryTag::mergeRight): (bmalloc::BoundaryTag::merge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::split): (bmalloc::BoundaryTag::allocate): No behavior change here. I just refactored the interface to remove some reference out parameters in order to clarify what changes and what doesn't. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateXLarge): Added an alignment API. (bmalloc::Heap::allocateLarge): * bmalloc/Heap.h: Added an alignment API. I split out allocateLarge into a few variants, so aligned and unaligned allocation could share some code. * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Changed to use a separate, explicit API for aligned allocation. It turns out that the aligned path is pretty different, since it ends up searching for two potential ways to satisfy an allocation: either large enough and aligned, or large enough to split into something not aligned and something large enough and aligned. * bmalloc/VMAllocate.h: (bmalloc::vmAllocate): Switched alignment to come before size because that's how the memalign API specifies it. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateLargeRange): Added an alignment API. 2015-01-20 Geoffrey Garen <ggaren@apple.com> bmalloc: a little bit of cleanup https://bugs.webkit.org/show_bug.cgi?id=140687 Reviewed by Anders Carlsson. * bmalloc/Algorithm.h: (bmalloc::isPowerOfTwo): Added a check for 0, since 0 would break a lot of code. * bmalloc/BoundaryTag.h: * bmalloc/BoundaryTagInlines.h: (bmalloc::BoundaryTag::mergeLeft): (bmalloc::BoundaryTag::mergeRight): (bmalloc::BoundaryTag::merge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::split): (bmalloc::BoundaryTag::allocate): (bmalloc::BoundaryTag::mergeLargeLeft): Deleted. (bmalloc::BoundaryTag::mergeLargeRight): Deleted. (bmalloc::BoundaryTag::mergeLarge): Deleted. (bmalloc::BoundaryTag::splitLarge): Deleted. Removed the word "Large" from all these functions, since boundary tags always pertain to large objects, and putting the word "Large" everywhere wasn't helping to explain that. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::findXLarge): (bmalloc::Heap::deallocateXLarge): * bmalloc/Heap.h: * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateXLarge): Deleted. (bmalloc::VMHeap::findXLarge): Deleted. (bmalloc::VMHeap::deallocateXLarge): Deleted. Moved XLarge allocation from VMHeap to Heap. Since the purpose of the VMHeap is to cache VM ranges, and the VMHeap never caches any XLarge ranges, it doesn't really make sense for the VMHeap to be involved. 2015-01-16 Geoffrey Garen <ggaren@apple.com> bmalloc: refactored XLarge allocation for better alignment https://bugs.webkit.org/show_bug.cgi?id=140582 Reviewed by Andreas Kling. XLarge objects used to be Large objects with an extra bit of metadata that said "actually, I'm not large -- I'm extra large". The metadata header in an XLarge allocation made it impossible for the XLarge object to honor a very large alignment request. The solution is to stop using a metadata header for XLarge objects, and instead to store explicit metadata on the side. This is a bit less astonishing, which is also nice. Finding XLarge metadata is now a linear search. That's probably OK, since it was always so in TCMalloc, and the usual number of XLarge allocations in a process is 0. This design makes it possible for the heap to cache XLarge allocations with and/or without physical pages. I haven't actually done that yet because the tradeoffs are subtle, so I don't want to do anything without a motivating test case. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): Removed the concept of an XLargeChunk, since an XLarge allocation is now just a naked buffer without a header. (bmalloc::Allocator::allocateXLarge): Added an explicit qualifier for XLarge alignment, since XLargeChunk won't give this to us implicitly anymore. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::setRange): (bmalloc::BoundaryTag::isXLarge): Deleted. (bmalloc::BoundaryTag::setXLarge): Deleted. * bmalloc/BoundaryTagInlines.h: (bmalloc::validate): (bmalloc::BoundaryTag::deallocate): Removed the XLarge hacks from Large allocations. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Heap.cpp: (bmalloc::Heap::findXLarge): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): * bmalloc/Heap.h: Updated for interface changes. * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: (bmalloc::isXLarge): We can now tell if a pointer is XLarge just by examining its bit pattern -- just like we do for other kinds of allocations -- which is nice. * bmalloc/Sizes.h: * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateXLarge): (bmalloc::VMHeap::findXLarge): (bmalloc::VMHeap::deallocateXLarge): Keep an explicit vector of metadata for XLarge allocations. * bmalloc/XLargeChunk.h: Removed. 2015-01-16 Geoffrey Garen <ggaren@apple.com> bmalloc: added some infrastructure for aligned allocation https://bugs.webkit.org/show_bug.cgi?id=140572 Reviewed by Andreas Kling. * bmalloc/Algorithm.h: (bmalloc::isPowerOfTwo): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): Refactored some duplicate code to use our isPowerOfTwo helper function. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocate): * bmalloc/Allocator.h: Stubbed out an implementation of aligned allocation. Doesn't do anything yet, but does correctly forward to system malloc when bmalloc is disabled. * bmalloc/Cache.cpp: (bmalloc::Cache::allocateSlowCaseNullCache): * bmalloc/Cache.h: (bmalloc::Cache::allocate): * bmalloc/bmalloc.h: (bmalloc::api::memalign): * bmalloc/mbmalloc.cpp: Stubbed out an API for aligned allocation. 2015-01-13 Geoffrey Garen <ggaren@apple.com> Consider alignment when allocating from a SegregatedFreeList https://bugs.webkit.org/show_bug.cgi?id=140408 Reviewed by Sam Weinig. In preparation for supporting aligned allocation. No performance change. Since this is just one extra branch in an already expensive function, I decided not to duplicate the function just to avoid the branch in the un-aligned case. * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: 2015-01-13 Geoffrey Garen <ggaren@apple.com> Renamed minimum to size in SegregatedFreeList https://bugs.webkit.org/show_bug.cgi?id=140406 Reviewed by Sam Weinig. In preparation for supporting aligned allocation. * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): Every size passed to malloc is really just a minimum. Let's not imply that this value is special. 2015-01-11 Dan Bernstein <mitz@apple.com> Geoff is organized, but he is not an organization. Rubber-stamped by Anders Carlsson. * bmalloc.xcodeproj/project.pbxproj: Removed the ORGANIZATIONNAME project attribute. 2015-01-07 Geoffrey Garen <ggaren@apple.com> Make bmalloc work with ASan https://bugs.webkit.org/show_bug.cgi?id=140194 Reviewed by Mark Lam. * bmalloc/BPlatform.h: Added a way to detect Darwin OSes, since we need an OS-specific API to test for loaded runtime libraries. * bmalloc/Environment.cpp: (bmalloc::isASanEnabled): (bmalloc::Environment::computeIsBmallocEnabled): Disabled bmalloc if ASan is enabled, since system malloc has the Asan hooks we need. You could check for the ASan compile-time flag instead, but doing this check at runtime prepares bmalloc for a world where it is a dynamic library that might be loaded into projects it did not compile with. 2015-01-05 Geoffrey Garen <ggaren@apple.com> Fix up bmalloc's PerThread for use on Linux https://bugs.webkit.org/show_bug.cgi?id=139804 Reviewed by Anders Carlsson. The previous implementation was a bit slow. * bmalloc/PerThread.h: (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): Added a catch-all cross-platform Unix way to do fast per-thread access without taking a lock every time. This probably works on all the platforms we care about, and it matches other techniques we use elsewhere in WebKit. (bmalloc::PerThread<T>::getFastCase): Removed the conditional from this class because PerThreadStorage now encapsulates everything that needs to be conditional. (bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Deleted. 2014-12-26 Dan Bernstein <mitz@apple.com> <rdar://problem/19348208> REGRESSION (r177027): iOS builds use the wrong toolchain https://bugs.webkit.org/show_bug.cgi?id=139950 Reviewed by David Kilzer. * Configurations/Base.xcconfig: Only define TOOLCHAINS when building for OS X, doing so in a manner that works with Xcode 5.1.1. 2014-12-15 Geoffrey Garen <ggaren@apple.com> Safari crashes when you set Malloc environment variables https://bugs.webkit.org/show_bug.cgi?id=139656 Reviewed by Michael Saboff. I forgot to cover the realloc() case. Whoops. (OoPS?) This time around, I ran the full MallocBench test suite in Malloc=1 mode, and it passed. * bmalloc/Allocator.cpp: (bmalloc::Allocator::reallocate): * bmalloc/Allocator.h: Pushed realloc() logic down into the allocator. It needs to be down there so that we can do the short-circuiting check for whether bmalloc is enabled first. Also added the check. * bmalloc/Cache.cpp: (bmalloc::Cache::scavenge): (bmalloc::Cache::Cache): (bmalloc::Cache::reallocateSlowCaseNullCache): * bmalloc/Cache.h: (bmalloc::Cache::deallocator): (bmalloc::Cache::reallocate): Ditto. * bmalloc/bmalloc.h: (bmalloc::api::free): (bmalloc::api::realloc): Ditto. (bmalloc::api::scavenge): Pushed this down into Cache to match the surrounding functions. 2014-12-11 Geoffrey Garen <ggaren@apple.com> bmalloc should support system memory analysis tools (part 2) https://bugs.webkit.org/show_bug.cgi?id=139565 Reviewed by Mark Lam. This patch actually queries the environment to see if memory analysis tools have been enabled. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): Don't process the object log if we've disabled bmalloc because it will be full of invalid nullptrs. * bmalloc/Environment.cpp: (bmalloc::isMallocEnvironmentVariableSet): Test for the list of known Malloc debugging flags. I also added a plain "Malloc" catch-all for when you want to disable bmalloc without enabling any kind of funny business. It would be slightly nicer just to iterate the list of environment variables and strstr them, but getenv is the more portable option, and performance here doesn't really matter. (bmalloc::isLibgmallocEnabled): Test for the libgmalloc insertion environment variable. (bmalloc::Environment::computeIsBmallocEnabled): 2014-12-11 Geoffrey Garen <ggaren@apple.com> Try to fix the iOS simulator build. #include the declaration of malloc / free. * bmalloc/Allocator.cpp: * bmalloc/Deallocator.cpp: 2014-12-11 Geoffrey Garen <ggaren@apple.com> Try to fix the build. * bmalloc.xcodeproj/project.pbxproj: Marked a header exported. 2014-12-11 Geoffrey Garen <ggaren@apple.com> bmalloc should support system memory analysis tools (part 1) https://bugs.webkit.org/show_bug.cgi?id=139559 Reviewed by Mark Lam. This patch adds the hooks to disable bmalloc at runtime if certain environment variables are set, but doesn't actually read from the environment yet. No performance change. * bmalloc.xcodeproj/project.pbxproj: Added the Environment class, which we'll use to read environment variables and see if memory analysis tools have been enabled. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): (bmalloc::Allocator::allocateSlowCase): Added a hook to disable bmalloc on the allocation path. We cache the setting to make the check fast. * bmalloc/Allocator.h: Interface changes. * bmalloc/Cache.cpp: (bmalloc::Cache::Cache): Pass a heap pointer through to our allocator and deallocator. This main purpose is to enable them to query the environment for whether bmalloc is enabled; but this is also a slightly cleaner way to guarantee to them that the Heap has been pre-initialized. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::Deallocator): If bmalloc is disable, artificially fill the object log to force us to take the slow path on all deallocations. (bmalloc::Deallocator::deallocateSlowCase): Do the disabled check. * bmalloc/Deallocator.h: Interface changes. * bmalloc/Environment.cpp: Added. (bmalloc::Environment::Environment): (bmalloc::Environment::computeIsBmallocEnabled): * bmalloc/Environment.h: Added. (bmalloc::Environment::isBmallocEnabled): This is the class that will encapsulate looking for environment variables that turn on heap analysis tools. * bmalloc/Heap.h: (bmalloc::Heap::environment): * bmalloc/Mutex.h: (bmalloc::Mutex::Mutex): * bmalloc/StaticMutex.h: A little refactoring to clarify these comments, since I got super confused about them while writing this patch. * bmalloc/VMHeap.cpp: Fixed an #include. 2014-12-09 David Kilzer <ddkilzer@apple.com> Switch from using PLATFORM_NAME to SDK selectors in ANGLE, bmalloc, gtest, JavaScriptCore, WTF <http://webkit.org/b/139212> Reviewed by Joseph Pecoraro. * Configurations/Base.xcconfig: - Only set GCC_ENABLE_OBJC_GC, GCC_MODEL_TUNING and TOOLCHAINS on OS X. * Configurations/DebugRelease.xcconfig: - Only set MACOSX_DEPLOYMENT_TARGET and SDKROOT on OS X. 2014-11-07 Geoffrey Garen <ggaren@apple.com> bmalloc uses 8X more virtual memory than necessary https://bugs.webkit.org/show_bug.cgi?id=138495 Reviewed by Mark Lam. iOS has a per-process virtual memory cap around 1GB, so there's some value to not going totally ham with virtual memory. We currently use about 8X the necessary amount: - 2X to align our VM allocation - 4X to reserve small / medium / (2) large chunk VM ranges per superchunk We can cut that down: - Return the unaligned portion of our VM allocation (-2X) - Use all the chunks in a superchunk, instead of allocating one chunk per superchunk (-4X) * bmalloc/Algorithm.h: (bmalloc::roundUpToMultipleOf): Added a non-constant version of this function so we can call it with getpagesize() at runtime. * bmalloc/Chunk.h: * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::create): Deleted. Instead of each chunk allocating its own VM, VMHeap allocates the superchunk and all the chunks in it at a time. * bmalloc/VMAllocate.h: (bmalloc::vmValidate): (bmalloc::vmAllocate): ASSERT that mmap succeeds to make crashes clearer if it does not succeed. Allocate precisely, and give back the extra. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateSuperChunk): (bmalloc::VMHeap::allocateSmallChunk): Deleted. (bmalloc::VMHeap::allocateMediumChunk): Deleted. (bmalloc::VMHeap::allocateLargeChunk): Deleted. Use all the chunks in a superchunk, instead of just one. * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): * bmalloc/XLargeChunk.h: (bmalloc::XLargeChunk::create): Updated to match changes above. 2014-11-01 David Kilzer <ddkilzer@apple.com> JavaScriptCore is missing debug info for bmalloc because libbmalloc.a is stripped <https://webkit.org/b/138286> <rdar://problem/18847087> Reviewed by Dan Bernstein. * Configurations/bmalloc.xcconfig: Set STRIP_INSTALLED_PRODUCT to NO for the target that produces libbmalloc.a so that the debug symbols will be linked into JavaScriptCore and end up in its dSYM file. 2014-10-30 Dana Burkart <dburkart@apple.com> <rdar://problem/18821260> Prepare for the mysterious future Reviewed by Lucas Forschler. * Configurations/Base.xcconfig: * Configurations/DebugRelease.xcconfig: 2014-09-24 Geoffrey Garen <ggaren@apple.com> bmalloc: cleaned up fast path vs slow path https://bugs.webkit.org/show_bug.cgi?id=137081 Reviewed by Sam Weinig. Might be a 1% speedup on MallocBench. Also cleans up the code a bit. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Merged the small and medium range caches, just like the small and medium allocators. Ranges are abstract objects that don't really care whether they hold small or medium objects, so they don't need to be segregated. (bmalloc::Allocator::scavenge): Ditto. (bmalloc::Allocator::allocateBumpRangeSlowCase): (bmalloc::Allocator::allocateBumpRange): Same thing here, except that we do care a tiny bit, because we need to specify small vs medium when allocating new ranges from the heap, to ensure that the heap allocates from the right segment of VM. (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): NO_INLINE because this was clouding up the fast path. Large allocation performance is dominated by allocation logic and initialization, so inlining it doesn't help. (bmalloc::Allocator::allocateSlowCase): Slow path got a bit cleaner since it doesn't need to distinguish small vs medium objects. (bmalloc::Allocator::allocateSmallBumpRange): Deleted. (bmalloc::Allocator::allocateMediumBumpRange): Deleted. * bmalloc/Allocator.h: * bmalloc/BumpRange.h: * bmalloc/Cache.cpp: (bmalloc::Cache::allocateSlowCase): Deleted. (bmalloc::Cache::deallocateSlowCase): Deleted. * bmalloc/Cache.h: (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): (bmalloc::Cache::allocateFastCase): Deleted. (bmalloc::Cache::deallocateFastCase): Deleted. Removed the Cache slow paths. The downside to this change is that the fast path branches to two distinct failure cases instead of one. The upside is that the slow path doesn't need to re-read the segment register, which is not as cheap as a normal register, and it doesn't need to do an extra level of function call. Seems to be worth it. * bmalloc/Deallocator.h: * bmalloc/Heap.cpp: (bmalloc::Heap::refillSmallBumpRangeCache): (bmalloc::Heap::refillMediumBumpRangeCache): * bmalloc/Heap.h: Updated for interface changes. * bmalloc/Sizes.h: The most ranges a cache will hold is the number of small lines in a page / 2, since any other free lines will coalesce with their neighbors. 2014-09-23 Geoffrey Garen <ggaren@apple.com> Rolled out r173346. bmalloc should honor the FastMalloc statistics API https://bugs.webkit.org/show_bug.cgi?id=136592 This didn't really work. Because we allow ranges with and without physical pages to merge, and we allow double-committing and double-decommitting, we can't rely on commit actions to track memory footprint. * bmalloc/Heap.cpp: (bmalloc::Heap::size): Deleted. (bmalloc::Heap::capacity): Deleted. * bmalloc/Heap.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): (bmalloc::VMHeap::size): Deleted. (bmalloc::VMHeap::capacity): Deleted. * bmalloc/bmalloc.h: (bmalloc::api::heapSize): Deleted. (bmalloc::api::heapCapacity): Deleted. 2014-09-23 Geoffrey Garen <ggaren@apple.com> bmalloc: Allocation should be more precise https://bugs.webkit.org/show_bug.cgi?id=136993 Reviewed by Gavin Barraclough. 13% reduction in heap size on the MallocBench *_memory_warning benchmarks. This patch teaches the allocator to merge adjacent free lines into a single allocatable range. This allows us to shrink the size of an individual line without increasing fragmentation or the rate of allocator slow paths. We'll only take more slow paths when available memory is sparse, which is exactly when it's worth it. When available memory is dense, we'll take fewer slow paths. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Algorithm.h: (bmalloc::divideRoundingUp): * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Updated for interface changes. (bmalloc::Allocator::scavenge): Scavenge by object instead of by line. Now that we merge lines, it's not convenient to scavenge by line. (bmalloc::Allocator::allocateSmallBumpRange): (bmalloc::Allocator::allocateMediumBumpRange): Allocate whole ranges instead of individual lines. (bmalloc::Allocator::allocateSlowCase): (bmalloc::Allocator::allocateSmallLine): Deleted. (bmalloc::Allocator::allocateMediumLine): Deleted. (bmalloc::Allocator::allocateMedium): Deleted. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): Folded medium allocations into the standard fast path with small allocations. Since a BumpAllocator just allocates out of an arbitrary range, it doesn't need to distinguish between small and medium lines. * bmalloc/BumpAllocator.h: (bmalloc::BumpAllocator::size): (bmalloc::BumpAllocator::BumpAllocator): (bmalloc::BumpAllocator::init): (bmalloc::BumpAllocator::refill): (bmalloc::BumpAllocator::line): Deleted. No need to track line information anymore: the heap just gives us a pointer and a pre-computed number of objects, and we allocate them. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): Updated for interface changes. * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::initializeLineMetadata): Pre-compute precise metadata detailing where all objects will lie in memory. After we merge two lines, we might allocate an object that spans from one line to the next. This metadata details which bits of memory overlap in that way, and how they overlap. (bmalloc::Heap::refillSmallBumpRangeCache): (bmalloc::Heap::refillMediumBumpRangeCache): Scan a whole page at a time, and merge adjacent free lines into BumpRanges. (bmalloc::Heap::allocateSmallPage): (bmalloc::Heap::allocateMediumPage): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::deallocateMediumLine): Track pages rather than lines, since we scan for free memory a page at a time. (bmalloc::Heap::allocateSmallLineSlowCase): Deleted. (bmalloc::Heap::allocateMediumLineSlowCase): Deleted. Folded into the fast path. * bmalloc/Heap.h: (bmalloc::Heap::derefSmallLine): (bmalloc::Heap::derefMediumLine): (bmalloc::Heap::deallocateSmallLine): Deleted. (bmalloc::Heap::allocateSmallLine): Deleted. (bmalloc::Heap::deallocateMediumLine): Deleted. (bmalloc::Heap::allocateMediumLine): Deleted. Updated for interface changes. * bmalloc/Line.h: (bmalloc::Line<Traits>::ref): (bmalloc::Line<Traits>::deref): (bmalloc::Line<Traits>::concurrentRef): Deleted. We don't pass a derefCount anymore, since we only ever deref by 1 now. * bmalloc/MediumAllocator.h: (bmalloc::MediumAllocator::isNull): Deleted. (bmalloc::MediumAllocator::MediumAllocator): Deleted. (bmalloc::MediumAllocator::line): Deleted. (bmalloc::MediumAllocator::allocate): Deleted. (bmalloc::MediumAllocator::derefCount): Deleted. (bmalloc::MediumAllocator::refill): Deleted. (bmalloc::MediumAllocator::clear): Deleted. Deleted some code that's been dead for a while, since it doesn't build anymore with this patch. * bmalloc/Page.h: (bmalloc::Page::sizeClass): (bmalloc::Page::setSizeClass): (bmalloc::Page::smallSizeClass): Deleted. (bmalloc::Page::setSmallSizeClass): Deleted. Renamed setSmallSizeClass to sizeClass, since we use it for medium sizes too. * bmalloc/Sizes.h: (bmalloc::Sizes::sizeClass): (bmalloc::Sizes::objectSize): Shrank line sizes to save memory. (bmalloc::Sizes::smallSizeClassFor): Deleted. (bmalloc::Sizes::mediumSizeClassFor): Deleted. * bmalloc/bmalloc.h: (bmalloc::api::realloc): Now that we have precise objects sizes, realloc can be a bit more precise. It also has to be, since we can't guarantee that an object ends at the end of a line anymore. 2014-09-19 Daniel Bates <dabates@apple.com> Always assume internal SDK when building configuration Production https://bugs.webkit.org/show_bug.cgi?id=136925 <rdar://problem/18362399> Reviewed by Dan Bernstein. * Configurations/Base.xcconfig: 2014-09-16 Geoffrey Garen <ggaren@apple.com> bmalloc: moved line caches from the deallocator to the allocator https://bugs.webkit.org/show_bug.cgi?id=136868 Reviewed by Gavin Barraclough. I did this mostly as a simplification, to make it easier to change the allocation strategy. No throughput change on MallocBench. Saves about 50kB. Since the deallocator needs to lock the heap when freeing lines anyway, there isn't much benefit to giving the deallocator a local cache of deallocated lines. We still give the allocator a local cache of lines because that does reduce the frequency at which it needs to lock the heap in order to acquire more lines. * bmalloc/Allocator.cpp: (bmalloc::Allocator::scavenge): (bmalloc::Allocator::allocateSmallLine): (bmalloc::Allocator::allocateMediumLine): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSmallLine): Deleted. (bmalloc::Deallocator::allocateSmallLine): Deleted. (bmalloc::Deallocator::deallocateMediumLine): Deleted. (bmalloc::Deallocator::allocateMediumLine): Deleted. * bmalloc/Deallocator.h: * bmalloc/Sizes.h: * bmalloc/VMAllocate.h: Took the opportunity to make the line cache size exactly one page in size. That's about what we were shooting for anyway, and it may make it easier to switch to per-page allocation in future. 2014-09-15 Geoffrey Garen <ggaren@apple.com> bmalloc: allocate small and medium objects using the same bump pointer class https://bugs.webkit.org/show_bug.cgi?id=136843 Reviewed by Gavin Barraclough. 4% speedup on MallocBench. Now that medium-sized objects have dedicated per-size allocators, they don't need to use an arbitrary bump pointer allocator. This means that every allocator knows how many objects it will allocate from the start, and we don't need a post-processing step to adjust refcounts based on real allocation count. * bmalloc.xcodeproj/project.pbxproj: Renamed SmallAllocator to BumpAllocator since it's used for small and medium objects now. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Updated to use new interface. (bmalloc::Allocator::scavenge): To "retire" an allocator, we just need to make sure that we finish allocating all the objects in it. (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): (bmalloc::Allocator::retire): Deleted. (bmalloc::Allocator::processSmallAllocatorLog): Deleted. (bmalloc::Allocator::processMediumAllocatorLog): Deleted. * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): Removed abstractions and data used to post-process an allocator based on how many objects it allocated. * bmalloc/BumpAllocator.h: Copied from Source/bmalloc/bmalloc/SmallAllocator.h. (bmalloc::BumpAllocator::BumpAllocator): (bmalloc::BumpAllocator::init): (bmalloc::BumpAllocator::line): (bmalloc::BumpAllocator::validate): (bmalloc::BumpAllocator::allocate): (bmalloc::BumpAllocator::refill): (bmalloc::BumpAllocator::clear): Updated these functions to be agnostic about the kinds of lines they allocate into. In some cases, the line type must be provided as a template parameter by the caller. (bmalloc::SmallAllocator::SmallAllocator): Deleted. (bmalloc::SmallAllocator::line): Deleted. (bmalloc::SmallAllocator::allocate): Deleted. (bmalloc::SmallAllocator::objectCount): Deleted. (bmalloc::SmallAllocator::derefCount): Deleted. (bmalloc::SmallAllocator::refill): Deleted. (bmalloc::SmallAllocator::clear): Deleted. * bmalloc/ObjectType.h: (bmalloc::isMedium): * bmalloc/SmallAllocator.h: (bmalloc::SmallAllocator::isNull): Deleted. (bmalloc::SmallAllocator::canAllocate): Deleted. (bmalloc::SmallAllocator::SmallAllocator): Deleted. (bmalloc::SmallAllocator::line): Deleted. (bmalloc::SmallAllocator::allocate): Deleted. (bmalloc::SmallAllocator::objectCount): Deleted. (bmalloc::SmallAllocator::derefCount): Deleted. (bmalloc::SmallAllocator::refill): Deleted. (bmalloc::SmallAllocator::clear): Deleted. 2014-09-12 Geoffrey Garen <ggaren@apple.com> Fixed a goof in bmalloc Vector sizing https://bugs.webkit.org/show_bug.cgi?id=136795 Reviewed by Gavin Barraclough and Sam Weinig. We want our minimum vector to be page-sized since the OS will give us a page no matter what -- but we want that many bytes, and not enough bytes to store that many elements. * bmalloc/Vector.h: Math is hard. 2014-09-11 Geoffrey Garen <ggaren@apple.com> bmalloc should segregate medium-sized objects by line like it does for small-sized objects https://bugs.webkit.org/show_bug.cgi?id=136693 Reviewed by Gavin Barraclough. 4% reduction in heap size on the MallocBench *_memory_warning benchmarks. No throughput change. We keep an array of medium allocators, just like our array of small allocators. In future, we can simplify the allocation fast path by merging the small and medium allocator arrays. For now, this is the simplest change that gets the win. * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): (bmalloc::Allocator::scavenge): (bmalloc::Allocator::allocateMedium): * bmalloc/Allocator.h: * bmalloc/Sizes.h: (bmalloc::Sizes::mediumSizeClassFor): 2014-09-11 Geoffrey Garen <ggaren@apple.com> Reviewed by Sam Weinig. Renamed log => retire for clarity. * bmalloc/Allocator.cpp: (bmalloc::Allocator::scavenge): (bmalloc::Allocator::retire): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): (bmalloc::Allocator::log): Deleted. * bmalloc/Allocator.h: 2014-09-11 Geoffrey Garen <ggaren@apple.com> bmalloc: eager scavenge leaves behind a bogus allocator https://bugs.webkit.org/show_bug.cgi?id=136743 Reviewed by Sam Weinig. Be sure to clear the allocator after logging it in the eager scavenge case, so that we don't later try to allocate out of the lines that we have thrown away. We didn't need to do this previously because scavenge would only happen at thread exit time, after which no further allocation from the per-thread cache would take place. * bmalloc/Allocator.cpp: (bmalloc::Allocator::scavenge): * bmalloc/MediumAllocator.h: (bmalloc::MediumAllocator::clear): * bmalloc/SmallAllocator.h: (bmalloc::SmallAllocator::clear): 2014-09-05 Geoffrey Garen <ggaren@apple.com> bmalloc should honor the FastMalloc statistics API https://bugs.webkit.org/show_bug.cgi?id=136592 Reviewed by Gavin Barraclough. We do this by tracking "size" and "capacity" in the VM heap. The VM heap's "capacity" is all the VM we ever allocated. The VM heap's "size" the subset of VM currently held onto by the VM heap (and therefore not in use by the regular heap). Somewhat ironically, reducing the process's memory footprint, increases the size of the VM heap, since the VM heap holds the pages that are purely virtual and not physical. * bmalloc/Heap.cpp: (bmalloc::Heap::size): (bmalloc::Heap::capacity): * bmalloc/Heap.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::size): (bmalloc::VMHeap::capacity): (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/bmalloc.h: (bmalloc::api::heapSize): (bmalloc::api::heapCapacity): 2014-09-02 Geoffrey Garen <ggaren@apple.com> bmalloc crashes on the EWS bots (due to bad large object allocation) https://bugs.webkit.org/show_bug.cgi?id=136469 Reviewed by Andreas Kling. It's possible to convince bmalloc to perform a bad large object allocation, through these steps: (1) Insert object A into freelist F0. (2) Split, merge and split again A's neighbors such that object B is inserted into freelist F0, with boundary tag and size equal to object A, but pointer not completely equal to object A. Put object B at the head of F0. (3) Allocate some other object from F0, swapping its position in the freelist with object B, such that object A is now ahead of object B. --> Now, the next allocation for size A/B will allocate object A, which has a slightly wrong idea about where the object actually begins. Immediately, you'll corrupt a little memory, and over time, you'll also corrupt boundary tag metadata. The solution is to store the begin pointer in the boundary tag. Luckily, this doesn't make the tag any bigger, and it's not a noticeable slowdown on MallocBench. * bmalloc/Algorithm.h: (bmalloc::rightShift): * bmalloc/BeginTag.h: (bmalloc::BeginTag::isInFreeList): This is the bug fix. Make sure to validate the start pointer when popping off the free list. Through a very uncommon set of steps, it is possible to have an item in the free list that is valid by all accounts except for its start pointer. * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::compactBegin): (bmalloc::BoundaryTag::setRange): (bmalloc::BoundaryTag::setSize): Deleted. Record a compact version of the start pointer. We don't need the whole pointer -- just the offset, in largeAlignment increments, into the relevant boundary tag bucket. * bmalloc/BoundaryTagInlines.h: (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::splitLarge): * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): Provide the whole range instead of the size when establishing a boundary tag, as required by the new interface. * bmalloc/Sizes.h: 2014-08-14 Geoffrey Garen <ggaren@apple.com> Fixed a bmalloc crash seen on the EWS bot https://bugs.webkit.org/show_bug.cgi?id=135955 Reviewed by Andreas Kling. * bmalloc/Syscall.h: Some CG APIs vm_copy their input buffers. If the input buffer is a malloc region, that region will get marked Copy-On-Write by the kernel. Calls to madvise() for COW regions fail and return EINVAL on older OS X's. In 10.10, they still fail, but they do not return EINVAL. So, we can only ASSERT that our syscalls succeed starting with 10.10. 2014-08-14 Geoffrey Garen <ggaren@apple.com> Fixed the bmalloc build https://bugs.webkit.org/show_bug.cgi?id=135953 Reviewed by Andreas Kling. * bmalloc.xcodeproj/project.pbxproj: Marked a few headers as private. These headers are used, so they must be available outside the project. 2014-08-13 Daniel Bates <dabates@apple.com> Attempt to fix the build following <http://trac.webkit.org/changeset/172576> (https://bugs.webkit.org/show_bug.cgi?id=135895) Substitute PerThreadStorage<T>::initSharedKeyIfNeeded() for initSharedKeyIfNeeded() in implementation of PerThread<T>::getFastCase(). * bmalloc/PerThread.h: (bmalloc::PerThread<T>::getFastCase): 2014-08-13 Daniel Bates <dabates@apple.com> Make bmalloc::PerThread work without C++ thread local storage https://bugs.webkit.org/show_bug.cgi?id=135895 Reviewed by Geoffrey Garen. Implement support for building bmalloc without C++ thread local storage. * bmalloc/BPlatform.h: Remove macro define BPLATFORM_IOS_SIMULATOR. Added macro function BCOMPILER_SUPPORTS() and macro define BCOMPILER_SUPPORTS_CXX_THREAD_LOCAL that can be used to determine whether the compiler supports C++ thread local storage. * bmalloc/PerThread.h: (bmalloc::PerThreadStorage::get): Modified to call pthread_getspecific() when building without C++ thread local storage. (bmalloc::PerThreadStorage::initSharedKeyIfNeeded): Added. (bmalloc::PerThreadStorage::init): Moved logic to initialize shared Pthread key from here to PerThreadStorage::initSharedKeyIfNeeded(). (bmalloc::PerThread<T>::getFastCase): Modified to call PerThreadStorage::initSharedKeyIfNeeded() before querying PerThreadStorage::get() when building without C++ thread local storage so as to ensure that the shared key has been initialized. (_pthread_setspecific_direct): Deleted. (_pthread_getspecific_direct): Deleted. 2014-08-13 Daniel Bates <dabates@apple.com> [iOS] Make JavaScriptCore and bmalloc build with the public SDK https://bugs.webkit.org/show_bug.cgi?id=135848 Reviewed by Geoffrey Garen. * bmalloc/BPlatform.h: Added macro BPLATFORM_IOS_SIMULATOR, which evaluates to true when building for the iOS Simulator. * bmalloc/PerThread.h: Use pthread_machdep.h code path when building for iOS Simulator using the public SDK. (_pthread_setspecific_direct): Added; only defined when building for the iOS Simulator using the public SDK. (_pthread_getspecific_direct): Added; only defined when building for the iOS Simulator using the public SDK. 2014-08-12 Daniel Bates <dabates@apple.com> BPLATFORM(IOS) always evaluates to false https://bugs.webkit.org/show_bug.cgi?id=135843 Reviewed by Geoffrey Garen. Fix typo in definition of BPLATFORM() and include system header TargetConditionals.h (when building on an Apple platform) so that BPLATFORM(X) evaluates to true when building for platform X. In particular, so that BPLATFORM(IOS) evaluates to true when building for iOS. As a side effect of this change, the change made in <http://trac.webkit.org/changeset/167289> will be honored and iOS will assume a VM page size of 16kB (again) instead of 4kB. * bmalloc/BPlatform.h: 2014-08-11 Andy Estes <aestes@apple.com> [iOS] Get rid of iOS.xcconfig https://bugs.webkit.org/show_bug.cgi?id=135809 Reviewed by Joseph Pecoraro. All iOS.xcconfig did was include AspenFamily.xcconfig, so there's no need for the indirection. * Configurations/Base.xcconfig: * Configurations/iOS.xcconfig: Removed. * bmalloc.xcodeproj/project.pbxproj: 2014-05-01 Dan Bernstein <mitz@apple.com> Fixed production builds for the iOS Simulator. <rdar://problem/16792221> * Configurations/bmalloc.xcconfig: Include INSTALL_PATH_PREFIX in PRIVATE_HEADERS_FOLDER_PATH when installing. 2014-04-20 Geoffrey Garen <ggaren@apple.com> bmalloc: Segregate pages by objects size https://bugs.webkit.org/show_bug.cgi?id=131909 Reviewed by Andreas Kling. 2% reduction in memory-at-end on the Membuster memory_warning benchmarks. * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::smallAllocatorFor): Use the new shared helper function for size class calculation. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): * bmalloc/Deallocator.h: Keep a cache for every size class, since the cache can't be shared anymore. * bmalloc/Heap.cpp: (bmalloc::Heap::allocateSmallLineSlowCase): * bmalloc/Heap.h: (bmalloc::Heap::deallocateSmallLine): Ditto. (bmalloc::Heap::allocateSmallLine): Check size class in addition to page refcount when allocating a line because we might have deallocated the page and the recycled it for another size class. (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Line.h: (bmalloc::Line::refCount): * bmalloc/Page.h: (bmalloc::Page::refCount): (bmalloc::Page::smallSizeClass): (bmalloc::Page::setSmallSizeClass): (bmalloc::Page<Traits>::refCount): Deleted. * bmalloc/Sizes.h: (bmalloc::Sizes::smallSizeClassFor): New shared API for computing an index into an array from a size. 2014-04-19 Geoffrey Garen <ggaren@apple.com> bmalloc: Improved alignment in LargeChunk https://bugs.webkit.org/show_bug.cgi?id=131895 Reviewed by Andreas Kling. * bmalloc/Chunk.h: * bmalloc/LargeChunk.h: Align to vmPageSize just like Chunk does. Technically, the previous alignment was harmless, but I would prefer, dear reader, not to have to explain the interlocking set of circumstances that made it so. 2014-04-19 Geoffrey Garen <ggaren@apple.com> Rolled out r167502 because it caused a crash on the facebook benchmark. Unreviewed. bmalloc: Added an XSmall line size https://bugs.webkit.org/show_bug.cgi?id=131851 Reviewed by Sam Weinig. 2014-04-19 Geoffrey Garen <ggaren@apple.com> bmalloc: Mutex should be harder to use wrong https://bugs.webkit.org/show_bug.cgi?id=131879 Reviewed by Andreas Kling. Mutex now has a proper constructor, so you can't deadlock by forgetting to initialize it. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::processXSmallAllocatorLog): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): Global replace Mutex => StaticMutex, since the Heap mutex is a static. * bmalloc/AsyncTask.h: (bmalloc::Function>::AsyncTask): Use Mutex, since we're not static. No need for explicit initialization anymore. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::deallocateXSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::allocateXSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: * bmalloc/Heap.cpp: (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeXSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateXSmallLineSlowCase): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: (bmalloc::Heap::deallocateXSmallLine): (bmalloc::Heap::allocateXSmallLine): (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Line.h: (bmalloc::Line<Traits>::deref): * bmalloc/Mutex.cpp: Removed. * bmalloc/Mutex.h: (bmalloc::Mutex::Mutex): (bmalloc::Mutex::init): Deleted. (bmalloc::Mutex::try_lock): Deleted. (bmalloc::Mutex::lock): Deleted. (bmalloc::Mutex::unlock): Deleted. * bmalloc/Page.h: (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/StaticMutex.cpp: Added. (bmalloc::StaticMutex::lockSlowCase): * bmalloc/StaticMutex.h: Added. (bmalloc::StaticMutex::init): (bmalloc::StaticMutex::try_lock): (bmalloc::StaticMutex::lock): (bmalloc::StaticMutex::unlock): * bmalloc/VMHeap.h: (bmalloc::VMHeap::deallocateXSmallPage): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/bmalloc.h: (bmalloc::api::scavenge): Global replace Mutex => StaticMutex, since the Heap mutex is a static. 2014-04-18 Geoffrey Garen <ggaren@apple.com> bmalloc: AsyncTask should use Mutex instead of std::mutex https://bugs.webkit.org/show_bug.cgi?id=131865 Reviewed by Gavin Barraclough. std::mutex is so slow that it makes parallelizing simple tasks through AsyncTask a net regression. Mutex fixes this. * bmalloc/AsyncTask.h: (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::entryPoint): * bmalloc/Mutex.h: (bmalloc::Mutex::init): 2014-04-18 Geoffrey Garen <ggaren@apple.com> bmalloc: Added an XSmall line size https://bugs.webkit.org/show_bug.cgi?id=131851 Reviewed by Sam Weinig. Reduces malloc footprint on Membuster recordings by 10%. This is a throughput regression, but we're still way ahead of TCMalloc. I have some ideas for how to recover the regression -- but I wanted to get this win in first. Full set of benchmark results: bmalloc> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks --measure-heap nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/ nopatch patch Δ Peak Memory: reddit_memory_warning 7,896kB 7,532kB ^ 1.05x smaller flickr_memory_warning 12,968kB 12,324kB ^ 1.05x smaller theverge_memory_warning 16,672kB 15,200kB ^ 1.1x smaller <geometric mean> 11,952kB 11,216kB ^ 1.07x smaller <arithmetic mean> 12,512kB 11,685kB ^ 1.07x smaller <harmonic mean> 11,375kB 10,726kB ^ 1.06x smaller Memory at End: reddit_memory_warning 7,320kB 6,856kB ^ 1.07x smaller flickr_memory_warning 10,848kB 9,692kB ^ 1.12x smaller theverge_memory_warning 16,380kB 14,872kB ^ 1.1x smaller <geometric mean> 10,916kB 9,961kB ^ 1.1x smaller <arithmetic mean> 11,516kB 10,473kB ^ 1.1x smaller <harmonic mean> 10,350kB 9,485kB ^ 1.09x smaller MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/ nopatch patch Δ Execution Time: churn 127ms 151ms ! 1.19x slower list_allocate 130ms 164ms ! 1.26x slower tree_allocate 109ms 127ms ! 1.17x slower tree_churn 115ms 120ms ! 1.04x slower facebook 240ms 259ms ! 1.08x slower fragment 91ms 131ms ! 1.44x slower fragment_iterate 105ms 106ms ! 1.01x slower message_one 260ms 259ms ^ 1.0x faster message_many 149ms 154ms ! 1.03x slower medium 194ms 248ms ! 1.28x slower big 157ms 160ms ! 1.02x slower <geometric mean> 144ms 163ms ! 1.13x slower <arithmetic mean> 152ms 171ms ! 1.12x slower <harmonic mean> 137ms 156ms ! 1.14x slower MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks nopatch:~/scratch/Build-nopatch/Release/ patch:~/webkit/WebKitBuild/Release/ nopatch patch Δ Execution Time: churn 126ms 148ms ! 1.17x slower churn --parallel 62ms 76ms ! 1.23x slower list_allocate 130ms 164ms ! 1.26x slower list_allocate --parallel 120ms 175ms ! 1.46x slower tree_allocate 111ms 127ms ! 1.14x slower tree_allocate --parallel 95ms 135ms ! 1.42x slower tree_churn 115ms 124ms ! 1.08x slower tree_churn --parallel 107ms 126ms ! 1.18x slower facebook 240ms 276ms ! 1.15x slower facebook --parallel 802ms 1,088ms ! 1.36x slower fragment 92ms 130ms ! 1.41x slower fragment --parallel 66ms 124ms ! 1.88x slower fragment_iterate 109ms 127ms ! 1.17x slower fragment_iterate --parallel 55ms 64ms ! 1.16x slower message_one 260ms 260ms message_many 170ms 238ms ! 1.4x slower medium 185ms 250ms ! 1.35x slower medium --parallel 210ms 334ms ! 1.59x slower big 150ms 169ms ! 1.13x slower big --parallel 138ms 144ms ! 1.04x slower <geometric mean> 135ms 170ms ! 1.26x slower <arithmetic mean> 167ms 214ms ! 1.28x slower <harmonic mean> 117ms 148ms ! 1.26x slower MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks TC:~/scratch/Build-TCMalloc/Release/ patch:~/webkit/WebKitBuild/Release/ TC patch Δ Peak Memory: reddit_memory_warning 13,836kB 13,436kB ^ 1.03x smaller flickr_memory_warning 24,868kB 25,188kB ! 1.01x bigger theverge_memory_warning 24,504kB 26,636kB ! 1.09x bigger <geometric mean> 20,353kB 20,812kB ! 1.02x bigger <arithmetic mean> 21,069kB 21,753kB ! 1.03x bigger <harmonic mean> 19,570kB 19,780kB ! 1.01x bigger Memory at End: reddit_memory_warning 8,656kB 10,016kB ! 1.16x bigger flickr_memory_warning 11,844kB 13,784kB ! 1.16x bigger theverge_memory_warning 18,516kB 22,748kB ! 1.23x bigger <geometric mean> 12,382kB 14,644kB ! 1.18x bigger <arithmetic mean> 13,005kB 15,516kB ! 1.19x bigger <harmonic mean> 11,813kB 13,867kB ! 1.17x bigger MallocBench> ~/webkit/PerformanceTests/MallocBench/run-malloc-benchmarks TC:~/scratch/Build-TCMalloc/Release/ patch:~/webkit/WebKitBuild/Release/ TC patch Δ Execution Time: churn 416ms 148ms ^ 2.81x faster list_allocate 463ms 164ms ^ 2.82x faster tree_allocate 292ms 127ms ^ 2.3x faster tree_churn 157ms 120ms ^ 1.31x faster facebook 327ms 276ms ^ 1.18x faster fragment 335ms 129ms ^ 2.6x faster fragment_iterate 344ms 108ms ^ 3.19x faster message_one 386ms 258ms ^ 1.5x faster message_many 410ms 154ms ^ 2.66x faster medium 391ms 245ms ^ 1.6x faster big 261ms 167ms ^ 1.56x faster <geometric mean> 332ms 164ms ^ 2.02x faster <arithmetic mean> 344ms 172ms ^ 1.99x faster <harmonic mean> 317ms 157ms ^ 2.02x faster * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::Allocator): Don't assume that each allocator's index corresponds with its size. Instead, use the size selection function explicitly. Now that we have XSmall, some small allocator entries are unused. (bmalloc::Allocator::scavenge): (bmalloc::Allocator::log): (bmalloc::Allocator::processXSmallAllocatorLog): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: (bmalloc::Allocator::xSmallAllocatorFor): (bmalloc::Allocator::allocateFastCase): * bmalloc/Chunk.h: * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::scavenge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateXSmallLine): (bmalloc::Deallocator::allocateXSmallLine): * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): * bmalloc/Heap.cpp: (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeXSmallPages): (bmalloc::Heap::allocateXSmallLineSlowCase): * bmalloc/Heap.h: (bmalloc::Heap::deallocateXSmallLine): (bmalloc::Heap::allocateXSmallLine): * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: * bmalloc/MediumAllocator.h: (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::refill): * bmalloc/ObjectType.cpp: (bmalloc::objectType): * bmalloc/ObjectType.h: (bmalloc::isXSmall): (bmalloc::isSmall): (bmalloc::isMedium): (bmalloc::isLarge): (bmalloc::isSmallOrMedium): Deleted. * bmalloc/SegregatedFreeList.h: I boiler-plate copied existing code for handling small objects. There's probably a reasonable way to share this code in the future -- I'll look into that once it's stopped changing. * bmalloc/Sizes.h: Tweaked size classes to make Membuster happy. This is the main reason things got slower. * bmalloc/SmallAllocator.h: (bmalloc::SmallAllocator::allocate): * bmalloc/SmallTraits.h: * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::allocateXSmallChunk): * bmalloc/VMHeap.h: (bmalloc::VMHeap::allocateXSmallPage): (bmalloc::VMHeap::deallocateXSmallPage): * bmalloc/XSmallAllocator.h: Added. (bmalloc::XSmallAllocator::isNull): (bmalloc::XSmallAllocator::canAllocate): (bmalloc::XSmallAllocator::XSmallAllocator): (bmalloc::XSmallAllocator::line): (bmalloc::XSmallAllocator::allocate): (bmalloc::XSmallAllocator::objectCount): (bmalloc::XSmallAllocator::derefCount): (bmalloc::XSmallAllocator::refill): * bmalloc/XSmallChunk.h: Added. * bmalloc/XSmallLine.h: Added. * bmalloc/XSmallPage.h: Added. * bmalloc/XSmallTraits.h: Added. * bmalloc/bmalloc.h: (bmalloc::api::realloc): Boiler-plate copy, as above. 2014-04-14 Geoffrey Garen <ggaren@apple.com> MallocBench should scavenge explicitly instead of waiting https://bugs.webkit.org/show_bug.cgi?id=131661 Reviewed by Andreas Kling. Added explicit scavenge support to bmalloc. This isn't a memory win, since bmalloc's per-thread cache is so small. But it makes testing simpler. * bmalloc/Allocator.cpp: (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::scavenge): * bmalloc/Allocator.h: * bmalloc/Cache.cpp: (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::scavenge): * bmalloc/Cache.h: * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::scavenge): * bmalloc/Deallocator.h: Factored existing scavenging code into helper functions, for reuse. * bmalloc/Heap.cpp: (bmalloc::sleep): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): * bmalloc/Heap.h: Made scavenge sleep duration a parameter. Forced scavenging -- in response to a benchmark or a low memory warning -- wants to complete as soon as possible, so its sleep duration is 0. * bmalloc/bmalloc.h: (bmalloc::api::scavenge): * bmalloc/mbmalloc.cpp: Exported the scavenge API for MallocBench's use. 2014-04-14 Geoffrey Garen <ggaren@apple.com> Use 4kB pages on Mac https://bugs.webkit.org/show_bug.cgi?id=131658 Reviewed by Sam Weinig. This reduces memory use a lot on Membuster: base patch Δ Execution Time: reddit_memory_warning 18ms 17ms ^ 1.06x faster flickr_memory_warning 34ms 36ms ! 1.06x slower theverge_memory_warning 39ms 41ms ! 1.05x slower <geometric mean> 29ms 29ms ! 1.02x slower <arithmetic mean> 30ms 31ms ! 1.03x slower <harmonic mean> 27ms 27ms ^ 1.0x faster Peak Memory: reddit_memory_warning 16,412kB 16,436kB ! 1.0x bigger flickr_memory_warning 30,120kB 30,184kB ! 1.0x bigger theverge_memory_warning 33,408kB 33,420kB ! 1.0x bigger <geometric mean> 25,466kB 25,499kB ! 1.0x bigger <arithmetic mean> 26,647kB 26,680kB ! 1.0x bigger <harmonic mean> 24,181kB 24,214kB ! 1.0x bigger Memory at End: reddit_memory_warning 2,404kB 1,920kB ^ 1.25x smaller flickr_memory_warning 3,764kB 3,072kB ^ 1.23x smaller theverge_memory_warning 3,648kB 3,132kB ^ 1.16x smaller <geometric mean> 3,208kB 2,644kB ^ 1.21x smaller <arithmetic mean> 3,272kB 2,708kB ^ 1.21x smaller <harmonic mean> 3,139kB 2,574kB ^ 1.22x smaller * bmalloc.xcodeproj/project.pbxproj: * bmalloc/BPlatform.h: Added. * bmalloc/VMAllocate.h: Only use 16kB pages on iOS because the page size is 4kB on Mac. 2014-04-14 Alexey Proskuryakov <ap@apple.com> Fixed svn:ignore on bmalloc.xcodeproj, it had erroneous leading spaces. * bmalloc.xcodeproj: Modified property svn:ignore. 2014-04-13 Geoffrey Garen <ggaren@apple.com> Fixed some mbmalloc exports https://bugs.webkit.org/show_bug.cgi?id=131599 Reviewed by Ryosuke Niwa. * bmalloc.xcodeproj/project.pbxproj: Made some headers a private part of the project, so we can call them from API. * bmalloc/mbmalloc.cpp: Marked the mbmalloc functions with default visibility, so they show up as exported in the .dylib. 2014-04-09 Geoffrey Garen <ggaren@apple.com> Put bmalloc headers in the right place https://bugs.webkit.org/show_bug.cgi?id=131464 Reviewed by Mark Rowe. * Configurations/bmalloc.xcconfig: Set PRIVATE_HEADERS_FOLDER_PATH to specify that we don't just want to dump all of our generically-named headers into /usr/local/include. 2014-04-08 Geoffrey Garen <ggaren@apple.com> Made bmalloc more #include friendly https://bugs.webkit.org/show_bug.cgi?id=131386 Reviewed by Andreas Kling. Marked a bunch of headers private so they can be used from client code that #includes bmalloc.h. Renamed ASSERT macros to BASSERT. This matches their header, which already had to be renamed, and fixes conflicts with WTF's ASSERT macros. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::allocateSlowCase): * bmalloc/AsyncTask.h: (bmalloc::Function>::runSlowCase): * bmalloc/BAssert.h: * bmalloc/BoundaryTag.h: (bmalloc::BoundaryTag::setSize): * bmalloc/BoundaryTagInlines.h: (bmalloc::validate): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Chunk.h: * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): * bmalloc/FixedVector.h: (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: (bmalloc::Heap::allocateLarge): * bmalloc/LargeChunk.h: (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: (bmalloc::MediumAllocator::allocate): * bmalloc/ObjectType.h: (bmalloc::isSmall): * bmalloc/Page.h: (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): * bmalloc/PerThread.h: (bmalloc::PerThread<T>::getSlowCase): * bmalloc/SegregatedFreeList.cpp: (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): * bmalloc/SmallAllocator.h: (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::refill): * bmalloc/Syscall.h: * bmalloc/VMAllocate.h: (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocatePhysicalPagesSloppy): * bmalloc/Vector.h: (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): * bmalloc/XLargeChunk.h: (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): 2014-04-08 Geoffrey Garen <ggaren@apple.com> Removed an unused file. Unreviewed. * bmalloc/AsyncTask.cpp: Removed. 2014-04-07 Geoffrey Garen <ggaren@apple.com> Build bmalloc on Mac https://bugs.webkit.org/show_bug.cgi?id=131333 Reviewed by Mark Rowe. * Makefile: Added. For make clients. These files are required for building any project in WebKit. I copied them from WTF: * Configurations: Added. * Configurations/Base.xcconfig: Added. * Configurations/DebugRelease.xcconfig: Added. * Configurations/bmalloc.xcconfig: Added. * Configurations/iOS.xcconfig: Added. * Configurations/mbmalloc.xcconfig: Added. * bmalloc.xcodeproj/project.pbxproj: I removed per-project-file stuff from here because everything is in .xcconfig files now. I had to fix a bunch of minor warnings, since they're enabled in our .xcconfig files: * bmalloc/AsyncTask.h: (bmalloc::Function>::AsyncTask): * bmalloc/BAssert.h: * bmalloc/BoundaryTagInlines.h: (bmalloc::validate): * bmalloc/Heap.cpp: (bmalloc::Heap::Heap): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Mutex.h: (bmalloc::Mutex::Mutex): Deleted. * bmalloc/VMAllocate.h: (bmalloc::vmValidate): * bmalloc/mbmalloc.cpp: 2014-04-07 Geoffrey Garen <ggaren@apple.com> bmalloc: Fixed a leak in the per-thread cache https://bugs.webkit.org/show_bug.cgi?id=131330 Reviewed by Andreas Kling. Remember to deallocate our line caches upon thread exit. * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::~Deallocator): 2014-04-07 Geoffrey Garen <ggaren@apple.com> bmalloc: rolled out the tryLock experiment https://bugs.webkit.org/show_bug.cgi?id=131328 Reviewed by Andreas Kling. It wasn't a speedup. * bmalloc.xcodeproj/project.pbxproj: * bmalloc/Allocator.cpp: (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): * bmalloc/Deallocator.cpp: (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): * bmalloc/Deallocator.h: (bmalloc::Deallocator::deallocateFastCase): * bmalloc/Heap.h: (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::deallocateMediumLine): * bmalloc/Line.h: (bmalloc::Line<Traits>::deref): * bmalloc/Page.h: (bmalloc::Page<Traits>::deref): 2014-04-07 Geoffrey Garen <ggaren@apple.com> bmalloc https://bugs.webkit.org/show_bug.cgi?id=131170 Reviewed by Andreas Kling. Initial commit. * bmalloc: Added. * bmalloc.xcodeproj: Added. * bmalloc.xcodeproj/project.pbxproj: Added. * bmalloc/Algorithm.h: Added. (bmalloc::max): (bmalloc::min): (bmalloc::mask): (bmalloc::test): (bmalloc::roundUpToMultipleOf): (bmalloc::roundDownToMultipleOf): (bmalloc::sizeOf): (bmalloc::bitCount): (bmalloc::isPowerOfTwo): * bmalloc/Allocator.cpp: Added. (bmalloc::Allocator::Allocator): (bmalloc::Allocator::~Allocator): (bmalloc::Allocator::log): (bmalloc::Allocator::processSmallAllocatorLog): (bmalloc::Allocator::processMediumAllocatorLog): (bmalloc::Allocator::allocateLarge): (bmalloc::Allocator::allocateXLarge): (bmalloc::Allocator::allocateMedium): (bmalloc::Allocator::allocateSlowCase): * bmalloc/Allocator.h: Added. (bmalloc::Allocator::smallAllocatorFor): (bmalloc::Allocator::allocateFastCase): (bmalloc::Allocator::allocate): * bmalloc/AsyncTask.cpp: Added. (bmalloc::AsyncTask<Function>::runSlowCase): (bmalloc::AsyncTask<Function>::pthreadEntryPoint): (bmalloc::AsyncTask<Function>::entryPoint): * bmalloc/AsyncTask.h: Added. (bmalloc::Function>::AsyncTask): (bmalloc::Function>::join): (bmalloc::Function>::run): (bmalloc::Function>::runSlowCase): (bmalloc::Function>::pthreadEntryPoint): (bmalloc::Function>::entryPoint): * bmalloc/BAssert.h: Added. * bmalloc/BeginTag.h: Added. (bmalloc::BeginTag::isInFreeList): * bmalloc/BoundaryTag.h: Added. (bmalloc::BoundaryTag::isXLarge): (bmalloc::BoundaryTag::setXLarge): (bmalloc::BoundaryTag::isFree): (bmalloc::BoundaryTag::setFree): (bmalloc::BoundaryTag::isEnd): (bmalloc::BoundaryTag::setEnd): (bmalloc::BoundaryTag::hasPhysicalPages): (bmalloc::BoundaryTag::setHasPhysicalPages): (bmalloc::BoundaryTag::isNull): (bmalloc::BoundaryTag::clear): (bmalloc::BoundaryTag::size): (bmalloc::BoundaryTag::setSize): (bmalloc::BoundaryTag::prev): (bmalloc::BoundaryTag::next): * bmalloc/BoundaryTagInlines.h: Added. (bmalloc::validate): (bmalloc::validatePrev): (bmalloc::validateNext): (bmalloc::BoundaryTag::init): (bmalloc::BoundaryTag::mergeLargeLeft): (bmalloc::BoundaryTag::mergeLargeRight): (bmalloc::BoundaryTag::mergeLarge): (bmalloc::BoundaryTag::deallocate): (bmalloc::BoundaryTag::splitLarge): (bmalloc::BoundaryTag::allocate): * bmalloc/Cache.cpp: Added. (bmalloc::Cache::operator new): (bmalloc::Cache::operator delete): (bmalloc::Cache::Cache): (bmalloc::Cache::allocateSlowCase): (bmalloc::Cache::allocateSlowCaseNullCache): (bmalloc::Cache::deallocateSlowCase): (bmalloc::Cache::deallocateSlowCaseNullCache): * bmalloc/Cache.h: Added. (bmalloc::Cache::allocator): (bmalloc::Cache::deallocator): (bmalloc::Cache::allocateFastCase): (bmalloc::Cache::deallocateFastCase): (bmalloc::Cache::allocate): (bmalloc::Cache::deallocate): * bmalloc/Chunk.h: Added. (bmalloc::Chunk::begin): (bmalloc::Chunk::end): (bmalloc::Chunk::lines): (bmalloc::Chunk::pages): * bmalloc/Deallocator.cpp: Added. (bmalloc::Deallocator::Deallocator): (bmalloc::Deallocator::~Deallocator): (bmalloc::Deallocator::deallocateLarge): (bmalloc::Deallocator::deallocateXLarge): (bmalloc::Deallocator::processObjectLog): (bmalloc::Deallocator::deallocateSlowCase): (bmalloc::Deallocator::deallocateSmallLine): (bmalloc::Deallocator::allocateSmallLine): (bmalloc::Deallocator::deallocateMediumLine): (bmalloc::Deallocator::allocateMediumLine): * bmalloc/Deallocator.h: Added. (bmalloc::Deallocator::deallocateFastCase): (bmalloc::Deallocator::deallocate): * bmalloc/EndTag.h: Added. (bmalloc::EndTag::operator=): * bmalloc/FixedVector.h: Added. (bmalloc::FixedVector::begin): (bmalloc::FixedVector::end): (bmalloc::FixedVector::size): (bmalloc::FixedVector::capacity): (bmalloc::FixedVector::clear): (bmalloc::FixedVector::isEmpty): (bmalloc::Capacity>::FixedVector): (bmalloc::Capacity>::operator): (bmalloc::Capacity>::push): (bmalloc::Capacity>::pop): (bmalloc::Capacity>::shrink): * bmalloc/Heap.cpp: Added. (bmalloc::sleep): (bmalloc::Heap::Heap): (bmalloc::Heap::concurrentScavenge): (bmalloc::Heap::scavengeSmallPages): (bmalloc::Heap::scavengeMediumPages): (bmalloc::Heap::scavengeLargeRanges): (bmalloc::Heap::allocateSmallLineSlowCase): (bmalloc::Heap::allocateMediumLineSlowCase): (bmalloc::Heap::allocateXLarge): (bmalloc::Heap::deallocateXLarge): (bmalloc::Heap::allocateLarge): (bmalloc::Heap::deallocateLarge): * bmalloc/Heap.h: Added. (bmalloc::Heap::deallocateSmallLine): (bmalloc::Heap::allocateSmallLine): (bmalloc::Heap::deallocateMediumLine): (bmalloc::Heap::allocateMediumLine): * bmalloc/Inline.h: Added. * bmalloc/LargeChunk.h: Added. (bmalloc::LargeChunk::begin): (bmalloc::LargeChunk::end): (bmalloc::LargeChunk::create): (bmalloc::LargeChunk::get): (bmalloc::LargeChunk::beginTag): (bmalloc::LargeChunk::endTag): * bmalloc/Line.h: Added. (bmalloc::Line<Traits>::begin): (bmalloc::Line<Traits>::end): (bmalloc::Line<Traits>::concurrentRef): (bmalloc::Line<Traits>::deref): * bmalloc/MediumAllocator.h: Added. (bmalloc::MediumAllocator::isNull): (bmalloc::MediumAllocator::MediumAllocator): (bmalloc::MediumAllocator::line): (bmalloc::MediumAllocator::allocate): (bmalloc::MediumAllocator::derefCount): (bmalloc::MediumAllocator::refill): * bmalloc/MediumChunk.h: Added. * bmalloc/MediumLine.h: Added. * bmalloc/MediumPage.h: Added. * bmalloc/MediumTraits.h: Added. * bmalloc/Mutex.cpp: Added. (bmalloc::Mutex::lockSlowCase): * bmalloc/Mutex.h: Added. (bmalloc::Mutex::Mutex): (bmalloc::Mutex::try_lock): (bmalloc::Mutex::lock): (bmalloc::Mutex::unlock): * bmalloc/ObjectType.cpp: Added. (bmalloc::objectType): * bmalloc/ObjectType.h: Added. (bmalloc::isSmallOrMedium): (bmalloc::isSmall): * bmalloc/Page.h: Added. (bmalloc::Page<Traits>::ref): (bmalloc::Page<Traits>::deref): (bmalloc::Page<Traits>::refCount): * bmalloc/PerProcess.h: Added. (bmalloc::PerProcess::mutex): (bmalloc::PerProcess<T>::getFastCase): (bmalloc::PerProcess<T>::get): (bmalloc::PerProcess<T>::getSlowCase): * bmalloc/PerThread.h: Added. (bmalloc::PerThreadStorage<Cache>::get): (bmalloc::PerThreadStorage<Cache>::init): (bmalloc::PerThreadStorage::get): (bmalloc::PerThreadStorage::init): (bmalloc::PerThread<T>::getFastCase): (bmalloc::PerThread<T>::get): (bmalloc::PerThread<T>::destructor): (bmalloc::PerThread<T>::getSlowCase): * bmalloc/Range.h: Added. (bmalloc::Range::Range): (bmalloc::Range::begin): (bmalloc::Range::end): (bmalloc::Range::size): (bmalloc::Range::operator!): (bmalloc::Range::operator<): * bmalloc/SegregatedFreeList.cpp: Added. (bmalloc::SegregatedFreeList::SegregatedFreeList): (bmalloc::SegregatedFreeList::insert): (bmalloc::SegregatedFreeList::takeGreedy): (bmalloc::SegregatedFreeList::take): * bmalloc/SegregatedFreeList.h: Added. * bmalloc/Sizes.h: Added. * bmalloc/SmallAllocator.h: Added. (bmalloc::SmallAllocator::isNull): (bmalloc::SmallAllocator::canAllocate): (bmalloc::SmallAllocator::SmallAllocator): (bmalloc::SmallAllocator::line): (bmalloc::SmallAllocator::allocate): (bmalloc::SmallAllocator::objectCount): (bmalloc::SmallAllocator::derefCount): (bmalloc::SmallAllocator::refill): * bmalloc/SmallChunk.h: Added. * bmalloc/SmallLine.h: Added. * bmalloc/SmallPage.h: Added. * bmalloc/SmallTraits.h: Added. * bmalloc/Syscall.h: Added. * bmalloc/VMAllocate.h: Added. (bmalloc::vmSize): (bmalloc::vmValidate): (bmalloc::vmAllocate): (bmalloc::vmDeallocate): (bmalloc::vmDeallocatePhysicalPages): (bmalloc::vmAllocatePhysicalPages): (bmalloc::vmDeallocatePhysicalPagesSloppy): (bmalloc::vmAllocatePhysicalPagesSloppy): * bmalloc/VMHeap.cpp: Added. (bmalloc::VMHeap::VMHeap): (bmalloc::VMHeap::allocateSmallChunk): (bmalloc::VMHeap::allocateMediumChunk): (bmalloc::VMHeap::allocateLargeChunk): * bmalloc/VMHeap.h: Added. (bmalloc::VMHeap::allocateSmallPage): (bmalloc::VMHeap::allocateMediumPage): (bmalloc::VMHeap::allocateLargeRange): (bmalloc::VMHeap::deallocateSmallPage): (bmalloc::VMHeap::deallocateMediumPage): (bmalloc::VMHeap::deallocateLargeRange): * bmalloc/Vector.h: Added. (bmalloc::Vector::begin): (bmalloc::Vector::end): (bmalloc::Vector::size): (bmalloc::Vector::capacity): (bmalloc::Vector::last): (bmalloc::Vector::pop): (bmalloc::Vector<T>::Vector): (bmalloc::Vector<T>::~Vector): (bmalloc::Vector<T>::operator): (bmalloc::Vector<T>::push): (bmalloc::Vector<T>::pop): (bmalloc::Vector<T>::shrink): (bmalloc::Vector<T>::reallocateBuffer): (bmalloc::Vector<T>::shrinkCapacity): (bmalloc::Vector<T>::growCapacity): * bmalloc/XLargeChunk.h: Added. (bmalloc::XLargeChunk::get): (bmalloc::XLargeChunk::begin): (bmalloc::XLargeChunk::XLargeChunk): (bmalloc::XLargeChunk::create): (bmalloc::XLargeChunk::destroy): (bmalloc::XLargeChunk::range): (bmalloc::XLargeChunk::size): * bmalloc/bmalloc.h: Added. (bmalloc::api::malloc): (bmalloc::api::free): (bmalloc::api::realloc): * bmalloc/mbmalloc.cpp: Added. |