Arquivos
hhvm/hphp/test/quick/args-test.php
T
mwilliams 412dce677f Better reffiness checks
While debugging a sandbox crash, I spent some time looking at a huge
sequnce of conditional masks, compares and branches that didnt seem
to belong in the code I was debugging. Finally realized that it was
a reffiness check. It looked way too complicated, so I investigated.

Part of the problem was that we were avoiding a malloc in the case
of a zero param function at the expense of an extra check.

Instead, this diff always sets up at least 64 bits worth of m_refBitVec.
But by using the space set aside for the pointer in Func::m_shared it
avoids a malloc for any function with fewer than 65 arguments, and
avoids the numParams check for the first 64 parameters.

In addition, the existing code was spitting out a generic test for
the guard condition - (mask & bits) == value - where mask and value
are known constants. Since the most common case is that value == 0
(all the parameters are expected to be by value), we can usually omit
the compare. In addition, since most functions only have a small
number of parameters, we can usually get away with 8 bit, or 32
bit operations.

The result is that for a typical function (fewer than 64 args, args
expected to be by value) the reffiness guard is now

  test <mask>, Func::m_refBitVec[0]
  jne exit

Rather than:

  move <mask>, reg1
  xor reg2, reg2
  cmp 1, Func::m_numParams
  jnl ok
  test AttrVarArgs, Func::m_attrs
  jne exit
  jmp done
ok:
  load reg3, Func::m_refBitVec[0]
  and mask, reg3
  cmp reg3, reg2
  jne exit
done:
2013-06-11 11:48:25 -07:00

104 linhas
4.3 KiB
PHP

<?php
function f($a0, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8,
$a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16,
$a17, $a18, $a19, $a20, $a21, $a22, $a23, $a24,
$a25, $a26, $a27, $a28, $a29, $a30, $a31, $a32,
$a33, $a34, $a35, $a36, $a37, $a38, $a39, $a40,
$a41, $a42, $a43, $a44, $a45, $a46, $a47, $a48,
$a49, $a50, $a51, $a52, $a53, $a54, $a55, $a56,
$a57, $a58, $a59, $a60, $a61, $a62, $a63, $a64,
$a65, $a66, $a67, $a68, $a69, $a70, $a71, $a72,
$a73, $a74, $a75, $a76) {
for ($i = 0; $i < 77; $i++) {
echo ${"a".$i}, "\n";
}
}
function g($a0, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8,
$a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16,
$a17, $a18, $a19, $a20, $a21, $a22, $a23, $a24,
$a25, $a26, $a27, $a28, $a29, $a30, $a31, $a32,
$a33, $a34, $a35, $a36, $a37, $a38, $a39, $a40,
$a41, $a42, $a43, $a44, $a45, $a46, $a47, $a48,
$a49, $a50, $a51, $a52, $a53, $a54, $a55, $a56,
$a57, $a58, $a59, $a60, $a61, $a62, $a63, $a64,
$a65, $a66, $a67, $a68, $a69, $a70, $a71, $a72,
$a73, $a74, $a75, $a76, $a77, $a78, $a79, $a80,
$a81, $a82, $a83, $a84, $a85, $a86, $a87, $a88,
$a89, $a90, $a91, $a92, $a93, $a94, $a95, $a96,
$a97, $a98, $a99, $a100, $a101, $a102, $a103, $a104,
$a105, $a106, $a107, $a108, $a109, $a110, $a111, $a112,
$a113, $a114, $a115, $a116, $a117, $a118, $a119, $a120,
$a121, $a122, $a123, $a124, $a125, $a126, $a127, $a128,
$a129, $a130, $a131, $a132, $a133, $a134, $a135, $a136,
$a137, $a138, $a139, $a140
) {
for ($i = 0; $i < 141; $i++) {
echo ${"a".$i}, "\n";
}
}
function gr($a0, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8,
$a9, $a10, $a11, $a12, $a13, $a14, $a15, $a16,
$a17, $a18, $a19, $a20, $a21, $a22, $a23, $a24,
$a25, $a26, $a27, $a28, $a29, $a30, $a31, $a32,
$a33, $a34, $a35, $a36, $a37, $a38, $a39, $a40,
$a41, $a42, $a43, $a44, $a45, $a46, $a47, $a48,
$a49, $a50, $a51, $a52, $a53, $a54, $a55, $a56,
$a57, $a58, $a59, $a60, $a61, $a62, $a63, &$a64,
&$a65, $a66, $a67, $a68, $a69, $a70, $a71, $a72,
$a73, $a74, $a75, $a76, $a77, $a78, $a79, $a80,
$a81, $a82, $a83, $a84, $a85, $a86, $a87, $a88,
$a89, $a90, $a91, $a92, $a93, $a94, $a95, $a96,
$a97, $a98, $a99, $a100, $a101, $a102, $a103, $a104,
$a105, $a106, $a107, $a108, $a109, $a110, $a111, $a112,
$a113, $a114, $a115, $a116, $a117, $a118, $a119, $a120,
$a121, $a122, $a123, $a124, $a125, $a126, $a127, $a128,
$a129, $a130, $a131, $a132, $a133, $a134, $a135, $a136,
$a137, $a138, $a139, $a140
) {
for ($i = 0; $i < 141; $i++) {
${"a".$i}++;
}
}
function test($f, $a) {
$f($a[0], $a[1], $a[2], $a[3], $a[4],
$a[5], $a[6], $a[7], $a[8], $a[9],
$a[10], $a[11], $a[12], $a[13], $a[14],
$a[15], $a[16], $a[17], $a[18], $a[19],
$a[20], $a[21], $a[22], $a[23], $a[24],
$a[25], $a[26], $a[27], $a[28], $a[29],
$a[30], $a[31], $a[32], $a[33], $a[34],
$a[35], $a[36], $a[37], $a[38], $a[39],
$a[40], $a[41], $a[42], $a[43], $a[44],
$a[45], $a[46], $a[47], $a[48], $a[49],
$a[50], $a[51], $a[52], $a[53], $a[54],
$a[55], $a[56], $a[57], $a[58], $a[59],
$a[60], $a[61], $a[62], $a[63], $a[64],
$a[65], $a[66], $a[67], $a[68], $a[69],
$a[70], $a[71], $a[72], $a[73], $a[74],
$a[75], $a[76], $a[77], $a[78], $a[79],
$a[80], $a[81], $a[82], $a[83], $a[84],
$a[85], $a[86], $a[87], $a[88], $a[89],
$a[90], $a[91], $a[92], $a[93], $a[94],
$a[95], $a[96], $a[97], $a[98], $a[99],
$a[100], $a[101], $a[102], $a[103], $a[104],
$a[105], $a[106], $a[107], $a[108], $a[109],
$a[110], $a[111], $a[112], $a[113], $a[114],
$a[115], $a[116], $a[117], $a[118], $a[119],
$a[120], $a[121], $a[122], $a[123], $a[124],
$a[125], $a[126], $a[127], $a[128], $a[129],
$a[130], $a[131], $a[132], $a[133], $a[134],
$a[135], $a[136], $a[137], $a[138], $a[139],
$a[140], $a[141], $a[142], $a[143], $a[144],
$a[145], $a[146], $a[147], $a[148], $a[149]);
var_dump($a);
}
test("f", range(0, 149));
test("g", range(0, 149));
test("gr", range(0, 149));