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