blob: 70bfb81c2312bc62014214f73eb22635e5372ceb [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Ian Rogersb033c752011-07-20 12:22:35 -070016
Ian Rogers700a4022014-05-19 16:49:03 -070017#include <memory>
18
Nicolas Geoffray54accbc2014-08-13 03:40:45 +010019#include <math.h>
20
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070021#include "class_linker.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080022#include "common_compiler_test.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070023#include "dex_file.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070024#include "gtest/gtest.h"
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070025#include "indirect_reference_table.h"
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070026#include "jni_internal.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -070027#include "mem_map.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070028#include "mirror/art_method-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070029#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030#include "mirror/class_loader.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031#include "mirror/object_array-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070032#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "mirror/stack_trace_element.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070034#include "runtime.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070035#include "ScopedLocalRef.h"
36#include "scoped_thread_state_change.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070037#include "thread.h"
Ian Rogersb033c752011-07-20 12:22:35 -070038
Elliott Hughesb264f082012-04-06 17:10:10 -070039extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_bar(JNIEnv*, jobject, jint count) {
Brian Carlstromb9cc1ca2012-01-27 00:57:42 -080040 return count + 1;
41}
42
Elliott Hughesb264f082012-04-06 17:10:10 -070043extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_sbar(JNIEnv*, jclass, jint count) {
Ian Rogers1cefdbd2012-02-29 09:34:50 -080044 return count + 1;
45}
46
Ian Rogersb033c752011-07-20 12:22:35 -070047namespace art {
48
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080049class JniCompilerTest : public CommonCompilerTest {
Ian Rogersb033c752011-07-20 12:22:35 -070050 protected:
Andreas Gampe6e498692014-08-18 16:43:12 -070051 void SetUp() OVERRIDE {
52 CommonCompilerTest::SetUp();
53 check_generic_jni_ = false;
54 }
55
56 void SetCheckGenericJni(bool generic) {
57 check_generic_jni_ = generic;
58 }
59
Ian Rogers00f7d0e2012-07-19 15:28:27 -070060 void CompileForTest(jobject class_loader, bool direct,
Andreas Gampe6e498692014-08-18 16:43:12 -070061 const char* method_name, const char* method_sig) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070062 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070063 StackHandleScope<1> hs(soa.Self());
64 Handle<mirror::ClassLoader> loader(
65 hs.NewHandle(soa.Decode<mirror::ClassLoader*>(class_loader)));
Brian Carlstrom25c33252011-09-18 15:58:35 -070066 // Compile the native method before starting the runtime
Ian Rogers98379392014-02-24 16:53:16 -080067 mirror::Class* c = class_linker_->FindClass(soa.Self(), "LMyClassNatives;", loader);
Brian Carlstromea46f952013-07-30 01:26:50 -070068 mirror::ArtMethod* method;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070069 if (direct) {
buzbeec143c552011-08-20 17:38:58 -070070 method = c->FindDirectMethod(method_name, method_sig);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070071 } else {
buzbeec143c552011-08-20 17:38:58 -070072 method = c->FindVirtualMethod(method_name, method_sig);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070073 }
Andreas Gampecf4035a2014-05-28 22:43:01 -070074 ASSERT_TRUE(method != nullptr) << method_name << " " << method_sig;
Andreas Gampe6e498692014-08-18 16:43:12 -070075 if (check_generic_jni_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -070076 method->SetEntryPointFromQuickCompiledCode(class_linker_->GetRuntimeQuickGenericJniStub());
Nicolas Geoffray54accbc2014-08-13 03:40:45 +010077 } else {
Ian Rogers6f3dbba2014-10-14 17:41:57 -070078 const void* code = method->GetEntryPointFromQuickCompiledCode();
79 if (code == nullptr || class_linker_->IsQuickGenericJniStub(code)) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +010080 CompileMethod(method);
81 ASSERT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr)
82 << method_name << " " << method_sig;
Nicolas Geoffray54accbc2014-08-13 03:40:45 +010083 }
Brian Carlstrom25c33252011-09-18 15:58:35 -070084 }
Brian Carlstrom25c33252011-09-18 15:58:35 -070085 }
86
Ian Rogers00f7d0e2012-07-19 15:28:27 -070087 void SetUpForTest(bool direct, const char* method_name, const char* method_sig,
Andreas Gampe6e498692014-08-18 16:43:12 -070088 void* native_fnptr) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070089 // Initialize class loader and compile method when runtime not started.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070090 if (!runtime_->IsStarted()) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070091 {
92 ScopedObjectAccess soa(Thread::Current());
93 class_loader_ = LoadDex("MyClassNatives");
94 }
Andreas Gampe6e498692014-08-18 16:43:12 -070095 CompileForTest(class_loader_, direct, method_name, method_sig);
Ian Rogers00f7d0e2012-07-19 15:28:27 -070096 // Start runtime.
97 Thread::Current()->TransitionFromSuspendedToRunnable();
Brian Carlstrombd86bcc2013-03-10 20:26:16 -070098 bool started = runtime_->Start();
99 CHECK(started);
Brian Carlstrom25c33252011-09-18 15:58:35 -0700100 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 // JNI operations after runtime start.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700102 env_ = Thread::Current()->GetJniEnv();
Elliott Hughesb264f082012-04-06 17:10:10 -0700103 jklass_ = env_->FindClass("MyClassNatives");
Andreas Gampecf4035a2014-05-28 22:43:01 -0700104 ASSERT_TRUE(jklass_ != nullptr) << method_name << " " << method_sig;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700105
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700106 if (direct) {
107 jmethod_ = env_->GetStaticMethodID(jklass_, method_name, method_sig);
108 } else {
109 jmethod_ = env_->GetMethodID(jklass_, method_name, method_sig);
110 }
Andreas Gampecf4035a2014-05-28 22:43:01 -0700111 ASSERT_TRUE(jmethod_ != nullptr) << method_name << " " << method_sig;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700112
Andreas Gampecf4035a2014-05-28 22:43:01 -0700113 if (native_fnptr != nullptr) {
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700114 JNINativeMethod methods[] = { { method_name, method_sig, native_fnptr } };
Brian Carlstromfc7120c2012-08-27 13:43:25 -0700115 ASSERT_EQ(JNI_OK, env_->RegisterNatives(jklass_, methods, 1))
116 << method_name << " " << method_sig;
Ian Rogersbdb03912011-09-14 00:55:44 -0700117 } else {
118 env_->UnregisterNatives(jklass_);
Shih-wei Liao31384c52011-09-06 15:27:45 -0700119 }
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700120
121 jmethodID constructor = env_->GetMethodID(jklass_, "<init>", "()V");
122 jobj_ = env_->NewObject(jklass_, constructor);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700123 ASSERT_TRUE(jobj_ != nullptr) << method_name << " " << method_sig;
Ian Rogersb033c752011-07-20 12:22:35 -0700124 }
125
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700126 public:
127 static jclass jklass_;
128 static jobject jobj_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700129 static jobject class_loader_;
130
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700131 protected:
Andreas Gampe6e498692014-08-18 16:43:12 -0700132 // We have to list the methods here so we can share them between default and generic JNI.
133 void CompileAndRunNoArgMethodImpl();
134 void CompileAndRunIntMethodThroughStubImpl();
135 void CompileAndRunStaticIntMethodThroughStubImpl();
136 void CompileAndRunIntMethodImpl();
137 void CompileAndRunIntIntMethodImpl();
138 void CompileAndRunLongLongMethodImpl();
139 void CompileAndRunDoubleDoubleMethodImpl();
140 void CompileAndRun_fooJJ_synchronizedImpl();
141 void CompileAndRunIntObjectObjectMethodImpl();
142 void CompileAndRunStaticIntIntMethodImpl();
143 void CompileAndRunStaticDoubleDoubleMethodImpl();
144 void RunStaticLogDoubleMethodImpl();
145 void RunStaticLogFloatMethodImpl();
146 void RunStaticReturnTrueImpl();
147 void RunStaticReturnFalseImpl();
148 void RunGenericStaticReturnIntImpl();
149 void CompileAndRunStaticIntObjectObjectMethodImpl();
150 void CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl();
151 void ExceptionHandlingImpl();
152 void NativeStackTraceElementImpl();
153 void ReturnGlobalRefImpl();
154 void LocalReferenceTableClearingTestImpl();
155 void JavaLangSystemArrayCopyImpl();
156 void CompareAndSwapIntImpl();
157 void GetTextImpl();
158 void GetSinkPropertiesNativeImpl();
159 void UpcallReturnTypeChecking_InstanceImpl();
160 void UpcallReturnTypeChecking_StaticImpl();
161 void UpcallArgumentTypeChecking_InstanceImpl();
162 void UpcallArgumentTypeChecking_StaticImpl();
163 void CompileAndRunFloatFloatMethodImpl();
164 void CheckParameterAlignImpl();
165 void MaxParamNumberImpl();
166 void WithoutImplementationImpl();
167 void StackArgsIntsFirstImpl();
168 void StackArgsFloatsFirstImpl();
169 void StackArgsMixedImpl();
170
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700171 JNIEnv* env_;
172 jmethodID jmethod_;
Andreas Gampe6e498692014-08-18 16:43:12 -0700173 bool check_generic_jni_;
Ian Rogersb033c752011-07-20 12:22:35 -0700174};
175
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700176jclass JniCompilerTest::jklass_;
177jobject JniCompilerTest::jobj_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700178jobject JniCompilerTest::class_loader_;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700179
Andreas Gampe6e498692014-08-18 16:43:12 -0700180#define JNI_TEST(TestName) \
181 TEST_F(JniCompilerTest, TestName ## Default) { \
182 TestName ## Impl(); \
183 } \
184 \
185 TEST_F(JniCompilerTest, TestName ## Generic) { \
186 TEST_DISABLED_FOR_MIPS(); \
187 SetCheckGenericJni(true); \
188 TestName ## Impl(); \
189 }
Andreas Gampecf4035a2014-05-28 22:43:01 -0700190
Elliott Hughesb264f082012-04-06 17:10:10 -0700191int gJava_MyClassNatives_foo_calls = 0;
192void Java_MyClassNatives_foo(JNIEnv* env, jobject thisObj) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700193 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700194 EXPECT_EQ(kNative, Thread::Current()->GetState());
195 Locks::mutator_lock_->AssertNotHeld(Thread::Current());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700196 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700197 EXPECT_TRUE(thisObj != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700198 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700199 gJava_MyClassNatives_foo_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800200 ScopedObjectAccess soa(Thread::Current());
201 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700202}
203
Andreas Gampe6e498692014-08-18 16:43:12 -0700204void JniCompilerTest::CompileAndRunNoArgMethodImpl() {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800205 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700206
Elliott Hughesb264f082012-04-06 17:10:10 -0700207 EXPECT_EQ(0, gJava_MyClassNatives_foo_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700208 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Elliott Hughesb264f082012-04-06 17:10:10 -0700209 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700210 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Elliott Hughesb264f082012-04-06 17:10:10 -0700211 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700212
213 gJava_MyClassNatives_foo_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700214}
215
Andreas Gampe6e498692014-08-18 16:43:12 -0700216JNI_TEST(CompileAndRunNoArgMethod)
217
218void JniCompilerTest::CompileAndRunIntMethodThroughStubImpl() {
Andreas Gampecf4035a2014-05-28 22:43:01 -0700219 SetUpForTest(false, "bar", "(I)I", nullptr);
220 // calling through stub will link with &Java_MyClassNatives_bar
Shih-wei Liao31384c52011-09-06 15:27:45 -0700221
Shih-wei Liao31384c52011-09-06 15:27:45 -0700222 std::string reason;
Ian Rogers68d8b422014-07-17 11:09:10 -0700223 ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary(env_, "", class_loader_, &reason))
224 << reason;
Shih-wei Liao31384c52011-09-06 15:27:45 -0700225
226 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 24);
227 EXPECT_EQ(25, result);
228}
229
Andreas Gampe6e498692014-08-18 16:43:12 -0700230JNI_TEST(CompileAndRunIntMethodThroughStub)
231
232void JniCompilerTest::CompileAndRunStaticIntMethodThroughStubImpl() {
Andreas Gampecf4035a2014-05-28 22:43:01 -0700233 SetUpForTest(true, "sbar", "(I)I", nullptr);
234 // calling through stub will link with &Java_MyClassNatives_sbar
Ian Rogers1cefdbd2012-02-29 09:34:50 -0800235
236 std::string reason;
Ian Rogers68d8b422014-07-17 11:09:10 -0700237 ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary(env_, "", class_loader_, &reason))
238 << reason;
Ian Rogers1cefdbd2012-02-29 09:34:50 -0800239
240 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42);
241 EXPECT_EQ(43, result);
242}
243
Andreas Gampe6e498692014-08-18 16:43:12 -0700244JNI_TEST(CompileAndRunStaticIntMethodThroughStub)
245
Elliott Hughesb264f082012-04-06 17:10:10 -0700246int gJava_MyClassNatives_fooI_calls = 0;
247jint Java_MyClassNatives_fooI(JNIEnv* env, jobject thisObj, jint x) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700248 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700249 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700250 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700251 EXPECT_TRUE(thisObj != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700252 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700253 gJava_MyClassNatives_fooI_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800254 ScopedObjectAccess soa(Thread::Current());
255 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700256 return x;
257}
258
Andreas Gampe6e498692014-08-18 16:43:12 -0700259void JniCompilerTest::CompileAndRunIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700260 SetUpForTest(false, "fooI", "(I)I",
Elliott Hughesb264f082012-04-06 17:10:10 -0700261 reinterpret_cast<void*>(&Java_MyClassNatives_fooI));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700262
Elliott Hughesb264f082012-04-06 17:10:10 -0700263 EXPECT_EQ(0, gJava_MyClassNatives_fooI_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700264 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 42);
265 EXPECT_EQ(42, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700266 EXPECT_EQ(1, gJava_MyClassNatives_fooI_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700267 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFED00D);
268 EXPECT_EQ(static_cast<jint>(0xCAFED00D), result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700269 EXPECT_EQ(2, gJava_MyClassNatives_fooI_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700270
271 gJava_MyClassNatives_fooI_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700272}
273
Andreas Gampe6e498692014-08-18 16:43:12 -0700274JNI_TEST(CompileAndRunIntMethod)
275
Elliott Hughesb264f082012-04-06 17:10:10 -0700276int gJava_MyClassNatives_fooII_calls = 0;
277jint Java_MyClassNatives_fooII(JNIEnv* env, jobject thisObj, jint x, jint y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700278 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700279 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700280 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700281 EXPECT_TRUE(thisObj != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700282 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700283 gJava_MyClassNatives_fooII_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800284 ScopedObjectAccess soa(Thread::Current());
285 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700286 return x - y; // non-commutative operator
287}
288
Andreas Gampe6e498692014-08-18 16:43:12 -0700289void JniCompilerTest::CompileAndRunIntIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700290 SetUpForTest(false, "fooII", "(II)I",
Elliott Hughesb264f082012-04-06 17:10:10 -0700291 reinterpret_cast<void*>(&Java_MyClassNatives_fooII));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700292
Elliott Hughesb264f082012-04-06 17:10:10 -0700293 EXPECT_EQ(0, gJava_MyClassNatives_fooII_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700294 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 99, 10);
295 EXPECT_EQ(99 - 10, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700296 EXPECT_EQ(1, gJava_MyClassNatives_fooII_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700297 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFEBABE,
298 0xCAFED00D);
299 EXPECT_EQ(static_cast<jint>(0xCAFEBABE - 0xCAFED00D), result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700300 EXPECT_EQ(2, gJava_MyClassNatives_fooII_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700301
302 gJava_MyClassNatives_fooII_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700303}
304
Andreas Gampe6e498692014-08-18 16:43:12 -0700305JNI_TEST(CompileAndRunIntIntMethod)
306
Elliott Hughesb264f082012-04-06 17:10:10 -0700307int gJava_MyClassNatives_fooJJ_calls = 0;
308jlong Java_MyClassNatives_fooJJ(JNIEnv* env, jobject thisObj, jlong x, jlong y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700309 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700310 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogers9b269d22011-09-04 14:06:05 -0700311 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700312 EXPECT_TRUE(thisObj != nullptr);
Ian Rogers9b269d22011-09-04 14:06:05 -0700313 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700314 gJava_MyClassNatives_fooJJ_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800315 ScopedObjectAccess soa(Thread::Current());
316 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogers9b269d22011-09-04 14:06:05 -0700317 return x - y; // non-commutative operator
318}
319
Andreas Gampe6e498692014-08-18 16:43:12 -0700320void JniCompilerTest::CompileAndRunLongLongMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700321 SetUpForTest(false, "fooJJ", "(JJ)J",
Elliott Hughesb264f082012-04-06 17:10:10 -0700322 reinterpret_cast<void*>(&Java_MyClassNatives_fooJJ));
Ian Rogers9b269d22011-09-04 14:06:05 -0700323
Elliott Hughesb264f082012-04-06 17:10:10 -0700324 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_calls);
Ian Rogers0f678472014-03-10 16:18:37 -0700325 jlong a = INT64_C(0x1234567890ABCDEF);
326 jlong b = INT64_C(0xFEDCBA0987654321);
Ian Rogers9b269d22011-09-04 14:06:05 -0700327 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b);
328 EXPECT_EQ(a - b, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700329 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_calls);
Ian Rogers9b269d22011-09-04 14:06:05 -0700330 result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, b, a);
331 EXPECT_EQ(b - a, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700332 EXPECT_EQ(2, gJava_MyClassNatives_fooJJ_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700333
334 gJava_MyClassNatives_fooJJ_calls = 0;
Ian Rogers9b269d22011-09-04 14:06:05 -0700335}
336
Andreas Gampe6e498692014-08-18 16:43:12 -0700337JNI_TEST(CompileAndRunLongLongMethod)
338
Elliott Hughesb264f082012-04-06 17:10:10 -0700339int gJava_MyClassNatives_fooDD_calls = 0;
340jdouble Java_MyClassNatives_fooDD(JNIEnv* env, jobject thisObj, jdouble x, jdouble y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700341 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700342 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700343 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700344 EXPECT_TRUE(thisObj != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700345 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700346 gJava_MyClassNatives_fooDD_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800347 ScopedObjectAccess soa(Thread::Current());
348 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700349 return x - y; // non-commutative operator
350}
351
Andreas Gampe6e498692014-08-18 16:43:12 -0700352void JniCompilerTest::CompileAndRunDoubleDoubleMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700353 SetUpForTest(false, "fooDD", "(DD)D",
Elliott Hughesb264f082012-04-06 17:10:10 -0700354 reinterpret_cast<void*>(&Java_MyClassNatives_fooDD));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700355
Elliott Hughesb264f082012-04-06 17:10:10 -0700356 EXPECT_EQ(0, gJava_MyClassNatives_fooDD_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700357 jdouble result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_,
358 99.0, 10.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700359 EXPECT_DOUBLE_EQ(99.0 - 10.0, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700360 EXPECT_EQ(1, gJava_MyClassNatives_fooDD_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700361 jdouble a = 3.14159265358979323846;
362 jdouble b = 0.69314718055994530942;
363 result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -0700364 EXPECT_DOUBLE_EQ(a - b, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700365 EXPECT_EQ(2, gJava_MyClassNatives_fooDD_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700366
367 gJava_MyClassNatives_fooDD_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700368}
369
Elliott Hughes3e778f72012-05-21 15:29:52 -0700370int gJava_MyClassNatives_fooJJ_synchronized_calls = 0;
371jlong Java_MyClassNatives_fooJJ_synchronized(JNIEnv* env, jobject thisObj, jlong x, jlong y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700372 // 1 = thisObj
Ian Rogers50b35e22012-10-04 10:09:15 -0700373 EXPECT_EQ(kNative, Thread::Current()->GetState());
Elliott Hughes3e778f72012-05-21 15:29:52 -0700374 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700375 EXPECT_TRUE(thisObj != nullptr);
Elliott Hughes3e778f72012-05-21 15:29:52 -0700376 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
377 gJava_MyClassNatives_fooJJ_synchronized_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800378 ScopedObjectAccess soa(Thread::Current());
379 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Elliott Hughes3e778f72012-05-21 15:29:52 -0700380 return x | y;
381}
382
Andreas Gampe6e498692014-08-18 16:43:12 -0700383void JniCompilerTest::CompileAndRun_fooJJ_synchronizedImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700384 SetUpForTest(false, "fooJJ_synchronized", "(JJ)J",
Elliott Hughes3e778f72012-05-21 15:29:52 -0700385 reinterpret_cast<void*>(&Java_MyClassNatives_fooJJ_synchronized));
386
387 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_synchronized_calls);
388 jlong a = 0x1000000020000000ULL;
389 jlong b = 0x00ff000000aa0000ULL;
390 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b);
391 EXPECT_EQ(a | b, result);
392 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_synchronized_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700393
394 gJava_MyClassNatives_fooJJ_synchronized_calls = 0;
Elliott Hughes3e778f72012-05-21 15:29:52 -0700395}
396
Andreas Gampe6e498692014-08-18 16:43:12 -0700397JNI_TEST(CompileAndRun_fooJJ_synchronized)
398
Elliott Hughesb264f082012-04-06 17:10:10 -0700399int gJava_MyClassNatives_fooIOO_calls = 0;
400jobject Java_MyClassNatives_fooIOO(JNIEnv* env, jobject thisObj, jint x, jobject y,
Ian Rogersb033c752011-07-20 12:22:35 -0700401 jobject z) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700402 // 3 = this + y + z
Ian Rogers50b35e22012-10-04 10:09:15 -0700403 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700404 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700405 EXPECT_TRUE(thisObj != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700406 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
Elliott Hughesb264f082012-04-06 17:10:10 -0700407 gJava_MyClassNatives_fooIOO_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800408 ScopedObjectAccess soa(Thread::Current());
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800409 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0);
410 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() ||
411 (3U - null_args) == Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700412 switch (x) {
413 case 1:
414 return y;
415 case 2:
416 return z;
417 default:
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700418 return thisObj;
Ian Rogersb033c752011-07-20 12:22:35 -0700419 }
420}
421
Andreas Gampe6e498692014-08-18 16:43:12 -0700422void JniCompilerTest::CompileAndRunIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700423 SetUpForTest(false, "fooIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700424 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700425 reinterpret_cast<void*>(&Java_MyClassNatives_fooIOO));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700426
Elliott Hughesb264f082012-04-06 17:10:10 -0700427 EXPECT_EQ(0, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700428 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700429 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700430 EXPECT_EQ(1, gJava_MyClassNatives_fooIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700431
Andreas Gampecf4035a2014-05-28 22:43:01 -0700432 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, jklass_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700433 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700434 EXPECT_EQ(2, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700435 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, nullptr, jklass_);
436 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700437 EXPECT_EQ(3, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700438 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, nullptr, jklass_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700439 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700440 EXPECT_EQ(4, gJava_MyClassNatives_fooIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700441
Andreas Gampecf4035a2014-05-28 22:43:01 -0700442 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, jklass_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700443 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700444 EXPECT_EQ(5, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700445 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, jklass_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700446 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700447 EXPECT_EQ(6, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700448 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, jklass_, nullptr);
449 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700450 EXPECT_EQ(7, gJava_MyClassNatives_fooIOO_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700451
452 gJava_MyClassNatives_fooIOO_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700453}
454
Andreas Gampe6e498692014-08-18 16:43:12 -0700455JNI_TEST(CompileAndRunIntObjectObjectMethod)
456
Elliott Hughesb264f082012-04-06 17:10:10 -0700457int gJava_MyClassNatives_fooSII_calls = 0;
458jint Java_MyClassNatives_fooSII(JNIEnv* env, jclass klass, jint x, jint y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700459 // 1 = klass
Ian Rogers50b35e22012-10-04 10:09:15 -0700460 EXPECT_EQ(kNative, Thread::Current()->GetState());
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700461 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700462 EXPECT_TRUE(klass != nullptr);
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700463 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
Elliott Hughesb264f082012-04-06 17:10:10 -0700464 gJava_MyClassNatives_fooSII_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800465 ScopedObjectAccess soa(Thread::Current());
466 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700467 return x + y;
468}
469
Andreas Gampe6e498692014-08-18 16:43:12 -0700470void JniCompilerTest::CompileAndRunStaticIntIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700471 SetUpForTest(true, "fooSII", "(II)I",
Elliott Hughesb264f082012-04-06 17:10:10 -0700472 reinterpret_cast<void*>(&Java_MyClassNatives_fooSII));
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700473
Elliott Hughesb264f082012-04-06 17:10:10 -0700474 EXPECT_EQ(0, gJava_MyClassNatives_fooSII_calls);
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700475 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 20, 30);
476 EXPECT_EQ(50, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700477 EXPECT_EQ(1, gJava_MyClassNatives_fooSII_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700478
479 gJava_MyClassNatives_fooSII_calls = 0;
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700480}
481
Andreas Gampe6e498692014-08-18 16:43:12 -0700482JNI_TEST(CompileAndRunStaticIntIntMethod)
483
Elliott Hughesb264f082012-04-06 17:10:10 -0700484int gJava_MyClassNatives_fooSDD_calls = 0;
485jdouble Java_MyClassNatives_fooSDD(JNIEnv* env, jclass klass, jdouble x, jdouble y) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700486 // 1 = klass
Ian Rogers50b35e22012-10-04 10:09:15 -0700487 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogers7a99c112011-09-07 12:48:27 -0700488 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700489 EXPECT_TRUE(klass != nullptr);
Ian Rogers7a99c112011-09-07 12:48:27 -0700490 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
Elliott Hughesb264f082012-04-06 17:10:10 -0700491 gJava_MyClassNatives_fooSDD_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800492 ScopedObjectAccess soa(Thread::Current());
493 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Ian Rogers7a99c112011-09-07 12:48:27 -0700494 return x - y; // non-commutative operator
495}
496
Andreas Gampe6e498692014-08-18 16:43:12 -0700497void JniCompilerTest::CompileAndRunStaticDoubleDoubleMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700498 SetUpForTest(true, "fooSDD", "(DD)D",
Elliott Hughesb264f082012-04-06 17:10:10 -0700499 reinterpret_cast<void*>(&Java_MyClassNatives_fooSDD));
Ian Rogers7a99c112011-09-07 12:48:27 -0700500
Elliott Hughesb264f082012-04-06 17:10:10 -0700501 EXPECT_EQ(0, gJava_MyClassNatives_fooSDD_calls);
Ian Rogers7a99c112011-09-07 12:48:27 -0700502 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 99.0, 10.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700503 EXPECT_DOUBLE_EQ(99.0 - 10.0, result);
Elliott Hughesb264f082012-04-06 17:10:10 -0700504 EXPECT_EQ(1, gJava_MyClassNatives_fooSDD_calls);
Ian Rogers7a99c112011-09-07 12:48:27 -0700505 jdouble a = 3.14159265358979323846;
506 jdouble b = 0.69314718055994530942;
507 result = env_->CallStaticDoubleMethod(jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -0700508 EXPECT_DOUBLE_EQ(a - b, result);
509 EXPECT_DOUBLE_EQ(2, gJava_MyClassNatives_fooSDD_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700510
511 gJava_MyClassNatives_fooSDD_calls = 0;
Ian Rogers7a99c112011-09-07 12:48:27 -0700512}
513
Andreas Gampe6e498692014-08-18 16:43:12 -0700514JNI_TEST(CompileAndRunStaticDoubleDoubleMethod)
515
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100516// The x86 generic JNI code had a bug where it assumed a floating
517// point return value would be in xmm0. We use log, to somehow ensure
518// the compiler will use the floating point stack.
519
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700520jdouble Java_MyClassNatives_logD(JNIEnv*, jclass, jdouble x) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100521 return log(x);
522}
523
Andreas Gampe6e498692014-08-18 16:43:12 -0700524void JniCompilerTest::RunStaticLogDoubleMethodImpl() {
Andreas Gampe6e498692014-08-18 16:43:12 -0700525 SetUpForTest(true, "logD", "(D)D", reinterpret_cast<void*>(&Java_MyClassNatives_logD));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100526
527 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 2.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700528 EXPECT_DOUBLE_EQ(log(2.0), result);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100529}
530
Andreas Gampe6e498692014-08-18 16:43:12 -0700531JNI_TEST(RunStaticLogDoubleMethod)
532
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700533jfloat Java_MyClassNatives_logF(JNIEnv*, jclass, jfloat x) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100534 return logf(x);
535}
536
Andreas Gampe6e498692014-08-18 16:43:12 -0700537void JniCompilerTest::RunStaticLogFloatMethodImpl() {
Andreas Gampe6e498692014-08-18 16:43:12 -0700538 SetUpForTest(true, "logF", "(F)F", reinterpret_cast<void*>(&Java_MyClassNatives_logF));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100539
540 jfloat result = env_->CallStaticFloatMethod(jklass_, jmethod_, 2.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700541 EXPECT_FLOAT_EQ(logf(2.0), result);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100542}
543
Andreas Gampe6e498692014-08-18 16:43:12 -0700544JNI_TEST(RunStaticLogFloatMethod)
545
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700546jboolean Java_MyClassNatives_returnTrue(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100547 return JNI_TRUE;
548}
549
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700550jboolean Java_MyClassNatives_returnFalse(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100551 return JNI_FALSE;
552}
553
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700554jint Java_MyClassNatives_returnInt(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100555 return 42;
556}
557
Andreas Gampe6e498692014-08-18 16:43:12 -0700558void JniCompilerTest::RunStaticReturnTrueImpl() {
Andreas Gampe6e498692014-08-18 16:43:12 -0700559 SetUpForTest(true, "returnTrue", "()Z", reinterpret_cast<void*>(&Java_MyClassNatives_returnTrue));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100560
561 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_);
562 EXPECT_TRUE(result);
563}
564
Andreas Gampe6e498692014-08-18 16:43:12 -0700565JNI_TEST(RunStaticReturnTrue)
566
567void JniCompilerTest::RunStaticReturnFalseImpl() {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100568 SetUpForTest(true, "returnFalse", "()Z",
Andreas Gampe6e498692014-08-18 16:43:12 -0700569 reinterpret_cast<void*>(&Java_MyClassNatives_returnFalse));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100570
571 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_);
572 EXPECT_FALSE(result);
573}
574
Andreas Gampe6e498692014-08-18 16:43:12 -0700575JNI_TEST(RunStaticReturnFalse)
576
577void JniCompilerTest::RunGenericStaticReturnIntImpl() {
Andreas Gampe6e498692014-08-18 16:43:12 -0700578 SetUpForTest(true, "returnInt", "()I", reinterpret_cast<void*>(&Java_MyClassNatives_returnInt));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100579
580 jint result = env_->CallStaticIntMethod(jklass_, jmethod_);
581 EXPECT_EQ(42, result);
582}
583
Andreas Gampe6e498692014-08-18 16:43:12 -0700584JNI_TEST(RunGenericStaticReturnInt)
585
Elliott Hughesb264f082012-04-06 17:10:10 -0700586int gJava_MyClassNatives_fooSIOO_calls = 0;
587jobject Java_MyClassNatives_fooSIOO(JNIEnv* env, jclass klass, jint x, jobject y,
Ian Rogersb033c752011-07-20 12:22:35 -0700588 jobject z) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700589 // 3 = klass + y + z
Ian Rogers50b35e22012-10-04 10:09:15 -0700590 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700591 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700592 EXPECT_TRUE(klass != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700593 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
Elliott Hughesb264f082012-04-06 17:10:10 -0700594 gJava_MyClassNatives_fooSIOO_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800595 ScopedObjectAccess soa(Thread::Current());
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800596 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0);
597 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() ||
598 (3U - null_args) == Thread::Current()->NumStackReferences());
Ian Rogersb033c752011-07-20 12:22:35 -0700599 switch (x) {
600 case 1:
601 return y;
602 case 2:
603 return z;
604 default:
605 return klass;
606 }
607}
608
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700609
Andreas Gampe6e498692014-08-18 16:43:12 -0700610void JniCompilerTest::CompileAndRunStaticIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700611 SetUpForTest(true, "fooSIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700612 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700613 reinterpret_cast<void*>(&Java_MyClassNatives_fooSIOO));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700614
Elliott Hughesb264f082012-04-06 17:10:10 -0700615 EXPECT_EQ(0, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700616 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700617 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700618 EXPECT_EQ(1, gJava_MyClassNatives_fooSIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700619
Andreas Gampecf4035a2014-05-28 22:43:01 -0700620 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700621 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700622 EXPECT_EQ(2, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700623 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_);
624 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700625 EXPECT_EQ(3, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700626 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700627 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700628 EXPECT_EQ(4, gJava_MyClassNatives_fooSIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700629
Andreas Gampecf4035a2014-05-28 22:43:01 -0700630 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700631 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700632 EXPECT_EQ(5, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700633 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700634 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700635 EXPECT_EQ(6, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700636 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr);
637 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700638 EXPECT_EQ(7, gJava_MyClassNatives_fooSIOO_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700639
640 gJava_MyClassNatives_fooSIOO_calls = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700641}
642
Andreas Gampe6e498692014-08-18 16:43:12 -0700643JNI_TEST(CompileAndRunStaticIntObjectObjectMethod)
644
Elliott Hughesb264f082012-04-06 17:10:10 -0700645int gJava_MyClassNatives_fooSSIOO_calls = 0;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700646jobject Java_MyClassNatives_fooSSIOO(JNIEnv* env, jclass klass, jint x, jobject y, jobject z) {
647 // 3 = klass + y + z
Ian Rogers50b35e22012-10-04 10:09:15 -0700648 EXPECT_EQ(kNative, Thread::Current()->GetState());
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700649 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700650 EXPECT_TRUE(klass != nullptr);
Ian Rogersa8cd9f42011-08-19 16:43:41 -0700651 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
Elliott Hughesb264f082012-04-06 17:10:10 -0700652 gJava_MyClassNatives_fooSSIOO_calls++;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800653 ScopedObjectAccess soa(Thread::Current());
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800654 size_t null_args = (y == nullptr ? 1 : 0) + (z == nullptr ? 1 : 0);
655 EXPECT_TRUE(3U == Thread::Current()->NumStackReferences() ||
656 (3U - null_args) == Thread::Current()->NumStackReferences());
Ian Rogersdf20fe02011-07-20 20:34:16 -0700657 switch (x) {
658 case 1:
659 return y;
660 case 2:
661 return z;
662 default:
663 return klass;
664 }
665}
666
Andreas Gampe6e498692014-08-18 16:43:12 -0700667void JniCompilerTest::CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700668 SetUpForTest(true, "fooSSIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700669 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700670 reinterpret_cast<void*>(&Java_MyClassNatives_fooSSIOO));
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700671
Elliott Hughesb264f082012-04-06 17:10:10 -0700672 EXPECT_EQ(0, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700673 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700674 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700675 EXPECT_EQ(1, gJava_MyClassNatives_fooSSIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700676
Andreas Gampecf4035a2014-05-28 22:43:01 -0700677 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700678 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700679 EXPECT_EQ(2, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700680 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_);
681 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700682 EXPECT_EQ(3, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700683 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700684 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700685 EXPECT_EQ(4, gJava_MyClassNatives_fooSSIOO_calls);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700686
Andreas Gampecf4035a2014-05-28 22:43:01 -0700687 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700688 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700689 EXPECT_EQ(5, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700690 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700691 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700692 EXPECT_EQ(6, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700693 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr);
694 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Elliott Hughesb264f082012-04-06 17:10:10 -0700695 EXPECT_EQ(7, gJava_MyClassNatives_fooSSIOO_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700696
697 gJava_MyClassNatives_fooSSIOO_calls = 0;
Ian Rogersdf20fe02011-07-20 20:34:16 -0700698}
699
Andreas Gampe6e498692014-08-18 16:43:12 -0700700JNI_TEST(CompileAndRunStaticSynchronizedIntObjectObjectMethod)
701
Elliott Hughesb264f082012-04-06 17:10:10 -0700702void Java_MyClassNatives_throwException(JNIEnv* env, jobject) {
Elliott Hughesa2501992011-08-26 19:39:54 -0700703 jclass c = env->FindClass("java/lang/RuntimeException");
704 env->ThrowNew(c, "hello");
705}
Ian Rogers45a76cb2011-07-21 22:00:15 -0700706
Andreas Gampe6e498692014-08-18 16:43:12 -0700707void JniCompilerTest::ExceptionHandlingImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700708 {
709 ASSERT_FALSE(runtime_->IsStarted());
710 ScopedObjectAccess soa(Thread::Current());
711 class_loader_ = LoadDex("MyClassNatives");
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700712
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700713 // all compilation needs to happen before Runtime::Start
714 CompileForTest(class_loader_, false, "foo", "()V");
715 CompileForTest(class_loader_, false, "throwException", "()V");
716 CompileForTest(class_loader_, false, "foo", "()V");
717 }
718 // Start runtime to avoid re-initialization in SetupForTest.
719 Thread::Current()->TransitionFromSuspendedToRunnable();
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700720 bool started = runtime_->Start();
721 CHECK(started);
Brian Carlstrom25c33252011-09-18 15:58:35 -0700722
Elliott Hughesb264f082012-04-06 17:10:10 -0700723 gJava_MyClassNatives_foo_calls = 0;
Elliott Hughesa2501992011-08-26 19:39:54 -0700724
Ian Rogers67375ac2011-09-14 00:55:44 -0700725 // Check a single call of a JNI method is ok
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700726 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700727 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Elliott Hughesb264f082012-04-06 17:10:10 -0700728 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls);
Ian Rogers67375ac2011-09-14 00:55:44 -0700729 EXPECT_FALSE(Thread::Current()->IsExceptionPending());
Elliott Hughesa2501992011-08-26 19:39:54 -0700730
Ian Rogers67375ac2011-09-14 00:55:44 -0700731 // Get class for exception we expect to be thrown
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700732 ScopedLocalRef<jclass> jlre(env_, env_->FindClass("java/lang/RuntimeException"));
733 SetUpForTest(false, "throwException", "()V",
Elliott Hughesb264f082012-04-06 17:10:10 -0700734 reinterpret_cast<void*>(&Java_MyClassNatives_throwException));
735 // Call Java_MyClassNatives_throwException (JNI method that throws exception)
Elliott Hughesa2501992011-08-26 19:39:54 -0700736 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Elliott Hughesb264f082012-04-06 17:10:10 -0700737 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700738 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE);
739 ScopedLocalRef<jthrowable> exception(env_, env_->ExceptionOccurred());
740 env_->ExceptionClear();
741 EXPECT_TRUE(env_->IsInstanceOf(exception.get(), jlre.get()));
Elliott Hughesa2501992011-08-26 19:39:54 -0700742
Ian Rogers67375ac2011-09-14 00:55:44 -0700743 // Check a single call of a JNI method is ok
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700744 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700745 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Elliott Hughesb264f082012-04-06 17:10:10 -0700746 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700747
748 gJava_MyClassNatives_foo_calls = 0;
Ian Rogers45a76cb2011-07-21 22:00:15 -0700749}
750
Andreas Gampe6e498692014-08-18 16:43:12 -0700751JNI_TEST(ExceptionHandling)
752
Elliott Hughesb264f082012-04-06 17:10:10 -0700753jint Java_MyClassNatives_nativeUpCall(JNIEnv* env, jobject thisObj, jint i) {
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700754 if (i <= 0) {
Andreas Gampecf4035a2014-05-28 22:43:01 -0700755 // We want to check raw Object* / Array* below
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700756 ScopedObjectAccess soa(env);
Ian Rogersaaa20802011-09-11 21:47:37 -0700757
758 // Build stack trace
Sebastien Hertzee1d79a2014-02-21 15:46:30 +0100759 jobject internal = Thread::Current()->CreateInternalStackTrace<false>(soa);
Ian Rogers53b8b092014-03-13 23:45:53 -0700760 jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800761 mirror::ObjectArray<mirror::StackTraceElement>* trace_array =
762 soa.Decode<mirror::ObjectArray<mirror::StackTraceElement>*>(ste_array);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700763 EXPECT_TRUE(trace_array != nullptr);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700764 EXPECT_EQ(11, trace_array->GetLength());
765
Ian Rogersaaa20802011-09-11 21:47:37 -0700766 // Check stack trace entries have expected values
Andreas Gampe277ccbd2014-11-03 21:36:10 -0800767 for (int32_t j = 0; j < trace_array->GetLength(); ++j) {
768 EXPECT_EQ(-2, trace_array->Get(j)->GetLineNumber());
769 mirror::StackTraceElement* ste = trace_array->Get(j);
Ian Rogersaaa20802011-09-11 21:47:37 -0700770 EXPECT_STREQ("MyClassNatives.java", ste->GetFileName()->ToModifiedUtf8().c_str());
Elliott Hughesb264f082012-04-06 17:10:10 -0700771 EXPECT_STREQ("MyClassNatives", ste->GetDeclaringClass()->ToModifiedUtf8().c_str());
Ian Rogersaaa20802011-09-11 21:47:37 -0700772 EXPECT_STREQ("fooI", ste->GetMethodName()->ToModifiedUtf8().c_str());
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700773 }
Ian Rogersaaa20802011-09-11 21:47:37 -0700774
775 // end recursion
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700776 return 0;
777 } else {
Elliott Hughesb264f082012-04-06 17:10:10 -0700778 jclass jklass = env->FindClass("MyClassNatives");
Andreas Gampecf4035a2014-05-28 22:43:01 -0700779 EXPECT_TRUE(jklass != nullptr);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700780 jmethodID jmethod = env->GetMethodID(jklass, "fooI", "(I)I");
Andreas Gampecf4035a2014-05-28 22:43:01 -0700781 EXPECT_TRUE(jmethod != nullptr);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700782
Ian Rogersaaa20802011-09-11 21:47:37 -0700783 // Recurse with i - 1
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700784 jint result = env->CallNonvirtualIntMethod(thisObj, jklass, jmethod, i - 1);
Ian Rogersaaa20802011-09-11 21:47:37 -0700785
786 // Return sum of all depths
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700787 return i + result;
788 }
789}
790
Andreas Gampe6e498692014-08-18 16:43:12 -0700791void JniCompilerTest::NativeStackTraceElementImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700792 SetUpForTest(false, "fooI", "(I)I",
Elliott Hughesb264f082012-04-06 17:10:10 -0700793 reinterpret_cast<void*>(&Java_MyClassNatives_nativeUpCall));
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700794 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 10);
Ian Rogersaaa20802011-09-11 21:47:37 -0700795 EXPECT_EQ(10+9+8+7+6+5+4+3+2+1, result);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -0700796}
797
Andreas Gampe6e498692014-08-18 16:43:12 -0700798JNI_TEST(NativeStackTraceElement)
799
Elliott Hughesb264f082012-04-06 17:10:10 -0700800jobject Java_MyClassNatives_fooO(JNIEnv* env, jobject, jobject x) {
Shih-wei Liao558788e2011-09-01 02:39:11 -0700801 return env->NewGlobalRef(x);
802}
803
Andreas Gampe6e498692014-08-18 16:43:12 -0700804void JniCompilerTest::ReturnGlobalRefImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700805 SetUpForTest(false, "fooO", "(Ljava/lang/Object;)Ljava/lang/Object;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700806 reinterpret_cast<void*>(&Java_MyClassNatives_fooO));
Shih-wei Liao558788e2011-09-01 02:39:11 -0700807 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, jobj_);
808 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(result));
809 EXPECT_TRUE(env_->IsSameObject(result, jobj_));
810}
811
Andreas Gampe6e498692014-08-18 16:43:12 -0700812JNI_TEST(ReturnGlobalRef)
813
Ian Rogersdc51b792011-09-22 20:41:37 -0700814jint local_ref_test(JNIEnv* env, jobject thisObj, jint x) {
815 // Add 10 local references
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700816 ScopedObjectAccess soa(env);
Ian Rogers5a7a74a2011-09-26 16:32:29 -0700817 for (int i = 0; i < 10; i++) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800818 soa.AddLocalReference<jobject>(soa.Decode<mirror::Object*>(thisObj));
Ian Rogersdc51b792011-09-22 20:41:37 -0700819 }
820 return x+1;
821}
822
Andreas Gampe6e498692014-08-18 16:43:12 -0700823void JniCompilerTest::LocalReferenceTableClearingTestImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700824 SetUpForTest(false, "fooI", "(I)I", reinterpret_cast<void*>(&local_ref_test));
Ian Rogersdc51b792011-09-22 20:41:37 -0700825 // 1000 invocations of a method that adds 10 local references
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700826 for (int i = 0; i < 1000; i++) {
Ian Rogersdc51b792011-09-22 20:41:37 -0700827 jint result = env_->CallIntMethod(jobj_, jmethod_, i);
828 EXPECT_TRUE(result == i + 1);
829 }
830}
831
Andreas Gampe6e498692014-08-18 16:43:12 -0700832JNI_TEST(LocalReferenceTableClearingTest)
833
Ian Rogersb9231c82011-09-05 22:13:19 -0700834void my_arraycopy(JNIEnv* env, jclass klass, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) {
835 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, klass));
836 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, dst));
Ian Rogers82f3e092011-09-05 22:54:45 -0700837 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, src));
Ian Rogersb9231c82011-09-05 22:13:19 -0700838 EXPECT_EQ(1234, src_pos);
839 EXPECT_EQ(5678, dst_pos);
840 EXPECT_EQ(9876, length);
841}
842
Andreas Gampe6e498692014-08-18 16:43:12 -0700843void JniCompilerTest::JavaLangSystemArrayCopyImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700844 SetUpForTest(true, "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V",
Ian Rogersb9231c82011-09-05 22:13:19 -0700845 reinterpret_cast<void*>(&my_arraycopy));
Ian Rogers82f3e092011-09-05 22:54:45 -0700846 env_->CallStaticVoidMethod(jklass_, jmethod_, jobj_, 1234, jklass_, 5678, 9876);
Ian Rogersb9231c82011-09-05 22:13:19 -0700847}
848
Andreas Gampe6e498692014-08-18 16:43:12 -0700849JNI_TEST(JavaLangSystemArrayCopy)
850
Ian Rogers67375ac2011-09-14 00:55:44 -0700851jboolean my_casi(JNIEnv* env, jobject unsafe, jobject obj, jlong offset, jint expected, jint newval) {
852 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, unsafe));
853 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj));
Ian Rogers0f678472014-03-10 16:18:37 -0700854 EXPECT_EQ(INT64_C(0x12345678ABCDEF88), offset);
Ian Rogers67375ac2011-09-14 00:55:44 -0700855 EXPECT_EQ(static_cast<jint>(0xCAFEF00D), expected);
856 EXPECT_EQ(static_cast<jint>(0xEBADF00D), newval);
857 return JNI_TRUE;
858}
859
Andreas Gampe6e498692014-08-18 16:43:12 -0700860void JniCompilerTest::CompareAndSwapIntImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700861 SetUpForTest(false, "compareAndSwapInt", "(Ljava/lang/Object;JII)Z",
Ian Rogers67375ac2011-09-14 00:55:44 -0700862 reinterpret_cast<void*>(&my_casi));
Ian Rogers0f678472014-03-10 16:18:37 -0700863 jboolean result = env_->CallBooleanMethod(jobj_, jmethod_, jobj_, INT64_C(0x12345678ABCDEF88),
864 0xCAFEF00D, 0xEBADF00D);
Ian Rogers67375ac2011-09-14 00:55:44 -0700865 EXPECT_EQ(result, JNI_TRUE);
866}
867
Andreas Gampe6e498692014-08-18 16:43:12 -0700868JNI_TEST(CompareAndSwapInt)
869
Ian Rogersc7792842012-03-03 15:36:20 -0800870jint my_gettext(JNIEnv* env, jclass klass, jlong val1, jobject obj1, jlong val2, jobject obj2) {
871 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
872 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj1));
873 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj2));
874 EXPECT_EQ(0x12345678ABCDEF88ll, val1);
875 EXPECT_EQ(0x7FEDCBA987654321ll, val2);
876 return 42;
877}
878
Andreas Gampe6e498692014-08-18 16:43:12 -0700879void JniCompilerTest::GetTextImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700880 SetUpForTest(true, "getText", "(JLjava/lang/Object;JLjava/lang/Object;)I",
Ian Rogersc7792842012-03-03 15:36:20 -0800881 reinterpret_cast<void*>(&my_gettext));
882 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 0x12345678ABCDEF88ll, jobj_,
Ian Rogers0f678472014-03-10 16:18:37 -0700883 INT64_C(0x7FEDCBA987654321), jobj_);
Ian Rogersc7792842012-03-03 15:36:20 -0800884 EXPECT_EQ(result, 42);
885}
886
Andreas Gampe6e498692014-08-18 16:43:12 -0700887JNI_TEST(GetText)
888
Vladimir Marko4e24b9d2014-07-24 17:01:58 +0100889int gJava_MyClassNatives_GetSinkProperties_calls = 0;
890jarray Java_MyClassNatives_GetSinkProperties(JNIEnv* env, jobject thisObj, jstring s) {
891 // 1 = thisObj
892 Thread* self = Thread::Current();
893 EXPECT_EQ(kNative, self->GetState());
894 Locks::mutator_lock_->AssertNotHeld(self);
895 EXPECT_EQ(self->GetJniEnv(), env);
896 EXPECT_TRUE(thisObj != nullptr);
897 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
898 EXPECT_EQ(s, nullptr);
899 gJava_MyClassNatives_GetSinkProperties_calls++;
900 ScopedObjectAccess soa(self);
901 EXPECT_EQ(2U, self->NumStackReferences());
902 EXPECT_TRUE(self->HoldsLock(soa.Decode<mirror::Object*>(thisObj)));
903 return nullptr;
904}
905
Andreas Gampe6e498692014-08-18 16:43:12 -0700906void JniCompilerTest::GetSinkPropertiesNativeImpl() {
Vladimir Marko4e24b9d2014-07-24 17:01:58 +0100907 SetUpForTest(false, "getSinkPropertiesNative", "(Ljava/lang/String;)[Ljava/lang/Object;",
908 reinterpret_cast<void*>(&Java_MyClassNatives_GetSinkProperties));
909
910 EXPECT_EQ(0, gJava_MyClassNatives_GetSinkProperties_calls);
911 jarray result = down_cast<jarray>(
912 env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, nullptr));
913 EXPECT_EQ(nullptr, result);
914 EXPECT_EQ(1, gJava_MyClassNatives_GetSinkProperties_calls);
Andreas Gampe6e498692014-08-18 16:43:12 -0700915
916 gJava_MyClassNatives_GetSinkProperties_calls = 0;
Brian Carlstromfc7120c2012-08-27 13:43:25 -0700917}
918
Andreas Gampe6e498692014-08-18 16:43:12 -0700919JNI_TEST(GetSinkPropertiesNative)
920
Elliott Hughesb264f082012-04-06 17:10:10 -0700921// This should return jclass, but we're imitating a bug pattern.
922jobject Java_MyClassNatives_instanceMethodThatShouldReturnClass(JNIEnv* env, jobject) {
923 return env->NewStringUTF("not a class!");
924}
925
926// This should return jclass, but we're imitating a bug pattern.
927jobject Java_MyClassNatives_staticMethodThatShouldReturnClass(JNIEnv* env, jclass) {
928 return env->NewStringUTF("not a class!");
929}
930
Andreas Gampe6e498692014-08-18 16:43:12 -0700931void JniCompilerTest::UpcallReturnTypeChecking_InstanceImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700932 SetUpForTest(false, "instanceMethodThatShouldReturnClass", "()Ljava/lang/Class;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700933 reinterpret_cast<void*>(&Java_MyClassNatives_instanceMethodThatShouldReturnClass));
934
935 CheckJniAbortCatcher check_jni_abort_catcher;
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700936 // This native method is bad, and tries to return a jstring as a jclass.
937 env_->CallObjectMethod(jobj_, jmethod_);
938 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass()");
939
940 // Here, we just call the method incorrectly; we should catch that too.
Ian Rogers68d8b422014-07-17 11:09:10 -0700941 env_->CallObjectMethod(jobj_, jmethod_);
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700942 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass()");
Ian Rogers68d8b422014-07-17 11:09:10 -0700943 env_->CallStaticObjectMethod(jklass_, jmethod_);
944 check_jni_abort_catcher.Check("calling non-static method java.lang.Class MyClassNatives.instanceMethodThatShouldReturnClass() with CallStaticObjectMethodV");
Elliott Hughesb264f082012-04-06 17:10:10 -0700945}
946
Andreas Gampe6e498692014-08-18 16:43:12 -0700947JNI_TEST(UpcallReturnTypeChecking_Instance)
948
949void JniCompilerTest::UpcallReturnTypeChecking_StaticImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700950 SetUpForTest(true, "staticMethodThatShouldReturnClass", "()Ljava/lang/Class;",
Elliott Hughesb264f082012-04-06 17:10:10 -0700951 reinterpret_cast<void*>(&Java_MyClassNatives_staticMethodThatShouldReturnClass));
952
953 CheckJniAbortCatcher check_jni_abort_catcher;
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700954 // This native method is bad, and tries to return a jstring as a jclass.
955 env_->CallStaticObjectMethod(jklass_, jmethod_);
956 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass()");
957
958 // Here, we just call the method incorrectly; we should catch that too.
Ian Rogers68d8b422014-07-17 11:09:10 -0700959 env_->CallStaticObjectMethod(jklass_, jmethod_);
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700960 check_jni_abort_catcher.Check("attempt to return an instance of java.lang.String from java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass()");
Ian Rogers68d8b422014-07-17 11:09:10 -0700961 env_->CallObjectMethod(jobj_, jmethod_);
962 check_jni_abort_catcher.Check("calling static method java.lang.Class MyClassNatives.staticMethodThatShouldReturnClass() with CallObjectMethodV");
Elliott Hughesb264f082012-04-06 17:10:10 -0700963}
964
Andreas Gampe6e498692014-08-18 16:43:12 -0700965JNI_TEST(UpcallReturnTypeChecking_Static)
966
Elliott Hughesb264f082012-04-06 17:10:10 -0700967// This should take jclass, but we're imitating a bug pattern.
968void Java_MyClassNatives_instanceMethodThatShouldTakeClass(JNIEnv*, jobject, jclass) {
969}
970
971// This should take jclass, but we're imitating a bug pattern.
972void Java_MyClassNatives_staticMethodThatShouldTakeClass(JNIEnv*, jclass, jclass) {
973}
974
Andreas Gampe6e498692014-08-18 16:43:12 -0700975void JniCompilerTest::UpcallArgumentTypeChecking_InstanceImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -0800976 // This will lead to error messages in the log.
977 ScopedLogSeverity sls(LogSeverity::FATAL);
978
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700979 SetUpForTest(false, "instanceMethodThatShouldTakeClass", "(ILjava/lang/Class;)V",
Elliott Hughesb264f082012-04-06 17:10:10 -0700980 reinterpret_cast<void*>(&Java_MyClassNatives_instanceMethodThatShouldTakeClass));
981
982 CheckJniAbortCatcher check_jni_abort_catcher;
983 // We deliberately pass a bad second argument here.
984 env_->CallVoidMethod(jobj_, jmethod_, 123, env_->NewStringUTF("not a class!"));
Elliott Hughes3f6635a2012-06-19 13:37:49 -0700985 check_jni_abort_catcher.Check("bad arguments passed to void MyClassNatives.instanceMethodThatShouldTakeClass(int, java.lang.Class)");
Elliott Hughesb264f082012-04-06 17:10:10 -0700986}
987
Andreas Gampe6e498692014-08-18 16:43:12 -0700988JNI_TEST(UpcallArgumentTypeChecking_Instance)
989
990void JniCompilerTest::UpcallArgumentTypeChecking_StaticImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -0800991 // This will lead to error messages in the log.
992 ScopedLogSeverity sls(LogSeverity::FATAL);
993
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700994 SetUpForTest(true, "staticMethodThatShouldTakeClass", "(ILjava/lang/Class;)V",
Elliott Hughesb264f082012-04-06 17:10:10 -0700995 reinterpret_cast<void*>(&Java_MyClassNatives_staticMethodThatShouldTakeClass));
996
997 CheckJniAbortCatcher check_jni_abort_catcher;
998 // We deliberately pass a bad second argument here.
999 env_->CallStaticVoidMethod(jklass_, jmethod_, 123, env_->NewStringUTF("not a class!"));
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001000 check_jni_abort_catcher.Check("bad arguments passed to void MyClassNatives.staticMethodThatShouldTakeClass(int, java.lang.Class)");
Elliott Hughesb264f082012-04-06 17:10:10 -07001001}
1002
Andreas Gampe6e498692014-08-18 16:43:12 -07001003JNI_TEST(UpcallArgumentTypeChecking_Static)
1004
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001005jfloat Java_MyClassNatives_checkFloats(JNIEnv* env, jobject thisObj, jfloat f1, jfloat f2) {
1006 EXPECT_EQ(kNative, Thread::Current()->GetState());
1007 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001008 EXPECT_TRUE(thisObj != nullptr);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001009 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
1010 ScopedObjectAccess soa(Thread::Current());
1011 EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
1012 return f1 - f2; // non-commutative operator
1013}
1014
Andreas Gampe6e498692014-08-18 16:43:12 -07001015void JniCompilerTest::CompileAndRunFloatFloatMethodImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001016 SetUpForTest(false, "checkFloats", "(FF)F",
1017 reinterpret_cast<void*>(&Java_MyClassNatives_checkFloats));
1018
1019 jfloat result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_,
1020 99.0F, 10.0F);
Ian Rogers647b1a82014-10-10 11:02:11 -07001021 EXPECT_FLOAT_EQ(99.0F - 10.0F, result);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001022 jfloat a = 3.14159F;
1023 jfloat b = 0.69314F;
1024 result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -07001025 EXPECT_FLOAT_EQ(a - b, result);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001026}
1027
Andreas Gampe6e498692014-08-18 16:43:12 -07001028JNI_TEST(CompileAndRunFloatFloatMethod)
1029
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001030void Java_MyClassNatives_checkParameterAlign(JNIEnv* env ATTRIBUTE_UNUSED,
1031 jobject thisObj ATTRIBUTE_UNUSED,
1032 jint i1 ATTRIBUTE_UNUSED,
1033 jlong l1 ATTRIBUTE_UNUSED) {
Andreas Gampecf4035a2014-05-28 22:43:01 -07001034// EXPECT_EQ(kNative, Thread::Current()->GetState());
1035// EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
1036// EXPECT_TRUE(thisObj != nullptr);
1037// EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
1038// ScopedObjectAccess soa(Thread::Current());
1039// EXPECT_EQ(1U, Thread::Current()->NumStackReferences());
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001040 EXPECT_EQ(i1, 1234);
Ian Rogers0f678472014-03-10 16:18:37 -07001041 EXPECT_EQ(l1, INT64_C(0x12345678ABCDEF0));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001042}
1043
Andreas Gampe6e498692014-08-18 16:43:12 -07001044void JniCompilerTest::CheckParameterAlignImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001045 SetUpForTest(false, "checkParameterAlign", "(IJ)V",
1046 reinterpret_cast<void*>(&Java_MyClassNatives_checkParameterAlign));
1047
Ian Rogers0f678472014-03-10 16:18:37 -07001048 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_, 1234, INT64_C(0x12345678ABCDEF0));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001049}
1050
Andreas Gampe6e498692014-08-18 16:43:12 -07001051JNI_TEST(CheckParameterAlign)
1052
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001053void Java_MyClassNatives_maxParamNumber(JNIEnv* env, jobject thisObj,
1054 jobject o0, jobject o1, jobject o2, jobject o3, jobject o4, jobject o5, jobject o6, jobject o7,
1055 jobject o8, jobject o9, jobject o10, jobject o11, jobject o12, jobject o13, jobject o14, jobject o15,
1056 jobject o16, jobject o17, jobject o18, jobject o19, jobject o20, jobject o21, jobject o22, jobject o23,
1057 jobject o24, jobject o25, jobject o26, jobject o27, jobject o28, jobject o29, jobject o30, jobject o31,
1058 jobject o32, jobject o33, jobject o34, jobject o35, jobject o36, jobject o37, jobject o38, jobject o39,
1059 jobject o40, jobject o41, jobject o42, jobject o43, jobject o44, jobject o45, jobject o46, jobject o47,
1060 jobject o48, jobject o49, jobject o50, jobject o51, jobject o52, jobject o53, jobject o54, jobject o55,
1061 jobject o56, jobject o57, jobject o58, jobject o59, jobject o60, jobject o61, jobject o62, jobject o63,
1062 jobject o64, jobject o65, jobject o66, jobject o67, jobject o68, jobject o69, jobject o70, jobject o71,
1063 jobject o72, jobject o73, jobject o74, jobject o75, jobject o76, jobject o77, jobject o78, jobject o79,
1064 jobject o80, jobject o81, jobject o82, jobject o83, jobject o84, jobject o85, jobject o86, jobject o87,
1065 jobject o88, jobject o89, jobject o90, jobject o91, jobject o92, jobject o93, jobject o94, jobject o95,
1066 jobject o96, jobject o97, jobject o98, jobject o99, jobject o100, jobject o101, jobject o102, jobject o103,
1067 jobject o104, jobject o105, jobject o106, jobject o107, jobject o108, jobject o109, jobject o110, jobject o111,
1068 jobject o112, jobject o113, jobject o114, jobject o115, jobject o116, jobject o117, jobject o118, jobject o119,
1069 jobject o120, jobject o121, jobject o122, jobject o123, jobject o124, jobject o125, jobject o126, jobject o127,
1070 jobject o128, jobject o129, jobject o130, jobject o131, jobject o132, jobject o133, jobject o134, jobject o135,
1071 jobject o136, jobject o137, jobject o138, jobject o139, jobject o140, jobject o141, jobject o142, jobject o143,
1072 jobject o144, jobject o145, jobject o146, jobject o147, jobject o148, jobject o149, jobject o150, jobject o151,
1073 jobject o152, jobject o153, jobject o154, jobject o155, jobject o156, jobject o157, jobject o158, jobject o159,
1074 jobject o160, jobject o161, jobject o162, jobject o163, jobject o164, jobject o165, jobject o166, jobject o167,
1075 jobject o168, jobject o169, jobject o170, jobject o171, jobject o172, jobject o173, jobject o174, jobject o175,
1076 jobject o176, jobject o177, jobject o178, jobject o179, jobject o180, jobject o181, jobject o182, jobject o183,
1077 jobject o184, jobject o185, jobject o186, jobject o187, jobject o188, jobject o189, jobject o190, jobject o191,
1078 jobject o192, jobject o193, jobject o194, jobject o195, jobject o196, jobject o197, jobject o198, jobject o199,
1079 jobject o200, jobject o201, jobject o202, jobject o203, jobject o204, jobject o205, jobject o206, jobject o207,
1080 jobject o208, jobject o209, jobject o210, jobject o211, jobject o212, jobject o213, jobject o214, jobject o215,
1081 jobject o216, jobject o217, jobject o218, jobject o219, jobject o220, jobject o221, jobject o222, jobject o223,
1082 jobject o224, jobject o225, jobject o226, jobject o227, jobject o228, jobject o229, jobject o230, jobject o231,
1083 jobject o232, jobject o233, jobject o234, jobject o235, jobject o236, jobject o237, jobject o238, jobject o239,
1084 jobject o240, jobject o241, jobject o242, jobject o243, jobject o244, jobject o245, jobject o246, jobject o247,
1085 jobject o248, jobject o249, jobject o250, jobject o251, jobject o252, jobject o253) {
1086 EXPECT_EQ(kNative, Thread::Current()->GetState());
1087 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001088 EXPECT_TRUE(thisObj != nullptr);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001089 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
1090 ScopedObjectAccess soa(Thread::Current());
1091 EXPECT_GE(255U, Thread::Current()->NumStackReferences());
1092
1093 // two tests possible
1094 if (o0 == nullptr) {
1095 // 1) everything is null
1096 EXPECT_TRUE(o0 == nullptr && o1 == nullptr && o2 == nullptr && o3 == nullptr && o4 == nullptr
1097 && o5 == nullptr && o6 == nullptr && o7 == nullptr && o8 == nullptr && o9 == nullptr
1098 && o10 == nullptr && o11 == nullptr && o12 == nullptr && o13 == nullptr && o14 == nullptr
1099 && o15 == nullptr && o16 == nullptr && o17 == nullptr && o18 == nullptr && o19 == nullptr
1100 && o20 == nullptr && o21 == nullptr && o22 == nullptr && o23 == nullptr && o24 == nullptr
1101 && o25 == nullptr && o26 == nullptr && o27 == nullptr && o28 == nullptr && o29 == nullptr
1102 && o30 == nullptr && o31 == nullptr && o32 == nullptr && o33 == nullptr && o34 == nullptr
1103 && o35 == nullptr && o36 == nullptr && o37 == nullptr && o38 == nullptr && o39 == nullptr
1104 && o40 == nullptr && o41 == nullptr && o42 == nullptr && o43 == nullptr && o44 == nullptr
1105 && o45 == nullptr && o46 == nullptr && o47 == nullptr && o48 == nullptr && o49 == nullptr
1106 && o50 == nullptr && o51 == nullptr && o52 == nullptr && o53 == nullptr && o54 == nullptr
1107 && o55 == nullptr && o56 == nullptr && o57 == nullptr && o58 == nullptr && o59 == nullptr
1108 && o60 == nullptr && o61 == nullptr && o62 == nullptr && o63 == nullptr && o64 == nullptr
1109 && o65 == nullptr && o66 == nullptr && o67 == nullptr && o68 == nullptr && o69 == nullptr
1110 && o70 == nullptr && o71 == nullptr && o72 == nullptr && o73 == nullptr && o74 == nullptr
1111 && o75 == nullptr && o76 == nullptr && o77 == nullptr && o78 == nullptr && o79 == nullptr
1112 && o80 == nullptr && o81 == nullptr && o82 == nullptr && o83 == nullptr && o84 == nullptr
1113 && o85 == nullptr && o86 == nullptr && o87 == nullptr && o88 == nullptr && o89 == nullptr
1114 && o90 == nullptr && o91 == nullptr && o92 == nullptr && o93 == nullptr && o94 == nullptr
1115 && o95 == nullptr && o96 == nullptr && o97 == nullptr && o98 == nullptr && o99 == nullptr
1116 && o100 == nullptr && o101 == nullptr && o102 == nullptr && o103 == nullptr && o104 == nullptr
1117 && o105 == nullptr && o106 == nullptr && o107 == nullptr && o108 == nullptr && o109 == nullptr
1118 && o110 == nullptr && o111 == nullptr && o112 == nullptr && o113 == nullptr && o114 == nullptr
1119 && o115 == nullptr && o116 == nullptr && o117 == nullptr && o118 == nullptr && o119 == nullptr
1120 && o120 == nullptr && o121 == nullptr && o122 == nullptr && o123 == nullptr && o124 == nullptr
1121 && o125 == nullptr && o126 == nullptr && o127 == nullptr && o128 == nullptr && o129 == nullptr
1122 && o130 == nullptr && o131 == nullptr && o132 == nullptr && o133 == nullptr && o134 == nullptr
1123 && o135 == nullptr && o136 == nullptr && o137 == nullptr && o138 == nullptr && o139 == nullptr
1124 && o140 == nullptr && o141 == nullptr && o142 == nullptr && o143 == nullptr && o144 == nullptr
1125 && o145 == nullptr && o146 == nullptr && o147 == nullptr && o148 == nullptr && o149 == nullptr
1126 && o150 == nullptr && o151 == nullptr && o152 == nullptr && o153 == nullptr && o154 == nullptr
1127 && o155 == nullptr && o156 == nullptr && o157 == nullptr && o158 == nullptr && o159 == nullptr
1128 && o160 == nullptr && o161 == nullptr && o162 == nullptr && o163 == nullptr && o164 == nullptr
1129 && o165 == nullptr && o166 == nullptr && o167 == nullptr && o168 == nullptr && o169 == nullptr
1130 && o170 == nullptr && o171 == nullptr && o172 == nullptr && o173 == nullptr && o174 == nullptr
1131 && o175 == nullptr && o176 == nullptr && o177 == nullptr && o178 == nullptr && o179 == nullptr
1132 && o180 == nullptr && o181 == nullptr && o182 == nullptr && o183 == nullptr && o184 == nullptr
1133 && o185 == nullptr && o186 == nullptr && o187 == nullptr && o188 == nullptr && o189 == nullptr
1134 && o190 == nullptr && o191 == nullptr && o192 == nullptr && o193 == nullptr && o194 == nullptr
1135 && o195 == nullptr && o196 == nullptr && o197 == nullptr && o198 == nullptr && o199 == nullptr
1136 && o200 == nullptr && o201 == nullptr && o202 == nullptr && o203 == nullptr && o204 == nullptr
1137 && o205 == nullptr && o206 == nullptr && o207 == nullptr && o208 == nullptr && o209 == nullptr
1138 && o210 == nullptr && o211 == nullptr && o212 == nullptr && o213 == nullptr && o214 == nullptr
1139 && o215 == nullptr && o216 == nullptr && o217 == nullptr && o218 == nullptr && o219 == nullptr
1140 && o220 == nullptr && o221 == nullptr && o222 == nullptr && o223 == nullptr && o224 == nullptr
1141 && o225 == nullptr && o226 == nullptr && o227 == nullptr && o228 == nullptr && o229 == nullptr
1142 && o230 == nullptr && o231 == nullptr && o232 == nullptr && o233 == nullptr && o234 == nullptr
1143 && o235 == nullptr && o236 == nullptr && o237 == nullptr && o238 == nullptr && o239 == nullptr
1144 && o240 == nullptr && o241 == nullptr && o242 == nullptr && o243 == nullptr && o244 == nullptr
1145 && o245 == nullptr && o246 == nullptr && o247 == nullptr && o248 == nullptr && o249 == nullptr
1146 && o250 == nullptr && o251 == nullptr && o252 == nullptr && o253 == nullptr);
1147 } else {
1148 EXPECT_EQ(0, env->GetArrayLength(reinterpret_cast<jarray>(o0)));
1149 EXPECT_EQ(1, env->GetArrayLength(reinterpret_cast<jarray>(o1)));
1150 EXPECT_EQ(2, env->GetArrayLength(reinterpret_cast<jarray>(o2)));
1151 EXPECT_EQ(3, env->GetArrayLength(reinterpret_cast<jarray>(o3)));
1152 EXPECT_EQ(4, env->GetArrayLength(reinterpret_cast<jarray>(o4)));
1153 EXPECT_EQ(5, env->GetArrayLength(reinterpret_cast<jarray>(o5)));
1154 EXPECT_EQ(6, env->GetArrayLength(reinterpret_cast<jarray>(o6)));
1155 EXPECT_EQ(7, env->GetArrayLength(reinterpret_cast<jarray>(o7)));
1156 EXPECT_EQ(8, env->GetArrayLength(reinterpret_cast<jarray>(o8)));
1157 EXPECT_EQ(9, env->GetArrayLength(reinterpret_cast<jarray>(o9)));
1158 EXPECT_EQ(10, env->GetArrayLength(reinterpret_cast<jarray>(o10)));
1159 EXPECT_EQ(11, env->GetArrayLength(reinterpret_cast<jarray>(o11)));
1160 EXPECT_EQ(12, env->GetArrayLength(reinterpret_cast<jarray>(o12)));
1161 EXPECT_EQ(13, env->GetArrayLength(reinterpret_cast<jarray>(o13)));
1162 EXPECT_EQ(14, env->GetArrayLength(reinterpret_cast<jarray>(o14)));
1163 EXPECT_EQ(15, env->GetArrayLength(reinterpret_cast<jarray>(o15)));
1164 EXPECT_EQ(16, env->GetArrayLength(reinterpret_cast<jarray>(o16)));
1165 EXPECT_EQ(17, env->GetArrayLength(reinterpret_cast<jarray>(o17)));
1166 EXPECT_EQ(18, env->GetArrayLength(reinterpret_cast<jarray>(o18)));
1167 EXPECT_EQ(19, env->GetArrayLength(reinterpret_cast<jarray>(o19)));
1168 EXPECT_EQ(20, env->GetArrayLength(reinterpret_cast<jarray>(o20)));
1169 EXPECT_EQ(21, env->GetArrayLength(reinterpret_cast<jarray>(o21)));
1170 EXPECT_EQ(22, env->GetArrayLength(reinterpret_cast<jarray>(o22)));
1171 EXPECT_EQ(23, env->GetArrayLength(reinterpret_cast<jarray>(o23)));
1172 EXPECT_EQ(24, env->GetArrayLength(reinterpret_cast<jarray>(o24)));
1173 EXPECT_EQ(25, env->GetArrayLength(reinterpret_cast<jarray>(o25)));
1174 EXPECT_EQ(26, env->GetArrayLength(reinterpret_cast<jarray>(o26)));
1175 EXPECT_EQ(27, env->GetArrayLength(reinterpret_cast<jarray>(o27)));
1176 EXPECT_EQ(28, env->GetArrayLength(reinterpret_cast<jarray>(o28)));
1177 EXPECT_EQ(29, env->GetArrayLength(reinterpret_cast<jarray>(o29)));
1178 EXPECT_EQ(30, env->GetArrayLength(reinterpret_cast<jarray>(o30)));
1179 EXPECT_EQ(31, env->GetArrayLength(reinterpret_cast<jarray>(o31)));
1180 EXPECT_EQ(32, env->GetArrayLength(reinterpret_cast<jarray>(o32)));
1181 EXPECT_EQ(33, env->GetArrayLength(reinterpret_cast<jarray>(o33)));
1182 EXPECT_EQ(34, env->GetArrayLength(reinterpret_cast<jarray>(o34)));
1183 EXPECT_EQ(35, env->GetArrayLength(reinterpret_cast<jarray>(o35)));
1184 EXPECT_EQ(36, env->GetArrayLength(reinterpret_cast<jarray>(o36)));
1185 EXPECT_EQ(37, env->GetArrayLength(reinterpret_cast<jarray>(o37)));
1186 EXPECT_EQ(38, env->GetArrayLength(reinterpret_cast<jarray>(o38)));
1187 EXPECT_EQ(39, env->GetArrayLength(reinterpret_cast<jarray>(o39)));
1188 EXPECT_EQ(40, env->GetArrayLength(reinterpret_cast<jarray>(o40)));
1189 EXPECT_EQ(41, env->GetArrayLength(reinterpret_cast<jarray>(o41)));
1190 EXPECT_EQ(42, env->GetArrayLength(reinterpret_cast<jarray>(o42)));
1191 EXPECT_EQ(43, env->GetArrayLength(reinterpret_cast<jarray>(o43)));
1192 EXPECT_EQ(44, env->GetArrayLength(reinterpret_cast<jarray>(o44)));
1193 EXPECT_EQ(45, env->GetArrayLength(reinterpret_cast<jarray>(o45)));
1194 EXPECT_EQ(46, env->GetArrayLength(reinterpret_cast<jarray>(o46)));
1195 EXPECT_EQ(47, env->GetArrayLength(reinterpret_cast<jarray>(o47)));
1196 EXPECT_EQ(48, env->GetArrayLength(reinterpret_cast<jarray>(o48)));
1197 EXPECT_EQ(49, env->GetArrayLength(reinterpret_cast<jarray>(o49)));
1198 EXPECT_EQ(50, env->GetArrayLength(reinterpret_cast<jarray>(o50)));
1199 EXPECT_EQ(51, env->GetArrayLength(reinterpret_cast<jarray>(o51)));
1200 EXPECT_EQ(52, env->GetArrayLength(reinterpret_cast<jarray>(o52)));
1201 EXPECT_EQ(53, env->GetArrayLength(reinterpret_cast<jarray>(o53)));
1202 EXPECT_EQ(54, env->GetArrayLength(reinterpret_cast<jarray>(o54)));
1203 EXPECT_EQ(55, env->GetArrayLength(reinterpret_cast<jarray>(o55)));
1204 EXPECT_EQ(56, env->GetArrayLength(reinterpret_cast<jarray>(o56)));
1205 EXPECT_EQ(57, env->GetArrayLength(reinterpret_cast<jarray>(o57)));
1206 EXPECT_EQ(58, env->GetArrayLength(reinterpret_cast<jarray>(o58)));
1207 EXPECT_EQ(59, env->GetArrayLength(reinterpret_cast<jarray>(o59)));
1208 EXPECT_EQ(60, env->GetArrayLength(reinterpret_cast<jarray>(o60)));
1209 EXPECT_EQ(61, env->GetArrayLength(reinterpret_cast<jarray>(o61)));
1210 EXPECT_EQ(62, env->GetArrayLength(reinterpret_cast<jarray>(o62)));
1211 EXPECT_EQ(63, env->GetArrayLength(reinterpret_cast<jarray>(o63)));
1212 EXPECT_EQ(64, env->GetArrayLength(reinterpret_cast<jarray>(o64)));
1213 EXPECT_EQ(65, env->GetArrayLength(reinterpret_cast<jarray>(o65)));
1214 EXPECT_EQ(66, env->GetArrayLength(reinterpret_cast<jarray>(o66)));
1215 EXPECT_EQ(67, env->GetArrayLength(reinterpret_cast<jarray>(o67)));
1216 EXPECT_EQ(68, env->GetArrayLength(reinterpret_cast<jarray>(o68)));
1217 EXPECT_EQ(69, env->GetArrayLength(reinterpret_cast<jarray>(o69)));
1218 EXPECT_EQ(70, env->GetArrayLength(reinterpret_cast<jarray>(o70)));
1219 EXPECT_EQ(71, env->GetArrayLength(reinterpret_cast<jarray>(o71)));
1220 EXPECT_EQ(72, env->GetArrayLength(reinterpret_cast<jarray>(o72)));
1221 EXPECT_EQ(73, env->GetArrayLength(reinterpret_cast<jarray>(o73)));
1222 EXPECT_EQ(74, env->GetArrayLength(reinterpret_cast<jarray>(o74)));
1223 EXPECT_EQ(75, env->GetArrayLength(reinterpret_cast<jarray>(o75)));
1224 EXPECT_EQ(76, env->GetArrayLength(reinterpret_cast<jarray>(o76)));
1225 EXPECT_EQ(77, env->GetArrayLength(reinterpret_cast<jarray>(o77)));
1226 EXPECT_EQ(78, env->GetArrayLength(reinterpret_cast<jarray>(o78)));
1227 EXPECT_EQ(79, env->GetArrayLength(reinterpret_cast<jarray>(o79)));
1228 EXPECT_EQ(80, env->GetArrayLength(reinterpret_cast<jarray>(o80)));
1229 EXPECT_EQ(81, env->GetArrayLength(reinterpret_cast<jarray>(o81)));
1230 EXPECT_EQ(82, env->GetArrayLength(reinterpret_cast<jarray>(o82)));
1231 EXPECT_EQ(83, env->GetArrayLength(reinterpret_cast<jarray>(o83)));
1232 EXPECT_EQ(84, env->GetArrayLength(reinterpret_cast<jarray>(o84)));
1233 EXPECT_EQ(85, env->GetArrayLength(reinterpret_cast<jarray>(o85)));
1234 EXPECT_EQ(86, env->GetArrayLength(reinterpret_cast<jarray>(o86)));
1235 EXPECT_EQ(87, env->GetArrayLength(reinterpret_cast<jarray>(o87)));
1236 EXPECT_EQ(88, env->GetArrayLength(reinterpret_cast<jarray>(o88)));
1237 EXPECT_EQ(89, env->GetArrayLength(reinterpret_cast<jarray>(o89)));
1238 EXPECT_EQ(90, env->GetArrayLength(reinterpret_cast<jarray>(o90)));
1239 EXPECT_EQ(91, env->GetArrayLength(reinterpret_cast<jarray>(o91)));
1240 EXPECT_EQ(92, env->GetArrayLength(reinterpret_cast<jarray>(o92)));
1241 EXPECT_EQ(93, env->GetArrayLength(reinterpret_cast<jarray>(o93)));
1242 EXPECT_EQ(94, env->GetArrayLength(reinterpret_cast<jarray>(o94)));
1243 EXPECT_EQ(95, env->GetArrayLength(reinterpret_cast<jarray>(o95)));
1244 EXPECT_EQ(96, env->GetArrayLength(reinterpret_cast<jarray>(o96)));
1245 EXPECT_EQ(97, env->GetArrayLength(reinterpret_cast<jarray>(o97)));
1246 EXPECT_EQ(98, env->GetArrayLength(reinterpret_cast<jarray>(o98)));
1247 EXPECT_EQ(99, env->GetArrayLength(reinterpret_cast<jarray>(o99)));
1248 EXPECT_EQ(100, env->GetArrayLength(reinterpret_cast<jarray>(o100)));
1249 EXPECT_EQ(101, env->GetArrayLength(reinterpret_cast<jarray>(o101)));
1250 EXPECT_EQ(102, env->GetArrayLength(reinterpret_cast<jarray>(o102)));
1251 EXPECT_EQ(103, env->GetArrayLength(reinterpret_cast<jarray>(o103)));
1252 EXPECT_EQ(104, env->GetArrayLength(reinterpret_cast<jarray>(o104)));
1253 EXPECT_EQ(105, env->GetArrayLength(reinterpret_cast<jarray>(o105)));
1254 EXPECT_EQ(106, env->GetArrayLength(reinterpret_cast<jarray>(o106)));
1255 EXPECT_EQ(107, env->GetArrayLength(reinterpret_cast<jarray>(o107)));
1256 EXPECT_EQ(108, env->GetArrayLength(reinterpret_cast<jarray>(o108)));
1257 EXPECT_EQ(109, env->GetArrayLength(reinterpret_cast<jarray>(o109)));
1258 EXPECT_EQ(110, env->GetArrayLength(reinterpret_cast<jarray>(o110)));
1259 EXPECT_EQ(111, env->GetArrayLength(reinterpret_cast<jarray>(o111)));
1260 EXPECT_EQ(112, env->GetArrayLength(reinterpret_cast<jarray>(o112)));
1261 EXPECT_EQ(113, env->GetArrayLength(reinterpret_cast<jarray>(o113)));
1262 EXPECT_EQ(114, env->GetArrayLength(reinterpret_cast<jarray>(o114)));
1263 EXPECT_EQ(115, env->GetArrayLength(reinterpret_cast<jarray>(o115)));
1264 EXPECT_EQ(116, env->GetArrayLength(reinterpret_cast<jarray>(o116)));
1265 EXPECT_EQ(117, env->GetArrayLength(reinterpret_cast<jarray>(o117)));
1266 EXPECT_EQ(118, env->GetArrayLength(reinterpret_cast<jarray>(o118)));
1267 EXPECT_EQ(119, env->GetArrayLength(reinterpret_cast<jarray>(o119)));
1268 EXPECT_EQ(120, env->GetArrayLength(reinterpret_cast<jarray>(o120)));
1269 EXPECT_EQ(121, env->GetArrayLength(reinterpret_cast<jarray>(o121)));
1270 EXPECT_EQ(122, env->GetArrayLength(reinterpret_cast<jarray>(o122)));
1271 EXPECT_EQ(123, env->GetArrayLength(reinterpret_cast<jarray>(o123)));
1272 EXPECT_EQ(124, env->GetArrayLength(reinterpret_cast<jarray>(o124)));
1273 EXPECT_EQ(125, env->GetArrayLength(reinterpret_cast<jarray>(o125)));
1274 EXPECT_EQ(126, env->GetArrayLength(reinterpret_cast<jarray>(o126)));
1275 EXPECT_EQ(127, env->GetArrayLength(reinterpret_cast<jarray>(o127)));
1276 EXPECT_EQ(128, env->GetArrayLength(reinterpret_cast<jarray>(o128)));
1277 EXPECT_EQ(129, env->GetArrayLength(reinterpret_cast<jarray>(o129)));
1278 EXPECT_EQ(130, env->GetArrayLength(reinterpret_cast<jarray>(o130)));
1279 EXPECT_EQ(131, env->GetArrayLength(reinterpret_cast<jarray>(o131)));
1280 EXPECT_EQ(132, env->GetArrayLength(reinterpret_cast<jarray>(o132)));
1281 EXPECT_EQ(133, env->GetArrayLength(reinterpret_cast<jarray>(o133)));
1282 EXPECT_EQ(134, env->GetArrayLength(reinterpret_cast<jarray>(o134)));
1283 EXPECT_EQ(135, env->GetArrayLength(reinterpret_cast<jarray>(o135)));
1284 EXPECT_EQ(136, env->GetArrayLength(reinterpret_cast<jarray>(o136)));
1285 EXPECT_EQ(137, env->GetArrayLength(reinterpret_cast<jarray>(o137)));
1286 EXPECT_EQ(138, env->GetArrayLength(reinterpret_cast<jarray>(o138)));
1287 EXPECT_EQ(139, env->GetArrayLength(reinterpret_cast<jarray>(o139)));
1288 EXPECT_EQ(140, env->GetArrayLength(reinterpret_cast<jarray>(o140)));
1289 EXPECT_EQ(141, env->GetArrayLength(reinterpret_cast<jarray>(o141)));
1290 EXPECT_EQ(142, env->GetArrayLength(reinterpret_cast<jarray>(o142)));
1291 EXPECT_EQ(143, env->GetArrayLength(reinterpret_cast<jarray>(o143)));
1292 EXPECT_EQ(144, env->GetArrayLength(reinterpret_cast<jarray>(o144)));
1293 EXPECT_EQ(145, env->GetArrayLength(reinterpret_cast<jarray>(o145)));
1294 EXPECT_EQ(146, env->GetArrayLength(reinterpret_cast<jarray>(o146)));
1295 EXPECT_EQ(147, env->GetArrayLength(reinterpret_cast<jarray>(o147)));
1296 EXPECT_EQ(148, env->GetArrayLength(reinterpret_cast<jarray>(o148)));
1297 EXPECT_EQ(149, env->GetArrayLength(reinterpret_cast<jarray>(o149)));
1298 EXPECT_EQ(150, env->GetArrayLength(reinterpret_cast<jarray>(o150)));
1299 EXPECT_EQ(151, env->GetArrayLength(reinterpret_cast<jarray>(o151)));
1300 EXPECT_EQ(152, env->GetArrayLength(reinterpret_cast<jarray>(o152)));
1301 EXPECT_EQ(153, env->GetArrayLength(reinterpret_cast<jarray>(o153)));
1302 EXPECT_EQ(154, env->GetArrayLength(reinterpret_cast<jarray>(o154)));
1303 EXPECT_EQ(155, env->GetArrayLength(reinterpret_cast<jarray>(o155)));
1304 EXPECT_EQ(156, env->GetArrayLength(reinterpret_cast<jarray>(o156)));
1305 EXPECT_EQ(157, env->GetArrayLength(reinterpret_cast<jarray>(o157)));
1306 EXPECT_EQ(158, env->GetArrayLength(reinterpret_cast<jarray>(o158)));
1307 EXPECT_EQ(159, env->GetArrayLength(reinterpret_cast<jarray>(o159)));
1308 EXPECT_EQ(160, env->GetArrayLength(reinterpret_cast<jarray>(o160)));
1309 EXPECT_EQ(161, env->GetArrayLength(reinterpret_cast<jarray>(o161)));
1310 EXPECT_EQ(162, env->GetArrayLength(reinterpret_cast<jarray>(o162)));
1311 EXPECT_EQ(163, env->GetArrayLength(reinterpret_cast<jarray>(o163)));
1312 EXPECT_EQ(164, env->GetArrayLength(reinterpret_cast<jarray>(o164)));
1313 EXPECT_EQ(165, env->GetArrayLength(reinterpret_cast<jarray>(o165)));
1314 EXPECT_EQ(166, env->GetArrayLength(reinterpret_cast<jarray>(o166)));
1315 EXPECT_EQ(167, env->GetArrayLength(reinterpret_cast<jarray>(o167)));
1316 EXPECT_EQ(168, env->GetArrayLength(reinterpret_cast<jarray>(o168)));
1317 EXPECT_EQ(169, env->GetArrayLength(reinterpret_cast<jarray>(o169)));
1318 EXPECT_EQ(170, env->GetArrayLength(reinterpret_cast<jarray>(o170)));
1319 EXPECT_EQ(171, env->GetArrayLength(reinterpret_cast<jarray>(o171)));
1320 EXPECT_EQ(172, env->GetArrayLength(reinterpret_cast<jarray>(o172)));
1321 EXPECT_EQ(173, env->GetArrayLength(reinterpret_cast<jarray>(o173)));
1322 EXPECT_EQ(174, env->GetArrayLength(reinterpret_cast<jarray>(o174)));
1323 EXPECT_EQ(175, env->GetArrayLength(reinterpret_cast<jarray>(o175)));
1324 EXPECT_EQ(176, env->GetArrayLength(reinterpret_cast<jarray>(o176)));
1325 EXPECT_EQ(177, env->GetArrayLength(reinterpret_cast<jarray>(o177)));
1326 EXPECT_EQ(178, env->GetArrayLength(reinterpret_cast<jarray>(o178)));
1327 EXPECT_EQ(179, env->GetArrayLength(reinterpret_cast<jarray>(o179)));
1328 EXPECT_EQ(180, env->GetArrayLength(reinterpret_cast<jarray>(o180)));
1329 EXPECT_EQ(181, env->GetArrayLength(reinterpret_cast<jarray>(o181)));
1330 EXPECT_EQ(182, env->GetArrayLength(reinterpret_cast<jarray>(o182)));
1331 EXPECT_EQ(183, env->GetArrayLength(reinterpret_cast<jarray>(o183)));
1332 EXPECT_EQ(184, env->GetArrayLength(reinterpret_cast<jarray>(o184)));
1333 EXPECT_EQ(185, env->GetArrayLength(reinterpret_cast<jarray>(o185)));
1334 EXPECT_EQ(186, env->GetArrayLength(reinterpret_cast<jarray>(o186)));
1335 EXPECT_EQ(187, env->GetArrayLength(reinterpret_cast<jarray>(o187)));
1336 EXPECT_EQ(188, env->GetArrayLength(reinterpret_cast<jarray>(o188)));
1337 EXPECT_EQ(189, env->GetArrayLength(reinterpret_cast<jarray>(o189)));
1338 EXPECT_EQ(190, env->GetArrayLength(reinterpret_cast<jarray>(o190)));
1339 EXPECT_EQ(191, env->GetArrayLength(reinterpret_cast<jarray>(o191)));
1340 EXPECT_EQ(192, env->GetArrayLength(reinterpret_cast<jarray>(o192)));
1341 EXPECT_EQ(193, env->GetArrayLength(reinterpret_cast<jarray>(o193)));
1342 EXPECT_EQ(194, env->GetArrayLength(reinterpret_cast<jarray>(o194)));
1343 EXPECT_EQ(195, env->GetArrayLength(reinterpret_cast<jarray>(o195)));
1344 EXPECT_EQ(196, env->GetArrayLength(reinterpret_cast<jarray>(o196)));
1345 EXPECT_EQ(197, env->GetArrayLength(reinterpret_cast<jarray>(o197)));
1346 EXPECT_EQ(198, env->GetArrayLength(reinterpret_cast<jarray>(o198)));
1347 EXPECT_EQ(199, env->GetArrayLength(reinterpret_cast<jarray>(o199)));
1348 EXPECT_EQ(200, env->GetArrayLength(reinterpret_cast<jarray>(o200)));
1349 EXPECT_EQ(201, env->GetArrayLength(reinterpret_cast<jarray>(o201)));
1350 EXPECT_EQ(202, env->GetArrayLength(reinterpret_cast<jarray>(o202)));
1351 EXPECT_EQ(203, env->GetArrayLength(reinterpret_cast<jarray>(o203)));
1352 EXPECT_EQ(204, env->GetArrayLength(reinterpret_cast<jarray>(o204)));
1353 EXPECT_EQ(205, env->GetArrayLength(reinterpret_cast<jarray>(o205)));
1354 EXPECT_EQ(206, env->GetArrayLength(reinterpret_cast<jarray>(o206)));
1355 EXPECT_EQ(207, env->GetArrayLength(reinterpret_cast<jarray>(o207)));
1356 EXPECT_EQ(208, env->GetArrayLength(reinterpret_cast<jarray>(o208)));
1357 EXPECT_EQ(209, env->GetArrayLength(reinterpret_cast<jarray>(o209)));
1358 EXPECT_EQ(210, env->GetArrayLength(reinterpret_cast<jarray>(o210)));
1359 EXPECT_EQ(211, env->GetArrayLength(reinterpret_cast<jarray>(o211)));
1360 EXPECT_EQ(212, env->GetArrayLength(reinterpret_cast<jarray>(o212)));
1361 EXPECT_EQ(213, env->GetArrayLength(reinterpret_cast<jarray>(o213)));
1362 EXPECT_EQ(214, env->GetArrayLength(reinterpret_cast<jarray>(o214)));
1363 EXPECT_EQ(215, env->GetArrayLength(reinterpret_cast<jarray>(o215)));
1364 EXPECT_EQ(216, env->GetArrayLength(reinterpret_cast<jarray>(o216)));
1365 EXPECT_EQ(217, env->GetArrayLength(reinterpret_cast<jarray>(o217)));
1366 EXPECT_EQ(218, env->GetArrayLength(reinterpret_cast<jarray>(o218)));
1367 EXPECT_EQ(219, env->GetArrayLength(reinterpret_cast<jarray>(o219)));
1368 EXPECT_EQ(220, env->GetArrayLength(reinterpret_cast<jarray>(o220)));
1369 EXPECT_EQ(221, env->GetArrayLength(reinterpret_cast<jarray>(o221)));
1370 EXPECT_EQ(222, env->GetArrayLength(reinterpret_cast<jarray>(o222)));
1371 EXPECT_EQ(223, env->GetArrayLength(reinterpret_cast<jarray>(o223)));
1372 EXPECT_EQ(224, env->GetArrayLength(reinterpret_cast<jarray>(o224)));
1373 EXPECT_EQ(225, env->GetArrayLength(reinterpret_cast<jarray>(o225)));
1374 EXPECT_EQ(226, env->GetArrayLength(reinterpret_cast<jarray>(o226)));
1375 EXPECT_EQ(227, env->GetArrayLength(reinterpret_cast<jarray>(o227)));
1376 EXPECT_EQ(228, env->GetArrayLength(reinterpret_cast<jarray>(o228)));
1377 EXPECT_EQ(229, env->GetArrayLength(reinterpret_cast<jarray>(o229)));
1378 EXPECT_EQ(230, env->GetArrayLength(reinterpret_cast<jarray>(o230)));
1379 EXPECT_EQ(231, env->GetArrayLength(reinterpret_cast<jarray>(o231)));
1380 EXPECT_EQ(232, env->GetArrayLength(reinterpret_cast<jarray>(o232)));
1381 EXPECT_EQ(233, env->GetArrayLength(reinterpret_cast<jarray>(o233)));
1382 EXPECT_EQ(234, env->GetArrayLength(reinterpret_cast<jarray>(o234)));
1383 EXPECT_EQ(235, env->GetArrayLength(reinterpret_cast<jarray>(o235)));
1384 EXPECT_EQ(236, env->GetArrayLength(reinterpret_cast<jarray>(o236)));
1385 EXPECT_EQ(237, env->GetArrayLength(reinterpret_cast<jarray>(o237)));
1386 EXPECT_EQ(238, env->GetArrayLength(reinterpret_cast<jarray>(o238)));
1387 EXPECT_EQ(239, env->GetArrayLength(reinterpret_cast<jarray>(o239)));
1388 EXPECT_EQ(240, env->GetArrayLength(reinterpret_cast<jarray>(o240)));
1389 EXPECT_EQ(241, env->GetArrayLength(reinterpret_cast<jarray>(o241)));
1390 EXPECT_EQ(242, env->GetArrayLength(reinterpret_cast<jarray>(o242)));
1391 EXPECT_EQ(243, env->GetArrayLength(reinterpret_cast<jarray>(o243)));
1392 EXPECT_EQ(244, env->GetArrayLength(reinterpret_cast<jarray>(o244)));
1393 EXPECT_EQ(245, env->GetArrayLength(reinterpret_cast<jarray>(o245)));
1394 EXPECT_EQ(246, env->GetArrayLength(reinterpret_cast<jarray>(o246)));
1395 EXPECT_EQ(247, env->GetArrayLength(reinterpret_cast<jarray>(o247)));
1396 EXPECT_EQ(248, env->GetArrayLength(reinterpret_cast<jarray>(o248)));
1397 EXPECT_EQ(249, env->GetArrayLength(reinterpret_cast<jarray>(o249)));
1398 EXPECT_EQ(250, env->GetArrayLength(reinterpret_cast<jarray>(o250)));
1399 EXPECT_EQ(251, env->GetArrayLength(reinterpret_cast<jarray>(o251)));
1400 EXPECT_EQ(252, env->GetArrayLength(reinterpret_cast<jarray>(o252)));
1401 EXPECT_EQ(253, env->GetArrayLength(reinterpret_cast<jarray>(o253)));
1402 }
1403}
1404
1405const char* longSig =
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;Ljava/lang/Object;"
1456 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V";
1457
Andreas Gampe6e498692014-08-18 16:43:12 -07001458void JniCompilerTest::MaxParamNumberImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001459 SetUpForTest(false, "maxParamNumber", longSig,
1460 reinterpret_cast<void*>(&Java_MyClassNatives_maxParamNumber));
1461
1462 jvalue args[254];
1463
1464 // First test: test with all arguments null.
1465 for (int i = 0; i < 254; ++i) {
1466 args[i].l = nullptr;
1467 }
1468
1469 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args);
1470
1471 // Second test: test with int[] objects with increasing lengths
1472 for (int i = 0; i < 254; ++i) {
1473 jintArray tmp = env_->NewIntArray(i);
1474 args[i].l = tmp;
1475 EXPECT_NE(args[i].l, nullptr);
1476 }
1477
1478 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args);
1479}
1480
Andreas Gampe6e498692014-08-18 16:43:12 -07001481JNI_TEST(MaxParamNumber)
1482
1483void JniCompilerTest::WithoutImplementationImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -08001484 // This will lead to error messages in the log.
1485 ScopedLogSeverity sls(LogSeverity::FATAL);
1486
Andreas Gampead615172014-04-04 16:20:13 -07001487 SetUpForTest(false, "withoutImplementation", "()V", nullptr);
1488
1489 env_->CallVoidMethod(jobj_, jmethod_);
1490
1491 EXPECT_TRUE(Thread::Current()->IsExceptionPending());
1492 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE);
1493}
1494
Andreas Gampe6e498692014-08-18 16:43:12 -07001495JNI_TEST(WithoutImplementation)
1496
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001497void Java_MyClassNatives_stackArgsIntsFirst(JNIEnv*, jclass, jint i1, jint i2, jint i3,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001498 jint i4, jint i5, jint i6, jint i7, jint i8, jint i9,
1499 jint i10, jfloat f1, jfloat f2, jfloat f3, jfloat f4,
1500 jfloat f5, jfloat f6, jfloat f7, jfloat f8, jfloat f9,
1501 jfloat f10) {
1502 EXPECT_EQ(i1, 1);
1503 EXPECT_EQ(i2, 2);
1504 EXPECT_EQ(i3, 3);
1505 EXPECT_EQ(i4, 4);
1506 EXPECT_EQ(i5, 5);
1507 EXPECT_EQ(i6, 6);
1508 EXPECT_EQ(i7, 7);
1509 EXPECT_EQ(i8, 8);
1510 EXPECT_EQ(i9, 9);
1511 EXPECT_EQ(i10, 10);
1512
Roland Levillainda4d79b2015-03-24 14:36:11 +00001513 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001514 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001515 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001516 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001517 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001518 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001519 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001520 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001521 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001522 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001523 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001524 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001525 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001526 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001527 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001528 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001529 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001530 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001531 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001532 EXPECT_EQ(i20, 20);
1533}
1534
Andreas Gampe6e498692014-08-18 16:43:12 -07001535void JniCompilerTest::StackArgsIntsFirstImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001536 SetUpForTest(true, "stackArgsIntsFirst", "(IIIIIIIIIIFFFFFFFFFF)V",
1537 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsIntsFirst));
1538
1539 jint i1 = 1;
1540 jint i2 = 2;
1541 jint i3 = 3;
1542 jint i4 = 4;
1543 jint i5 = 5;
1544 jint i6 = 6;
1545 jint i7 = 7;
1546 jint i8 = 8;
1547 jint i9 = 9;
1548 jint i10 = 10;
1549
Roland Levillainda4d79b2015-03-24 14:36:11 +00001550 jfloat f1 = bit_cast<jfloat, jint>(11);
1551 jfloat f2 = bit_cast<jfloat, jint>(12);
1552 jfloat f3 = bit_cast<jfloat, jint>(13);
1553 jfloat f4 = bit_cast<jfloat, jint>(14);
1554 jfloat f5 = bit_cast<jfloat, jint>(15);
1555 jfloat f6 = bit_cast<jfloat, jint>(16);
1556 jfloat f7 = bit_cast<jfloat, jint>(17);
1557 jfloat f8 = bit_cast<jfloat, jint>(18);
1558 jfloat f9 = bit_cast<jfloat, jint>(19);
1559 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001560
1561 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, f1, f2,
1562 f3, f4, f5, f6, f7, f8, f9, f10);
1563}
1564
Andreas Gampe6e498692014-08-18 16:43:12 -07001565JNI_TEST(StackArgsIntsFirst)
1566
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001567void Java_MyClassNatives_stackArgsFloatsFirst(JNIEnv*, jclass, jfloat f1, jfloat f2,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001568 jfloat f3, jfloat f4, jfloat f5, jfloat f6, jfloat f7,
1569 jfloat f8, jfloat f9, jfloat f10, jint i1, jint i2,
1570 jint i3, jint i4, jint i5, jint i6, jint i7, jint i8,
1571 jint i9, jint i10) {
1572 EXPECT_EQ(i1, 1);
1573 EXPECT_EQ(i2, 2);
1574 EXPECT_EQ(i3, 3);
1575 EXPECT_EQ(i4, 4);
1576 EXPECT_EQ(i5, 5);
1577 EXPECT_EQ(i6, 6);
1578 EXPECT_EQ(i7, 7);
1579 EXPECT_EQ(i8, 8);
1580 EXPECT_EQ(i9, 9);
1581 EXPECT_EQ(i10, 10);
1582
Roland Levillainda4d79b2015-03-24 14:36:11 +00001583 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001584 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001585 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001586 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001587 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001588 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001589 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001590 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001591 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001592 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001593 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001594 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001595 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001596 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001597 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001598 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001599 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001600 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001601 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001602 EXPECT_EQ(i20, 20);
1603}
1604
Andreas Gampe6e498692014-08-18 16:43:12 -07001605void JniCompilerTest::StackArgsFloatsFirstImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001606 SetUpForTest(true, "stackArgsFloatsFirst", "(FFFFFFFFFFIIIIIIIIII)V",
1607 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsFloatsFirst));
1608
1609 jint i1 = 1;
1610 jint i2 = 2;
1611 jint i3 = 3;
1612 jint i4 = 4;
1613 jint i5 = 5;
1614 jint i6 = 6;
1615 jint i7 = 7;
1616 jint i8 = 8;
1617 jint i9 = 9;
1618 jint i10 = 10;
1619
Roland Levillainda4d79b2015-03-24 14:36:11 +00001620 jfloat f1 = bit_cast<jfloat, jint>(11);
1621 jfloat f2 = bit_cast<jfloat, jint>(12);
1622 jfloat f3 = bit_cast<jfloat, jint>(13);
1623 jfloat f4 = bit_cast<jfloat, jint>(14);
1624 jfloat f5 = bit_cast<jfloat, jint>(15);
1625 jfloat f6 = bit_cast<jfloat, jint>(16);
1626 jfloat f7 = bit_cast<jfloat, jint>(17);
1627 jfloat f8 = bit_cast<jfloat, jint>(18);
1628 jfloat f9 = bit_cast<jfloat, jint>(19);
1629 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001630
1631 env_->CallStaticVoidMethod(jklass_, jmethod_, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, i1, i2, i3,
1632 i4, i5, i6, i7, i8, i9, i10);
1633}
1634
Andreas Gampe6e498692014-08-18 16:43:12 -07001635JNI_TEST(StackArgsFloatsFirst)
1636
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001637void Java_MyClassNatives_stackArgsMixed(JNIEnv*, jclass, jint i1, jfloat f1, jint i2,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001638 jfloat f2, jint i3, jfloat f3, jint i4, jfloat f4, jint i5,
1639 jfloat f5, jint i6, jfloat f6, jint i7, jfloat f7, jint i8,
1640 jfloat f8, jint i9, jfloat f9, jint i10, jfloat f10) {
1641 EXPECT_EQ(i1, 1);
1642 EXPECT_EQ(i2, 2);
1643 EXPECT_EQ(i3, 3);
1644 EXPECT_EQ(i4, 4);
1645 EXPECT_EQ(i5, 5);
1646 EXPECT_EQ(i6, 6);
1647 EXPECT_EQ(i7, 7);
1648 EXPECT_EQ(i8, 8);
1649 EXPECT_EQ(i9, 9);
1650 EXPECT_EQ(i10, 10);
1651
Roland Levillainda4d79b2015-03-24 14:36:11 +00001652 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001653 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001654 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001655 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001656 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001657 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001658 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001659 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001660 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001661 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001662 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001663 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001664 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001665 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001666 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001667 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001668 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001669 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001670 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001671 EXPECT_EQ(i20, 20);
1672}
1673
Andreas Gampe6e498692014-08-18 16:43:12 -07001674void JniCompilerTest::StackArgsMixedImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001675 SetUpForTest(true, "stackArgsMixed", "(IFIFIFIFIFIFIFIFIFIF)V",
1676 reinterpret_cast<void*>(&Java_MyClassNatives_stackArgsMixed));
1677
1678 jint i1 = 1;
1679 jint i2 = 2;
1680 jint i3 = 3;
1681 jint i4 = 4;
1682 jint i5 = 5;
1683 jint i6 = 6;
1684 jint i7 = 7;
1685 jint i8 = 8;
1686 jint i9 = 9;
1687 jint i10 = 10;
1688
Roland Levillainda4d79b2015-03-24 14:36:11 +00001689 jfloat f1 = bit_cast<jfloat, jint>(11);
1690 jfloat f2 = bit_cast<jfloat, jint>(12);
1691 jfloat f3 = bit_cast<jfloat, jint>(13);
1692 jfloat f4 = bit_cast<jfloat, jint>(14);
1693 jfloat f5 = bit_cast<jfloat, jint>(15);
1694 jfloat f6 = bit_cast<jfloat, jint>(16);
1695 jfloat f7 = bit_cast<jfloat, jint>(17);
1696 jfloat f8 = bit_cast<jfloat, jint>(18);
1697 jfloat f9 = bit_cast<jfloat, jint>(19);
1698 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001699
1700 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7,
1701 f7, i8, f8, i9, f9, i10, f10);
1702}
1703
Andreas Gampe6e498692014-08-18 16:43:12 -07001704JNI_TEST(StackArgsMixed)
1705
Ian Rogersb033c752011-07-20 12:22:35 -07001706} // namespace art