summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-03-29 01:32:44 +0100
committerOndřej Surý <ondrej@sury.org>2013-03-29 01:32:44 +0100
commitcf099ba2ee4e438bae16c3670a14ce0c4390529a (patch)
tree062683b6a7226ded35262e94c933b9bd81199314 /ext/opcache
parentf21eff8954d5956842795ea5653a9a5b8d62caa3 (diff)
downloadphp-upstream/5.5.0_beta2.tar.gz
Imported Upstream version 5.5.0~beta2upstream/5.5.0_beta2
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/Optimizer/block_pass.c4
-rw-r--r--ext/opcache/Optimizer/pass1_5.c4
-rw-r--r--ext/opcache/README6
-rw-r--r--ext/opcache/ZendAccelerator.c33
-rw-r--r--ext/opcache/ZendAccelerator.h6
-rw-r--r--ext/opcache/config.m433
-rw-r--r--ext/opcache/shared_alloc_win32.c2
-rw-r--r--ext/opcache/tests/bug64482.inc2
-rw-r--r--ext/opcache/tests/bug64482.phpt17
-rw-r--r--ext/opcache/zend_accelerator_module.c1
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c2
-rw-r--r--ext/opcache/zend_shared_alloc.c14
-rw-r--r--ext/opcache/zend_shared_alloc.h4
13 files changed, 106 insertions, 22 deletions
diff --git a/ext/opcache/Optimizer/block_pass.c b/ext/opcache/Optimizer/block_pass.c
index d4299c8ad..7fd986ca6 100644
--- a/ext/opcache/Optimizer/block_pass.c
+++ b/ext/opcache/Optimizer/block_pass.c
@@ -972,7 +972,11 @@ static void zend_optimize_block(zend_code_block *block, zend_op_array *op_array,
zval result;
if (unary_op) {
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ unary_op(&result, &ZEND_OP1_LITERAL(opline));
+#else
unary_op(&result, &ZEND_OP1_LITERAL(opline) TSRMLS_CC);
+#endif
literal_dtor(&ZEND_OP1_LITERAL(opline));
} else {
/* BOOL */
diff --git a/ext/opcache/Optimizer/pass1_5.c b/ext/opcache/Optimizer/pass1_5.c
index 8938e148c..dc9e7319a 100644
--- a/ext/opcache/Optimizer/pass1_5.c
+++ b/ext/opcache/Optimizer/pass1_5.c
@@ -203,7 +203,11 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
er = EG(error_reporting);
EG(error_reporting) = 0;
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ if (unary_op(&result, &ZEND_OP1_LITERAL(opline)) != SUCCESS) {
+#else
if (unary_op(&result, &ZEND_OP1_LITERAL(opline) TSRMLS_CC) != SUCCESS) {
+#endif
EG(error_reporting) = er;
break;
}
diff --git a/ext/opcache/README b/ext/opcache/README
index f87e1ccbf..03386a0a7 100644
--- a/ext/opcache/README
+++ b/ext/opcache/README
@@ -63,7 +63,11 @@ Configuration Directives
------------------------
opcache.enable (default "1")
- OPcache On/Off switch. When set to Off, code is not optimized.
+ OPcache On/Off switch. When set to Off, code is not optimized and cached.
+
+opcache.enable_cli (default "0")
+ Enables the OPcache for the CLI version of PHP. It's mostly for testing
+ and debugging.
opcache.memory_consumption (default "64")
The OPcache shared memory storage size. The amount of memory for storing
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index 64c5aa8f1..694bbed55 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -134,6 +134,12 @@ static inline int is_stream_path(const char *filename)
return ((*p == ':') && (p - filename > 1) && (p[1] == '/') && (p[2] == '/'));
}
+static inline int is_cachable_stream_path(const char *filename)
+{
+ return memcmp(filename, "file://", sizeof("file://") - 1) == 0 ||
+ memcmp(filename, "phar://", sizeof("phar://") - 1) == 0;
+}
+
/* O+ overrides PHP chdir() function and remembers the current working directory
* in ZCG(cwd) and ZCG(cwd_len). Later accel_getcwd() can use stored value and
* avoid getcwd() call.
@@ -1204,10 +1210,18 @@ static zend_persistent_script *compile_and_cache_file(zend_file_handle *file_han
} else {
*op_array_p = NULL;
if (type == ZEND_REQUIRE) {
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
+#else
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename TSRMLS_CC);
+#endif
zend_bailout();
} else {
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
+#else
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename TSRMLS_CC);
+#endif
}
return NULL;
}
@@ -1365,7 +1379,9 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int
!ZCG(enabled) || !accel_startup_ok ||
(!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
CG(interactive) ||
- (ZCSG(restart_in_progress) && accel_restart_is_active(TSRMLS_C))) {
+ (ZCSG(restart_in_progress) && accel_restart_is_active(TSRMLS_C)) ||
+ (is_stream_path(file_handle->filename) &&
+ !is_cachable_stream_path(file_handle->filename))) {
/* The Accelerator is disabled, act as if without the Accelerator */
return accelerator_orig_compile_file(file_handle, type TSRMLS_CC);
}
@@ -1422,10 +1438,18 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int
zend_stream_open(file_handle->filename, file_handle TSRMLS_CC) == FAILURE) {
#endif
if (type == ZEND_REQUIRE) {
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
+#else
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename TSRMLS_CC);
+#endif
zend_bailout();
} else {
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename);
+#else
zend_message_dispatcher(ZMSG_FAILED_INCLUDE_FOPEN, file_handle->filename TSRMLS_CC);
+#endif
}
return NULL;
}
@@ -1542,7 +1566,11 @@ static zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int
zend_hash_quick_add(&EG(included_files), persistent_script->full_path, persistent_script->full_path_len + 1, persistent_script->hash_value, &dummy, sizeof(void *), NULL);
}
}
+#if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
+ zend_file_handle_dtor(file_handle);
+#else
zend_file_handle_dtor(file_handle TSRMLS_CC);
+#endif
from_shared_memory = 1;
}
@@ -2342,7 +2370,8 @@ static void zend_accel_init_shm(TSRMLS_D)
ZCSG(manual_restarts) = 0;
ZCSG(accelerator_enabled) = 1;
- ZCSG(last_restart_time) = zend_accel_get_time();
+ ZCSG(start_time) = zend_accel_get_time();
+ ZCSG(last_restart_time) = 0;
ZCSG(restart_in_progress) = 0;
zend_shared_alloc_unlock(TSRMLS_C);
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index 3f10630ac..f9b51b0df 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -27,7 +27,7 @@
#endif
#define ACCELERATOR_PRODUCT_NAME "Zend OPcache"
-#define ACCELERATOR_VERSION "7.0.1-dev"
+#define ACCELERATOR_VERSION "7.0.2-dev"
/* 2 - added Profiler support, on 20010712 */
/* 3 - added support for Optimizer's encoded-only-files mode */
/* 4 - works with the new Optimizer, that supports the file format with licenses */
@@ -88,12 +88,13 @@
#define PHP_5_2_X_API_NO 220060519
#define PHP_5_3_X_API_NO 220090626
#define PHP_5_4_X_API_NO 220100525
+#define PHP_5_5_X_API_NO 220121212
/*** file locking ***/
#ifndef ZEND_WIN32
extern int lock_file;
-# if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__)/* Darwin */) || defined(__OpenBSD__) || defined(__NetBSD__)
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (defined(__APPLE__) && defined(__MACH__)/* Darwin */) || defined(__OpenBSD__) || defined(__NetBSD__)
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
struct flock name = {start, len, -1, type, whence}
# elif defined(__svr4__)
@@ -274,6 +275,7 @@ typedef struct _zend_accel_shared_globals {
zend_accel_hash include_paths; /* used "include_path" values */
/* Directives & Maintenance */
+ time_t start_time;
time_t last_restart_time;
time_t force_restart_time;
zend_bool accelerator_enabled;
diff --git a/ext/opcache/config.m4 b/ext/opcache/config.m4
index cbf7d5a19..f9c38b1f7 100644
--- a/ext/opcache/config.m4
+++ b/ext/opcache/config.m4
@@ -325,6 +325,39 @@ int main() {
AC_DEFINE(HAVE_SHM_MMAP_FILE, 1, [Define if you have mmap() SHM support])
msg=yes,msg=no,msg=no)
AC_MSG_RESULT([$msg])
+
+ AC_MSG_CHECKING(for known struct flock definition)
+ dnl Copied from ZendAccelerator.h
+ AC_TRY_RUN([
+#include <fcntl.h>
+#include <stdlib.h>
+
+#ifndef ZEND_WIN32
+extern int lock_file;
+
+# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || (defined(__APPLE__) && defined(__MACH__)/* Darwin */) || defined(__OpenBSD__) || defined(__NetBSD__)
+# define FLOCK_STRUCTURE(name, type, whence, start, len) \
+ struct flock name = {start, len, -1, type, whence}
+# elif defined(__svr4__)
+# define FLOCK_STRUCTURE(name, type, whence, start, len) \
+ struct flock name = {type, whence, start, len}
+# elif defined(__linux__) || defined(__hpux)
+# define FLOCK_STRUCTURE(name, type, whence, start, len) \
+ struct flock name = {type, whence, start, len, 0}
+# elif defined(_AIX)
+# if defined(_LARGE_FILES) || defined(__64BIT__)
+# define FLOCK_STRUCTURE(name, type, whence, start, len) \
+ struct flock name = {type, whence, 0, 0, 0, start, len }
+# else
+# define FLOCK_STRUCTURE(name, type, whence, start, len) \
+ struct flock name = {type, whence, start, len}
+# endif
+# else
+# error "Don't know how to define struct flock"
+# endif
+#endif
+int main() { return 0; }
+], [], [AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])], [])
PHP_NEW_EXTENSION(opcache,
ZendAccelerator.c \
diff --git a/ext/opcache/shared_alloc_win32.c b/ext/opcache/shared_alloc_win32.c
index e32395284..2c3218414 100644
--- a/ext/opcache/shared_alloc_win32.c
+++ b/ext/opcache/shared_alloc_win32.c
@@ -166,7 +166,7 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
}
return ALLOC_FAIL_MAPPING;
}
- smm_shared_globals = (zend_smm_shared_globals *) (((char *) mapping_base) + sizeof(zend_shared_memory_block_header));
+ smm_shared_globals = (zend_smm_shared_globals *) mapping_base;
return SUCCESSFULLY_REATTACHED;
}
diff --git a/ext/opcache/tests/bug64482.inc b/ext/opcache/tests/bug64482.inc
new file mode 100644
index 000000000..e3d2b210c
--- /dev/null
+++ b/ext/opcache/tests/bug64482.inc
@@ -0,0 +1,2 @@
+<?php
+echo "Dynamic include";
diff --git a/ext/opcache/tests/bug64482.phpt b/ext/opcache/tests/bug64482.phpt
new file mode 100644
index 000000000..fa722f6d4
--- /dev/null
+++ b/ext/opcache/tests/bug64482.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Bug #64482 (Opcodes for dynamic includes should not be cached)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+include 'bug64482.inc';
+echo "\n";
+include 'php://filter/read=string.toupper/resource=bug64482.inc';
+echo "\n";
+?>
+--EXPECT--
+Dynamic include
+DYNAMIC INCLUDE
diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c
index 778fee54b..0d452adf8 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -503,6 +503,7 @@ static ZEND_FUNCTION(opcache_get_status)
add_assoc_long(statistics, "num_cached_keys", ZCSG(hash).num_entries);
add_assoc_long(statistics, "max_cached_keys", ZCSG(hash).max_num_entries);
add_assoc_long(statistics, "hits", ZCSG(hits));
+ add_assoc_long(statistics, "start_time", ZCSG(start_time));
add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time));
add_assoc_long(statistics, "oom_restarts", ZCSG(oom_restarts));
add_assoc_long(statistics, "wasted_restarts", ZCSG(wasted_restarts));
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index 7d5028c4c..75b156171 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -857,7 +857,7 @@ static void zend_do_delayed_early_binding(zend_op_array *op_array, zend_uint ear
}
opline_num = op_array->opcodes[opline_num].result.u.opline_num;
}
- zend_restore_compiled_filename(orig_compiled_filename);
+ zend_restore_compiled_filename(orig_compiled_filename TSRMLS_CC);
CG(in_compilation) = orig_in_compilation;
}
}
diff --git a/ext/opcache/zend_shared_alloc.c b/ext/opcache/zend_shared_alloc.c
index f4465ce78..18e8bdb1f 100644
--- a/ext/opcache/zend_shared_alloc.c
+++ b/ext/opcache/zend_shared_alloc.c
@@ -284,7 +284,7 @@ static size_t zend_shared_alloc_get_largest_free_block(void)
void *zend_shared_alloc(size_t size)
{
int i;
- unsigned int block_size = size + sizeof(zend_shared_memory_block_header);
+ unsigned int block_size = ZEND_ALIGNED_SIZE(size);
TSRMLS_FETCH();
#if 1
@@ -298,19 +298,11 @@ void *zend_shared_alloc(size_t size)
}
for (i = 0; i < ZSMMG(shared_segments_count); i++) {
if (ZSMMG(shared_segments)[i]->size - ZSMMG(shared_segments)[i]->pos >= block_size) { /* found a valid block */
- zend_shared_memory_block_header *p = (zend_shared_memory_block_header *) (((char *) ZSMMG(shared_segments)[i]->p) + ZSMMG(shared_segments)[i]->pos);
- int remainder = block_size % PLATFORM_ALIGNMENT;
- void *retval;
+ void *retval = (void *) (((char *) ZSMMG(shared_segments)[i]->p) + ZSMMG(shared_segments)[i]->pos);
- if (remainder != 0) {
- size += PLATFORM_ALIGNMENT - remainder;
- block_size += PLATFORM_ALIGNMENT - remainder;
- }
ZSMMG(shared_segments)[i]->pos += block_size;
ZSMMG(shared_free) -= block_size;
- p->size = size;
- retval = ((char *) p) + sizeof(zend_shared_memory_block_header);
- memset(retval, 0, size);
+ memset(retval, 0, block_size);
return retval;
}
}
diff --git a/ext/opcache/zend_shared_alloc.h b/ext/opcache/zend_shared_alloc.h
index 23af630f8..b7f36299b 100644
--- a/ext/opcache/zend_shared_alloc.h
+++ b/ext/opcache/zend_shared_alloc.h
@@ -89,10 +89,6 @@ typedef struct _handler_entry {
zend_shared_memory_handlers *handler;
} zend_shared_memory_handler_entry;
-typedef struct _zend_shared_memory_block_header {
- int size;
-} zend_shared_memory_block_header;
-
typedef struct _zend_shared_memory_state {
int *positions; /* current positions for each segment */
int shared_free; /* amount of free shared memory */