diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-01 18:14:40 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-01 18:14:40 +0000 |
commit | 0f25b8d92e80a545fbe7ea422a4abc8b1dcfd54a (patch) | |
tree | bdc9cdedd58ab6abfc0560b23cc6877d8b31098b | |
parent | b6de3afcab136ae3a8b60e9a11a7c3e6e647c6ba (diff) | |
parent | dc41395969220505ed41db97e2ceaccac55d8af1 (diff) | |
download | art-0f25b8d92e80a545fbe7ea422a4abc8b1dcfd54a.tar.gz |
Snap for 9550112 from dc41395969220505ed41db97e2ceaccac55d8af1 to mainline-permission-releaseaml_per_331611010
Change-Id: Ibb653216300267681799c77f6da40cc575649701
-rw-r--r-- | dex2oat/dex2oat_cts_test.cc | 45 | ||||
-rw-r--r-- | libartbase/base/common_art_test.h | 4 | ||||
-rw-r--r-- | libartpalette/apex/palette_test.cc | 27 | ||||
-rw-r--r-- | runtime/dex2oat_environment_test.h | 74 | ||||
-rw-r--r-- | runtime/gc/collector/mark_compact.cc | 2 | ||||
-rw-r--r-- | runtime/gc/heap.cc | 11 | ||||
-rw-r--r-- | test/924-threads/src/art/Test924.java | 24 |
7 files changed, 140 insertions, 47 deletions
diff --git a/dex2oat/dex2oat_cts_test.cc b/dex2oat/dex2oat_cts_test.cc index 41c7015090..254126446d 100644 --- a/dex2oat/dex2oat_cts_test.cc +++ b/dex2oat/dex2oat_cts_test.cc @@ -14,11 +14,54 @@ * limitations under the License. */ +#include "base/file_utils.h" #include "dex2oat_environment_test.h" namespace art { -class Dex2oatCtsTest : public Dex2oatEnvironmentTest {}; +class Dex2oatCtsTest : public CommonArtTest, public Dex2oatScratchDirs { + public: + void SetUp() override { + CommonArtTest::SetUp(); + Dex2oatScratchDirs::SetUp(android_data_); + } + + void TearDown() override { + Dex2oatScratchDirs::TearDown(); + CommonArtTest::TearDown(); + } + + protected: + // Stripped down counterpart to Dex2oatEnvironmentTest::Dex2Oat that only adds + // enough arguments for our purposes. + int Dex2Oat(const std::vector<std::string>& dex2oat_args, + std::string* output, + std::string* error_msg) { + // This command line should work regardless of bitness, ISA, etc. + std::vector<std::string> argv = {std::string(kAndroidArtApexDefaultPath) + "/bin/dex2oat"}; + argv.insert(argv.end(), dex2oat_args.begin(), dex2oat_args.end()); + + // We must set --android-root. + const char* android_root = getenv("ANDROID_ROOT"); + CHECK(android_root != nullptr); + argv.push_back("--android-root=" + std::string(android_root)); + + // We need dex2oat to actually log things. + auto post_fork_fn = []() { return setenv("ANDROID_LOG_TAGS", "*:d", 1) == 0; }; + ForkAndExecResult res = ForkAndExec(argv, post_fork_fn, output); + if (res.stage != ForkAndExecResult::kFinished) { + *error_msg = strerror(errno); + ::testing::AssertionFailure() << "Failed to finish dex2oat invocation: " << *error_msg; + } + + if (!res.StandardSuccess()) { + // We cannot use ASSERT_TRUE since the method returns an int and not void. + ::testing::AssertionFailure() << "dex2oat fork/exec failed: " << *error_msg; + } + + return res.status_code; + } +}; // Run dex2oat with --enable-palette-compilation-hooks to force calls to // PaletteNotify{Start,End}Dex2oatCompilation. diff --git a/libartbase/base/common_art_test.h b/libartbase/base/common_art_test.h index 6124ed9e2a..bd06043907 100644 --- a/libartbase/base/common_art_test.h +++ b/libartbase/base/common_art_test.h @@ -139,6 +139,8 @@ class CommonArtTestImpl { static void TearDownAndroidDataDir(const std::string& android_data, bool fail_on_error); + static void ClearDirectory(const char* dirpath, bool recursive = true); + // Get the names of the libcore modules. virtual std::vector<std::string> GetLibCoreModuleNames() const; @@ -231,8 +233,6 @@ class CommonArtTestImpl { std::unique_ptr<const DexFile> LoadExpectSingleDexFile(const char* location); - void ClearDirectory(const char* dirpath, bool recursive = true); - // Open a file (allows reading of framework jars). std::vector<std::unique_ptr<const DexFile>> OpenDexFiles(const char* filename); diff --git a/libartpalette/apex/palette_test.cc b/libartpalette/apex/palette_test.cc index 853dc29f58..0bcc09329b 100644 --- a/libartpalette/apex/palette_test.cc +++ b/libartpalette/apex/palette_test.cc @@ -21,7 +21,6 @@ #include <sys/syscall.h> #include <unistd.h> -#include "common_runtime_test.h" #include "gtest/gtest.h" namespace { @@ -70,14 +69,32 @@ TEST_F(PaletteClientTest, Ashmem) { #endif } -class PaletteClientJniTest : public art::CommonRuntimeTest {}; - -TEST_F(PaletteClientJniTest, JniInvocation) { +TEST_F(PaletteClientTest, JniInvocation) { +#ifndef ART_TARGET_ANDROID + // On host we need to set up a boot classpath and pass it in here. Let's not + // bother since this test is only for native API coverage on target. + GTEST_SKIP() << "Will only spin up a VM on Android"; +#else bool enabled; EXPECT_EQ(PALETTE_STATUS_OK, PaletteShouldReportJniInvocations(&enabled)); - JNIEnv* env = art::Thread::Current()->GetJniEnv(); + JavaVMInitArgs vm_args; + JavaVMOption options[] = { + {.optionString = "-verbose:jni", .extraInfo = nullptr}, + }; + vm_args.version = JNI_VERSION_1_6; + vm_args.nOptions = std::size(options); + vm_args.options = options; + vm_args.ignoreUnrecognized = JNI_TRUE; + + JavaVM* jvm = nullptr; + JNIEnv* env = nullptr; + EXPECT_EQ(JNI_OK, JNI_CreateJavaVM(&jvm, &env, &vm_args)); ASSERT_NE(nullptr, env); + PaletteNotifyBeginJniInvocation(env); PaletteNotifyEndJniInvocation(env); + + EXPECT_EQ(JNI_OK, jvm->DestroyJavaVM()); +#endif } diff --git a/runtime/dex2oat_environment_test.h b/runtime/dex2oat_environment_test.h index 964b7f3fff..e867c4f915 100644 --- a/runtime/dex2oat_environment_test.h +++ b/runtime/dex2oat_environment_test.h @@ -41,21 +41,17 @@ namespace art { static constexpr bool kDebugArgs = false; -// Test class that provides some helpers to set a test up for compilation using dex2oat. -class Dex2oatEnvironmentTest : public CommonRuntimeTest { +class Dex2oatScratchDirs { public: - void SetUp() override { - CommonRuntimeTest::SetUp(); - const ArtDexFileLoader dex_file_loader; - + void SetUp(const std::string& android_data) { // Create a scratch directory to work from. // Get the realpath of the android data. The oat dir should always point to real location // when generating oat files in dalvik-cache. This avoids complicating the unit tests // when matching the expected paths. - UniqueCPtr<const char[]> android_data_real(realpath(android_data_.c_str(), nullptr)); + UniqueCPtr<const char[]> android_data_real(realpath(android_data.c_str(), nullptr)); ASSERT_TRUE(android_data_real != nullptr) - << "Could not get the realpath of the android data" << android_data_ << strerror(errno); + << "Could not get the realpath of the android data" << android_data << strerror(errno); scratch_dir_.assign(android_data_real.get()); scratch_dir_ += "/Dex2oatEnvironmentTest"; @@ -67,6 +63,41 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { odex_dir_ = odex_oat_dir_ + "/" + std::string(GetInstructionSetString(kRuntimeISA)); ASSERT_EQ(0, mkdir(odex_dir_.c_str(), 0700)); + } + + void TearDown() { + CommonArtTest::ClearDirectory(odex_dir_.c_str()); + ASSERT_EQ(0, rmdir(odex_dir_.c_str())); + + CommonArtTest::ClearDirectory(odex_oat_dir_.c_str()); + ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str())); + + CommonArtTest::ClearDirectory(scratch_dir_.c_str()); + ASSERT_EQ(0, rmdir(scratch_dir_.c_str())); + } + + // Scratch directory, for dex and odex files (oat files will go in the + // dalvik cache). + const std::string& GetScratchDir() const { return scratch_dir_; } + + // Odex directory is the subdirectory in the scratch directory where odex + // files should be located. + const std::string& GetOdexDir() const { return odex_dir_; } + + private: + std::string scratch_dir_; + std::string odex_oat_dir_; + std::string odex_dir_; +}; + +// Test class that provides some helpers to set a test up for compilation using dex2oat. +class Dex2oatEnvironmentTest : public Dex2oatScratchDirs, public CommonRuntimeTest { + public: + void SetUp() override { + CommonRuntimeTest::SetUp(); + Dex2oatScratchDirs::SetUp(android_data_); + + const ArtDexFileLoader dex_file_loader; // Verify the environment is as we expect std::vector<uint32_t> checksums; @@ -122,15 +153,7 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { } void TearDown() override { - ClearDirectory(odex_dir_.c_str()); - ASSERT_EQ(0, rmdir(odex_dir_.c_str())); - - ClearDirectory(odex_oat_dir_.c_str()); - ASSERT_EQ(0, rmdir(odex_oat_dir_.c_str())); - - ClearDirectory(scratch_dir_.c_str()); - ASSERT_EQ(0, rmdir(scratch_dir_.c_str())); - + Dex2oatScratchDirs::TearDown(); CommonRuntimeTest::TearDown(); } @@ -165,18 +188,6 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { return GetTestDexFileName("Nested"); } - // Scratch directory, for dex and odex files (oat files will go in the - // dalvik cache). - const std::string& GetScratchDir() const { - return scratch_dir_; - } - - // Odex directory is the subdirectory in the scratch directory where odex - // files should be located. - const std::string& GetOdexDir() const { - return odex_dir_; - } - int Dex2Oat(const std::vector<std::string>& dex2oat_args, std::string* output, std::string* error_msg) { @@ -232,11 +243,6 @@ class Dex2oatEnvironmentTest : public CommonRuntimeTest { return res.status_code; } - - private: - std::string scratch_dir_; - std::string odex_oat_dir_; - std::string odex_dir_; }; } // namespace art diff --git a/runtime/gc/collector/mark_compact.cc b/runtime/gc/collector/mark_compact.cc index 38cbcb72e8..015027d62f 100644 --- a/runtime/gc/collector/mark_compact.cc +++ b/runtime/gc/collector/mark_compact.cc @@ -250,7 +250,7 @@ MarkCompact::MarkCompact(Heap* heap) compaction_in_progress_count_(0), compacting_(false), uffd_initialized_(false), - uffd_minor_fault_supported_(GetUffdAndMinorFault().second), + uffd_minor_fault_supported_(false), minor_fault_initialized_(false), map_linear_alloc_shared_(false) { // TODO: Depending on how the bump-pointer space move is implemented. If we diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 2cb1bf1680..df4b779e5d 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -417,7 +417,18 @@ Heap::Heap(size_t initial_size, if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { LOG(INFO) << "Heap() entering"; } + LOG(INFO) << "Using " << foreground_collector_type_ << " GC."; + if (!gUseUserfaultfd) { + // This ensures that userfaultfd syscall is done before any seccomp filter is installed. + // TODO(b/266731037): Remove this when we no longer need to collect metric on userfaultfd + // support. + auto [uffd_supported, minor_fault_supported] = collector::MarkCompact::GetUffdAndMinorFault(); + // The check is just to ensure that compiler doesn't eliminate the function call above. + // Userfaultfd support is certain to be there if its minor-fault feature is supported. + CHECK_IMPLIES(minor_fault_supported, uffd_supported); + } + if (gUseReadBarrier) { CHECK_EQ(foreground_collector_type_, kCollectorTypeCC); CHECK_EQ(background_collector_type_, kCollectorTypeCCBackground); diff --git a/test/924-threads/src/art/Test924.java b/test/924-threads/src/art/Test924.java index e97c9c6b35..355572044f 100644 --- a/test/924-threads/src/art/Test924.java +++ b/test/924-threads/src/art/Test924.java @@ -337,6 +337,19 @@ public class Test924 { } } + private static List<String> filterForThread(Object[] thread_messages, String thread_name) { + List<String> messageListForThread = new ArrayList<String>(); + + for (int i = 0; i < thread_messages.length; i++) { + String message = (String)thread_messages[i]; + if (message.startsWith("Thread(" + thread_name + ")")) { + messageListForThread.add(message); + } + } + + return messageListForThread; + } + private static void doTestEvents() throws Exception { enableThreadEvents(true); @@ -354,21 +367,24 @@ public class Test924 { } } }; - Thread t = new Thread(r, "EventTestThread"); + String thread_name = "EventTestThread"; + Thread t = new Thread(r, thread_name); System.out.println("Constructed thread"); Thread.yield(); Thread.sleep(100); - System.out.println(Arrays.toString(getThreadEventMessages())); + + // Check that there are no events related to EventTestThread that we just created. + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); t.start(); cdl1.await(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); cdl2.countDown(); t.join(); - System.out.println(Arrays.toString(getThreadEventMessages())); + System.out.println(filterForThread(getThreadEventMessages(), thread_name).toString()); System.out.println("Thread joined"); |