Revert "Expand sharpening's ComputeLoadClassKind to cover cross-dex cases"

This reverts commit 32b8c8f33ad68982357c1fa3d0f132d06b070ab5.

Bug: 154012332
Bug: 214850438

Reason for revert: b/214850438

Change-Id: I479c0910ce5da593e170bc5e4f6fa10dfe5d67b2
diff --git a/compiler/driver/compiler_options.h b/compiler/driver/compiler_options.h
index 326e833..a31be3f 100644
--- a/compiler/driver/compiler_options.h
+++ b/compiler/driver/compiler_options.h
@@ -26,7 +26,6 @@
 #include "base/globals.h"
 #include "base/hash_set.h"
 #include "base/macros.h"
-#include "base/stl_util.h"
 #include "base/utils.h"
 #include "optimizing/register_allocator.h"
 
@@ -375,7 +374,8 @@
   }
 
   bool WithinOatFile(const DexFile* dex_file) const {
-    return ContainsElement(GetDexFilesForOatFile(), dex_file);
+    return std::find(GetDexFilesForOatFile().begin(), GetDexFilesForOatFile().end(), dex_file) !=
+           GetDexFilesForOatFile().end();
   }
 
  private:
diff --git a/compiler/optimizing/sharpening.cc b/compiler/optimizing/sharpening.cc
index cb9edc0..1fd76f7 100644
--- a/compiler/optimizing/sharpening.cc
+++ b/compiler/optimizing/sharpening.cc
@@ -275,18 +275,15 @@
   }
   HLoadClass::LoadKind load_kind = codegen->GetSupportedLoadClassKind(desired_load_kind);
 
-  // If we cannot reference this class due to .bss requirements, we're forced to bail.
   if (!IsSameDexFile(load_class->GetDexFile(), *dex_compilation_unit.GetDexFile())) {
-    if (load_kind == HLoadClass::LoadKind::kRuntimeCall) {
-      return HLoadClass::LoadKind::kInvalid;
-    }
-
-    if (load_kind == HLoadClass::LoadKind::kBssEntry ||
+    if (load_kind == HLoadClass::LoadKind::kRuntimeCall ||
+        load_kind == HLoadClass::LoadKind::kBssEntry ||
         load_kind == HLoadClass::LoadKind::kBssEntryPublic ||
         load_kind == HLoadClass::LoadKind::kBssEntryPackage) {
-      if (!codegen->GetCompilerOptions().WithinOatFile(&load_class->GetDexFile())) {
-        return HLoadClass::LoadKind::kInvalid;
-      }
+      // We actually cannot reference this class, we're forced to bail.
+      // We cannot reference this class with Bss, as the entrypoint will lookup the class
+      // in the caller's dex file, but that dex file does not reference the class.
+      return HLoadClass::LoadKind::kInvalid;
     }
   }
   return load_kind;
diff --git a/dex2oat/linker/oat_writer.cc b/dex2oat/linker/oat_writer.cc
index a8b0e1a..eccc3d5 100644
--- a/dex2oat/linker/oat_writer.cc
+++ b/dex2oat/linker/oat_writer.cc
@@ -946,7 +946,8 @@
                        /*inout*/ SafeMap<const DexFile*, BitVector>* references) {
     // We currently support inlining of throwing instructions only when they originate in the
     // same oat file as the outer method. All .bss references are used by throwing instructions.
-    DCHECK(ContainsElement(*writer_->dex_files_, ref.dex_file));
+    DCHECK(std::find(writer_->dex_files_->begin(), writer_->dex_files_->end(), ref.dex_file) !=
+           writer_->dex_files_->end());
     DCHECK_LT(ref.index, number_of_indexes);
 
     auto refs_it = references->find(ref.dex_file);
diff --git a/test/2238-checker-load-class-multidex/expected-stderr.txt b/test/2238-checker-load-class-multidex/expected-stderr.txt
deleted file mode 100644
index e69de29..0000000
--- a/test/2238-checker-load-class-multidex/expected-stderr.txt
+++ /dev/null
diff --git a/test/2238-checker-load-class-multidex/expected-stdout.txt b/test/2238-checker-load-class-multidex/expected-stdout.txt
deleted file mode 100644
index e69de29..0000000
--- a/test/2238-checker-load-class-multidex/expected-stdout.txt
+++ /dev/null
diff --git a/test/2238-checker-load-class-multidex/info.txt b/test/2238-checker-load-class-multidex/info.txt
deleted file mode 100644
index c4ef65e..0000000
--- a/test/2238-checker-load-class-multidex/info.txt
+++ /dev/null
@@ -1 +0,0 @@
-Check that the Invoke's load class uses the .bss entries.
diff --git a/test/2238-checker-load-class-multidex/src-multidex/Caller.java b/test/2238-checker-load-class-multidex/src-multidex/Caller.java
deleted file mode 100644
index 223230a..0000000
--- a/test/2238-checker-load-class-multidex/src-multidex/Caller.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2021 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.
- */
-
-public class Caller {
-  /// CHECK-START: void Caller.doCall() builder (after)
-  /// CHECK:       LoadClass load_kind:BssEntry class_name:pkg1.SuperClass
-  /// CHECK:       InvokeStaticOrDirect method_name:pkg1.SuperClass.$noinline$callMethod
-  public static void doCall() {
-    pkg1.SubClass.$noinline$callMethod();
-  }
-}
\ No newline at end of file
diff --git a/test/2238-checker-load-class-multidex/src/Main.java b/test/2238-checker-load-class-multidex/src/Main.java
deleted file mode 100644
index a2f595d..0000000
--- a/test/2238-checker-load-class-multidex/src/Main.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2021 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.
- */
-
-final class Main {
-  public static void main(String[] args) {
-    pkg1.SubClass.$noinline$callMethod();
-    Caller.doCall();
-  }
-}
diff --git a/test/2238-checker-load-class-multidex/src/pkg1/SubClass.java b/test/2238-checker-load-class-multidex/src/pkg1/SubClass.java
deleted file mode 100644
index 0e01c3c..0000000
--- a/test/2238-checker-load-class-multidex/src/pkg1/SubClass.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2021 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.
- */
-
-package pkg1;
-
-// `SuperClass` is only visible to classes in packge `pkg1`.
-class SuperClass {
-  public static void $noinline$callMethod() {
-  }
-}
-
-// Any class (inside or outside `pkg1`) can access `SuperClass.callMethod` by referencing it as
-// `SubClass.callMethod`.
-public class SubClass extends SuperClass {
-}