Merge "jit/dex info: mask out top byte of 64 bit addresses"
diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp
index 2d561a5..24dc03d 100644
--- a/libunwindstack/DexFile.cpp
+++ b/libunwindstack/DexFile.cpp
@@ -44,7 +44,7 @@
   return true;
 }
 
-std::unique_ptr<DexFile> DexFile::Create(uint64_t base_addr, uint64_t file_size, Memory* memory,
+std::shared_ptr<DexFile> DexFile::Create(uint64_t base_addr, uint64_t file_size, Memory* memory,
                                          MapInfo* info) {
   static bool has_dex_support = CheckDexSupport();
   if (!has_dex_support || file_size == 0) {
@@ -79,7 +79,7 @@
   std::unique_ptr<art_api::dex::DexFile> dex;
   art_api::dex::DexFile::Create(dex_memory->GetPtr(), file_size, nullptr, location, &dex);
   if (dex != nullptr) {
-    return std::unique_ptr<DexFile>(
+    return std::shared_ptr<DexFile>(
         new DexFile(std::move(dex_memory), base_addr, file_size, std::move(dex)));
   }
   return nullptr;
diff --git a/libunwindstack/DexFile.h b/libunwindstack/DexFile.h
index a80ea94..cae3ea5 100644
--- a/libunwindstack/DexFile.h
+++ b/libunwindstack/DexFile.h
@@ -47,7 +47,7 @@
 
   bool GetFunctionName(uint64_t dex_pc, SharedString* method_name, uint64_t* method_offset);
 
-  static std::unique_ptr<DexFile> Create(uint64_t base_addr, uint64_t file_size, Memory* memory,
+  static std::shared_ptr<DexFile> Create(uint64_t base_addr, uint64_t file_size, Memory* memory,
                                          MapInfo* info);
 
  private:
diff --git a/libunwindstack/DexFiles.cpp b/libunwindstack/DexFiles.cpp
index 2a3912b..bc99012 100644
--- a/libunwindstack/DexFiles.cpp
+++ b/libunwindstack/DexFiles.cpp
@@ -28,7 +28,7 @@
 
 template <>
 bool GlobalDebugInterface<DexFile>::Load(Maps* maps, std::shared_ptr<Memory>& memory, uint64_t addr,
-                                         uint64_t size, /*out*/ std::unique_ptr<DexFile>& dex) {
+                                         uint64_t size, /*out*/ std::shared_ptr<DexFile>& dex) {
   dex = DexFile::Create(addr, size, memory.get(), maps->Find(addr));
   return dex.get() != nullptr;
 }
@@ -42,7 +42,7 @@
 
 template <>
 bool GlobalDebugInterface<DexFile>::Load(Maps*, std::shared_ptr<Memory>&, uint64_t, uint64_t,
-                                         std::unique_ptr<DexFile>&) {
+                                         std::shared_ptr<DexFile>&) {
   return false;
 }
 
diff --git a/libunwindstack/GlobalDebugImpl.h b/libunwindstack/GlobalDebugImpl.h
index 473b90b..ca6fa86 100644
--- a/libunwindstack/GlobalDebugImpl.h
+++ b/libunwindstack/GlobalDebugImpl.h
@@ -256,7 +256,7 @@
         // The symfile was already loaded - just copy the reference.
         entries->emplace(uid, it->second);
       } else if (data.symfile_addr != 0) {
-        std::unique_ptr<Symfile> symfile;
+        std::shared_ptr<Symfile> symfile;
         bool ok = this->Load(maps, memory_, data.symfile_addr, data.symfile_size.value, symfile);
         // Check seqlock first because load can fail due to race (so we want to trigger retry).
         // TODO: Extract the memory copy code before the load, so that it is immune to races.
@@ -265,7 +265,7 @@
         }
         // Exclude symbol files that fail to load (but continue loading other files).
         if (ok) {
-          entries->emplace(uid, symfile.release());
+          entries->emplace(uid, symfile);
         }
       }
 
diff --git a/libunwindstack/JitDebug.cpp b/libunwindstack/JitDebug.cpp
index 7699e5e..1aebcf5 100644
--- a/libunwindstack/JitDebug.cpp
+++ b/libunwindstack/JitDebug.cpp
@@ -25,7 +25,7 @@
 
 template <>
 bool GlobalDebugInterface<Elf>::Load(Maps*, std::shared_ptr<Memory>& memory, uint64_t addr,
-                                     uint64_t size, /*out*/ std::unique_ptr<Elf>& elf) {
+                                     uint64_t size, /*out*/ std::shared_ptr<Elf>& elf) {
   std::unique_ptr<MemoryBuffer> copy(new MemoryBuffer());
   if (!copy->Resize(size) || !memory->ReadFully(addr, copy->GetPtr(0), size)) {
     return false;
diff --git a/libunwindstack/include/GlobalDebugInterface.h b/libunwindstack/include/GlobalDebugInterface.h
index bd15c40..45eec63 100644
--- a/libunwindstack/include/GlobalDebugInterface.h
+++ b/libunwindstack/include/GlobalDebugInterface.h
@@ -37,7 +37,7 @@
 
  protected:
   bool Load(Maps* maps, std::shared_ptr<Memory>& memory, uint64_t addr, uint64_t size,
-            /*out*/ std::unique_ptr<Symfile>& dex);
+            /*out*/ std::shared_ptr<Symfile>& dex);
 };
 
 }  // namespace unwindstack
diff --git a/libunwindstack/tests/DexFileTest.cpp b/libunwindstack/tests/DexFileTest.cpp
index 1dc0db2..05b368b 100644
--- a/libunwindstack/tests/DexFileTest.cpp
+++ b/libunwindstack/tests/DexFileTest.cpp
@@ -142,7 +142,7 @@
   MemoryFake memory;
   memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
   MapInfo info(nullptr, nullptr, 0x4000, 0x10000, 0x200, 0x5, "/does/not/exist");
-  std::unique_ptr<DexFile> dex_file = DexFile::Create(0x4000, sizeof(kDexData), &memory, &info);
+  std::shared_ptr<DexFile> dex_file = DexFile::Create(0x4000, sizeof(kDexData), &memory, &info);
   ASSERT_TRUE(dex_file != nullptr);
 
   // Check it came from memory by clearing memory and verifying it fails.
@@ -169,7 +169,7 @@
   MemoryFake memory;
   memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
   MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "");
-  std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, sizeof(kDexData), &memory, &info));
+  std::shared_ptr<DexFile> dex_file(DexFile::Create(0x4000, sizeof(kDexData), &memory, &info));
   ASSERT_TRUE(dex_file != nullptr);
 
   SharedString method;
@@ -187,7 +187,7 @@
   MemoryFake memory;
   memory.SetMemory(0x4000, kDexData, sizeof(kDexData));
   MapInfo info(nullptr, nullptr, 0x100, 0x10000, 0x200, 0x5, "");
-  std::unique_ptr<DexFile> dex_file(DexFile::Create(0x4000, sizeof(kDexData), &memory, &info));
+  std::shared_ptr<DexFile> dex_file(DexFile::Create(0x4000, sizeof(kDexData), &memory, &info));
   ASSERT_TRUE(dex_file != nullptr);
 
   SharedString method;
@@ -206,7 +206,7 @@
 
   MemoryFake memory;
   MapInfo info(nullptr, nullptr, 0x4000, 0x10000, 0, 0x5, tf.path);
-  std::unique_ptr<DexFile> dex_file = DexFile::Create(0x4000, sizeof(kDexData), &memory, &info);
+  std::shared_ptr<DexFile> dex_file = DexFile::Create(0x4000, sizeof(kDexData), &memory, &info);
   EXPECT_TRUE(dex_file != nullptr);
 
   SharedString method;