Remove unused MadviseState hints

The only MadviseState enum value that is used is MadviseStateAtLoad.
Remove the enum entirely in favor of explicit load semantics for the
OatDexFile::MadviseDexFile call.

Follow-up work will address some of the existing madvise behavior for
low-RAM devices, particularly as it relates to the more recently added
madvise knobs like dalvik.vm.madvise.vdexfile.size.

Bug: 196052575
Test: test-art-host
Change-Id: I88211efce9193dc4c45274957898ce7b94eb330c
diff --git a/libdexfile/dex/dex_file_layout.cc b/libdexfile/dex/dex_file_layout.cc
index 929025a..f15e925 100644
--- a/libdexfile/dex/dex_file_layout.cc
+++ b/libdexfile/dex/dex_file_layout.cc
@@ -56,40 +56,19 @@
                                   advice);
 }
 
-void DexLayoutSections::Madvise(const DexFile* dex_file, MadviseState state) const {
+void DexLayoutSections::MadviseAtLoad(const DexFile* dex_file) const {
 #ifdef _WIN32
   UNUSED(dex_file);
-  UNUSED(state);
   PLOG(WARNING) << "madvise is unsupported on Windows.";
 #else
   // The dex file is already defaulted to random access everywhere.
   for (const DexLayoutSection& section : sections_) {
-    switch (state) {
-      case MadviseState::kMadviseStateAtLoad: {
-        section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeStartupOnly)].Madvise(
-            dex_file,
-            MADV_WILLNEED);
-        section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeHot)].Madvise(
-            dex_file,
-            MADV_WILLNEED);
-        break;
-      }
-      case MadviseState::kMadviseStateFinishedLaunch: {
-        section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeStartupOnly)].Madvise(
-            dex_file,
-            MADV_DONTNEED);
-        break;
-      }
-      case MadviseState::kMadviseStateFinishedTrim: {
-        section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeSometimesUsed)].Madvise(
-            dex_file,
-            MADV_DONTNEED);
-        section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeUsedOnce)].Madvise(
-            dex_file,
-            MADV_DONTNEED);
-        break;
-      }
-    }
+    section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeStartupOnly)].Madvise(
+        dex_file,
+        MADV_WILLNEED);
+    section.parts_[static_cast<size_t>(LayoutType::kLayoutTypeHot)].Madvise(
+        dex_file,
+        MADV_WILLNEED);
   }
 #endif
 }
diff --git a/libdexfile/dex/dex_file_layout.h b/libdexfile/dex/dex_file_layout.h
index 8ee91ff..e1ae44d 100644
--- a/libdexfile/dex/dex_file_layout.h
+++ b/libdexfile/dex/dex_file_layout.h
@@ -52,16 +52,6 @@
   return std::min(a, b);
 }
 
-enum class MadviseState : uint8_t {
-  // Madvise based on a file that was just loaded.
-  kMadviseStateAtLoad,
-  // Madvise based after launch is finished.
-  kMadviseStateFinishedLaunch,
-  // Trim by madvising code that is unlikely to be too important in the future.
-  kMadviseStateFinishedTrim,
-};
-std::ostream& operator<<(std::ostream& os, MadviseState collector_type);
-
 // A dex layout section such as code items or strings. Each section is composed of subsections
 // that are laid out adjacently to each other such as (hot, unused, startup, etc...).
 class DexLayoutSection {
@@ -111,9 +101,9 @@
     kSectionCount,
   };
 
-  // Advise access about the dex file based on layout. The caller is expected to have already
+  // Advise load access about the dex file based on layout. The caller is expected to have already
   // madvised to MADV_RANDOM.
-  void Madvise(const DexFile* dex_file, MadviseState state) const;
+  void MadviseAtLoad(const DexFile* dex_file) const;
 
   DexLayoutSection sections_[static_cast<size_t>(SectionType::kSectionCount)];
 };
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 5e6ae1a..314aa29 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1280,7 +1280,7 @@
                            std::make_move_iterator(dex_files.end()));
   }
   for (const std::unique_ptr<const DexFile>& dex_file : boot_dex_files_) {
-    OatDexFile::MadviseDexFile(*dex_file, MadviseState::kMadviseStateAtLoad);
+    OatDexFile::MadviseDexFileAtLoad(*dex_file);
   }
   InitializeObjectVirtualMethodHashes(GetClassRoot<mirror::Object>(this),
                                       image_pointer_size_,
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 347b58f..aca44bd 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -2218,14 +2218,14 @@
 }
 
 // Madvise the dex file based on the state we are moving to.
-void OatDexFile::MadviseDexFile(const DexFile& dex_file, MadviseState state) {
+void OatDexFile::MadviseDexFileAtLoad(const DexFile& dex_file) {
   Runtime* const runtime = Runtime::Current();
   const bool low_ram = runtime->GetHeap()->IsLowMemoryMode();
-  // TODO: Also do madvise hints for non low ram devices.
+  // TODO(b/196052575): Revisit low-ram madvise behavior in light of vdex/odex/art madvise hints.
   if (!low_ram) {
     return;
   }
-  if (state == MadviseState::kMadviseStateAtLoad && runtime->MAdviseRandomAccess()) {
+  if (runtime->MAdviseRandomAccess()) {
     // Default every dex file to MADV_RANDOM when its loaded by default for low ram devices.
     // Other devices have enough page cache to get performance benefits from loading more pages
     // into the page cache.
@@ -2238,7 +2238,7 @@
     // Should always be there.
     const DexLayoutSections* const sections = oat_dex_file->GetDexLayoutSections();
     if (sections != nullptr) {
-      sections->Madvise(&dex_file, state);
+      sections->MadviseAtLoad(&dex_file);
     } else {
       DCHECK(oat_dex_file->IsBackedByVdexOnly());
     }
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 5c98176..c979c7e 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -551,8 +551,8 @@
                                            const char* descriptor,
                                            size_t hash);
 
-  // Madvise the dex file based on the state we are moving to.
-  static void MadviseDexFile(const DexFile& dex_file, MadviseState state);
+  // Madvise the dex file for load-time usage.
+  static void MadviseDexFileAtLoad(const DexFile& dex_file);
 
   const TypeLookupTable& GetTypeLookupTable() const {
     return lookup_table_;
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 542ea09..921c6d2 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -334,7 +334,7 @@
       } else {
         // Opened dex files from an oat file, madvise them to their loaded state.
          for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
-           OatDexFile::MadviseDexFile(*dex_file, MadviseState::kMadviseStateAtLoad);
+           OatDexFile::MadviseDexFileAtLoad(*dex_file);
          }
       }