Refactor the temporary solution of the stubs.

Also, fix test 032 and 088.

Change-Id: I84049356b29ca6d9a5c852c926190de76b285780
diff --git a/src/compiler_llvm/upcall_compiler.cc b/src/compiler_llvm/upcall_compiler.cc
index 6d14a19..691d7e5 100644
--- a/src/compiler_llvm/upcall_compiler.cc
+++ b/src/compiler_llvm/upcall_compiler.cc
@@ -144,6 +144,8 @@
   }
 
   // Invoke managed method now!
+  // TODO: If we solve the trampoline related problems, we can just get the code address and call.
+#if 0
   llvm::Value* code_field_offset_value =
     irb_.getPtrEquivInt(Method::GetCodeOffset().Int32Value());
 
@@ -151,15 +153,20 @@
     irb_.CreatePtrDisp(method_object_addr, code_field_offset_value,
                        accurate_func_type->getPointerTo()->getPointerTo());
 
-  llvm::Value* code_addr_ = irb_.CreateLoad(code_field_addr);
-  llvm::Value* code_addr;
-  // TODO: Inline check
-  llvm::Value* runtime_func = irb_.GetRuntime(runtime_support::EnsureInitialized);
-  llvm::Value* result = irb_.CreateCall2(runtime_func,
-                                         method_object_addr,
-                                         irb_.CreatePointerCast(code_addr_,
-                                                                irb_.getJObjectTy()));
-  code_addr = irb_.CreatePointerCast(result, accurate_func_type->getPointerTo());
+  llvm::Value* code_addr = irb_.CreateLoad(code_field_addr);
+#else
+  llvm::Value* result = irb_.CreateCall(irb_.GetRuntime(FixStub), method_object_addr);
+  llvm::Value* code_addr = irb_.CreatePointerCast(result, accurate_func_type->getPointerTo());
+
+  // Exception unwind.
+  llvm::Value* exception_pending = irb_.CreateCall(irb_.GetRuntime(IsExceptionPending));
+  llvm::BasicBlock* block_unwind = llvm::BasicBlock::Create(*context_, "exception_unwind", func);
+  llvm::BasicBlock* block_cont = llvm::BasicBlock::Create(*context_, "cont", func);
+  irb_.CreateCondBr(exception_pending, block_unwind, block_cont);
+  irb_.SetInsertPoint(block_unwind);
+  irb_.CreateRetVoid();
+  irb_.SetInsertPoint(block_cont);
+#endif
 
   llvm::Value* retval = irb_.CreateCall(code_addr, args);