diff --git include/llvm/ExecutionEngine/ExecutionEngine.h include/llvm/ExecutionEngine/ExecutionEngine.h
index 9f56ed1..fb67676 100644
--- include/llvm/ExecutionEngine/ExecutionEngine.h
+++ include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -116,6 +116,14 @@ class ExecutionEngine {
   /// using dlsym).
   bool SymbolSearchingDisabled;
 
+  /// Whether always stubs should be returned as function addresses, so that
+  /// all callsites use the same function stub, and this is the only place to
+  /// update when recompiling/relinking functions.
+  /// This avoids chains of jmps when repeatedly recompiling functions,
+  /// but adds a small burden to each method call where the function is never
+  /// recompiled.
+  bool KeepStubs;
+
   friend class EngineBuilder;  // To allow access to JITCtor and InterpCtor.
 
 protected:
@@ -409,6 +417,19 @@ public:
     return SymbolSearchingDisabled;
   }
 
+  /// setJITKeepStubs - Set whether the JIT should always keep the stubs
+  /// and call these instead of the compiled function.
+  /// This speeds up execution if repeatedly exchanging functions (via
+  /// recompileAndRelinkFunction) since it avoids chains of jmps,
+  /// but adds a small burden to each method call where the function is never
+  /// recompiled.
+  void SetKeepStubs(bool Enable = true) {
+    KeepStubs = Enable;
+  }
+  bool isKeepStubs() {
+    return KeepStubs;
+  }
+
   /// InstallLazyFunctionCreator - If an unknown function is needed, the
   /// specified function pointer is invoked to create it.  If it returns null,
   /// the JIT will abort.
diff --git lib/ExecutionEngine/ExecutionEngine.cpp lib/ExecutionEngine/ExecutionEngine.cpp
index 2890174..5b64e3b 100644
--- lib/ExecutionEngine/ExecutionEngine.cpp
+++ lib/ExecutionEngine/ExecutionEngine.cpp
@@ -61,6 +61,7 @@ ExecutionEngine::ExecutionEngine(Module *M)
   CompilingLazily         = false;
   GVCompilationDisabled   = false;
   SymbolSearchingDisabled = false;
+  KeepStubs               = false;
   Modules.push_back(M);
   assert(M && "Module is null?");
 }
diff --git lib/ExecutionEngine/JIT/JIT.cpp lib/ExecutionEngine/JIT/JIT.cpp
index f715f6f..a78f6cd 100644
--- lib/ExecutionEngine/JIT/JIT.cpp
+++ lib/ExecutionEngine/JIT/JIT.cpp
@@ -625,20 +625,31 @@ void JIT::runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked) {
            "Externally-defined function should not be in pending list.");
 
     jitTheFunction(PF, locked);
-
-    // Now that the function has been jitted, ask the JITEmitter to rewrite
-    // the stub with real address of the function.
-    updateFunctionStub(PF);
   }
 }
 
 void JIT::jitTheFunction(Function *F, const MutexGuard &locked) {
+  // If KeepStubs is set, then the global mapping should always hold the stub.
+  assert(!isKeepStubs() || getPointerToGlobalIfAvailable(F) == 0 ||
+      getPointerToGlobalIfAvailable(F) == getFunctionStubIfAvailable(F));
+
   isAlreadyCodeGenerating = true;
   jitstate->getPM(locked).run(*F);
   isAlreadyCodeGenerating = false;
 
   // clear basic block addresses after this function is done
   getBasicBlockAddressMap(locked).clear();
+
+  // If KeepStubs is set, or there is an old or temporary stub,
+  // then update that stub.
+  // If KeepStubs is set, the stub is created if not present, and also the
+  // global mapping is updated to use the stub address.
+  void *Stub = getFunctionStubIfAvailable(F);
+  if (Stub || isKeepStubs()) {
+    updateFunctionStub(F);
+    if (isKeepStubs())
+      updateGlobalMapping(F, Stub ? Stub : getFunctionStubIfAvailable(F));
+  }
 }
 
 /// getPointerToFunction - This method is used to get the address of the
@@ -760,10 +771,15 @@ void *JIT::recompileAndRelinkFunction(Function *F) {
   // Recodegen the function
   runJITOnFunction(F);
 
-  // Update state, forward the old function to the new function.
   void *Addr = getPointerToGlobalIfAvailable(F);
   assert(Addr && "Code generation didn't add function to GlobalAddress table!");
-  TJI.replaceMachineCodeForFunction(OldAddr, Addr);
+
+  // If KeepStubs is set, then all callsites only call the stub,
+  // which has already been updated.
+  // Otherwiese forward the old function to the new function.
+  if (!isKeepStubs())
+    TJI.replaceMachineCodeForFunction(OldAddr, Addr);
+
   return Addr;
 }
 
diff --git lib/ExecutionEngine/JIT/JIT.h lib/ExecutionEngine/JIT/JIT.h
index 17d33fe..b9e9499 100644
--- lib/ExecutionEngine/JIT/JIT.h
+++ lib/ExecutionEngine/JIT/JIT.h
@@ -212,6 +212,7 @@ private:
   void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked);
   void updateFunctionStub(Function *F);
   void jitTheFunction(Function *F, const MutexGuard &locked);
+  void *getFunctionStubIfAvailable(Function *F);
 
 protected:
 
diff --git lib/ExecutionEngine/JIT/JITEmitter.cpp lib/ExecutionEngine/JIT/JITEmitter.cpp
index 504c8bd..2d77f37 100644
--- lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -1269,8 +1269,8 @@ void JIT::updateFunctionStub(Function *F) {
   // Get the empty stub we generated earlier.
   assert(isa<JITEmitter>(JCE) && "Unexpected MCE?");
   JITEmitter *JE = cast<JITEmitter>(getCodeEmitter());
-  void *Stub = JE->getJITResolver().getLazyFunctionStub(F);
   void *Addr = getPointerToGlobalIfAvailable(F);
+  void *Stub = JE->getJITResolver().getLazyFunctionStub(F);
   assert(Addr != Stub && "Function must have non-stub address to be updated.");
 
   // Tell the target jit info to rewrite the stub at the specified address,
@@ -1281,6 +1281,13 @@ void JIT::updateFunctionStub(Function *F) {
   JE->finishGVStub();
 }
 
+void *JIT::getFunctionStubIfAvailable(Function *F) {
+  // Get the empty stub we generated earlier.
+  assert(isa<JITEmitter>(JCE) && "Unexpected MCE?");
+  JITEmitter *JE = cast<JITEmitter>(getCodeEmitter());
+  return JE->getJITResolver().getLazyFunctionStubIfAvailable(F);
+}
+
 /// freeMachineCodeForFunction - release machine code memory for given Function.
 ///
 void JIT::freeMachineCodeForFunction(Function *F) {

