diff options
author | 2021-10-11 05:04:34 +0000 | |
---|---|---|
committer | 2021-10-15 13:03:49 +0000 | |
commit | ebf496f245dec69af6abfa115aa0e5872aee93d1 (patch) | |
tree | 4d90ed1ea13dc04c364e1f75de45098cc1b2333b | |
parent | 0d0d91a2acd58696366021982279bacc6638b123 (diff) |
Deprecate --updatable-bcp-packages-fd and --updatable-bcp-packages-file
These flags are no longer needed and therefore deprecated. They are
still kept for compatibility, but they do not take any effect now.
Bug: 200241946
Test: Presubmits
Change-Id: I17b937e382cd3fe6eb20f2a686a638492c93d58e
-rw-r--r-- | build/Android.gtest.mk | 2 | ||||
-rw-r--r-- | dex2oat/dex2oat.cc | 85 | ||||
-rw-r--r-- | dex2oat/dex2oat_options.cc | 12 | ||||
-rw-r--r-- | runtime/Android.bp | 1 | ||||
-rw-r--r-- | runtime/aot_class_linker.cc | 43 | ||||
-rw-r--r-- | runtime/aot_class_linker.h | 6 | ||||
-rw-r--r-- | runtime/class_linker.cc | 18 | ||||
-rw-r--r-- | runtime/class_linker.h | 2 | ||||
-rw-r--r-- | runtime/module_exclusion_test.cc | 193 |
9 files changed, 11 insertions, 351 deletions
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk index 0bc93c2254..c23911fa88 100644 --- a/build/Android.gtest.mk +++ b/build/Android.gtest.mk @@ -483,8 +483,6 @@ ART_GTEST_dex2oat_test_TARGET_DEPS := ART_GTEST_dex2oat_image_test_DEX_DEPS := ART_GTEST_dex2oat_image_test_HOST_DEPS := ART_GTEST_dex2oat_image_test_TARGET_DEPS := -ART_GTEST_module_exclusion_test_HOST_DEPS := -ART_GTEST_module_exclusion_test_TARGET_DEPS := ART_GTEST_object_test_DEX_DEPS := ART_GTEST_proxy_test_DEX_DEPS := ART_GTEST_reflection_test_DEX_DEPS := diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 6f013297c8..bb6dd8554d 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -529,8 +529,6 @@ class Dex2Oat final { passes_to_run_filename_(nullptr), dirty_image_objects_filename_(nullptr), dirty_image_objects_fd_(-1), - updatable_bcp_packages_filename_(nullptr), - updatable_bcp_packages_fd_(-1), is_host_(false), elf_writers_(), oat_writers_(), @@ -826,15 +824,6 @@ class Dex2Oat final { Usage("--dirty-image-objects and --dirty-image-objects-fd should not be both specified"); } - if ((IsBootImage() || IsBootImageExtension()) && (updatable_bcp_packages_filename_ != nullptr || - updatable_bcp_packages_fd_ != -1)) { - Usage("Do not specify --updatable-bcp-packages-file[-fd] for boot image compilation."); - } - if (updatable_bcp_packages_filename_ != nullptr && updatable_bcp_packages_fd_ != -1) { - Usage("--updatable-bcp-packages-file and --updatable-bcp-packages-fd should not be " - "both specified"); - } - if (!cpu_set_.empty()) { SetCpuAffinity(cpu_set_); } @@ -1092,8 +1081,6 @@ class Dex2Oat final { AssignIfExists(args, M::ClasspathDir, &classpath_dir_); AssignIfExists(args, M::DirtyImageObjects, &dirty_image_objects_filename_); AssignIfExists(args, M::DirtyImageObjectsFd, &dirty_image_objects_fd_); - AssignIfExists(args, M::UpdatableBcpPackagesFile, &updatable_bcp_packages_filename_); - AssignIfExists(args, M::UpdatableBcpPackagesFd, &updatable_bcp_packages_fd_); AssignIfExists(args, M::ImageFormat, &image_storage_mode_); AssignIfExists(args, M::CompilationReason, &compilation_reason_); AssignTrueIfExists(args, M::CheckLinkageConditions, &check_linkage_conditions_); @@ -1181,6 +1168,15 @@ class Dex2Oat final { "--class-loader-context is also specified"); } + if (args.Exists(M::UpdatableBcpPackagesFile)) { + LOG(WARNING) + << "Option --updatable-bcp-packages-file is deprecated and no longer takes effect"; + } + + if (args.Exists(M::UpdatableBcpPackagesFd)) { + LOG(WARNING) << "Option --updatable-bcp-packages-fd is deprecated and no longer takes effect"; + } + // If we have a profile, change the default compiler filter to speed-profile // before reading compiler options. static_assert(CompilerFilter::kDefaultCompilerFilter == CompilerFilter::kSpeed); @@ -1671,11 +1667,6 @@ class Dex2Oat final { class_loader_context_->EncodeContextForOatFile(classpath_dir_, stored_class_loader_context_.get()); key_value_store_->Put(OatHeader::kClassPathKey, class_path_key); - - // Prepare exclusion list for updatable boot class path packages. - if (!PrepareUpdatableBcpPackages()) { - return dex2oat::ReturnCode::kOther; - } } // Now that we have finalized key_value_store_, start writing the .rodata section. @@ -2540,62 +2531,6 @@ class Dex2Oat final { return true; } - bool PrepareUpdatableBcpPackages() { - DCHECK(!IsBootImage() && !IsBootImageExtension()); - AotClassLinker* aot_class_linker = down_cast<AotClassLinker*>(runtime_->GetClassLinker()); - std::unique_ptr<std::vector<std::string>> updatable_bcp_packages; - if (updatable_bcp_packages_fd_ != -1) { - updatable_bcp_packages = ReadCommentedInputFromFd<std::vector<std::string>>( - updatable_bcp_packages_fd_, - nullptr); // No post-processing. - // Close since we won't need it again. - close(updatable_bcp_packages_fd_); - updatable_bcp_packages_fd_ = -1; - if (updatable_bcp_packages == nullptr) { - LOG(ERROR) << "Failed to load updatable boot class path packages from fd " - << updatable_bcp_packages_fd_; - return false; - } - } else if (updatable_bcp_packages_filename_ != nullptr) { - updatable_bcp_packages = ReadCommentedInputFromFile<std::vector<std::string>>( - updatable_bcp_packages_filename_, - nullptr); // No post-processing. - if (updatable_bcp_packages == nullptr) { - LOG(ERROR) << "Failed to load updatable boot class path packages from '" - << updatable_bcp_packages_filename_ << "'"; - return false; - } - } else { - // Use the default list based on updatable packages for Android 11. - return aot_class_linker->SetUpdatableBootClassPackages({ - // Reserved conscrypt packages (includes sub-packages under these paths). - // "android.net.ssl", // Covered by android.net below. - "com.android.org.conscrypt", - // Reserved updatable-media package (includes sub-packages under this path). - "android.media", - // Reserved framework-mediaprovider package (includes sub-packages under this path). - "android.provider", - // Reserved framework-statsd packages (includes sub-packages under these paths). - "android.app", - "android.os", - "android.util", - "com.android.internal.statsd", - // Reserved framework-permission packages (includes sub-packages under this path). - "android.permission", - // "android.app.role", // Covered by android.app above. - // Reserved framework-sdkextensions package (includes sub-packages under this path). - // "android.os.ext", // Covered by android.os above. - // Reserved framework-wifi packages (includes sub-packages under these paths). - "android.hardware.wifi", - // "android.net.wifi", // Covered by android.net below. - "com.android.wifi.x", - // Reserved framework-tethering package (includes sub-packages under this path). - "android.net", - }); - } - return aot_class_linker->SetUpdatableBootClassPackages(*updatable_bcp_packages); - } - void PruneNonExistentDexFiles() { DCHECK_EQ(dex_filenames_.size(), dex_locations_.size()); size_t kept = 0u; @@ -2961,8 +2896,6 @@ class Dex2Oat final { const char* dirty_image_objects_filename_; int dirty_image_objects_fd_; std::unique_ptr<HashSet<std::string>> dirty_image_objects_; - const char* updatable_bcp_packages_filename_; - int updatable_bcp_packages_fd_; std::unique_ptr<std::vector<std::string>> passes_to_run_; bool is_host_; std::string android_root_; diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc index f42f3984dd..988b288ec6 100644 --- a/dex2oat/dex2oat_options.cc +++ b/dex2oat/dex2oat_options.cc @@ -200,19 +200,11 @@ static void AddImageMappings(Builder& builder) { .IntoKey(M::DirtyImageObjectsFd) .Define("--updatable-bcp-packages-file=_") .WithType<std::string>() - .WithHelp("file with a list of updatable boot class path packages. Classes in these\n" - "packages and sub-packages shall not be resolved during app compilation to\n" - "avoid AOT assumptions being invalidated after applying updates to these\n" - "components." - ) + .WithHelp("Deprecated. No longer takes effect.") .IntoKey(M::UpdatableBcpPackagesFile) .Define("--updatable-bcp-packages-fd=_") .WithType<int>() - .WithHelp("File descriptor to read a list of updatable boot class path packages.\n" - "Classes in these packages and sub-packages shall not be resolved during app\n" - "compilation to avoid AOT assumptions being invalidated after applying\n" - "updates to these components." - ) + .WithHelp("Deprecated. No longer takes effect.") .IntoKey(M::UpdatableBcpPackagesFd) .Define("--image-format=_") .WithType<ImageHeader::StorageMode>() diff --git a/runtime/Android.bp b/runtime/Android.bp index 244f255fff..7be5007887 100644 --- a/runtime/Android.bp +++ b/runtime/Android.bp @@ -821,7 +821,6 @@ art_cc_defaults { name: "art_runtime_compiler_tests_defaults", srcs: [ "reflection_test.cc", - "module_exclusion_test.cc", ], data: [ ":art-gtest-jars-Main", diff --git a/runtime/aot_class_linker.cc b/runtime/aot_class_linker.cc index 5d8b61df7c..9b2e8767ef 100644 --- a/runtime/aot_class_linker.cc +++ b/runtime/aot_class_linker.cc @@ -201,49 +201,6 @@ bool AotClassLinker::CanReferenceInBootImageExtension(ObjPtr<mirror::Class> klas return true; } -bool AotClassLinker::SetUpdatableBootClassPackages(const std::vector<std::string>& packages) { - DCHECK(updatable_boot_class_path_descriptor_prefixes_.empty()); - // Transform package names to descriptor prefixes. - std::vector<std::string> prefixes; - prefixes.reserve(packages.size()); - for (const std::string& package : packages) { - if (package.empty() || package.find('/') != std::string::npos) { - LOG(ERROR) << "Invalid package name: " << package; - return false; - } - std::string prefix = 'L' + package + '/'; - std::replace(prefix.begin(), prefix.end(), '.', '/'); - prefixes.push_back(std::move(prefix)); - } - // Sort and remove unnecessary prefixes. - std::sort(prefixes.begin(), prefixes.end()); - std::string last_prefix; - auto end_it = std::remove_if( - prefixes.begin(), - prefixes.end(), - [&last_prefix](const std::string& s) { - if (!last_prefix.empty() && StartsWith(s, last_prefix)) { - return true; - } else { - last_prefix = s; - return false; - } - }); - prefixes.resize(std::distance(prefixes.begin(), end_it)); - prefixes.shrink_to_fit(); - updatable_boot_class_path_descriptor_prefixes_.swap(prefixes); - return true; -} - -bool AotClassLinker::IsUpdatableBootClassPathDescriptor(const char* descriptor) { - std::string_view descriptor_sv(descriptor); - for (const std::string& prefix : updatable_boot_class_path_descriptor_prefixes_) { - if (StartsWith(descriptor_sv, prefix)) { - return true; - } - } - return false; -} void AotClassLinker::SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker) { sdk_checker_ = std::move(sdk_checker); } diff --git a/runtime/aot_class_linker.h b/runtime/aot_class_linker.h index 9be8869faa..30a19c87d3 100644 --- a/runtime/aot_class_linker.h +++ b/runtime/aot_class_linker.h @@ -36,8 +36,6 @@ class AotClassLinker : public ClassLinker { static bool CanReferenceInBootImageExtension(ObjPtr<mirror::Class> klass, gc::Heap* heap) REQUIRES_SHARED(Locks::mutator_lock_); - bool SetUpdatableBootClassPackages(const std::vector<std::string>& packages); - void SetSdkChecker(std::unique_ptr<SdkChecker>&& sdk_checker_); const SdkChecker* GetSdkChecker() const; @@ -74,11 +72,7 @@ static bool CanReferenceInBootImageExtension(ObjPtr<mirror::Class> klass, gc::He REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); - bool IsUpdatableBootClassPathDescriptor(const char* descriptor) override; - private: - std::vector<std::string> updatable_boot_class_path_descriptor_prefixes_; - std::unique_ptr<SdkChecker> sdk_checker_; }; diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index df5038721c..454a20fa11 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -3054,18 +3054,6 @@ ObjPtr<mirror::Class> ClassLinker::DefineClass(Thread* self, } } - // For AOT-compilation of an app, we may use a shortened boot class path that excludes - // some runtime modules. Prevent definition of classes in app class loader that could clash - // with these modules as these classes could be resolved differently during execution. - if (class_loader != nullptr && - Runtime::Current()->IsAotCompiler() && - IsUpdatableBootClassPathDescriptor(descriptor)) { - ObjPtr<mirror::Throwable> pre_allocated = - Runtime::Current()->GetPreAllocatedNoClassDefFoundError(); - self->SetException(pre_allocated); - return sdc.Finish(nullptr); - } - // For AOT-compilation of an app, we may use only a public SDK to resolve symbols. If the SDK // checks are configured (a non null SdkChecker) and the descriptor is not in the provided // public class path then we prevent the definition of the class. @@ -10117,12 +10105,6 @@ ObjPtr<mirror::IfTable> ClassLinker::AllocIfTable(Thread* self, size_t ifcount) ifcount * mirror::IfTable::kMax))); } -bool ClassLinker::IsUpdatableBootClassPathDescriptor(const char* descriptor ATTRIBUTE_UNUSED) { - // Should not be called on ClassLinker, only on AotClassLinker that overrides this. - LOG(FATAL) << "UNREACHABLE"; - UNREACHABLE(); -} - bool ClassLinker::DenyAccessBasedOnPublicSdk(ArtMethod* art_method ATTRIBUTE_UNUSED) const REQUIRES_SHARED(Locks::mutator_lock_) { // Should not be called on ClassLinker, only on AotClassLinker that overrides this. diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 09f19fa236..8f334051ca 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -863,8 +863,6 @@ class ClassLinker { return true; } - virtual bool IsUpdatableBootClassPathDescriptor(const char* descriptor); - private: class LinkFieldsHelper; class LinkInterfaceMethodsHelper; diff --git a/runtime/module_exclusion_test.cc b/runtime/module_exclusion_test.cc deleted file mode 100644 index b62fc01522..0000000000 --- a/runtime/module_exclusion_test.cc +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "common_compiler_test.h" - -#include "aot_class_linker.h" -#include "base/casts.h" -#include "class_linker-inl.h" -#include "handle.h" -#include "handle_scope-inl.h" -#include "mirror/class_loader-inl.h" -#include "mirror/dex_cache.h" -#include "mirror/object-inl.h" -#include "runtime.h" -#include "scoped_thread_state_change-inl.h" -#include "thread-current-inl.h" -#include "well_known_classes.h" - -namespace art { - -class ModuleExclusionTest : public CommonCompilerTest { - public: - explicit ModuleExclusionTest(const std::string& module) - : CommonCompilerTest(), - module_(module) {} - - std::vector<std::string> GetLibCoreModuleNames() const override { - std::vector<std::string> modules = CommonCompilerTest::GetLibCoreModuleNames(); - // Exclude `module_` from boot class path. - auto it = std::find(modules.begin(), modules.end(), module_); - if (it != modules.end()) { - modules.erase(it); - } - return modules; - } - - void DoTest() { - Thread* self = Thread::Current(); - ScopedObjectAccess soa(self); - StackHandleScope<2u> hs(self); - Runtime* runtime = Runtime::Current(); - ASSERT_TRUE(runtime->IsAotCompiler()); - ClassLinker* class_linker = runtime->GetClassLinker(); - CHECK(loaded_dex_files_.empty()); - Handle<mirror::ClassLoader> class_loader = hs.NewHandle(LoadModule(soa, class_linker)); - MutableHandle<mirror::DexCache> dex_cache = hs.NewHandle<mirror::DexCache>(nullptr); - CHECK(!loaded_dex_files_.empty()); - - // Verify that classes defined in the loaded dex files cannot be resolved. - for (const std::unique_ptr<const DexFile>& dex_file : loaded_dex_files_) { - dex_cache.Assign(class_linker->RegisterDexFile(*dex_file, class_loader.Get())); - for (size_t i = 0u, size = dex_file->NumClassDefs(); i != size; ++i) { - const dex::ClassDef& class_def = dex_file->GetClassDef(i); - ObjPtr<mirror::Class> resolved_type = - class_linker->ResolveType(class_def.class_idx_, dex_cache, class_loader); - ASSERT_TRUE(resolved_type == nullptr) << resolved_type->PrettyDescriptor(); - ASSERT_TRUE(self->IsExceptionPending()); - self->ClearException(); - } - } - } - - protected: - void SetUpRuntimeOptions(RuntimeOptions* options) override { - CommonCompilerTest::SetUpRuntimeOptions(options); - - // Set up the image location to be used by StartDex2OatCommandLine(). - // Using a prebuilt image also makes the test run faster. - options->push_back(std::make_pair("-Ximage:" + GetImageLocation(), nullptr)); - } - - std::string GetModuleFileName() const { - std::vector<std::string> filename = GetLibCoreDexFileNames({ module_ }); - CHECK_EQ(filename.size(), 1u); - return filename[0]; - } - - // Load the module as an app, i.e. in a class loader other than the boot class loader. - ObjPtr<mirror::ClassLoader> LoadModule(ScopedObjectAccess& soa, ClassLinker* class_linker) - REQUIRES_SHARED(Locks::mutator_lock_) { - std::string filename = GetModuleFileName(); - std::vector<std::unique_ptr<const DexFile>> dex_files = OpenDexFiles(filename.c_str()); - - std::vector<const DexFile*> class_path; - CHECK_NE(0U, dex_files.size()); - for (auto& dex_file : dex_files) { - class_path.push_back(dex_file.get()); - loaded_dex_files_.push_back(std::move(dex_file)); - } - - StackHandleScope<1u> hs(soa.Self()); - Handle<mirror::Class> loader_class(hs.NewHandle( - soa.Decode<mirror::Class>(WellKnownClasses::dalvik_system_PathClassLoader))); - ScopedNullHandle<mirror::ClassLoader> parent_loader; - ScopedNullHandle<mirror::ObjectArray<mirror::ClassLoader>> shared_libraries; - - ObjPtr<mirror::ClassLoader> result = class_linker->CreateWellKnownClassLoader( - soa.Self(), - class_path, - loader_class, - parent_loader, - shared_libraries); - - // Verify that the result has the correct class. - CHECK_EQ(loader_class.Get(), result->GetClass()); - // Verify that the parent is not null. The boot class loader will be set up as a - // proper BootClassLoader object. - ObjPtr<mirror::ClassLoader> actual_parent(result->GetParent()); - CHECK(actual_parent != nullptr); - CHECK(class_linker->IsBootClassLoader(soa, actual_parent)); - - return result; - } - - const std::string module_; -}; - -class ConscryptExclusionTest : public ModuleExclusionTest { - public: - ConscryptExclusionTest() : ModuleExclusionTest("conscrypt") {} -}; - -TEST_F(ConscryptExclusionTest, Test) { - Runtime* runtime = Runtime::Current(); - ASSERT_TRUE(runtime->IsAotCompiler()); - AotClassLinker* aot_class_linker = down_cast<AotClassLinker*>(runtime->GetClassLinker()); - const std::vector<std::string> package_list = { - // Reserved conscrypt packages (includes sub-packages under these paths). - "android.net.ssl", - "com.android.org.conscrypt", - }; - bool list_applied = aot_class_linker->SetUpdatableBootClassPackages(package_list); - ASSERT_TRUE(list_applied); - DoTest(); - - // Also test passing the list to dex2oat. - ScratchFile package_list_file; - for (const std::string& package : package_list) { - std::string data = package + '\n'; - ASSERT_TRUE(package_list_file.GetFile()->WriteFully(data.data(), data.size())); - } - ASSERT_EQ(0, package_list_file.GetFile()->Flush()); - ScratchDir scratch_dir; - std::string jar_name = GetModuleFileName(); - std::string odex_name = scratch_dir.GetPath() + module_ + ".odex"; - std::vector<std::string> argv; - std::string error_msg; - bool success = StartDex2OatCommandLine(&argv, &error_msg); - ASSERT_TRUE(success) << error_msg; - argv.insert(argv.end(), { - "--dex-file=" + jar_name, - "--dex-location=" + jar_name, - "--oat-file=" + odex_name, - "--compiler-filter=speed", - "--updatable-bcp-packages-file=" + package_list_file.GetFilename() - }); - success = RunDex2Oat(argv, &error_msg); - ASSERT_TRUE(success) << error_msg; - // Load the odex file. - std::unique_ptr<OatFile> odex_file(OatFile::Open(/*zip_fd=*/ -1, - odex_name.c_str(), - odex_name.c_str(), - /*executable=*/ false, - /*low_4gb=*/ false, - jar_name, - &error_msg)); - ASSERT_TRUE(odex_file != nullptr) << error_msg; - // Check that no classes have been initialized. - for (const OatDexFile* oat_dex_file : odex_file->GetOatDexFiles()) { - std::unique_ptr<const DexFile> dex_file = oat_dex_file->OpenDexFile(&error_msg); - ASSERT_TRUE(dex_file != nullptr); - for (size_t i = 0, num_class_defs = dex_file->NumClassDefs(); i != num_class_defs; ++i) { - ClassStatus status = oat_dex_file->GetOatClass(i).GetStatus(); - ASSERT_FALSE(mirror::Class::IsErroneous(status)); - ASSERT_LE(status, ClassStatus::kVerified); - } - } -} - -} // namespace art |