Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non recursive cyclic garbage collector #3889

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ef168c2
fix small typo
drealecs Feb 21, 2019
ee5a004
make gc_mark_grey, gc_scan and gc_scan_black non recursive by using a…
drealecs Feb 25, 2019
06d84e1
remove tail recursion call in gc_mark_grey, gc_scan and gc_scan_black
drealecs Feb 25, 2019
98b4423
fix gc_scan_black to check at the start of the function instead of be…
drealecs Feb 26, 2019
b23b94b
make gc_collect_white non recursive by using a linked list stack
drealecs Feb 27, 2019
2862a84
revert tail recursion removal
drealecs Feb 27, 2019
c2d2051
add back checks before adding to the stack in gc_scan_black
drealecs Feb 27, 2019
5c4abaf
add checks for the other stack adding places if we know that processi…
drealecs Feb 27, 2019
b9b1347
create a stack type and pass it by reference so that there will not b…
drealecs Mar 1, 2019
a7744aa
implement stack using a dynamically resized array to avoid many calls…
drealecs Mar 2, 2019
14e72d4
reuse the same stack for black marking to avoid instantiating a new o…
drealecs Mar 2, 2019
1287f05
add two test cases for cyclic garbage collector stack overflow
drealecs Mar 2, 2019
7154f6f
remove gc_refcounted_stack_element as it was just a pointer to zend_r…
drealecs Mar 2, 2019
a1c4cf0
extract stack initial size as a constant and change it to 16
drealecs Mar 2, 2019
7f309a8
avoid adding the same ref multiple times onto the stack by setting re…
drealecs Mar 3, 2019
860794a
change initial stack size to 512 as suggested
drealecs Mar 4, 2019
3bd22ce
reuse the same stack (defined on stack instead of heap) between gc_ma…
drealecs Mar 4, 2019
22d788f
Merge branch 'PHP-7.2' into non_recursive_cyclic_garbage_collector-7.2
drealecs Mar 4, 2019
1bb940a
add the conditions so that if a color was changed while the item is i…
drealecs Mar 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions Zend/tests/bug77345_gc_1.phpt
@@ -0,0 +1,42 @@
--TEST--
Bug #77345 (Segmentation faults stack overflow in cyclic garbage collector) (Bug #77427)
--INI--
zend.enable_gc = 1
--FILE--
<?php

class Node
{
/** @var Node */
public $previous;
/** @var Node */
public $next;
}

var_dump(gc_enabled());
var_dump('start');

$firstNode = new Node();
$firstNode->previous = $firstNode;
$firstNode->next = $firstNode;

$circularDoublyLinkedList = $firstNode;

for ($i = 0; $i < 200000; $i++) {
$currentNode = $circularDoublyLinkedList;
$nextNode = $circularDoublyLinkedList->next;

$newNode = new Node();

$newNode->previous = $currentNode;
$currentNode->next = $newNode;
$newNode->next = $nextNode;
$nextNode->previous = $newNode;

$circularDoublyLinkedList = $nextNode;
}
var_dump('end');
--EXPECT--
bool(true)
string(5) "start"
string(3) "end"
48 changes: 48 additions & 0 deletions Zend/tests/bug77345_gc_2.phpt
@@ -0,0 +1,48 @@
--TEST--
Bug #77345 (Segmentation faults stack overflow in cyclic garbage collector) (Bug #77427)
--INI--
zend.enable_gc = 1
--FILE--
<?php

class Node
{
/** @var Node */
public $previous;
/** @var Node */
public $next;
}

var_dump(gc_enabled());
var_dump('start');

function xxx() {
$firstNode = new Node();
$firstNode->previous = $firstNode;
$firstNode->next = $firstNode;

$circularDoublyLinkedList = $firstNode;

for ($i = 0; $i < 300000; $i++) {
$currentNode = $circularDoublyLinkedList;
$nextNode = $circularDoublyLinkedList->next;

$newNode = new Node();

$newNode->previous = $currentNode;
$currentNode->next = $newNode;
$newNode->next = $nextNode;
$nextNode->previous = $newNode;

$circularDoublyLinkedList = $nextNode;
}
}

xxx();
gc_collect_cycles();

var_dump('end');
--EXPECT--
bool(true)
string(5) "start"
string(3) "end"