Move ReflectionTest.StaticMainMethod to compiler/.

And clean up some related code.

Test: m test-art-host-gtest
Test: atest art_standalone_runtime_tests
Test: atest art_standalone_compiler_tests
Test: atest ArtGtestsTargetChroot
Change-Id: I6b60e553dad7111f6247fbd873cd46af11f00276
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 0aa6295..708e263 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -1301,9 +1301,6 @@
       "name": "art_standalone_profman_tests[com.google.android.art.apex]"
     },
     {
-      "name": "art_standalone_runtime_compiler_tests[com.google.android.art.apex]"
-    },
-    {
       "name": "art_standalone_runtime_tests[com.google.android.art.apex]"
     },
     {
@@ -2635,9 +2632,6 @@
       "name": "art_standalone_profman_tests"
     },
     {
-      "name": "art_standalone_runtime_compiler_tests"
-    },
-    {
       "name": "art_standalone_runtime_tests"
     },
     {
@@ -3957,9 +3951,6 @@
       "name": "art_standalone_profman_tests"
     },
     {
-      "name": "art_standalone_runtime_compiler_tests"
-    },
-    {
       "name": "art_standalone_runtime_tests"
     },
     {
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index 0c897b4..fe5449e 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -128,7 +128,6 @@
     art_libprofile_tests \
     art_oatdump_tests \
     art_profman_tests \
-    art_runtime_compiler_tests \
     art_runtime_tests \
     art_sigchain_tests \
 
diff --git a/build/apex/Android.bp b/build/apex/Android.bp
index 80acd81..6728821 100644
--- a/build/apex/Android.bp
+++ b/build/apex/Android.bp
@@ -420,7 +420,6 @@
     "art_oatdump_tests",
     "art_odrefresh_tests",
     "art_profman_tests",
-    "art_runtime_compiler_tests",
     "art_runtime_tests",
     "art_sigchain_tests",
 ]
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 0ee79bf..3f98903 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -692,7 +692,6 @@
     self._checker.check_art_test_executable('art_oatdump_tests')
     self._checker.check_art_test_executable('art_odrefresh_tests')
     self._checker.check_art_test_executable('art_profman_tests')
-    self._checker.check_art_test_executable('art_runtime_compiler_tests')
     self._checker.check_art_test_executable('art_runtime_tests')
     self._checker.check_art_test_executable('art_sigchain_tests')
 
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 50af288..830a9f0 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -370,6 +370,7 @@
     data: [
         ":art-gtest-jars-ExceptionHandle",
         ":art-gtest-jars-Interfaces",
+        ":art-gtest-jars-Main",
         ":art-gtest-jars-MyClassNatives",
     ],
     tidy_timeout_srcs: [
@@ -382,6 +383,7 @@
         "optimizing/ssa_test.cc",
     ],
     srcs: [
+        "compiler_reflection_test.cc",
         "debug/dwarf/dwarf_test.cc",
         "debug/src_map_elem_test.cc",
         "driver/compiled_method_storage_test.cc",
diff --git a/compiler/art_standalone_compiler_tests.xml b/compiler/art_standalone_compiler_tests.xml
index f723971..08fcdc9 100644
--- a/compiler/art_standalone_compiler_tests.xml
+++ b/compiler/art_standalone_compiler_tests.xml
@@ -24,6 +24,7 @@
         <option name="cleanup" value="true" />
         <option name="push" value="art-gtest-jars-ExceptionHandle.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-ExceptionHandle.jar" />
         <option name="push" value="art-gtest-jars-Interfaces.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-Interfaces.jar" />
+        <option name="push" value="art-gtest-jars-Main.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-Main.jar" />
         <option name="push" value="art-gtest-jars-MyClassNatives.jar->/data/local/tmp/art_standalone_compiler_tests/art-gtest-jars-MyClassNatives.jar" />
     </target_preparer>
 
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index bbb2016..ab0e3e1 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -267,40 +267,6 @@
   CompiledMethod::ReleaseSwapAllocatedCompiledMethod(&storage, compiled_method);
 }
 
-void CommonCompilerTestImpl::CompileDirectMethod(Handle<mirror::ClassLoader> class_loader,
-                                                 const char* class_name,
-                                                 const char* method_name,
-                                                 const char* signature) {
-  std::string class_descriptor(DotToDescriptor(class_name));
-  Thread* self = Thread::Current();
-  ClassLinker* class_linker = GetClassLinker();
-  ObjPtr<mirror::Class> klass =
-      class_linker->FindClass(self, class_descriptor.c_str(), class_loader);
-  CHECK(klass != nullptr) << "Class not found " << class_name;
-  auto pointer_size = class_linker->GetImagePointerSize();
-  ArtMethod* method = klass->FindClassMethod(method_name, signature, pointer_size);
-  CHECK(method != nullptr && method->IsDirect()) << "Direct method not found: "
-      << class_name << "." << method_name << signature;
-  CompileMethod(method);
-}
-
-void CommonCompilerTestImpl::CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader,
-                                                  const char* class_name,
-                                                  const char* method_name,
-                                                  const char* signature) {
-  std::string class_descriptor(DotToDescriptor(class_name));
-  Thread* self = Thread::Current();
-  ClassLinker* class_linker = GetClassLinker();
-  ObjPtr<mirror::Class> klass =
-      class_linker->FindClass(self, class_descriptor.c_str(), class_loader);
-  CHECK(klass != nullptr) << "Class not found " << class_name;
-  auto pointer_size = class_linker->GetImagePointerSize();
-  ArtMethod* method = klass->FindClassMethod(method_name, signature, pointer_size);
-  CHECK(method != nullptr && !method->IsDirect()) << "Virtual method not found: "
-      << class_name << "." << method_name << signature;
-  CompileMethod(method);
-}
-
 void CommonCompilerTestImpl::ClearBootImageOption() {
   compiler_options_->image_type_ = CompilerOptions::ImageType::kNone;
 }
diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h
index 89cc1fa..cc021b8 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -74,14 +74,6 @@
 
   void CompileMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_);
 
-  void CompileDirectMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
-                           const char* method_name, const char* signature)
-      REQUIRES_SHARED(Locks::mutator_lock_);
-
-  void CompileVirtualMethod(Handle<mirror::ClassLoader> class_loader, const char* class_name,
-                            const char* method_name, const char* signature)
-      REQUIRES_SHARED(Locks::mutator_lock_);
-
   void ApplyInstructionSet();
   void OverrideInstructionSetFeatures(InstructionSet instruction_set, const std::string& variant);
 
diff --git a/compiler/compiler_reflection_test.cc b/compiler/compiler_reflection_test.cc
new file mode 100644
index 0000000..3b7b8b7
--- /dev/null
+++ b/compiler/compiler_reflection_test.cc
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2022 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 "reflection.h"
+
+#include "class_linker.h"
+#include "common_compiler_test.h"
+#include "handle_scope-inl.h"
+#include "jni/jni_internal.h"
+#include "mirror/class.h"
+#include "mirror/class_loader.h"
+
+namespace art {
+
+class CompilerReflectionTest : public CommonCompilerTest {};
+
+TEST_F(CompilerReflectionTest, StaticMainMethod) {
+  ScopedObjectAccess soa(Thread::Current());
+  jobject jclass_loader = LoadDex("Main");
+  StackHandleScope<1> hs(soa.Self());
+  Handle<mirror::ClassLoader> class_loader(
+      hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader)));
+
+  ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
+  ASSERT_TRUE(klass != nullptr);
+
+  ArtMethod* method = klass->FindClassMethod("main",
+                                             "([Ljava/lang/String;)V",
+                                             kRuntimePointerSize);
+  ASSERT_TRUE(method != nullptr);
+  ASSERT_TRUE(method->IsStatic());
+
+  CompileMethod(method);
+
+  // Start runtime.
+  bool started = runtime_->Start();
+  CHECK(started);
+  soa.Self()->TransitionFromSuspendedToRunnable();
+
+  jvalue args[1];
+  args[0].l = nullptr;
+  InvokeWithJValues(soa, nullptr, jni::EncodeArtMethod(method), args);
+}
+
+}  // namespace art
diff --git a/runtime/Android.bp b/runtime/Android.bp
index a9a4424..2acf8f4 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -746,6 +746,7 @@
         ":art-gtest-jars-MyClass",
         ":art-gtest-jars-MyClassNatives",
         ":art-gtest-jars-Nested",
+        ":art-gtest-jars-NonStaticLeafMethods",
         ":art-gtest-jars-Packages",
         ":art-gtest-jars-ProfileTestMultiDex",
         ":art-gtest-jars-ProtoCompare",
@@ -842,6 +843,7 @@
         "prebuilt_tools_test.cc",
         "proxy_test.cc",
         "reference_table_test.cc",
+        "reflection_test.cc",
         "runtime_callbacks_test.cc",
         "runtime_test.cc",
         "subtype_check_info_test.cc",
@@ -900,59 +902,6 @@
     test_config: "art_standalone_runtime_tests.xml",
 }
 
-art_cc_defaults {
-    name: "art_runtime_compiler_tests_defaults",
-    tidy_timeout_srcs: [
-        "reflection_test.cc",
-    ],
-    srcs: [
-        "reflection_test.cc",
-    ],
-    data: [
-        ":art-gtest-jars-Main",
-        ":art-gtest-jars-NonStaticLeafMethods",
-        ":art-gtest-jars-StaticLeafMethods",
-    ],
-}
-
-// Version of ART gtest `art_runtime_compiler_tests` bundled with the ART APEX on target.
-// TODO(b/192274705): Remove this module when the migration to standalone ART gtests is complete.
-art_cc_test {
-    name: "art_runtime_compiler_tests",
-    defaults: [
-        "art_gtest_defaults",
-        "art_runtime_compiler_tests_defaults",
-    ],
-    shared_libs: [
-        "libartd-compiler",
-    ],
-    target: {
-        host: {
-            required: ["dex2oatd"],
-        },
-    },
-}
-
-// Standalone version of ART gtest `art_runtime_compiler_tests`, not bundled with the ART APEX on
-// target.
-art_cc_test {
-    name: "art_standalone_runtime_compiler_tests",
-    defaults: [
-        "art_standalone_gtest_defaults",
-        "art_runtime_compiler_tests_defaults",
-    ],
-    data: [":generate-boot-image"],
-    shared_libs: [
-        "libart-compiler",
-    ],
-    target: {
-        host: {
-            required: ["dex2oat"],
-        },
-    },
-    test_config: "art_standalone_runtime_compiler_tests.xml",
-}
-
 genrule {
     name: "libart_mterp.x86ng",
     out: ["mterp_x86ng.S"],
diff --git a/runtime/art_standalone_runtime_compiler_tests.xml b/runtime/art_standalone_runtime_compiler_tests.xml
deleted file mode 100644
index 3ae3a82..0000000
--- a/runtime/art_standalone_runtime_compiler_tests.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- 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.
--->
-<configuration description="Runs art_standalone_runtime_compiler_tests.">
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
-        <option name="cleanup" value="true" />
-        <option name="push" value="art_standalone_runtime_compiler_tests->/data/local/tmp/art_standalone_runtime_compiler_tests/art_standalone_runtime_compiler_tests" />
-        <option name="append-bitness" value="true" />
-    </target_preparer>
-
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
-        <option name="cleanup" value="true" />
-        <option name="push" value="art-gtest-jars-Main.jar->/data/local/tmp/art_standalone_runtime_compiler_tests/art-gtest-jars-Main.jar" />
-        <option name="push" value="art-gtest-jars-NonStaticLeafMethods.jar->/data/local/tmp/art_standalone_runtime_compiler_tests/art-gtest-jars-NonStaticLeafMethods.jar" />
-        <option name="push" value="art-gtest-jars-StaticLeafMethods.jar->/data/local/tmp/art_standalone_runtime_compiler_tests/art-gtest-jars-StaticLeafMethods.jar" />
-    </target_preparer>
-
-    <target_preparer class="com.android.compatibility.common.tradefed.targetprep.FilePusher">
-        <option name="cleanup" value="true" />
-        <option name="append-bitness" value="true" />
-        <option name="push-file" key="generate-boot-image" value="/data/local/tmp/art_standalone_runtime_compiler_tests/generate-boot-image" />
-    </target_preparer>
-
-    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
-        <option name="throw-if-cmd-fail" value="true" />
-        <option name="run-command" value="mkdir -p /data/local/tmp/art_standalone_runtime_compiler_tests/art_boot_images" />
-        <option name="run-command" value="/data/local/tmp/art_standalone_runtime_compiler_tests/generate-boot-image --output-dir=/data/local/tmp/art_standalone_runtime_compiler_tests/art_boot_images" />
-        <option name="teardown-command" value="rm -rf /data/local/tmp/art_standalone_runtime_compiler_tests/art_boot_images" />
-    </target_preparer>
-
-    <test class="com.android.tradefed.testtype.GTest" >
-        <option name="native-test-device-path" value="/data/local/tmp/art_standalone_runtime_compiler_tests" />
-        <option name="module-name" value="art_standalone_runtime_compiler_tests" />
-        <option name="ld-library-path-32" value="/apex/com.android.art/lib" />
-        <option name="ld-library-path-64" value="/apex/com.android.art/lib64" />
-    </test>
-
-    <!-- When this test is run in a Mainline context (e.g. with `mts-tradefed`), only enable it if
-         one of the Mainline modules below is present on the device used for testing. -->
-    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.MainlineTestModuleController">
-        <!-- ART Mainline Module (internal version). -->
-        <option name="mainline-module-package-name" value="com.google.android.art" />
-        <!-- ART Mainline Module (external (AOSP) version). -->
-        <option name="mainline-module-package-name" value="com.android.art" />
-    </object>
-
-    <!-- Only run tests if the device under test is SDK version 31 (Android 12) or above. -->
-    <object type="module_controller" class="com.android.tradefed.testtype.suite.module.Sdk31ModuleController" />
-</configuration>
diff --git a/runtime/art_standalone_runtime_tests.xml b/runtime/art_standalone_runtime_tests.xml
index 36c16aa..0772562 100644
--- a/runtime/art_standalone_runtime_tests.xml
+++ b/runtime/art_standalone_runtime_tests.xml
@@ -48,6 +48,7 @@
         <option name="push" value="art-gtest-jars-MyClass.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-MyClass.jar" />
         <option name="push" value="art-gtest-jars-MyClassNatives.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-MyClassNatives.jar" />
         <option name="push" value="art-gtest-jars-Nested.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-Nested.jar" />
+        <option name="push" value="art-gtest-jars-NonStaticLeafMethods.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-NonStaticLeafMethods.jar" />
         <option name="push" value="art-gtest-jars-Packages.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-Packages.jar" />
         <option name="push" value="art-gtest-jars-ProfileTestMultiDex.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-ProfileTestMultiDex.jar" />
         <option name="push" value="art-gtest-jars-ProtoCompare.jar->/data/local/tmp/art_standalone_runtime_tests/art-gtest-jars-ProtoCompare.jar" />
diff --git a/runtime/reflection_test.cc b/runtime/reflection_test.cc
index 8a76855..4a24d2a 100644
--- a/runtime/reflection_test.cc
+++ b/runtime/reflection_test.cc
@@ -21,7 +21,7 @@
 
 #include "art_method-inl.h"
 #include "base/enums.h"
-#include "common_compiler_test.h"
+#include "common_runtime_test.h"
 #include "dex/descriptors_names.h"
 #include "jni/java_vm_ext.h"
 #include "jni/jni_internal.h"
@@ -31,11 +31,10 @@
 
 namespace art {
 
-// TODO: Convert to CommonRuntimeTest. Currently CompileDirectMethod is used in one test.
-class ReflectionTest : public CommonCompilerTest {
+class ReflectionTest : public CommonRuntimeTest {
  protected:
   void SetUp() override {
-    CommonCompilerTest::SetUp();
+    CommonRuntimeTest::SetUp();
 
     vm_ = Runtime::Current()->GetJavaVM();
 
@@ -76,7 +75,7 @@
 
   void TearDown() override {
     CleanUpJniEnv();
-    CommonCompilerTest::TearDown();
+    CommonRuntimeTest::TearDown();
   }
 
   jclass GetPrimitiveClass(char descriptor) {
@@ -511,33 +510,6 @@
   jclass sioobe_;
 };
 
-TEST_F(ReflectionTest, StaticMainMethod) {
-  ScopedObjectAccess soa(Thread::Current());
-  jobject jclass_loader = LoadDex("Main");
-  StackHandleScope<1> hs(soa.Self());
-  Handle<mirror::ClassLoader> class_loader(
-      hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader)));
-  CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V");
-
-  ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
-  ASSERT_TRUE(klass != nullptr);
-
-  ArtMethod* method = klass->FindClassMethod("main",
-                                             "([Ljava/lang/String;)V",
-                                             kRuntimePointerSize);
-  ASSERT_TRUE(method != nullptr);
-  ASSERT_TRUE(method->IsStatic());
-
-  // Start runtime.
-  bool started = runtime_->Start();
-  CHECK(started);
-  soa.Self()->TransitionFromSuspendedToRunnable();
-
-  jvalue args[1];
-  args[0].l = nullptr;
-  InvokeWithJValues(soa, nullptr, jni::EncodeArtMethod(method), args);
-}
-
 TEST_F(ReflectionTest, StaticNopMethod) {
   InvokeNopMethod(true);
 }
diff --git a/test/utils/regen-test-files b/test/utils/regen-test-files
index 784868c..e2ea8f0 100755
--- a/test/utils/regen-test-files
+++ b/test/utils/regen-test-files
@@ -232,7 +232,6 @@
     "art_standalone_libprofile_tests",
     "art_standalone_oatdump_tests",
     "art_standalone_odrefresh_tests",
-    "art_standalone_runtime_compiler_tests",
     "art_standalone_runtime_tests",
     "art_standalone_sigchain_tests",
     "libnativeloader_test",