XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

700 lines
16 KiB

  1. #include "xc_optimizer.h"
  2. #include "xcache/xc_extension.h"
  3. #include "xcache/xc_ini.h"
  4. #include "xcache/xc_utils.h"
  5. #include "util/xc_vector.h"
  6. #include "util/xc_trace.h"
  7. #include "xcache_globals.h"
  8. #include "ext/standard/info.h"
  9. #ifdef XCACHE_DEBUG
  10. # include "xc_processor.h"
  11. # include "xcache/xc_const_string.h"
  12. # include "xcache/xc_opcode_spec.h"
  13. # include "ext/standard/php_var.h"
  14. #endif
  15. #ifdef IS_CV
  16. # define XCACHE_IS_CV IS_CV
  17. #else
  18. # define XCACHE_IS_CV 16
  19. #endif
  20. #ifdef ZEND_ENGINE_2_4
  21. # undef Z_OP_CONSTANT
  22. /* Z_OP_CONSTANT is used before pass_two is applied */
  23. # define Z_OP_CONSTANT(op) op_array->literals[(op).constant].constant
  24. #endif
  25. typedef zend_uint bbid_t;
  26. #define BBID_INVALID ((bbid_t) -1)
  27. /* {{{ basic block */
  28. typedef struct _bb_t {
  29. bbid_t id;
  30. zend_bool used;
  31. zend_bool alloc;
  32. zend_op *opcodes;
  33. int count;
  34. int size;
  35. bbid_t fall;
  36. zend_uint opnum; /* opnum after joining basic block */
  37. } bb_t;
  38. /* }}} */
  39. /* basic blocks */
  40. typedef xc_vector_t bbs_t;
  41. /* op array helper functions */
  42. static int op_array_convert_switch(zend_op_array *op_array) /* {{{ */
  43. {
  44. zend_uint i;
  45. if (op_array->brk_cont_array == NULL) {
  46. return SUCCESS;
  47. }
  48. for (i = 0; i < op_array->last; i ++) {
  49. zend_op *opline = &op_array->opcodes[i];
  50. zend_brk_cont_element *jmp_to;
  51. zend_bool can_convert = 1;
  52. int array_offset, nest_levels;
  53. switch (opline->opcode) {
  54. case ZEND_BRK:
  55. case ZEND_CONT:
  56. break;
  57. #ifdef ZEND_GOTO
  58. case ZEND_GOTO:
  59. #endif
  60. continue;
  61. default:
  62. continue;
  63. }
  64. if (Z_OP_TYPE(opline->op2) != IS_CONST
  65. || Z_OP_CONSTANT(opline->op2).type != IS_LONG) {
  66. return FAILURE;
  67. }
  68. nest_levels = Z_OP_CONSTANT(opline->op2).value.lval;
  69. array_offset = Z_OP(opline->op1).opline_num;
  70. do {
  71. if (array_offset == -1) {
  72. return FAILURE;
  73. }
  74. jmp_to = &op_array->brk_cont_array[array_offset];
  75. if (nest_levels > 1) {
  76. zend_op *brk_opline = &op_array->opcodes[jmp_to->brk];
  77. switch (brk_opline->opcode) {
  78. case ZEND_SWITCH_FREE:
  79. case ZEND_FREE:
  80. #ifdef EXT_TYPE_FREE_ON_RETURN
  81. if (!(brk_opline->extended_value & EXT_TYPE_FREE_ON_RETURN))
  82. #endif
  83. {
  84. can_convert = 0;
  85. }
  86. break;
  87. }
  88. }
  89. array_offset = jmp_to->parent;
  90. } while (--nest_levels > 0);
  91. if (can_convert) {
  92. /* rewrite to jmp */
  93. switch (opline->opcode) {
  94. case ZEND_BRK:
  95. Z_OP(opline->op1).opline_num = jmp_to->brk;
  96. break;
  97. case ZEND_CONT:
  98. Z_OP(opline->op1).opline_num = jmp_to->cont;
  99. break;
  100. }
  101. Z_OP_TYPE(opline->op2) = IS_UNUSED;
  102. opline->opcode = ZEND_JMP;
  103. }
  104. }
  105. return SUCCESS;
  106. }
  107. /* }}} */
  108. /* {{{ op_flowinfo helper func */
  109. enum {
  110. XC_OPNUM_INVALID = -1
  111. };
  112. typedef struct {
  113. int jmpout_op1;
  114. int jmpout_op2;
  115. int jmpout_ext;
  116. zend_bool fall;
  117. } op_flowinfo_t;
  118. static void op_flowinfo_init(op_flowinfo_t *fi)
  119. {
  120. fi->jmpout_op1 = fi->jmpout_op2 = fi->jmpout_ext = XC_OPNUM_INVALID;
  121. fi->fall = 0;
  122. }
  123. /* }}} */
  124. static int op_get_flowinfo(op_flowinfo_t *fi, zend_op *opline) /* {{{ */
  125. {
  126. op_flowinfo_init(fi);
  127. switch (opline->opcode) {
  128. #ifdef ZEND_HANDLE_EXCEPTION
  129. case ZEND_HANDLE_EXCEPTION:
  130. #endif
  131. case ZEND_RETURN:
  132. #ifdef ZEND_FAST_RET
  133. case ZEND_FAST_RET:
  134. #endif
  135. #ifdef ZEND_GENERATOR_RETURN
  136. case ZEND_GENERATOR_RETURN:
  137. #endif
  138. case ZEND_EXIT:
  139. return SUCCESS; /* no fall */
  140. #ifdef ZEND_GOTO
  141. case ZEND_GOTO:
  142. #endif
  143. case ZEND_JMP:
  144. fi->jmpout_op1 = Z_OP(opline->op1).opline_num;
  145. return SUCCESS; /* no fall */
  146. #ifdef ZEND_FAST_CALL
  147. case ZEND_FAST_CALL:
  148. fi->jmpout_op1 = Z_OP(opline->op1).opline_num;
  149. if (opline->extended_value) {
  150. fi->jmpout_op2 = Z_OP(opline->op2).opline_num;
  151. }
  152. return SUCCESS; /* no fall */
  153. #endif
  154. case ZEND_JMPZNZ:
  155. fi->jmpout_op2 = Z_OP(opline->op2).opline_num;
  156. fi->jmpout_ext = (int) opline->extended_value;
  157. return SUCCESS; /* no fall */
  158. case ZEND_JMPZ:
  159. case ZEND_JMPNZ:
  160. case ZEND_JMPZ_EX:
  161. case ZEND_JMPNZ_EX:
  162. #ifdef ZEND_JMP_SET
  163. case ZEND_JMP_SET:
  164. #endif
  165. #ifdef ZEND_JMP_SET_VAR
  166. case ZEND_JMP_SET_VAR:
  167. #endif
  168. #ifdef ZEND_JMP_NO_CTOR
  169. case ZEND_JMP_NO_CTOR:
  170. #endif
  171. #ifdef ZEND_NEW
  172. case ZEND_NEW:
  173. #endif
  174. #ifdef ZEND_FE_RESET
  175. case ZEND_FE_RESET:
  176. #endif
  177. case ZEND_FE_FETCH:
  178. fi->jmpout_op2 = Z_OP(opline->op2).opline_num;
  179. fi->fall = 1;
  180. return SUCCESS;
  181. #ifdef ZEND_CATCH
  182. case ZEND_CATCH:
  183. fi->jmpout_ext = (int) opline->extended_value;
  184. fi->fall = 1;
  185. return SUCCESS;
  186. #endif
  187. default:
  188. return FAILURE;
  189. }
  190. }
  191. /* }}} */
  192. #ifdef XCACHE_DEBUG
  193. static void op_snprint(zend_op_array *op_array, char *buf, int size, zend_uchar op_type, znode_op *op, xc_op_spec_t op_spec) /* {{{ */
  194. {
  195. switch ((op_spec & OPSPEC_UNUSED) ? IS_UNUSED : op_type) {
  196. case IS_CONST:
  197. {
  198. zval result;
  199. zval *zv = &Z_OP_CONSTANT(*op);
  200. TSRMLS_FETCH();
  201. php_output_start_default(TSRMLS_C);
  202. php_var_export(&zv, 1 TSRMLS_CC);
  203. php_output_get_contents(&result TSRMLS_CC);
  204. php_output_discard(TSRMLS_C);
  205. snprintf(buf, size, Z_STRVAL(result));
  206. zval_dtor(&result);
  207. }
  208. break;
  209. case IS_TMP_VAR:
  210. snprintf(buf, size, "t@%d", Z_OP(*op).var);
  211. break;
  212. case XCACHE_IS_CV:
  213. case IS_VAR:
  214. snprintf(buf, size, "v@%d", Z_OP(*op).var);
  215. break;
  216. case IS_UNUSED:
  217. if (Z_OP(*op).opline_num) {
  218. snprintf(buf, size, "u#%d", Z_OP(*op).opline_num);
  219. }
  220. else {
  221. snprintf(buf, size, "-");
  222. }
  223. break;
  224. default:
  225. snprintf(buf, size, "%d %d", op_type, Z_OP(*op).var);
  226. }
  227. }
  228. /* }}} */
  229. static void op_print(zend_op_array *op_array, int line, zend_op *first, zend_op *end) /* {{{ */
  230. {
  231. zend_op *opline;
  232. for (opline = first; opline < end; opline ++) {
  233. char buf_r[20];
  234. char buf_1[20];
  235. char buf_2[20];
  236. const xc_opcode_spec_t *opcode_spec = xc_get_opcode_spec(opline->opcode);
  237. op_snprint(op_array, buf_r, sizeof(buf_r), Z_OP_TYPE(opline->result), &opline->result, opcode_spec->res);
  238. op_snprint(op_array, buf_1, sizeof(buf_1), Z_OP_TYPE(opline->op1), &opline->op1, opcode_spec->op1);
  239. op_snprint(op_array, buf_2, sizeof(buf_2), Z_OP_TYPE(opline->op2), &opline->op2, opcode_spec->op2);
  240. fprintf(stderr,
  241. "%3d %3lu"
  242. " %-25s%-8s%-20s%-20s%5lu\n"
  243. , opline->lineno, (long) (opline - first + line)
  244. , xc_get_opcode(opline->opcode), buf_r, buf_1, buf_2, opline->extended_value);
  245. }
  246. }
  247. /* }}} */
  248. static void op_array_print_try_catch(zend_op_array *op_array TSRMLS_DC) /* {{{ */
  249. {
  250. int i;
  251. for (i = 0; i < op_array->last_try_catch; i ++) {
  252. zend_try_catch_element *element = &op_array->try_catch_array[i];
  253. # ifdef ZEND_ENGINE_2_5
  254. fprintf(stderr, "try_catch[%d] = %u, %u, %u, %u\n", i, element->try_op, element->catch_op, element->finally_op, element->finally_end);
  255. # else
  256. fprintf(stderr, "try_catch[%d] = %u, %u\n", i, element->try_op, element->catch_op);
  257. # endif
  258. }
  259. }
  260. /* }}} */
  261. #endif
  262. /*
  263. * basic block functions
  264. */
  265. static bb_t *bb_new_ex(zend_op *opcodes, int count) /* {{{ */
  266. {
  267. bb_t *bb = (bb_t *) ecalloc(sizeof(bb_t), 1);
  268. bb->fall = BBID_INVALID;
  269. if (opcodes) {
  270. bb->alloc = 0;
  271. bb->size = bb->count = count;
  272. bb->opcodes = opcodes;
  273. }
  274. else {
  275. bb->alloc = 1;
  276. bb->size = bb->count = 8;
  277. bb->opcodes = ecalloc(sizeof(zend_op), bb->size);
  278. }
  279. return bb;
  280. }
  281. /* }}} */
  282. #define bb_new() bb_new_ex(NULL, 0)
  283. static void bb_destroy(bb_t *bb) /* {{{ */
  284. {
  285. if (bb->alloc) {
  286. efree(bb->opcodes);
  287. }
  288. efree(bb);
  289. }
  290. /* }}} */
  291. #ifdef XCACHE_DEBUG
  292. static void bb_print(bb_t *bb, zend_op_array *op_array) /* {{{ */
  293. {
  294. int line = bb->opcodes - op_array->opcodes;
  295. op_flowinfo_t fi;
  296. zend_op *last = bb->opcodes + bb->count - 1;
  297. op_get_flowinfo(&fi, last);
  298. fprintf(stderr,
  299. "\n==== #%-3d cnt:%-3d lno:%-3d"
  300. " %c%c"
  301. " op1:%-3d op2:%-3d ext:%-3d fal:%-3d %s ====\n"
  302. , bb->id, bb->count, bb->alloc ? -1 : line
  303. , bb->used ? 'U' : ' ', bb->alloc ? 'A' : ' '
  304. , fi.jmpout_op1, fi.jmpout_op2, fi.jmpout_ext, bb->fall, xc_get_opcode(last->opcode)
  305. );
  306. op_print(op_array, line, bb->opcodes, last + 1);
  307. }
  308. /* }}} */
  309. #endif
  310. static bb_t *bbs_get(bbs_t *bbs, int n) /* {{{ */
  311. {
  312. return xc_vector_data(bb_t *, bbs)[n];
  313. }
  314. /* }}} */
  315. static int bbs_count(bbs_t *bbs) /* {{{ */
  316. {
  317. return xc_vector_size(bbs);
  318. }
  319. /* }}} */
  320. static void bbs_destroy(bbs_t *bbs TSRMLS_DC) /* {{{ */
  321. {
  322. bb_t *bb;
  323. while (bbs_count(bbs)) {
  324. bb = xc_vector_pop_back(bb_t *, bbs);
  325. bb_destroy(bb);
  326. }
  327. xc_vector_destroy(bbs);
  328. }
  329. /* }}} */
  330. #ifdef XCACHE_DEBUG
  331. static void bbs_print(bbs_t *bbs, zend_op_array *op_array) /* {{{ */
  332. {
  333. int i;
  334. for (i = 0; i < xc_vector_size(bbs); i ++) {
  335. bb_print(bbs_get(bbs, i), op_array);
  336. }
  337. }
  338. /* }}} */
  339. #endif
  340. #define bbs_init(bbs) xc_vector_init(bb_t *, bbs, 0)
  341. #define bbs_initializer() xc_vector_initializer(bb_t *, 0)
  342. static bb_t *bbs_add_bb(bbs_t *bbs, bb_t *bb TSRMLS_DC) /* {{{ */
  343. {
  344. bb->id = (bbid_t) bbs_count(bbs);
  345. xc_vector_push_back(bbs, &bb);
  346. return bb;
  347. }
  348. /* }}} */
  349. static bb_t *bbs_new_bb_ex(bbs_t *bbs, zend_op *opcodes, int count TSRMLS_DC) /* {{{ */
  350. {
  351. return bbs_add_bb(bbs, bb_new_ex(opcodes, count) TSRMLS_CC);
  352. }
  353. /* }}} */
  354. static int bbs_build_from(bbs_t *bbs, zend_op_array *op_array, int count TSRMLS_DC) /* {{{ */
  355. {
  356. int i, start;
  357. bb_t *bb;
  358. bbid_t id;
  359. op_flowinfo_t fi;
  360. zend_op *opline;
  361. ALLOCA_FLAG(opline_infos_use_heap)
  362. typedef struct {
  363. zend_bool isbbhead;
  364. bbid_t bbid;
  365. } oplineinfo_t;
  366. oplineinfo_t *oplineinfos = xc_do_alloca(count * sizeof(oplineinfo_t), opline_infos_use_heap);
  367. memset(oplineinfos, 0, count * sizeof(oplineinfo_t));
  368. /* {{{ mark jmpin/jumpout */
  369. oplineinfos[0].isbbhead = 1;
  370. for (i = 0; i < count; i ++) {
  371. if (op_get_flowinfo(&fi, &op_array->opcodes[i]) == SUCCESS) {
  372. if (fi.jmpout_op1 != XC_OPNUM_INVALID) {
  373. oplineinfos[fi.jmpout_op1].isbbhead = 1;
  374. }
  375. if (fi.jmpout_op2 != XC_OPNUM_INVALID) {
  376. oplineinfos[fi.jmpout_op2].isbbhead = 1;
  377. }
  378. if (fi.jmpout_ext != XC_OPNUM_INVALID) {
  379. oplineinfos[fi.jmpout_ext].isbbhead = 1;
  380. }
  381. if (i + 1 < count) {
  382. oplineinfos[i + 1].isbbhead = 1;
  383. }
  384. }
  385. }
  386. #ifdef ZEND_ENGINE_2
  387. /* mark try start */
  388. for (i = 0; i < op_array->last_try_catch; i ++) {
  389. # define MARK_OP_BB_HEAD(name) \
  390. oplineinfos[op_array->try_catch_array[i].name].isbbhead = 1
  391. MARK_OP_BB_HEAD(try_op);
  392. MARK_OP_BB_HEAD(catch_op);
  393. # ifdef ZEND_ENGINE_2_5
  394. MARK_OP_BB_HEAD(finally_op);
  395. # endif
  396. # undef MARK_OP_BB_HEAD
  397. }
  398. #endif
  399. /* }}} */
  400. /* {{{ fill op lines with newly allocated id */
  401. for (i = 0; i < count; i ++) {
  402. oplineinfos[i].bbid = BBID_INVALID;
  403. }
  404. id = -1;
  405. for (i = 0; i < count; i ++) {
  406. if (oplineinfos[i].isbbhead) {
  407. id ++;
  408. }
  409. oplineinfos[i].bbid = id;
  410. TRACE("bbids[%d] = %d", i, id);
  411. }
  412. /* }}} */
  413. #ifdef ZEND_ENGINE_2
  414. /* {{{ convert try_catch_array.* from oplinenum to bbid */
  415. for (i = 0; i < op_array->last_try_catch; i ++) {
  416. # define OPNUM_TO_BBID(name) \
  417. op_array->try_catch_array[i].name = oplineinfos[op_array->try_catch_array[i].name].bbid;
  418. OPNUM_TO_BBID(try_op);
  419. OPNUM_TO_BBID(catch_op);
  420. # ifdef ZEND_ENGINE_2_5
  421. OPNUM_TO_BBID(finally_op);
  422. # endif
  423. # undef OPNUM_TO_BBID
  424. }
  425. /* }}} */
  426. #endif
  427. /* {{{ create basic blocks */
  428. start = 0;
  429. id = 0;
  430. /* loop over to deal with the last block */
  431. for (i = 1; i <= count; i ++) {
  432. if (i < count && id == oplineinfos[i].bbid) {
  433. continue;
  434. }
  435. opline = op_array->opcodes + start;
  436. bb = bbs_new_bb_ex(bbs, opline, i - start TSRMLS_CC);
  437. /* last */
  438. opline = bb->opcodes + bb->count - 1;
  439. if (op_get_flowinfo(&fi, opline) == SUCCESS) {
  440. if (fi.jmpout_op1 != XC_OPNUM_INVALID) {
  441. Z_OP(opline->op1).opline_num = oplineinfos[fi.jmpout_op1].bbid;
  442. assert(Z_OP(opline->op1).opline_num != BBID_INVALID);
  443. }
  444. if (fi.jmpout_op2 != XC_OPNUM_INVALID) {
  445. Z_OP(opline->op2).opline_num = oplineinfos[fi.jmpout_op2].bbid;
  446. assert(Z_OP(opline->op2).opline_num != BBID_INVALID);
  447. }
  448. if (fi.jmpout_ext != XC_OPNUM_INVALID) {
  449. opline->extended_value = oplineinfos[fi.jmpout_ext].bbid;
  450. assert(opline->extended_value != BBID_INVALID);
  451. }
  452. if (fi.fall && i + 1 < count) {
  453. bb->fall = oplineinfos[i + 1].bbid;
  454. TRACE("fall %d", bb->fall);
  455. assert(bb->fall != BBID_INVALID);
  456. }
  457. }
  458. if (i >= count) {
  459. break;
  460. }
  461. start = i;
  462. id = oplineinfos[i].bbid;
  463. }
  464. /* }}} */
  465. xc_free_alloca(oplineinfos, opline_infos_use_heap);
  466. return SUCCESS;
  467. }
  468. /* }}} */
  469. static void bbs_restore_opnum(bbs_t *bbs, zend_op_array *op_array) /* {{{ */
  470. {
  471. int bbid;
  472. int i;
  473. for (bbid = 0; bbid < bbs_count(bbs); bbid ++) {
  474. op_flowinfo_t fi;
  475. bb_t *bb = bbs_get(bbs, bbid);
  476. zend_op *last = bb->opcodes + bb->count - 1;
  477. if (op_get_flowinfo(&fi, last) == SUCCESS) {
  478. if (fi.jmpout_op1 != XC_OPNUM_INVALID) {
  479. Z_OP(last->op1).opline_num = bbs_get(bbs, fi.jmpout_op1)->opnum;
  480. assert(Z_OP(last->op1).opline_num != BBID_INVALID);
  481. }
  482. if (fi.jmpout_op2 != XC_OPNUM_INVALID) {
  483. Z_OP(last->op2).opline_num = bbs_get(bbs, fi.jmpout_op2)->opnum;
  484. assert(Z_OP(last->op2).opline_num != BBID_INVALID);
  485. }
  486. if (fi.jmpout_ext != XC_OPNUM_INVALID) {
  487. last->extended_value = bbs_get(bbs, fi.jmpout_ext)->opnum;
  488. assert(last->extended_value != BBID_INVALID);
  489. }
  490. }
  491. }
  492. #ifdef ZEND_ENGINE_2
  493. /* {{{ convert try_catch_array from bbid to oplinenum */
  494. for (i = 0; i < op_array->last_try_catch; i ++) {
  495. # define BBID_TO_OPNUM(name) \
  496. op_array->try_catch_array[i].name = bbs_get(bbs, op_array->try_catch_array[i].name)->opnum;
  497. BBID_TO_OPNUM(try_op);
  498. BBID_TO_OPNUM(catch_op);
  499. # ifdef ZEND_ENGINE_2_5
  500. BBID_TO_OPNUM(finally_op);
  501. # endif
  502. # undef BBID_TO_OPNUM
  503. }
  504. /* }}} */
  505. #endif /* ZEND_ENGINE_2 */
  506. }
  507. /* }}} */
  508. /*
  509. * optimize
  510. */
  511. static int xc_optimize_op_array(zend_op_array *op_array TSRMLS_DC) /* {{{ */
  512. {
  513. if (op_array->type != ZEND_USER_FUNCTION) {
  514. return 0;
  515. }
  516. #ifdef XCACHE_DEBUG
  517. TRACE("optimize file: %s", op_array->filename);
  518. # if 0 && HAVE_XCACHE_DPRINT
  519. xc_dprint_zend_op_array(op_array, 0 TSRMLS_CC);
  520. # endif
  521. op_array_print_try_catch(op_array TSRMLS_CC);
  522. op_print(op_array, 0, op_array->opcodes, op_array->opcodes + op_array->last);
  523. #endif
  524. if (op_array_convert_switch(op_array) == SUCCESS) {
  525. bbs_t bbs = bbs_initializer();
  526. if (bbs_build_from(&bbs, op_array, op_array->last TSRMLS_CC) == SUCCESS) {
  527. int i;
  528. #ifdef XCACHE_DEBUG
  529. bbs_print(&bbs, op_array);
  530. #endif
  531. /* TODO: calc opnum after basic block move */
  532. for (i = 0; i < bbs_count(&bbs); i ++) {
  533. bb_t *bb = bbs_get(&bbs, i);
  534. bb->opnum = bb->opcodes - op_array->opcodes;
  535. }
  536. bbs_restore_opnum(&bbs, op_array);
  537. }
  538. bbs_destroy(&bbs TSRMLS_CC);
  539. }
  540. #ifdef XCACHE_DEBUG
  541. TRACE("%s", "after compiles");
  542. # if 0
  543. xc_dprint_zend_op_array(op_array, 0 TSRMLS_CC);
  544. # endif
  545. op_array_print_try_catch(op_array TSRMLS_CC);
  546. op_print(op_array, 0, op_array->opcodes, op_array->opcodes + op_array->last);
  547. #endif
  548. return 0;
  549. }
  550. /* }}} */
  551. static void xc_optimizer_op_array_handler(zend_op_array *op_array) /* {{{ */
  552. {
  553. TSRMLS_FETCH();
  554. if (XG(optimizer)) {
  555. xc_optimize_op_array(op_array TSRMLS_CC);
  556. }
  557. }
  558. /* }}} */
  559. static int xc_coverager_zend_startup(zend_extension *extension) /* {{{ */
  560. {
  561. return SUCCESS;
  562. }
  563. /* }}} */
  564. static void xc_coverager_zend_shutdown(zend_extension *extension) /* {{{ */
  565. {
  566. }
  567. /* }}} */
  568. /* {{{ zend extension definition structure */
  569. static zend_extension xc_optimizer_zend_extension_entry = {
  570. XCACHE_NAME " Optimizer",
  571. XCACHE_VERSION,
  572. XCACHE_AUTHOR,
  573. XCACHE_URL,
  574. XCACHE_COPYRIGHT,
  575. xc_coverager_zend_startup,
  576. xc_coverager_zend_shutdown,
  577. NULL, /* activate_func_t */
  578. NULL, /* deactivate_func_t */
  579. NULL, /* message_handler_func_t */
  580. xc_optimizer_op_array_handler,
  581. NULL, /* statement_handler_func_t */
  582. NULL, /* fcall_begin_handler_func_t */
  583. NULL, /* fcall_end_handler_func_t */
  584. NULL, /* op_array_ctor_func_t */
  585. NULL, /* op_array_dtor_func_t */
  586. STANDARD_ZEND_EXTENSION_PROPERTIES
  587. };
  588. /* }}} */
  589. /* {{{ ini */
  590. PHP_INI_BEGIN()
  591. STD_PHP_INI_BOOLEAN("xcache.optimizer", "0", PHP_INI_ALL, OnUpdateBool, optimizer, zend_xcache_globals, xcache_globals)
  592. PHP_INI_END()
  593. /* }}} */
  594. static PHP_MINFO_FUNCTION(xcache_optimizer) /* {{{ */
  595. {
  596. php_info_print_table_start();
  597. php_info_print_table_row(2, "XCache Optimizer Module", "enabled");
  598. php_info_print_table_end();
  599. DISPLAY_INI_ENTRIES();
  600. }
  601. /* }}} */
  602. static PHP_MINIT_FUNCTION(xcache_optimizer) /* {{{ */
  603. {
  604. REGISTER_INI_ENTRIES();
  605. return xcache_zend_extension_add(&xc_optimizer_zend_extension_entry, 0);
  606. }
  607. /* }}} */
  608. static PHP_MSHUTDOWN_FUNCTION(xcache_optimizer) /* {{{ */
  609. {
  610. UNREGISTER_INI_ENTRIES();
  611. return xcache_zend_extension_remove(&xc_optimizer_zend_extension_entry);
  612. }
  613. /* }}} */
  614. static zend_module_entry xcache_optimizer_module_entry = { /* {{{ */
  615. STANDARD_MODULE_HEADER,
  616. XCACHE_NAME " Optimizer",
  617. NULL,
  618. PHP_MINIT(xcache_optimizer),
  619. PHP_MSHUTDOWN(xcache_optimizer),
  620. NULL,
  621. NULL,
  622. PHP_MINFO(xcache_optimizer),
  623. XCACHE_VERSION,
  624. #ifdef PHP_GINIT
  625. NO_MODULE_GLOBALS,
  626. #endif
  627. #ifdef ZEND_ENGINE_2
  628. NULL,
  629. #else
  630. NULL,
  631. NULL,
  632. #endif
  633. STANDARD_MODULE_PROPERTIES_EX
  634. };
  635. /* }}} */
  636. int xc_optimizer_startup_module() /* {{{ */
  637. {
  638. return zend_startup_module(&xcache_optimizer_module_entry);
  639. }
  640. /* }}} */