Index: /trunk/processor/processor.m4
===================================================================
--- /trunk/processor/processor.m4	(revision 267)
+++ /trunk/processor/processor.m4	(revision 268)
@@ -708,4 +708,16 @@
 ')
 dnl }}}
+#ifdef ZEND_ENGINE_2_1
+DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
+	DISPATCH(zend_uint, key_len)
+#ifdef IS_UNICODE
+	DISPATCH(zend_uchar, type)
+#endif
+	IFRESTORE(`COPY(key)', `
+		PROC_ZSTRING_L(type, key, key_len)
+	')
+')
+dnl }}}
+#endif
 DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
 	zend_uint i;
@@ -736,4 +748,8 @@
 	')
 	STRUCT_ARRAY(classinfo_cnt, xc_classinfo_t, classinfos)
+#ifdef ZEND_ENGINE_2_1
+	DISPATCH(zend_uint, autoglobal_cnt)
+	STRUCT_ARRAY(autoglobal_cnt, xc_autoglobal_t, autoglobals)
+#endif
 	DISPATCH(zend_bool, have_early_binding)
 	popdef(`BEFORE_LOOP')
Index: /trunk/utils.c
===================================================================
--- /trunk/utils.c	(revision 267)
+++ /trunk/utils.c	(revision 268)
@@ -511,4 +511,27 @@
 #define OG(x) (sandbox->orig_##x)
 /* }}} */
+#ifdef ZEND_ENGINE_2_1
+static zend_bool xc_auto_global_callback(char *name, uint name_len TSRMLS_DC) /* {{{ */
+{
+	zend_auto_global *auto_global;
+	if (zend_u_hash_find(CG(auto_globals), UG(unicode) ? IS_UNICODE : IS_STRING, ZSTR(name), name_len + 1, (void **) &auto_global) == FAILURE) {
+		return 1;
+	}
+	return 0;
+}
+/* }}} */
+static int xc_auto_global_arm(zend_auto_global *auto_global TSRMLS_DC) /* {{{ */
+{
+	if (auto_global->auto_global_callback) {
+		auto_global->armed = 1;
+		auto_global->auto_global_callback = xc_auto_global_callback;
+	}
+	else {
+		auto_global->armed = 0;
+	}
+	return ZEND_HASH_APPLY_KEEP;
+}
+/* }}} */
+#endif
 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */
 {
@@ -535,4 +558,9 @@
 	EG(class_table) = CG(class_table);
 
+#ifdef ZEND_ENGINE_2_1
+	OG(auto_globals) = CG(auto_globals);
+	CG(auto_globals) = &TG(auto_globals);
+#endif
+
 	TG(included_files) = &EG(included_files);
 
@@ -543,4 +571,13 @@
 	zend_hash_init_ex(&TG(function_table), 128, NULL, OG(function_table)->pDestructor, 0, 0);
 	zend_hash_init_ex(&TG(class_table), 16, NULL, OG(class_table)->pDestructor, 0, 0);
+#ifdef ZEND_ENGINE_2_1
+	zend_hash_init_ex(&TG(auto_globals), 8, NULL, OG(auto_globals)->pDestructor, 0, 0);
+	{
+		zend_auto_global tmp_autoglobal;
+
+		zend_hash_copy(&TG(auto_globals), OG(auto_globals), NULL, (void *) &tmp_autoglobal, sizeof(tmp_autoglobal));
+		zend_hash_apply(&TG(auto_globals), (apply_func_t) xc_auto_global_arm TSRMLS_CC);
+	}
+#endif
 
 	sandbox->filename = filename;
@@ -592,4 +629,16 @@
 		b = b->pListNext;
 	}
+
+#ifdef ZEND_ENGINE_2_1
+	/* trigger auto_globals jit */
+	for (b = TG(auto_globals).pListHead; b != NULL; b = b->pListNext) {
+		zend_auto_global *auto_global = (zend_auto_global *) b->pData;
+		/* check if actived */
+		if (auto_global->auto_global_callback && !auto_global->armed) {
+			zend_u_is_auto_global(BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), auto_global->name_len TSRMLS_CC);
+		}
+	}
+#endif
+
 	xc_undo_pass_two(CG(active_op_array) TSRMLS_CC);
 	xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC);
@@ -609,4 +658,7 @@
 	CG(class_table)    = OG(class_table);
 	EG(class_table)    = CG(class_table);
+#ifdef ZEND_ENGINE_2_1
+	CG(auto_globals)   = OG(auto_globals);
+#endif
 
 	if (install) {
@@ -624,4 +676,7 @@
 		TG(function_table).pDestructor = NULL;
 		TG(class_table).pDestructor = NULL;
+#ifdef ZEND_ENGINE_2_1
+		TG(auto_globals).pDestructor = NULL;
+#endif
 	}
 
@@ -632,4 +687,7 @@
 	zend_hash_destroy(&TG(function_table));
 	zend_hash_destroy(&TG(class_table));
+#ifdef ZEND_ENGINE_2_1
+	zend_hash_destroy(&TG(auto_globals));
+#endif
 	zend_hash_destroy(TG(included_files));
 
Index: /trunk/utils.h
===================================================================
--- /trunk/utils.h	(revision 267)
+++ /trunk/utils.h	(revision 268)
@@ -49,6 +49,8 @@
 	HashTable *orig_function_table;
 	HashTable *orig_class_table;
+	HashTable *orig_auto_globals;
 	HashTable tmp_function_table;
 	HashTable tmp_class_table;
+	HashTable tmp_auto_globals;
 } xc_sandbox_t;
 
Index: /trunk/xcache-zh-gb2312.ini
===================================================================
--- /trunk/xcache-zh-gb2312.ini	(revision 267)
+++ /trunk/xcache-zh-gb2312.ini	(revision 268)
@@ -9,7 +9,4 @@
 ;; »òÕß Win32 ÏµÍ³:
 ; extension = php_xcache.dll
-
-; Èç¹ûÄúÔÚ php5.1 »òÕßÒÔÉÏ°æ±¾ÆôÓÃ XCache, Ôò±ØÐëÊ¹ÓÃÒÔÏÂÉèÖÃ
-auto_globals_jit = Off
 
 [xcache.admin]
Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 267)
+++ /trunk/xcache.c	(revision 268)
@@ -500,4 +500,7 @@
 			add_assoc_long_ex(ei, ZEND_STRS("function_cnt"),  php->funcinfo_cnt);
 			add_assoc_long_ex(ei, ZEND_STRS("class_cnt"),     php->classinfo_cnt);
+#ifdef ZEND_ENGINE_2_1
+			add_assoc_long_ex(ei, ZEND_STRS("autoglobal_cnt"),php->autoglobal_cnt);
+#endif
 			break;
 		case XC_TYPE_VAR:
@@ -580,4 +583,20 @@
 				UNISW(0, ci->type), ci->key, ci->key_size TSRMLS_CC);
 	}
+
+#ifdef ZEND_ENGINE_2_1
+	/* trigger auto_globals jit */
+	for (i = 0; i < p->autoglobal_cnt; i ++) {
+		xc_autoglobal_t *aginfo = &p->autoglobals[i];
+		/*
+		zend_auto_global *auto_global;
+		if (zend_u_hash_find(CG(auto_globals), aginfo->type, aginfo->key, aginfo->key_len+1, (void **) &auto_global)==SUCCESS) {
+			if (auto_global->armed) {
+				auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
+			}
+		}
+		*/
+		zend_u_is_auto_global(aginfo->type, aginfo->key, aginfo->key_len TSRMLS_CC);
+	}
+#endif
 
 	i = 1;
@@ -949,8 +968,23 @@
 
 #ifdef HAVE_XCACHE_CONSTANT
-	php.constinfo_cnt = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt;
-#endif
-	php.funcinfo_cnt  = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt;
-	php.classinfo_cnt = zend_hash_num_elements(CG(class_table))    - old_classinfo_cnt;
+	php.constinfo_cnt  = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt;
+#endif
+	php.funcinfo_cnt   = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt;
+	php.classinfo_cnt  = zend_hash_num_elements(CG(class_table))    - old_classinfo_cnt;
+#ifdef ZEND_ENGINE_2_1
+	/* {{{ count php.autoglobal_cnt */ {
+		Bucket *b;
+
+		php.autoglobal_cnt = 0;
+		for (b = CG(auto_globals)->pListHead; b != NULL; b = b->pListNext) {
+			zend_auto_global *auto_global = (zend_auto_global *) b->pData;
+			/* check if actived */
+			if (auto_global->auto_global_callback && !auto_global->armed) {
+				php.autoglobal_cnt ++;
+			}
+		}
+	}
+	/* }}} */
+#endif
 
 #define X_ALLOC_N(var, cnt) do {     \
@@ -967,8 +1001,11 @@
 
 #ifdef HAVE_XCACHE_CONSTANT
-	X_ALLOC_N(constinfos, constinfo_cnt);
-#endif
-	X_ALLOC_N(funcinfos,  funcinfo_cnt);
-	X_ALLOC_N(classinfos, classinfo_cnt);
+	X_ALLOC_N(constinfos,  constinfo_cnt);
+#endif
+	X_ALLOC_N(funcinfos,   funcinfo_cnt);
+	X_ALLOC_N(classinfos,  classinfo_cnt);
+#ifdef ZEND_ENGINE_2_1
+	X_ALLOC_N(autoglobals, autoglobal_cnt);
+#endif
 #undef X_ALLOC
 	/* }}} */
@@ -1006,5 +1043,28 @@
 
 #undef COPY_H
-		/* for ZE1, cest need to fix inside store */
+
+		/* for ZE1, cest need to be fixed inside store */
+
+#ifdef ZEND_ENGINE_2_1
+		/* scan for acatived auto globals */
+		i = 0;
+		for (b = CG(auto_globals)->pListHead; b != NULL; b = b->pListNext) {
+			zend_auto_global *auto_global = (zend_auto_global *) b->pData;
+			/* check if actived */
+			if (auto_global->auto_global_callback && !auto_global->armed) {
+				xc_autoglobal_t *data = &php.autoglobals[i ++];
+
+				assert(i < php.autoglobal_cnt);
+				UNISW(NOTHING, data->type = b->key.type;)
+				if (UNISW(1, b->key.type == IS_STRING)) {
+					ZSTR_S(data->key)     = BUCKET_KEY_S(b);
+				}
+				else {
+					ZSTR_U(data->key)     = BUCKET_KEY_U(b);
+				}
+				data->key_len = b->nKeyLength - 1;
+			}
+		}
+#endif
 	}
 	/* }}} */
@@ -1036,4 +1096,7 @@
 err_##var:
 
+#ifdef ZEND_ENGINE_2_1
+	X_FREE(autoglobals)
+#endif
 	X_FREE(classinfos)
 	X_FREE(funcinfos)
@@ -1100,4 +1163,7 @@
 		efree(xce.data.php->var); \
 	}
+#ifdef ZEND_ENGINE_2_1
+	X_FREE(autoglobals)
+#endif
 	X_FREE(classinfos)
 	X_FREE(funcinfos)
Index: /trunk/xcache.h
===================================================================
--- /trunk/xcache.h	(revision 267)
+++ /trunk/xcache.h	(revision 268)
@@ -128,4 +128,6 @@
 		add_assoc_zval_ex(arg, key, key_len, value)
 
+#	define zend_u_is_auto_global(type, name, name_len) \
+		zend_is_auto_global(name, name_len)
 #endif
 /* }}} */
@@ -221,4 +223,15 @@
 } xc_funcinfo_t;
 /* }}} */
+#ifdef ZEND_ENGINE_2_1
+/* {{{ xc_autoglobal_t */
+typedef struct {
+#ifdef IS_UNICODE
+	zend_uchar type;
+#endif
+	zstr       key;
+	zend_uint  key_len;
+} xc_autoglobal_t;
+/* }}} */
+#endif
 typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
 /* {{{ xc_entry_data_php_t */
@@ -244,4 +257,9 @@
 	xc_classinfo_t *classinfos;
 	zend_bool have_early_binding;
+
+#ifdef ZEND_ENGINE_2_1
+	zend_uint autoglobal_cnt;
+	xc_autoglobal_t *autoglobals;
+#endif
 } xc_entry_data_php_t;
 /* }}} */
Index: /trunk/xcache.ini
===================================================================
--- /trunk/xcache.ini	(revision 267)
+++ /trunk/xcache.ini	(revision 268)
@@ -9,7 +9,4 @@
 ;; or win32:
 ; extension = php_xcache.dll
-
-; required for >=php5.1 if you turn XCache on
-auto_globals_jit = Off
 
 [xcache.admin]
