1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "reflection.h"
18
19 #include "base/macros.h"
20 #include "class_linker.h"
21 #include "common_compiler_test.h"
22 #include "handle_scope-inl.h"
23 #include "jni/jni_internal.h"
24 #include "mirror/class.h"
25 #include "mirror/class_loader.h"
26
27 namespace art HIDDEN {
28
29 class CompilerReflectionTest : public CommonCompilerTest {};
30
TEST_F(CompilerReflectionTest,StaticMainMethod)31 TEST_F(CompilerReflectionTest, StaticMainMethod) {
32 ScopedObjectAccess soa(Thread::Current());
33 jobject jclass_loader = LoadDex("Main");
34 StackHandleScope<1> hs(soa.Self());
35 Handle<mirror::ClassLoader> class_loader(
36 hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader)));
37
38 ObjPtr<mirror::Class> klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
39 ASSERT_TRUE(klass != nullptr);
40
41 ArtMethod* method = klass->FindClassMethod("main",
42 "([Ljava/lang/String;)V",
43 kRuntimePointerSize);
44 ASSERT_TRUE(method != nullptr);
45 ASSERT_TRUE(method->IsStatic());
46
47 CompileMethod(method);
48
49 // Start runtime.
50 bool started = runtime_->Start();
51 CHECK(started);
52 soa.Self()->TransitionFromSuspendedToRunnable();
53
54 jvalue args[1];
55 args[0].l = nullptr;
56 InvokeWithJValues(soa, nullptr, jni::EncodeArtMethod(method), args);
57 }
58
59 } // namespace art
60