Add ELF index to art::CompiledMethod.

(cherry picked from commit fd9514dbab8eaca357b6d712bb7e1b635617f92e)

Change-Id: I79bff6bf9d05ce6ffc25c3cef41d1acefc4d8d2a
diff --git a/src/compiled_method.cc b/src/compiled_method.cc
index 3328ab0..e85809c 100644
--- a/src/compiled_method.cc
+++ b/src/compiled_method.cc
@@ -18,13 +18,6 @@
 
 namespace art {
 
-#if defined(ART_USE_LLVM_COMPILER)
-CompiledMethod::CompiledMethod(art::InstructionSet instruction_set,
-                               llvm::Function *func)
-    : instruction_set_(instruction_set), func_(func), frame_size_in_bytes_(0),
-      core_spill_mask_(0), fp_spill_mask_(0) {
-}
-#endif
 CompiledMethod::CompiledMethod(InstructionSet instruction_set,
                                const std::vector<uint8_t>& code,
                                const size_t frame_size_in_bytes,
@@ -33,7 +26,9 @@
                                const std::vector<uint32_t>& mapping_table,
                                const std::vector<uint16_t>& vmap_table)
     : instruction_set_(instruction_set), frame_size_in_bytes_(frame_size_in_bytes),
-      core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask) {
+      core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask),
+      elf_idx_(-1)
+{
   CHECK_NE(code.size(), 0U);
   DCHECK_EQ(vmap_table.size(),
             static_cast<uint32_t>(__builtin_popcount(core_spill_mask)
@@ -82,10 +77,17 @@
                                const uint32_t core_spill_mask,
                                const uint32_t fp_spill_mask)
     : instruction_set_(instruction_set), code_(code), frame_size_in_bytes_(frame_size_in_bytes),
-      core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask) {
+      core_spill_mask_(core_spill_mask), fp_spill_mask_(fp_spill_mask),
+      elf_idx_(-1)
+{
   CHECK_NE(code.size(), 0U);
 }
 
+CompiledMethod::CompiledMethod(InstructionSet instruction_set, size_t elf_idx)
+    : instruction_set_(instruction_set), frame_size_in_bytes_(0),
+      core_spill_mask_(0), fp_spill_mask_(0), elf_idx_(elf_idx) {
+}
+
 CompiledMethod::~CompiledMethod() {}
 
 InstructionSet CompiledMethod::GetInstructionSet() const {
@@ -171,11 +173,12 @@
 }
 
 #if defined(ART_USE_LLVM_COMPILER)
-CompiledInvokeStub::CompiledInvokeStub(llvm::Function* func) : func_(func) {
-  CHECK_NE(func, static_cast<llvm::Function*>(NULL));
+CompiledInvokeStub::CompiledInvokeStub(size_t elf_idx) : elf_idx_(elf_idx) {
 }
 #endif
-CompiledInvokeStub::CompiledInvokeStub(std::vector<uint8_t>& code) {
+
+CompiledInvokeStub::CompiledInvokeStub(std::vector<uint8_t>& code)
+    : elf_idx_(-1) {
   CHECK_NE(code.size(), 0U);
   code_ = code;
 }
diff --git a/src/compiled_method.h b/src/compiled_method.h
index 6dc5128..d2c28a7 100644
--- a/src/compiled_method.h
+++ b/src/compiled_method.h
@@ -30,11 +30,6 @@
 
 class CompiledMethod {
  public:
-#if defined(ART_USE_LLVM_COMPILER)
-  // Constructs a CompiledMethod for the LLVM compiler.
-  CompiledMethod(InstructionSet instruction_set, llvm::Function* func);
-#endif
-
   // Constructs a CompiledMethod for the non-LLVM compilers.
   CompiledMethod(InstructionSet instruction_set,
                  const std::vector<uint8_t>& code,
@@ -54,6 +49,9 @@
                  const uint32_t core_spill_mask,
                  const uint32_t fp_spill_mask);
 
+  // Constructs a CompiledMethod for the LLVM compiler.
+  CompiledMethod(InstructionSet instruction_set, size_t elf_idx);
+
   ~CompiledMethod();
 
   InstructionSet GetInstructionSet() const;
@@ -81,11 +79,17 @@
   static const void* CodePointer(const void* code_pointer,
                                  InstructionSet instruction_set);
 
+  size_t GetElfIndex() const {
+    return elf_idx_;
+  }
+
+  bool IsExecutableInElf() const {
+    return (elf_idx_ != static_cast<size_t>(-1));
+  }
+
  private:
+  // For non-LLVM
   const InstructionSet instruction_set_;
-#if defined(ART_USE_LLVM_COMPILER)
-  llvm::Function* func_;
-#endif
   std::vector<uint8_t> code_;
   const size_t frame_size_in_bytes_;
   const uint32_t core_spill_mask_;
@@ -93,23 +97,31 @@
   std::vector<uint32_t> mapping_table_;
   std::vector<uint16_t> vmap_table_;
   std::vector<uint8_t> gc_map_;
+  // For LLVM
+  size_t elf_idx_;
 };
 
 class CompiledInvokeStub {
  public:
-#if defined(ART_USE_LLVM_COMPILER)
-  explicit CompiledInvokeStub(llvm::Function* func);
-#endif
   explicit CompiledInvokeStub(std::vector<uint8_t>& code);
-  ~CompiledInvokeStub();
-  const std::vector<uint8_t>& GetCode() const;
- private:
 #if defined(ART_USE_LLVM_COMPILER)
-  llvm::Function* func_;
+  explicit CompiledInvokeStub(size_t elf_idx);
 #endif
-  // TODO: Change the line above from #endif to #else, after oat_writer is
-  // changed.
+  ~CompiledInvokeStub();
+
+  const std::vector<uint8_t>& GetCode() const;
+
+  size_t GetElfIndex() const {
+    return elf_idx_;
+  }
+
+  bool IsExecutableInElf() const {
+    return (elf_idx_ != static_cast<size_t>(-1));
+  }
+
+ private:
   std::vector<uint8_t> code_;
+  size_t elf_idx_;
 };
 
 }  // namespace art
diff --git a/src/compiler_llvm/jni_compiler.cc b/src/compiler_llvm/jni_compiler.cc
index 6cccbe1..ad730dc 100644
--- a/src/compiler_llvm/jni_compiler.cc
+++ b/src/compiler_llvm/jni_compiler.cc
@@ -253,7 +253,8 @@
   // Verify the generated bitcode
   llvm::verifyFunction(*func_, llvm::PrintMessageAction);
 
-  return new CompiledMethod(cunit_->GetInstructionSet(), func_);
+  return new CompiledMethod(cunit_->GetInstructionSet(),
+                            cunit_->GetElfIndex());
 }
 
 
diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc
index 0c04bf1..2269be7 100644
--- a/src/compiler_llvm/method_compiler.cc
+++ b/src/compiler_llvm/method_compiler.cc
@@ -3580,7 +3580,8 @@
   // Dex file.  Besides, we have to convert the code unit into bytes.
   // Thus, we got our magic number 9.
 
-  return new CompiledMethod(cunit_->GetInstructionSet(), func_);
+  return new CompiledMethod(cunit_->GetInstructionSet(),
+                            cunit_->GetElfIndex());
 }
 
 
diff --git a/src/compiler_llvm/upcall_compiler.cc b/src/compiler_llvm/upcall_compiler.cc
index ec433c2..20bd94b 100644
--- a/src/compiler_llvm/upcall_compiler.cc
+++ b/src/compiler_llvm/upcall_compiler.cc
@@ -179,7 +179,7 @@
   // store ret_addr, and ret_void.  Beside, we guess that we have to use
   // 50 bytes to represent one LLVM instruction.
 
-  return new CompiledInvokeStub(func);
+  return new CompiledInvokeStub(cunit_->GetElfIndex());
 }