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