Avoid compile time rewriting of dex code by verifier.

Compile time rewriting of dex code leads to dead code that is causing
issues with the LLVM compiler. Make instantiation and incompatible class
change errors be detected in slow path field and invoke logic so its
safe for the compile time verification just to softly fail the effected
classes.

This change places incompatible class change logic into the class
linkers ResolveMethod and consequently changes a number of APIs.

Change-Id: Ifb25f09accea348d15180f6ff041e38dfe0d536e
diff --git a/src/compiler/Compiler.h b/src/compiler/Compiler.h
index 214f603..659b5a6 100644
--- a/src/compiler/Compiler.h
+++ b/src/compiler/Compiler.h
@@ -204,7 +204,9 @@
 
 extern "C" art::CompiledMethod* ArtCompileMethod(art::Compiler& compiler,
                                                  const art::DexFile::CodeItem* code_item,
-                                                 uint32_t access_flags, uint32_t method_idx,
+                                                 uint32_t access_flags,
+                                                 art::InvokeType invoke_type,
+                                                 uint32_t method_idx,
                                                  jobject class_loader,
                                                  const art::DexFile& dex_file);
 
diff --git a/src/compiler/CompilerIR.h b/src/compiler/CompilerIR.h
index a606287..914d2ab 100644
--- a/src/compiler/CompilerIR.h
+++ b/src/compiler/CompilerIR.h
@@ -331,6 +331,7 @@
       method_idx(0),
       code_item(NULL),
       access_flags(0),
+      invoke_type(kDirect),
       shorty(NULL),
       firstLIRInsn(NULL),
       lastLIRInsn(NULL),
@@ -440,6 +441,7 @@
   uint32_t method_idx;                // compiling method's index into method_ids of DexFile
   const DexFile::CodeItem* code_item;  // compiling method's DexFile code_item
   uint32_t access_flags;              // compiling method's access flags
+  InvokeType invoke_type;             // compiling method's invocation type
   const char* shorty;                 // compiling method's shorty
   LIR* firstLIRInsn;
   LIR* lastLIRInsn;
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index 78c0f94..3c579c4 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -742,7 +742,8 @@
 
 CompiledMethod* oatCompileMethod(Compiler& compiler,
                                  const DexFile::CodeItem* code_item,
-                                 uint32_t access_flags, uint32_t method_idx,
+                                 uint32_t access_flags, InvokeType invoke_type,
+                                 uint32_t method_idx,
                                  jobject class_loader,
                                  const DexFile& dex_file)
 {
@@ -764,6 +765,7 @@
   cUnit->method_idx = method_idx;
   cUnit->code_item = code_item;
   cUnit->access_flags = access_flags;
+  cUnit->invoke_type = invoke_type;
   cUnit->shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
   cUnit->instructionSet = compiler.GetInstructionSet();
   cUnit->insns = code_item->insns_;
@@ -1182,11 +1184,11 @@
 extern "C" art::CompiledMethod*
     ArtCompileMethod(art::Compiler& compiler,
                      const art::DexFile::CodeItem* code_item,
-                     uint32_t access_flags, uint32_t method_idx,
-                     jobject class_loader,
+                     uint32_t access_flags, art::InvokeType invoke_type,
+                     uint32_t method_idx, jobject class_loader,
                      const art::DexFile& dex_file)
 {
   CHECK_EQ(compiler.GetInstructionSet(), art::oatInstructionSet());
-  return art::oatCompileMethod(compiler, code_item, access_flags, method_idx,
-                 class_loader, dex_file);
+  return art::oatCompileMethod(compiler, code_item, access_flags, invoke_type,
+                               method_idx, class_loader, dex_file);
 }
diff --git a/src/compiler/codegen/CodegenUtil.cc b/src/compiler/codegen/CodegenUtil.cc
index dd7daba..3aea76a 100644
--- a/src/compiler/codegen/CodegenUtil.cc
+++ b/src/compiler/codegen/CodegenUtil.cc
@@ -646,9 +646,9 @@
       uint32_t target = dataLIR->operands[0];
       cUnit->compiler->AddCodePatch(cUnit->dex_file,
                                     cUnit->method_idx,
-                                    cUnit->access_flags,
+                                    cUnit->invoke_type,
                                     target,
-                                    IsDirect(dataLIR->operands[1]),
+                                    static_cast<InvokeType>(dataLIR->operands[1]),
                                     cUnit->codeBuffer.size());
       const DexFile::MethodId& id = cUnit->dex_file->GetMethodId(target);
       // unique based on target to ensure code deduplication works
@@ -661,9 +661,9 @@
       uint32_t target = dataLIR->operands[0];
       cUnit->compiler->AddMethodPatch(cUnit->dex_file,
                                       cUnit->method_idx,
-                                      cUnit->access_flags,
+                                      cUnit->invoke_type,
                                       target,
-                                      IsDirect(dataLIR->operands[1]),
+                                      static_cast<InvokeType>(dataLIR->operands[1]),
                                       cUnit->codeBuffer.size());
       const DexFile::MethodId& id = cUnit->dex_file->GetMethodId(target);
       // unique based on target to ensure code deduplication works