summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/Android.bp2
-rw-r--r--compiler/art_standalone_compiler_tests.xml1
-rw-r--r--compiler/common_compiler_test.cc34
-rw-r--r--compiler/common_compiler_test.h8
-rw-r--r--compiler/compiler_reflection_test.cc58
5 files changed, 61 insertions, 42 deletions
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 50af288b39..830a9f0e8a 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -370,6 +370,7 @@ art_cc_defaults {
data: [
":art-gtest-jars-ExceptionHandle",
":art-gtest-jars-Interfaces",
+ ":art-gtest-jars-Main",
":art-gtest-jars-MyClassNatives",
],
tidy_timeout_srcs: [
@@ -382,6 +383,7 @@ art_cc_defaults {
"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 f723971928..08fcdc9833 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 bbb2016566..ab0e3e17cf 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -267,40 +267,6 @@ void CommonCompilerTestImpl::CompileMethod(ArtMethod* method) {
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 89cc1fa28f..cc021b829e 100644
--- a/compiler/common_compiler_test.h
+++ b/compiler/common_compiler_test.h
@@ -74,14 +74,6 @@ class CommonCompilerTestImpl {
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 0000000000..3b7b8b7369
--- /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