Merge "Remove ashmem from system/extras"
diff --git a/perfprofd/tests/perfprofd_test.cc b/perfprofd/tests/perfprofd_test.cc
index 3748f3a..530d5f4 100644
--- a/perfprofd/tests/perfprofd_test.cc
+++ b/perfprofd/tests/perfprofd_test.cc
@@ -209,7 +209,7 @@
      std::string sqexp = squeezeWhite(expected, "expected");
 
      // Strip out JIT errors.
-     std::regex jit_regex("E: Failed to open ELF file: [^ ]*ashmem/dalvik-jit-code-cache.*");
+     std::regex jit_regex("E: Failed to open ELF file: [^ ]*dalvik-jit-code-cache.*");
      auto strip_jit = [&](const std::string& str) {
        std::smatch jit_match;
        return !std::regex_match(str, jit_match, jit_regex);
diff --git a/simpleperf/cmd_record.cpp b/simpleperf/cmd_record.cpp
index ff1977e..db21d4c 100644
--- a/simpleperf/cmd_record.cpp
+++ b/simpleperf/cmd_record.cpp
@@ -1140,7 +1140,7 @@
 bool RecordCommand::ShouldOmitRecord(Record* record) {
   if (jit_debug_reader_) {
     // To profile jitted Java code, we need PROT_JIT_SYMFILE_MAP maps not overlapped by maps for
-    // /dev/ashmem/dalvik-jit-code-cache. To profile interpreted Java code, we record maps that
+    // [anon:dalvik-jit-code-cache]. To profile interpreted Java code, we record maps that
     // are not executable. Some non-exec maps (like those for stack, heap) provide misleading map
     // entries for unwinding, as in http://b/77236599. So it is better to remove
     // dalvik-jit-code-cache and other maps that only exist in memory.
diff --git a/simpleperf/read_apk.cpp b/simpleperf/read_apk.cpp
index fd0e0f7..8c85073 100644
--- a/simpleperf/read_apk.cpp
+++ b/simpleperf/read_apk.cpp
@@ -139,24 +139,29 @@
   return std::make_tuple(true, path.substr(0, pos), path.substr(pos + 2));
 }
 
-// Parse path like "/dev/ashmem/dalvik-classes.dex extracted in memory from /..base.apk (deleted)".
+// Parse path like "[anon:dalvik-classes.dex extracted in memory from /..base.apk] (deleted)",
+// or "/dev/ashmem/dalvik-classes.dex extracted in memory from /..base.apk (deleted)" on Android P.
 bool ParseExtractedInMemoryPath(const std::string& path, std::string* zip_path,
                                 std::string* entry_name) {
-  const char* prefix = "/dev/ashmem/dalvik-";
+  const char* prefixes[2] = {"[anon:dalvik-", "/dev/ashmem/dalvik-"};
   const char* key = " extracted in memory from ";
   size_t pos = path.find(key);
-  if (pos != std::string::npos && android::base::StartsWith(path, prefix)) {
-    size_t entry_name_start = strlen(prefix);
-    size_t entry_name_end = pos;
-    size_t zip_path_start = pos + strlen(key);
-    size_t zip_path_end = path.find(' ', zip_path_start);
-    if (zip_path_end == std::string::npos) {
-      zip_path_end = path.size();
-    }
-    if (entry_name_start < entry_name_end && zip_path_start < zip_path_end) {
-      *entry_name = path.substr(entry_name_start, entry_name_end - entry_name_start);
-      *zip_path = path.substr(zip_path_start, zip_path_end - zip_path_start);
-      return true;
+  if (pos != std::string::npos) {
+    for (const char* prefix : prefixes) {
+      if (android::base::StartsWith(path, prefix)) {
+        size_t entry_name_start = strlen(prefix);
+        size_t entry_name_end = pos;
+        size_t zip_path_start = pos + strlen(key);
+        size_t zip_path_end = path.find_first_of(" ]", zip_path_start);
+        if (zip_path_end == std::string::npos) {
+          zip_path_end = path.size();
+        }
+        if (entry_name_start < entry_name_end && zip_path_start < zip_path_end) {
+          *entry_name = path.substr(entry_name_start, entry_name_end - entry_name_start);
+          *zip_path = path.substr(zip_path_start, zip_path_end - zip_path_start);
+          return true;
+        }
+      }
     }
   }
   return false;
diff --git a/simpleperf/read_apk.h b/simpleperf/read_apk.h
index 329b05e..c37366b 100644
--- a/simpleperf/read_apk.h
+++ b/simpleperf/read_apk.h
@@ -90,7 +90,8 @@
 std::string GetUrlInApk(const std::string& apk_path, const std::string& elf_filename);
 std::tuple<bool, std::string, std::string> SplitUrlInApk(const std::string& path);
 
-// Parse path like "/dev/ashmem/dalvik-classes.dex extracted in memory from /..base.apk (deleted)".
+// Parse path like "[anon:dalvik-classes.dex extracted in memory from /..base.apk] (deleted)",
+// or "/dev/ashmem/dalvik-classes.dex extracted in memory from /..base.apk (deleted)" on Android P.
 bool ParseExtractedInMemoryPath(const std::string& path, std::string* zip_path,
                                 std::string* entry_name);
 
diff --git a/simpleperf/read_apk_test.cpp b/simpleperf/read_apk_test.cpp
index d5e44e1..6d8bf2d 100644
--- a/simpleperf/read_apk_test.cpp
+++ b/simpleperf/read_apk_test.cpp
@@ -46,6 +46,14 @@
 TEST(read_apk, ParseExtractedInMemoryPath) {
   std::string zip_path;
   std::string entry_name;
+  ASSERT_TRUE(ParseExtractedInMemoryPath("[anon:dalvik-classes.dex extracted in memory from "
+      "/data/app/com.example.simpleperf.simpleperfexamplepurejava-HZK6bPs3Z9SDT3a-tqmasA==/"
+      "base.apk]", &zip_path, &entry_name));
+  ASSERT_EQ(zip_path, "/data/app/com.example.simpleperf.simpleperfexamplepurejava"
+            "-HZK6bPs3Z9SDT3a-tqmasA==/base.apk");
+  ASSERT_EQ(entry_name, "classes.dex");
+  ASSERT_FALSE(ParseExtractedInMemoryPath("[anon:dalvik-thread local mark stack]",
+                                          &zip_path, &entry_name));
   ASSERT_TRUE(ParseExtractedInMemoryPath("/dev/ashmem/dalvik-classes.dex extracted in memory from "
       "/data/app/com.example.simpleperf.simpleperfexamplepurejava-HZK6bPs3Z9SDT3a-tqmasA==/base.apk"
       " (deleted)", &zip_path, &entry_name));
diff --git a/simpleperf/scripts/debug_unwind_reporter.py b/simpleperf/scripts/debug_unwind_reporter.py
index b60dea6..864003a 100755
--- a/simpleperf/scripts/debug_unwind_reporter.py
+++ b/simpleperf/scripts/debug_unwind_reporter.py
@@ -251,7 +251,7 @@
 
     def should_omit(self, sample_result, joined_record):
         # 1. Can't unwind code generated in memory.
-        for name in ['/dev/ashmem/dalvik-jit-code-cache', '//anon']:
+        for name in ['/dev/ashmem/dalvik-jit-code-cache', '[anon:dalvik-jit-code-cache]', '//anon']:
             if name in sample_result.callchain[-1].filename:
                 return True
         # 2. Don't report complete callchains, which can reach __libc_init or __start_thread in
@@ -341,7 +341,7 @@
         elif items[0] == 'callchain:':
             in_callchain = True
         elif in_callchain:
-            # "dalvik-jit-code-cache (deleted)[+346c] (/dev/ashmem/dalvik-jit-code-cache
+            # "dalvik-jit-code-cache (deleted)[+346c] ([anon:dalvik-jit-code-cache]
             #  (deleted)[+346c])"
             if re.search(r'\)\[\+\w+\]\)$', line):
                 break_pos = line.rfind('(', 0, line.rfind('('))