Populate dex cache for sharpened calls.

We ensured the resolved method was in the dex cache, but for a sharpened call
this is abstract. Ensure that the concrete method is also resolved.
Limit the use of direct dex cache based dispatch to cases where we know how to
patch the dex cache.

Bug 11389002

Change-Id: I08252686a53b5948650632837c74bcd5cbf8a862
diff --git a/compiler/dex/quick/gen_invoke.cc b/compiler/dex/quick/gen_invoke.cc
index 64938f3..62feade 100644
--- a/compiler/dex/quick/gen_invoke.cc
+++ b/compiler/dex/quick/gen_invoke.cc
@@ -350,16 +350,13 @@
                           uintptr_t direct_code, uintptr_t direct_method,
                           InvokeType type) {
   Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
-  if (cu->instruction_set != kThumb2) {
-    // Disable sharpening
-    direct_code = 0;
-    direct_method = 0;
-  }
   if (direct_code != 0 && direct_method != 0) {
     switch (state) {
     case 0:  // Get the current Method* [sets kArg0]
       if (direct_code != static_cast<unsigned int>(-1)) {
-        cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code);
+        if (cu->instruction_set != kX86) {
+          cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code);
+        }
       } else {
         CHECK_EQ(cu->dex_file, target_method.dex_file);
         LIR* data_target = cg->ScanLiteralPool(cg->code_literal_list_,
@@ -405,6 +402,7 @@
           cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code);
         } else {
           CHECK_EQ(cu->dex_file, target_method.dex_file);
+          CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
           LIR* data_target = cg->ScanLiteralPool(cg->code_literal_list_,
                                                  target_method.dex_method_index, 0);
           if (data_target == NULL) {
@@ -501,10 +499,6 @@
                                  uint32_t unused, uintptr_t unused2,
                                  uintptr_t direct_method, InvokeType unused4) {
   Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
-  if (cu->instruction_set != kThumb2) {
-    // Disable sharpening
-    direct_method = 0;
-  }
   ThreadOffset trampoline = QUICK_ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline);
 
   if (direct_method != 0) {