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 #include <type_traits> 19 20 #include <math.h> 21 22 #include "art_method-inl.h" 23 #include "base/bit_utils.h" 24 #include "class_linker.h" 25 #include "common_compiler_test.h" 26 #include "compiler.h" 27 #include "dex_file.h" 28 #include "gtest/gtest.h" 29 #include "indirect_reference_table.h" 30 #include "java_vm_ext.h" 31 #include "jni_internal.h" 32 #include "mem_map.h" 33 #include "mirror/class-inl.h" 34 #include "mirror/class_loader.h" 35 #include "mirror/object_array-inl.h" 36 #include "mirror/object-inl.h" 37 #include "mirror/stack_trace_element.h" 38 #include "nativeloader/native_loader.h" 39 #include "runtime.h" 40 #include "ScopedLocalRef.h" 41 #include "scoped_thread_state_change-inl.h" 42 #include "thread.h" 43 44 extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_bar(JNIEnv*, jobject, jint count) { 45 return count + 1; 46 } 47 48 extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_sbar(JNIEnv*, jclass, jint count) { 49 return count + 1; 50 } 51 52 namespace art { 53 54 enum class JniKind { 55 kNormal = Compiler::kNone, // Regular kind of un-annotated natives. 56 kFast = Compiler::kFastNative, // Native method annotated with @FastNative. 57 kCritical = Compiler::kCriticalNative, // Native method annotated with @CriticalNative. 58 kCount = Compiler::kCriticalNative + 1 // How many different types of JNIs we can have. 59 }; 60 61 // Used to initialize array sizes that want to have different state per current jni. 62 static constexpr size_t kJniKindCount = static_cast<size_t>(JniKind::kCount); 63 // Do not use directly, use the helpers instead. 64 uint32_t gCurrentJni = static_cast<uint32_t>(JniKind::kNormal); 65 66 // Is the current native method under test @CriticalNative? 67 static bool IsCurrentJniCritical() { 68 return gCurrentJni == static_cast<uint32_t>(JniKind::kCritical); 69 } 70 71 // Is the current native method a plain-old non-annotated native? 72 static bool IsCurrentJniNormal() { 73 return gCurrentJni == static_cast<uint32_t>(JniKind::kNormal); 74 } 75 76 // Signifify that a different kind of JNI is about to be tested. 77 static void UpdateCurrentJni(JniKind kind) { 78 gCurrentJni = static_cast<uint32_t>(kind); 79 } 80 81 // (Match the name suffixes of native methods in MyClassNatives.java) 82 static std::string CurrentJniStringSuffix() { 83 switch (gCurrentJni) { 84 case static_cast<uint32_t>(JniKind::kNormal): { 85 return ""; 86 } 87 case static_cast<uint32_t>(JniKind::kFast): { 88 return "_Fast"; 89 } 90 case static_cast<uint32_t>(JniKind::kCritical): { 91 return "_Critical"; 92 } 93 default: 94 LOG(FATAL) << "Invalid current JNI value: " << gCurrentJni; 95 UNREACHABLE(); 96 } 97 } 98 99 // Dummy values passed to our JNI handlers when we enter @CriticalNative. 100 // Normally @CriticalNative calling convention strips out the "JNIEnv*, jclass" parameters. 101 // However to avoid duplicating every single test method we have a templated handler 102 // that inserts dummy parameters (0,1) to make it compatible with a regular JNI handler. 103 static JNIEnv* const kCriticalDummyJniEnv = reinterpret_cast<JNIEnv*>(0xDEADFEAD); 104 static jclass const kCriticalDummyJniClass = reinterpret_cast<jclass>(0xBEAFBEEF); 105 106 // Type trait. Returns true if "T" is the same type as one of the types in Args... 107 // 108 // Logically equal to OR(std::same_type<T, U> for all U in Args). 109 template <typename T, typename ... Args> 110 struct is_any_of; 111 112 template <typename T, typename U, typename ... Args> 113 struct is_any_of<T, U, Args ...> { 114 using value_type = bool; 115 static constexpr const bool value = std::is_same<T, U>::value || is_any_of<T, Args ...>::value; 116 }; 117 118 template <typename T, typename U> 119 struct is_any_of<T, U> { 120 using value_type = bool; 121 static constexpr const bool value = std::is_same<T, U>::value; 122 }; 123 124 // Type traits for JNI types. 125 template <typename T> 126 struct jni_type_traits { 127 // True if type T ends up holding an object reference. False otherwise. 128 // (Non-JNI types will also be false). 129 static constexpr const bool is_ref = 130 is_any_of<T, jclass, jobject, jstring, jobjectArray, jintArray, 131 jcharArray, jfloatArray, jshortArray, jdoubleArray, jlongArray>::value; 132 }; 133 134 template <typename ... Args> 135 struct count_refs_helper { 136 using value_type = size_t; 137 static constexpr const size_t value = 0; 138 }; 139 140 template <typename Arg, typename ... Args> 141 struct count_refs_helper<Arg, Args ...> { 142 using value_type = size_t; 143 static constexpr size_t value = 144 (jni_type_traits<Arg>::is_ref ? 1 : 0) + count_refs_helper<Args ...>::value; 145 }; 146 147 template <typename T, T fn> 148 struct count_refs_fn_helper; 149 150 template <typename R, typename ... Args, R fn(Args...)> 151 struct count_refs_fn_helper<R(Args...), fn> : public count_refs_helper<Args...> {}; 152 153 // Given a function type 'T' figure out how many of the parameter types are a reference. 154 // -- The implicit jclass and thisObject also count as 1 reference. 155 // 156 // Fields: 157 // * value - the result counting # of refs 158 // * value_type - the type of value (size_t) 159 template <typename T, T fn> 160 struct count_refs : public count_refs_fn_helper<T, fn> {}; 161 162 // Base case: No parameters = 0 refs. 163 size_t count_nonnull_refs_helper() { 164 return 0; 165 } 166 167 // SFINAE for ref types. 1 if non-null, 0 otherwise. 168 template <typename T> 169 size_t count_nonnull_refs_single_helper(T arg, 170 typename std::enable_if<jni_type_traits<T>::is_ref>::type* 171 = nullptr) { 172 return ((arg == NULL) ? 0 : 1); 173 } 174 175 // SFINAE for non-ref-types. Always 0. 176 template <typename T> 177 size_t count_nonnull_refs_single_helper(T arg ATTRIBUTE_UNUSED, 178 typename std::enable_if<!jni_type_traits<T>::is_ref>::type* 179 = nullptr) { 180 return 0; 181 } 182 183 // Recursive case. 184 template <typename T, typename ... Args> 185 size_t count_nonnull_refs_helper(T arg, Args ... args) { 186 return count_nonnull_refs_single_helper(arg) + count_nonnull_refs_helper(args...); 187 } 188 189 // Given any list of parameters, check how many object refs there are and only count 190 // them if their runtime value is non-null. 191 // 192 // For example given (jobject, jint, jclass) we can get (2) if both #0/#2 are non-null, 193 // (1) if either #0/#2 are null but not both, and (0) if all parameters are null. 194 // Primitive parameters (including JNIEnv*, if present) are ignored. 195 template <typename ... Args> 196 size_t count_nonnull_refs(Args ... args) { 197 return count_nonnull_refs_helper(args...); 198 } 199 200 template <typename T, T fn> 201 struct remove_extra_parameters_helper; 202 203 template <typename R, typename Arg1, typename Arg2, typename ... Args, R fn(Arg1, Arg2, Args...)> 204 struct remove_extra_parameters_helper<R(Arg1, Arg2, Args...), fn> { 205 // Note: Do not use Args&& here to maintain C-style parameter types. 206 static R apply(Args... args) { 207 JNIEnv* env = kCriticalDummyJniEnv; 208 jclass kls = kCriticalDummyJniClass; 209 return fn(env, kls, args...); 210 } 211 }; 212 213 // Given a function 'fn' create a function 'apply' which will omit the JNIEnv/jklass parameters 214 // 215 // i.e. if fn(JNIEnv*,jklass,a,b,c,d,e...) then apply(a,b,c,d,e,...) 216 template <typename T, T fn> 217 struct jni_remove_extra_parameters : public remove_extra_parameters_helper<T, fn> {}; 218 219 class JniCompilerTest : public CommonCompilerTest { 220 protected: 221 void SetUp() OVERRIDE { 222 CommonCompilerTest::SetUp(); 223 check_generic_jni_ = false; 224 } 225 226 void TearDown() OVERRIDE { 227 android::ResetNativeLoader(); 228 CommonCompilerTest::TearDown(); 229 } 230 231 void SetCheckGenericJni(bool generic) { 232 check_generic_jni_ = generic; 233 } 234 235 private: 236 void CompileForTest(jobject class_loader, 237 bool direct, 238 const char* method_name, 239 const char* method_sig) { 240 ScopedObjectAccess soa(Thread::Current()); 241 StackHandleScope<1> hs(soa.Self()); 242 Handle<mirror::ClassLoader> loader( 243 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader))); 244 // Compile the native method before starting the runtime 245 mirror::Class* c = class_linker_->FindClass(soa.Self(), "LMyClassNatives;", loader); 246 const auto pointer_size = class_linker_->GetImagePointerSize(); 247 ArtMethod* method = direct ? c->FindDirectMethod(method_name, method_sig, pointer_size) : 248 c->FindVirtualMethod(method_name, method_sig, pointer_size); 249 ASSERT_TRUE(method != nullptr) << method_name << " " << method_sig; 250 if (check_generic_jni_) { 251 method->SetEntryPointFromQuickCompiledCode(class_linker_->GetRuntimeQuickGenericJniStub()); 252 } else { 253 const void* code = method->GetEntryPointFromQuickCompiledCode(); 254 if (code == nullptr || class_linker_->IsQuickGenericJniStub(code)) { 255 CompileMethod(method); 256 ASSERT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr) 257 << method_name << " " << method_sig; 258 } 259 } 260 } 261 262 protected: 263 void CompileForTestWithCurrentJni(jobject class_loader, 264 bool direct, 265 const char* method_name_orig, 266 const char* method_sig) { 267 // Append the JNI kind to the method name, so that we automatically get the 268 // fast or critical versions of the same method. 269 std::string method_name_str = std::string(method_name_orig) + CurrentJniStringSuffix(); 270 const char* method_name = method_name_str.c_str(); 271 272 CompileForTest(class_loader, direct, method_name, method_sig); 273 } 274 275 void SetUpForTest(bool direct, 276 const char* method_name_orig, 277 const char* method_sig, 278 void* native_fnptr) { 279 // Append the JNI kind to the method name, so that we automatically get the 280 // fast or critical versions of the same method. 281 std::string method_name_str = std::string(method_name_orig) + CurrentJniStringSuffix(); 282 const char* method_name = method_name_str.c_str(); 283 284 // Initialize class loader and compile method when runtime not started. 285 if (!runtime_->IsStarted()) { 286 { 287 ScopedObjectAccess soa(Thread::Current()); 288 class_loader_ = LoadDex("MyClassNatives"); 289 } 290 CompileForTest(class_loader_, direct, method_name, method_sig); 291 // Start runtime. 292 Thread::Current()->TransitionFromSuspendedToRunnable(); 293 android::InitializeNativeLoader(); 294 bool started = runtime_->Start(); 295 CHECK(started); 296 } 297 // JNI operations after runtime start. 298 env_ = Thread::Current()->GetJniEnv(); 299 library_search_path_ = env_->NewStringUTF(""); 300 jklass_ = env_->FindClass("MyClassNatives"); 301 ASSERT_TRUE(jklass_ != nullptr) << method_name << " " << method_sig; 302 303 if (direct) { 304 jmethod_ = env_->GetStaticMethodID(jklass_, method_name, method_sig); 305 } else { 306 jmethod_ = env_->GetMethodID(jklass_, method_name, method_sig); 307 } 308 ASSERT_TRUE(jmethod_ != nullptr) << method_name << " " << method_sig; 309 310 if (native_fnptr != nullptr) { 311 JNINativeMethod methods[] = { { method_name, method_sig, native_fnptr } }; 312 ASSERT_EQ(JNI_OK, env_->RegisterNatives(jklass_, methods, 1)) 313 << method_name << " " << method_sig; 314 } else { 315 env_->UnregisterNatives(jklass_); 316 } 317 318 jmethodID constructor = env_->GetMethodID(jklass_, "<init>", "()V"); 319 jobj_ = env_->NewObject(jklass_, constructor); 320 ASSERT_TRUE(jobj_ != nullptr) << method_name << " " << method_sig; 321 } 322 323 public: 324 // Available as statics so our JNI handlers can access these. 325 static jclass jklass_; 326 static jobject jobj_; 327 static jobject class_loader_; 328 329 protected: 330 // We have to list the methods here so we can share them between default and generic JNI. 331 void CompileAndRunNoArgMethodImpl(); 332 void CompileAndRunIntMethodThroughStubImpl(); 333 void CompileAndRunStaticIntMethodThroughStubImpl(); 334 void CompileAndRunIntMethodImpl(); 335 void CompileAndRunIntIntMethodImpl(); 336 void CompileAndRunLongLongMethodImpl(); 337 void CompileAndRunDoubleDoubleMethodImpl(); 338 void CompileAndRun_fooJJ_synchronizedImpl(); 339 void CompileAndRunIntObjectObjectMethodImpl(); 340 void CompileAndRunStaticIntIntMethodImpl(); 341 void CompileAndRunStaticDoubleDoubleMethodImpl(); 342 void RunStaticLogDoubleMethodImpl(); 343 void RunStaticLogFloatMethodImpl(); 344 void RunStaticReturnTrueImpl(); 345 void RunStaticReturnFalseImpl(); 346 void RunGenericStaticReturnIntImpl(); 347 void RunGenericStaticReturnDoubleImpl(); 348 void RunGenericStaticReturnLongImpl(); 349 void CompileAndRunStaticIntObjectObjectMethodImpl(); 350 void CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl(); 351 void ExceptionHandlingImpl(); 352 void NativeStackTraceElementImpl(); 353 void ReturnGlobalRefImpl(); 354 void LocalReferenceTableClearingTestImpl(); 355 void JavaLangSystemArrayCopyImpl(); 356 void CompareAndSwapIntImpl(); 357 void GetTextImpl(); 358 void GetSinkPropertiesNativeImpl(); 359 void UpcallReturnTypeChecking_InstanceImpl(); 360 void UpcallReturnTypeChecking_StaticImpl(); 361 void UpcallArgumentTypeChecking_InstanceImpl(); 362 void UpcallArgumentTypeChecking_StaticImpl(); 363 void CompileAndRunFloatFloatMethodImpl(); 364 void CheckParameterAlignImpl(); 365 void MaxParamNumberImpl(); 366 void WithoutImplementationImpl(); 367 void WithoutImplementationRefReturnImpl(); 368 void StackArgsIntsFirstImpl(); 369 void StackArgsFloatsFirstImpl(); 370 void StackArgsMixedImpl(); 371 #if defined(__mips__) && defined(__LP64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 372 void StackArgsSignExtendedMips64Impl(); 373 #endif 374 375 void NormalNativeImpl(); 376 void FastNativeImpl(); 377 void CriticalNativeImpl(); 378 379 JNIEnv* env_; 380 jstring library_search_path_; 381 jmethodID jmethod_; 382 383 private: 384 bool check_generic_jni_; 385 }; 386 387 jclass JniCompilerTest::jklass_; 388 jobject JniCompilerTest::jobj_; 389 jobject JniCompilerTest::class_loader_; 390 391 // Test the normal compiler and normal generic JNI only. 392 // The following features are unsupported in @FastNative: 393 // 1) JNI stubs (lookup via dlsym) when methods aren't explicitly registered 394 // 2) synchronized keyword 395 // -- TODO: We can support (1) if we remove the mutator lock assert during stub lookup. 396 # define JNI_TEST_NORMAL_ONLY(TestName) \ 397 TEST_F(JniCompilerTest, TestName ## NormalCompiler) { \ 398 ScopedCheckHandleScope top_handle_scope_check; \ 399 SCOPED_TRACE("Normal JNI with compiler"); \ 400 gCurrentJni = static_cast<uint32_t>(JniKind::kNormal); \ 401 TestName ## Impl(); \ 402 } \ 403 TEST_F(JniCompilerTest, TestName ## NormalGeneric) { \ 404 ScopedCheckHandleScope top_handle_scope_check; \ 405 SCOPED_TRACE("Normal JNI with generic"); \ 406 gCurrentJni = static_cast<uint32_t>(JniKind::kNormal); \ 407 SetCheckGenericJni(true); \ 408 TestName ## Impl(); \ 409 } 410 411 // Test (normal, @FastNative) x (compiler, generic). 412 #define JNI_TEST(TestName) \ 413 JNI_TEST_NORMAL_ONLY(TestName) \ 414 TEST_F(JniCompilerTest, TestName ## FastCompiler) { \ 415 ScopedCheckHandleScope top_handle_scope_check; \ 416 SCOPED_TRACE("@FastNative JNI with compiler"); \ 417 gCurrentJni = static_cast<uint32_t>(JniKind::kFast); \ 418 TestName ## Impl(); \ 419 } \ 420 \ 421 TEST_F(JniCompilerTest, TestName ## FastGeneric) { \ 422 ScopedCheckHandleScope top_handle_scope_check; \ 423 SCOPED_TRACE("@FastNative JNI with generic"); \ 424 gCurrentJni = static_cast<uint32_t>(JniKind::kFast); \ 425 SetCheckGenericJni(true); \ 426 TestName ## Impl(); \ 427 } 428 429 // Test (@CriticalNative) x (compiler, generic) only. 430 #define JNI_TEST_CRITICAL_ONLY(TestName) \ 431 TEST_F(JniCompilerTest, TestName ## CriticalCompiler) { \ 432 ScopedCheckHandleScope top_handle_scope_check; \ 433 SCOPED_TRACE("@CriticalNative JNI with compiler"); \ 434 gCurrentJni = static_cast<uint32_t>(JniKind::kCritical); \ 435 TestName ## Impl(); \ 436 } \ 437 TEST_F(JniCompilerTest, TestName ## CriticalGeneric) { \ 438 ScopedCheckHandleScope top_handle_scope_check; \ 439 SCOPED_TRACE("@CriticalNative JNI with generic"); \ 440 gCurrentJni = static_cast<uint32_t>(JniKind::kCritical); \ 441 SetCheckGenericJni(true); \ 442 TestName ## Impl(); \ 443 } 444 445 // Test everything: (normal, @FastNative, @CriticalNative) x (compiler, generic). 446 #define JNI_TEST_CRITICAL(TestName) \ 447 JNI_TEST(TestName) \ 448 JNI_TEST_CRITICAL_ONLY(TestName) \ 449 450 static void expectValidThreadState() { 451 // Normal JNI always transitions to "Native". Other JNIs stay in the "Runnable" state. 452 if (IsCurrentJniNormal()) { 453 EXPECT_EQ(kNative, Thread::Current()->GetState()); 454 } else { 455 EXPECT_EQ(kRunnable, Thread::Current()->GetState()); 456 } 457 } 458 459 #define EXPECT_THREAD_STATE_FOR_CURRENT_JNI() expectValidThreadState() 460 461 static void expectValidMutatorLockHeld() { 462 if (IsCurrentJniNormal()) { 463 Locks::mutator_lock_->AssertNotHeld(Thread::Current()); 464 } else { 465 Locks::mutator_lock_->AssertSharedHeld(Thread::Current()); 466 } 467 } 468 469 #define EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI() expectValidMutatorLockHeld() 470 471 static void expectValidJniEnvAndObject(JNIEnv* env, jobject thisObj) { 472 if (!IsCurrentJniCritical()) { 473 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 474 ASSERT_TRUE(thisObj != nullptr); 475 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_)); 476 } else { 477 LOG(FATAL) << "Objects are not supported for @CriticalNative, why is this being tested?"; 478 UNREACHABLE(); 479 } 480 } 481 482 // Validates the JNIEnv to be the same as the current thread's JNIEnv, and makes sure 483 // that the object here is an instance of the class we registered the method with. 484 // 485 // Hard-fails if this somehow gets invoked for @CriticalNative since objects are unsupported. 486 #define EXPECT_JNI_ENV_AND_OBJECT_FOR_CURRENT_JNI(env, thisObj) \ 487 expectValidJniEnvAndObject(env, thisObj) 488 489 static void expectValidJniEnvAndClass(JNIEnv* env, jclass kls) { 490 if (!IsCurrentJniCritical()) { 491 EXPECT_EQ(Thread::Current()->GetJniEnv(), env); 492 ASSERT_TRUE(kls != nullptr); 493 EXPECT_TRUE(env->IsSameObject(static_cast<jobject>(JniCompilerTest::jklass_), 494 static_cast<jobject>(kls))); 495 } else { 496 // This is pretty much vacuously true but catch any testing setup mistakes. 497 EXPECT_EQ(env, kCriticalDummyJniEnv); 498 EXPECT_EQ(kls, kCriticalDummyJniClass); 499 } 500 } 501 502 // Validates the JNIEnv is the same as the current thread's JNIenv, and makes sure 503 // that the jclass we got in the JNI handler is the same one as the class the method was looked 504 // up for. 505 // 506 // (Checks are skipped for @CriticalNative since the two values are dummy). 507 #define EXPECT_JNI_ENV_AND_CLASS_FOR_CURRENT_JNI(env, kls) expectValidJniEnvAndClass(env, kls) 508 509 // Temporarily disable the EXPECT_NUM_STACK_REFERENCES check (for a single test). 510 struct ScopedDisableCheckNumStackReferences { 511 ScopedDisableCheckNumStackReferences() { 512 CHECK(sCheckNumStackReferences); // No nested support. 513 sCheckNumStackReferences = false; 514 } 515 516 ~ScopedDisableCheckNumStackReferences() { 517 sCheckNumStackReferences = true; 518 } 519 520 static bool sCheckNumStackReferences; 521 }; 522 523 bool ScopedDisableCheckNumStackReferences::sCheckNumStackReferences = true; 524 525 // Check that the handle scope at the start of this block is the same as the handle scope at the end of the block. 526 struct ScopedCheckHandleScope { 527 ScopedCheckHandleScope() : handle_scope_(Thread::Current()->GetTopHandleScope()) { 528 } 529 530 ~ScopedCheckHandleScope() { 531 EXPECT_EQ(handle_scope_, Thread::Current()->GetTopHandleScope()) 532 << "Top-most handle scope must be the same after all the JNI " 533 << "invocations have finished (as before they were invoked)."; 534 } 535 536 BaseHandleScope* const handle_scope_; 537 }; 538 539 // Number of references allocated in JNI ShadowFrames on the given thread. 540 static size_t NumJniShadowFrameReferences(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { 541 return self->GetManagedStack()->NumJniShadowFrameReferences(); 542 } 543 544 // Number of references in handle scope on the given thread. 545 static size_t NumHandleReferences(Thread* self) { 546 size_t count = 0; 547 for (BaseHandleScope* cur = self->GetTopHandleScope(); cur != nullptr; cur = cur->GetLink()) { 548 count += cur->NumberOfReferences(); 549 } 550 return count; 551 } 552 553 // Number of references allocated in handle scopes & JNI shadow frames on this thread. 554 static size_t NumStackReferences(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { 555 return NumHandleReferences(self) + NumJniShadowFrameReferences(self); 556 } 557 558 static void expectNumStackReferences(size_t val1, size_t val2) { 559 // In rare cases when JNI functions call themselves recursively, 560 // disable this test because it will have a false negative. 561 if (!IsCurrentJniCritical() && ScopedDisableCheckNumStackReferences::sCheckNumStackReferences) { 562 /* @CriticalNative doesn't build a HandleScope, so this test is meaningless then. */ 563 ScopedObjectAccess soa(Thread::Current()); 564 565 size_t actual_num = NumStackReferences(Thread::Current()); 566 // XX: Not too sure what's going on. 567 // Sometimes null references get placed and sometimes they don't? 568 EXPECT_TRUE(val1 == actual_num || val2 == actual_num) 569 << "expected either " << val1 << " or " << val2 570 << " number of stack references, but got: " << actual_num; 571 } 572 } 573 574 #define EXPECT_NUM_STACK_REFERENCES(val1, val2) expectNumStackReferences(val1, val2) 575 576 template <typename T, T fn> 577 struct make_jni_test_decorator; 578 579 // Decorator for "static" JNI callbacks. 580 template <typename R, typename ... Args, R fn(JNIEnv*, jclass, Args...)> 581 struct make_jni_test_decorator<R(JNIEnv*, jclass kls, Args...), fn> { 582 static R apply(JNIEnv* env, jclass kls, Args ... args) { 583 EXPECT_THREAD_STATE_FOR_CURRENT_JNI(); 584 EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI(); 585 EXPECT_JNI_ENV_AND_CLASS_FOR_CURRENT_JNI(env, kls); 586 // All incoming parameters + the jclass get put into the transition's StackHandleScope. 587 EXPECT_NUM_STACK_REFERENCES(count_nonnull_refs(kls, args...), 588 (count_refs_helper<jclass, Args...>::value)); 589 590 return fn(env, kls, args...); 591 } 592 }; 593 594 // Decorator for instance JNI callbacks. 595 template <typename R, typename ... Args, R fn(JNIEnv*, jobject, Args...)> 596 struct make_jni_test_decorator<R(JNIEnv*, jobject, Args...), fn> { 597 static R apply(JNIEnv* env, jobject thisObj, Args ... args) { 598 EXPECT_THREAD_STATE_FOR_CURRENT_JNI(); 599 EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI(); 600 EXPECT_JNI_ENV_AND_OBJECT_FOR_CURRENT_JNI(env, thisObj); 601 // All incoming parameters + the implicit 'this' get put into the transition's StackHandleScope. 602 EXPECT_NUM_STACK_REFERENCES(count_nonnull_refs(thisObj, args...), 603 (count_refs_helper<jobject, Args...>::value)); 604 605 return fn(env, thisObj, args...); 606 } 607 }; 608 609 // Decorate the regular JNI callee with the extra gtest checks. 610 // This way we can have common test logic for everything generic like checking if a lock is held, 611 // checking handle scope state, etc. 612 #define MAKE_JNI_TEST_DECORATOR(fn) make_jni_test_decorator<decltype(fn), (fn)>::apply 613 614 // Convert function f(JNIEnv*,jclass,a,b,c,d...) into f2(a,b,c,d...) 615 // -- This way we don't have to write out each implementation twice for @CriticalNative. 616 #define JNI_CRITICAL_WRAPPER(func) jni_remove_extra_parameters<decltype(func), (func)>::apply 617 // Get a function pointer whose calling convention either matches a regular native 618 // or a critical native depending on which kind of jni is currently under test. 619 // -- This also has the benefit of genering a compile time error if the 'func' doesn't properly 620 // have JNIEnv and jclass parameters first. 621 #define CURRENT_JNI_WRAPPER(func) \ 622 (IsCurrentJniCritical() \ 623 ? reinterpret_cast<void*>(&JNI_CRITICAL_WRAPPER(MAKE_JNI_TEST_DECORATOR(func))) \ 624 : reinterpret_cast<void*>(&MAKE_JNI_TEST_DECORATOR(func))) 625 626 // Do the opposite of the above. Do *not* wrap the function, instead just cast it to a void*. 627 // Only for "TEST_JNI_NORMAL_ONLY" configs, and it inserts a test assert to ensure this is the case. 628 #define NORMAL_JNI_ONLY_NOWRAP(func) \ 629 ({ ASSERT_TRUE(IsCurrentJniNormal()); reinterpret_cast<void*>(&(func)); }) 630 // Same as above, but with nullptr. When we want to test the stub functionality. 631 #define NORMAL_JNI_ONLY_NULLPTR \ 632 ({ ASSERT_TRUE(IsCurrentJniNormal()); nullptr; }) 633 634 635 int gJava_MyClassNatives_foo_calls[kJniKindCount] = {}; 636 void Java_MyClassNatives_foo(JNIEnv*, jobject) { 637 gJava_MyClassNatives_foo_calls[gCurrentJni]++; 638 } 639 640 void JniCompilerTest::CompileAndRunNoArgMethodImpl() { 641 SetUpForTest(false, "foo", "()V", CURRENT_JNI_WRAPPER(Java_MyClassNatives_foo)); 642 643 EXPECT_EQ(0, gJava_MyClassNatives_foo_calls[gCurrentJni]); 644 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 645 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]); 646 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 647 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls[gCurrentJni]); 648 649 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0; 650 } 651 652 JNI_TEST(CompileAndRunNoArgMethod) 653 654 void JniCompilerTest::CompileAndRunIntMethodThroughStubImpl() { 655 SetUpForTest(false, "bar", "(I)I", NORMAL_JNI_ONLY_NULLPTR); 656 // calling through stub will link with &Java_MyClassNatives_bar 657 658 std::string reason; 659 ASSERT_TRUE(Runtime::Current()->GetJavaVM()-> 660 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason)) 661 << reason; 662 663 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 24); 664 EXPECT_EQ(25, result); 665 } 666 667 // TODO: Support @FastNative and @CriticalNative through stubs. 668 JNI_TEST_NORMAL_ONLY(CompileAndRunIntMethodThroughStub) 669 670 void JniCompilerTest::CompileAndRunStaticIntMethodThroughStubImpl() { 671 SetUpForTest(true, "sbar", "(I)I", NORMAL_JNI_ONLY_NULLPTR); 672 // calling through stub will link with &Java_MyClassNatives_sbar 673 674 std::string reason; 675 ASSERT_TRUE(Runtime::Current()->GetJavaVM()-> 676 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason)) 677 << reason; 678 679 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42); 680 EXPECT_EQ(43, result); 681 } 682 683 // TODO: Support @FastNative and @CriticalNative through stubs. 684 JNI_TEST_NORMAL_ONLY(CompileAndRunStaticIntMethodThroughStub) 685 686 int gJava_MyClassNatives_fooI_calls[kJniKindCount] = {}; 687 jint Java_MyClassNatives_fooI(JNIEnv*, jobject, jint x) { 688 gJava_MyClassNatives_fooI_calls[gCurrentJni]++; 689 return x; 690 } 691 692 void JniCompilerTest::CompileAndRunIntMethodImpl() { 693 SetUpForTest(false, "fooI", "(I)I", 694 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooI)); 695 696 EXPECT_EQ(0, gJava_MyClassNatives_fooI_calls[gCurrentJni]); 697 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 42); 698 EXPECT_EQ(42, result); 699 EXPECT_EQ(1, gJava_MyClassNatives_fooI_calls[gCurrentJni]); 700 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFED00D); 701 EXPECT_EQ(static_cast<jint>(0xCAFED00D), result); 702 EXPECT_EQ(2, gJava_MyClassNatives_fooI_calls[gCurrentJni]); 703 704 gJava_MyClassNatives_fooI_calls[gCurrentJni] = 0; 705 } 706 707 JNI_TEST(CompileAndRunIntMethod) 708 709 int gJava_MyClassNatives_fooII_calls[kJniKindCount] = {}; 710 jint Java_MyClassNatives_fooII(JNIEnv*, jobject, jint x, jint y) { 711 gJava_MyClassNatives_fooII_calls[gCurrentJni]++; 712 return x - y; // non-commutative operator 713 } 714 715 void JniCompilerTest::CompileAndRunIntIntMethodImpl() { 716 SetUpForTest(false, "fooII", "(II)I", 717 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooII)); 718 719 EXPECT_EQ(0, gJava_MyClassNatives_fooII_calls[gCurrentJni]); 720 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 99, 10); 721 EXPECT_EQ(99 - 10, result); 722 EXPECT_EQ(1, gJava_MyClassNatives_fooII_calls[gCurrentJni]); 723 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFEBABE, 724 0xCAFED00D); 725 EXPECT_EQ(static_cast<jint>(0xCAFEBABE - 0xCAFED00D), result); 726 EXPECT_EQ(2, gJava_MyClassNatives_fooII_calls[gCurrentJni]); 727 728 gJava_MyClassNatives_fooII_calls[gCurrentJni] = 0; 729 } 730 731 JNI_TEST(CompileAndRunIntIntMethod) 732 733 int gJava_MyClassNatives_fooJJ_calls[kJniKindCount] = {}; 734 jlong Java_MyClassNatives_fooJJ(JNIEnv*, jobject, jlong x, jlong y) { 735 gJava_MyClassNatives_fooJJ_calls[gCurrentJni]++; 736 return x - y; // non-commutative operator 737 } 738 739 void JniCompilerTest::CompileAndRunLongLongMethodImpl() { 740 SetUpForTest(false, "fooJJ", "(JJ)J", 741 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooJJ)); 742 743 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]); 744 jlong a = INT64_C(0x1234567890ABCDEF); 745 jlong b = INT64_C(0xFEDCBA0987654321); 746 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b); 747 EXPECT_EQ(a - b, result); 748 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]); 749 result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, b, a); 750 EXPECT_EQ(b - a, result); 751 EXPECT_EQ(2, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]); 752 753 gJava_MyClassNatives_fooJJ_calls[gCurrentJni] = 0; 754 } 755 756 JNI_TEST(CompileAndRunLongLongMethod) 757 758 int gJava_MyClassNatives_fooDD_calls[kJniKindCount] = {}; 759 jdouble Java_MyClassNatives_fooDD(JNIEnv*, jobject, jdouble x, jdouble y) { 760 gJava_MyClassNatives_fooDD_calls[gCurrentJni]++; 761 return x - y; // non-commutative operator 762 } 763 764 void JniCompilerTest::CompileAndRunDoubleDoubleMethodImpl() { 765 SetUpForTest(false, "fooDD", "(DD)D", 766 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooDD)); 767 768 EXPECT_EQ(0, gJava_MyClassNatives_fooDD_calls[gCurrentJni]); 769 jdouble result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, 770 99.0, 10.0); 771 EXPECT_DOUBLE_EQ(99.0 - 10.0, result); 772 EXPECT_EQ(1, gJava_MyClassNatives_fooDD_calls[gCurrentJni]); 773 jdouble a = 3.14159265358979323846; 774 jdouble b = 0.69314718055994530942; 775 result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, a, b); 776 EXPECT_DOUBLE_EQ(a - b, result); 777 EXPECT_EQ(2, gJava_MyClassNatives_fooDD_calls[gCurrentJni]); 778 779 gJava_MyClassNatives_fooDD_calls[gCurrentJni] = 0; 780 } 781 782 int gJava_MyClassNatives_fooJJ_synchronized_calls[kJniKindCount] = {}; 783 jlong Java_MyClassNatives_fooJJ_synchronized(JNIEnv*, jobject, jlong x, jlong y) { 784 gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]++; 785 return x | y; 786 } 787 788 void JniCompilerTest::CompileAndRun_fooJJ_synchronizedImpl() { 789 SetUpForTest(false, "fooJJ_synchronized", "(JJ)J", 790 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooJJ_synchronized)); 791 792 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]); 793 jlong a = 0x1000000020000000ULL; 794 jlong b = 0x00ff000000aa0000ULL; 795 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b); 796 EXPECT_EQ(a | b, result); 797 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]); 798 799 gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni] = 0; 800 } 801 802 JNI_TEST_NORMAL_ONLY(CompileAndRun_fooJJ_synchronized) 803 804 int gJava_MyClassNatives_fooIOO_calls[kJniKindCount] = {}; 805 jobject Java_MyClassNatives_fooIOO(JNIEnv*, jobject thisObj, jint x, jobject y, 806 jobject z) { 807 gJava_MyClassNatives_fooIOO_calls[gCurrentJni]++; 808 switch (x) { 809 case 1: 810 return y; 811 case 2: 812 return z; 813 default: 814 return thisObj; 815 } 816 } 817 818 void JniCompilerTest::CompileAndRunIntObjectObjectMethodImpl() { 819 SetUpForTest(false, "fooIOO", 820 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 821 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooIOO)); 822 823 EXPECT_EQ(0, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 824 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, nullptr); 825 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 826 EXPECT_EQ(1, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 827 828 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, jklass_); 829 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 830 EXPECT_EQ(2, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 831 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, nullptr, jklass_); 832 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 833 EXPECT_EQ(3, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 834 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, nullptr, jklass_); 835 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 836 EXPECT_EQ(4, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 837 838 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, jklass_, nullptr); 839 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 840 EXPECT_EQ(5, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 841 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, jklass_, nullptr); 842 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 843 EXPECT_EQ(6, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 844 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, jklass_, nullptr); 845 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 846 EXPECT_EQ(7, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]); 847 848 gJava_MyClassNatives_fooIOO_calls[gCurrentJni] = 0; 849 } 850 851 JNI_TEST(CompileAndRunIntObjectObjectMethod) 852 853 int gJava_MyClassNatives_fooSII_calls[kJniKindCount] = {}; 854 jint Java_MyClassNatives_fooSII(JNIEnv* env ATTRIBUTE_UNUSED, 855 jclass klass ATTRIBUTE_UNUSED, 856 jint x, 857 jint y) { 858 gJava_MyClassNatives_fooSII_calls[gCurrentJni]++; 859 return x + y; 860 } 861 862 void JniCompilerTest::CompileAndRunStaticIntIntMethodImpl() { 863 SetUpForTest(true, "fooSII", "(II)I", 864 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSII)); 865 866 EXPECT_EQ(0, gJava_MyClassNatives_fooSII_calls[gCurrentJni]); 867 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 20, 30); 868 EXPECT_EQ(50, result); 869 EXPECT_EQ(1, gJava_MyClassNatives_fooSII_calls[gCurrentJni]); 870 871 gJava_MyClassNatives_fooSII_calls[gCurrentJni] = 0; 872 } 873 874 JNI_TEST_CRITICAL(CompileAndRunStaticIntIntMethod) 875 876 int gJava_MyClassNatives_fooSDD_calls[kJniKindCount] = {}; 877 jdouble Java_MyClassNatives_fooSDD(JNIEnv* env ATTRIBUTE_UNUSED, 878 jclass klass ATTRIBUTE_UNUSED, 879 jdouble x, 880 jdouble y) { 881 gJava_MyClassNatives_fooSDD_calls[gCurrentJni]++; 882 return x - y; // non-commutative operator 883 } 884 885 void JniCompilerTest::CompileAndRunStaticDoubleDoubleMethodImpl() { 886 SetUpForTest(true, "fooSDD", "(DD)D", 887 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSDD)); 888 889 EXPECT_EQ(0, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]); 890 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 99.0, 10.0); 891 EXPECT_DOUBLE_EQ(99.0 - 10.0, result); 892 EXPECT_EQ(1, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]); 893 jdouble a = 3.14159265358979323846; 894 jdouble b = 0.69314718055994530942; 895 result = env_->CallStaticDoubleMethod(jklass_, jmethod_, a, b); 896 EXPECT_DOUBLE_EQ(a - b, result); 897 EXPECT_DOUBLE_EQ(2, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]); 898 899 gJava_MyClassNatives_fooSDD_calls[gCurrentJni] = 0; 900 } 901 902 JNI_TEST_CRITICAL(CompileAndRunStaticDoubleDoubleMethod) 903 904 // The x86 generic JNI code had a bug where it assumed a floating 905 // point return value would be in xmm0. We use log, to somehow ensure 906 // the compiler will use the floating point stack. 907 908 jdouble Java_MyClassNatives_logD(JNIEnv*, jclass, jdouble x) { 909 return log(x); 910 } 911 912 jdouble Java_MyClassNatives_logD_notNormal(JNIEnv*, jclass, jdouble x) { 913 EXPECT_DOUBLE_EQ(2.0, x); 914 return log(x); 915 } 916 917 void JniCompilerTest::RunStaticLogDoubleMethodImpl() { 918 void* jni_handler; 919 if (IsCurrentJniNormal()) { 920 // This test seems a bit special, don't use a JNI wrapper here. 921 jni_handler = NORMAL_JNI_ONLY_NOWRAP(Java_MyClassNatives_logD); 922 } else { 923 jni_handler = CURRENT_JNI_WRAPPER(Java_MyClassNatives_logD_notNormal); 924 } 925 SetUpForTest(true, "logD", "(D)D", jni_handler); 926 927 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 2.0); 928 EXPECT_DOUBLE_EQ(log(2.0), result); 929 } 930 931 JNI_TEST_CRITICAL(RunStaticLogDoubleMethod) 932 933 jfloat Java_MyClassNatives_logF(JNIEnv*, jclass, jfloat x) { 934 return logf(x); 935 } 936 937 void JniCompilerTest::RunStaticLogFloatMethodImpl() { 938 void* jni_handler; 939 if (IsCurrentJniNormal()) { 940 // This test seems a bit special, don't use a JNI wrapper here. 941 jni_handler = NORMAL_JNI_ONLY_NOWRAP(Java_MyClassNatives_logF); 942 } else { 943 jni_handler = CURRENT_JNI_WRAPPER(Java_MyClassNatives_logF); 944 } 945 946 SetUpForTest(true, "logF", "(F)F", jni_handler); 947 948 jfloat result = env_->CallStaticFloatMethod(jklass_, jmethod_, 2.0); 949 EXPECT_FLOAT_EQ(logf(2.0), result); 950 } 951 952 JNI_TEST_CRITICAL(RunStaticLogFloatMethod) 953 954 jboolean Java_MyClassNatives_returnTrue(JNIEnv*, jclass) { 955 return JNI_TRUE; 956 } 957 958 jboolean Java_MyClassNatives_returnFalse(JNIEnv*, jclass) { 959 return JNI_FALSE; 960 } 961 962 jint Java_MyClassNatives_returnInt(JNIEnv*, jclass) { 963 return 42; 964 } 965 966 void JniCompilerTest::RunStaticReturnTrueImpl() { 967 SetUpForTest(true, "returnTrue", "()Z", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnTrue)); 968 969 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_); 970 EXPECT_TRUE(result); 971 } 972 973 JNI_TEST_CRITICAL(RunStaticReturnTrue) 974 975 void JniCompilerTest::RunStaticReturnFalseImpl() { 976 SetUpForTest(true, "returnFalse", "()Z", 977 CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnFalse)); 978 979 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_); 980 EXPECT_FALSE(result); 981 } 982 983 JNI_TEST_CRITICAL(RunStaticReturnFalse) 984 985 void JniCompilerTest::RunGenericStaticReturnIntImpl() { 986 SetUpForTest(true, "returnInt", "()I", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnInt)); 987 988 jint result = env_->CallStaticIntMethod(jklass_, jmethod_); 989 EXPECT_EQ(42, result); 990 } 991 992 JNI_TEST_CRITICAL(RunGenericStaticReturnInt) 993 994 int gJava_MyClassNatives_returnDouble_calls[kJniKindCount] = {}; 995 jdouble Java_MyClassNatives_returnDouble(JNIEnv*, jclass) { 996 gJava_MyClassNatives_returnDouble_calls[gCurrentJni]++; 997 return 4.0; 998 } 999 1000 void JniCompilerTest::RunGenericStaticReturnDoubleImpl() { 1001 SetUpForTest(true, "returnDouble", "()D", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnDouble)); 1002 1003 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_); 1004 EXPECT_DOUBLE_EQ(4.0, result); 1005 EXPECT_EQ(1, gJava_MyClassNatives_returnDouble_calls[gCurrentJni]); 1006 1007 gJava_MyClassNatives_returnDouble_calls[gCurrentJni] = 0; 1008 } 1009 1010 JNI_TEST_CRITICAL(RunGenericStaticReturnDouble) 1011 1012 jlong Java_MyClassNatives_returnLong(JNIEnv*, jclass) { 1013 return 0xFEEDDEADFEEDL; 1014 } 1015 1016 void JniCompilerTest::RunGenericStaticReturnLongImpl() { 1017 SetUpForTest(true, "returnLong", "()J", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnLong)); 1018 1019 jlong result = env_->CallStaticLongMethod(jklass_, jmethod_); 1020 EXPECT_EQ(0xFEEDDEADFEEDL, result); 1021 } 1022 1023 JNI_TEST_CRITICAL(RunGenericStaticReturnLong) 1024 1025 int gJava_MyClassNatives_fooSIOO_calls[kJniKindCount] = {}; 1026 jobject Java_MyClassNatives_fooSIOO(JNIEnv*, jclass klass, jint x, jobject y, jobject z) { 1027 gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]++; 1028 switch (x) { 1029 case 1: 1030 return y; 1031 case 2: 1032 return z; 1033 default: 1034 return klass; 1035 } 1036 } 1037 1038 void JniCompilerTest::CompileAndRunStaticIntObjectObjectMethodImpl() { 1039 SetUpForTest(true, "fooSIOO", 1040 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 1041 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSIOO)); 1042 1043 EXPECT_EQ(0, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1044 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr); 1045 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1046 EXPECT_EQ(1, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1047 1048 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_); 1049 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1050 EXPECT_EQ(2, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1051 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_); 1052 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 1053 EXPECT_EQ(3, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1054 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_); 1055 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 1056 EXPECT_EQ(4, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1057 1058 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr); 1059 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1060 EXPECT_EQ(5, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1061 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr); 1062 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 1063 EXPECT_EQ(6, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1064 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr); 1065 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 1066 EXPECT_EQ(7, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]); 1067 1068 gJava_MyClassNatives_fooSIOO_calls[gCurrentJni] = 0; 1069 } 1070 1071 JNI_TEST(CompileAndRunStaticIntObjectObjectMethod) 1072 1073 int gJava_MyClassNatives_fooSSIOO_calls[kJniKindCount] = {}; 1074 jobject Java_MyClassNatives_fooSSIOO(JNIEnv*, jclass klass, jint x, jobject y, jobject z) { 1075 gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]++; 1076 switch (x) { 1077 case 1: 1078 return y; 1079 case 2: 1080 return z; 1081 default: 1082 return klass; 1083 } 1084 } 1085 1086 void JniCompilerTest::CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl() { 1087 SetUpForTest(true, "fooSSIOO", 1088 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", 1089 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSSIOO)); 1090 1091 EXPECT_EQ(0, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1092 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr); 1093 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1094 EXPECT_EQ(1, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1095 1096 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_); 1097 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1098 EXPECT_EQ(2, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1099 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_); 1100 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 1101 EXPECT_EQ(3, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1102 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_); 1103 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 1104 EXPECT_EQ(4, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1105 1106 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr); 1107 EXPECT_TRUE(env_->IsSameObject(jklass_, result)); 1108 EXPECT_EQ(5, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1109 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr); 1110 EXPECT_TRUE(env_->IsSameObject(jobj_, result)); 1111 EXPECT_EQ(6, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1112 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr); 1113 EXPECT_TRUE(env_->IsSameObject(nullptr, result)); 1114 EXPECT_EQ(7, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]); 1115 1116 gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni] = 0; 1117 } 1118 1119 // TODO: Maybe. @FastNative support for returning Objects? 1120 JNI_TEST_NORMAL_ONLY(CompileAndRunStaticSynchronizedIntObjectObjectMethod) 1121 1122 void Java_MyClassNatives_throwException(JNIEnv* env, jobject) { 1123 jclass c = env->FindClass("java/lang/RuntimeException"); 1124 env->ThrowNew(c, "hello"); 1125 } 1126 1127 void JniCompilerTest::ExceptionHandlingImpl() { 1128 { 1129 ASSERT_FALSE(runtime_->IsStarted()); 1130 ScopedObjectAccess soa(Thread::Current()); 1131 class_loader_ = LoadDex("MyClassNatives"); 1132 1133 // all compilation needs to happen before Runtime::Start 1134 CompileForTestWithCurrentJni(class_loader_, false, "foo", "()V"); 1135 CompileForTestWithCurrentJni(class_loader_, false, "throwException", "()V"); 1136 CompileForTestWithCurrentJni(class_loader_, false, "foo", "()V"); 1137 } 1138 // Start runtime to avoid re-initialization in SetupForTest. 1139 Thread::Current()->TransitionFromSuspendedToRunnable(); 1140 bool started = runtime_->Start(); 1141 CHECK(started); 1142 1143 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0; 1144 1145 // Check a single call of a JNI method is ok 1146 SetUpForTest(false, "foo", "()V", CURRENT_JNI_WRAPPER(Java_MyClassNatives_foo)); 1147 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 1148 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]); 1149 EXPECT_FALSE(Thread::Current()->IsExceptionPending()); 1150 1151 // Get class for exception we expect to be thrown 1152 ScopedLocalRef<jclass> jlre(env_, env_->FindClass("java/lang/RuntimeException")); 1153 SetUpForTest(false, "throwException", "()V", 1154 CURRENT_JNI_WRAPPER(Java_MyClassNatives_throwException)); 1155 // Call Java_MyClassNatives_throwException (JNI method that throws exception) 1156 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 1157 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]); 1158 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 1159 ScopedLocalRef<jthrowable> exception(env_, env_->ExceptionOccurred()); 1160 env_->ExceptionClear(); 1161 EXPECT_TRUE(env_->IsInstanceOf(exception.get(), jlre.get())); 1162 1163 // Check a single call of a JNI method is ok 1164 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo)); 1165 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_); 1166 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls[gCurrentJni]); 1167 1168 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0; 1169 } 1170 1171 JNI_TEST(ExceptionHandling) 1172 1173 jint Java_MyClassNatives_nativeUpCall(JNIEnv* env, jobject thisObj, jint i) { 1174 if (i <= 0) { 1175 // We want to check raw Object* / Array* below 1176 ScopedObjectAccess soa(env); 1177 1178 // Build stack trace 1179 jobject internal = Thread::Current()->CreateInternalStackTrace<false>(soa); 1180 jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal); 1181 ObjPtr<mirror::ObjectArray<mirror::StackTraceElement>> trace_array = 1182 soa.Decode<mirror::ObjectArray<mirror::StackTraceElement>>(ste_array); 1183 EXPECT_TRUE(trace_array != nullptr); 1184 EXPECT_EQ(11, trace_array->GetLength()); 1185 1186 // Check stack trace entries have expected values 1187 for (int32_t j = 0; j < trace_array->GetLength(); ++j) { 1188 EXPECT_EQ(-2, trace_array->Get(j)->GetLineNumber()); 1189 mirror::StackTraceElement* ste = trace_array->Get(j); 1190 EXPECT_STREQ("MyClassNatives.java", ste->GetFileName()->ToModifiedUtf8().c_str()); 1191 EXPECT_STREQ("MyClassNatives", ste->GetDeclaringClass()->ToModifiedUtf8().c_str()); 1192 EXPECT_EQ(("fooI" + CurrentJniStringSuffix()), ste->GetMethodName()->ToModifiedUtf8()); 1193 } 1194 1195 // end recursion 1196 return 0; 1197 } else { 1198 jclass jklass = env->FindClass("MyClassNatives"); 1199 EXPECT_TRUE(jklass != nullptr); 1200 jmethodID jmethod = env->GetMethodID(jklass, 1201 ("fooI" + CurrentJniStringSuffix()).c_str(), 1202 "(I)I"); 1203 EXPECT_TRUE(jmethod != nullptr); 1204 1205 // Recurse with i - 1 1206 jint result = env->CallNonvirtualIntMethod(thisObj, jklass, jmethod, i - 1); 1207 1208 // Return sum of all depths 1209 return i + result; 1210 } 1211 } 1212 1213 void JniCompilerTest::NativeStackTraceElementImpl() { 1214 SetUpForTest(false, "fooI", "(I)I", 1215 CURRENT_JNI_WRAPPER(Java_MyClassNatives_nativeUpCall)); 1216 1217 // Usual # local references on stack check fails because nativeUpCall calls itself recursively, 1218 // each time the # of local references will therefore go up. 1219 ScopedDisableCheckNumStackReferences disable_num_stack_check; 1220 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 10); 1221 1222 EXPECT_EQ(10+9+8+7+6+5+4+3+2+1, result); 1223 } 1224 1225 JNI_TEST(NativeStackTraceElement) 1226 1227 jobject Java_MyClassNatives_fooO(JNIEnv* env, jobject, jobject x) { 1228 return env->NewGlobalRef(x); 1229 } 1230 1231 void JniCompilerTest::ReturnGlobalRefImpl() { 1232 SetUpForTest(false, "fooO", "(Ljava/lang/Object;)Ljava/lang/Object;", 1233 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooO)); 1234 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, jobj_); 1235 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(result)); 1236 EXPECT_TRUE(env_->IsSameObject(result, jobj_)); 1237 } 1238 1239 JNI_TEST(ReturnGlobalRef) 1240 1241 jint local_ref_test(JNIEnv* env, jobject thisObj, jint x) { 1242 // Add 10 local references 1243 ScopedObjectAccess soa(env); 1244 for (int i = 0; i < 10; i++) { 1245 soa.AddLocalReference<jobject>(soa.Decode<mirror::Object>(thisObj)); 1246 } 1247 return x+1; 1248 } 1249 1250 void JniCompilerTest::LocalReferenceTableClearingTestImpl() { 1251 SetUpForTest(false, "fooI", "(I)I", CURRENT_JNI_WRAPPER(local_ref_test)); 1252 // 1000 invocations of a method that adds 10 local references 1253 for (int i = 0; i < 1000; i++) { 1254 jint result = env_->CallIntMethod(jobj_, jmethod_, i); 1255 EXPECT_TRUE(result == i + 1); 1256 } 1257 } 1258 1259 JNI_TEST(LocalReferenceTableClearingTest) 1260 1261 void my_arraycopy(JNIEnv* env, jclass klass, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) { 1262 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, klass)); 1263 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, dst)); 1264 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, src)); 1265 EXPECT_EQ(1234, src_pos); 1266 EXPECT_EQ(5678, dst_pos); 1267 EXPECT_EQ(9876, length); 1268 } 1269 1270 void JniCompilerTest::JavaLangSystemArrayCopyImpl() { 1271 SetUpForTest(true, "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", 1272 CURRENT_JNI_WRAPPER(my_arraycopy)); 1273 env_->CallStaticVoidMethod(jklass_, jmethod_, jobj_, 1234, jklass_, 5678, 9876); 1274 } 1275 1276 JNI_TEST(JavaLangSystemArrayCopy) 1277 1278 jboolean my_casi(JNIEnv* env, jobject unsafe, jobject obj, jlong offset, jint expected, jint newval) { 1279 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, unsafe)); 1280 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj)); 1281 EXPECT_EQ(INT64_C(0x12345678ABCDEF88), offset); 1282 EXPECT_EQ(static_cast<jint>(0xCAFEF00D), expected); 1283 EXPECT_EQ(static_cast<jint>(0xEBADF00D), newval); 1284 return JNI_TRUE; 1285 } 1286 1287 void JniCompilerTest::CompareAndSwapIntImpl() { 1288 SetUpForTest(false, "compareAndSwapInt", "(Ljava/lang/Object;JII)Z", 1289 CURRENT_JNI_WRAPPER(my_casi)); 1290 jboolean result = env_->CallBooleanMethod(jobj_, jmethod_, jobj_, INT64_C(0x12345678ABCDEF88), 1291 0xCAFEF00D, 0xEBADF00D); 1292 EXPECT_EQ(result, JNI_TRUE); 1293 } 1294 1295 JNI_TEST(CompareAndSwapInt) 1296 1297 jint my_gettext(JNIEnv* env, jclass klass, jlong val1, jobject obj1, jlong val2, jobject obj2) { 1298 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass)); 1299 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj1)); 1300 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj2)); 1301 EXPECT_EQ(0x12345678ABCDEF88ll, val1); 1302 EXPECT_EQ(0x7FEDCBA987654321ll, val2); 1303 return 42; 1304 } 1305 1306 void JniCompilerTest::GetTextImpl() { 1307 SetUpForTest(true, "getText", "(JLjava/lang/Object;JLjava/lang/Object;)I", 1308 CURRENT_JNI_WRAPPER(my_gettext)); 1309 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 0x12345678ABCDEF88ll, jobj_, 1310 INT64_C(0x7FEDCBA987654321), jobj_); 1311 EXPECT_EQ(result, 42); 1312 } 1313 1314 JNI_TEST(GetText) 1315 1316 int gJava_MyClassNatives_GetSinkProperties_calls[kJniKindCount] = {}; 1317 jarray Java_MyClassNatives_GetSinkProperties(JNIEnv*, jobject thisObj, jstring s) { 1318 EXPECT_EQ(s, nullptr); 1319 gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]++; 1320 1321 Thread* self = Thread::Current(); 1322 ScopedObjectAccess soa(self); 1323 EXPECT_TRUE(self->HoldsLock(soa.Decode<mirror::Object>(thisObj).Ptr())); 1324 return nullptr; 1325 } 1326 1327 void JniCompilerTest::GetSinkPropertiesNativeImpl() { 1328 SetUpForTest(false, "getSinkPropertiesNative", "(Ljava/lang/String;)[Ljava/lang/Object;", 1329 CURRENT_JNI_WRAPPER(Java_MyClassNatives_GetSinkProperties)); 1330 1331 EXPECT_EQ(0, gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]); 1332 jarray result = down_cast<jarray>( 1333 env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, nullptr)); 1334 EXPECT_EQ(nullptr, result); 1335 EXPECT_EQ(1, gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]); 1336 1337 gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni] = 0; 1338 } 1339 1340 // @FastNative doesn't support 'synchronized' keyword and 1341 // never will -- locking functions aren't fast. 1342 JNI_TEST_NORMAL_ONLY(GetSinkPropertiesNative) 1343 1344 // This should return jclass, but we're imitating a bug pattern. 1345 jobject Java_MyClassNatives_instanceMethodThatShouldReturnClass(JNIEnv* env, jobject) { 1346 return env->NewStringUTF("not a class!"); 1347 } 1348 1349 // This should return jclass, but we're imitating a bug pattern. 1350 jobject Java_MyClassNatives_staticMethodThatShouldReturnClass(JNIEnv* env, jclass) { 1351 return env->NewStringUTF("not a class!"); 1352 } 1353 1354 void JniCompilerTest::UpcallReturnTypeChecking_InstanceImpl() { 1355 SetUpForTest(false, "instanceMethodThatShouldReturnClass", "()Ljava/lang/Class;", 1356 CURRENT_JNI_WRAPPER(Java_MyClassNatives_instanceMethodThatShouldReturnClass)); 1357 1358 CheckJniAbortCatcher check_jni_abort_catcher; 1359 // This native method is bad, and tries to return a jstring as a jclass. 1360 env_->CallObjectMethod(jobj_, jmethod_); 1361 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " + 1362 "of java.lang.String from java.lang.Class " + 1363 "MyClassNatives.instanceMethodThatShouldReturnClass" + 1364 CurrentJniStringSuffix() + "()"); 1365 1366 // Here, we just call the method incorrectly; we should catch that too. 1367 env_->CallObjectMethod(jobj_, jmethod_); 1368 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " + 1369 "of java.lang.String from java.lang.Class " + 1370 "MyClassNatives.instanceMethodThatShouldReturnClass" + 1371 CurrentJniStringSuffix() + "()"); 1372 env_->CallStaticObjectMethod(jklass_, jmethod_); 1373 check_jni_abort_catcher.Check(std::string() + "calling non-static method " + 1374 "java.lang.Class " + 1375 "MyClassNatives.instanceMethodThatShouldReturnClass" + 1376 CurrentJniStringSuffix() + "() with CallStaticObjectMethodV"); 1377 } 1378 1379 JNI_TEST(UpcallReturnTypeChecking_Instance) 1380 1381 void JniCompilerTest::UpcallReturnTypeChecking_StaticImpl() { 1382 SetUpForTest(true, "staticMethodThatShouldReturnClass", "()Ljava/lang/Class;", 1383 CURRENT_JNI_WRAPPER(Java_MyClassNatives_staticMethodThatShouldReturnClass)); 1384 1385 CheckJniAbortCatcher check_jni_abort_catcher; 1386 // This native method is bad, and tries to return a jstring as a jclass. 1387 env_->CallStaticObjectMethod(jklass_, jmethod_); 1388 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " + 1389 "of java.lang.String from java.lang.Class " + 1390 "MyClassNatives.staticMethodThatShouldReturnClass" + 1391 CurrentJniStringSuffix() + "()"); 1392 1393 // Here, we just call the method incorrectly; we should catch that too. 1394 env_->CallStaticObjectMethod(jklass_, jmethod_); 1395 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " + 1396 "of java.lang.String from java.lang.Class " + 1397 "MyClassNatives.staticMethodThatShouldReturnClass" + 1398 CurrentJniStringSuffix() + "()"); 1399 env_->CallObjectMethod(jobj_, jmethod_); 1400 check_jni_abort_catcher.Check(std::string() + "calling static method " + 1401 "java.lang.Class " + 1402 "MyClassNatives.staticMethodThatShouldReturnClass" + 1403 CurrentJniStringSuffix() + "() with CallObjectMethodV"); 1404 } 1405 1406 JNI_TEST(UpcallReturnTypeChecking_Static) 1407 1408 // This should take jclass, but we're imitating a bug pattern. 1409 void Java_MyClassNatives_instanceMethodThatShouldTakeClass(JNIEnv*, jobject, jclass) { 1410 } 1411 1412 // This should take jclass, but we're imitating a bug pattern. 1413 void Java_MyClassNatives_staticMethodThatShouldTakeClass(JNIEnv*, jclass, jclass) { 1414 } 1415 1416 void JniCompilerTest::UpcallArgumentTypeChecking_InstanceImpl() { 1417 // This will lead to error messages in the log. 1418 ScopedLogSeverity sls(LogSeverity::FATAL); 1419 1420 SetUpForTest(false, "instanceMethodThatShouldTakeClass", "(ILjava/lang/Class;)V", 1421 CURRENT_JNI_WRAPPER(Java_MyClassNatives_instanceMethodThatShouldTakeClass)); 1422 1423 CheckJniAbortCatcher check_jni_abort_catcher; 1424 // We deliberately pass a bad second argument here. 1425 env_->CallVoidMethod(jobj_, jmethod_, 123, env_->NewStringUTF("not a class!")); 1426 check_jni_abort_catcher.Check(std::string() + "bad arguments passed to void " + 1427 "MyClassNatives.instanceMethodThatShouldTakeClass" + 1428 CurrentJniStringSuffix() + "(int, java.lang.Class)"); 1429 } 1430 1431 JNI_TEST(UpcallArgumentTypeChecking_Instance) 1432 1433 void JniCompilerTest::UpcallArgumentTypeChecking_StaticImpl() { 1434 // This will lead to error messages in the log. 1435 ScopedLogSeverity sls(LogSeverity::FATAL); 1436 1437 SetUpForTest(true, "staticMethodThatShouldTakeClass", "(ILjava/lang/Class;)V", 1438 CURRENT_JNI_WRAPPER(Java_MyClassNatives_staticMethodThatShouldTakeClass)); 1439 1440 CheckJniAbortCatcher check_jni_abort_catcher; 1441 // We deliberately pass a bad second argument here. 1442 env_->CallStaticVoidMethod(jklass_, jmethod_, 123, env_->NewStringUTF("not a class!")); 1443 check_jni_abort_catcher.Check(std::string() + "bad arguments passed to void " + 1444 "MyClassNatives.staticMethodThatShouldTakeClass" + 1445 CurrentJniStringSuffix() + "(int, java.lang.Class)"); 1446 } 1447 1448 JNI_TEST(UpcallArgumentTypeChecking_Static) 1449 1450 jfloat Java_MyClassNatives_checkFloats(JNIEnv*, jobject, jfloat f1, jfloat f2) { 1451 return f1 - f2; // non-commutative operator 1452 } 1453 1454 void JniCompilerTest::CompileAndRunFloatFloatMethodImpl() { 1455 SetUpForTest(false, "checkFloats", "(FF)F", 1456 CURRENT_JNI_WRAPPER(Java_MyClassNatives_checkFloats)); 1457 1458 jfloat result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, 1459 99.0F, 10.0F); 1460 EXPECT_FLOAT_EQ(99.0F - 10.0F, result); 1461 jfloat a = 3.14159F; 1462 jfloat b = 0.69314F; 1463 result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, a, b); 1464 EXPECT_FLOAT_EQ(a - b, result); 1465 } 1466 1467 JNI_TEST(CompileAndRunFloatFloatMethod) 1468 1469 void Java_MyClassNatives_checkParameterAlign(JNIEnv* env ATTRIBUTE_UNUSED, 1470 jobject thisObj ATTRIBUTE_UNUSED, 1471 jint i1, 1472 jlong l1) { 1473 EXPECT_EQ(i1, 1234); 1474 EXPECT_EQ(l1, INT64_C(0x12345678ABCDEF0)); 1475 } 1476 1477 void JniCompilerTest::CheckParameterAlignImpl() { 1478 SetUpForTest(false, "checkParameterAlign", "(IJ)V", 1479 CURRENT_JNI_WRAPPER(Java_MyClassNatives_checkParameterAlign)); 1480 1481 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_, 1234, INT64_C(0x12345678ABCDEF0)); 1482 } 1483 1484 JNI_TEST(CheckParameterAlign) 1485 1486 void Java_MyClassNatives_maxParamNumber(JNIEnv* env, jobject, 1487 jobject o0, jobject o1, jobject o2, jobject o3, jobject o4, jobject o5, jobject o6, jobject o7, 1488 jobject o8, jobject o9, jobject o10, jobject o11, jobject o12, jobject o13, jobject o14, jobject o15, 1489 jobject o16, jobject o17, jobject o18, jobject o19, jobject o20, jobject o21, jobject o22, jobject o23, 1490 jobject o24, jobject o25, jobject o26, jobject o27, jobject o28, jobject o29, jobject o30, jobject o31, 1491 jobject o32, jobject o33, jobject o34, jobject o35, jobject o36, jobject o37, jobject o38, jobject o39, 1492 jobject o40, jobject o41, jobject o42, jobject o43, jobject o44, jobject o45, jobject o46, jobject o47, 1493 jobject o48, jobject o49, jobject o50, jobject o51, jobject o52, jobject o53, jobject o54, jobject o55, 1494 jobject o56, jobject o57, jobject o58, jobject o59, jobject o60, jobject o61, jobject o62, jobject o63, 1495 jobject o64, jobject o65, jobject o66, jobject o67, jobject o68, jobject o69, jobject o70, jobject o71, 1496 jobject o72, jobject o73, jobject o74, jobject o75, jobject o76, jobject o77, jobject o78, jobject o79, 1497 jobject o80, jobject o81, jobject o82, jobject o83, jobject o84, jobject o85, jobject o86, jobject o87, 1498 jobject o88, jobject o89, jobject o90, jobject o91, jobject o92, jobject o93, jobject o94, jobject o95, 1499 jobject o96, jobject o97, jobject o98, jobject o99, jobject o100, jobject o101, jobject o102, jobject o103, 1500 jobject o104, jobject o105, jobject o106, jobject o107, jobject o108, jobject o109, jobject o110, jobject o111, 1501 jobject o112, jobject o113, jobject o114, jobject o115, jobject o116, jobject o117, jobject o118, jobject o119, 1502 jobject o120, jobject o121, jobject o122, jobject o123, jobject o124, jobject o125, jobject o126, jobject o127, 1503 jobject o128, jobject o129, jobject o130, jobject o131, jobject o132, jobject o133, jobject o134, jobject o135, 1504 jobject o136, jobject o137, jobject o138, jobject o139, jobject o140, jobject o141, jobject o142, jobject o143, 1505 jobject o144, jobject o145, jobject o146, jobject o147, jobject o148, jobject o149, jobject o150, jobject o151, 1506 jobject o152, jobject o153, jobject o154, jobject o155, jobject o156, jobject o157, jobject o158, jobject o159, 1507 jobject o160, jobject o161, jobject o162, jobject o163, jobject o164, jobject o165, jobject o166, jobject o167, 1508 jobject o168, jobject o169, jobject o170, jobject o171, jobject o172, jobject o173, jobject o174, jobject o175, 1509 jobject o176, jobject o177, jobject o178, jobject o179, jobject o180, jobject o181, jobject o182, jobject o183, 1510 jobject o184, jobject o185, jobject o186, jobject o187, jobject o188, jobject o189, jobject o190, jobject o191, 1511 jobject o192, jobject o193, jobject o194, jobject o195, jobject o196, jobject o197, jobject o198, jobject o199, 1512 jobject o200, jobject o201, jobject o202, jobject o203, jobject o204, jobject o205, jobject o206, jobject o207, 1513 jobject o208, jobject o209, jobject o210, jobject o211, jobject o212, jobject o213, jobject o214, jobject o215, 1514 jobject o216, jobject o217, jobject o218, jobject o219, jobject o220, jobject o221, jobject o222, jobject o223, 1515 jobject o224, jobject o225, jobject o226, jobject o227, jobject o228, jobject o229, jobject o230, jobject o231, 1516 jobject o232, jobject o233, jobject o234, jobject o235, jobject o236, jobject o237, jobject o238, jobject o239, 1517 jobject o240, jobject o241, jobject o242, jobject o243, jobject o244, jobject o245, jobject o246, jobject o247, 1518 jobject o248, jobject o249, jobject o250, jobject o251, jobject o252, jobject o253) { 1519 // two tests possible 1520 if (o0 == nullptr) { 1521 // 1) everything is null 1522 EXPECT_TRUE(o0 == nullptr && o1 == nullptr && o2 == nullptr && o3 == nullptr && o4 == nullptr 1523 && o5 == nullptr && o6 == nullptr && o7 == nullptr && o8 == nullptr && o9 == nullptr 1524 && o10 == nullptr && o11 == nullptr && o12 == nullptr && o13 == nullptr && o14 == nullptr 1525 && o15 == nullptr && o16 == nullptr && o17 == nullptr && o18 == nullptr && o19 == nullptr 1526 && o20 == nullptr && o21 == nullptr && o22 == nullptr && o23 == nullptr && o24 == nullptr 1527 && o25 == nullptr && o26 == nullptr && o27 == nullptr && o28 == nullptr && o29 == nullptr 1528 && o30 == nullptr && o31 == nullptr && o32 == nullptr && o33 == nullptr && o34 == nullptr 1529 && o35 == nullptr && o36 == nullptr && o37 == nullptr && o38 == nullptr && o39 == nullptr 1530 && o40 == nullptr && o41 == nullptr && o42 == nullptr && o43 == nullptr && o44 == nullptr 1531 && o45 == nullptr && o46 == nullptr && o47 == nullptr && o48 == nullptr && o49 == nullptr 1532 && o50 == nullptr && o51 == nullptr && o52 == nullptr && o53 == nullptr && o54 == nullptr 1533 && o55 == nullptr && o56 == nullptr && o57 == nullptr && o58 == nullptr && o59 == nullptr 1534 && o60 == nullptr && o61 == nullptr && o62 == nullptr && o63 == nullptr && o64 == nullptr 1535 && o65 == nullptr && o66 == nullptr && o67 == nullptr && o68 == nullptr && o69 == nullptr 1536 && o70 == nullptr && o71 == nullptr && o72 == nullptr && o73 == nullptr && o74 == nullptr 1537 && o75 == nullptr && o76 == nullptr && o77 == nullptr && o78 == nullptr && o79 == nullptr 1538 && o80 == nullptr && o81 == nullptr && o82 == nullptr && o83 == nullptr && o84 == nullptr 1539 && o85 == nullptr && o86 == nullptr && o87 == nullptr && o88 == nullptr && o89 == nullptr 1540 && o90 == nullptr && o91 == nullptr && o92 == nullptr && o93 == nullptr && o94 == nullptr 1541 && o95 == nullptr && o96 == nullptr && o97 == nullptr && o98 == nullptr && o99 == nullptr 1542 && o100 == nullptr && o101 == nullptr && o102 == nullptr && o103 == nullptr && o104 == nullptr 1543 && o105 == nullptr && o106 == nullptr && o107 == nullptr && o108 == nullptr && o109 == nullptr 1544 && o110 == nullptr && o111 == nullptr && o112 == nullptr && o113 == nullptr && o114 == nullptr 1545 && o115 == nullptr && o116 == nullptr && o117 == nullptr && o118 == nullptr && o119 == nullptr 1546 && o120 == nullptr && o121 == nullptr && o122 == nullptr && o123 == nullptr && o124 == nullptr 1547 && o125 == nullptr && o126 == nullptr && o127 == nullptr && o128 == nullptr && o129 == nullptr 1548 && o130 == nullptr && o131 == nullptr && o132 == nullptr && o133 == nullptr && o134 == nullptr 1549 && o135 == nullptr && o136 == nullptr && o137 == nullptr && o138 == nullptr && o139 == nullptr 1550 && o140 == nullptr && o141 == nullptr && o142 == nullptr && o143 == nullptr && o144 == nullptr 1551 && o145 == nullptr && o146 == nullptr && o147 == nullptr && o148 == nullptr && o149 == nullptr 1552 && o150 == nullptr && o151 == nullptr && o152 == nullptr && o153 == nullptr && o154 == nullptr 1553 && o155 == nullptr && o156 == nullptr && o157 == nullptr && o158 == nullptr && o159 == nullptr 1554 && o160 == nullptr && o161 == nullptr && o162 == nullptr && o163 == nullptr && o164 == nullptr 1555 && o165 == nullptr && o166 == nullptr && o167 == nullptr && o168 == nullptr && o169 == nullptr 1556 && o170 == nullptr && o171 == nullptr && o172 == nullptr && o173 == nullptr && o174 == nullptr 1557 && o175 == nullptr && o176 == nullptr && o177 == nullptr && o178 == nullptr && o179 == nullptr 1558 && o180 == nullptr && o181 == nullptr && o182 == nullptr && o183 == nullptr && o184 == nullptr 1559 && o185 == nullptr && o186 == nullptr && o187 == nullptr && o188 == nullptr && o189 == nullptr 1560 && o190 == nullptr && o191 == nullptr && o192 == nullptr && o193 == nullptr && o194 == nullptr 1561 && o195 == nullptr && o196 == nullptr && o197 == nullptr && o198 == nullptr && o199 == nullptr 1562 && o200 == nullptr && o201 == nullptr && o202 == nullptr && o203 == nullptr && o204 == nullptr 1563 && o205 == nullptr && o206 == nullptr && o207 == nullptr && o208 == nullptr && o209 == nullptr 1564 && o210 == nullptr && o211 == nullptr && o212 == nullptr && o213 == nullptr && o214 == nullptr 1565 && o215 == nullptr && o216 == nullptr && o217 == nullptr && o218 == nullptr && o219 == nullptr 1566 && o220 == nullptr && o221 == nullptr && o222 == nullptr && o223 == nullptr && o224 == nullptr 1567 && o225 == nullptr && o226 == nullptr && o227 == nullptr && o228 == nullptr && o229 == nullptr 1568 && o230 == nullptr && o231 == nullptr && o232 == nullptr && o233 == nullptr && o234 == nullptr 1569 && o235 == nullptr && o236 == nullptr && o237 == nullptr && o238 == nullptr && o239 == nullptr 1570 && o240 == nullptr && o241 == nullptr && o242 == nullptr && o243 == nullptr && o244 == nullptr 1571 && o245 == nullptr && o246 == nullptr && o247 == nullptr && o248 == nullptr && o249 == nullptr 1572 && o250 == nullptr && o251 == nullptr && o252 == nullptr && o253 == nullptr); 1573 } else { 1574 EXPECT_EQ(0, env->GetArrayLength(reinterpret_cast<jarray>(o0))); 1575 EXPECT_EQ(1, env->GetArrayLength(reinterpret_cast<jarray>(o1))); 1576 EXPECT_EQ(2, env->GetArrayLength(reinterpret_cast<jarray>(o2))); 1577 EXPECT_EQ(3, env->GetArrayLength(reinterpret_cast<jarray>(o3))); 1578 EXPECT_EQ(4, env->GetArrayLength(reinterpret_cast<jarray>(o4))); 1579 EXPECT_EQ(5, env->GetArrayLength(reinterpret_cast<jarray>(o5))); 1580 EXPECT_EQ(6, env->GetArrayLength(reinterpret_cast<jarray>(o6))); 1581 EXPECT_EQ(7, env->GetArrayLength(reinterpret_cast<jarray>(o7))); 1582 EXPECT_EQ(8, env->GetArrayLength(reinterpret_cast<jarray>(o8))); 1583 EXPECT_EQ(9, env->GetArrayLength(reinterpret_cast<jarray>(o9))); 1584 EXPECT_EQ(10, env->GetArrayLength(reinterpret_cast<jarray>(o10))); 1585 EXPECT_EQ(11, env->GetArrayLength(reinterpret_cast<jarray>(o11))); 1586 EXPECT_EQ(12, env->GetArrayLength(reinterpret_cast<jarray>(o12))); 1587 EXPECT_EQ(13, env->GetArrayLength(reinterpret_cast<jarray>(o13))); 1588 EXPECT_EQ(14, env->GetArrayLength(reinterpret_cast<jarray>(o14))); 1589 EXPECT_EQ(15, env->GetArrayLength(reinterpret_cast<jarray>(o15))); 1590 EXPECT_EQ(16, env->GetArrayLength(reinterpret_cast<jarray>(o16))); 1591 EXPECT_EQ(17, env->GetArrayLength(reinterpret_cast<jarray>(o17))); 1592 EXPECT_EQ(18, env->GetArrayLength(reinterpret_cast<jarray>(o18))); 1593 EXPECT_EQ(19, env->GetArrayLength(reinterpret_cast<jarray>(o19))); 1594 EXPECT_EQ(20, env->GetArrayLength(reinterpret_cast<jarray>(o20))); 1595 EXPECT_EQ(21, env->GetArrayLength(reinterpret_cast<jarray>(o21))); 1596 EXPECT_EQ(22, env->GetArrayLength(reinterpret_cast<jarray>(o22))); 1597 EXPECT_EQ(23, env->GetArrayLength(reinterpret_cast<jarray>(o23))); 1598 EXPECT_EQ(24, env->GetArrayLength(reinterpret_cast<jarray>(o24))); 1599 EXPECT_EQ(25, env->GetArrayLength(reinterpret_cast<jarray>(o25))); 1600 EXPECT_EQ(26, env->GetArrayLength(reinterpret_cast<jarray>(o26))); 1601 EXPECT_EQ(27, env->GetArrayLength(reinterpret_cast<jarray>(o27))); 1602 EXPECT_EQ(28, env->GetArrayLength(reinterpret_cast<jarray>(o28))); 1603 EXPECT_EQ(29, env->GetArrayLength(reinterpret_cast<jarray>(o29))); 1604 EXPECT_EQ(30, env->GetArrayLength(reinterpret_cast<jarray>(o30))); 1605 EXPECT_EQ(31, env->GetArrayLength(reinterpret_cast<jarray>(o31))); 1606 EXPECT_EQ(32, env->GetArrayLength(reinterpret_cast<jarray>(o32))); 1607 EXPECT_EQ(33, env->GetArrayLength(reinterpret_cast<jarray>(o33))); 1608 EXPECT_EQ(34, env->GetArrayLength(reinterpret_cast<jarray>(o34))); 1609 EXPECT_EQ(35, env->GetArrayLength(reinterpret_cast<jarray>(o35))); 1610 EXPECT_EQ(36, env->GetArrayLength(reinterpret_cast<jarray>(o36))); 1611 EXPECT_EQ(37, env->GetArrayLength(reinterpret_cast<jarray>(o37))); 1612 EXPECT_EQ(38, env->GetArrayLength(reinterpret_cast<jarray>(o38))); 1613 EXPECT_EQ(39, env->GetArrayLength(reinterpret_cast<jarray>(o39))); 1614 EXPECT_EQ(40, env->GetArrayLength(reinterpret_cast<jarray>(o40))); 1615 EXPECT_EQ(41, env->GetArrayLength(reinterpret_cast<jarray>(o41))); 1616 EXPECT_EQ(42, env->GetArrayLength(reinterpret_cast<jarray>(o42))); 1617 EXPECT_EQ(43, env->GetArrayLength(reinterpret_cast<jarray>(o43))); 1618 EXPECT_EQ(44, env->GetArrayLength(reinterpret_cast<jarray>(o44))); 1619 EXPECT_EQ(45, env->GetArrayLength(reinterpret_cast<jarray>(o45))); 1620 EXPECT_EQ(46, env->GetArrayLength(reinterpret_cast<jarray>(o46))); 1621 EXPECT_EQ(47, env->GetArrayLength(reinterpret_cast<jarray>(o47))); 1622 EXPECT_EQ(48, env->GetArrayLength(reinterpret_cast<jarray>(o48))); 1623 EXPECT_EQ(49, env->GetArrayLength(reinterpret_cast<jarray>(o49))); 1624 EXPECT_EQ(50, env->GetArrayLength(reinterpret_cast<jarray>(o50))); 1625 EXPECT_EQ(51, env->GetArrayLength(reinterpret_cast<jarray>(o51))); 1626 EXPECT_EQ(52, env->GetArrayLength(reinterpret_cast<jarray>(o52))); 1627 EXPECT_EQ(53, env->GetArrayLength(reinterpret_cast<jarray>(o53))); 1628 EXPECT_EQ(54, env->GetArrayLength(reinterpret_cast<jarray>(o54))); 1629 EXPECT_EQ(55, env->GetArrayLength(reinterpret_cast<jarray>(o55))); 1630 EXPECT_EQ(56, env->GetArrayLength(reinterpret_cast<jarray>(o56))); 1631 EXPECT_EQ(57, env->GetArrayLength(reinterpret_cast<jarray>(o57))); 1632 EXPECT_EQ(58, env->GetArrayLength(reinterpret_cast<jarray>(o58))); 1633 EXPECT_EQ(59, env->GetArrayLength(reinterpret_cast<jarray>(o59))); 1634 EXPECT_EQ(60, env->GetArrayLength(reinterpret_cast<jarray>(o60))); 1635 EXPECT_EQ(61, env->GetArrayLength(reinterpret_cast<jarray>(o61))); 1636 EXPECT_EQ(62, env->GetArrayLength(reinterpret_cast<jarray>(o62))); 1637 EXPECT_EQ(63, env->GetArrayLength(reinterpret_cast<jarray>(o63))); 1638 EXPECT_EQ(64, env->GetArrayLength(reinterpret_cast<jarray>(o64))); 1639 EXPECT_EQ(65, env->GetArrayLength(reinterpret_cast<jarray>(o65))); 1640 EXPECT_EQ(66, env->GetArrayLength(reinterpret_cast<jarray>(o66))); 1641 EXPECT_EQ(67, env->GetArrayLength(reinterpret_cast<jarray>(o67))); 1642 EXPECT_EQ(68, env->GetArrayLength(reinterpret_cast<jarray>(o68))); 1643 EXPECT_EQ(69, env->GetArrayLength(reinterpret_cast<jarray>(o69))); 1644 EXPECT_EQ(70, env->GetArrayLength(reinterpret_cast<jarray>(o70))); 1645 EXPECT_EQ(71, env->GetArrayLength(reinterpret_cast<jarray>(o71))); 1646 EXPECT_EQ(72, env->GetArrayLength(reinterpret_cast<jarray>(o72))); 1647 EXPECT_EQ(73, env->GetArrayLength(reinterpret_cast<jarray>(o73))); 1648 EXPECT_EQ(74, env->GetArrayLength(reinterpret_cast<jarray>(o74))); 1649 EXPECT_EQ(75, env->GetArrayLength(reinterpret_cast<jarray>(o75))); 1650 EXPECT_EQ(76, env->GetArrayLength(reinterpret_cast<jarray>(o76))); 1651 EXPECT_EQ(77, env->GetArrayLength(reinterpret_cast<jarray>(o77))); 1652 EXPECT_EQ(78, env->GetArrayLength(reinterpret_cast<jarray>(o78))); 1653 EXPECT_EQ(79, env->GetArrayLength(reinterpret_cast<jarray>(o79))); 1654 EXPECT_EQ(80, env->GetArrayLength(reinterpret_cast<jarray>(o80))); 1655 EXPECT_EQ(81, env->GetArrayLength(reinterpret_cast<jarray>(o81))); 1656 EXPECT_EQ(82, env->GetArrayLength(reinterpret_cast<jarray>(o82))); 1657 EXPECT_EQ(83, env->GetArrayLength(reinterpret_cast<jarray>(o83))); 1658 EXPECT_EQ(84, env->GetArrayLength(reinterpret_cast<jarray>(o84))); 1659 EXPECT_EQ(85, env->GetArrayLength(reinterpret_cast<jarray>(o85))); 1660 EXPECT_EQ(86, env->GetArrayLength(reinterpret_cast<jarray>(o86))); 1661 EXPECT_EQ(87, env->GetArrayLength(reinterpret_cast<jarray>(o87))); 1662 EXPECT_EQ(88, env->GetArrayLength(reinterpret_cast<jarray>(o88))); 1663 EXPECT_EQ(89, env->GetArrayLength(reinterpret_cast<jarray>(o89))); 1664 EXPECT_EQ(90, env->GetArrayLength(reinterpret_cast<jarray>(o90))); 1665 EXPECT_EQ(91, env->GetArrayLength(reinterpret_cast<jarray>(o91))); 1666 EXPECT_EQ(92, env->GetArrayLength(reinterpret_cast<jarray>(o92))); 1667 EXPECT_EQ(93, env->GetArrayLength(reinterpret_cast<jarray>(o93))); 1668 EXPECT_EQ(94, env->GetArrayLength(reinterpret_cast<jarray>(o94))); 1669 EXPECT_EQ(95, env->GetArrayLength(reinterpret_cast<jarray>(o95))); 1670 EXPECT_EQ(96, env->GetArrayLength(reinterpret_cast<jarray>(o96))); 1671 EXPECT_EQ(97, env->GetArrayLength(reinterpret_cast<jarray>(o97))); 1672 EXPECT_EQ(98, env->GetArrayLength(reinterpret_cast<jarray>(o98))); 1673 EXPECT_EQ(99, env->GetArrayLength(reinterpret_cast<jarray>(o99))); 1674 EXPECT_EQ(100, env->GetArrayLength(reinterpret_cast<jarray>(o100))); 1675 EXPECT_EQ(101, env->GetArrayLength(reinterpret_cast<jarray>(o101))); 1676 EXPECT_EQ(102, env->GetArrayLength(reinterpret_cast<jarray>(o102))); 1677 EXPECT_EQ(103, env->GetArrayLength(reinterpret_cast<jarray>(o103))); 1678 EXPECT_EQ(104, env->GetArrayLength(reinterpret_cast<jarray>(o104))); 1679 EXPECT_EQ(105, env->GetArrayLength(reinterpret_cast<jarray>(o105))); 1680 EXPECT_EQ(106, env->GetArrayLength(reinterpret_cast<jarray>(o106))); 1681 EXPECT_EQ(107, env->GetArrayLength(reinterpret_cast<jarray>(o107))); 1682 EXPECT_EQ(108, env->GetArrayLength(reinterpret_cast<jarray>(o108))); 1683 EXPECT_EQ(109, env->GetArrayLength(reinterpret_cast<jarray>(o109))); 1684 EXPECT_EQ(110, env->GetArrayLength(reinterpret_cast<jarray>(o110))); 1685 EXPECT_EQ(111, env->GetArrayLength(reinterpret_cast<jarray>(o111))); 1686 EXPECT_EQ(112, env->GetArrayLength(reinterpret_cast<jarray>(o112))); 1687 EXPECT_EQ(113, env->GetArrayLength(reinterpret_cast<jarray>(o113))); 1688 EXPECT_EQ(114, env->GetArrayLength(reinterpret_cast<jarray>(o114))); 1689 EXPECT_EQ(115, env->GetArrayLength(reinterpret_cast<jarray>(o115))); 1690 EXPECT_EQ(116, env->GetArrayLength(reinterpret_cast<jarray>(o116))); 1691 EXPECT_EQ(117, env->GetArrayLength(reinterpret_cast<jarray>(o117))); 1692 EXPECT_EQ(118, env->GetArrayLength(reinterpret_cast<jarray>(o118))); 1693 EXPECT_EQ(119, env->GetArrayLength(reinterpret_cast<jarray>(o119))); 1694 EXPECT_EQ(120, env->GetArrayLength(reinterpret_cast<jarray>(o120))); 1695 EXPECT_EQ(121, env->GetArrayLength(reinterpret_cast<jarray>(o121))); 1696 EXPECT_EQ(122, env->GetArrayLength(reinterpret_cast<jarray>(o122))); 1697 EXPECT_EQ(123, env->GetArrayLength(reinterpret_cast<jarray>(o123))); 1698 EXPECT_EQ(124, env->GetArrayLength(reinterpret_cast<jarray>(o124))); 1699 EXPECT_EQ(125, env->GetArrayLength(reinterpret_cast<jarray>(o125))); 1700 EXPECT_EQ(126, env->GetArrayLength(reinterpret_cast<jarray>(o126))); 1701 EXPECT_EQ(127, env->GetArrayLength(reinterpret_cast<jarray>(o127))); 1702 EXPECT_EQ(128, env->GetArrayLength(reinterpret_cast<jarray>(o128))); 1703 EXPECT_EQ(129, env->GetArrayLength(reinterpret_cast<jarray>(o129))); 1704 EXPECT_EQ(130, env->GetArrayLength(reinterpret_cast<jarray>(o130))); 1705 EXPECT_EQ(131, env->GetArrayLength(reinterpret_cast<jarray>(o131))); 1706 EXPECT_EQ(132, env->GetArrayLength(reinterpret_cast<jarray>(o132))); 1707 EXPECT_EQ(133, env->GetArrayLength(reinterpret_cast<jarray>(o133))); 1708 EXPECT_EQ(134, env->GetArrayLength(reinterpret_cast<jarray>(o134))); 1709 EXPECT_EQ(135, env->GetArrayLength(reinterpret_cast<jarray>(o135))); 1710 EXPECT_EQ(136, env->GetArrayLength(reinterpret_cast<jarray>(o136))); 1711 EXPECT_EQ(137, env->GetArrayLength(reinterpret_cast<jarray>(o137))); 1712 EXPECT_EQ(138, env->GetArrayLength(reinterpret_cast<jarray>(o138))); 1713 EXPECT_EQ(139, env->GetArrayLength(reinterpret_cast<jarray>(o139))); 1714 EXPECT_EQ(140, env->GetArrayLength(reinterpret_cast<jarray>(o140))); 1715 EXPECT_EQ(141, env->GetArrayLength(reinterpret_cast<jarray>(o141))); 1716 EXPECT_EQ(142, env->GetArrayLength(reinterpret_cast<jarray>(o142))); 1717 EXPECT_EQ(143, env->GetArrayLength(reinterpret_cast<jarray>(o143))); 1718 EXPECT_EQ(144, env->GetArrayLength(reinterpret_cast<jarray>(o144))); 1719 EXPECT_EQ(145, env->GetArrayLength(reinterpret_cast<jarray>(o145))); 1720 EXPECT_EQ(146, env->GetArrayLength(reinterpret_cast<jarray>(o146))); 1721 EXPECT_EQ(147, env->GetArrayLength(reinterpret_cast<jarray>(o147))); 1722 EXPECT_EQ(148, env->GetArrayLength(reinterpret_cast<jarray>(o148))); 1723 EXPECT_EQ(149, env->GetArrayLength(reinterpret_cast<jarray>(o149))); 1724 EXPECT_EQ(150, env->GetArrayLength(reinterpret_cast<jarray>(o150))); 1725 EXPECT_EQ(151, env->GetArrayLength(reinterpret_cast<jarray>(o151))); 1726 EXPECT_EQ(152, env->GetArrayLength(reinterpret_cast<jarray>(o152))); 1727 EXPECT_EQ(153, env->GetArrayLength(reinterpret_cast<jarray>(o153))); 1728 EXPECT_EQ(154, env->GetArrayLength(reinterpret_cast<jarray>(o154))); 1729 EXPECT_EQ(155, env->GetArrayLength(reinterpret_cast<jarray>(o155))); 1730 EXPECT_EQ(156, env->GetArrayLength(reinterpret_cast<jarray>(o156))); 1731 EXPECT_EQ(157, env->GetArrayLength(reinterpret_cast<jarray>(o157))); 1732 EXPECT_EQ(158, env->GetArrayLength(reinterpret_cast<jarray>(o158))); 1733 EXPECT_EQ(159, env->GetArrayLength(reinterpret_cast<jarray>(o159))); 1734 EXPECT_EQ(160, env->GetArrayLength(reinterpret_cast<jarray>(o160))); 1735 EXPECT_EQ(161, env->GetArrayLength(reinterpret_cast<jarray>(o161))); 1736 EXPECT_EQ(162, env->GetArrayLength(reinterpret_cast<jarray>(o162))); 1737 EXPECT_EQ(163, env->GetArrayLength(reinterpret_cast<jarray>(o163))); 1738 EXPECT_EQ(164, env->GetArrayLength(reinterpret_cast<jarray>(o164))); 1739 EXPECT_EQ(165, env->GetArrayLength(reinterpret_cast<jarray>(o165))); 1740 EXPECT_EQ(166, env->GetArrayLength(reinterpret_cast<jarray>(o166))); 1741 EXPECT_EQ(167, env->GetArrayLength(reinterpret_cast<jarray>(o167))); 1742 EXPECT_EQ(168, env->GetArrayLength(reinterpret_cast<jarray>(o168))); 1743 EXPECT_EQ(169, env->GetArrayLength(reinterpret_cast<jarray>(o169))); 1744 EXPECT_EQ(170, env->GetArrayLength(reinterpret_cast<jarray>(o170))); 1745 EXPECT_EQ(171, env->GetArrayLength(reinterpret_cast<jarray>(o171))); 1746 EXPECT_EQ(172, env->GetArrayLength(reinterpret_cast<jarray>(o172))); 1747 EXPECT_EQ(173, env->GetArrayLength(reinterpret_cast<jarray>(o173))); 1748 EXPECT_EQ(174, env->GetArrayLength(reinterpret_cast<jarray>(o174))); 1749 EXPECT_EQ(175, env->GetArrayLength(reinterpret_cast<jarray>(o175))); 1750 EXPECT_EQ(176, env->GetArrayLength(reinterpret_cast<jarray>(o176))); 1751 EXPECT_EQ(177, env->GetArrayLength(reinterpret_cast<jarray>(o177))); 1752 EXPECT_EQ(178, env->GetArrayLength(reinterpret_cast<jarray>(o178))); 1753 EXPECT_EQ(179, env->GetArrayLength(reinterpret_cast<jarray>(o179))); 1754 EXPECT_EQ(180, env->GetArrayLength(reinterpret_cast<jarray>(o180))); 1755 EXPECT_EQ(181, env->GetArrayLength(reinterpret_cast<jarray>(o181))); 1756 EXPECT_EQ(182, env->GetArrayLength(reinterpret_cast<jarray>(o182))); 1757 EXPECT_EQ(183, env->GetArrayLength(reinterpret_cast<jarray>(o183))); 1758 EXPECT_EQ(184, env->GetArrayLength(reinterpret_cast<jarray>(o184))); 1759 EXPECT_EQ(185, env->GetArrayLength(reinterpret_cast<jarray>(o185))); 1760 EXPECT_EQ(186, env->GetArrayLength(reinterpret_cast<jarray>(o186))); 1761 EXPECT_EQ(187, env->GetArrayLength(reinterpret_cast<jarray>(o187))); 1762 EXPECT_EQ(188, env->GetArrayLength(reinterpret_cast<jarray>(o188))); 1763 EXPECT_EQ(189, env->GetArrayLength(reinterpret_cast<jarray>(o189))); 1764 EXPECT_EQ(190, env->GetArrayLength(reinterpret_cast<jarray>(o190))); 1765 EXPECT_EQ(191, env->GetArrayLength(reinterpret_cast<jarray>(o191))); 1766 EXPECT_EQ(192, env->GetArrayLength(reinterpret_cast<jarray>(o192))); 1767 EXPECT_EQ(193, env->GetArrayLength(reinterpret_cast<jarray>(o193))); 1768 EXPECT_EQ(194, env->GetArrayLength(reinterpret_cast<jarray>(o194))); 1769 EXPECT_EQ(195, env->GetArrayLength(reinterpret_cast<jarray>(o195))); 1770 EXPECT_EQ(196, env->GetArrayLength(reinterpret_cast<jarray>(o196))); 1771 EXPECT_EQ(197, env->GetArrayLength(reinterpret_cast<jarray>(o197))); 1772 EXPECT_EQ(198, env->GetArrayLength(reinterpret_cast<jarray>(o198))); 1773 EXPECT_EQ(199, env->GetArrayLength(reinterpret_cast<jarray>(o199))); 1774 EXPECT_EQ(200, env->GetArrayLength(reinterpret_cast<jarray>(o200))); 1775 EXPECT_EQ(201, env->GetArrayLength(reinterpret_cast<jarray>(o201))); 1776 EXPECT_EQ(202, env->GetArrayLength(reinterpret_cast<jarray>(o202))); 1777 EXPECT_EQ(203, env->GetArrayLength(reinterpret_cast<jarray>(o203))); 1778 EXPECT_EQ(204, env->GetArrayLength(reinterpret_cast<jarray>(o204))); 1779 EXPECT_EQ(205, env->GetArrayLength(reinterpret_cast<jarray>(o205))); 1780 EXPECT_EQ(206, env->GetArrayLength(reinterpret_cast<jarray>(o206))); 1781 EXPECT_EQ(207, env->GetArrayLength(reinterpret_cast<jarray>(o207))); 1782 EXPECT_EQ(208, env->GetArrayLength(reinterpret_cast<jarray>(o208))); 1783 EXPECT_EQ(209, env->GetArrayLength(reinterpret_cast<jarray>(o209))); 1784 EXPECT_EQ(210, env->GetArrayLength(reinterpret_cast<jarray>(o210))); 1785 EXPECT_EQ(211, env->GetArrayLength(reinterpret_cast<jarray>(o211))); 1786 EXPECT_EQ(212, env->GetArrayLength(reinterpret_cast<jarray>(o212))); 1787 EXPECT_EQ(213, env->GetArrayLength(reinterpret_cast<jarray>(o213))); 1788 EXPECT_EQ(214, env->GetArrayLength(reinterpret_cast<jarray>(o214))); 1789 EXPECT_EQ(215, env->GetArrayLength(reinterpret_cast<jarray>(o215))); 1790 EXPECT_EQ(216, env->GetArrayLength(reinterpret_cast<jarray>(o216))); 1791 EXPECT_EQ(217, env->GetArrayLength(reinterpret_cast<jarray>(o217))); 1792 EXPECT_EQ(218, env->GetArrayLength(reinterpret_cast<jarray>(o218))); 1793 EXPECT_EQ(219, env->GetArrayLength(reinterpret_cast<jarray>(o219))); 1794 EXPECT_EQ(220, env->GetArrayLength(reinterpret_cast<jarray>(o220))); 1795 EXPECT_EQ(221, env->GetArrayLength(reinterpret_cast<jarray>(o221))); 1796 EXPECT_EQ(222, env->GetArrayLength(reinterpret_cast<jarray>(o222))); 1797 EXPECT_EQ(223, env->GetArrayLength(reinterpret_cast<jarray>(o223))); 1798 EXPECT_EQ(224, env->GetArrayLength(reinterpret_cast<jarray>(o224))); 1799 EXPECT_EQ(225, env->GetArrayLength(reinterpret_cast<jarray>(o225))); 1800 EXPECT_EQ(226, env->GetArrayLength(reinterpret_cast<jarray>(o226))); 1801 EXPECT_EQ(227, env->GetArrayLength(reinterpret_cast<jarray>(o227))); 1802 EXPECT_EQ(228, env->GetArrayLength(reinterpret_cast<jarray>(o228))); 1803 EXPECT_EQ(229, env->GetArrayLength(reinterpret_cast<jarray>(o229))); 1804 EXPECT_EQ(230, env->GetArrayLength(reinterpret_cast<jarray>(o230))); 1805 EXPECT_EQ(231, env->GetArrayLength(reinterpret_cast<jarray>(o231))); 1806 EXPECT_EQ(232, env->GetArrayLength(reinterpret_cast<jarray>(o232))); 1807 EXPECT_EQ(233, env->GetArrayLength(reinterpret_cast<jarray>(o233))); 1808 EXPECT_EQ(234, env->GetArrayLength(reinterpret_cast<jarray>(o234))); 1809 EXPECT_EQ(235, env->GetArrayLength(reinterpret_cast<jarray>(o235))); 1810 EXPECT_EQ(236, env->GetArrayLength(reinterpret_cast<jarray>(o236))); 1811 EXPECT_EQ(237, env->GetArrayLength(reinterpret_cast<jarray>(o237))); 1812 EXPECT_EQ(238, env->GetArrayLength(reinterpret_cast<jarray>(o238))); 1813 EXPECT_EQ(239, env->GetArrayLength(reinterpret_cast<jarray>(o239))); 1814 EXPECT_EQ(240, env->GetArrayLength(reinterpret_cast<jarray>(o240))); 1815 EXPECT_EQ(241, env->GetArrayLength(reinterpret_cast<jarray>(o241))); 1816 EXPECT_EQ(242, env->GetArrayLength(reinterpret_cast<jarray>(o242))); 1817 EXPECT_EQ(243, env->GetArrayLength(reinterpret_cast<jarray>(o243))); 1818 EXPECT_EQ(244, env->GetArrayLength(reinterpret_cast<jarray>(o244))); 1819 EXPECT_EQ(245, env->GetArrayLength(reinterpret_cast<jarray>(o245))); 1820 EXPECT_EQ(246, env->GetArrayLength(reinterpret_cast<jarray>(o246))); 1821 EXPECT_EQ(247, env->GetArrayLength(reinterpret_cast<jarray>(o247))); 1822 EXPECT_EQ(248, env->GetArrayLength(reinterpret_cast<jarray>(o248))); 1823 EXPECT_EQ(249, env->GetArrayLength(reinterpret_cast<jarray>(o249))); 1824 EXPECT_EQ(250, env->GetArrayLength(reinterpret_cast<jarray>(o250))); 1825 EXPECT_EQ(251, env->GetArrayLength(reinterpret_cast<jarray>(o251))); 1826 EXPECT_EQ(252, env->GetArrayLength(reinterpret_cast<jarray>(o252))); 1827 EXPECT_EQ(253, env->GetArrayLength(reinterpret_cast<jarray>(o253))); 1828 } 1829 } 1830 1831 const char* longSig = 1832 "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1833 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1834 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1835 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1836 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1837 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1838 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1839 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1840 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1841 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1842 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1843 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1844 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1845 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1846 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1847 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1848 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1849 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1850 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1851 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1852 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1853 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1854 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1855 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1856 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1857 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1858 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1859 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1860 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1861 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1862 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1863 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1864 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1865 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1866 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1867 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1868 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1869 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1870 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1871 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1872 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1873 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1874 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1875 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1876 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1877 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1878 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1879 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1880 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1881 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;" 1882 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V"; 1883 1884 void JniCompilerTest::MaxParamNumberImpl() { 1885 SetUpForTest(false, "maxParamNumber", longSig, 1886 CURRENT_JNI_WRAPPER(Java_MyClassNatives_maxParamNumber)); 1887 1888 jvalue args[254]; 1889 1890 // First test: test with all arguments null. 1891 for (int i = 0; i < 254; ++i) { 1892 args[i].l = nullptr; 1893 } 1894 1895 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args); 1896 1897 // Second test: test with int[] objects with increasing lengths 1898 for (int i = 0; i < 254; ++i) { 1899 jintArray tmp = env_->NewIntArray(i); 1900 args[i].l = tmp; 1901 EXPECT_NE(args[i].l, nullptr); 1902 } 1903 1904 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args); 1905 } 1906 1907 JNI_TEST(MaxParamNumber) 1908 1909 void JniCompilerTest::WithoutImplementationImpl() { 1910 // This will lead to error messages in the log. 1911 ScopedLogSeverity sls(LogSeverity::FATAL); 1912 1913 SetUpForTest(false, "withoutImplementation", "()V", NORMAL_JNI_ONLY_NULLPTR); 1914 1915 env_->CallVoidMethod(jobj_, jmethod_); 1916 1917 EXPECT_TRUE(Thread::Current()->IsExceptionPending()); 1918 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 1919 } 1920 1921 // TODO: Don't test @FastNative here since it goes through a stub lookup (unsupported) which would 1922 // normally fail with an exception, but fails with an assert. 1923 JNI_TEST_NORMAL_ONLY(WithoutImplementation) 1924 1925 void JniCompilerTest::WithoutImplementationRefReturnImpl() { 1926 // This will lead to error messages in the log. 1927 ScopedLogSeverity sls(LogSeverity::FATAL); 1928 1929 SetUpForTest(false, 1930 "withoutImplementationRefReturn", 1931 "()Ljava/lang/Object;", 1932 NORMAL_JNI_ONLY_NULLPTR); 1933 1934 env_->CallObjectMethod(jobj_, jmethod_); 1935 1936 EXPECT_TRUE(Thread::Current()->IsExceptionPending()); 1937 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE); 1938 } 1939 1940 // TODO: Should work for @FastNative too. 1941 JNI_TEST_NORMAL_ONLY(WithoutImplementationRefReturn) 1942 1943 void Java_MyClassNatives_stackArgsIntsFirst(JNIEnv*, jclass, jint i1, jint i2, jint i3, 1944 jint i4, jint i5, jint i6, jint i7, jint i8, jint i9, 1945 jint i10, jfloat f1, jfloat f2, jfloat f3, jfloat f4, 1946 jfloat f5, jfloat f6, jfloat f7, jfloat f8, jfloat f9, 1947 jfloat f10) { 1948 EXPECT_EQ(i1, 1); 1949 EXPECT_EQ(i2, 2); 1950 EXPECT_EQ(i3, 3); 1951 EXPECT_EQ(i4, 4); 1952 EXPECT_EQ(i5, 5); 1953 EXPECT_EQ(i6, 6); 1954 EXPECT_EQ(i7, 7); 1955 EXPECT_EQ(i8, 8); 1956 EXPECT_EQ(i9, 9); 1957 EXPECT_EQ(i10, 10); 1958 1959 jint i11 = bit_cast<jint, jfloat>(f1); 1960 EXPECT_EQ(i11, 11); 1961 jint i12 = bit_cast<jint, jfloat>(f2); 1962 EXPECT_EQ(i12, 12); 1963 jint i13 = bit_cast<jint, jfloat>(f3); 1964 EXPECT_EQ(i13, 13); 1965 jint i14 = bit_cast<jint, jfloat>(f4); 1966 EXPECT_EQ(i14, 14); 1967 jint i15 = bit_cast<jint, jfloat>(f5); 1968 EXPECT_EQ(i15, 15); 1969 jint i16 = bit_cast<jint, jfloat>(f6); 1970 EXPECT_EQ(i16, 16); 1971 jint i17 = bit_cast<jint, jfloat>(f7); 1972 EXPECT_EQ(i17, 17); 1973 jint i18 = bit_cast<jint, jfloat>(f8); 1974 EXPECT_EQ(i18, 18); 1975 jint i19 = bit_cast<jint, jfloat>(f9); 1976 EXPECT_EQ(i19, 19); 1977 jint i20 = bit_cast<jint, jfloat>(f10); 1978 EXPECT_EQ(i20, 20); 1979 } 1980 1981 void JniCompilerTest::StackArgsIntsFirstImpl() { 1982 SetUpForTest(true, "stackArgsIntsFirst", "(IIIIIIIIIIFFFFFFFFFF)V", 1983 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsIntsFirst)); 1984 1985 jint i1 = 1; 1986 jint i2 = 2; 1987 jint i3 = 3; 1988 jint i4 = 4; 1989 jint i5 = 5; 1990 jint i6 = 6; 1991 jint i7 = 7; 1992 jint i8 = 8; 1993 jint i9 = 9; 1994 jint i10 = 10; 1995 1996 jfloat f1 = bit_cast<jfloat, jint>(11); 1997 jfloat f2 = bit_cast<jfloat, jint>(12); 1998 jfloat f3 = bit_cast<jfloat, jint>(13); 1999 jfloat f4 = bit_cast<jfloat, jint>(14); 2000 jfloat f5 = bit_cast<jfloat, jint>(15); 2001 jfloat f6 = bit_cast<jfloat, jint>(16); 2002 jfloat f7 = bit_cast<jfloat, jint>(17); 2003 jfloat f8 = bit_cast<jfloat, jint>(18); 2004 jfloat f9 = bit_cast<jfloat, jint>(19); 2005 jfloat f10 = bit_cast<jfloat, jint>(20); 2006 2007 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, f1, f2, 2008 f3, f4, f5, f6, f7, f8, f9, f10); 2009 } 2010 2011 JNI_TEST_CRITICAL(StackArgsIntsFirst) 2012 2013 void Java_MyClassNatives_stackArgsFloatsFirst(JNIEnv*, jclass, jfloat f1, jfloat f2, 2014 jfloat f3, jfloat f4, jfloat f5, jfloat f6, jfloat f7, 2015 jfloat f8, jfloat f9, jfloat f10, jint i1, jint i2, 2016 jint i3, jint i4, jint i5, jint i6, jint i7, jint i8, 2017 jint i9, jint i10) { 2018 EXPECT_EQ(i1, 1); 2019 EXPECT_EQ(i2, 2); 2020 EXPECT_EQ(i3, 3); 2021 EXPECT_EQ(i4, 4); 2022 EXPECT_EQ(i5, 5); 2023 EXPECT_EQ(i6, 6); 2024 EXPECT_EQ(i7, 7); 2025 EXPECT_EQ(i8, 8); 2026 EXPECT_EQ(i9, 9); 2027 EXPECT_EQ(i10, 10); 2028 2029 jint i11 = bit_cast<jint, jfloat>(f1); 2030 EXPECT_EQ(i11, 11); 2031 jint i12 = bit_cast<jint, jfloat>(f2); 2032 EXPECT_EQ(i12, 12); 2033 jint i13 = bit_cast<jint, jfloat>(f3); 2034 EXPECT_EQ(i13, 13); 2035 jint i14 = bit_cast<jint, jfloat>(f4); 2036 EXPECT_EQ(i14, 14); 2037 jint i15 = bit_cast<jint, jfloat>(f5); 2038 EXPECT_EQ(i15, 15); 2039 jint i16 = bit_cast<jint, jfloat>(f6); 2040 EXPECT_EQ(i16, 16); 2041 jint i17 = bit_cast<jint, jfloat>(f7); 2042 EXPECT_EQ(i17, 17); 2043 jint i18 = bit_cast<jint, jfloat>(f8); 2044 EXPECT_EQ(i18, 18); 2045 jint i19 = bit_cast<jint, jfloat>(f9); 2046 EXPECT_EQ(i19, 19); 2047 jint i20 = bit_cast<jint, jfloat>(f10); 2048 EXPECT_EQ(i20, 20); 2049 } 2050 2051 void JniCompilerTest::StackArgsFloatsFirstImpl() { 2052 SetUpForTest(true, "stackArgsFloatsFirst", "(FFFFFFFFFFIIIIIIIIII)V", 2053 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsFloatsFirst)); 2054 2055 jint i1 = 1; 2056 jint i2 = 2; 2057 jint i3 = 3; 2058 jint i4 = 4; 2059 jint i5 = 5; 2060 jint i6 = 6; 2061 jint i7 = 7; 2062 jint i8 = 8; 2063 jint i9 = 9; 2064 jint i10 = 10; 2065 2066 jfloat f1 = bit_cast<jfloat, jint>(11); 2067 jfloat f2 = bit_cast<jfloat, jint>(12); 2068 jfloat f3 = bit_cast<jfloat, jint>(13); 2069 jfloat f4 = bit_cast<jfloat, jint>(14); 2070 jfloat f5 = bit_cast<jfloat, jint>(15); 2071 jfloat f6 = bit_cast<jfloat, jint>(16); 2072 jfloat f7 = bit_cast<jfloat, jint>(17); 2073 jfloat f8 = bit_cast<jfloat, jint>(18); 2074 jfloat f9 = bit_cast<jfloat, jint>(19); 2075 jfloat f10 = bit_cast<jfloat, jint>(20); 2076 2077 env_->CallStaticVoidMethod(jklass_, jmethod_, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, i1, i2, i3, 2078 i4, i5, i6, i7, i8, i9, i10); 2079 } 2080 2081 JNI_TEST_CRITICAL(StackArgsFloatsFirst) 2082 2083 void Java_MyClassNatives_stackArgsMixed(JNIEnv*, jclass, jint i1, jfloat f1, jint i2, 2084 jfloat f2, jint i3, jfloat f3, jint i4, jfloat f4, jint i5, 2085 jfloat f5, jint i6, jfloat f6, jint i7, jfloat f7, jint i8, 2086 jfloat f8, jint i9, jfloat f9, jint i10, jfloat f10) { 2087 EXPECT_EQ(i1, 1); 2088 EXPECT_EQ(i2, 2); 2089 EXPECT_EQ(i3, 3); 2090 EXPECT_EQ(i4, 4); 2091 EXPECT_EQ(i5, 5); 2092 EXPECT_EQ(i6, 6); 2093 EXPECT_EQ(i7, 7); 2094 EXPECT_EQ(i8, 8); 2095 EXPECT_EQ(i9, 9); 2096 EXPECT_EQ(i10, 10); 2097 2098 jint i11 = bit_cast<jint, jfloat>(f1); 2099 EXPECT_EQ(i11, 11); 2100 jint i12 = bit_cast<jint, jfloat>(f2); 2101 EXPECT_EQ(i12, 12); 2102 jint i13 = bit_cast<jint, jfloat>(f3); 2103 EXPECT_EQ(i13, 13); 2104 jint i14 = bit_cast<jint, jfloat>(f4); 2105 EXPECT_EQ(i14, 14); 2106 jint i15 = bit_cast<jint, jfloat>(f5); 2107 EXPECT_EQ(i15, 15); 2108 jint i16 = bit_cast<jint, jfloat>(f6); 2109 EXPECT_EQ(i16, 16); 2110 jint i17 = bit_cast<jint, jfloat>(f7); 2111 EXPECT_EQ(i17, 17); 2112 jint i18 = bit_cast<jint, jfloat>(f8); 2113 EXPECT_EQ(i18, 18); 2114 jint i19 = bit_cast<jint, jfloat>(f9); 2115 EXPECT_EQ(i19, 19); 2116 jint i20 = bit_cast<jint, jfloat>(f10); 2117 EXPECT_EQ(i20, 20); 2118 } 2119 2120 void JniCompilerTest::StackArgsMixedImpl() { 2121 SetUpForTest(true, "stackArgsMixed", "(IFIFIFIFIFIFIFIFIFIF)V", 2122 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsMixed)); 2123 2124 jint i1 = 1; 2125 jint i2 = 2; 2126 jint i3 = 3; 2127 jint i4 = 4; 2128 jint i5 = 5; 2129 jint i6 = 6; 2130 jint i7 = 7; 2131 jint i8 = 8; 2132 jint i9 = 9; 2133 jint i10 = 10; 2134 2135 jfloat f1 = bit_cast<jfloat, jint>(11); 2136 jfloat f2 = bit_cast<jfloat, jint>(12); 2137 jfloat f3 = bit_cast<jfloat, jint>(13); 2138 jfloat f4 = bit_cast<jfloat, jint>(14); 2139 jfloat f5 = bit_cast<jfloat, jint>(15); 2140 jfloat f6 = bit_cast<jfloat, jint>(16); 2141 jfloat f7 = bit_cast<jfloat, jint>(17); 2142 jfloat f8 = bit_cast<jfloat, jint>(18); 2143 jfloat f9 = bit_cast<jfloat, jint>(19); 2144 jfloat f10 = bit_cast<jfloat, jint>(20); 2145 2146 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7, 2147 f7, i8, f8, i9, f9, i10, f10); 2148 } 2149 2150 JNI_TEST_CRITICAL(StackArgsMixed) 2151 2152 #if defined(__mips__) && defined(__LP64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 2153 // Function will fetch the last argument passed from caller that is now on top of the stack and 2154 // return it as a 8B long. That way we can test if the caller has properly sign-extended the 2155 // value when placing it on the stack. 2156 __attribute__((naked)) 2157 jlong Java_MyClassNatives_getStackArgSignExtendedMips64( 2158 JNIEnv*, jclass, // Arguments passed from caller 2159 jint, jint, jint, jint, jint, jint, // through regs a0 to a7. 2160 jint) { // The last argument will be passed on the stack. 2161 __asm__( 2162 ".set noreorder\n\t" // Just return and store 8 bytes from the top of the stack 2163 "jr $ra\n\t" // in v0 (in branch delay slot). This should be the last 2164 "ld $v0, 0($sp)\n\t"); // argument. It is a 32-bit int, but it should be sign 2165 // extended and it occupies 64-bit location. 2166 } 2167 2168 void JniCompilerTest::StackArgsSignExtendedMips64Impl() { 2169 uint64_t ret; 2170 SetUpForTest(true, 2171 "getStackArgSignExtendedMips64", 2172 "(IIIIIII)J", 2173 // Don't use wrapper because this is raw assembly function. 2174 reinterpret_cast<void*>(&Java_MyClassNatives_getStackArgSignExtendedMips64)); 2175 2176 // Mips64 ABI requires that arguments passed through stack be sign-extended 8B slots. 2177 // First 8 arguments are passed through registers. 2178 // Final argument's value is 7. When sign-extended, higher stack bits should be 0. 2179 ret = env_->CallStaticLongMethod(jklass_, jmethod_, 1, 2, 3, 4, 5, 6, 7); 2180 EXPECT_EQ(High32Bits(ret), static_cast<uint32_t>(0)); 2181 2182 // Final argument's value is -8. When sign-extended, higher stack bits should be 0xffffffff. 2183 ret = env_->CallStaticLongMethod(jklass_, jmethod_, 1, 2, 3, 4, 5, 6, -8); 2184 EXPECT_EQ(High32Bits(ret), static_cast<uint32_t>(0xffffffff)); 2185 } 2186 2187 JNI_TEST(StackArgsSignExtendedMips64) 2188 #endif 2189 2190 void Java_MyClassNatives_normalNative(JNIEnv*, jclass) { 2191 // Intentionally left empty. 2192 } 2193 2194 // Methods not annotated with anything are not considered "fast native" 2195 // -- Check that the annotation lookup does not find it. 2196 void JniCompilerTest::NormalNativeImpl() { 2197 SetUpForTest(/* direct */ true, 2198 "normalNative", 2199 "()V", 2200 CURRENT_JNI_WRAPPER(Java_MyClassNatives_normalNative)); 2201 2202 ArtMethod* method = jni::DecodeArtMethod(jmethod_); 2203 ASSERT_TRUE(method != nullptr); 2204 2205 EXPECT_FALSE(method->IsAnnotatedWithCriticalNative()); 2206 EXPECT_FALSE(method->IsAnnotatedWithFastNative()); 2207 } 2208 2209 // TODO: just rename the java functions to the standard convention and remove duplicated tests 2210 JNI_TEST_NORMAL_ONLY(NormalNative) 2211 2212 // Methods annotated with @FastNative are considered "fast native" 2213 // -- Check that the annotation lookup succeeds. 2214 void Java_MyClassNatives_fastNative(JNIEnv*, jclass) { 2215 // Intentionally left empty. 2216 } 2217 2218 void JniCompilerTest::FastNativeImpl() { 2219 SetUpForTest(/* direct */ true, 2220 "fastNative", 2221 "()V", 2222 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fastNative)); 2223 2224 ArtMethod* method = jni::DecodeArtMethod(jmethod_); 2225 ASSERT_TRUE(method != nullptr); 2226 2227 EXPECT_FALSE(method->IsAnnotatedWithCriticalNative()); 2228 EXPECT_TRUE(method->IsAnnotatedWithFastNative()); 2229 } 2230 2231 // TODO: just rename the java functions to the standard convention and remove duplicated tests 2232 JNI_TEST_NORMAL_ONLY(FastNative) 2233 2234 int gJava_myClassNatives_criticalNative_calls[kJniKindCount] = {}; 2235 // Methods annotated with @CriticalNative are considered "critical native" 2236 // -- Check that the annotation lookup succeeds. 2237 void Java_MyClassNatives_criticalNative() { 2238 gJava_myClassNatives_criticalNative_calls[gCurrentJni]++; 2239 } 2240 2241 void JniCompilerTest::CriticalNativeImpl() { 2242 SetUpForTest(/* direct */ true, 2243 // Important: Don't change the "current jni" yet to avoid a method name suffix. 2244 "criticalNative", 2245 "()V", 2246 // TODO: Use CURRENT_JNI_WRAPPER instead which is more generic. 2247 reinterpret_cast<void*>(&Java_MyClassNatives_criticalNative)); 2248 2249 // TODO: remove this manual updating of the current JNI. Merge with the other tests. 2250 UpdateCurrentJni(JniKind::kCritical); 2251 ASSERT_TRUE(IsCurrentJniCritical()); 2252 2253 ArtMethod* method = jni::DecodeArtMethod(jmethod_); 2254 ASSERT_TRUE(method != nullptr); 2255 2256 EXPECT_TRUE(method->IsAnnotatedWithCriticalNative()); 2257 EXPECT_FALSE(method->IsAnnotatedWithFastNative()); 2258 2259 EXPECT_EQ(0, gJava_myClassNatives_criticalNative_calls[gCurrentJni]); 2260 env_->CallStaticVoidMethod(jklass_, jmethod_); 2261 EXPECT_EQ(1, gJava_myClassNatives_criticalNative_calls[gCurrentJni]); 2262 2263 gJava_myClassNatives_criticalNative_calls[gCurrentJni] = 0; 2264 } 2265 2266 // TODO: just rename the java functions to the standard convention and remove duplicated tests 2267 JNI_TEST_NORMAL_ONLY(CriticalNative) 2268 2269 } // namespace art 2270