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