Code cleanup. Full sharpening.

Change-Id: I6e8238f64a6a8fe15f9ff018ab88a9a615282cbf
diff --git a/src/compiler_llvm/art_module.ll b/src/compiler_llvm/art_module.ll
index 457efa2..eb2e1b8 100644
--- a/src/compiler_llvm/art_module.ll
+++ b/src/compiler_llvm/art_module.ll
@@ -172,6 +172,4 @@
 
 declare void @art_mark_gc_card_from_code(%JavaObject*, %JavaObject*)
 
-declare %JavaObject* @art_fix_stub_from_code(%JavaObject*)
-
 declare void @art_proxy_invoke_handler_from_code(%JavaObject*, ...)
diff --git a/src/compiler_llvm/generated/art_module.cc b/src/compiler_llvm/generated/art_module.cc
index 491d1ec..033316d 100644
--- a/src/compiler_llvm/generated/art_module.cc
+++ b/src/compiler_llvm/generated/art_module.cc
@@ -976,17 +976,6 @@
 AttrListPtr func_art_mark_gc_card_from_code_PAL;
 func_art_mark_gc_card_from_code->setAttributes(func_art_mark_gc_card_from_code_PAL);
 
-Function* func_art_fix_stub_from_code = mod->getFunction("art_fix_stub_from_code");
-if (!func_art_fix_stub_from_code) {
-func_art_fix_stub_from_code = Function::Create(
- /*Type=*/FuncTy_4,
- /*Linkage=*/GlobalValue::ExternalLinkage,
- /*Name=*/"art_fix_stub_from_code", mod); // (external, no body)
-func_art_fix_stub_from_code->setCallingConv(CallingConv::C);
-}
-AttrListPtr func_art_fix_stub_from_code_PAL;
-func_art_fix_stub_from_code->setAttributes(func_art_fix_stub_from_code_PAL);
-
 Function* func_art_proxy_invoke_handler_from_code = mod->getFunction("art_proxy_invoke_handler_from_code");
 if (!func_art_proxy_invoke_handler_from_code) {
 func_art_proxy_invoke_handler_from_code = Function::Create(
diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc
index 6c3bdb0..13f2327 100644
--- a/src/compiler_llvm/method_compiler.cc
+++ b/src/compiler_llvm/method_compiler.cc
@@ -2738,7 +2738,7 @@
 
   // Compute invoke related information for compiler decision
   int vtable_idx = -1;
-  uintptr_t direct_code = 0; // Currently unused
+  uintptr_t direct_code = 0;
   uintptr_t direct_method = 0;
   bool is_fast_path = compiler_->
     ComputeInvokeInfo(callee_method_idx, oat_compilation_unit_,
@@ -2834,11 +2834,19 @@
     }
   }
 
-  llvm::Value* code_addr =
-    irb_.LoadFromObjectOffset(callee_method_object_addr,
-                              Method::GetCodeOffset().Int32Value(),
-                              GetFunctionType(callee_method_idx, is_static)->getPointerTo(),
-                              kTBAAJRuntime);
+  llvm::Value* code_addr;
+  if (direct_code != 0u &&
+      direct_code != static_cast<uintptr_t>(-1)) {
+    code_addr =
+      irb_.CreateIntToPtr(irb_.getPtrEquivInt(direct_code),
+                          GetFunctionType(callee_method_idx, is_static)->getPointerTo());
+  } else {
+    code_addr =
+      irb_.LoadFromObjectOffset(callee_method_object_addr,
+                                Method::GetCodeOffset().Int32Value(),
+                                GetFunctionType(callee_method_idx, is_static)->getPointerTo(),
+                                kTBAAJRuntime);
+  }
 
   // Invoke callee
   EmitUpdateDexPC(dex_pc);
diff --git a/src/compiler_llvm/method_compiler.h b/src/compiler_llvm/method_compiler.h
index ec27d96..41c43f0 100644
--- a/src/compiler_llvm/method_compiler.h
+++ b/src/compiler_llvm/method_compiler.h
@@ -201,14 +201,6 @@
   void EmitInsn_SPut(GEN_INSN_ARGS, JType field_jty);
 
   // INVOKE instructions
-  llvm::Value* EmitFixStub(llvm::Value* callee_method_object_addr,
-                           uint32_t method_idx,
-                           bool is_static);
-  llvm::Value* EmitEnsureResolved(llvm::Value* callee,
-                                  llvm::Value* caller,
-                                  uint32_t dex_method_idx,
-                                  bool is_virtual);
-
   void EmitInsn_Invoke(GEN_INSN_ARGS,
                        InvokeType invoke_type,
                        InvokeArgFmt arg_fmt);
diff --git a/src/compiler_llvm/runtime_support_func_list.h b/src/compiler_llvm/runtime_support_func_list.h
index 62729c6..30c6d6b 100644
--- a/src/compiler_llvm/runtime_support_func_list.h
+++ b/src/compiler_llvm/runtime_support_func_list.h
@@ -63,7 +63,6 @@
   V(IsExceptionPending, art_is_exception_pending_from_code) \
   V(FindCatchBlock, art_find_catch_block_from_code) \
   V(MarkGCCard, art_mark_gc_card_from_code) \
-  V(FixStub, art_fix_stub_from_code) \
   V(ProxyInvokeHandler, art_proxy_invoke_handler_from_code) \
   V(DecodeJObjectInThread, art_decode_jobject_in_thread) \
   V(art_d2l, art_d2l) \
diff --git a/src/compiler_llvm/runtime_support_llvm.cc b/src/compiler_llvm/runtime_support_llvm.cc
index cfaaea4..155fb7c 100644
--- a/src/compiler_llvm/runtime_support_llvm.cc
+++ b/src/compiler_llvm/runtime_support_llvm.cc
@@ -639,21 +639,6 @@
   }
 }
 
-// TODO: This runtime support function is the temporary solution for the link issue.
-// It calls to this function before invoking any function, and this function will check:
-// 1. The code address is 0.                       -> Link the code by ELFLoader
-// That will solved by in-place linking at image loading.
-const void* art_fix_stub_from_code(Method* called) {
-  const void* code = called->GetCode();
-  // 1. The code address is 0.                       -> Link the code by ELFLoader
-  if (UNLIKELY(code == NULL)) {
-    Runtime::Current()->GetClassLinker()->LinkOatCodeFor(called);
-    return called->GetCode();
-  }
-
-  return code;
-}
-
 // Handler for invocation on proxy methods. We create a boxed argument array. And we invoke
 // the invocation handler which is a field within the proxy object receiver.
 void art_proxy_invoke_handler_from_code(Method* proxy_method, ...) {
diff --git a/src/compiler_llvm/runtime_support_llvm.h b/src/compiler_llvm/runtime_support_llvm.h
index 8ab28c6..dabd88f 100644
--- a/src/compiler_llvm/runtime_support_llvm.h
+++ b/src/compiler_llvm/runtime_support_llvm.h
@@ -63,8 +63,6 @@
 
 void* art_find_runtime_support_func(void* context, char const* name);
 
-const void* art_fix_stub_from_code(Method* called);
-
 }  // namespace art
 
 #endif  // ART_SRC_COMPILER_LLVM_RUNTIME_SUPPORT_LLVM_H_