Changeset 832 for trunk/xcache.c
- Timestamp:
- 03/23/2012 05:17:34 PM (14 months ago)
- Files:
-
- 1 modified
-
trunk/xcache.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xcache.c
r827 r832 1178 1178 /* {{{ Constant Usage */ 1179 1179 #ifdef ZEND_ENGINE_2_4 1180 # define xcache_literal_is_dir 1 1181 # define xcache_literal_is_file 2 1180 1182 #else 1181 1183 # define xcache_op1_is_file 1 … … 1193 1195 static void xc_collect_op_array_info(xc_entry_t *xce, xc_entry_data_php_t *php, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */ 1194 1196 { 1195 #ifdef ZEND_ENGINE_2_4 1196 int oplineno; 1197 #else 1198 int oplineno; 1199 #endif 1200 xc_vector_t vector_int; 1201 1202 xc_vector_init(int, &vector_int); 1203 1204 #ifdef ZEND_ENGINE_2_4 1205 #else 1206 #define XCACHE_CHECK_OP(type, op) \ 1197 int i; 1198 xc_vector_t details; 1199 1200 xc_vector_init(xc_op_array_info_detail_t, &details); 1201 1202 #define XCACHE_ANALYZE_LITERAL(type) \ 1203 if (zend_binary_strcmp(Z_STRVAL(literal->constant), Z_STRLEN(literal->constant), xce->type##path, xce->type##path_len) == 0) { \ 1204 usage->type##path_used = 1; \ 1205 literalinfo |= xcache_##literal##_is_##type; \ 1206 } 1207 1208 #define XCACHE_U_ANALYZE_LITERAL(type) \ 1209 if (zend_u_##binary_strcmp(Z_USTRVAL(literal->constant), Z_USTRLEN(literal->constant), xce->u##type##path, xce->u##type##path_len) == 0) { \ 1210 usage->u##type##path_used = 1; \ 1211 literalinfo |= xcache_##literal##_is_##type; \ 1212 } 1213 1214 #define XCACHE_ANALYZE_OP(type, op) \ 1207 1215 if (zend_binary_strcmp(Z_STRVAL(Z_OP_CONSTANT(opline->op)), Z_STRLEN(Z_OP_CONSTANT(opline->op)), xce->type##path, xce->type##path_len) == 0) { \ 1208 1216 usage->type##path_used = 1; \ … … 1210 1218 } 1211 1219 1212 #define XCACHE_U_ CHECK_OP(type, op) \1220 #define XCACHE_U_ANALYZE_OP(type, op) \ 1213 1221 if (zend_u_##binary_strcmp(Z_USTRVAL(Z_OP_CONSTANT(opline->op)), Z_USTRLEN(Z_OP_CONSTANT(opline->op)), xce->u##type##path, xce->u##type##path_len) == 0) { \ 1214 1222 usage->u##type##path_used = 1; \ … … 1216 1224 } 1217 1225 1218 for (oplineno = 0; oplineno < op_array->last; oplineno++) { 1219 zend_op *opline = &op_array->opcodes[oplineno]; 1220 int oplineinfo = 0; 1226 #ifdef ZEND_ENGINE_2_4 1227 for (i = 0; i < op_array->last_literal; i++) { 1228 zend_literal *literal = &op_array->literals[i]; 1229 zend_uint literalinfo = 0; 1230 if (Z_TYPE(literal->constant) == IS_STRING) { 1231 XCACHE_ANALYZE_LITERAL(file) 1232 else XCACHE_ANALYZE_LITERAL(dir) 1233 } 1234 #ifdef IS_UNICODE 1235 else if (Z_TYPE(literal->constant) == IS_UNICODE) { 1236 XCACHE_U_ANALYZE_LITERAL(file) 1237 else XCACHE_U_ANALYZE_LITERAL(dir) 1238 } 1239 #endif 1240 if (literalinfo) { 1241 xc_op_array_info_detail_t detail; 1242 detail.index = i; 1243 detail.info = literalinfo; 1244 xc_vector_add(xc_op_array_info_detail_t, &details, detail); 1245 } 1246 } 1247 1248 op_array_info->literalinfo_cnt = details.cnt; 1249 op_array_info->literalinfos = xc_vector_detach(xc_op_array_info_detail_t, &details); 1250 #else /* ZEND_ENGINE_2_4 */ 1251 for (i = 0; i < op_array->last; i++) { 1252 zend_op *opline = &op_array->opcodes[i]; 1253 zend_uint oplineinfo = 0; 1221 1254 if (Z_OP_TYPE(opline->op1) == IS_CONST) { 1222 1255 if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_STRING) { 1223 XCACHE_CHECK_OP(file, op1) 1224 else XCACHE_CHECK_OP(dir, op1) 1225 } 1226 1256 XCACHE_ANALYZE_OP(file, op1) 1257 else XCACHE_ANALYZE_OP(dir, op1) 1258 } 1227 1259 #ifdef IS_UNICODE 1228 1260 else if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_UNICODE) { 1229 XCACHE_U_CHECK_OP(file, op1) 1230 else XCACHE_U_CHECK_OP(dir, op1) 1231 } 1232 #endif 1233 } 1261 XCACHE_U_ANALYZE_OP(file, op1) 1262 else XCACHE_U_ANALYZE_OP(dir, op1) 1263 } 1264 #endif 1265 } 1266 1234 1267 if (Z_OP_TYPE(opline->op2) == IS_CONST) { 1235 1268 if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_STRING) { 1236 XCACHE_CHECK_OP(file, op2) 1237 else XCACHE_CHECK_OP(dir, op2) 1238 } 1239 1269 XCACHE_ANALYZE_OP(file, op2) 1270 else XCACHE_ANALYZE_OP(dir, op2) 1271 } 1240 1272 #ifdef IS_UNICODE 1241 1273 else if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_UNICODE) { 1242 XCACHE_U_CHECK_OP(file, op2) 1243 else XCACHE_U_CHECK_OP(dir, op2) 1244 } 1245 #endif 1246 } 1274 XCACHE_U_ANALYZE_OP(file, op2) 1275 else XCACHE_U_ANALYZE_OP(dir, op2) 1276 } 1277 #endif 1278 } 1279 1247 1280 if (oplineinfo) { 1248 xc_vector_add(int, &vector_int, oplineno); 1249 xc_vector_add(int, &vector_int, oplineinfo); 1250 } 1251 } 1252 1253 op_array_info->oplineinfo_cnt = vector_int.cnt; 1254 op_array_info->oplineinfos = xc_vector_detach(int, &vector_int); 1255 #endif 1256 xc_vector_free(int, &vector_int); 1257 } 1258 /* }}} */ 1259 void xc_fix_op_array_info(const xc_entry_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int copy, const xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */ 1260 { 1281 xc_op_array_info_detail_t detail; 1282 detail.index = i; 1283 detail.info = oplineinfo; 1284 xc_vector_add(xc_op_array_info_detail_t, &details, detail); 1285 } 1286 } 1287 1288 op_array_info->oplineinfo_cnt = details.cnt; 1289 op_array_info->oplineinfos = xc_vector_detach(xc_op_array_info_detail_t, &details); 1290 #endif /* ZEND_ENGINE_2_4 */ 1291 xc_vector_free(xc_op_array_info_detail_t, &details); 1292 } 1293 /* }}} */ 1294 void xc_fix_op_array_info(const xc_entry_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */ 1295 { 1296 int i; 1297 1261 1298 #ifdef ZEND_ENGINE_2_4 1299 for (i = 0; i < op_array_info->literalinfo_cnt; ++i) { 1300 int index = op_array_info->literalinfos[i].index; 1301 int literalinfo = op_array_info->literalinfos[i].info; 1302 zend_literal *literal = &op_array->literals[index]; 1303 if ((literalinfo & xcache_literal_is_file)) { 1304 if (!shallow_copy) { 1305 efree(Z_STRVAL(literal->constant)); 1306 } 1307 if (Z_TYPE(literal->constant) == IS_STRING) { 1308 assert(xce->filepath); 1309 ZVAL_STRINGL(&literal->constant, xce->filepath, xce->filepath_len, !shallow_copy); 1310 TRACE("restored literal constant: %s", xce->filepath); 1311 } 1312 #ifdef IS_UNICODE 1313 else if (Z_TYPE(literal->constant) == IS_UNICODE) { 1314 assert(xce->ufilepath); 1315 ZVAL_UNICODEL(&literal->constant, xce->ufilepath, xce->ufilepath_len, !shallow_copy); 1316 } 1317 #endif 1318 else { 1319 assert(0); 1320 } 1321 } 1322 else if ((literalinfo & xcache_literal_is_dir)) { 1323 if (!shallow_copy) { 1324 efree(Z_STRVAL(literal->constant)); 1325 } 1326 if (Z_TYPE(literal->constant) == IS_STRING) { 1327 assert(xce->dirpath); 1328 TRACE("restored literal constant: %s", xce->dirpath); 1329 ZVAL_STRINGL(&literal->constant, xce->dirpath, xce->dirpath_len, !shallow_copy); 1330 } 1331 #ifdef IS_UNICODE 1332 else if (Z_TYPE(literal->constant) == IS_UNICODE) { 1333 assert(!xce->udirpath); 1334 ZVAL_UNICODEL(&literal->constant, xce->udirpath, xce->udirpath_len, !shallow_copy); 1335 } 1336 #endif 1337 else { 1338 assert(0); 1339 } 1340 } 1341 } 1262 1342 #else 1263 int i; 1264 #endif 1265 1266 #ifdef ZEND_ENGINE_2_4 1267 #else 1268 for (i = 0; i < op_array_info->oplineinfo_cnt; i += 2) { 1269 int oplineno = op_array_info->oplineinfos[i]; 1270 int oplineinfo = op_array_info->oplineinfos[i + 1]; 1343 for (i = 0; i < op_array_info->oplineinfo_cnt; ++i) { 1344 int oplineno = op_array_info->oplineinfos[i].index; 1345 int oplineinfo = op_array_info->oplineinfos[i].info; 1271 1346 zend_op *opline = &op_array->opcodes[oplineno]; 1272 1347 if ((oplineinfo & xcache_op1_is_file)) { 1273 1348 assert(Z_OP_TYPE(opline->op1) == IS_CONST); 1274 if ( copy) {1349 if (!shallow_copy) { 1275 1350 efree(Z_STRVAL(Z_OP_CONSTANT(opline->op1))); 1276 1351 } 1277 1352 if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_STRING) { 1278 1353 assert(xce->filepath); 1279 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op1), xce->filepath, xce->filepath_len, copy);1280 TRACE(" fixing op1 to%s", xce->filepath);1354 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op1), xce->filepath, xce->filepath_len, !shallow_copy); 1355 TRACE("restored op1 constant: %s", xce->filepath); 1281 1356 } 1282 1357 #ifdef IS_UNICODE 1283 1358 else if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_UNICODE) { 1284 1359 assert(xce->ufilepath); 1285 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op1), xce->ufilepath, xce->ufilepath_len, copy);1360 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op1), xce->ufilepath, xce->ufilepath_len, !shallow_copy); 1286 1361 } 1287 1362 #endif … … 1292 1367 else if ((oplineinfo & xcache_op1_is_dir)) { 1293 1368 assert(Z_OP_TYPE(opline->op1) == IS_CONST); 1294 if ( copy) {1369 if (!shallow_copy) { 1295 1370 efree(Z_STRVAL(Z_OP_CONSTANT(opline->op1))); 1296 1371 } 1297 1372 if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_STRING) { 1298 1373 assert(xce->dirpath); 1299 TRACE(" fixing op1 to%s", xce->dirpath);1300 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op1), xce->dirpath, xce->dirpath_len, copy);1374 TRACE("restored op1 constant: %s", xce->dirpath); 1375 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op1), xce->dirpath, xce->dirpath_len, !shallow_copy); 1301 1376 } 1302 1377 #ifdef IS_UNICODE 1303 1378 else if (Z_TYPE(Z_OP_CONSTANT(opline->op1)) == IS_UNICODE) { 1304 1379 assert(!xce->udirpath); 1305 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op1), xce->udirpath, xce->udirpath_len, copy);1380 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op1), xce->udirpath, xce->udirpath_len, !shallow_copy); 1306 1381 } 1307 1382 #endif … … 1313 1388 if ((oplineinfo & xcache_op2_is_file)) { 1314 1389 assert(Z_OP_TYPE(opline->op2) == IS_CONST); 1315 if ( copy) {1390 if (!shallow_copy) { 1316 1391 efree(Z_STRVAL(Z_OP_CONSTANT(opline->op2))); 1317 1392 } 1318 1393 if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_STRING) { 1319 1394 assert(xce->filepath); 1320 TRACE(" fixing op2 to%s", xce->filepath);1321 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op2), xce->filepath, xce->filepath_len, copy);1395 TRACE("restored op2 constant: %s", xce->filepath); 1396 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op2), xce->filepath, xce->filepath_len, !shallow_copy); 1322 1397 } 1323 1398 #ifdef IS_UNICODE 1324 1399 else if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_UNICODE) { 1325 1400 assert(xce->ufilepath); 1326 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op2), xce->ufilepath, xce->ufilepath_len, copy);1401 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op2), xce->ufilepath, xce->ufilepath_len, !shallow_copy); 1327 1402 } 1328 1403 #endif … … 1333 1408 else if ((oplineinfo & xcache_op2_is_dir)) { 1334 1409 assert(Z_OP_TYPE(opline->op2) == IS_CONST); 1335 if ( copy) {1410 if (!shallow_copy) { 1336 1411 efree(Z_STRVAL(Z_OP_CONSTANT(opline->op2))); 1337 1412 } 1338 1413 if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_STRING) { 1339 1414 assert(!xce->dirpath); 1340 TRACE(" fixing op2 to%s", xce->dirpath);1341 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op2), xce->dirpath, xce->dirpath_len, copy);1415 TRACE("restored op2 constant: %s", xce->dirpath); 1416 ZVAL_STRINGL(&Z_OP_CONSTANT(opline->op2), xce->dirpath, xce->dirpath_len, !shallow_copy); 1342 1417 } 1343 1418 #ifdef IS_UNICODE 1344 1419 else if (Z_TYPE(Z_OP_CONSTANT(opline->op2)) == IS_UNICODE) { 1345 1420 assert(!xce->udirpath); 1346 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op2), xce->udirpath, xce->udirpath_len, copy);1421 ZVAL_UNICODEL(&Z_OP_CONSTANT(opline->op2), xce->udirpath, xce->udirpath_len, !shallow_copy); 1347 1422 } 1348 1423 #endif

