Index: trunk/src/VBox/VMM/VMMAll/IEMAll.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 99929)
+++ trunk/src/VBox/VMM/VMMAll/IEMAll.cpp	(revision 99930)
@@ -10143,70 +10143,4 @@
 
 
-/** @def IEM_TRY_SETJMP
- * Wrapper around setjmp / try, hiding all the ugly differences.
- *
- * @note Use with extreme care as this is a fragile macro.
- * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
- * @param   a_rcTarget  The variable that should receive the status code in case
- *                      of a longjmp/throw.
- */
-/** @def IEM_TRY_SETJMP_AGAIN
- * For when setjmp / try is used again in the same variable scope as a previous
- * IEM_TRY_SETJMP invocation.
- */
-/** @def IEM_CATCH_LONGJMP_BEGIN
- * Start wrapper for catch / setjmp-else.
- *
- * This will set up a scope.
- *
- * @note Use with extreme care as this is a fragile macro.
- * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
- * @param   a_rcTarget  The variable that should receive the status code in case
- *                      of a longjmp/throw.
- */
-/** @def IEM_CATCH_LONGJMP_END
- * End wrapper for catch / setjmp-else.
- *
- * This will close the scope set up by IEM_CATCH_LONGJMP_BEGIN and clean up the
- * state.
- *
- * @note Use with extreme care as this is a fragile macro.
- * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
- */
-#if defined(IEM_WITH_SETJMP) || defined(DOXYGEN_RUNNING)
-# ifdef IEM_WITH_THROW_CATCH
-#  define IEM_TRY_SETJMP(a_pVCpu, a_rcTarget) \
-        a_rcTarget = VINF_SUCCESS; \
-        try
-#  define IEM_TRY_SETJMP_AGAIN(a_pVCpu, a_rcTarget) \
-        IEM_TRY_SETJMP(a_pVCpu, a_rcTarget)
-#  define IEM_CATCH_LONGJMP_BEGIN(a_pVCpu, a_rcTarget) \
-        catch (int rcThrown) \
-        { \
-            a_rcTarget = rcThrown
-#  define IEM_CATCH_LONGJMP_END(a_pVCpu) \
-        } \
-        ((void)0)
-# else  /* !IEM_WITH_THROW_CATCH */
-#  define IEM_TRY_SETJMP(a_pVCpu, a_rcTarget) \
-        jmp_buf  JmpBuf; \
-        jmp_buf * volatile pSavedJmpBuf = pVCpu->iem.s.CTX_SUFF(pJmpBuf); \
-        pVCpu->iem.s.CTX_SUFF(pJmpBuf) = &JmpBuf; \
-        if ((rcStrict = setjmp(JmpBuf)) == 0)
-#  define IEM_TRY_SETJMP_AGAIN(a_pVCpu, a_rcTarget) \
-        pSavedJmpBuf = pVCpu->iem.s.CTX_SUFF(pJmpBuf); \
-        pVCpu->iem.s.CTX_SUFF(pJmpBuf) = &JmpBuf; \
-        if ((rcStrict = setjmp(JmpBuf)) == 0)
-#  define IEM_CATCH_LONGJMP_BEGIN(a_pVCpu, a_rcTarget) \
-        else \
-        { \
-            ((void)0)
-#  define IEM_CATCH_LONGJMP_END(a_pVCpu) \
-        } \
-        (a_pVCpu)->iem.s.CTX_SUFF(pJmpBuf) = pSavedJmpBuf
-# endif /* !IEM_WITH_THROW_CATCH */
-#endif  /* IEM_WITH_SETJMP */
-
-
 /**
  * The actual code execution bits of IEMExecOne, IEMExecOneEx, and
Index: trunk/src/VBox/VMM/VMMAll/IEMAllInstructionsThreadedRecompiler.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/IEMAllInstructionsThreadedRecompiler.cpp	(revision 99929)
+++ trunk/src/VBox/VMM/VMMAll/IEMAllInstructionsThreadedRecompiler.cpp	(revision 99930)
@@ -261,2 +261,72 @@
  */
 
+static VBOXSTRICTRC iemThreadedCompile(PVMCCV pVM, PVMCPUCC pVCpu)
+{
+    RT_NOREF(pVM, pVCpu, pTb);
+    return VERR_NOT_IMPLEMENTED;
+}
+
+
+static VBOXSTRICTRC iemThreadedCompileLongJumped(PVMCCV pVM, PVMCPUCC pVCpu, VBOXSTRICTRC rcStrict)
+{
+    RT_NOREF(pVM, pVCpu);
+    return rcStrict;
+}
+
+
+static PIEMTB iemThreadedTbLookup(PVMCCV pVM, PVMCPUCC pVCpu)
+{
+    RT_NOREF(pVM, pVCpu);
+    return NULL;
+}
+
+
+static VBOXSTRICTRC iemThreadedTbExec(PVMCCV pVM, PVMCPUCC pVCpu, PIEMTB pTb)
+{
+    RT_NOREF(pVM, pVCpu, pTb);
+    return VERR_NOT_IMPLEMENTED;
+}
+
+
+VMMDECL(VBOXSTRICTRC) IEMExecRecompilerThreaded(PVMCC pVM, PVMCPUCC pVCpu)
+{
+    /*
+     * Run-loop. 
+     *  
+     * If we're using setjmp/longjmp we combine all the catching here to avoid 
+     * having to call setjmp for each block we're executing.
+     */
+    for (;;)
+    {
+        PIEMTB       pTb = NULL;
+        VBOXSTRICTRC rcStrict;
+#ifdef IEM_WITH_SETJMP
+        IEM_TRY_SETJMP(pVCpu, rcStrict)
+#endif
+        {
+            for (;;)
+            {
+                pTb = iemThreadedTbLookup(pVM, pVCpu);
+                if (pTb)
+                    rcStrict = iemThreadedTbExec(pVM, pVCpu, pTb);
+                else
+                    rcStrict = iemThreadedCompile(pVM, pVCpu);
+                if (rcStrict == VINF_SUCCESS)
+                { /* likely */ }
+                else
+                    return rcStrict;
+            }
+        }
+#ifdef IEM_WITH_SETJMP
+        IEM_CATCH_LONGJMP_BEGIN(pVCpu, rcStrict);
+        {
+            pVCpu->iem.s.cLongJumps++;
+            if (pTb)
+                return rcStrict;
+            return iemThreadedCompileLongJumped(pVM, pVCpu, rcStrict);
+        }
+        IEM_CATCH_LONGJMP_END(pVCpu);
+#endif
+    }
+}
+
Index: trunk/src/VBox/VMM/VMMR3/EM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 99929)
+++ trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 99930)
@@ -1082,5 +1082,5 @@
 #ifdef VBOX_WITH_IEM_RECOMPILER
             if (pVM->em.s.fIemRecompiled)
-                rcStrict = IEMExecLots(pVCpu, 8192 /*cMaxInstructions*/, 4095 /*cPollRate*/, NULL /*pcInstructions*/);
+                rcStrict = IEMExecRecompilerThreaded(pVCpu);
             else
 #endif
Index: trunk/src/VBox/VMM/include/IEMInternal.h
===================================================================
--- trunk/src/VBox/VMM/include/IEMInternal.h	(revision 99929)
+++ trunk/src/VBox/VMM/include/IEMInternal.h	(revision 99930)
@@ -957,4 +957,69 @@
 # define IEM_GET_INSTR_LEN(a_pVCpu)     ((a_pVCpu)->iem.s.offOpcode)
 #endif
+
+/** @def IEM_TRY_SETJMP
+ * Wrapper around setjmp / try, hiding all the ugly differences.
+ *
+ * @note Use with extreme care as this is a fragile macro.
+ * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
+ * @param   a_rcTarget  The variable that should receive the status code in case
+ *                      of a longjmp/throw.
+ */
+/** @def IEM_TRY_SETJMP_AGAIN
+ * For when setjmp / try is used again in the same variable scope as a previous
+ * IEM_TRY_SETJMP invocation.
+ */
+/** @def IEM_CATCH_LONGJMP_BEGIN
+ * Start wrapper for catch / setjmp-else.
+ *
+ * This will set up a scope.
+ *
+ * @note Use with extreme care as this is a fragile macro.
+ * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
+ * @param   a_rcTarget  The variable that should receive the status code in case
+ *                      of a longjmp/throw.
+ */
+/** @def IEM_CATCH_LONGJMP_END
+ * End wrapper for catch / setjmp-else.
+ *
+ * This will close the scope set up by IEM_CATCH_LONGJMP_BEGIN and clean up the
+ * state.
+ *
+ * @note Use with extreme care as this is a fragile macro.
+ * @param   a_pVCpu     The cross context virtual CPU structure of the calling EMT.
+ */
+#if defined(IEM_WITH_SETJMP) || defined(DOXYGEN_RUNNING)
+# ifdef IEM_WITH_THROW_CATCH
+#  define IEM_TRY_SETJMP(a_pVCpu, a_rcTarget) \
+        a_rcTarget = VINF_SUCCESS; \
+        try
+#  define IEM_TRY_SETJMP_AGAIN(a_pVCpu, a_rcTarget) \
+        IEM_TRY_SETJMP(a_pVCpu, a_rcTarget)
+#  define IEM_CATCH_LONGJMP_BEGIN(a_pVCpu, a_rcTarget) \
+        catch (int rcThrown) \
+        { \
+            a_rcTarget = rcThrown
+#  define IEM_CATCH_LONGJMP_END(a_pVCpu) \
+        } \
+        ((void)0)
+# else  /* !IEM_WITH_THROW_CATCH */
+#  define IEM_TRY_SETJMP(a_pVCpu, a_rcTarget) \
+        jmp_buf  JmpBuf; \
+        jmp_buf * volatile pSavedJmpBuf = pVCpu->iem.s.CTX_SUFF(pJmpBuf); \
+        pVCpu->iem.s.CTX_SUFF(pJmpBuf) = &JmpBuf; \
+        if ((rcStrict = setjmp(JmpBuf)) == 0)
+#  define IEM_TRY_SETJMP_AGAIN(a_pVCpu, a_rcTarget) \
+        pSavedJmpBuf = pVCpu->iem.s.CTX_SUFF(pJmpBuf); \
+        pVCpu->iem.s.CTX_SUFF(pJmpBuf) = &JmpBuf; \
+        if ((rcStrict = setjmp(JmpBuf)) == 0)
+#  define IEM_CATCH_LONGJMP_BEGIN(a_pVCpu, a_rcTarget) \
+        else \
+        { \
+            ((void)0)
+#  define IEM_CATCH_LONGJMP_END(a_pVCpu) \
+        } \
+        (a_pVCpu)->iem.s.CTX_SUFF(pJmpBuf) = pSavedJmpBuf
+# endif /* !IEM_WITH_THROW_CATCH */
+#endif  /* IEM_WITH_SETJMP */
 
 
