Skip to content

[opcache] [jit] Attribute support #5915

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 1 commit into from

Conversation

beberlei
Copy link
Contributor

@beberlei beberlei commented Jul 31, 2020

Remove the obsolete doc-comment based JIT trigger. Since function and
tracing JITs are recommended for now, the attribute based trigger mode
is removed for now.

Only @@jit("off") is available to disable the JIT for a function/method.

Open Questions:

  • Are we ok with removing ´@jit("on"), @@jit("tracing")and@@jit("function")` for now to thoroughly discuss best approach for 8.1?
  • Rename @@Jit to something more specific like @@JitOptions, @@JitConfig or @@JitHint?
  • Remove the attribute trigger constant 4, and move tracing JIT to use 4 instead of 5?

@beberlei
Copy link
Contributor Author

@dstogov This is my attempt at Attribute support for JIT. Looking forward for your feedback.

@nikic
Copy link
Member

nikic commented Jul 31, 2020

I think we need some more clarity on what we expect these attributes to actually be useful for.

Is the attribute trigger mode something purely for debugging, so one can JIT one function out of a large code base easily?

@beberlei
Copy link
Contributor Author

beberlei commented Jul 31, 2020

@nikic I agree, @@Jit("off") works independent of trigger mode, that makes it clear. But the others only work with the attribute trigger.

More consistent would probably be to remove the trigger=attribute completly, and have the @@Jit attribute work as an overwrite that immediately JITs the attributed function. This would not make use of the tracing / callgraph optimizations though that other triggers have, potentially causing less optimized code?

@beberlei beberlei changed the title [opcace] [jit] Attribute support [opcache] [jit] Attribute support Jul 31, 2020
void zend_jit_validate_opcache_attribute(zend_attribute *jit, uint32_t target, zend_class_entry *scope)
{
if (jit->argc > 1) {
zend_error(E_COMPILE_ERROR, "@@Jit requires zero or one argument, %d arguments given", jit->argc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems inconsistent to emit E_COMPILE_ERROR with opcache but not without opcache. I'd personally prefer E_WARNING like some of the other warnings about failing to optimize.

  • And to return early but proceed with optimizing the file anywhere where the attribute is seen with invalid count or argument types
ext/opcache/zend_accelerator_module.c
893:                    zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not compile file %s", handle.filename);

Also, zend_error proceeds with execution after being called. You may want zend_error_noreturn(E_COMPILE_ERROR, if the intent is actually to make php stop executing - I don't know if that actually works in the opcache step, though

@beberlei
Copy link
Contributor Author

beberlei commented Aug 3, 2020

@dstogov can you comment please? Looking to merge this tomorrow morning (Europe time)

@dstogov
Copy link
Member

dstogov commented Aug 3, 2020

looks good, but I would remove opcache.jit=attributes.
We will also have to add checks into trace recorder to stop recording for functions with inappropriate @@jit attribute.

@nikic
Copy link
Member

nikic commented Aug 3, 2020

I think it would be good to bring this up on the mailing list. I'm still not completely clear on what the use-case for them will be, and I'm also a bit uncomfortable with adding a global Jit class.

@beberlei
Copy link
Contributor Author

beberlei commented Aug 3, 2020

@nikic from am APM perspective my primary use case is @@Jit("off") to make sure instrumented code is never jitted. That can certainly be handled by an internal API, but I understand Dmitry is reluctant to add one when I proposed it.

I would be willing to hold this off until 8.1 to discuss the implications and use-cases in more detail, if extensions get another way to selectively control the JIT.

The positive use case of enabling the JIT for certain functions I can see when code gets microoptimized towards the JIT, then maybe a human makes better decisions on what function should be jitted, and which ones not.

@beberlei
Copy link
Contributor Author

beberlei commented Aug 3, 2020

@dstogov One question I just had, if I wanted to disable the JIT for selected functions:

It is now possible for an extension to use opcache.jit at runtime to disable the JIT in a zend_compile hook for a selected file and then reset to its previous value afterwards?

@beberlei beberlei force-pushed the OpcacheJitAttribute branch 6 times, most recently from f3e09f0 to 1192b51 Compare August 4, 2020 14:17
@beberlei
Copy link
Contributor Author

beberlei commented Aug 4, 2020

@dstogov ping, sorry for being pushy :-(

Remove the obsolete doc-comment based JIT trigger. Since function and
tracing JITs are recommended for now, the attribute based trigger mode
is removed for now.

Only @@jit("off") is available to disable the JIT for a function/method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants