Revert "Revert "Add JIT""

Added missing EntryPointToCodePointer.

This reverts commit a5ca888d715cd0c6c421313211caa1928be3e399.

Change-Id: Ia74df0ef3a7babbdcb0466fd24da28e304e3f5af
diff --git a/runtime/mirror/art_field.cc b/runtime/mirror/art_field.cc
index 5a4ebd1..3cea4a1 100644
--- a/runtime/mirror/art_field.cc
+++ b/runtime/mirror/art_field.cc
@@ -44,7 +44,7 @@
 
 void ArtField::SetOffset(MemberOffset num_bytes) {
   DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous());
-  if (kIsDebugBuild && Runtime::Current()->IsCompiler() &&
+  if (kIsDebugBuild && Runtime::Current()->IsAotCompiler() &&
       !Runtime::Current()->UseCompileTimeClassPath()) {
     Primitive::Type type = GetTypeAsPrimitiveType();
     if (type == Primitive::kPrimDouble || type == Primitive::kPrimLong) {
diff --git a/runtime/mirror/art_method-inl.h b/runtime/mirror/art_method-inl.h
index 7d31148..c27c6e9 100644
--- a/runtime/mirror/art_method-inl.h
+++ b/runtime/mirror/art_method-inl.h
@@ -147,7 +147,10 @@
 
 inline uint32_t ArtMethod::GetCodeSize() {
   DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this);
-  const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode());
+  return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()));
+}
+
+inline uint32_t ArtMethod::GetCodeSize(const void* code) {
   if (code == nullptr) {
     return 0u;
   }
diff --git a/runtime/mirror/art_method.cc b/runtime/mirror/art_method.cc
index b2016dc..26f6f34 100644
--- a/runtime/mirror/art_method.cc
+++ b/runtime/mirror/art_method.cc
@@ -27,6 +27,8 @@
 #include "entrypoints/runtime_asm_entrypoints.h"
 #include "gc/accounting/card_table-inl.h"
 #include "interpreter/interpreter.h"
+#include "jit/jit.h"
+#include "jit/jit_code_cache.h"
 #include "jni_internal.h"
 #include "mapping_table.h"
 #include "object_array-inl.h"
@@ -229,6 +231,7 @@
   if (abort_on_failure) {
       LOG(FATAL) << "Failed to find Dex offset for PC offset " << reinterpret_cast<void*>(sought_offset)
              << "(PC " << reinterpret_cast<void*>(pc) << ", entry_point=" << entry_point
+             << " current entry_point=" << GetQuickOatEntryPoint(sizeof(void*))
              << ") in " << PrettyMethod(this);
   }
   return DexFile::kDexNoIndex;
@@ -329,6 +332,13 @@
       class_linker->IsQuickResolutionStub(code)) {
     return;
   }
+  // If we are the JIT then we may have just compiled the method after the
+  // IsQuickToInterpreterBridge check.
+  jit::Jit* const jit = Runtime::Current()->GetJit();
+  if (jit != nullptr &&
+      jit->GetCodeCache()->ContainsCodePtr(reinterpret_cast<const void*>(code))) {
+    return;
+  }
   /*
    * During a stack walk, a return PC may point past-the-end of the code
    * in the case that the last instruction is a call that isn't expected to
@@ -336,11 +346,12 @@
    *
    * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
    */
-  CHECK(PcIsWithinQuickCode(pc))
+  CHECK(PcIsWithinQuickCode(reinterpret_cast<uintptr_t>(code), pc))
       << PrettyMethod(this)
       << " pc=" << std::hex << pc
       << " code=" << code
-      << " size=" << GetCodeSize();
+      << " size=" << GetCodeSize(
+          EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
 }
 
 bool ArtMethod::IsEntrypointInterpreter() {
@@ -410,7 +421,8 @@
       }
 
       // Ensure that we won't be accidentally calling quick compiled code when -Xint.
-      if (kIsDebugBuild && Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly()) {
+      if (kIsDebugBuild && runtime->GetInstrumentation()->IsForcedInterpretOnly()) {
+        DCHECK(!runtime->UseJit());
         CHECK(IsEntrypointInterpreter())
             << "Don't call compiled code when -Xint " << PrettyMethod(this);
       }
diff --git a/runtime/mirror/art_method.h b/runtime/mirror/art_method.h
index f33ca94..d878f25 100644
--- a/runtime/mirror/art_method.h
+++ b/runtime/mirror/art_method.h
@@ -305,18 +305,8 @@
   // quick entrypoint. This code isn't robust for instrumentation, etc. and is only used for
   // debug purposes.
   bool PcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    uintptr_t code = reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode());
-    if (code == 0) {
-      return pc == 0;
-    }
-    /*
-     * During a stack walk, a return PC may point past-the-end of the code
-     * in the case that the last instruction is a call that isn't expected to
-     * return.  Thus, we check <= code + GetCodeSize().
-     *
-     * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
-     */
-    return code <= pc && pc <= code + GetCodeSize();
+    return PcIsWithinQuickCode(
+        reinterpret_cast<uintptr_t>(GetEntryPointFromQuickCompiledCode()), pc);
   }
 
   void AssertPcIsWithinQuickCode(uintptr_t pc) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -622,6 +612,24 @@
     return offset;
   }
 
+  // Code points to the start of the quick code.
+  static uint32_t GetCodeSize(const void* code);
+
+  static bool PcIsWithinQuickCode(uintptr_t code, uintptr_t pc) {
+    if (code == 0) {
+      return pc == 0;
+    }
+    /*
+     * During a stack walk, a return PC may point past-the-end of the code
+     * in the case that the last instruction is a call that isn't expected to
+     * return.  Thus, we check <= code + GetCodeSize().
+     *
+     * NOTE: For Thumb both pc and code are offset by 1 indicating the Thumb state.
+     */
+    return code <= pc && pc <= code + GetCodeSize(
+        EntryPointToCodePointer(reinterpret_cast<const void*>(code)));
+  }
+
   friend struct art::ArtMethodOffsets;  // for verifying offset information
   DISALLOW_IMPLICIT_CONSTRUCTORS(ArtMethod);
 };