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