Skip to content

Commit 5e14b51

Browse files
committed
Move weakref key to zend_object* conversions to zend_weakrefs.h
Make it public for any extensions that need to work with EG(weakrefs) for instrumentation, debugging, etc. PHP 8.1 and below would use the raw pointer value instead.
1 parent 5b99401 commit 5e14b51

File tree

3 files changed

+27
-54
lines changed

3 files changed

+27
-54
lines changed

Zend/zend_weakrefs.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,6 @@ typedef struct _zend_weakmap_iterator {
5252
#define ZEND_WEAKREF_GET_PTR(p) ((void *) (((uintptr_t) (p)) & ~3))
5353
#define ZEND_WEAKREF_ENCODE(p, t) ((void *) (((uintptr_t) (p)) | (t)))
5454

55-
/* Because php uses the raw numbers as a hash function, raw pointers will lead to hash collisions.
56-
* We have a guarantee that the lowest ZEND_MM_ALIGNED_OFFSET_LOG2 bits of a pointer are zero.
57-
*
58-
* E.g. On most 64-bit platforms, pointers are aligned to 8 bytes, so the least significant 3 bits are always 0 and can be discarded.
59-
*
60-
* NOTE: This function is only used for EG(weakrefs) and zend_weakmap->ht.
61-
* It is not used for the HashTable instances associated with ZEND_WEAKREF_TAG_HT tags (created in zend_weakref_register, which uses ZEND_WEAKREF_ENCODE instead).
62-
* The ZEND_WEAKREF_TAG_HT instances are used to disambiguate between multiple weak references to the same zend_object.
63-
*/
64-
static zend_always_inline zend_ulong zend_object_ptr_to_weakref_key(const zend_object *object)
65-
{
66-
ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
67-
return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
68-
}
69-
70-
static zend_always_inline zend_object *zend_weakref_key_to_zend_object_ptr(zend_ulong key)
71-
{
72-
return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
73-
}
74-
7555
zend_class_entry *zend_ce_weakref;
7656
zend_class_entry *zend_ce_weakmap;
7757
static zend_object_handlers zend_weakref_handlers;

Zend/zend_weakrefs.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef ZEND_WEAKREFS_H
1818
#define ZEND_WEAKREFS_H
1919

20+
#include "zend_alloc.h"
21+
2022
BEGIN_EXTERN_C()
2123

2224
extern ZEND_API zend_class_entry *zend_ce_weakref;
@@ -40,6 +42,26 @@ static zend_always_inline void *zend_weakrefs_hash_add_ptr(HashTable *ht, zend_o
4042
}
4143
}
4244

45+
/* Because php uses the raw numbers as a hash function, raw pointers will lead to hash collisions.
46+
* We have a guarantee that the lowest ZEND_MM_ALIGNED_OFFSET_LOG2 bits of a pointer are zero.
47+
*
48+
* E.g. On most 64-bit platforms, pointers are aligned to 8 bytes, so the least significant 3 bits are always 0 and can be discarded.
49+
*
50+
* NOTE: This function is only used for EG(weakrefs) and zend_weakmap->ht.
51+
* It is not used for the HashTable instances associated with ZEND_WEAKREF_TAG_HT tags (created in zend_weakref_register, which uses ZEND_WEAKREF_ENCODE instead).
52+
* The ZEND_WEAKREF_TAG_HT instances are used to disambiguate between multiple weak references to the same zend_object.
53+
*/
54+
static zend_always_inline zend_ulong zend_object_ptr_to_weakref_key(const zend_object *object)
55+
{
56+
ZEND_ASSERT(((uintptr_t)object) % ZEND_MM_ALIGNMENT == 0);
57+
return ((uintptr_t) object) >> ZEND_MM_ALIGNMENT_LOG2;
58+
}
59+
60+
static zend_always_inline zend_object *zend_weakref_key_to_zend_object_ptr(zend_ulong key)
61+
{
62+
return (zend_object *) (((uintptr_t) key) << ZEND_MM_ALIGNMENT_LOG2);
63+
}
64+
4365
END_EXTERN_C()
4466

4567
#endif

travis/compile.sh

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
11
#!/bin/bash
2-
set -ex
3-
if [[ "$ENABLE_ZTS" == 1 ]]; then
4-
TS="--enable-zts";
5-
else
6-
TS="";
7-
fi
8-
if [[ "$ENABLE_DEBUG" == 1 ]]; then
9-
DEBUG="--enable-debug";
10-
else
11-
DEBUG="";
12-
fi
13-
if [[ "$S390X" == 1 ]]; then
14-
S390X_CONFIG="--without-pcre-jit";
15-
else
16-
S390X_CONFIG="";
17-
fi
182

193
./buildconf --force
204
./configure \
21-
--enable-option-checking=fatal \
22-
--prefix="$HOME"/php-install \
23-
$CONFIG_QUIET \
24-
$DEBUG \
25-
$TS \
26-
$S390X_CONFIG \
5+
--prefix=/home/tyson/php-8.2.0-weakmap-second-optimization \
276
--enable-phpdbg \
287
--enable-fpm \
298
--with-pdo-mysql=mysqlnd \
@@ -32,10 +11,9 @@ $S390X_CONFIG \
3211
--with-pdo-pgsql \
3312
--with-pdo-sqlite \
3413
--enable-intl \
35-
--without-pear \
14+
--with-pear \
3615
--enable-gd \
3716
--with-jpeg \
38-
--with-webp \
3917
--with-freetype \
4018
--with-xpm \
4119
--enable-exif \
@@ -63,16 +41,9 @@ $S390X_CONFIG \
6341
--enable-ftp \
6442
--with-pspell=/usr \
6543
--with-enchant=/usr \
66-
--with-kerberos \
6744
--enable-sysvmsg \
6845
--with-ffi \
69-
--with-sodium \
70-
--enable-zend-test=shared \
71-
--enable-werror \
72-
--with-pear
46+
--enable-zend-test=shared
7347

74-
if [[ -z "$CONFIG_ONLY" ]]; then
75-
MAKE_JOBS=${MAKE_JOBS:-$(nproc)}
76-
make "-j${MAKE_JOBS}" $MAKE_QUIET
77-
make install
78-
fi
48+
make -j9 | tee my_compile.log
49+
make install

0 commit comments

Comments
 (0)