php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56103 optimizer hang, taking up 40% cpu usage
Submitted: 2004-06-19 01:06 UTC Modified: 2013-02-05 05:39 UTC
From: xuefer at 21cn dot com Assigned:
Status: Wont fix Package: APC (PECL)
PHP Version: 4.3.3 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xuefer at 21cn dot com
New email:
PHP Version: OS:

 

 [2004-06-19 01:06 UTC] xuefer at 21cn dot com
Description:
------------
apc.optimization=1

i have tested on my code, but i don't have a stripped down testcase script
this patch solved the problem.
logically, RESTART_PEEPHOLE_LOOP should be done only when opcode is modified
apc is still SEGV with this patch for my script, but at least it won't hang

Index: apc_optimizer.c
===================================================================
RCS file: /repository/pecl/apc/apc_optimizer.c,v
retrieving revision 3.24
diff -u -r3.24 apc_optimizer.c
--- apc_optimizer.c     20 Jul 2003 00:07:02 -0000      3.24
+++ apc_optimizer.c     19 Jun 2004 05:09:40 -0000
@@ -790,15 +790,15 @@
         if ((p = peephole_inc(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_inc(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
         
         if ((p = peephole_print(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_print(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
         
         if ((p = peephole_multiple_echo(op_array->opcodes, i, op_array->last))) {
@@ -810,27 +810,27 @@
         if ((p = peephole_constant_fold(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_constant_fold(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
         
         if ((p = peephole_fcall(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_fcall(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
         if ((p = peephole_add_string(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_add_string(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
         if ((p = peephole_needless_bool(op_array->opcodes, i, op_array->last))) {
             if (!are_branch_targets(cdr(p), jumps)) {
                 rewrite_needless_bool(op_array->opcodes, p);
+                RESTART_PEEPHOLE_LOOP;
             }
-            RESTART_PEEPHOLE_LOOP;
         }
     }
 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-23 12:35 UTC] xuefer at 21cn dot com
this patch
1. fixed for http://pecl.php.net/bugs/bug.php?id=1679
2. improved "Cannot break/continue***", tell which file which line
3. fixed previous patch's memory leak: do pair_destroy(p);
4. comment out "constant_fold", it's not stable, without it all my scripts work fine

Index: apc_optimizer.c
===================================================================
RCS file: /repository/pecl/apc/apc_optimizer.c,v
retrieving revision 3.24
diff -u -r3.24 apc_optimizer.c
--- apc_optimizer.c	20 Jul 2003 00:07:02 -0000	3.24
+++ apc_optimizer.c	23 Jun 2004 16:29:21 -0000
@@ -139,7 +139,10 @@
                 if (ops[j].opcode != ZEND_NOP) {
                     break;
                 }
-                j++;
+                if (++ j >= num_ops) {
+                    j --;
+                    break;
+                }
             }
 
             /* update jump table IFF ops[j] is a branch */
@@ -392,8 +395,10 @@
         array_offset = opline->op1.u.opline_num;
         do {
             if (array_offset < 0) {
-                zend_error(E_ERROR, "Cannot break/continue %d level", 
-                           original_nest_levels);
+                zend_error(E_ERROR, "Cannot break/continue %d level (%s#%d)", 
+                           original_nest_levels,
+                           op_array->filename,
+                           opline->lineno);
             }
             jmp_to = &op_array->brk_cont_array[array_offset];
             if (nest_levels>1) {
@@ -763,6 +768,22 @@
 zend_op_array* apc_optimize_op_array(zend_op_array* op_array)
 {
 #define RESTART_PEEPHOLE_LOOP { pair_destroy(p); i = -1; continue; }
+#define OPTIMIZE1(name) { \
+        if ((p = peephole_ ## name(op_array->opcodes, i, op_array->last))) { \
+            rewrite_ ## name(op_array->opcodes, p); \
+            pair_destroy(p); \
+        } \
+}
+
+#define OPTIMIZE2(name) { \
+        if ((p = peephole_ ## name(op_array->opcodes, i, op_array->last))) { \
+            if (!are_branch_targets(cdr(p), jumps)) { \
+                rewrite_ ## name(op_array->opcodes, p); \
+                RESTART_PEEPHOLE_LOOP; \
+            } \
+            pair_destroy(p); \
+        } \
+}
 
     Pair** jumps;
     int i;
@@ -777,61 +798,17 @@
     for (i = 0; i < op_array->last; i++) {
         Pair* p;
         
-        if ((p = peephole_cast(op_array->opcodes, i, op_array->last))) {
-            rewrite_const_cast(op_array->opcodes, p);
-            RESTART_PEEPHOLE_LOOP;
-        }
-
-        if ((p = peephole_is_equal_bool(op_array->opcodes, i, op_array->last))) {
-            rewrite_is_equal_bool(op_array->opcodes, p);
-            RESTART_PEEPHOLE_LOOP;
-        } 
-        
-        if ((p = peephole_inc(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_inc(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
-        
-        if ((p = peephole_print(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_print(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
-        
-        if ((p = peephole_multiple_echo(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_multiple_echo(op_array->opcodes, p);
-            }
-        } 
-        
-        if ((p = peephole_constant_fold(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_constant_fold(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
-        
-        if ((p = peephole_fcall(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_fcall(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
-        if ((p = peephole_add_string(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_add_string(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
-        if ((p = peephole_needless_bool(op_array->opcodes, i, op_array->last))) {
-            if (!are_branch_targets(cdr(p), jumps)) {
-                rewrite_needless_bool(op_array->opcodes, p);
-            }
-            RESTART_PEEPHOLE_LOOP;
-        }
+        OPTIMIZE1(cast);
+        OPTIMIZE1(is_equal_bool);
+        OPTIMIZE2(inc);
+        OPTIMIZE2(print);
+        OPTIMIZE2(multiple_echo);
+        /* not stable
+        OPTIMIZE2(constant_fold);
+        */
+        OPTIMIZE2(fcall);
+        OPTIMIZE2(add_string);
+        OPTIMIZE2(needless_bool);
     }
 
     op_array->last = compress_ops(op_array, jumps);
@@ -839,6 +816,8 @@
     
     return op_array;
 
+#undef OPTIMIZE1
+#undef OPTIMIZE2
 #undef RESTART_PEEPHOLE_LOOP
 }
 /* }}} */
 [2004-06-23 12:42 UTC] xuefer at 21cn dot com
OPTIMIZE1(cast); should be OPTIMIZE1(const_cast);
and:
@@ -518,7 +523,7 @@
 
 /* {{{ peephole match functions */
 
-static Pair* peephole_cast(zend_op* ops, int i, int num_ops)
+static Pair* peephole_const_cast(zend_op* ops, int i, int num_ops)
 {
     if (ops[i].opcode == ZEND_CAST &&
         ops[i].op1.op_type == IS_CONST &&
 [2013-02-05 05:39 UTC] gopalv@php.net
Optimizer removed from codebase
 [2013-02-05 05:39 UTC] gopalv@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 04:01:28 2024 UTC