• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REQUIRES(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     static_assert(SCHAR_MIN == -128, "SCHAR_MIN unexpected");
161     args[0].b = SCHAR_MIN;
162     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
163     EXPECT_EQ(SCHAR_MIN, result.GetB());
164   }
165 
InvokeIdentityIntMethod(bool is_static)166   void InvokeIdentityIntMethod(bool is_static) {
167     ScopedObjectAccess soa(env_);
168     ArtMethod* method;
169     mirror::Object* receiver;
170     ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(I)I");
171     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
172     jvalue args[1];
173 
174     args[0].i = 0;
175     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
176     EXPECT_EQ(0, result.GetI());
177 
178     args[0].i = -1;
179     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
180     EXPECT_EQ(-1, result.GetI());
181 
182     args[0].i = INT_MAX;
183     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
184     EXPECT_EQ(INT_MAX, result.GetI());
185 
186     args[0].i = INT_MIN;
187     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
188     EXPECT_EQ(INT_MIN, result.GetI());
189   }
190 
InvokeIdentityDoubleMethod(bool is_static)191   void InvokeIdentityDoubleMethod(bool is_static) {
192     ScopedObjectAccess soa(env_);
193     ArtMethod* method;
194     mirror::Object* receiver;
195     ReflectionTestMakeExecutable(&method, &receiver, is_static, "identity", "(D)D");
196     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
197     jvalue args[1];
198 
199     args[0].d = 0.0;
200     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
201     EXPECT_DOUBLE_EQ(0.0, result.GetD());
202 
203     args[0].d = -1.0;
204     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
205     EXPECT_DOUBLE_EQ(-1.0, result.GetD());
206 
207     args[0].d = DBL_MAX;
208     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
209     EXPECT_DOUBLE_EQ(DBL_MAX, result.GetD());
210 
211     args[0].d = DBL_MIN;
212     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
213     EXPECT_DOUBLE_EQ(DBL_MIN, result.GetD());
214   }
215 
InvokeSumIntIntMethod(bool is_static)216   void InvokeSumIntIntMethod(bool is_static) {
217     ScopedObjectAccess soa(env_);
218     ArtMethod* method;
219     mirror::Object* receiver;
220     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(II)I");
221     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
222     jvalue args[2];
223 
224     args[0].i = 1;
225     args[1].i = 2;
226     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
227     EXPECT_EQ(3, result.GetI());
228 
229     args[0].i = -2;
230     args[1].i = 5;
231     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
232     EXPECT_EQ(3, result.GetI());
233 
234     args[0].i = INT_MAX;
235     args[1].i = INT_MIN;
236     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
237     EXPECT_EQ(-1, result.GetI());
238 
239     args[0].i = INT_MAX;
240     args[1].i = INT_MAX;
241     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
242     EXPECT_EQ(-2, result.GetI());
243   }
244 
InvokeSumIntIntIntMethod(bool is_static)245   void InvokeSumIntIntIntMethod(bool is_static) {
246     ScopedObjectAccess soa(env_);
247     ArtMethod* method;
248     mirror::Object* receiver;
249     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(III)I");
250     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
251     jvalue args[3];
252 
253     args[0].i = 0;
254     args[1].i = 0;
255     args[2].i = 0;
256     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
257     EXPECT_EQ(0, result.GetI());
258 
259     args[0].i = 1;
260     args[1].i = 2;
261     args[2].i = 3;
262     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
263     EXPECT_EQ(6, result.GetI());
264 
265     args[0].i = -1;
266     args[1].i = 2;
267     args[2].i = -3;
268     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
269     EXPECT_EQ(-2, result.GetI());
270 
271     args[0].i = INT_MAX;
272     args[1].i = INT_MIN;
273     args[2].i = INT_MAX;
274     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
275     EXPECT_EQ(2147483646, result.GetI());
276 
277     args[0].i = INT_MAX;
278     args[1].i = INT_MAX;
279     args[2].i = INT_MAX;
280     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
281     EXPECT_EQ(2147483645, result.GetI());
282   }
283 
InvokeSumIntIntIntIntMethod(bool is_static)284   void InvokeSumIntIntIntIntMethod(bool is_static) {
285     ScopedObjectAccess soa(env_);
286     ArtMethod* method;
287     mirror::Object* receiver;
288     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIII)I");
289     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
290     jvalue args[4];
291 
292     args[0].i = 0;
293     args[1].i = 0;
294     args[2].i = 0;
295     args[3].i = 0;
296     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
297     EXPECT_EQ(0, result.GetI());
298 
299     args[0].i = 1;
300     args[1].i = 2;
301     args[2].i = 3;
302     args[3].i = 4;
303     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
304     EXPECT_EQ(10, result.GetI());
305 
306     args[0].i = -1;
307     args[1].i = 2;
308     args[2].i = -3;
309     args[3].i = 4;
310     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
311     EXPECT_EQ(2, result.GetI());
312 
313     args[0].i = INT_MAX;
314     args[1].i = INT_MIN;
315     args[2].i = INT_MAX;
316     args[3].i = INT_MIN;
317     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
318     EXPECT_EQ(-2, result.GetI());
319 
320     args[0].i = INT_MAX;
321     args[1].i = INT_MAX;
322     args[2].i = INT_MAX;
323     args[3].i = INT_MAX;
324     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
325     EXPECT_EQ(-4, result.GetI());
326   }
327 
InvokeSumIntIntIntIntIntMethod(bool is_static)328   void InvokeSumIntIntIntIntIntMethod(bool is_static) {
329     ScopedObjectAccess soa(env_);
330     ArtMethod* method;
331     mirror::Object* receiver;
332     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(IIIII)I");
333     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
334     jvalue args[5];
335 
336     args[0].i = 0;
337     args[1].i = 0;
338     args[2].i = 0;
339     args[3].i = 0;
340     args[4].i = 0;
341     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
342     EXPECT_EQ(0, result.GetI());
343 
344     args[0].i = 1;
345     args[1].i = 2;
346     args[2].i = 3;
347     args[3].i = 4;
348     args[4].i = 5;
349     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
350     EXPECT_EQ(15, result.GetI());
351 
352     args[0].i = -1;
353     args[1].i = 2;
354     args[2].i = -3;
355     args[3].i = 4;
356     args[4].i = -5;
357     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
358     EXPECT_EQ(-3, result.GetI());
359 
360     args[0].i = INT_MAX;
361     args[1].i = INT_MIN;
362     args[2].i = INT_MAX;
363     args[3].i = INT_MIN;
364     args[4].i = INT_MAX;
365     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
366     EXPECT_EQ(2147483645, result.GetI());
367 
368     args[0].i = INT_MAX;
369     args[1].i = INT_MAX;
370     args[2].i = INT_MAX;
371     args[3].i = INT_MAX;
372     args[4].i = INT_MAX;
373     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
374     EXPECT_EQ(2147483643, result.GetI());
375   }
376 
InvokeSumDoubleDoubleMethod(bool is_static)377   void InvokeSumDoubleDoubleMethod(bool is_static) {
378     ScopedObjectAccess soa(env_);
379     ArtMethod* method;
380     mirror::Object* receiver;
381     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DD)D");
382     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
383     jvalue args[2];
384 
385     args[0].d = 0.0;
386     args[1].d = 0.0;
387     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
388     EXPECT_DOUBLE_EQ(0.0, result.GetD());
389 
390     args[0].d = 1.0;
391     args[1].d = 2.0;
392     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
393     EXPECT_DOUBLE_EQ(3.0, result.GetD());
394 
395     args[0].d = 1.0;
396     args[1].d = -2.0;
397     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
398     EXPECT_DOUBLE_EQ(-1.0, result.GetD());
399 
400     args[0].d = DBL_MAX;
401     args[1].d = DBL_MIN;
402     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
403     EXPECT_DOUBLE_EQ(1.7976931348623157e308, result.GetD());
404 
405     args[0].d = DBL_MAX;
406     args[1].d = DBL_MAX;
407     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
408     EXPECT_DOUBLE_EQ(INFINITY, result.GetD());
409   }
410 
InvokeSumDoubleDoubleDoubleMethod(bool is_static)411   void InvokeSumDoubleDoubleDoubleMethod(bool is_static) {
412     ScopedObjectAccess soa(env_);
413     ArtMethod* method;
414     mirror::Object* receiver;
415     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDD)D");
416     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
417     jvalue args[3];
418 
419     args[0].d = 0.0;
420     args[1].d = 0.0;
421     args[2].d = 0.0;
422     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
423     EXPECT_DOUBLE_EQ(0.0, result.GetD());
424 
425     args[0].d = 1.0;
426     args[1].d = 2.0;
427     args[2].d = 3.0;
428     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
429     EXPECT_DOUBLE_EQ(6.0, result.GetD());
430 
431     args[0].d = 1.0;
432     args[1].d = -2.0;
433     args[2].d = 3.0;
434     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
435     EXPECT_DOUBLE_EQ(2.0, result.GetD());
436   }
437 
InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static)438   void InvokeSumDoubleDoubleDoubleDoubleMethod(bool is_static) {
439     ScopedObjectAccess soa(env_);
440     ArtMethod* method;
441     mirror::Object* receiver;
442     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDD)D");
443     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
444     jvalue args[4];
445 
446     args[0].d = 0.0;
447     args[1].d = 0.0;
448     args[2].d = 0.0;
449     args[3].d = 0.0;
450     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
451     EXPECT_DOUBLE_EQ(0.0, result.GetD());
452 
453     args[0].d = 1.0;
454     args[1].d = 2.0;
455     args[2].d = 3.0;
456     args[3].d = 4.0;
457     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
458     EXPECT_DOUBLE_EQ(10.0, result.GetD());
459 
460     args[0].d = 1.0;
461     args[1].d = -2.0;
462     args[2].d = 3.0;
463     args[3].d = -4.0;
464     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
465     EXPECT_DOUBLE_EQ(-2.0, result.GetD());
466   }
467 
InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static)468   void InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(bool is_static) {
469     ScopedObjectAccess soa(env_);
470     ArtMethod* method;
471     mirror::Object* receiver;
472     ReflectionTestMakeExecutable(&method, &receiver, is_static, "sum", "(DDDDD)D");
473     ScopedLocalRef<jobject> receiver_ref(soa.Env(), soa.AddLocalReference<jobject>(receiver));
474     jvalue args[5];
475 
476     args[0].d = 0.0;
477     args[1].d = 0.0;
478     args[2].d = 0.0;
479     args[3].d = 0.0;
480     args[4].d = 0.0;
481     JValue result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
482     EXPECT_DOUBLE_EQ(0.0, result.GetD());
483 
484     args[0].d = 1.0;
485     args[1].d = 2.0;
486     args[2].d = 3.0;
487     args[3].d = 4.0;
488     args[4].d = 5.0;
489     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
490     EXPECT_DOUBLE_EQ(15.0, result.GetD());
491 
492     args[0].d = 1.0;
493     args[1].d = -2.0;
494     args[2].d = 3.0;
495     args[3].d = -4.0;
496     args[4].d = 5.0;
497     result = InvokeWithJValues(soa, receiver_ref.get(), soa.EncodeMethod(method), args);
498     EXPECT_DOUBLE_EQ(3.0, result.GetD());
499   }
500 
501   JavaVMExt* vm_;
502   JNIEnv* env_;
503   jclass aioobe_;
504   jclass ase_;
505   jclass sioobe_;
506 };
507 
TEST_F(ReflectionTest,StaticMainMethod)508 TEST_F(ReflectionTest, StaticMainMethod) {
509   TEST_DISABLED_FOR_READ_BARRIER_WITH_OPTIMIZING_FOR_UNSUPPORTED_INSTRUCTION_SETS();
510   ScopedObjectAccess soa(Thread::Current());
511   jobject jclass_loader = LoadDex("Main");
512   StackHandleScope<1> hs(soa.Self());
513   Handle<mirror::ClassLoader> class_loader(
514       hs.NewHandle(soa.Decode<mirror::ClassLoader*>(jclass_loader)));
515   CompileDirectMethod(class_loader, "Main", "main", "([Ljava/lang/String;)V");
516 
517   mirror::Class* klass = class_linker_->FindClass(soa.Self(), "LMain;", class_loader);
518   ASSERT_TRUE(klass != nullptr);
519 
520   ArtMethod* method = klass->FindDirectMethod("main", "([Ljava/lang/String;)V", sizeof(void*));
521   ASSERT_TRUE(method != nullptr);
522 
523   // Start runtime.
524   bool started = runtime_->Start();
525   CHECK(started);
526   soa.Self()->TransitionFromSuspendedToRunnable();
527 
528   jvalue args[1];
529   args[0].l = nullptr;
530   InvokeWithJValues(soa, nullptr, soa.EncodeMethod(method), args);
531 }
532 
TEST_F(ReflectionTest,StaticNopMethod)533 TEST_F(ReflectionTest, StaticNopMethod) {
534   InvokeNopMethod(true);
535 }
536 
TEST_F(ReflectionTest,NonStaticNopMethod)537 TEST_F(ReflectionTest, NonStaticNopMethod) {
538   InvokeNopMethod(false);
539 }
540 
TEST_F(ReflectionTest,StaticIdentityByteMethod)541 TEST_F(ReflectionTest, StaticIdentityByteMethod) {
542   InvokeIdentityByteMethod(true);
543 }
544 
TEST_F(ReflectionTest,NonStaticIdentityByteMethod)545 TEST_F(ReflectionTest, NonStaticIdentityByteMethod) {
546   InvokeIdentityByteMethod(false);
547 }
548 
TEST_F(ReflectionTest,StaticIdentityIntMethod)549 TEST_F(ReflectionTest, StaticIdentityIntMethod) {
550   InvokeIdentityIntMethod(true);
551 }
552 
TEST_F(ReflectionTest,NonStaticIdentityIntMethod)553 TEST_F(ReflectionTest, NonStaticIdentityIntMethod) {
554   InvokeIdentityIntMethod(false);
555 }
556 
TEST_F(ReflectionTest,StaticIdentityDoubleMethod)557 TEST_F(ReflectionTest, StaticIdentityDoubleMethod) {
558   InvokeIdentityDoubleMethod(true);
559 }
560 
TEST_F(ReflectionTest,NonStaticIdentityDoubleMethod)561 TEST_F(ReflectionTest, NonStaticIdentityDoubleMethod) {
562   InvokeIdentityDoubleMethod(false);
563 }
564 
TEST_F(ReflectionTest,StaticSumIntIntMethod)565 TEST_F(ReflectionTest, StaticSumIntIntMethod) {
566   InvokeSumIntIntMethod(true);
567 }
568 
TEST_F(ReflectionTest,NonStaticSumIntIntMethod)569 TEST_F(ReflectionTest, NonStaticSumIntIntMethod) {
570   InvokeSumIntIntMethod(false);
571 }
572 
TEST_F(ReflectionTest,StaticSumIntIntIntMethod)573 TEST_F(ReflectionTest, StaticSumIntIntIntMethod) {
574   InvokeSumIntIntIntMethod(true);
575 }
576 
TEST_F(ReflectionTest,NonStaticSumIntIntIntMethod)577 TEST_F(ReflectionTest, NonStaticSumIntIntIntMethod) {
578   InvokeSumIntIntIntMethod(false);
579 }
580 
TEST_F(ReflectionTest,StaticSumIntIntIntIntMethod)581 TEST_F(ReflectionTest, StaticSumIntIntIntIntMethod) {
582   InvokeSumIntIntIntIntMethod(true);
583 }
584 
TEST_F(ReflectionTest,NonStaticSumIntIntIntIntMethod)585 TEST_F(ReflectionTest, NonStaticSumIntIntIntIntMethod) {
586   InvokeSumIntIntIntIntMethod(false);
587 }
588 
TEST_F(ReflectionTest,StaticSumIntIntIntIntIntMethod)589 TEST_F(ReflectionTest, StaticSumIntIntIntIntIntMethod) {
590   InvokeSumIntIntIntIntIntMethod(true);
591 }
592 
TEST_F(ReflectionTest,NonStaticSumIntIntIntIntIntMethod)593 TEST_F(ReflectionTest, NonStaticSumIntIntIntIntIntMethod) {
594   InvokeSumIntIntIntIntIntMethod(false);
595 }
596 
TEST_F(ReflectionTest,StaticSumDoubleDoubleMethod)597 TEST_F(ReflectionTest, StaticSumDoubleDoubleMethod) {
598   InvokeSumDoubleDoubleMethod(true);
599 }
600 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleMethod)601 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleMethod) {
602   InvokeSumDoubleDoubleMethod(false);
603 }
604 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleMethod)605 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleMethod) {
606   InvokeSumDoubleDoubleDoubleMethod(true);
607 }
608 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleMethod)609 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleMethod) {
610   InvokeSumDoubleDoubleDoubleMethod(false);
611 }
612 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleDoubleMethod)613 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleMethod) {
614   InvokeSumDoubleDoubleDoubleDoubleMethod(true);
615 }
616 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleDoubleMethod)617 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleMethod) {
618   InvokeSumDoubleDoubleDoubleDoubleMethod(false);
619 }
620 
TEST_F(ReflectionTest,StaticSumDoubleDoubleDoubleDoubleDoubleMethod)621 TEST_F(ReflectionTest, StaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
622   InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(true);
623 }
624 
TEST_F(ReflectionTest,NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod)625 TEST_F(ReflectionTest, NonStaticSumDoubleDoubleDoubleDoubleDoubleMethod) {
626   InvokeSumDoubleDoubleDoubleDoubleDoubleMethod(false);
627 }
628 
629 }  // namespace art
630