FAQ

On Fri, 11 Apr 2008, Dmitry Stogov wrote:

dmitry Fri Apr 11 09:43:31 2008 UTC

Modified files: (Branch: PHP_5_3)
/php-src NEWS
/ZendEngine2 zend.c zend_execute_API.c zend_vm_def.h
zend_vm_execute.h
Log:
Optimized ZEND_RETURN opcode to not allocate and copy return value if it is not
used.
Hmm, I'm not too happy with this, as it breaks some functionality in
Xdebug. Xdebug allows you to create a function trace, including all
return values. For example the following script:

<?php
function foo() { return 42; }
foo();
echo foo();
?>

Gave a function trace like
(with php -d xdebug.auto_trace=1 -dxdebug.collect_return=1 test-ft.php):

TRACE START [2008-04-11 10:29:49]
0.0002 650528 -> {main}() /tmp/test-ft.php:0
0.0003 650840 -> foo() /tmp/test-ft.php:8
=> 42
0.0004 650840 -> foo() /tmp/test-ft.php:9
=> 42
=> 1
0.0013 54536
TRACE END [2008-04-11 10:29:49]

However, with this change, I only get:

TRACE START [2008-04-11 10:32:11]
0.2148 652336 -> {main}() /tmp/test-ft.php:0
0.2907 652648 -> foo() /tmp/test-ft.php:8
0.3178 652648 -> foo() /tmp/test-ft.php:9
=> 42
0.4802 56344
TRACE END [2008-04-11 10:32:12]


Is it still possible to get the return values of the functions that are
*not* used? I currently check if EG(return_value_ptr_ptr) and
*EG(return_value_ptr_ptr) are not NULL to see if there is a return
value, and now (of course) they are empty (null pointer).

regards,
Derick

Search Discussions

  • Dmitry Stogov at Apr 11, 2008 at 5:43 pm
    Hi Derick,

    Sorry, but I think mainly about PHP performance, and of course I didn't
    know that you trace return_values it in xdebug.

    After the patch, in case if return value is not used we set
    EG(return_value_ptr_ptr) to NULL before call to nested execute().
    I assume you can just check for (EG(return_value_ptr_ptr)==NULL) before
    write it. Will it work for you?

    Thanks. Dmitry.

    Derick Rethans wrote:
    On Fri, 11 Apr 2008, Dmitry Stogov wrote:

    dmitry Fri Apr 11 09:43:31 2008 UTC

    Modified files: (Branch: PHP_5_3)
    /php-src NEWS
    /ZendEngine2 zend.c zend_execute_API.c zend_vm_def.h
    zend_vm_execute.h
    Log:
    Optimized ZEND_RETURN opcode to not allocate and copy return value if it is not
    used.
    Hmm, I'm not too happy with this, as it breaks some functionality in
    Xdebug. Xdebug allows you to create a function trace, including all
    return values. For example the following script:

    <?php
    function foo() { return 42; }
    foo();
    echo foo();
    ?>

    Gave a function trace like
    (with php -d xdebug.auto_trace=1 -dxdebug.collect_return=1 test-ft.php):

    TRACE START [2008-04-11 10:29:49]
    0.0002 650528 -> {main}() /tmp/test-ft.php:0
    0.0003 650840 -> foo() /tmp/test-ft.php:8
    => 42
    0.0004 650840 -> foo() /tmp/test-ft.php:9
    => 42
    => 1
    0.0013 54536
    TRACE END [2008-04-11 10:29:49]

    However, with this change, I only get:

    TRACE START [2008-04-11 10:32:11]
    0.2148 652336 -> {main}() /tmp/test-ft.php:0
    0.2907 652648 -> foo() /tmp/test-ft.php:8
    0.3178 652648 -> foo() /tmp/test-ft.php:9
    => 42
    0.4802 56344
    TRACE END [2008-04-11 10:32:12]


    Is it still possible to get the return values of the functions that are
    *not* used? I currently check if EG(return_value_ptr_ptr) and
    *EG(return_value_ptr_ptr) are not NULL to see if there is a return
    value, and now (of course) they are empty (null pointer).

    regards,
    Derick
  • Derick Rethans at Apr 16, 2008 at 6:26 pm

    On Fri, 11 Apr 2008, Dmitry Stogov wrote:

    Sorry, but I think mainly about PHP performance, and of course I didn't know
    that you trace return_values it in xdebug.

    After the patch, in case if return value is not used we set
    EG(return_value_ptr_ptr) to NULL before call to nested execute().
    I assume you can just check for (EG(return_value_ptr_ptr)==NULL) before write
    it. Will it work for you?
    I'm already doing that, so not went really wrong. I am just wondering
    whether it would be possible to always have those return values there
    through some kind of option.

    regards,
    Derick
  • Dmitry Stogov at Apr 17, 2008 at 6:58 am
    Another idea: In case xdebug overwrites zend_execute() it can set
    EG(return_value_ptr_ptr) to point to some local variable then call
    original executor and then print pass return_value to caller or destroy
    it dependent on previous value of EG(return_value_ptr_ptr).

    Thanks. Dmitry.

    Derick Rethans wrote:
    On Fri, 11 Apr 2008, Dmitry Stogov wrote:

    Sorry, but I think mainly about PHP performance, and of course I didn't know
    that you trace return_values it in xdebug.

    After the patch, in case if return value is not used we set
    EG(return_value_ptr_ptr) to NULL before call to nested execute().
    I assume you can just check for (EG(return_value_ptr_ptr)==NULL) before write
    it. Will it work for you?
    I'm already doing that, so not went really wrong. I am just wondering
    whether it would be possible to always have those return values there
    through some kind of option.

    regards,
    Derick
  • Derick Rethans at Apr 17, 2008 at 6:18 pm

    On Thu, 17 Apr 2008, Dmitry Stogov wrote:

    Another idea: In case xdebug overwrites zend_execute() it can set
    EG(return_value_ptr_ptr) to point to some local variable then call original
    executor and then print pass return_value to caller or destroy it dependent on
    previous value of EG(return_value_ptr_ptr).
    See, I was looking for just such a trick. I'll give it a try later.
    Thanks

    Derick

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedApr 11, '08 at 10:37a
activeApr 17, '08 at 6:18p
posts5
users2
websitephp.net

2 users in discussion

Derick Rethans: 3 posts Dmitry Stogov: 2 posts

People

Translate

site design / logo © 2022 Grokbase