Remove `CompiledCode::CodePointer()`.

And clean up some related test helpers in preparation for
moving `CompiledMethod` to dex2oat/.

Test: m test-art-host-gtest
Test: run-gtests.sh
Change-Id: I13b42bfb4f6ee3a7f7f22bbc8d22203c5d56e00b
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 7d7b70b..99fb581 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -59,8 +59,8 @@
     OatQuickMethodHeader method_header(vmap_table_offset);
     const size_t code_alignment = GetInstructionSetCodeAlignment(instruction_set);
     DCHECK_ALIGNED_PARAM(kPageSize, code_alignment);
-    code_offset_ = RoundUp(vmap_table.size() + sizeof(method_header), code_alignment);
-    const uint32_t capacity = RoundUp(code_offset_ + code_size, kPageSize);
+    const uint32_t code_offset = RoundUp(vmap_table.size() + sizeof(method_header), code_alignment);
+    const uint32_t capacity = RoundUp(code_offset + code_size, kPageSize);
 
     // Create a memfd handle with sufficient capacity.
     android::base::unique_fd mem_fd(art::memfd_create_compat("test code", /*flags=*/ 0));
@@ -81,12 +81,12 @@
     CHECK(rw_map_.IsValid()) << error_msg;
 
     // Store data.
-    uint8_t* code_addr = rw_map_.Begin() + code_offset_;
+    uint8_t* code_addr = rw_map_.Begin() + code_offset;
     CHECK_ALIGNED_PARAM(code_addr, code_alignment);
-    CHECK_LE(vmap_table_offset, code_offset_);
+    CHECK_LE(vmap_table_offset, code_offset);
     memcpy(code_addr - vmap_table_offset, vmap_table.data(), vmap_table.size());
     static_assert(std::is_trivially_copyable<OatQuickMethodHeader>::value, "Cannot use memcpy");
-    CHECK_LE(sizeof(method_header), code_offset_);
+    CHECK_LE(sizeof(method_header), code_offset);
     memcpy(code_addr - sizeof(method_header), &method_header, sizeof(method_header));
     CHECK_LE(code_size, static_cast<size_t>(rw_map_.End() - code_addr));
     memcpy(code_addr, code.data(), code_size);
@@ -107,18 +107,21 @@
                               /*filename=*/ "test code",
                               &error_msg);
     CHECK(rx_map_.IsValid()) << error_msg;
+
+    DCHECK_LT(code_offset, rx_map_.Size());
+    size_t adjustment = GetInstructionSetEntryPointAdjustment(instruction_set);
+    entry_point_ = rx_map_.Begin() + code_offset + adjustment;
   }
 
-  const void* GetCodePointer() const {
+  const void* GetEntryPoint() const {
     DCHECK(rx_map_.IsValid());
-    DCHECK_LE(code_offset_, rx_map_.Size());
-    return rx_map_.Begin() + code_offset_;
+    return entry_point_;
   }
 
  private:
   MemMap rw_map_;
   MemMap rx_map_;
-  uint32_t code_offset_;
+  const void* entry_point_;
 
   DISALLOW_COPY_AND_ASSIGN(CodeAndMetadata);
 };
@@ -142,24 +145,7 @@
                                                    InstructionSet instruction_set) {
   CHECK_NE(code.size(), 0u);
   code_and_metadata_.emplace_back(code, vmap_table, instruction_set);
-  return code_and_metadata_.back().GetCodePointer();
-}
-
-void CommonCompilerTestImpl::MakeExecutable(ArtMethod* method,
-                                            const CompiledMethod* compiled_method) {
-  CHECK(method != nullptr);
-  const void* method_code = nullptr;
-  // If the code size is 0 it means the method was skipped due to profile guided compilation.
-  if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) {
-    const void* code_ptr = MakeExecutable(compiled_method->GetQuickCode(),
-                                          compiled_method->GetVmapTable(),
-                                          compiled_method->GetInstructionSet());
-    method_code =
-        CompiledMethod::CodePointer(code_ptr, compiled_method->GetInstructionSet());
-    LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code;
-  }
-  Runtime::Current()->GetInstrumentation()->InitializeMethodsCode(
-      method, /*aot_code=*/ method_code);
+  return code_and_metadata_.back().GetEntryPoint();
 }
 
 void CommonCompilerTestImpl::SetUp() {
@@ -253,11 +239,16 @@
                                           dex_file,
                                           dex_cache);
     }
+    CHECK(compiled_method != nullptr) << "Failed to compile " << method->PrettyMethod();
+    CHECK_NE(compiled_method->GetQuickCode().size(), 0u);
   }
-  CHECK(method != nullptr);
   {
     TimingLogger::ScopedTiming t2("MakeExecutable", &timings);
-    MakeExecutable(method, compiled_method);
+    const void* method_code = MakeExecutable(compiled_method->GetQuickCode(),
+                                             compiled_method->GetVmapTable(),
+                                             compiled_method->GetInstructionSet());
+    LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code;
+    GetRuntime()->GetInstrumentation()->InitializeMethodsCode(method, /*aot_code=*/ method_code);
   }
   CompiledMethod::ReleaseSwapAllocatedCompiledMethod(&storage, compiled_method);
 }
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index cc74f8f..be2e483 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -33,7 +33,6 @@
 class ClassLoader;
 }  // namespace mirror
 
-class CompiledMethod;
 class CompilerOptions;
 class CumulativeLogger;
 class DexFile;
@@ -54,9 +53,6 @@
                              ArrayRef<const uint8_t> vmap_table,
                              InstructionSet instruction_set);
 
-  void MakeExecutable(ArtMethod* method, const CompiledMethod* compiled_method)
-      REQUIRES_SHARED(Locks::mutator_lock_);
-
  protected:
   void SetUp();
 
diff --git a/compiler/compiled_method.cc b/compiler/compiled_method.cc
index 21d5ed9..0a0a005 100644
--- a/compiler/compiled_method.cc
+++ b/compiler/compiled_method.cc
@@ -58,25 +58,6 @@
   return GetInstructionSetEntryPointAdjustment(GetInstructionSet());
 }
 
-const void* CompiledCode::CodePointer(const void* code_pointer, InstructionSet instruction_set) {
-  switch (instruction_set) {
-    case InstructionSet::kArm:
-    case InstructionSet::kArm64:
-    case InstructionSet::kX86:
-    case InstructionSet::kX86_64:
-      return code_pointer;
-    case InstructionSet::kThumb2: {
-      uintptr_t address = reinterpret_cast<uintptr_t>(code_pointer);
-      // Set the low-order bit so a BLX will switch to Thumb mode
-      address |= 0x1;
-      return reinterpret_cast<const void*>(address);
-    }
-    default:
-      LOG(FATAL) << "Unknown InstructionSet: " << instruction_set;
-      UNREACHABLE();
-  }
-}
-
 CompiledMethod::CompiledMethod(CompiledMethodStorage* storage,
                                InstructionSet instruction_set,
                                const ArrayRef<const uint8_t>& quick_code,
diff --git a/compiler/compiled_method.h b/compiler/compiled_method.h
index fa80d67..ed31ca7 100644
--- a/compiler/compiled_method.h
+++ b/compiler/compiled_method.h
@@ -62,11 +62,6 @@
   // Mainly to cope with `kThumb2` where the lower bit must be set.
   size_t GetEntryPointAdjustment() const;
 
-  // Returns a pointer suitable for invoking the code at the argument
-  // code_pointer address.  Mainly to cope with kThumb2 where the
-  // lower bit must be set to indicate Thumb mode.
-  static const void* CodePointer(const void* code_pointer, InstructionSet instruction_set);
-
  protected:
   static constexpr size_t kInstructionSetFieldSize =
       MinimumBitsToStore(static_cast<size_t>(InstructionSet::kLast));
diff --git a/compiler/optimizing/codegen_test_utils.h b/compiler/optimizing/codegen_test_utils.h
index 95cb548..8e93f4d 100644
--- a/compiler/optimizing/codegen_test_utils.h
+++ b/compiler/optimizing/codegen_test_utils.h
@@ -254,15 +254,11 @@
     Runtime* GetRuntime() override { return nullptr; }
   };
   CodeHolder code_holder;
-  const void* code_ptr =
+  const void* method_code =
       code_holder.MakeExecutable(allocator.GetMemory(), ArrayRef<const uint8_t>(), target_isa);
 
   using fptr = Expected (*)();
-  fptr f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(code_ptr));
-  if (target_isa == InstructionSet::kThumb2) {
-    // For thumb we need the bottom bit set.
-    f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(f) + 1);
-  }
+  fptr f = reinterpret_cast<fptr>(reinterpret_cast<uintptr_t>(method_code));
   VerifyGeneratedCode(target_isa, f, has_result, expected);
 }
 
diff --git a/dex2oat/driver/compiler_driver_test.cc b/dex2oat/driver/compiler_driver_test.cc
index 65aa888..7e3f40c 100644
--- a/dex2oat/driver/compiler_driver_test.cc
+++ b/dex2oat/driver/compiler_driver_test.cc
@@ -25,6 +25,7 @@
 #include "base/casts.h"
 #include "class_linker-inl.h"
 #include "common_compiler_driver_test.h"
+#include "compiled_method-inl.h"
 #include "compiler_callbacks.h"
 #include "dex/dex_file.h"
 #include "dex/dex_file_types.h"
@@ -80,14 +81,19 @@
   void MakeExecutable(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) {
     CHECK(method != nullptr);
 
-    const CompiledMethod* compiled_method = nullptr;
+    const void* method_code = nullptr;
     if (!method->IsAbstract()) {
-      const DexFile& dex_file = *method->GetDexFile();
-      compiled_method =
-          compiler_driver_->GetCompiledMethod(MethodReference(&dex_file,
-                                                              method->GetDexMethodIndex()));
+      MethodReference method_ref(method->GetDexFile(), method->GetDexMethodIndex());
+      const CompiledMethod* compiled_method = compiler_driver_->GetCompiledMethod(method_ref);
+      // If the code size is 0 it means the method was skipped due to profile guided compilation.
+      if (compiled_method != nullptr && compiled_method->GetQuickCode().size() != 0u) {
+        method_code = CommonCompilerTest::MakeExecutable(compiled_method->GetQuickCode(),
+                                                         compiled_method->GetVmapTable(),
+                                                         compiled_method->GetInstructionSet());
+        LOG(INFO) << "MakeExecutable " << method->PrettyMethod() << " code=" << method_code;
+      }
     }
-    CommonCompilerTest::MakeExecutable(method, compiled_method);
+    runtime_->GetInstrumentation()->InitializeMethodsCode(method, /*aot_code=*/ method_code);
   }
 
   void MakeDexFileExecutable(jobject class_loader, const DexFile& dex_file) {