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 <memory> 18 19 #include <math.h> 20 21 #include "art_method-inl.h" 22 #include "class_linker.h" 23 #include "common_compiler_test.h" 24 #include "dex_file.h" 25 #include "gtest/gtest.h" 26 #include "indirect_reference_table.h" 27 #include "jni_internal.h" 28 #include "mem_map.h" 29 #include "mirror/class-inl.h" 30 #include "mirror/class_loader.h" 31 #include "mirror/object_array-inl.h" 32 #include "mirror/object-inl.h" 33 #include "mirror/stack_trace_element.h" 34 #include "nativeloader/native_loader.h" 35 #include "runtime.h" 36 #include "ScopedLocalRef.h" 37 #include "scoped_thread_state_change.h" 38 #include "thread.h" 39 40 extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_bar(JNIEnv*, jobject, jint count) { 41 return count + 1; 42 } 43 44 extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_sbar(JNIEnv*, jclass, jint count) { 45 return count + 1; 46 } 47 48 namespace art { 49 50 class JniCompilerTest : public CommonCompilerTest { 51 protected: 52 void SetUp() OVERRIDE { 53 CommonCompilerTest::SetUp(); 54 check_generic_jni_ = false; 55 } 56 57 void TearDown() OVERRIDE { 58 android::ResetNativeLoader(); 59 CommonCompilerTest::TearDown(); 60 } 61 62 void SetCheckGenericJni(bool generic) { 63 check_generic_jni_ = generic; 64 } 65 66 void CompileForTest(jobject class_loader, bool direct, 67 const char* method_name, const char* method_sig) { 68 ScopedObjectAccess soa(Thread::Current()); 69 StackHandleScope<1> hs(soa.Self()); 70 Handle<mirror::ClassLoader> loader( 71 hs.NewHandle(soa.Decode<mirror::ClassLoader*>(class_loader))); 72 // Compile the native method before starting the runtime 73 mirror::Class* c = class_linker_->FindClass(soa.Self(), "LMyClassNatives;", loader); 74 const auto pointer_size = class_linker_->GetImagePointerSize(); 75 ArtMethod* method = direct ? c->FindDirectMethod(method_name, method_sig, pointer_size) : 76 c->FindVirtualMethod(method_name, method_sig, pointer_size); 77 ASSERT_TRUE(method != nullptr) << method_name << " " << method_sig; 78 if (check_generic_jni_) { 79 method->SetEntryPointFromQuickCompiledCode(class_linker_->GetRuntimeQuickGenericJniStub()); 80 } else { 81 const void* code = method->GetEntryPointFromQuickCompiledCode(); 82 if (code == nullptr || class_linker_->IsQuickGenericJniStub(code)) { 83 CompileMethod(method); 84 ASSERT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr) 85 << method_name << " " << method_sig; 86 } 87 } 88 } 89 90 void SetUpForTest(bool direct, const char* method_name, const char* method_sig, 91 void* native_fnptr) { 92 // Initialize class loader and compile method when runtime not started. 93 if (!runtime_->IsStarted()) { 94 { 95 ScopedObjectAccess soa(Thread::Current()); 96 class_loader_ = LoadDex("MyClassNatives"); 97 } 98 CompileForTest(class_loader_, direct, method_name, method_sig); 99 // Start runtime. 100 Thread::Current()->TransitionFromSuspendedToRunnable(); 101 android::InitializeNativeLoader(); 102 bool started = runtime_->Start(); 103 CHECK(started); 104 } 105 // JNI operations after runtime start. 106 env_ = Thread::Current()->GetJniEnv(); 107 library_search_path_ = env_->NewStringUTF(""); 108 jklass_ = env_->FindClass("MyClassNatives"); 109 ASSERT_TRUE(jklass_ != nullptr) << method_name << " " << method_sig; 110 111 if (direct) { 112 jmethod_ = env_->GetStaticMethodID(jklass_, method_name, method_sig); 113 } else { 114 jmethod_ = env_->GetMethodID(jklass_, method_name, method_sig); 115 } 116 ASSERT_TRUE(jmethod_ != nullptr) << method_name << " " << method_sig; 117 118 if (native_fnptr != nullptr) { 119 JNINativeMethod methods[] = { { method_name, method_sig, native_fnptr } }; 120 ASSERT_EQ(JNI_OK, env_->RegisterNatives(jklass_, methods, 1)) 121 << method_name << " " << method_sig; 122 } else { 123 env_->UnregisterNatives(jklass_); 124 } 125 126 jmethodID constructor = env_->GetMethodID(jklass_, "<init>", "()V"); 127 jobj_ = env_->NewObject(jklass_, constructor); 128 ASSERT_TRUE(jobj_ != nullptr) << method_name << " " << method_sig; 129 } 130 131 public: 132 static jclass jklass_; 133 static jobject jobj_; 134 static jobject class_loader_; 135 136 protected: 137 // We have to list the methods here so we can share them between default and generic JNI. 138 void CompileAndRunNoArgMethodImpl(); 139 void CompileAndRunIntMethodThroughStubImpl(); 140 void CompileAndRunStaticIntMethodThroughStubImpl(); 141 void CompileAndRunIntMethodImpl(); 142 void CompileAndRunIntIntMethodImpl(); 143 void CompileAndRunLongLongMethodImpl(); 144 void CompileAndRunDoubleDoubleMethodImpl(); 145 void CompileAndRun_fooJJ_synchronizedImpl(); 146 void CompileAndRunIntObjectObjectMethodImpl(); 147 void CompileAndRunStaticIntIntMethodImpl(); 148 void CompileAndRunStaticDoubleDoubleMethodImpl(); 149 void RunStaticLogDoubleMethodImpl(); 150 void RunStaticLogFloatMethodImpl(); 151 void RunStaticReturnTrueImpl(); 152 void RunStaticReturnFalseImpl(); 153 void RunGenericStaticReturnIntImpl(); 154 void CompileAndRunStaticIntObjectObjectMethodImpl(); 155 void CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl(); 156 void ExceptionHandlingImpl(); 157 void NativeStackTraceElementImpl(); 158 void ReturnGlobalRefImpl(); 159 void LocalReferenceTableClearingTestImpl(); 160 void JavaLangSystemArrayCopyImpl(); 161 void CompareAndSwapIntImpl(); 162 void GetTextImpl(); 163 void GetSinkPropertiesNativeImpl(); 164 void UpcallReturnTypeChecking_InstanceImpl(); 165 void UpcallReturnTypeChecking_StaticImpl(); 166 void UpcallArgumentTypeChecking_InstanceImpl(); 167 void UpcallArgumentTypeChecking_StaticImpl(); 168 void CompileAndRunFloatFloatMethodImpl(); 169 void CheckParameterAlignImpl(); 170 void MaxParamNumberImpl(); 171 void WithoutImplementationImpl(); 172 void WithoutImplementationRefReturnImpl(); 173 void StackArgsIntsFirstImpl(); 174 void StackArgsFloatsFirstImpl(); 175 void StackArgsMixedImpl(); 176 void StackArgsSignExtendedMips64Impl(); 177 178 JNIEnv* env_; 179 jstring library_search_path_; 180 jmethodID jmethod_; 181 bool check_generic_jni_; 182 }; 183 184 jclass JniCompilerTest::jklass_; 185 jobject JniCompilerTest::jobj_; 186 jobject JniCompilerTest::class_loader_; 187 188 #define JNI_TEST(TestName) \ 189 TEST_F(JniCompilerTest, TestName ## Default) { \ 190 TestName ## Impl(); \ 191 } \ 192 \ 193 TEST_F(JniCompilerTest, TestName ## Generic) { \ 194 TEST_DISABLED_FOR_MIPS(); \ 195 SetCheckGenericJni(true); \ 196 TestName ## Impl(); \ 197 } 198 199 int gJava_MyClassNatives_foo_calls = 0; 200 void Java_MyClassNatives_foo(JNIEnv* env, jobject thisObj) { 201 // 1 = thisObj 202 EXPECT_EQ(kNative, Thread::Current()->GetState()); 203 Locks::mutator_lock_->AssertNotHeld(Thread::Current()); 204 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 205 EXPECT_TRUE(thisObj != nullptr); 206 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 207 gJava_MyClassNatives_foo_calls++; 208 ScopedObjectAccess soa(Thread::Current()); 209 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 210 } 211 212 void JniCompilerTest::CompileAndRunNoArgMethodImpl() { 213 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo)); 214 215 EXPECT_EQ(0, gJava_MyClassNatives_foo_calls); 216 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 217 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls); 218 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 219 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls); 220 221 gJava_MyClassNatives_foo_calls = 0; 222 } 223 224 JNI_TEST(CompileAndRunNoArgMethod) 225 226 void JniCompilerTest::CompileAndRunIntMethodThroughStubImpl() { 227 SetUpForTest(false, "bar", "(I)I", nullptr); 228 // calling through stub will link with &Java_MyClassNatives_bar 229 230 std::string reason; 231 ASSERT_TRUE(Runtime::Current()->GetJavaVM()-> 232 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason)) 233 << reason; 234 235 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 24); 236 EXPECT_EQ(25, result); 237 } 238 239 JNI_TEST(CompileAndRunIntMethodThroughStub) 240 241 void JniCompilerTest::CompileAndRunStaticIntMethodThroughStubImpl() { 242 SetUpForTest(true, "sbar", "(I)I", nullptr); 243 // calling through stub will link with &Java_MyClassNatives_sbar 244 245 std::string reason; 246 ASSERT_TRUE(Runtime::Current()->GetJavaVM()-> 247 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason)) 248 << reason; 249 250 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42); 251 EXPECT_EQ(43, result); 252 } 253 254 JNI_TEST(CompileAndRunStaticIntMethodThroughStub) 255 256 int gJava_MyClassNatives_fooI_calls = 0; 257 jint Java_MyClassNatives_fooI(JNIEnv* env, jobject thisObj, jint x) { 258 // 1 = thisObj 259 EXPECT_EQ(kNative, Thread::Current()->GetState()); 260 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 261 EXPECT_TRUE(thisObj != nullptr); 262 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 263 gJava_MyClassNatives_fooI_calls++; 264 ScopedObjectAccess soa(Thread::Current()); 265 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 266 return x; 267 } 268 269 void JniCompilerTest::CompileAndRunIntMethodImpl() { 270 SetUpForTest(false, "fooI", "(I)I", 271 reinterpret_cast<void*>(&Java_MyClassNatives_fooI)); 272 273 EXPECT_EQ(0, gJava_MyClassNatives_fooI_calls); 274 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 42); 275 EXPECT_EQ(42, result); 276 EXPECT_EQ(1, gJava_MyClassNatives_fooI_calls); 277 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFED00D); 278 EXPECT_EQ(static_cast<jint>(0xCAFED00D), result); 279 EXPECT_EQ(2, gJava_MyClassNatives_fooI_calls); 280 281 gJava_MyClassNatives_fooI_calls = 0; 282 } 283 284 JNI_TEST(CompileAndRunIntMethod) 285 286 int gJava_MyClassNatives_fooII_calls = 0; 287 jint Java_MyClassNatives_fooII(JNIEnv* env, jobject thisObj, jint x, jint y) { 288 // 1 = thisObj 289 EXPECT_EQ(kNative, Thread::Current()->GetState()); 290 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 291 EXPECT_TRUE(thisObj != nullptr); 292 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 293 gJava_MyClassNatives_fooII_calls++; 294 ScopedObjectAccess soa(Thread::Current()); 295 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 296 return x - y; // non-commutative operator 297 } 298 299 void JniCompilerTest::CompileAndRunIntIntMethodImpl() { 300 SetUpForTest(false, "fooII", "(II)I", 301 reinterpret_cast<void*>(&Java_MyClassNatives_fooII)); 302 303 EXPECT_EQ(0, gJava_MyClassNatives_fooII_calls); 304 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 99, 10); 305 EXPECT_EQ(99 - 10, result); 306 EXPECT_EQ(1, gJava_MyClassNatives_fooII_calls); 307 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFEBABE, 308 0xCAFED00D); 309 EXPECT_EQ(static_cast<jint>(0xCAFEBABE - 0xCAFED00D), result); 310 EXPECT_EQ(2, gJava_MyClassNatives_fooII_calls); 311 312 gJava_MyClassNatives_fooII_calls = 0; 313 } 314 315 JNI_TEST(CompileAndRunIntIntMethod) 316 317 int gJava_MyClassNatives_fooJJ_calls = 0; 318 jlong Java_MyClassNatives_fooJJ(JNIEnv* env, jobject thisObj, jlong x, jlong y) { 319 // 1 = thisObj 320 EXPECT_EQ(kNative, Thread::Current()->GetState()); 321 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 322 EXPECT_TRUE(thisObj != nullptr); 323 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 324 gJava_MyClassNatives_fooJJ_calls++; 325 ScopedObjectAccess soa(Thread::Current()); 326 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 327 return x - y; // non-commutative operator 328 } 329 330 void JniCompilerTest::CompileAndRunLongLongMethodImpl() { 331 SetUpForTest(false, "fooJJ", "(JJ)J", 332 reinterpret_cast<void*>(&Java_MyClassNatives_fooJJ)); 333 334 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_calls); 335 jlong a = INT64_C(0x1234567890ABCDEF); 336 jlong b = INT64_C(0xFEDCBA0987654321); 337 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b); 338 EXPECT_EQ(a - b, result); 339 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_calls); 340 result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, b, a); 341 EXPECT_EQ(b - a, result); 342 EXPECT_EQ(2, gJava_MyClassNatives_fooJJ_calls); 343 344 gJava_MyClassNatives_fooJJ_calls = 0; 345 } 346 347 JNI_TEST(CompileAndRunLongLongMethod) 348 349 int gJava_MyClassNatives_fooDD_calls = 0; 350 jdouble Java_MyClassNatives_fooDD(JNIEnv* env, jobject thisObj, jdouble x, jdouble y) { 351 // 1 = thisObj 352 EXPECT_EQ(kNative, Thread::Current()->GetState()); 353 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 354 EXPECT_TRUE(thisObj != nullptr); 355 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 356 gJava_MyClassNatives_fooDD_calls++; 357 ScopedObjectAccess soa(Thread::Current()); 358 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 359 return x - y; // non-commutative operator 360 } 361 362 void JniCompilerTest::CompileAndRunDoubleDoubleMethodImpl() { 363 SetUpForTest(false, "fooDD", "(DD)D", 364 reinterpret_cast<void*>(&Java_MyClassNatives_fooDD)); 365 366 EXPECT_EQ(0, gJava_MyClassNatives_fooDD_calls); 367 jdouble result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, 368 99.0, 10.0); 369 EXPECT_DOUBLE_EQ(99.0 - 10.0, result); 370 EXPECT_EQ(1, gJava_MyClassNatives_fooDD_calls); 371 jdouble a = 3.14159265358979323846; 372 jdouble b = 0.69314718055994530942; 373 result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, a, b); 374 EXPECT_DOUBLE_EQ(a - b, result); 375 EXPECT_EQ(2, gJava_MyClassNatives_fooDD_calls); 376 377 gJava_MyClassNatives_fooDD_calls = 0; 378 } 379 380 int gJava_MyClassNatives_fooJJ_synchronized_calls = 0; 381 jlong Java_MyClassNatives_fooJJ_synchronized(JNIEnv* env, jobject thisObj, jlong x, jlong y) { 382 // 1 = thisObj 383 EXPECT_EQ(kNative, Thread::Current()->GetState()); 384 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 385 EXPECT_TRUE(thisObj != nullptr); 386 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 387 gJava_MyClassNatives_fooJJ_synchronized_calls++; 388 ScopedObjectAccess soa(Thread::Current()); 389 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 390 return x | y; 391 } 392 393 void JniCompilerTest::CompileAndRun_fooJJ_synchronizedImpl() { 394 SetUpForTest(false, "fooJJ_synchronized", "(JJ)J", 395 reinterpret_cast<void*>(&Java_MyClassNatives_fooJJ_synchronized)); 396 397 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_synchronized_calls); 398 jlong a = 0x1000000020000000ULL; 399 jlong b = 0x00ff000000aa0000ULL; 400 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b); 401 EXPECT_EQ(a | b, result); 402 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_synchronized_calls); 403 404 gJava_MyClassNatives_fooJJ_synchronized_calls = 0; 405 } 406 407 JNI_TEST(CompileAndRun_fooJJ_synchronized) 408 409 int gJava_MyClassNatives_fooIOO_calls = 0; 410 jobject Java_MyClassNatives_fooIOO(JNIEnv* env, jobject thisObj, jint x, jobject y, 411 jobject z) { 412 // 3 = this + y + z 413 EXPECT_EQ(kNative, Thread::Current()->GetState()); 414 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 415 EXPECT_TRUE(thisObj != nullptr); 416 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 417 gJava_MyClassNatives_fooIOO_calls++; 418 ScopedObjectAccess soa(Thread::Current()); 419 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0); 420 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() || 421 (3U - null_args) == Thread::Current()->NumStackReferences()); 422 switch (x) { 423 case 1: 424 return y; 425 case 2: 426 return z; 427 default: 428 return thisObj; 429 } 430 } 431 432 void JniCompilerTest::CompileAndRunIntObjectObjectMethodImpl() { 433 SetUpForTest(false, "fooIOO", 434 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 435 reinterpret_cast<void*>(&Java_MyClassNatives_fooIOO)); 436 437 EXPECT_EQ(0, gJava_MyClassNatives_fooIOO_calls); 438 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, nullptr); 439 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 440 EXPECT_EQ(1, gJava_MyClassNatives_fooIOO_calls); 441 442 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, jklass_); 443 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 444 EXPECT_EQ(2, gJava_MyClassNatives_fooIOO_calls); 445 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, nullptr, jklass_); 446 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 447 EXPECT_EQ(3, gJava_MyClassNatives_fooIOO_calls); 448 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, nullptr, jklass_); 449 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 450 EXPECT_EQ(4, gJava_MyClassNatives_fooIOO_calls); 451 452 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, jklass_, nullptr); 453 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 454 EXPECT_EQ(5, gJava_MyClassNatives_fooIOO_calls); 455 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, jklass_, nullptr); 456 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 457 EXPECT_EQ(6, gJava_MyClassNatives_fooIOO_calls); 458 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, jklass_, nullptr); 459 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 460 EXPECT_EQ(7, gJava_MyClassNatives_fooIOO_calls); 461 462 gJava_MyClassNatives_fooIOO_calls = 0; 463 } 464 465 JNI_TEST(CompileAndRunIntObjectObjectMethod) 466 467 int gJava_MyClassNatives_fooSII_calls = 0; 468 jint Java_MyClassNatives_fooSII(JNIEnv* env, jclass klass, jint x, jint y) { 469 // 1 = klass 470 EXPECT_EQ(kNative, Thread::Current()->GetState()); 471 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 472 EXPECT_TRUE(klass != nullptr); 473 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 474 gJava_MyClassNatives_fooSII_calls++; 475 ScopedObjectAccess soa(Thread::Current()); 476 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 477 return x + y; 478 } 479 480 void JniCompilerTest::CompileAndRunStaticIntIntMethodImpl() { 481 SetUpForTest(true, "fooSII", "(II)I", 482 reinterpret_cast<void*>(&Java_MyClassNatives_fooSII)); 483 484 EXPECT_EQ(0, gJava_MyClassNatives_fooSII_calls); 485 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 20, 30); 486 EXPECT_EQ(50, result); 487 EXPECT_EQ(1, gJava_MyClassNatives_fooSII_calls); 488 489 gJava_MyClassNatives_fooSII_calls = 0; 490 } 491 492 JNI_TEST(CompileAndRunStaticIntIntMethod) 493 494 int gJava_MyClassNatives_fooSDD_calls = 0; 495 jdouble Java_MyClassNatives_fooSDD(JNIEnv* env, jclass klass, jdouble x, jdouble y) { 496 // 1 = klass 497 EXPECT_EQ(kNative, Thread::Current()->GetState()); 498 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 499 EXPECT_TRUE(klass != nullptr); 500 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 501 gJava_MyClassNatives_fooSDD_calls++; 502 ScopedObjectAccess soa(Thread::Current()); 503 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 504 return x - y; // non-commutative operator 505 } 506 507 void JniCompilerTest::CompileAndRunStaticDoubleDoubleMethodImpl() { 508 SetUpForTest(true, "fooSDD", "(DD)D", 509 reinterpret_cast<void*>(&Java_MyClassNatives_fooSDD)); 510 511 EXPECT_EQ(0, gJava_MyClassNatives_fooSDD_calls); 512 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 99.0, 10.0); 513 EXPECT_DOUBLE_EQ(99.0 - 10.0, result); 514 EXPECT_EQ(1, gJava_MyClassNatives_fooSDD_calls); 515 jdouble a = 3.14159265358979323846; 516 jdouble b = 0.69314718055994530942; 517 result = env_->CallStaticDoubleMethod(jklass_, jmethod_, a, b); 518 EXPECT_DOUBLE_EQ(a - b, result); 519 EXPECT_DOUBLE_EQ(2, gJava_MyClassNatives_fooSDD_calls); 520 521 gJava_MyClassNatives_fooSDD_calls = 0; 522 } 523 524 JNI_TEST(CompileAndRunStaticDoubleDoubleMethod) 525 526 // The x86 generic JNI code had a bug where it assumed a floating 527 // point return value would be in xmm0. We use log, to somehow ensure 528 // the compiler will use the floating point stack. 529 530 jdouble Java_MyClassNatives_logD(JNIEnv*, jclass, jdouble x) { 531 return log(x); 532 } 533 534 void JniCompilerTest::RunStaticLogDoubleMethodImpl() { 535 SetUpForTest(true, "logD", "(D)D", reinterpret_cast<void*>(&Java_MyClassNatives_logD)); 536 537 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 2.0); 538 EXPECT_DOUBLE_EQ(log(2.0), result); 539 } 540 541 JNI_TEST(RunStaticLogDoubleMethod) 542 543 jfloat Java_MyClassNatives_logF(JNIEnv*, jclass, jfloat x) { 544 return logf(x); 545 } 546 547 void JniCompilerTest::RunStaticLogFloatMethodImpl() { 548 SetUpForTest(true, "logF", "(F)F", reinterpret_cast<void*>(&Java_MyClassNatives_logF)); 549 550 jfloat result = env_->CallStaticFloatMethod(jklass_, jmethod_, 2.0); 551 EXPECT_FLOAT_EQ(logf(2.0), result); 552 } 553 554 JNI_TEST(RunStaticLogFloatMethod) 555 556 jboolean Java_MyClassNatives_returnTrue(JNIEnv*, jclass) { 557 return JNI_TRUE; 558 } 559 560 jboolean Java_MyClassNatives_returnFalse(JNIEnv*, jclass) { 561 return JNI_FALSE; 562 } 563 564 jint Java_MyClassNatives_returnInt(JNIEnv*, jclass) { 565 return 42; 566 } 567 568 void JniCompilerTest::RunStaticReturnTrueImpl() { 569 SetUpForTest(true, "returnTrue", "()Z", reinterpret_cast<void*>(&Java_MyClassNatives_returnTrue)); 570 571 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_); 572 EXPECT_TRUE(result); 573 } 574 575 JNI_TEST(RunStaticReturnTrue) 576 577 void JniCompilerTest::RunStaticReturnFalseImpl() { 578 SetUpForTest(true, "returnFalse", "()Z", 579 reinterpret_cast<void*>(&Java_MyClassNatives_returnFalse)); 580 581 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_); 582 EXPECT_FALSE(result); 583 } 584 585 JNI_TEST(RunStaticReturnFalse) 586 587 void JniCompilerTest::RunGenericStaticReturnIntImpl() { 588 SetUpForTest(true, "returnInt", "()I", reinterpret_cast<void*>(&Java_MyClassNatives_returnInt)); 589 590 jint result = env_->CallStaticIntMethod(jklass_, jmethod_); 591 EXPECT_EQ(42, result); 592 } 593 594 JNI_TEST(RunGenericStaticReturnInt) 595 596 int gJava_MyClassNatives_fooSIOO_calls = 0; 597 jobject Java_MyClassNatives_fooSIOO(JNIEnv* env, jclass klass, jint x, jobject y, 598 jobject z) { 599 // 3 = klass + y + z 600 EXPECT_EQ(kNative, Thread::Current()->GetState()); 601 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 602 EXPECT_TRUE(klass != nullptr); 603 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 604 gJava_MyClassNatives_fooSIOO_calls++; 605 ScopedObjectAccess soa(Thread::Current()); 606 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0); 607 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() || 608 (3U - null_args) == Thread::Current()->NumStackReferences()); 609 switch (x) { 610 case 1: 611 return y; 612 case 2: 613 return z; 614 default: 615 return klass; 616 } 617 } 618 619 620 void JniCompilerTest::CompileAndRunStaticIntObjectObjectMethodImpl() { 621 SetUpForTest(true, "fooSIOO", 622 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 623 reinterpret_cast<void*>(&Java_MyClassNatives_fooSIOO)); 624 625 EXPECT_EQ(0, gJava_MyClassNatives_fooSIOO_calls); 626 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr); 627 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 628 EXPECT_EQ(1, gJava_MyClassNatives_fooSIOO_calls); 629 630 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_); 631 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 632 EXPECT_EQ(2, gJava_MyClassNatives_fooSIOO_calls); 633 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_); 634 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 635 EXPECT_EQ(3, gJava_MyClassNatives_fooSIOO_calls); 636 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_); 637 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 638 EXPECT_EQ(4, gJava_MyClassNatives_fooSIOO_calls); 639 640 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr); 641 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 642 EXPECT_EQ(5, gJava_MyClassNatives_fooSIOO_calls); 643 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr); 644 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 645 EXPECT_EQ(6, gJava_MyClassNatives_fooSIOO_calls); 646 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr); 647 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 648 EXPECT_EQ(7, gJava_MyClassNatives_fooSIOO_calls); 649 650 gJava_MyClassNatives_fooSIOO_calls = 0; 651 } 652 653 JNI_TEST(CompileAndRunStaticIntObjectObjectMethod) 654 655 int gJava_MyClassNatives_fooSSIOO_calls = 0; 656 jobject Java_MyClassNatives_fooSSIOO(JNIEnv* env, jclass klass, jint x, jobject y, jobject z) { 657 // 3 = klass + y + z 658 EXPECT_EQ(kNative, Thread::Current()->GetState()); 659 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 660 EXPECT_TRUE(klass != nullptr); 661 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 662 gJava_MyClassNatives_fooSSIOO_calls++; 663 ScopedObjectAccess soa(Thread::Current()); 664 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0); 665 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() || 666 (3U - null_args) == Thread::Current()->NumStackReferences()); 667 switch (x) { 668 case 1: 669 return y; 670 case 2: 671 return z; 672 default: 673 return klass; 674 } 675 } 676 677 void JniCompilerTest::CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl() { 678 SetUpForTest(true, "fooSSIOO", 679 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 680 reinterpret_cast<void*>(&Java_MyClassNatives_fooSSIOO)); 681 682 EXPECT_EQ(0, gJava_MyClassNatives_fooSSIOO_calls); 683 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr); 684 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 685 EXPECT_EQ(1, gJava_MyClassNatives_fooSSIOO_calls); 686 687 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_); 688 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 689 EXPECT_EQ(2, gJava_MyClassNatives_fooSSIOO_calls); 690 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_); 691 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 692 EXPECT_EQ(3, gJava_MyClassNatives_fooSSIOO_calls); 693 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_); 694 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 695 EXPECT_EQ(4, gJava_MyClassNatives_fooSSIOO_calls); 696 697 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr); 698 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 699 EXPECT_EQ(5, gJava_MyClassNatives_fooSSIOO_calls); 700 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr); 701 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 702 EXPECT_EQ(6, gJava_MyClassNatives_fooSSIOO_calls); 703 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr); 704 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 705 EXPECT_EQ(7, gJava_MyClassNatives_fooSSIOO_calls); 706 707 gJava_MyClassNatives_fooSSIOO_calls = 0; 708 } 709 710 JNI_TEST(CompileAndRunStaticSynchronizedIntObjectObjectMethod) 711 712 void Java_MyClassNatives_throwException(JNIEnv* env, jobject) { 713 jclass c = env->FindClass("java/lang/RuntimeException"); 714 env->ThrowNew(c, "hello"); 715 } 716 717 void JniCompilerTest::ExceptionHandlingImpl() { 718 { 719 ASSERT_FALSE(runtime_->IsStarted()); 720 ScopedObjectAccess soa(Thread::Current()); 721 class_loader_ = LoadDex("MyClassNatives"); 722 723 // all compilation needs to happen before Runtime::Start 724 CompileForTest(class_loader_, false, "foo", "()V"); 725 CompileForTest(class_loader_, false, "throwException", "()V"); 726 CompileForTest(class_loader_, false, "foo", "()V"); 727 } 728 // Start runtime to avoid re-initialization in SetupForTest. 729 Thread::Current()->TransitionFromSuspendedToRunnable(); 730 bool started = runtime_->Start(); 731 CHECK(started); 732 733 gJava_MyClassNatives_foo_calls = 0; 734 735 // Check a single call of a JNI method is ok 736 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo)); 737 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 738 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls); 739 EXPECT_FALSE(Thread::Current()->IsExceptionPending()); 740 741 // Get class for exception we expect to be thrown 742 ScopedLocalRef<jclass> jlre(env_, env_->FindClass("java/lang/RuntimeException")); 743 SetUpForTest(false, "throwException", "()V", 744 reinterpret_cast<void*>(&Java_MyClassNatives_throwException)); 745 // Call Java_MyClassNatives_throwException (JNI method that throws exception) 746 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 747 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls); 748 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 749 ScopedLocalRef<jthrowable> exception(env_, env_->ExceptionOccurred()); 750 env_->ExceptionClear(); 751 EXPECT_TRUE(env_->IsInstanceOf(exception.get(), jlre.get())); 752 753 // Check a single call of a JNI method is ok 754 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo)); 755 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 756 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls); 757 758 gJava_MyClassNatives_foo_calls = 0; 759 } 760 761 JNI_TEST(ExceptionHandling) 762 763 jint Java_MyClassNatives_nativeUpCall(JNIEnv* env, jobject thisObj, jint i) { 764 if (i <= 0) { 765 // We want to check raw Object* / Array* below 766 ScopedObjectAccess soa(env); 767 768 // Build stack trace 769 jobject internal = Thread::Current()->CreateInternalStackTrace<false>(soa); 770 jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal); 771 mirror::ObjectArray<mirror::StackTraceElement>* trace_array = 772 soa.Decode<mirror::ObjectArray<mirror::StackTraceElement>*>(ste_array); 773 EXPECT_TRUE(trace_array != nullptr); 774 EXPECT_EQ(11, trace_array->GetLength()); 775 776 // Check stack trace entries have expected values 777 for (int32_t j = 0; j < trace_array->GetLength(); ++j) { 778 EXPECT_EQ(-2, trace_array->Get(j)->GetLineNumber()); 779 mirror::StackTraceElement* ste = trace_array->Get(j); 780 EXPECT_STREQ("MyClassNatives.java", ste->GetFileName()->ToModifiedUtf8().c_str()); 781 EXPECT_STREQ("MyClassNatives", ste->GetDeclaringClass()->ToModifiedUtf8().c_str()); 782 EXPECT_STREQ("fooI", ste->GetMethodName()->ToModifiedUtf8().c_str()); 783 } 784 785 // end recursion 786 return 0; 787 } else { 788 jclass jklass = env->FindClass("MyClassNatives"); 789 EXPECT_TRUE(jklass != nullptr); 790 jmethodID jmethod = env->GetMethodID(jklass, "fooI", "(I)I"); 791 EXPECT_TRUE(jmethod != nullptr); 792 793 // Recurse with i - 1 794 jint result = env->CallNonvirtualIntMethod(thisObj, jklass, jmethod, i - 1); 795 796 // Return sum of all depths 797 return i + result; 798 } 799 } 800 801 void JniCompilerTest::NativeStackTraceElementImpl() { 802 SetUpForTest(false, "fooI", "(I)I", 803 reinterpret_cast<void*>(&Java_MyClassNatives_nativeUpCall)); 804 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 10); 805 EXPECT_EQ(10+9+8+7+6+5+4+3+2+1, result); 806 } 807 808 JNI_TEST(NativeStackTraceElement) 809 810 jobject Java_MyClassNatives_fooO(JNIEnv* env, jobject, jobject x) { 811 return env->NewGlobalRef(x); 812 } 813 814 void JniCompilerTest::ReturnGlobalRefImpl() { 815 SetUpForTest(false, "fooO", "(Ljava/lang/Object;)Ljava/lang/Object;", 816 reinterpret_cast<void*>(&Java_MyClassNatives_fooO)); 817 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, jobj_); 818 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(result)); 819 EXPECT_TRUE(env_->IsSameObject(result, jobj_)); 820 } 821 822 JNI_TEST(ReturnGlobalRef) 823 824 jint local_ref_test(JNIEnv* env, jobject thisObj, jint x) { 825 // Add 10 local references 826 ScopedObjectAccess soa(env); 827 for (int i = 0; i < 10; i++) { 828 soa.AddLocalReference<jobject>(soa.Decode<mirror::Object*>(thisObj)); 829 } 830 return x+1; 831 } 832 833 void JniCompilerTest::LocalReferenceTableClearingTestImpl() { 834 SetUpForTest(false, "fooI", "(I)I", reinterpret_cast<void*>(&local_ref_test)); 835 // 1000 invocations of a method that adds 10 local references 836 for (int i = 0; i < 1000; i++) { 837 jint result = env_->CallIntMethod(jobj_, jmethod_, i); 838 EXPECT_TRUE(result == i + 1); 839 } 840 } 841 842 JNI_TEST(LocalReferenceTableClearingTest) 843 844 void my_arraycopy(JNIEnv* env, jclass klass, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { 845 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, klass)); 846 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, dst)); 847 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, src)); 848 EXPECT_EQ(1234, src_pos); 849 EXPECT_EQ(5678, dst_pos); 850 EXPECT_EQ(9876, length); 851 } 852 853 void JniCompilerTest::JavaLangSystemArrayCopyImpl() { 854 SetUpForTest(true, "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", 855 reinterpret_cast<void*>(&my_arraycopy)); 856 env_->CallStaticVoidMethod(jklass_, jmethod_, jobj_, 1234, jklass_, 5678, 9876); 857 } 858 859 JNI_TEST(JavaLangSystemArrayCopy) 860 861 jboolean my_casi(JNIEnv* env, jobject unsafe, jobject obj, jlong offset, jint expected, jint newval) { 862 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, unsafe)); 863 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj)); 864 EXPECT_EQ(INT64_C(0x12345678ABCDEF88), offset); 865 EXPECT_EQ(static_cast<jint>(0xCAFEF00D), expected); 866 EXPECT_EQ(static_cast<jint>(0xEBADF00D), newval); 867 return JNI_TRUE; 868 } 869 870 void JniCompilerTest::CompareAndSwapIntImpl() { 871 SetUpForTest(false, "compareAndSwapInt", "(Ljava/lang/Object;JII)Z", 872 reinterpret_cast<void*>(&my_casi)); 873 jboolean result = env_->CallBooleanMethod(jobj_, jmethod_, jobj_, INT64_C(0x12345678ABCDEF88), 874 0xCAFEF00D, 0xEBADF00D); 875 EXPECT_EQ(result, JNI_TRUE); 876 } 877 878 JNI_TEST(CompareAndSwapInt) 879 880 jint my_gettext(JNIEnv* env, jclass klass, jlong val1, jobject obj1, jlong val2, jobject obj2) { 881 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 882 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj1)); 883 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj2)); 884 EXPECT_EQ(0x12345678ABCDEF88ll, val1); 885 EXPECT_EQ(0x7FEDCBA987654321ll, val2); 886 return 42; 887 } 888 889 void JniCompilerTest::GetTextImpl() { 890 SetUpForTest(true, "getText", "(JLjava/lang/Object;JLjava/lang/Object;)I", 891 reinterpret_cast<void*>(&my_gettext)); 892 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 0x12345678ABCDEF88ll, jobj_, 893 INT64_C(0x7FEDCBA987654321), jobj_); 894 EXPECT_EQ(result, 42); 895 } 896 897 JNI_TEST(GetText) 898 899 int gJava_MyClassNatives_GetSinkProperties_calls = 0; 900 jarray Java_MyClassNatives_GetSinkProperties(JNIEnv* env, jobject thisObj, jstring s) { 901 // 1 = thisObj 902 Thread* self = Thread::Current(); 903 EXPECT_EQ(kNative, self->GetState()); 904 Locks::mutator_lock_->AssertNotHeld(self); 905 EXPECT_EQ(self->GetJniEnv(), env); 906 EXPECT_TRUE(thisObj != nullptr); 907 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 908 EXPECT_EQ(s, nullptr); 909 gJava_MyClassNatives_GetSinkProperties_calls++; 910 ScopedObjectAccess soa(self); 911 EXPECT_EQ(2U, self->NumStackReferences()); 912 EXPECT_TRUE(self->HoldsLock(soa.Decode<mirror::Object*>(thisObj))); 913 return nullptr; 914 } 915 916 void JniCompilerTest::GetSinkPropertiesNativeImpl() { 917 SetUpForTest(false, "getSinkPropertiesNative", "(Ljava/lang/String;)[Ljava/lang/Object;", 918 reinterpret_cast<void*>(&Java_MyClassNatives_GetSinkProperties)); 919 920 EXPECT_EQ(0, gJava_MyClassNatives_GetSinkProperties_calls); 921 jarray result = down_cast<jarray>( 922 env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, nullptr)); 923 EXPECT_EQ(nullptr, result); 924 EXPECT_EQ(1, gJava_MyClassNatives_GetSinkProperties_calls); 925 926 gJava_MyClassNatives_GetSinkProperties_calls = 0; 927 } 928 929 JNI_TEST(GetSinkPropertiesNative) 930 931 // This should return jclass, but we're imitating a bug pattern. 932 jobject Java_MyClassNatives_instanceMethodThatShouldReturnClass(JNIEnv* env, jobject) { 933 return env->NewStringUTF("not a class!"); 934 } 935 936 // This should return jclass, but we're imitating a bug pattern. 937 jobject Java_MyClassNatives_staticMethodThatShouldReturnClass(JNIEnv* env, jclass) { 938 return env->NewStringUTF("not a class!"); 939 } 940 941 void JniCompilerTest::UpcallReturnTypeChecking_InstanceImpl() { 942 SetUpForTest(false, "instanceMethodThatShouldReturnClass", "()Ljava/lang/Class;", 943 reinterpret_cast<void*>(&Java_MyClassNatives_instanceMethodThatShouldReturnClass)); 944 945 CheckJniAbortCatcher check_jni_abort_catcher; 946 // This native method is bad, and tries to return a jstring as a jclass. 947 env_->CallObjectMethod(jobj_, jmethod_); 948 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass()"); 949 950 // Here, we just call the method incorrectly; we should catch that too. 951 env_->CallObjectMethod(jobj_, jmethod_); 952 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass()"); 953 env_->CallStaticObjectMethod(jklass_, jmethod_); 954 check_jni_abort_catcher.Check("calling non-static method java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass() with CallStaticObjectMethodV"); 955 } 956 957 JNI_TEST(UpcallReturnTypeChecking_Instance) 958 959 void JniCompilerTest::UpcallReturnTypeChecking_StaticImpl() { 960 SetUpForTest(true, "staticMethodThatShouldReturnClass", "()Ljava/lang/Class;", 961 reinterpret_cast<void*>(&Java_MyClassNatives_staticMethodThatShouldReturnClass)); 962 963 CheckJniAbortCatcher check_jni_abort_catcher; 964 // This native method is bad, and tries to return a jstring as a jclass. 965 env_->CallStaticObjectMethod(jklass_, jmethod_); 966 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass()"); 967 968 // Here, we just call the method incorrectly; we should catch that too. 969 env_->CallStaticObjectMethod(jklass_, jmethod_); 970 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass()"); 971 env_->CallObjectMethod(jobj_, jmethod_); 972 check_jni_abort_catcher.Check("calling static method java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass() with CallObjectMethodV"); 973 } 974 975 JNI_TEST(UpcallReturnTypeChecking_Static) 976 977 // This should take jclass, but we're imitating a bug pattern. 978 void Java_MyClassNatives_instanceMethodThatShouldTakeClass(JNIEnv*, jobject, jclass) { 979 } 980 981 // This should take jclass, but we're imitating a bug pattern. 982 void Java_MyClassNatives_staticMethodThatShouldTakeClass(JNIEnv*, jclass, jclass) { 983 } 984 985 void JniCompilerTest::UpcallArgumentTypeChecking_InstanceImpl() { 986 // This will lead to error messages in the log. 987 ScopedLogSeverity sls(LogSeverity::FATAL); 988 989 SetUpForTest(false, "instanceMethodThatShouldTakeClass", "(ILjava/lang/Class;)V", 990 reinterpret_cast<void*>(&Java_MyClassNatives_instanceMethodThatShouldTakeClass)); 991 992 CheckJniAbortCatcher check_jni_abort_catcher; 993 // We deliberately pass a bad second argument here. 994 env_->CallVoidMethod(jobj_, jmethod_, 123, env_->NewStringUTF("not a class!")); 995 check_jni_abort_catcher.Check("bad arguments passed to void MyClassNatives.instanceMethodThatShouldTakeClass(int, java.lang.Class)"); 996 } 997 998 JNI_TEST(UpcallArgumentTypeChecking_Instance) 999 1000 void JniCompilerTest::UpcallArgumentTypeChecking_StaticImpl() { 1001 // This will lead to error messages in the log. 1002 ScopedLogSeverity sls(LogSeverity::FATAL); 1003 1004 SetUpForTest(true, "staticMethodThatShouldTakeClass", "(ILjava/lang/Class;)V", 1005 reinterpret_cast<void*>(&Java_MyClassNatives_staticMethodThatShouldTakeClass)); 1006 1007 CheckJniAbortCatcher check_jni_abort_catcher; 1008 // We deliberately pass a bad second argument here. 1009 env_->CallStaticVoidMethod(jklass_, jmethod_, 123, env_->NewStringUTF("not a class!")); 1010 check_jni_abort_catcher.Check("bad arguments passed to void MyClassNatives.staticMethodThatShouldTakeClass(int, java.lang.Class)"); 1011 } 1012 1013 JNI_TEST(UpcallArgumentTypeChecking_Static) 1014 1015 jfloat Java_MyClassNatives_checkFloats(JNIEnv* env, jobject thisObj, jfloat f1, jfloat f2) { 1016 EXPECT_EQ(kNative, Thread::Current()->GetState()); 1017 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 1018 EXPECT_TRUE(thisObj != nullptr); 1019 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 1020 ScopedObjectAccess soa(Thread::Current()); 1021 EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 1022 return f1 - f2; // non-commutative operator 1023 } 1024 1025 void JniCompilerTest::CompileAndRunFloatFloatMethodImpl() { 1026 SetUpForTest(false, "checkFloats", "(FF)F", 1027 reinterpret_cast<void*>(&Java_MyClassNatives_checkFloats)); 1028 1029 jfloat result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, 1030 99.0F, 10.0F); 1031 EXPECT_FLOAT_EQ(99.0F - 10.0F, result); 1032 jfloat a = 3.14159F; 1033 jfloat b = 0.69314F; 1034 result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, a, b); 1035 EXPECT_FLOAT_EQ(a - b, result); 1036 } 1037 1038 JNI_TEST(CompileAndRunFloatFloatMethod) 1039 1040 void Java_MyClassNatives_checkParameterAlign(JNIEnv* env ATTRIBUTE_UNUSED, 1041 jobject thisObj ATTRIBUTE_UNUSED, 1042 jint i1 ATTRIBUTE_UNUSED, 1043 jlong l1 ATTRIBUTE_UNUSED) { 1044 // EXPECT_EQ(kNative, Thread::Current()->GetState()); 1045 // EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 1046 // EXPECT_TRUE(thisObj != nullptr); 1047 // EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 1048 // ScopedObjectAccess soa(Thread::Current()); 1049 // EXPECT_EQ(1U, Thread::Current()->NumStackReferences()); 1050 EXPECT_EQ(i1, 1234); 1051 EXPECT_EQ(l1, INT64_C(0x12345678ABCDEF0)); 1052 } 1053 1054 void JniCompilerTest::CheckParameterAlignImpl() { 1055 SetUpForTest(false, "checkParameterAlign", "(IJ)V", 1056 reinterpret_cast<void*>(&Java_MyClassNatives_checkParameterAlign)); 1057 1058 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_, 1234, INT64_C(0x12345678ABCDEF0)); 1059 } 1060 1061 JNI_TEST(CheckParameterAlign) 1062 1063 void Java_MyClassNatives_maxParamNumber(JNIEnv* env, jobject thisObj, 1064 jobject o0, jobject o1, jobject o2, jobject o3, jobject o4, jobject o5, jobject o6, jobject o7, 1065 jobject o8, jobject o9, jobject o10, jobject o11, jobject o12, jobject o13, jobject o14, jobject o15, 1066 jobject o16, jobject o17, jobject o18, jobject o19, jobject o20, jobject o21, jobject o22, jobject o23, 1067 jobject o24, jobject o25, jobject o26, jobject o27, jobject o28, jobject o29, jobject o30, jobject o31, 1068 jobject o32, jobject o33, jobject o34, jobject o35, jobject o36, jobject o37, jobject o38, jobject o39, 1069 jobject o40, jobject o41, jobject o42, jobject o43, jobject o44, jobject o45, jobject o46, jobject o47, 1070 jobject o48, jobject o49, jobject o50, jobject o51, jobject o52, jobject o53, jobject o54, jobject o55, 1071 jobject o56, jobject o57, jobject o58, jobject o59, jobject o60, jobject o61, jobject o62, jobject o63, 1072 jobject o64, jobject o65, jobject o66, jobject o67, jobject o68, jobject o69, jobject o70, jobject o71, 1073 jobject o72, jobject o73, jobject o74, jobject o75, jobject o76, jobject o77, jobject o78, jobject o79, 1074 jobject o80, jobject o81, jobject o82, jobject o83, jobject o84, jobject o85, jobject o86, jobject o87, 1075 jobject o88, jobject o89, jobject o90, jobject o91, jobject o92, jobject o93, jobject o94, jobject o95, 1076 jobject o96, jobject o97, jobject o98, jobject o99, jobject o100, jobject o101, jobject o102, jobject o103, 1077 jobject o104, jobject o105, jobject o106, jobject o107, jobject o108, jobject o109, jobject o110, jobject o111, 1078 jobject o112, jobject o113, jobject o114, jobject o115, jobject o116, jobject o117, jobject o118, jobject o119, 1079 jobject o120, jobject o121, jobject o122, jobject o123, jobject o124, jobject o125, jobject o126, jobject o127, 1080 jobject o128, jobject o129, jobject o130, jobject o131, jobject o132, jobject o133, jobject o134, jobject o135, 1081 jobject o136, jobject o137, jobject o138, jobject o139, jobject o140, jobject o141, jobject o142, jobject o143, 1082 jobject o144, jobject o145, jobject o146, jobject o147, jobject o148, jobject o149, jobject o150, jobject o151, 1083 jobject o152, jobject o153, jobject o154, jobject o155, jobject o156, jobject o157, jobject o158, jobject o159, 1084 jobject o160, jobject o161, jobject o162, jobject o163, jobject o164, jobject o165, jobject o166, jobject o167, 1085 jobject o168, jobject o169, jobject o170, jobject o171, jobject o172, jobject o173, jobject o174, jobject o175, 1086 jobject o176, jobject o177, jobject o178, jobject o179, jobject o180, jobject o181, jobject o182, jobject o183, 1087 jobject o184, jobject o185, jobject o186, jobject o187, jobject o188, jobject o189, jobject o190, jobject o191, 1088 jobject o192, jobject o193, jobject o194, jobject o195, jobject o196, jobject o197, jobject o198, jobject o199, 1089 jobject o200, jobject o201, jobject o202, jobject o203, jobject o204, jobject o205, jobject o206, jobject o207, 1090 jobject o208, jobject o209, jobject o210, jobject o211, jobject o212, jobject o213, jobject o214, jobject o215, 1091 jobject o216, jobject o217, jobject o218, jobject o219, jobject o220, jobject o221, jobject o222, jobject o223, 1092 jobject o224, jobject o225, jobject o226, jobject o227, jobject o228, jobject o229, jobject o230, jobject o231, 1093 jobject o232, jobject o233, jobject o234, jobject o235, jobject o236, jobject o237, jobject o238, jobject o239, 1094 jobject o240, jobject o241, jobject o242, jobject o243, jobject o244, jobject o245, jobject o246, jobject o247, 1095 jobject o248, jobject o249, jobject o250, jobject o251, jobject o252, jobject o253) { 1096 EXPECT_EQ(kNative, Thread::Current()->GetState()); 1097 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 1098 EXPECT_TRUE(thisObj != nullptr); 1099 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 1100 ScopedObjectAccess soa(Thread::Current()); 1101 EXPECT_GE(255U, Thread::Current()->NumStackReferences()); 1102 1103 // two tests possible 1104 if (o0 == nullptr) { 1105 // 1) everything is null 1106 EXPECT_TRUE(o0 == nullptr && o1 == nullptr && o2 == nullptr && o3 == nullptr && o4 == nullptr 1107 && o5 == nullptr && o6 == nullptr && o7 == nullptr && o8 == nullptr && o9 == nullptr 1108 && o10 == nullptr && o11 == nullptr && o12 == nullptr && o13 == nullptr && o14 == nullptr 1109 && o15 == nullptr && o16 == nullptr && o17 == nullptr && o18 == nullptr && o19 == nullptr 1110 && o20 == nullptr && o21 == nullptr && o22 == nullptr && o23 == nullptr && o24 == nullptr 1111 && o25 == nullptr && o26 == nullptr && o27 == nullptr && o28 == nullptr && o29 == nullptr 1112 && o30 == nullptr && o31 == nullptr && o32 == nullptr && o33 == nullptr && o34 == nullptr 1113 && o35 == nullptr && o36 == nullptr && o37 == nullptr && o38 == nullptr && o39 == nullptr 1114 && o40 == nullptr && o41 == nullptr && o42 == nullptr && o43 == nullptr && o44 == nullptr 1115 && o45 == nullptr && o46 == nullptr && o47 == nullptr && o48 == nullptr && o49 == nullptr 1116 && o50 == nullptr && o51 == nullptr && o52 == nullptr && o53 == nullptr && o54 == nullptr 1117 && o55 == nullptr && o56 == nullptr && o57 == nullptr && o58 == nullptr && o59 == nullptr 1118 && o60 == nullptr && o61 == nullptr && o62 == nullptr && o63 == nullptr && o64 == nullptr 1119 && o65 == nullptr && o66 == nullptr && o67 == nullptr && o68 == nullptr && o69 == nullptr 1120 && o70 == nullptr && o71 == nullptr && o72 == nullptr && o73 == nullptr && o74 == nullptr 1121 && o75 == nullptr && o76 == nullptr && o77 == nullptr && o78 == nullptr && o79 == nullptr 1122 && o80 == nullptr && o81 == nullptr && o82 == nullptr && o83 == nullptr && o84 == nullptr 1123 && o85 == nullptr && o86 == nullptr && o87 == nullptr && o88 == nullptr && o89 == nullptr 1124 && o90 == nullptr && o91 == nullptr && o92 == nullptr && o93 == nullptr && o94 == nullptr 1125 && o95 == nullptr && o96 == nullptr && o97 == nullptr && o98 == nullptr && o99 == nullptr 1126 && o100 == nullptr && o101 == nullptr && o102 == nullptr && o103 == nullptr && o104 == nullptr 1127 && o105 == nullptr && o106 == nullptr && o107 == nullptr && o108 == nullptr && o109 == nullptr 1128 && o110 == nullptr && o111 == nullptr && o112 == nullptr && o113 == nullptr && o114 == nullptr 1129 && o115 == nullptr && o116 == nullptr && o117 == nullptr && o118 == nullptr && o119 == nullptr 1130 && o120 == nullptr && o121 == nullptr && o122 == nullptr && o123 == nullptr && o124 == nullptr 1131 && o125 == nullptr && o126 == nullptr && o127 == nullptr && o128 == nullptr && o129 == nullptr 1132 && o130 == nullptr && o131 == nullptr && o132 == nullptr && o133 == nullptr && o134 == nullptr 1133 && o135 == nullptr && o136 == nullptr && o137 == nullptr && o138 == nullptr && o139 == nullptr 1134 && o140 == nullptr && o141 == nullptr && o142 == nullptr && o143 == nullptr && o144 == nullptr 1135 && o145 == nullptr && o146 == nullptr && o147 == nullptr && o148 == nullptr && o149 == nullptr 1136 && o150 == nullptr && o151 == nullptr && o152 == nullptr && o153 == nullptr && o154 == nullptr 1137 && o155 == nullptr && o156 == nullptr && o157 == nullptr && o158 == nullptr && o159 == nullptr 1138 && o160 == nullptr && o161 == nullptr && o162 == nullptr && o163 == nullptr && o164 == nullptr 1139 && o165 == nullptr && o166 == nullptr && o167 == nullptr && o168 == nullptr && o169 == nullptr 1140 && o170 == nullptr && o171 == nullptr && o172 == nullptr && o173 == nullptr && o174 == nullptr 1141 && o175 == nullptr && o176 == nullptr && o177 == nullptr && o178 == nullptr && o179 == nullptr 1142 && o180 == nullptr && o181 == nullptr && o182 == nullptr && o183 == nullptr && o184 == nullptr 1143 && o185 == nullptr && o186 == nullptr && o187 == nullptr && o188 == nullptr && o189 == nullptr 1144 && o190 == nullptr && o191 == nullptr && o192 == nullptr && o193 == nullptr && o194 == nullptr 1145 && o195 == nullptr && o196 == nullptr && o197 == nullptr && o198 == nullptr && o199 == nullptr 1146 && o200 == nullptr && o201 == nullptr && o202 == nullptr && o203 == nullptr && o204 == nullptr 1147 && o205 == nullptr && o206 == nullptr && o207 == nullptr && o208 == nullptr && o209 == nullptr 1148 && o210 == nullptr && o211 == nullptr && o212 == nullptr && o213 == nullptr && o214 == nullptr 1149 && o215 == nullptr && o216 == nullptr && o217 == nullptr && o218 == nullptr && o219 == nullptr 1150 && o220 == nullptr && o221 == nullptr && o222 == nullptr && o223 == nullptr && o224 == nullptr 1151 && o225 == nullptr && o226 == nullptr && o227 == nullptr && o228 == nullptr && o229 == nullptr 1152 && o230 == nullptr && o231 == nullptr && o232 == nullptr && o233 == nullptr && o234 == nullptr 1153 && o235 == nullptr && o236 == nullptr && o237 == nullptr && o238 == nullptr && o239 == nullptr 1154 && o240 == nullptr && o241 == nullptr && o242 == nullptr && o243 == nullptr && o244 == nullptr 1155 && o245 == nullptr && o246 == nullptr && o247 == nullptr && o248 == nullptr && o249 == nullptr 1156 && o250 == nullptr && o251 == nullptr && o252 == nullptr && o253 == nullptr); 1157 } else { 1158 EXPECT_EQ(0, env->GetArrayLength(reinterpret_cast<jarray>(o0))); 1159 EXPECT_EQ(1, env->GetArrayLength(reinterpret_cast<jarray>(o1))); 1160 EXPECT_EQ(2, env->GetArrayLength(reinterpret_cast<jarray>(o2))); 1161 EXPECT_EQ(3, env->GetArrayLength(reinterpret_cast<jarray>(o3))); 1162 EXPECT_EQ(4, env->GetArrayLength(reinterpret_cast<jarray>(o4))); 1163 EXPECT_EQ(5, env->GetArrayLength(reinterpret_cast<jarray>(o5))); 1164 EXPECT_EQ(6, env->GetArrayLength(reinterpret_cast<jarray>(o6))); 1165 EXPECT_EQ(7, env->GetArrayLength(reinterpret_cast<jarray>(o7))); 1166 EXPECT_EQ(8, env->GetArrayLength(reinterpret_cast<jarray>(o8))); 1167 EXPECT_EQ(9, env->GetArrayLength(reinterpret_cast<jarray>(o9))); 1168 EXPECT_EQ(10, env->GetArrayLength(reinterpret_cast<jarray>(o10))); 1169 EXPECT_EQ(11, env->GetArrayLength(reinterpret_cast<jarray>(o11))); 1170 EXPECT_EQ(12, env->GetArrayLength(reinterpret_cast<jarray>(o12))); 1171 EXPECT_EQ(13, env->GetArrayLength(reinterpret_cast<jarray>(o13))); 1172 EXPECT_EQ(14, env->GetArrayLength(reinterpret_cast<jarray>(o14))); 1173 EXPECT_EQ(15, env->GetArrayLength(reinterpret_cast<jarray>(o15))); 1174 EXPECT_EQ(16, env->GetArrayLength(reinterpret_cast<jarray>(o16))); 1175 EXPECT_EQ(17, env->GetArrayLength(reinterpret_cast<jarray>(o17))); 1176 EXPECT_EQ(18, env->GetArrayLength(reinterpret_cast<jarray>(o18))); 1177 EXPECT_EQ(19, env->GetArrayLength(reinterpret_cast<jarray>(o19))); 1178 EXPECT_EQ(20, env->GetArrayLength(reinterpret_cast<jarray>(o20))); 1179 EXPECT_EQ(21, env->GetArrayLength(reinterpret_cast<jarray>(o21))); 1180 EXPECT_EQ(22, env->GetArrayLength(reinterpret_cast<jarray>(o22))); 1181 EXPECT_EQ(23, env->GetArrayLength(reinterpret_cast<jarray>(o23))); 1182 EXPECT_EQ(24, env->GetArrayLength(reinterpret_cast<jarray>(o24))); 1183 EXPECT_EQ(25, env->GetArrayLength(reinterpret_cast<jarray>(o25))); 1184 EXPECT_EQ(26, env->GetArrayLength(reinterpret_cast<jarray>(o26))); 1185 EXPECT_EQ(27, env->GetArrayLength(reinterpret_cast<jarray>(o27))); 1186 EXPECT_EQ(28, env->GetArrayLength(reinterpret_cast<jarray>(o28))); 1187 EXPECT_EQ(29, env->GetArrayLength(reinterpret_cast<jarray>(o29))); 1188 EXPECT_EQ(30, env->GetArrayLength(reinterpret_cast<jarray>(o30))); 1189 EXPECT_EQ(31, env->GetArrayLength(reinterpret_cast<jarray>(o31))); 1190 EXPECT_EQ(32, env->GetArrayLength(reinterpret_cast<jarray>(o32))); 1191 EXPECT_EQ(33, env->GetArrayLength(reinterpret_cast<jarray>(o33))); 1192 EXPECT_EQ(34, env->GetArrayLength(reinterpret_cast<jarray>(o34))); 1193 EXPECT_EQ(35, env->GetArrayLength(reinterpret_cast<jarray>(o35))); 1194 EXPECT_EQ(36, env->GetArrayLength(reinterpret_cast<jarray>(o36))); 1195 EXPECT_EQ(37, env->GetArrayLength(reinterpret_cast<jarray>(o37))); 1196 EXPECT_EQ(38, env->GetArrayLength(reinterpret_cast<jarray>(o38))); 1197 EXPECT_EQ(39, env->GetArrayLength(reinterpret_cast<jarray>(o39))); 1198 EXPECT_EQ(40, env->GetArrayLength(reinterpret_cast<jarray>(o40))); 1199 EXPECT_EQ(41, env->GetArrayLength(reinterpret_cast<jarray>(o41))); 1200 EXPECT_EQ(42, env->GetArrayLength(reinterpret_cast<jarray>(o42))); 1201 EXPECT_EQ(43, env->GetArrayLength(reinterpret_cast<jarray>(o43))); 1202 EXPECT_EQ(44, env->GetArrayLength(reinterpret_cast<jarray>(o44))); 1203 EXPECT_EQ(45, env->GetArrayLength(reinterpret_cast<jarray>(o45))); 1204 EXPECT_EQ(46, env->GetArrayLength(reinterpret_cast<jarray>(o46))); 1205 EXPECT_EQ(47, env->GetArrayLength(reinterpret_cast<jarray>(o47))); 1206 EXPECT_EQ(48, env->GetArrayLength(reinterpret_cast<jarray>(o48))); 1207 EXPECT_EQ(49, env->GetArrayLength(reinterpret_cast<jarray>(o49))); 1208 EXPECT_EQ(50, env->GetArrayLength(reinterpret_cast<jarray>(o50))); 1209 EXPECT_EQ(51, env->GetArrayLength(reinterpret_cast<jarray>(o51))); 1210 EXPECT_EQ(52, env->GetArrayLength(reinterpret_cast<jarray>(o52))); 1211 EXPECT_EQ(53, env->GetArrayLength(reinterpret_cast<jarray>(o53))); 1212 EXPECT_EQ(54, env->GetArrayLength(reinterpret_cast<jarray>(o54))); 1213 EXPECT_EQ(55, env->GetArrayLength(reinterpret_cast<jarray>(o55))); 1214 EXPECT_EQ(56, env->GetArrayLength(reinterpret_cast<jarray>(o56))); 1215 EXPECT_EQ(57, env->GetArrayLength(reinterpret_cast<jarray>(o57))); 1216 EXPECT_EQ(58, env->GetArrayLength(reinterpret_cast<jarray>(o58))); 1217 EXPECT_EQ(59, env->GetArrayLength(reinterpret_cast<jarray>(o59))); 1218 EXPECT_EQ(60, env->GetArrayLength(reinterpret_cast<jarray>(o60))); 1219 EXPECT_EQ(61, env->GetArrayLength(reinterpret_cast<jarray>(o61))); 1220 EXPECT_EQ(62, env->GetArrayLength(reinterpret_cast<jarray>(o62))); 1221 EXPECT_EQ(63, env->GetArrayLength(reinterpret_cast<jarray>(o63))); 1222 EXPECT_EQ(64, env->GetArrayLength(reinterpret_cast<jarray>(o64))); 1223 EXPECT_EQ(65, env->GetArrayLength(reinterpret_cast<jarray>(o65))); 1224 EXPECT_EQ(66, env->GetArrayLength(reinterpret_cast<jarray>(o66))); 1225 EXPECT_EQ(67, env->GetArrayLength(reinterpret_cast<jarray>(o67))); 1226 EXPECT_EQ(68, env->GetArrayLength(reinterpret_cast<jarray>(o68))); 1227 EXPECT_EQ(69, env->GetArrayLength(reinterpret_cast<jarray>(o69))); 1228 EXPECT_EQ(70, env->GetArrayLength(reinterpret_cast<jarray>(o70))); 1229 EXPECT_EQ(71, env->GetArrayLength(reinterpret_cast<jarray>(o71))); 1230 EXPECT_EQ(72, env->GetArrayLength(reinterpret_cast<jarray>(o72))); 1231 EXPECT_EQ(73, env->GetArrayLength(reinterpret_cast<jarray>(o73))); 1232 EXPECT_EQ(74, env->GetArrayLength(reinterpret_cast<jarray>(o74))); 1233 EXPECT_EQ(75, env->GetArrayLength(reinterpret_cast<jarray>(o75))); 1234 EXPECT_EQ(76, env->GetArrayLength(reinterpret_cast<jarray>(o76))); 1235 EXPECT_EQ(77, env->GetArrayLength(reinterpret_cast<jarray>(o77))); 1236 EXPECT_EQ(78, env->GetArrayLength(reinterpret_cast<jarray>(o78))); 1237 EXPECT_EQ(79, env->GetArrayLength(reinterpret_cast<jarray>(o79))); 1238 EXPECT_EQ(80, env->GetArrayLength(reinterpret_cast<jarray>(o80))); 1239 EXPECT_EQ(81, env->GetArrayLength(reinterpret_cast<jarray>(o81))); 1240 EXPECT_EQ(82, env->GetArrayLength(reinterpret_cast<jarray>(o82))); 1241 EXPECT_EQ(83, env->GetArrayLength(reinterpret_cast<jarray>(o83))); 1242 EXPECT_EQ(84, env->GetArrayLength(reinterpret_cast<jarray>(o84))); 1243 EXPECT_EQ(85, env->GetArrayLength(reinterpret_cast<jarray>(o85))); 1244 EXPECT_EQ(86, env->GetArrayLength(reinterpret_cast<jarray>(o86))); 1245 EXPECT_EQ(87, env->GetArrayLength(reinterpret_cast<jarray>(o87))); 1246 EXPECT_EQ(88, env->GetArrayLength(reinterpret_cast<jarray>(o88))); 1247 EXPECT_EQ(89, env->GetArrayLength(reinterpret_cast<jarray>(o89))); 1248 EXPECT_EQ(90, env->GetArrayLength(reinterpret_cast<jarray>(o90))); 1249 EXPECT_EQ(91, env->GetArrayLength(reinterpret_cast<jarray>(o91))); 1250 EXPECT_EQ(92, env->GetArrayLength(reinterpret_cast<jarray>(o92))); 1251 EXPECT_EQ(93, env->GetArrayLength(reinterpret_cast<jarray>(o93))); 1252 EXPECT_EQ(94, env->GetArrayLength(reinterpret_cast<jarray>(o94))); 1253 EXPECT_EQ(95, env->GetArrayLength(reinterpret_cast<jarray>(o95))); 1254 EXPECT_EQ(96, env->GetArrayLength(reinterpret_cast<jarray>(o96))); 1255 EXPECT_EQ(97, env->GetArrayLength(reinterpret_cast<jarray>(o97))); 1256 EXPECT_EQ(98, env->GetArrayLength(reinterpret_cast<jarray>(o98))); 1257 EXPECT_EQ(99, env->GetArrayLength(reinterpret_cast<jarray>(o99))); 1258 EXPECT_EQ(100, env->GetArrayLength(reinterpret_cast<jarray>(o100))); 1259 EXPECT_EQ(101, env->GetArrayLength(reinterpret_cast<jarray>(o101))); 1260 EXPECT_EQ(102, env->GetArrayLength(reinterpret_cast<jarray>(o102))); 1261 EXPECT_EQ(103, env->GetArrayLength(reinterpret_cast<jarray>(o103))); 1262 EXPECT_EQ(104, env->GetArrayLength(reinterpret_cast<jarray>(o104))); 1263 EXPECT_EQ(105, env->GetArrayLength(reinterpret_cast<jarray>(o105))); 1264 EXPECT_EQ(106, env->GetArrayLength(reinterpret_cast<jarray>(o106))); 1265 EXPECT_EQ(107, env->GetArrayLength(reinterpret_cast<jarray>(o107))); 1266 EXPECT_EQ(108, env->GetArrayLength(reinterpret_cast<jarray>(o108))); 1267 EXPECT_EQ(109, env->GetArrayLength(reinterpret_cast<jarray>(o109))); 1268 EXPECT_EQ(110, env->GetArrayLength(reinterpret_cast<jarray>(o110))); 1269 EXPECT_EQ(111, env->GetArrayLength(reinterpret_cast<jarray>(o111))); 1270 EXPECT_EQ(112, env->GetArrayLength(reinterpret_cast<jarray>(o112))); 1271 EXPECT_EQ(113, env->GetArrayLength(reinterpret_cast<jarray>(o113))); 1272 EXPECT_EQ(114, env->GetArrayLength(reinterpret_cast<jarray>(o114))); 1273 EXPECT_EQ(115, env->GetArrayLength(reinterpret_cast<jarray>(o115))); 1274 EXPECT_EQ(116, env->GetArrayLength(reinterpret_cast<jarray>(o116))); 1275 EXPECT_EQ(117, env->GetArrayLength(reinterpret_cast<jarray>(o117))); 1276 EXPECT_EQ(118, env->GetArrayLength(reinterpret_cast<jarray>(o118))); 1277 EXPECT_EQ(119, env->GetArrayLength(reinterpret_cast<jarray>(o119))); 1278 EXPECT_EQ(120, env->GetArrayLength(reinterpret_cast<jarray>(o120))); 1279 EXPECT_EQ(121, env->GetArrayLength(reinterpret_cast<jarray>(o121))); 1280 EXPECT_EQ(122, env->GetArrayLength(reinterpret_cast<jarray>(o122))); 1281 EXPECT_EQ(123, env->GetArrayLength(reinterpret_cast<jarray>(o123))); 1282 EXPECT_EQ(124, env->GetArrayLength(reinterpret_cast<jarray>(o124))); 1283 EXPECT_EQ(125, env->GetArrayLength(reinterpret_cast<jarray>(o125))); 1284 EXPECT_EQ(126, env->GetArrayLength(reinterpret_cast<jarray>(o126))); 1285 EXPECT_EQ(127, env->GetArrayLength(reinterpret_cast<jarray>(o127))); 1286 EXPECT_EQ(128, env->GetArrayLength(reinterpret_cast<jarray>(o128))); 1287 EXPECT_EQ(129, env->GetArrayLength(reinterpret_cast<jarray>(o129))); 1288 EXPECT_EQ(130, env->GetArrayLength(reinterpret_cast<jarray>(o130))); 1289 EXPECT_EQ(131, env->GetArrayLength(reinterpret_cast<jarray>(o131))); 1290 EXPECT_EQ(132, env->GetArrayLength(reinterpret_cast<jarray>(o132))); 1291 EXPECT_EQ(133, env->GetArrayLength(reinterpret_cast<jarray>(o133))); 1292 EXPECT_EQ(134, env->GetArrayLength(reinterpret_cast<jarray>(o134))); 1293 EXPECT_EQ(135, env->GetArrayLength(reinterpret_cast<jarray>(o135))); 1294 EXPECT_EQ(136, env->GetArrayLength(reinterpret_cast<jarray>(o136))); 1295 EXPECT_EQ(137, env->GetArrayLength(reinterpret_cast<jarray>(o137))); 1296 EXPECT_EQ(138, env->GetArrayLength(reinterpret_cast<jarray>(o138))); 1297 EXPECT_EQ(139, env->GetArrayLength(reinterpret_cast<jarray>(o139))); 1298 EXPECT_EQ(140, env->GetArrayLength(reinterpret_cast<jarray>(o140))); 1299 EXPECT_EQ(141, env->GetArrayLength(reinterpret_cast<jarray>(o141))); 1300 EXPECT_EQ(142, env->GetArrayLength(reinterpret_cast<jarray>(o142))); 1301 EXPECT_EQ(143, env->GetArrayLength(reinterpret_cast<jarray>(o143))); 1302 EXPECT_EQ(144, env->GetArrayLength(reinterpret_cast<jarray>(o144))); 1303 EXPECT_EQ(145, env->GetArrayLength(reinterpret_cast<jarray>(o145))); 1304 EXPECT_EQ(146, env->GetArrayLength(reinterpret_cast<jarray>(o146))); 1305 EXPECT_EQ(147, env->GetArrayLength(reinterpret_cast<jarray>(o147))); 1306 EXPECT_EQ(148, env->GetArrayLength(reinterpret_cast<jarray>(o148))); 1307 EXPECT_EQ(149, env->GetArrayLength(reinterpret_cast<jarray>(o149))); 1308 EXPECT_EQ(150, env->GetArrayLength(reinterpret_cast<jarray>(o150))); 1309 EXPECT_EQ(151, env->GetArrayLength(reinterpret_cast<jarray>(o151))); 1310 EXPECT_EQ(152, env->GetArrayLength(reinterpret_cast<jarray>(o152))); 1311 EXPECT_EQ(153, env->GetArrayLength(reinterpret_cast<jarray>(o153))); 1312 EXPECT_EQ(154, env->GetArrayLength(reinterpret_cast<jarray>(o154))); 1313 EXPECT_EQ(155, env->GetArrayLength(reinterpret_cast<jarray>(o155))); 1314 EXPECT_EQ(156, env->GetArrayLength(reinterpret_cast<jarray>(o156))); 1315 EXPECT_EQ(157, env->GetArrayLength(reinterpret_cast<jarray>(o157))); 1316 EXPECT_EQ(158, env->GetArrayLength(reinterpret_cast<jarray>(o158))); 1317 EXPECT_EQ(159, env->GetArrayLength(reinterpret_cast<jarray>(o159))); 1318 EXPECT_EQ(160, env->GetArrayLength(reinterpret_cast<jarray>(o160))); 1319 EXPECT_EQ(161, env->GetArrayLength(reinterpret_cast<jarray>(o161))); 1320 EXPECT_EQ(162, env->GetArrayLength(reinterpret_cast<jarray>(o162))); 1321 EXPECT_EQ(163, env->GetArrayLength(reinterpret_cast<jarray>(o163))); 1322 EXPECT_EQ(164, env->GetArrayLength(reinterpret_cast<jarray>(o164))); 1323 EXPECT_EQ(165, env->GetArrayLength(reinterpret_cast<jarray>(o165))); 1324 EXPECT_EQ(166, env->GetArrayLength(reinterpret_cast<jarray>(o166))); 1325 EXPECT_EQ(167, env->GetArrayLength(reinterpret_cast<jarray>(o167))); 1326 EXPECT_EQ(168, env->GetArrayLength(reinterpret_cast<jarray>(o168))); 1327 EXPECT_EQ(169, env->GetArrayLength(reinterpret_cast<jarray>(o169))); 1328 EXPECT_EQ(170, env->GetArrayLength(reinterpret_cast<jarray>(o170))); 1329 EXPECT_EQ(171, env->GetArrayLength(reinterpret_cast<jarray>(o171))); 1330 EXPECT_EQ(172, env->GetArrayLength(reinterpret_cast<jarray>(o172))); 1331 EXPECT_EQ(173, env->GetArrayLength(reinterpret_cast<jarray>(o173))); 1332 EXPECT_EQ(174, env->GetArrayLength(reinterpret_cast<jarray>(o174))); 1333 EXPECT_EQ(175, env->GetArrayLength(reinterpret_cast<jarray>(o175))); 1334 EXPECT_EQ(176, env->GetArrayLength(reinterpret_cast<jarray>(o176))); 1335 EXPECT_EQ(177, env->GetArrayLength(reinterpret_cast<jarray>(o177))); 1336 EXPECT_EQ(178, env->GetArrayLength(reinterpret_cast<jarray>(o178))); 1337 EXPECT_EQ(179, env->GetArrayLength(reinterpret_cast<jarray>(o179))); 1338 EXPECT_EQ(180, env->GetArrayLength(reinterpret_cast<jarray>(o180))); 1339 EXPECT_EQ(181, env->GetArrayLength(reinterpret_cast<jarray>(o181))); 1340 EXPECT_EQ(182, env->GetArrayLength(reinterpret_cast<jarray>(o182))); 1341 EXPECT_EQ(183, env->GetArrayLength(reinterpret_cast<jarray>(o183))); 1342 EXPECT_EQ(184, env->GetArrayLength(reinterpret_cast<jarray>(o184))); 1343 EXPECT_EQ(185, env->GetArrayLength(reinterpret_cast<jarray>(o185))); 1344 EXPECT_EQ(186, env->GetArrayLength(reinterpret_cast<jarray>(o186))); 1345 EXPECT_EQ(187, env->GetArrayLength(reinterpret_cast<jarray>(o187))); 1346 EXPECT_EQ(188, env->GetArrayLength(reinterpret_cast<jarray>(o188))); 1347 EXPECT_EQ(189, env->GetArrayLength(reinterpret_cast<jarray>(o189))); 1348 EXPECT_EQ(190, env->GetArrayLength(reinterpret_cast<jarray>(o190))); 1349 EXPECT_EQ(191, env->GetArrayLength(reinterpret_cast<jarray>(o191))); 1350 EXPECT_EQ(192, env->GetArrayLength(reinterpret_cast<jarray>(o192))); 1351 EXPECT_EQ(193, env->GetArrayLength(reinterpret_cast<jarray>(o193))); 1352 EXPECT_EQ(194, env->GetArrayLength(reinterpret_cast<jarray>(o194))); 1353 EXPECT_EQ(195, env->GetArrayLength(reinterpret_cast<jarray>(o195))); 1354 EXPECT_EQ(196, env->GetArrayLength(reinterpret_cast<jarray>(o196))); 1355 EXPECT_EQ(197, env->GetArrayLength(reinterpret_cast<jarray>(o197))); 1356 EXPECT_EQ(198, env->GetArrayLength(reinterpret_cast<jarray>(o198))); 1357 EXPECT_EQ(199, env->GetArrayLength(reinterpret_cast<jarray>(o199))); 1358 EXPECT_EQ(200, env->GetArrayLength(reinterpret_cast<jarray>(o200))); 1359 EXPECT_EQ(201, env->GetArrayLength(reinterpret_cast<jarray>(o201))); 1360 EXPECT_EQ(202, env->GetArrayLength(reinterpret_cast<jarray>(o202))); 1361 EXPECT_EQ(203, env->GetArrayLength(reinterpret_cast<jarray>(o203))); 1362 EXPECT_EQ(204, env->GetArrayLength(reinterpret_cast<jarray>(o204))); 1363 EXPECT_EQ(205, env->GetArrayLength(reinterpret_cast<jarray>(o205))); 1364 EXPECT_EQ(206, env->GetArrayLength(reinterpret_cast<jarray>(o206))); 1365 EXPECT_EQ(207, env->GetArrayLength(reinterpret_cast<jarray>(o207))); 1366 EXPECT_EQ(208, env->GetArrayLength(reinterpret_cast<jarray>(o208))); 1367 EXPECT_EQ(209, env->GetArrayLength(reinterpret_cast<jarray>(o209))); 1368 EXPECT_EQ(210, env->GetArrayLength(reinterpret_cast<jarray>(o210))); 1369 EXPECT_EQ(211, env->GetArrayLength(reinterpret_cast<jarray>(o211))); 1370 EXPECT_EQ(212, env->GetArrayLength(reinterpret_cast<jarray>(o212))); 1371 EXPECT_EQ(213, env->GetArrayLength(reinterpret_cast<jarray>(o213))); 1372 EXPECT_EQ(214, env->GetArrayLength(reinterpret_cast<jarray>(o214))); 1373 EXPECT_EQ(215, env->GetArrayLength(reinterpret_cast<jarray>(o215))); 1374 EXPECT_EQ(216, env->GetArrayLength(reinterpret_cast<jarray>(o216))); 1375 EXPECT_EQ(217, env->GetArrayLength(reinterpret_cast<jarray>(o217))); 1376 EXPECT_EQ(218, env->GetArrayLength(reinterpret_cast<jarray>(o218))); 1377 EXPECT_EQ(219, env->GetArrayLength(reinterpret_cast<jarray>(o219))); 1378 EXPECT_EQ(220, env->GetArrayLength(reinterpret_cast<jarray>(o220))); 1379 EXPECT_EQ(221, env->GetArrayLength(reinterpret_cast<jarray>(o221))); 1380 EXPECT_EQ(222, env->GetArrayLength(reinterpret_cast<jarray>(o222))); 1381 EXPECT_EQ(223, env->GetArrayLength(reinterpret_cast<jarray>(o223))); 1382 EXPECT_EQ(224, env->GetArrayLength(reinterpret_cast<jarray>(o224))); 1383 EXPECT_EQ(225, env->GetArrayLength(reinterpret_cast<jarray>(o225))); 1384 EXPECT_EQ(226, env->GetArrayLength(reinterpret_cast<jarray>(o226))); 1385 EXPECT_EQ(227, env->GetArrayLength(reinterpret_cast<jarray>(o227))); 1386 EXPECT_EQ(228, env->GetArrayLength(reinterpret_cast<jarray>(o228))); 1387 EXPECT_EQ(229, env->GetArrayLength(reinterpret_cast<jarray>(o229))); 1388 EXPECT_EQ(230, env->GetArrayLength(reinterpret_cast<jarray>(o230))); 1389 EXPECT_EQ(231, env->GetArrayLength(reinterpret_cast<jarray>(o231))); 1390 EXPECT_EQ(232, env->GetArrayLength(reinterpret_cast<jarray>(o232))); 1391 EXPECT_EQ(233, env->GetArrayLength(reinterpret_cast<jarray>(o233))); 1392 EXPECT_EQ(234, env->GetArrayLength(reinterpret_cast<jarray>(o234))); 1393 EXPECT_EQ(235, env->GetArrayLength(reinterpret_cast<jarray>(o235))); 1394 EXPECT_EQ(236, env->GetArrayLength(reinterpret_cast<jarray>(o236))); 1395 EXPECT_EQ(237, env->GetArrayLength(reinterpret_cast<jarray>(o237))); 1396 EXPECT_EQ(238, env->GetArrayLength(reinterpret_cast<jarray>(o238))); 1397 EXPECT_EQ(239, env->GetArrayLength(reinterpret_cast<jarray>(o239))); 1398 EXPECT_EQ(240, env->GetArrayLength(reinterpret_cast<jarray>(o240))); 1399 EXPECT_EQ(241, env->GetArrayLength(reinterpret_cast<jarray>(o241))); 1400 EXPECT_EQ(242, env->GetArrayLength(reinterpret_cast<jarray>(o242))); 1401 EXPECT_EQ(243, env->GetArrayLength(reinterpret_cast<jarray>(o243))); 1402 EXPECT_EQ(244, env->GetArrayLength(reinterpret_cast<jarray>(o244))); 1403 EXPECT_EQ(245, env->GetArrayLength(reinterpret_cast<jarray>(o245))); 1404 EXPECT_EQ(246, env->GetArrayLength(reinterpret_cast<jarray>(o246))); 1405 EXPECT_EQ(247, env->GetArrayLength(reinterpret_cast<jarray>(o247))); 1406 EXPECT_EQ(248, env->GetArrayLength(reinterpret_cast<jarray>(o248))); 1407 EXPECT_EQ(249, env->GetArrayLength(reinterpret_cast<jarray>(o249))); 1408 EXPECT_EQ(250, env->GetArrayLength(reinterpret_cast<jarray>(o250))); 1409 EXPECT_EQ(251, env->GetArrayLength(reinterpret_cast<jarray>(o251))); 1410 EXPECT_EQ(252, env->GetArrayLength(reinterpret_cast<jarray>(o252))); 1411 EXPECT_EQ(253, env->GetArrayLength(reinterpret_cast<jarray>(o253))); 1412 } 1413 } 1414 1415 const char* longSig = 1416 "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1417 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1418 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1419 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1420 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1421 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1422 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1423 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1424 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1425 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1426 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1427 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1428 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1429 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1430 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1431 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1432 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1433 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1434 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1435 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1436 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1437 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1438 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1439 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1440 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1441 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1442 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1443 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1444 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1445 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1446 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1447 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1448 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1449 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1450 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1451 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1452 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1453 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1454 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1455 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1456 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1457 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1458 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1459 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1460 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1461 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1462 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1463 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1464 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1465 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1466 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"; 1467 1468 void JniCompilerTest::MaxParamNumberImpl() { 1469 SetUpForTest(false, "maxParamNumber", longSig, 1470 reinterpret_cast<void*>(&Java_MyClassNatives_maxParamNumber)); 1471 1472 jvalue args[254]; 1473 1474 // First test: test with all arguments null. 1475 for (int i = 0; i < 254; ++i) { 1476 args[i].l = nullptr; 1477 } 1478 1479 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args); 1480 1481 // Second test: test with int[] objects with increasing lengths 1482 for (int i = 0; i < 254; ++i) { 1483 jintArray tmp = env_->NewIntArray(i); 1484 args[i].l = tmp; 1485 EXPECT_NE(args[i].l, nullptr); 1486 } 1487 1488 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args); 1489 } 1490 1491 JNI_TEST(MaxParamNumber) 1492 1493 void JniCompilerTest::WithoutImplementationImpl() { 1494 // This will lead to error messages in the log. 1495 ScopedLogSeverity sls(LogSeverity::FATAL); 1496 1497 SetUpForTest(false, "withoutImplementation", "()V", nullptr); 1498 1499 env_->CallVoidMethod(jobj_, jmethod_); 1500 1501 EXPECT_TRUE(Thread::Current()->IsExceptionPending()); 1502 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 1503 } 1504 1505 JNI_TEST(WithoutImplementation) 1506 1507 void JniCompilerTest::WithoutImplementationRefReturnImpl() { 1508 // This will lead to error messages in the log. 1509 ScopedLogSeverity sls(LogSeverity::FATAL); 1510 1511 SetUpForTest(false, "withoutImplementationRefReturn", "()Ljava/lang/Object;", nullptr); 1512 1513 env_->CallObjectMethod(jobj_, jmethod_); 1514 1515 EXPECT_TRUE(Thread::Current()->IsExceptionPending()); 1516 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 1517 } 1518 1519 JNI_TEST(WithoutImplementationRefReturn) 1520 1521 void Java_MyClassNatives_stackArgsIntsFirst(JNIEnv*, jclass, jint i1, jint i2, jint i3, 1522 jint i4, jint i5, jint i6, jint i7, jint i8, jint i9, 1523 jint i10, jfloat f1, jfloat f2, jfloat f3, jfloat f4, 1524 jfloat f5, jfloat f6, jfloat f7, jfloat f8, jfloat f9, 1525 jfloat f10) { 1526 EXPECT_EQ(i1, 1); 1527 EXPECT_EQ(i2, 2); 1528 EXPECT_EQ(i3, 3); 1529 EXPECT_EQ(i4, 4); 1530 EXPECT_EQ(i5, 5); 1531 EXPECT_EQ(i6, 6); 1532 EXPECT_EQ(i7, 7); 1533 EXPECT_EQ(i8, 8); 1534 EXPECT_EQ(i9, 9); 1535 EXPECT_EQ(i10, 10); 1536 1537 jint i11 = bit_cast<jint, jfloat>(f1); 1538 EXPECT_EQ(i11, 11); 1539 jint i12 = bit_cast<jint, jfloat>(f2); 1540 EXPECT_EQ(i12, 12); 1541 jint i13 = bit_cast<jint, jfloat>(f3); 1542 EXPECT_EQ(i13, 13); 1543 jint i14 = bit_cast<jint, jfloat>(f4); 1544 EXPECT_EQ(i14, 14); 1545 jint i15 = bit_cast<jint, jfloat>(f5); 1546 EXPECT_EQ(i15, 15); 1547 jint i16 = bit_cast<jint, jfloat>(f6); 1548 EXPECT_EQ(i16, 16); 1549 jint i17 = bit_cast<jint, jfloat>(f7); 1550 EXPECT_EQ(i17, 17); 1551 jint i18 = bit_cast<jint, jfloat>(f8); 1552 EXPECT_EQ(i18, 18); 1553 jint i19 = bit_cast<jint, jfloat>(f9); 1554 EXPECT_EQ(i19, 19); 1555 jint i20 = bit_cast<jint, jfloat>(f10); 1556 EXPECT_EQ(i20, 20); 1557 } 1558 1559 void JniCompilerTest::StackArgsIntsFirstImpl() { 1560 SetUpForTest(true, "stackArgsIntsFirst", "(IIIIIIIIIIFFFFFFFFFF)V", 1561 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsIntsFirst)); 1562 1563 jint i1 = 1; 1564 jint i2 = 2; 1565 jint i3 = 3; 1566 jint i4 = 4; 1567 jint i5 = 5; 1568 jint i6 = 6; 1569 jint i7 = 7; 1570 jint i8 = 8; 1571 jint i9 = 9; 1572 jint i10 = 10; 1573 1574 jfloat f1 = bit_cast<jfloat, jint>(11); 1575 jfloat f2 = bit_cast<jfloat, jint>(12); 1576 jfloat f3 = bit_cast<jfloat, jint>(13); 1577 jfloat f4 = bit_cast<jfloat, jint>(14); 1578 jfloat f5 = bit_cast<jfloat, jint>(15); 1579 jfloat f6 = bit_cast<jfloat, jint>(16); 1580 jfloat f7 = bit_cast<jfloat, jint>(17); 1581 jfloat f8 = bit_cast<jfloat, jint>(18); 1582 jfloat f9 = bit_cast<jfloat, jint>(19); 1583 jfloat f10 = bit_cast<jfloat, jint>(20); 1584 1585 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, f1, f2, 1586 f3, f4, f5, f6, f7, f8, f9, f10); 1587 } 1588 1589 JNI_TEST(StackArgsIntsFirst) 1590 1591 void Java_MyClassNatives_stackArgsFloatsFirst(JNIEnv*, jclass, jfloat f1, jfloat f2, 1592 jfloat f3, jfloat f4, jfloat f5, jfloat f6, jfloat f7, 1593 jfloat f8, jfloat f9, jfloat f10, jint i1, jint i2, 1594 jint i3, jint i4, jint i5, jint i6, jint i7, jint i8, 1595 jint i9, jint i10) { 1596 EXPECT_EQ(i1, 1); 1597 EXPECT_EQ(i2, 2); 1598 EXPECT_EQ(i3, 3); 1599 EXPECT_EQ(i4, 4); 1600 EXPECT_EQ(i5, 5); 1601 EXPECT_EQ(i6, 6); 1602 EXPECT_EQ(i7, 7); 1603 EXPECT_EQ(i8, 8); 1604 EXPECT_EQ(i9, 9); 1605 EXPECT_EQ(i10, 10); 1606 1607 jint i11 = bit_cast<jint, jfloat>(f1); 1608 EXPECT_EQ(i11, 11); 1609 jint i12 = bit_cast<jint, jfloat>(f2); 1610 EXPECT_EQ(i12, 12); 1611 jint i13 = bit_cast<jint, jfloat>(f3); 1612 EXPECT_EQ(i13, 13); 1613 jint i14 = bit_cast<jint, jfloat>(f4); 1614 EXPECT_EQ(i14, 14); 1615 jint i15 = bit_cast<jint, jfloat>(f5); 1616 EXPECT_EQ(i15, 15); 1617 jint i16 = bit_cast<jint, jfloat>(f6); 1618 EXPECT_EQ(i16, 16); 1619 jint i17 = bit_cast<jint, jfloat>(f7); 1620 EXPECT_EQ(i17, 17); 1621 jint i18 = bit_cast<jint, jfloat>(f8); 1622 EXPECT_EQ(i18, 18); 1623 jint i19 = bit_cast<jint, jfloat>(f9); 1624 EXPECT_EQ(i19, 19); 1625 jint i20 = bit_cast<jint, jfloat>(f10); 1626 EXPECT_EQ(i20, 20); 1627 } 1628 1629 void JniCompilerTest::StackArgsFloatsFirstImpl() { 1630 SetUpForTest(true, "stackArgsFloatsFirst", "(FFFFFFFFFFIIIIIIIIII)V", 1631 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsFloatsFirst)); 1632 1633 jint i1 = 1; 1634 jint i2 = 2; 1635 jint i3 = 3; 1636 jint i4 = 4; 1637 jint i5 = 5; 1638 jint i6 = 6; 1639 jint i7 = 7; 1640 jint i8 = 8; 1641 jint i9 = 9; 1642 jint i10 = 10; 1643 1644 jfloat f1 = bit_cast<jfloat, jint>(11); 1645 jfloat f2 = bit_cast<jfloat, jint>(12); 1646 jfloat f3 = bit_cast<jfloat, jint>(13); 1647 jfloat f4 = bit_cast<jfloat, jint>(14); 1648 jfloat f5 = bit_cast<jfloat, jint>(15); 1649 jfloat f6 = bit_cast<jfloat, jint>(16); 1650 jfloat f7 = bit_cast<jfloat, jint>(17); 1651 jfloat f8 = bit_cast<jfloat, jint>(18); 1652 jfloat f9 = bit_cast<jfloat, jint>(19); 1653 jfloat f10 = bit_cast<jfloat, jint>(20); 1654 1655 env_->CallStaticVoidMethod(jklass_, jmethod_, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, i1, i2, i3, 1656 i4, i5, i6, i7, i8, i9, i10); 1657 } 1658 1659 JNI_TEST(StackArgsFloatsFirst) 1660 1661 void Java_MyClassNatives_stackArgsMixed(JNIEnv*, jclass, jint i1, jfloat f1, jint i2, 1662 jfloat f2, jint i3, jfloat f3, jint i4, jfloat f4, jint i5, 1663 jfloat f5, jint i6, jfloat f6, jint i7, jfloat f7, jint i8, 1664 jfloat f8, jint i9, jfloat f9, jint i10, jfloat f10) { 1665 EXPECT_EQ(i1, 1); 1666 EXPECT_EQ(i2, 2); 1667 EXPECT_EQ(i3, 3); 1668 EXPECT_EQ(i4, 4); 1669 EXPECT_EQ(i5, 5); 1670 EXPECT_EQ(i6, 6); 1671 EXPECT_EQ(i7, 7); 1672 EXPECT_EQ(i8, 8); 1673 EXPECT_EQ(i9, 9); 1674 EXPECT_EQ(i10, 10); 1675 1676 jint i11 = bit_cast<jint, jfloat>(f1); 1677 EXPECT_EQ(i11, 11); 1678 jint i12 = bit_cast<jint, jfloat>(f2); 1679 EXPECT_EQ(i12, 12); 1680 jint i13 = bit_cast<jint, jfloat>(f3); 1681 EXPECT_EQ(i13, 13); 1682 jint i14 = bit_cast<jint, jfloat>(f4); 1683 EXPECT_EQ(i14, 14); 1684 jint i15 = bit_cast<jint, jfloat>(f5); 1685 EXPECT_EQ(i15, 15); 1686 jint i16 = bit_cast<jint, jfloat>(f6); 1687 EXPECT_EQ(i16, 16); 1688 jint i17 = bit_cast<jint, jfloat>(f7); 1689 EXPECT_EQ(i17, 17); 1690 jint i18 = bit_cast<jint, jfloat>(f8); 1691 EXPECT_EQ(i18, 18); 1692 jint i19 = bit_cast<jint, jfloat>(f9); 1693 EXPECT_EQ(i19, 19); 1694 jint i20 = bit_cast<jint, jfloat>(f10); 1695 EXPECT_EQ(i20, 20); 1696 } 1697 1698 void JniCompilerTest::StackArgsMixedImpl() { 1699 SetUpForTest(true, "stackArgsMixed", "(IFIFIFIFIFIFIFIFIFIF)V", 1700 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsMixed)); 1701 1702 jint i1 = 1; 1703 jint i2 = 2; 1704 jint i3 = 3; 1705 jint i4 = 4; 1706 jint i5 = 5; 1707 jint i6 = 6; 1708 jint i7 = 7; 1709 jint i8 = 8; 1710 jint i9 = 9; 1711 jint i10 = 10; 1712 1713 jfloat f1 = bit_cast<jfloat, jint>(11); 1714 jfloat f2 = bit_cast<jfloat, jint>(12); 1715 jfloat f3 = bit_cast<jfloat, jint>(13); 1716 jfloat f4 = bit_cast<jfloat, jint>(14); 1717 jfloat f5 = bit_cast<jfloat, jint>(15); 1718 jfloat f6 = bit_cast<jfloat, jint>(16); 1719 jfloat f7 = bit_cast<jfloat, jint>(17); 1720 jfloat f8 = bit_cast<jfloat, jint>(18); 1721 jfloat f9 = bit_cast<jfloat, jint>(19); 1722 jfloat f10 = bit_cast<jfloat, jint>(20); 1723 1724 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7, 1725 f7, i8, f8, i9, f9, i10, f10); 1726 } 1727 1728 JNI_TEST(StackArgsMixed) 1729 1730 void Java_MyClassNatives_stackArgsSignExtendedMips64(JNIEnv*, jclass, jint i1, jint i2, jint i3, 1731 jint i4, jint i5, jint i6, jint i7, jint i8) { 1732 EXPECT_EQ(i1, 1); 1733 EXPECT_EQ(i2, 2); 1734 EXPECT_EQ(i3, 3); 1735 EXPECT_EQ(i4, 4); 1736 EXPECT_EQ(i5, 5); 1737 EXPECT_EQ(i6, 6); 1738 EXPECT_EQ(i7, 7); 1739 EXPECT_EQ(i8, -8); 1740 1741 #if defined(__mips__) && defined(__LP64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 1742 // Mips64 ABI requires that arguments passed through stack be sign-extended 8B slots. 1743 // First 8 arguments are passed through registers, check i7 and i8. 1744 uint32_t stack1_high = *(&i7 + 1); 1745 uint32_t stack2_high = *(&i8 + 1); 1746 1747 EXPECT_EQ(stack1_high, static_cast<uint32_t>(0)); 1748 EXPECT_EQ(stack2_high, static_cast<uint32_t>(0xffffffff)); 1749 #else 1750 LOG(INFO) << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on " 1751 << kRuntimeISA; 1752 // Force-print to std::cout so it's also outside the logcat. 1753 std::cout << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on " 1754 << kRuntimeISA << std::endl; 1755 #endif 1756 } 1757 1758 void JniCompilerTest::StackArgsSignExtendedMips64Impl() { 1759 SetUpForTest(true, "stackArgsSignExtendedMips64", "(IIIIIIII)V", 1760 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsSignExtendedMips64)); 1761 jint i1 = 1; 1762 jint i2 = 2; 1763 jint i3 = 3; 1764 jint i4 = 4; 1765 jint i5 = 5; 1766 jint i6 = 6; 1767 jint i7 = 7; 1768 jint i8 = -8; 1769 1770 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8); 1771 } 1772 1773 JNI_TEST(StackArgsSignExtendedMips64) 1774 1775 } // namespace art 1776