Add oat file generation and tests to build

- Currently builds boot.oat for host and target
  and target oat files for art tests.
- Added cross compilation support via --strip-prefix option to dex2oat
- Reduced output to prevent build log spam (Compiler::verbose_)
- Added image roots for recovering important pointers on image load
- Redid JNI stub creation and made the stub array an image root
- Fixed JNI stub test by making JNI stub array executable
- Fixed JNI UnregisterNative to having it reinstall the JNI stub
- Fixed ARM JNI stub to generate PIC code (with irogers)
- Fixed JniCompiler to generate PIC code (with irogers)
- Fixed FindNativeMethod to handle recursive calls
- Finished checkFieldType to use Object::InstanceOf
- Fixed thread unsafe access to ClassLinker::{dex_files_,dex_caches_}
- Added ResolvedMethod variant for use with Method* for context
- Fixed ImageWriter to call FixupMethod
- Fixed ImageWriter to rewrite JNI stub references
- Improved error reporting on lack of ANDROID_DATA dir or art-cache dir
- Fixed Runtime::Start to InitLibraries before creating thread peer
- Implemented Space::IsCondemned to skip spaces loaded from images
- Implemented artFindInterfaceMethodInCache,
  allowing interface invocation from managed code

Change-Id: I603e97fa0ac44508ae05a2e47c1cdb4481678d7b
diff --git a/src/jni_compiler.cc b/src/jni_compiler.cc
index 11b99c8..eb84f14 100644
--- a/src/jni_compiler.cc
+++ b/src/jni_compiler.cc
@@ -25,7 +25,20 @@
 ByteArray* CreateJniStub();
 }
 
-JniCompiler::JniCompiler(InstructionSet insns) : jni_stub_(NULL) {
+ByteArray* JniCompiler::CreateJniStub(InstructionSet instruction_set) {
+  switch (instruction_set) {
+    case kArm:
+    case kThumb2:
+      return arm::CreateJniStub();
+    case kX86:
+      return x86::CreateJniStub();
+    default:
+      LOG(FATAL) << "Unknown InstructionSet " << (int) instruction_set;
+      return NULL;
+  }
+}
+
+JniCompiler::JniCompiler(InstructionSet insns) {
   if (insns == kThumb2) {
     // currently only ARM code generation is supported
     instruction_set_ = kArm;
@@ -36,11 +49,6 @@
 
 JniCompiler::~JniCompiler() {}
 
-// Return value helper for jobject return types
-static Object* DecodeJObjectInThread(Thread* thread, jobject obj) {
-  return thread->DecodeJObject(obj);
-}
-
 // Generate the JNI bridge for the given method, general contract:
 // - Arguments are in the managed runtime format, either on stack or in
 //   registers, a reference to the method object is supplied as part of this
@@ -68,17 +76,6 @@
   // Cache of IsStatic as we call it often enough
   const bool is_static = native_method->IsStatic();
 
-  // 0. native_method->RegisterNative(jni_stub_ stuff). Note that jni_stub_ will invoke dlsym.
-  if (jni_stub_ == NULL) {
-    if (instruction_set_ == kArm) {
-      jni_stub_ = arm::CreateJniStub();
-    } else {
-      jni_stub_ = x86::CreateJniStub();
-    }
-  }
-  if (!native_method->IsRegistered()) {
-    native_method->RegisterNative(jni_stub_->GetData());
-  }
   // TODO: Need to make sure that the stub is copied into the image. I.e.,
   // ByteArray* needs to be reachable either as a root or from the object graph.
 
@@ -347,14 +344,17 @@
     jni_conv->ResetIterator(FrameOffset(out_arg_size));
     if (jni_conv->IsCurrentParamInRegister()) {
       __ GetCurrentThread(jni_conv->CurrentParamRegister());
+      __ Call(jni_conv->CurrentParamRegister(),
+              Offset(OFFSETOF_MEMBER(Thread, pDecodeJObjectInThread)),
+              jni_conv->InterproceduralScratchRegister());
     } else {
       __ GetCurrentThread(jni_conv->CurrentParamStackOffset(),
                           jni_conv->InterproceduralScratchRegister());
+      __ Call(jni_conv->CurrentParamStackOffset(),
+              Offset(OFFSETOF_MEMBER(Thread, pDecodeJObjectInThread)),
+              jni_conv->InterproceduralScratchRegister());
     }
 
-    __ Call(reinterpret_cast<uintptr_t>(DecodeJObjectInThread),
-            jni_conv->InterproceduralScratchRegister());
-
     __ DecreaseFrameSize(out_arg_size);
     jni_conv->ResetIterator(FrameOffset(0));
   }