Skip to content

opcache: Register constants for opcache.opt_debug_level and opcache.jit_debug #15503

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tstarling
Copy link
Contributor

opcache: Register constants for opcache.opt_debug_level and opcache.jit_debug

Register constants for the integer values which can be used for opcache.opt_debug_level and opcache.jit_debug.

Utility is limited since, contrary to a comment in php.ini-development, extension constants apparently cannot be used in php.ini after the zend_extension= line. But that can be fixed separately. With this change it is possible to do

ini_set('opcache.jit_debug', OPCACHE_JIT_DEBUG_ASM);

And that's something at least. Perhaps more importantly, registering these constants gives us a place to document their values in the PHP manual -- "read the source" is unsatisfying.

I did ZEND -> OPCACHE to reflect the current organisation of the code. I think ZEND_ in this case refers to the Zend Accelerator rather than the Zend Engine, which is confusing.

…it_debug

Register constants for the integer values which can be used for
opcache.opt_debug_level and opcache.jit_debug.

Utility is limited since, contrary to a comment in php.ini-development,
extension constants apparently cannot be used in php.ini after the
zend_extension= line. But that can be fixed separately. With this change
it is possible to do

ini_set('opcache.jit_debug', OPCACHE_JIT_DEBUG_ASM);

And that's something at least. Perhaps more importantly, registering
these constants gives us a place to document their values in the PHP
manual -- "read the source" is unsatisfying.

I did ZEND -> OPCACHE to reflect the current organisation of the code. I
think ZEND_ in this case refers to the Zend Accelerator rather than the
Zend Engine, which is confusing.
@iluuu1994
Copy link
Member

Most of these INI settings are PHP_INI_SYSTEM settings, so they cannot be used in php.ini. If that feature can be implemented, I suppose it makes more sense.

@tstarling
Copy link
Contributor Author

@iluuu1994 Would you merge it if it only had the OPCACHE_JIT_DEBUG_* constants?

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

I'm not sure if we need to expose these constants to user level.
These options are really necessary only for debugging of internal bugs and mostly useful in command line.

Usage of long string names doesn't make big advantage over hex bit mask.
Personally, I remember the most useful hex masks and look into *.h files than I need something specific.

Probably a set of "short" names might be useful, but this would require especial parser for this options + additional documentation. I wouldn't invest into this work.

@tstarling
Copy link
Contributor Author

I wrote this because I personally needed it for #15502. I did things like

	$old = ini_get( 'opcache.jit_debug' );
	ini_set('opcache.jit_debug',
		OPCACHE_JIT_DEBUG_ASM
		| OPCACHE_JIT_DEBUG_ASM_ADDR
		| OPCACHE_JIT_DEBUG_REG_ALLOC
		| OPCACHE_JIT_DEBUG_TRACE_EXIT
		| OPCACHE_JIT_DEBUG_TRACE_ABORT
		| OPCACHE_JIT_DEBUG_TRACE_BLACKLIST
		| OPCACHE_JIT_DEBUG_TRACE_COMPILED
		| OPCACHE_JIT_DEBUG_TRACE_EXIT_INFO
		| OPCACHE_JIT_DEBUG_PERF_DUMP
	);
	$filename = self::find( $className );
	ini_set( 'opcache.jit_debug', $old );

Usage of long string names doesn't make big advantage over hex bit mask.

@dstogov: PHP is very lucky to have you, and I very much hope we never lose you. But you are very special, you are not a normal user or developer of this application. Please believe me when I tell you: some people prefer to use names rather than hexadecimal numbers.

@dstogov
Copy link
Member

dstogov commented Aug 27, 2024

I know and I think normal users would never need to use opcache.jit_debug at all.
In case you came to this, you are not a normal user as well :)

Anyway, I'm not totally against this. The patch doesn't make any harm or complication.
I just don't see a real value.

@iluuu1994 @nielsdos @arnaud-lb @bwoebi @kocsismate what do you think?

@iluuu1994
Copy link
Member

I don't object for things that can actually be set from userland. It would indeed be useful if these flags could be used from ini files. I'm notoriously bad at remembering numbers.

@nielsdos
Copy link
Member

A bit niche but I don't object.

@arnaud-lb
Copy link
Member

I think it's useful.

I've been using a small script to generate numeric values for opcache.jit_debug:

#!/bin/bash

ref=$(grep '#define ZEND_JIT_DEBUG_' ext/opcache/jit/zend_jit.h)

flags=0

for name in "$@"; do
    if [ "$name" = "list" ]; then
        echo "$ref"
        exit
    fi

    val=$(echo "$ref" | grep -i "ZEND_JIT_DEBUG_$name " | awk '{ print $3 }' | cut -d'<' -f3 | cut -d')' -f1)
    if [ -z "$val" ]; then
        printf "Invalid flag: %s\n" "$name" >&2
    fi

    flags=$((flags | (1<<val)))
done

echo "$flags"
$ jit_debug list
$ php -dopcache.jit_debug=$(jit_debug asm gdb) ...

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