Skip to content
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

Special JIT support for FFI #14491

Draft
wants to merge 68 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
7e23792
Initial JIT/FFI PoC
dstogov Jun 6, 2024
dc42020
JIT: Implement FFI Array Bounds Checks
dstogov Jun 7, 2024
43e9e14
JIT: Separate FFI assing_op helper. Add support for all SUB, AND, etc
dstogov Jun 7, 2024
2bce349
JIT: Fix NULL dereference
dstogov Jun 7, 2024
da99a94
JIT: Fix FFI pointer access through FETCH_DIM, ASSIGN_DIM
dstogov Jun 7, 2024
4d904fa
JIT: Fix memory leak in ext/ffi/tests/032.phpt
dstogov Jun 7, 2024
883d2bd
Support for 32-bit build
dstogov Jun 10, 2024
2388a10
Move "zend_ffi_cdata_ce" to Zend to allow JIT<->FFI interopability on…
dstogov Jun 10, 2024
ef0405f
Cache FFI types in opcache SHM (incomplete)
dstogov Jun 14, 2024
2b9a960
Make cached HashTables immutable
dstogov Jun 14, 2024
86005e2
Cache FFI types and scopes in opcache SHM
dstogov Jun 17, 2024
119a440
Fix incorrect return type
dstogov Jun 17, 2024
b9620a3
Cache FFI scope created by FFI::load()
dstogov Jun 17, 2024
d87d621
Add class abd FFI type guards
dstogov Jun 18, 2024
70d96b0
Avoid repeatable FFI type guards (no LICM yet)
dstogov Jun 18, 2024
ee956a7
JIT: Implement special support for FFI "struct" access
dstogov Jun 19, 2024
7b1e039
Fix incorrect 64-bit reads
dstogov Jun 20, 2024
2606d39
Prevent JIT code generation for 64-bit FFI data in 32-bit build
dstogov Jun 20, 2024
9b64623
Synch register allocation rules
dstogov Jun 21, 2024
88d3a2f
Support for assignment FFI CData to another CData array/struct
dstogov Jun 21, 2024
77d663d
Disable modification of "const" fields
dstogov Jun 24, 2024
ff18925
JIT to read FFI variables
dstogov Jun 24, 2024
2d5b0ff
Add FFI class and cdef guards
dstogov Jun 24, 2024
324fa74
JIT to write to FFI variables
dstogov Jun 24, 2024
5facfdb
Fix 32-bit build
dstogov Jun 25, 2024
3fbd43a
Fix Windows build
dstogov Jun 25, 2024
413cf85
JIT support for FFI calls (incomplete)
dstogov Jun 27, 2024
c7cf1b9
Fix memory leaks
dstogov Jun 27, 2024
c70c7ce
iFix build wthout FFI
dstogov Jun 27, 2024
e7c05a3
Make predefined types pesistent
dstogov Jun 27, 2024
6033912
Reset persistent attribute
dstogov Jun 27, 2024
2847bbf
Make FFI type cache context senseive
dstogov Jul 3, 2024
51fdbdb
Cleanup pointer compression
dstogov Jul 3, 2024
ce6721f
Add symbols guard
dstogov Jul 3, 2024
1891126
Allow JIT for reading FFI arrays/structs/pointers
dstogov Jul 3, 2024
239b023
Fix registers update
dstogov Jul 4, 2024
7f3be2e
FFI and CData are "final" classes. Their object handlers can't be cal…
dstogov Jul 4, 2024
424f09d
Support for FFI pointer math
dstogov Jul 4, 2024
13bc3de
Support for ASSIGN_OBJ/DIM with result
dstogov Jul 4, 2024
0c735ee
Support for FFI pointer assignment
dstogov Jul 4, 2024
473b9c4
FFI JIT for FETCH_DIM/OBJ_W
dstogov Jul 4, 2024
fdc2bcc
Fix uninitialized data access
dstogov Jul 5, 2024
2b369b0
Fix calling convention
dstogov Jul 5, 2024
1fdf332
FFI JIT for FETCH_DIM/OBJ_W + ASSIGN_DIM
dstogov Jul 5, 2024
45ded20
FFI JIT for FETCH_DIM_RW + ASSIGN_DIM_OP
dstogov Jul 5, 2024
6ba17bb
FFI JIT for PRE/POST_INC/DEC_OBJ
dstogov Jul 5, 2024
137c869
Remove useless checks
dstogov Jul 25, 2024
44de6f4
Move FFI related JIT code generation into zend_jit_ir_ffi.c
dstogov Jul 25, 2024
5c46d94
Better JIT support for FFI function calls
dstogov Jul 26, 2024
788ee84
JIT/FFI support for "cdata" property of scalar ffi objects
dstogov Jul 30, 2024
d5ae4da
Avoid modification of "const" CData
dstogov Jul 30, 2024
9c73df9
Add JIT/FFI tests
dstogov Jul 30, 2024
d29afc8
Add SKIPIF sectionis and "stdout" recovery code
dstogov Jul 30, 2024
819f39d
Reciver "stdout" before calling var_dump()
dstogov Jul 30, 2024
2abbe8d
Add EXTENSIONS section
dstogov Jul 30, 2024
d688505
Fix SKIPIF sections
dstogov Jul 30, 2024
913c0cd
JIT/FFI support for closure calls (pointers to functions)
dstogov Aug 5, 2024
c8c951b
JIT/FFI cleanup arguments
dstogov Aug 5, 2024
2c4d943
FFI/JIT better support for enums
dstogov Aug 5, 2024
4f55a31
JIT/FFI add tet for closure call
dstogov Aug 6, 2024
893e834
JIT/FFI print FFI types in JIT debug traces
dstogov Aug 6, 2024
df1befe
JIT/FFI support for temporary POINTER types (e.g. created by FFI::addr)
dstogov Aug 6, 2024
29278f9
JIT/FFI better support for temporary POINTER types
dstogov Aug 6, 2024
c1a7a72
Fixed support for lazy objects
dstogov Sep 10, 2024
ed8f25e
Fix register allocation
dstogov Sep 17, 2024
68d9d2f
Use signed comparison
dstogov Sep 19, 2024
f59d92d
Improve register allocation
dstogov Sep 19, 2024
528eec9
Fix tests for 32-bit systems
dstogov Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ ZEND_API void (*zend_post_shutdown_cb)(void) = NULL;
ZEND_ATTRIBUTE_NONNULL ZEND_API zend_result (*zend_random_bytes)(void *bytes, size_t size, char *errstr, size_t errstr_size) = NULL;
ZEND_ATTRIBUTE_NONNULL ZEND_API void (*zend_random_bytes_insecure)(zend_random_bytes_insecure_state *state, void *bytes, size_t size) = NULL;

ZEND_API zend_class_entry *zend_ffi_ce = NULL;
ZEND_API zend_class_entry *zend_ffi_cdata_ce = NULL;
ZEND_API zend_ffi_cdata* (*zend_ffi_cdata_create)(void *ptr, zend_ffi_type *type) = NULL;
ZEND_API zend_ffi_dcl* (*zend_ffi_cache_type_get)(zend_string *str, void *context) = NULL;
ZEND_API zend_ffi_dcl* (*zend_ffi_cache_type_add)(zend_string *str, zend_ffi_dcl *dcl, void *context) = NULL;
ZEND_API zend_ffi_scope* (*zend_ffi_cache_scope_get)(zend_string *str) = NULL;
ZEND_API zend_ffi_scope* (*zend_ffi_cache_scope_add)(zend_string *str, zend_ffi_scope *scope) = NULL;
ZEND_API void (*zend_ffi_type_print)(FILE *f, const zend_ffi_type *type) = NULL;

/* This callback must be signal handler safe! */
void (*zend_on_timeout)(int seconds);

Expand Down
16 changes: 16 additions & 0 deletions Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,22 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_strerror_noreturn(int type, int errn,
extern ZEND_API zend_class_entry *zend_standard_class_def;
extern ZEND_API zend_utility_values zend_uv;

/* FFI/OPCache interopability API */
extern ZEND_API zend_class_entry *zend_ffi_ce;
extern ZEND_API zend_class_entry *zend_ffi_cdata_ce;

typedef struct _zend_ffi_dcl zend_ffi_dcl;
typedef struct _zend_ffi_scope zend_ffi_scope;
typedef struct _zend_ffi_cdata zend_ffi_cdata;
typedef struct _zend_ffi_type zend_ffi_type;

ZEND_API extern zend_ffi_cdata* (*zend_ffi_cdata_create)(void *ptr, zend_ffi_type *type);
ZEND_API extern zend_ffi_dcl* (*zend_ffi_cache_type_get)(zend_string *str, void *context);
ZEND_API extern zend_ffi_dcl* (*zend_ffi_cache_type_add)(zend_string *str, zend_ffi_dcl *dcl, void *context);
ZEND_API extern zend_ffi_scope* (*zend_ffi_cache_scope_get)(zend_string *str);
ZEND_API extern zend_ffi_scope* (*zend_ffi_cache_scope_add)(zend_string *str, zend_ffi_scope *scope);
ZEND_API extern void (*zend_ffi_type_print)(FILE *f, const zend_ffi_type *type);

/* If DTrace is available and enabled */
extern ZEND_API bool zend_dtrace_enabled;
END_EXTERN_C()
Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,8 @@ static zend_always_inline uint32_t zval_gc_info(uint32_t gc_type_info) {
#define IS_STR_PERSISTENT GC_PERSISTENT /* allocated using malloc */
#define IS_STR_PERMANENT (1<<8) /* relives request boundary */
#define IS_STR_VALID_UTF8 (1<<9) /* valid UTF-8 according to PCRE */
#define IS_STR_FFI_TYPE (1<<10) /* intrned string associated with FFI type */
#define IS_STR_FFI_SCOPE (1<<11) /* intrned string associated with FFI declaration object */

/* array flags */
#define IS_ARRAY_IMMUTABLE GC_IMMUTABLE
Expand Down
Loading
Loading