Skip to content

[wip] Add missing SAVE_OPLINE() #10004

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

Closed
wants to merge 4 commits into from
Closed

Conversation

arnaud-lb
Copy link
Member

This is a follow up to #9933 / #10003

SAVE_OPLINE() is used to save the register variable opline in EX(opline). It appears to have at least these purposes:

  • Save the return opline before entering an other op_array
  • Expose opline outside of execute_ex(). EX(opline) is used at least in zend_error() and in exception handling

zend_error() will crash if EX(opline) was not saved. zend_vm_def.h appears to consistenly save opline before anything that may trigger an error, but does not always account for the fact that memory allocations may trigger an error.

In this change I'm adding an assertion in emalloc functions to ensure that opline was saved, and a few missing SAVE_OPLINE() that the assertion helped to discover.

There is a remaining crash in jit_exit that I need to investigate. I also need to update zend_jit_arm64.dasc.

@iluuu1994
Copy link
Member

iluuu1994 commented Nov 26, 2022

This will slow down the VM somewhat, although it's hard to say whether that makes a big difference without measuring. Essentially any handler that allocates memory could potentially throw out-of-memory errors, which are likely most of them.

AFAIK the main reason for the SAVE_OPLINE in error handling is that the current opline is replaced with an exception handler, which then later restores opline. If opline refers to an old opline then the exception handler will jump back to the wrong location.

EG(opline_before_exception) = EG(current_execute_data)->opline;
EG(current_execute_data)->opline = EG(exception_op);

The out of memory errors just do bailout, where an accurate opline is not really necessary. Thus the additional overhead in the VM might not be worth it.

Please let me know if there's something I'm missing!

@arnaud-lb
Copy link
Member Author

I had the same concerns, but I wanted to measure the impact of adding them.

Right now I'm seeing a stable ~1% regression on the Symfony blog benchmark (only this one, interestingly), and since the crash is fixed in #10003, I will probably not pursue this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants