Bug #80447 [NEW]: Strange out of memory error when running with JIT
| From: | dac514 at hotmail dot com | Date: | Mon, 30 Nov 2020 20:21:49 +0000 |
| Subject: | Bug #80447 [NEW]: Strange out of memory error when running with JIT | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-230745@lists.php.net to get a copy of this message | ||
From: dac514 at hotmail dot com
Operating system: Ubuntu
PHP version: 8.0.0
Package: Unknown/Other Function
Bug Type: Bug
Bug description:Strange out of memory error when running with JIT
Description:
------------
In the last few days benchmarksgame-team.pages.debian.net upgraded to
PHP8.
This script;
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/binarytrees-php-4.html
When run with JIT:
`/opt/src/php-8.0.0/bin/php
-dzend_extension=/opt/src/php-8.0.0/lib/php/extensions/no-debug-non-zts-20200930/opcache.so
-dopcache.enable_cli=1 -dopcache.jit_buffer_size=64M -n -d
memory_limit=4096M binarytrees.php-4.php 21`
Runs out of memory, very unusually, (it did not run out of memory in
previous versions of PHP)
The following weird hack is a workaround, change:
```
function createTree($depth)
{
if (!$depth) {
return [null, null];
```
To:
```
function createTree($depth)
{
echo '';
if (!$depth) {
return [null, null];
```
I don't get it?
Test script:
---------------
function createTree($depth)
{
// echo ''; // TODO: This hack works?!
if (!$depth) {
return [null, null];
}
$depth--;
return [
createTree($depth),
createTree($depth)
];
}
function checkTree($treeNode)
{
return 1
+ ($treeNode[0][0] === null ? 1 : checkTree($treeNode[0]))
+ ($treeNode[1][0] === null ? 1 : checkTree($treeNode[1]));
}
$minDepth = 4;
$n = ($argc == 2) ? $argv[1] : 1;
$maxDepth = max($minDepth + 2, $n);
$stretchDepth = $maxDepth + 1;
$stretchTree = createTree($stretchDepth);
echo "stretch tree of depth $stretchDepth\t check: ",
checkTree($stretchTree), PHP_EOL;
unset($stretchTree);
$longLivedTree = createTree($maxDepth);
function startWorker($depth, $iter, $n, $size, $shmId)
{
$pid = pcntl_fork();
if ($pid) {
return $pid;
} else {
$check = 0;
for ($i = 1; $i <= $iter; ++$i) {
$t = createTree($depth);
$check += checkTree($t);
unset($t);
}
$result = "$iter\t trees of depth $depth\t check: $check\n";
shmop_write($shmId, $result, $size * ($n - 1));
exit(0);
}
}
$iterations = 1 << ($maxDepth);
$depthIterations = [$minDepth => $iterations];
do {
$minDepth += 2;
if ($minDepth <= $maxDepth) {
$iterations >>= 2;
$depthIterations[$minDepth] = $iterations;
}
} while ($minDepth <= $maxDepth);
extension_loaded('shmop') or dl('shmop.so');
$size = 128;
$shmId = shmop_open(ftok(__FILE__, 'b'), 'c', 0644, $size *
(count($depthIterations) + 1));
$PIDs = [];
$n = 0;
foreach ($depthIterations as $d => $i) {
$PIDs[] = startWorker($d, $i, ++$n, $size, $shmId);
}
foreach ($PIDs as $PID) {
pcntl_waitpid($PID, $status);
}
foreach (range(1, count($depthIterations)) as $n) {
echo trim(shmop_read($shmId, $size * ($n - 1), $size)), PHP_EOL;
}
shmop_delete($shmId);
echo "long lived tree of depth $maxDepth\t check: ",
checkTree($longLivedTree), PHP_EOL;
Expected result:
----------------
PROGRAM OUTPUT:
stretch tree of depth 22 check: 8388607
2097152 trees of depth 4 check: 65011712
524288 trees of depth 6 check: 66584576
131072 trees of depth 8 check: 66977792
32768 trees of depth 10 check: 67076096
8192 trees of depth 12 check: 67100672
2048 trees of depth 14 check: 67106816
512 trees of depth 16 check: 67108352
128 trees of depth 18 check: 67108736
32 trees of depth 20 check: 67108832
long lived tree of depth 21 check: 4194303
Actual result:
--------------
Out of memory error. Terminated.
--
Edit bug report at https://bugs.php.net/bug.php?id=80447&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80447&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80447&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80447&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80447&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80447&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80447&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80447&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80447&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80447&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80447&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80447&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80447&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80447&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80447&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80447&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80447&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80447&r=mysqlcfg