From 5659a59fd64dbb5505594d3a5e6fc6f9e42e2089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ols=CC=8Cavsky=CC=81?= Date: Sun, 7 Aug 2022 20:21:53 +0200 Subject: [PATCH 1/4] Do not reset cleared count on GC rerun --- Zend/tests/gc_045.phpt | 60 ++++++++++++++++++++++++++++++++++++++++++ Zend/zend_gc.c | 6 +++-- 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/gc_045.phpt diff --git a/Zend/tests/gc_045.phpt b/Zend/tests/gc_045.phpt new file mode 100644 index 0000000000000..cabb47f87465e --- /dev/null +++ b/Zend/tests/gc_045.phpt @@ -0,0 +1,60 @@ +--TEST-- +GC 045: Total count persisted when GC is rerun due to destructor call +--INI-- +zend.enable_gc=1 +--FILE-- +val = $val; + $this->selfRef = $this; + } +} + +for ($j = 0; $j < 10; $j++) { + for ($i = 0; $i < 3000; $i++) { + new Foo(new Value()); + } +} + +var_dump(gc_status()); +echo 'ok'; +?> +--EXPECT-- +array(4) { + ["runs"]=> + int(10) + ["collected"]=> + int(25000) + ["threshold"]=> + int(10001) + ["roots"]=> + int(10000) +} +ok diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index 3319b7aa34e64..766e1ffea9a61 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -1469,12 +1469,13 @@ static void zend_gc_root_tmpvars(void); ZEND_API int zend_gc_collect_cycles(void) { - int count = 0; + int total_count = 0; bool should_rerun_gc = 0; bool did_rerun_gc = 0; rerun_gc: if (GC_G(num_roots)) { + int count; gc_root_buffer *current, *last; zend_refcounted *p; uint32_t gc_flags = 0; @@ -1652,6 +1653,7 @@ ZEND_API int zend_gc_collect_cycles(void) GC_TRACE("Collection finished"); GC_G(collected) += count; + total_count += count; GC_G(gc_active) = 0; } @@ -1668,7 +1670,7 @@ ZEND_API int zend_gc_collect_cycles(void) finish: zend_get_gc_buffer_release(); zend_gc_root_tmpvars(); - return count; + return total_count; } ZEND_API void zend_gc_get_status(zend_gc_status *status) From e1477f41163cccd66ba78832be71a59b55d8fd50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ols=CC=8Cavsky=CC=81?= Date: Sun, 7 Aug 2022 21:43:00 +0200 Subject: [PATCH 2/4] Fix indent --- Zend/tests/gc_045.phpt | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Zend/tests/gc_045.phpt b/Zend/tests/gc_045.phpt index cabb47f87465e..b47acb4a9ab44 100644 --- a/Zend/tests/gc_045.phpt +++ b/Zend/tests/gc_045.phpt @@ -6,41 +6,41 @@ zend.enable_gc=1 val = $val; - $this->selfRef = $this; - } + public function __construct(Value $val) + { + $this->val = $val; + $this->selfRef = $this; + } } for ($j = 0; $j < 10; $j++) { - for ($i = 0; $i < 3000; $i++) { - new Foo(new Value()); - } + for ($i = 0; $i < 3000; $i++) { + new Foo(new Value()); + } } var_dump(gc_status()); From 8c23420fe4db28e0b70c92bc1c1cb26bc2dfe313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ols=CC=8Cavsky=CC=81?= Date: Sun, 7 Aug 2022 23:40:45 +0200 Subject: [PATCH 3/4] Fix indent in test --- Zend/tests/gc_045.phpt | 54 +++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/Zend/tests/gc_045.phpt b/Zend/tests/gc_045.phpt index b47acb4a9ab44..dc7a739c3efc5 100644 --- a/Zend/tests/gc_045.phpt +++ b/Zend/tests/gc_045.phpt @@ -6,41 +6,41 @@ zend.enable_gc=1 val = $val; - $this->selfRef = $this; - } + public function __construct(Value $val) + { + $this->val = $val; + $this->selfRef = $this; + } } for ($j = 0; $j < 10; $j++) { - for ($i = 0; $i < 3000; $i++) { - new Foo(new Value()); - } + for ($i = 0; $i < 3000; $i++) { + new Foo(new Value()); + } } var_dump(gc_status()); @@ -48,13 +48,13 @@ echo 'ok'; ?> --EXPECT-- array(4) { - ["runs"]=> - int(10) - ["collected"]=> - int(25000) - ["threshold"]=> - int(10001) - ["roots"]=> - int(10000) + ["runs"]=> + int(10) + ["collected"]=> + int(25000) + ["threshold"]=> + int(10001) + ["roots"]=> + int(10000) } ok From dec349f7f64f01186255aeb9cdfcd92197517719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Ols=CC=8Cavsky=CC=81?= Date: Mon, 8 Aug 2022 18:47:21 +0200 Subject: [PATCH 4/4] Fix review issue --- Zend/tests/gc_045.phpt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Zend/tests/gc_045.phpt b/Zend/tests/gc_045.phpt index dc7a739c3efc5..865462ecfbc3f 100644 --- a/Zend/tests/gc_045.phpt +++ b/Zend/tests/gc_045.phpt @@ -44,7 +44,6 @@ for ($j = 0; $j < 10; $j++) { } var_dump(gc_status()); -echo 'ok'; ?> --EXPECT-- array(4) { @@ -57,4 +56,3 @@ array(4) { ["roots"]=> int(10000) } -ok