Merge "Revert "Include core library jars in runtime apex.""
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index f00da9c..3dab025 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -198,7 +198,7 @@
 ART_GTEST_oat_file_assistant_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
 ART_GTEST_dexoptanalyzer_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
 ART_GTEST_image_space_test_DEX_DEPS := $(ART_GTEST_dex2oat_environment_tests_DEX_DEPS)
-ART_GTEST_oat_file_test_DEX_DEPS := Main MultiDex MainUncompressed MultiDexUncompressed
+ART_GTEST_oat_file_test_DEX_DEPS := Main MultiDex MainUncompressed MultiDexUncompressed MainStripped Nested MultiDexModifiedSecondary
 ART_GTEST_oat_test_DEX_DEPS := Main
 ART_GTEST_oat_writer_test_DEX_DEPS := Main
 ART_GTEST_object_test_DEX_DEPS := ProtoCompare ProtoCompare2 StaticsFromCode XandY
diff --git a/build/apex/ld.config.txt b/build/apex/ld.config.txt
index 0129772..d5eb9fa 100644
--- a/build/apex/ld.config.txt
+++ b/build/apex/ld.config.txt
@@ -10,9 +10,13 @@
 [runtime]
 additional.namespaces = platform,conscrypt
 
-# Keep in sync with runtime namespace in /system/etc/ld.config.txt.
+# Keep in sync with the runtime namespace in /system/etc/ld.config.txt.
 namespace.default.isolated = true
+# Visible because some libraries are dlopen'ed, e.g. libopenjdk is dlopen'ed by
+# libart.
+namespace.default.visible = true
 namespace.default.search.paths = /apex/com.android.runtime/${LIB}
+namespace.default.asan.search.paths = /apex/com.android.runtime/${LIB}
 # odex files are in /system/framework. dalvikvm has to be able to dlopen the
 # files for CTS.
 namespace.default.permitted.paths = /system/framework
@@ -20,9 +24,10 @@
 # TODO(b/119867084): Restrict fallback to platform namespace to PALette library.
 namespace.default.link.platform.allow_all_shared_libs = true
 
-# Keep in sync with default namespace in /system/etc/ld.config.txt.
+# Keep in sync with the default namespace in /system/etc/ld.config.txt.
 namespace.platform.isolated = true
 namespace.platform.search.paths = /system/${LIB}
+namespace.platform.asan.search.paths = /data/asan/system/${LIB}
 namespace.platform.links = default
 namespace.platform.link.default.shared_libs  = libart.so:libartd.so
 namespace.platform.link.default.shared_libs += libnativebridge.so
@@ -44,6 +49,7 @@
 namespace.conscrypt.visible = true
 
 namespace.conscrypt.search.paths = /apex/com.android.conscrypt/${LIB}
+namespace.conscrypt.asan.search.paths = /apex/com.android.conscrypt/${LIB}
 namespace.conscrypt.links = platform
 namespace.conscrypt.link.platform.shared_libs  = libc.so
 namespace.conscrypt.link.platform.shared_libs += libm.so
diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc
index 3b34e8d..42dbc77 100644
--- a/compiler/optimizing/optimizing_compiler.cc
+++ b/compiler/optimizing/optimizing_compiler.cc
@@ -1460,22 +1460,27 @@
                                               const debug::MethodDebugInfo& info) {
   const CompilerOptions& compiler_options = GetCompilerDriver()->GetCompilerOptions();
   DCHECK(compiler_options.GenerateAnyDebugInfo());
+  TimingLogger logger("Generate JIT debug info logger", true, VLOG_IS_ON(jit));
+  {
+    TimingLogger::ScopedTiming st("Generate JIT debug info", &logger);
 
-  // If both flags are passed, generate full debug info.
-  const bool mini_debug_info = !compiler_options.GetGenerateDebugInfo();
+    // If both flags are passed, generate full debug info.
+    const bool mini_debug_info = !compiler_options.GetGenerateDebugInfo();
 
-  // Create entry for the single method that we just compiled.
-  std::vector<uint8_t> elf_file = debug::MakeElfFileForJIT(
-      compiler_options.GetInstructionSet(),
-      compiler_options.GetInstructionSetFeatures(),
-      mini_debug_info,
-      info);
-  AddNativeDebugInfoForJit(Thread::Current(),
-                           reinterpret_cast<const void*>(info.code_address),
-                           elf_file,
-                           debug::PackElfFileForJIT,
-                           compiler_options.GetInstructionSet(),
-                           compiler_options.GetInstructionSetFeatures());
+    // Create entry for the single method that we just compiled.
+    std::vector<uint8_t> elf_file = debug::MakeElfFileForJIT(
+        compiler_options.GetInstructionSet(),
+        compiler_options.GetInstructionSetFeatures(),
+        mini_debug_info,
+        info);
+    AddNativeDebugInfoForJit(Thread::Current(),
+                             reinterpret_cast<const void*>(info.code_address),
+                             elf_file,
+                             debug::PackElfFileForJIT,
+                             compiler_options.GetInstructionSet(),
+                             compiler_options.GetInstructionSetFeatures());
+  }
+  Runtime::Current()->GetJit()->AddTimingLogger(logger);
 }
 
 }  // namespace art
diff --git a/runtime/Android.bp b/runtime/Android.bp
index a3081e9..b89eb02 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -396,10 +396,8 @@
         "libnativeloader",
         "libbacktrace",
         "liblog",
-        // For atrace, properties, ashmem.
+        // For atrace, properties, ashmem, set_sched_policy.
         "libcutils",
-        // For set_sched_policy.
-        "libprocessgroup",
         // For common macros.
         "libbase",
     ],
diff --git a/runtime/native/dalvik_system_DexFile.cc b/runtime/native/dalvik_system_DexFile.cc
index daf02fe..4f9cf70 100644
--- a/runtime/native/dalvik_system_DexFile.cc
+++ b/runtime/native/dalvik_system_DexFile.cc
@@ -244,7 +244,7 @@
   }
 
   size_t length = static_cast<size_t>(end - start);
-  memcpy(dex_mem_map.Begin(), base_address, length);
+  memcpy(dex_mem_map.Begin(), base_address + start, length);
   return CreateSingleDexFileCookie(env, std::move(dex_mem_map));
 }
 
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index f4a8c50..e433cbc 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -1410,20 +1410,23 @@
 
 std::string OatFile::ResolveRelativeEncodedDexLocation(
       const char* abs_dex_location, const std::string& rel_dex_location) {
-  // For host, we still do resolution as the rel_dex_location might be absolute
-  // for a target dex (for example /system/foo/foo.apk).
-  if (abs_dex_location != nullptr && (rel_dex_location[0] != '/' || !kIsTargetBuild)) {
-    // Strip :classes<N>.dex used for secondary multidex files.
+  if (abs_dex_location != nullptr) {
     std::string base = DexFileLoader::GetBaseLocation(rel_dex_location);
+    // Strip :classes<N>.dex used for secondary multidex files.
     std::string multidex_suffix = DexFileLoader::GetMultiDexSuffix(rel_dex_location);
-
-    // Check if the base is a suffix of the provided abs_dex_location.
-    std::string target_suffix = ((rel_dex_location[0] != '/') ? "/" : "") + base;
-    std::string abs_location(abs_dex_location);
-    if (abs_location.size() > target_suffix.size()) {
-      size_t pos = abs_location.size() - target_suffix.size();
-      if (abs_location.compare(pos, std::string::npos, target_suffix) == 0) {
-        return abs_location + multidex_suffix;
+    if (!kIsTargetBuild) {
+      // For host, we still do resolution as the rel_dex_location might be absolute
+      // for a target dex (for example /system/foo/foo.apk).
+      return std::string(abs_dex_location) + multidex_suffix;
+    } else if (rel_dex_location[0] != '/') {
+      // Check if the base is a suffix of the provided abs_dex_location.
+      std::string target_suffix = ((rel_dex_location[0] != '/') ? "/" : "") + base;
+      std::string abs_location(abs_dex_location);
+      if (abs_location.size() > target_suffix.size()) {
+        size_t pos = abs_location.size() - target_suffix.size();
+        if (abs_location.compare(pos, std::string::npos, target_suffix) == 0) {
+          return abs_location + multidex_suffix;
+        }
       }
     }
   }
diff --git a/runtime/oat_file_test.cc b/runtime/oat_file_test.cc
index b547113..ce09da4d 100644
--- a/runtime/oat_file_test.cc
+++ b/runtime/oat_file_test.cc
@@ -35,10 +35,6 @@
       OatFile::ResolveRelativeEncodedDexLocation(
         nullptr, "/data/app/foo/base.apk"));
 
-  EXPECT_EQ(std::string("/system/framework/base.apk"),
-      OatFile::ResolveRelativeEncodedDexLocation(
-        "/data/app/foo/base.apk", "/system/framework/base.apk"));
-
   EXPECT_EQ(std::string("/data/app/foo/base.apk"),
       OatFile::ResolveRelativeEncodedDexLocation(
         "/data/app/foo/base.apk", "base.apk"));
@@ -55,13 +51,29 @@
       OatFile::ResolveRelativeEncodedDexLocation(
         "/data/app/foo/base.apk", "base.apk!classes11.dex"));
 
-  EXPECT_EQ(std::string("base.apk"),
-      OatFile::ResolveRelativeEncodedDexLocation(
-        "/data/app/foo/sludge.apk", "base.apk"));
-
-  EXPECT_EQ(std::string("o/base.apk"),
-      OatFile::ResolveRelativeEncodedDexLocation(
-        "/data/app/foo/base.apk", "o/base.apk"));
+  // Host and target differ in their way of handling locations
+  // that are prefix of one another, due to boot image files.
+  if (kIsTargetBuild) {
+    EXPECT_EQ(std::string("/system/framework/base.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/base.apk", "/system/framework/base.apk"));
+    EXPECT_EQ(std::string("base.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/sludge.apk", "base.apk"));
+    EXPECT_EQ(std::string("o/base.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/base.apk", "o/base.apk"));
+  } else {
+    EXPECT_EQ(std::string("/data/app/foo/base.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/base.apk", "/system/framework/base.apk"));
+    EXPECT_EQ(std::string("/data/app/foo/sludge.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/sludge.apk", "base.apk"));
+    EXPECT_EQ(std::string("/data/app/foo/base.apk"),
+        OatFile::ResolveRelativeEncodedDexLocation(
+          "/data/app/foo/base.apk", "o/base.apk"));
+  }
 }
 
 TEST_F(OatFileTest, LoadOat) {
diff --git a/runtime/thread_android.cc b/runtime/thread_android.cc
index 24864f9..8ff6c52 100644
--- a/runtime/thread_android.cc
+++ b/runtime/thread_android.cc
@@ -21,7 +21,7 @@
 #include <sys/resource.h>
 #include <sys/time.h>
 
-#include <processgroup/sched_policy.h>
+#include <cutils/sched_policy.h>
 #include <utils/threads.h>
 
 #include "base/macros.h"
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index 97fbcbf..f426d02 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -974,11 +974,8 @@
           auto fn_shared = [&](const DexMember& boot_member) {
             auto it = api_list.find(boot_member.GetApiEntry());
             bool api_list_found = (it != api_list.end());
-            // TODO: Fix ART buildbots and turn this into a CHECK.
-            if (force_assign_all_ && !api_list_found) {
-              LOG(WARNING) << "Could not find hiddenapi flags for dex entry: "
-                           << boot_member.GetApiEntry();
-            }
+            CHECK(!force_assign_all_ || api_list_found)
+                << "Could not find hiddenapi flags for dex entry: " << boot_member.GetApiEntry();
             builder.WriteFlags(api_list_found ? it->second : ApiList::Whitelist());
           };
           auto fn_field = [&](const ClassAccessor::Field& boot_field) {
diff --git a/tools/veridex/hidden_api.h b/tools/veridex/hidden_api.h
index 3c7f29a..e1b67a2 100644
--- a/tools/veridex/hidden_api.h
+++ b/tools/veridex/hidden_api.h
@@ -41,7 +41,7 @@
   }
 
   bool IsInAnyList(const std::string& name) const {
-    return GetApiList(name).IsEmpty();
+    return !GetApiList(name).IsEmpty();
   }
 
   static std::string GetApiMethodName(const DexFile& dex_file, uint32_t method_index);
diff --git a/tools/veridex/hidden_api_finder.cc b/tools/veridex/hidden_api_finder.cc
index 3cd7c95..fe6d88a 100644
--- a/tools/veridex/hidden_api_finder.cc
+++ b/tools/veridex/hidden_api_finder.cc
@@ -180,6 +180,7 @@
   for (const std::pair<const std::string,
                        std::vector<MethodReference>>& pair : method_locations_) {
     hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first);
+    CHECK(api_list.IsValid());
     stats->api_counts[api_list.GetIntValue()]++;
     os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):";
     os << std::endl;
@@ -191,6 +192,7 @@
   for (const std::pair<const std::string,
                        std::vector<MethodReference>>& pair : field_locations_) {
     hiddenapi::ApiList api_list = hidden_api_.GetApiList(pair.first);
+    CHECK(api_list.IsValid());
     stats->api_counts[api_list.GetIntValue()]++;
     os << "#" << ++stats->count << ": Linking " << api_list << " " << pair.first << " use(s):";
     os << std::endl;