1 /*
2  * Copyright (C) 2011 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 <float.h>
20 #include <limits.h>
21 #include "ScopedLocalRef.h"
22 
23 #include "art_method-inl.h"
24 #include "common_compiler_test.h"
25 #include "scoped_thread_state_change.h"
26 
27 namespace art {
28 
29 // TODO: Convert to CommonRuntimeTest. Currently MakeExecutable is used.
30 class ReflectionTest : public CommonCompilerTest {
31  protected:
SetUp()32   virtual void SetUp() {
33     CommonCompilerTest::SetUp();
34 
35     vm_ = Runtime::Current()->GetJavaVM();
36 
37     // Turn on -verbose:jni for the JNI tests.
38     // gLogVerbosity.jni = true;
39 
40     vm_->AttachCurrentThread(&env_, nullptr);
41 
42     ScopedLocalRef<jclass> aioobe(env_,
43                                   env_->FindClass("java/lang/ArrayIndexOutOfBoundsException"));
44     CHECK(aioobe.get() != nullptr);
45     aioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(aioobe.get()));
46 
47     ScopedLocalRef<jclass> ase(env_, env_->FindClass("java/lang/ArrayStoreException"));
48     CHECK(ase.get() != nullptr);
49     ase_ = reinterpret_cast<jclass>(env_->NewGlobalRef(ase.get()));
50 
51     ScopedLocalRef<jclass> sioobe(env_,
52                                   env_->FindClass("java/lang/StringIndexOutOfBoundsException"));
53     CHECK(sioobe.get() != nullptr);
54     sioobe_ = reinterpret_cast<jclass>(env_->NewGlobalRef(sioobe.get()));
55   }
56 
CleanUpJniEnv()57   void CleanUpJniEnv() {
58     if (aioobe_ != nullptr) {
59       env_->DeleteGlobalRef(aioobe_);
60       aioobe_ = nullptr;
61     }
62     if (ase_ != nullptr) {
63       env_->DeleteGlobalRef(ase_);
64       ase_ = nullptr;
65     }
66     if (sioobe_ != nullptr) {
67       env_->DeleteGlobalRef(sioobe_);
68       sioobe_ = nullptr;
69     }
70   }
71 
TearDown()72   virtual void TearDown() {
73     CleanUpJniEnv();
74     CommonCompilerTest::TearDown();
75   }
76 
GetPrimitiveClass(char descriptor)77   jclass GetPrimitiveClass(char descriptor) {
78     ScopedObjectAccess soa(env_);
79     mirror::Class* c = class_linker_->FindPrimitiveClass(descriptor);
80     CHECK(c != nullptr);
81     return soa.AddLocalReference<jclass>(c);
82   }
83 
ReflectionTestMakeExecutable(ArtMethod ** method,mirror::Object ** receiver,bool is_static,const char * method_name,const char * method_signature)84   void ReflectionTestMakeExecutable(ArtMethod** method,
85                                     mirror::Object** receiver,
86                                     bool is_static, const char* method_name,
87                                     const char* method_signature)
88       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
89     const char* class_name = is_static ? "StaticLeafMethods" : "NonStaticLeafMethods";
90     jobject jclass_loader(LoadDex(class_name));
91     Thread* self = Thread::Current();
92     StackHandleScope<2> hs(self);
93     Handle<mirror::ClassLoader> class_loader(
94         hs.NewHandle(
95             ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader)));
96     if (is_static) {
97       MakeExecutable(ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader),
98                      class_name);
99     } else {
100       MakeExecutable(nullptr, "java.lang.Class");
101       MakeExecutable(nullptr, "java.lang.Object");
102       MakeExecutable(ScopedObjectAccessUnchecked(self).Decode<mirror::ClassLoader*>(jclass_loader),
103                      class_name);
104     }
105 
106     mirror::Class* c = class_linker_->FindClass(self, DotToDescriptor(class_name).c_str(),
107                                                 class_loader);
108     CHECK(c != nullptr);
109 
110     *method = is_static ? c->FindDirectMethod(method_name, method_signature, sizeof(void*))
111                         : c->FindVirtualMethod(method_name, method_signature, sizeof(void*));
112     CHECK(method != nullptr);
113 
114     if (is_static) {
115       *receiver = nullptr;
116     } else {
117       // Ensure class is initialized before allocating object
118       StackHandleScope<1> hs2(self);
119       Handle<mirror::Class> h_class(hs2.NewHandle(c));
120       bool initialized = class_linker_->EnsureInitialized(self, h_class, true, true);
121       CHECK(initialized);
122       *receiver = c->AllocObject(self);
123     }
124 
125     // Start runtime.
126     bool started = runtime_->Start();
127     CHECK(started);
128     self->TransitionFromSuspendedToRunnable();
129   }
130 
InvokeNopMethod(bool is_static)131   void InvokeNopMethod(bool is_static) {
132     ScopedObjectAccess soa(env_);
133     ArtMethod* method;
134     mirror::Object* receiver;
135     ReflectionTestMakeExecutable(&method, &receiver, is_static, "nop", "()V");
136     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
137     InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), nullptr);
138   }
139 
InvokeIdentityByteMethod(bool is_static)140   void InvokeIdentityByteMethod(bool is_static) {
141     ScopedObjectAccess soa(env_);
142     ArtMethod* method;
143     mirror::Object* receiver;
144     ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(B)B");
145     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
146     jvalue args[1];
147 
148     args[0].b = 0;
149     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
150     EXPECT_EQ(0, result.GetB());
151 
152     args[0].b = -1;
153     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
154     EXPECT_EQ(-1, result.GetB());
155 
156     args[0].b = SCHAR_MAX;
157     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
158     EXPECT_EQ(SCHAR_MAX, result.GetB());
159 
160     args[0].b = (SCHAR_MIN << 24) >> 24;
161     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
162     EXPECT_EQ(SCHAR_MIN, result.GetB());
163   }
164 
InvokeIdentityIntMethod(bool is_static)165   void InvokeIdentityIntMethod(bool is_static) {
166     ScopedObjectAccess soa(env_);
167     ArtMethod* method;
168     mirror::Object* receiver;
169     ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(I)I");
170     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
171     jvalue args[1];
172 
173     args[0].i = 0;
174     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
175     EXPECT_EQ(0, result.GetI());
176 
177     args[0].i = -1;
178     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
179     EXPECT_EQ(-1, result.GetI());
180 
181     args[0].i = INT_MAX;
182     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
183     EXPECT_EQ(INT_MAX, result.GetI());
184 
185     args[0].i = INT_MIN;
186     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
187     EXPECT_EQ(INT_MIN, result.GetI());
188   }
189 
InvokeIdentityDoubleMethod(bool is_static)190   void InvokeIdentityDoubleMethod(bool is_static) {
191     ScopedObjectAccess soa(env_);
192     ArtMethod* method;
193     mirror::Object* receiver;
194     ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(D)D");
195     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
196     jvalue args[1];
197 
198     args[0].d = 0.0;
199     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
200     EXPECT_DOUBLE_EQ(0.0, result.GetD());
201 
202     args[0].d = -1.0;
203     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
204     EXPECT_DOUBLE_EQ(-1.0, result.GetD());
205 
206     args[0].d = DBL_MAX;
207     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
208     EXPECT_DOUBLE_EQ(DBL_MAX, result.GetD());
209 
210     args[0].d = DBL_MIN;
211     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
212     EXPECT_DOUBLE_EQ(DBL_MIN, result.GetD());
213   }
214 
InvokeSumIntIntMethod(bool is_static)215   void InvokeSumIntIntMethod(bool is_static) {
216     ScopedObjectAccess soa(env_);
217     ArtMethod* method;
218     mirror::Object* receiver;
219     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(II)I");
220     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
221     jvalue args[2];
222 
223     args[0].i = 1;
224     args[1].i = 2;
225     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
226     EXPECT_EQ(3, result.GetI());
227 
228     args[0].i = -2;
229     args[1].i = 5;
230     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
231     EXPECT_EQ(3, result.GetI());
232 
233     args[0].i = INT_MAX;
234     args[1].i = INT_MIN;
235     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
236     EXPECT_EQ(-1, result.GetI());
237 
238     args[0].i = INT_MAX;
239     args[1].i = INT_MAX;
240     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
241     EXPECT_EQ(-2, result.GetI());
242   }
243 
InvokeSumIntIntIntMethod(bool is_static)244   void InvokeSumIntIntIntMethod(bool is_static) {
245     ScopedObjectAccess soa(env_);
246     ArtMethod* method;
247     mirror::Object* receiver;
248     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(III)I");
249     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
250     jvalue args[3];
251 
252     args[0].i = 0;
253     args[1].i = 0;
254     args[2].i = 0;
255     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
256     EXPECT_EQ(0, result.GetI());
257 
258     args[0].i = 1;
259     args[1].i = 2;
260     args[2].i = 3;
261     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
262     EXPECT_EQ(6, result.GetI());
263 
264     args[0].i = -1;
265     args[1].i = 2;
266     args[2].i = -3;
267     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
268     EXPECT_EQ(-2, result.GetI());
269 
270     args[0].i = INT_MAX;
271     args[1].i = INT_MIN;
272     args[2].i = INT_MAX;
273     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
274     EXPECT_EQ(2147483646, result.GetI());
275 
276     args[0].i = INT_MAX;
277     args[1].i = INT_MAX;
278     args[2].i = INT_MAX;
279     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
280     EXPECT_EQ(2147483645, result.GetI());
281   }
282 
InvokeSumIntIntIntIntMethod(bool is_static)283   void InvokeSumIntIntIntIntMethod(bool is_static) {
284     ScopedObjectAccess soa(env_);
285     ArtMethod* method;
286     mirror::Object* receiver;
287     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIII)I");
288     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
289     jvalue args[4];
290 
291     args[0].i = 0;
292     args[1].i = 0;
293     args[2].i = 0;
294     args[3].i = 0;
295     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
296     EXPECT_EQ(0, result.GetI());
297 
298     args[0].i = 1;
299     args[1].i = 2;
300     args[2].i = 3;
301     args[3].i = 4;
302     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
303     EXPECT_EQ(10, result.GetI());
304 
305     args[0].i = -1;
306     args[1].i = 2;
307     args[2].i = -3;
308     args[3].i = 4;
309     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
310     EXPECT_EQ(2, result.GetI());
311 
312     args[0].i = INT_MAX;
313     args[1].i = INT_MIN;
314     args[2].i = INT_MAX;
315     args[3].i = INT_MIN;
316     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
317     EXPECT_EQ(-2, result.GetI());
318 
319     args[0].i = INT_MAX;
320     args[1].i = INT_MAX;
321     args[2].i = INT_MAX;
322     args[3].i = INT_MAX;
323     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
324     EXPECT_EQ(-4, result.GetI());
325   }
326 
InvokeSumIntIntIntIntIntMethod(bool is_static)327   void InvokeSumIntIntIntIntIntMethod(bool is_static) {
328     ScopedObjectAccess soa(env_);
329     ArtMethod* method;
330     mirror::Object* receiver;
331     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIIII)I");
332     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
333     jvalue args[5];
334 
335     args[0].i = 0;
336     args[1].i = 0;
337     args[2].i = 0;
338     args[3].i = 0;
339     args[4].i = 0;
340     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
341     EXPECT_EQ(0, result.GetI());
342 
343     args[0].i = 1;
344     args[1].i = 2;
345     args[2].i = 3;
346     args[3].i = 4;
347     args[4].i = 5;
348     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
349     EXPECT_EQ(15, result.GetI());
350 
351     args[0].i = -1;
352     args[1].i = 2;
353     args[2].i = -3;
354     args[3].i = 4;
355     args[4].i = -5;
356     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
357     EXPECT_EQ(-3, result.GetI());
358 
359     args[0].i = INT_MAX;
360     args[1].i = INT_MIN;
361     args[2].i = INT_MAX;
362     args[3].i = INT_MIN;
363     args[4].i = INT_MAX;
364     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
365     EXPECT_EQ(2147483645, result.GetI());
366 
367     args[0].i = INT_MAX;
368     args[1].i = INT_MAX;
369     args[2].i = INT_MAX;
370     args[3].i = INT_MAX;
371     args[4].i = INT_MAX;
372     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
373     EXPECT_EQ(2147483643, result.GetI());
374   }
375 
InvokeSumDoubleDoubleMethod(bool is_static)376   void InvokeSumDoubleDoubleMethod(bool is_static) {
377     ScopedObjectAccess soa(env_);
378     ArtMethod* method;
379     mirror::Object* receiver;
380     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DD)D");
381     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
382     jvalue args[2];
383 
384     args[0].d = 0.0;
385     args[1].d = 0.0;
386     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
387     EXPECT_DOUBLE_EQ(0.0, result.GetD());
388 
389     args[0].d = 1.0;
390     args[1].d = 2.0;
391     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
392     EXPECT_DOUBLE_EQ(3.0, result.GetD());
393 
394     args[0].d = 1.0;
395     args[1].d = -2.0;
396     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
397     EXPECT_DOUBLE_EQ(-1.0, result.GetD());
398 
399     args[0].d = DBL_MAX;
400     args[1].d = DBL_MIN;
401     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
402     EXPECT_DOUBLE_EQ(1.7976931348623157e308, result.GetD());
403 
404     args[0].d = DBL_MAX;
405     args[1].d = DBL_MAX;
406     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
407     EXPECT_DOUBLE_EQ(INFINITY, result.GetD());
408   }
409 
InvokeSumDoubleDoubleDoubleMethod(bool is_static)410   void InvokeSumDoubleDoubleDoubleMethod(bool is_static) {
411     ScopedObjectAccess soa(env_);
412     ArtMethod* method;
413     mirror::Object* receiver;
414     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDD)D");
415     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
416     jvalue args[3];
417 
418     args[0].d = 0.0;
419     args[1].d = 0.0;
420     args[2].d = 0.0;
421     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
422     EXPECT_DOUBLE_EQ(0.0, result.GetD());
423 
424     args[0].d = 1.0;
425     args[1].d = 2.0;
426     args[2].d = 3.0;
427     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
428     EXPECT_DOUBLE_EQ(6.0, result.GetD());
429 
430     args[0].d = 1.0;
431     args[1].d = -2.0;
432     args[2].d = 3.0;
433     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
434     EXPECT_DOUBLE_EQ(2.0, result.GetD());
435   }
436 
InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static)437   void InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static) {
438     ScopedObjectAccess soa(env_);
439     ArtMethod* method;
440     mirror::Object* receiver;
441     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDD)D");
442     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
443     jvalue args[4];
444 
445     args[0].d = 0.0;
446     args[1].d = 0.0;
447     args[2].d = 0.0;
448     args[3].d = 0.0;
449     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
450     EXPECT_DOUBLE_EQ(0.0, result.GetD());
451 
452     args[0].d = 1.0;
453     args[1].d = 2.0;
454     args[2].d = 3.0;
455     args[3].d = 4.0;
456     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
457     EXPECT_DOUBLE_EQ(10.0, result.GetD());
458 
459     args[0].d = 1.0;
460     args[1].d = -2.0;
461     args[2].d = 3.0;
462     args[3].d = -4.0;
463     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
464     EXPECT_DOUBLE_EQ(-2.0, result.GetD());
465   }
466 
InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static)467   void InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static) {
468     ScopedObjectAccess soa(env_);
469     ArtMethod* method;
470     mirror::Object* receiver;
471     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDDD)D");
472     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
473     jvalue args[5];
474 
475     args[0].d = 0.0;
476     args[1].d = 0.0;
477     args[2].d = 0.0;
478     args[3].d = 0.0;
479     args[4].d = 0.0;
480     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
481     EXPECT_DOUBLE_EQ(0.0, result.GetD());
482 
483     args[0].d = 1.0;
484     args[1].d = 2.0;
485     args[2].d = 3.0;
486     args[3].d = 4.0;
487     args[4].d = 5.0;
488     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
489     EXPECT_DOUBLE_EQ(15.0, result.GetD());
490 
491     args[0].d = 1.0;
492     args[1].d = -2.0;
493     args[2].d = 3.0;
494     args[3].d = -4.0;
495     args[4].d = 5.0;
496     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
497     EXPECT_DOUBLE_EQ(3.0, result.GetD());
498   }
499 
500   JavaVMExt* vm_;
501   JNIEnv* env_;
502   jclass aioobe_;
503   jclass ase_;
504   jclass sioobe_;
505 };
506 
TEST_F(ReflectionTest,StaticMainMethod)507 TEST_F(ReflectionTest, StaticMainMethod) {
508   ScopedObjectAccess soa(Thread::Current());
509   jobject jclass_loader = LoadDex("Main");
510   StackHandleScope<1> hs(soa.Self());
511   Handle<mirror::ClassLoader> class_loader(
512       hs.NewHandle(soa.Decode<mirror::ClassLoader*>(jclass_loader)));
513   CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V");
514 
515   mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
516   ASSERT_TRUE(klass != nullptr);
517 
518   ArtMethod* method = klass->FindDirectMethod("main", "([Ljava/lang/String;)V", sizeof(void*));
519   ASSERT_TRUE(method != nullptr);
520 
521   // Start runtime.
522   bool started = runtime_->Start();
523   CHECK(started);
524   soa.Self()->TransitionFromSuspendedToRunnable();
525 
526   jvalue args[1];
527   args[0].l = nullptr;
528   InvokeWithJValues(soa, nullptr, soa.EncodeMethod(method), args);
529 }
530 
TEST_F(ReflectionTest,StaticNopMethod)531 TEST_F(ReflectionTest, StaticNopMethod) {
532   InvokeNopMethod(true);
533 }
534 
TEST_F(ReflectionTest,NonStaticNopMethod)535 TEST_F(ReflectionTest, NonStaticNopMethod) {
536   InvokeNopMethod(false);
537 }
538 
TEST_F(ReflectionTest,StaticIdentityByteMethod)539 TEST_F(ReflectionTest, StaticIdentityByteMethod) {
540   InvokeIdentityByteMethod(true);
541 }
542 
TEST_F(ReflectionTest,NonStaticIdentityByteMethod)543 TEST_F(ReflectionTest, NonStaticIdentityByteMethod) {
544   InvokeIdentityByteMethod(false);
545 }
546 
TEST_F(ReflectionTest,StaticIdentityIntMethod)547 TEST_F(ReflectionTest, StaticIdentityIntMethod) {
548   InvokeIdentityIntMethod(true);
549 }
550 
TEST_F(ReflectionTest,NonStaticIdentityIntMethod)551 TEST_F(ReflectionTest, NonStaticIdentityIntMethod) {
552   InvokeIdentityIntMethod(false);
553 }
554 
TEST_F(ReflectionTest,StaticIdentityDoubleMethod)555 TEST_F(ReflectionTest, StaticIdentityDoubleMethod) {
556   InvokeIdentityDoubleMethod(true);
557 }
558 
TEST_F(ReflectionTest,NonStaticIdentityDoubleMethod)559 TEST_F(ReflectionTest, NonStaticIdentityDoubleMethod) {
560   InvokeIdentityDoubleMethod(false);
561 }
562 
TEST_F(ReflectionTest,StaticSumIntIntMethod)563 TEST_F(ReflectionTest, StaticSumIntIntMethod) {
564   InvokeSumIntIntMethod(true);
565 }
566 
TEST_F(ReflectionTest,NonStaticSumIntIntMethod)567 TEST_F(ReflectionTest, NonStaticSumIntIntMethod) {
568   InvokeSumIntIntMethod(false);
569 }
570 
TEST_F(ReflectionTest,StaticSumIntIntIntMethod)571 TEST_F(ReflectionTest, StaticSumIntIntIntMethod) {
572   InvokeSumIntIntIntMethod(true);
573 }
574 
TEST_F(ReflectionTest,NonStaticSumIntIntIntMethod)575 TEST_F(ReflectionTest, NonStaticSumIntIntIntMethod) {
576   InvokeSumIntIntIntMethod(false);
577 }
578 
TEST_F(ReflectionTest,StaticSumIntIntIntIntMethod)579 TEST_F(ReflectionTest, StaticSumIntIntIntIntMethod) {
580   InvokeSumIntIntIntIntMethod(true);
581 }
582 
TEST_F(ReflectionTest,NonStaticSumIntIntIntIntMethod)583 TEST_F(ReflectionTest, NonStaticSumIntIntIntIntMethod) {
584   InvokeSumIntIntIntIntMethod(false);
585 }
586 
TEST_F(ReflectionTest,StaticSumIntIntIntIntIntMethod)587 TEST_F(ReflectionTest, StaticSumIntIntIntIntIntMethod) {
588   InvokeSumIntIntIntIntIntMethod(true);
589 }
590 
TEST_F(ReflectionTest,NonStaticSumIntIntIntIntIntMethod)591 TEST_F(ReflectionTest, NonStaticSumIntIntIntIntIntMethod) {
592   InvokeSumIntIntIntIntIntMethod(false);
593 }
594 
TEST_F(ReflectionTest,StaticSumDoubleDoubleMethod)595 TEST_F(ReflectionTest, StaticSumDoubleDoubleMethod) {
596   InvokeSumDoubleDoubleMethod(true);
597 }
598 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleMethod)599 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleMethod) {
600   InvokeSumDoubleDoubleMethod(false);
601 }
602 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleMethod)603 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleMethod) {
604   InvokeSumDoubleDoubleDoubleMethod(true);
605 }
606 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleMethod)607 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleMethod) {
608   InvokeSumDoubleDoubleDoubleMethod(false);
609 }
610 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleDoubleMethod)611 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleMethod) {
612   InvokeSumDoubleDoubleDoubleDoubleMethod(true);
613 }
614 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleDoubleMethod)615 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleMethod) {
616   InvokeSumDoubleDoubleDoubleDoubleMethod(false);
617 }
618 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleDoubleDoubleMethod)619 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
620   InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(true);
621 }
622 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod)623 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
624   InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(false);
625 }
626 
627 }  // namespace art
628