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