blob: afb8fce8d77172cc19897fd6ab0530b186bf725f [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>
Igor Murashkin367f3dd2016-09-01 17:00:24 -070018#include <type_traits>
Ian Rogers700a4022014-05-19 16:49:03 -070019
Nicolas Geoffray54accbc2014-08-13 03:40:45 +010020#include <math.h>
21
Mathieu Chartiere401d142015-04-22 13:56:20 -070022#include "art_method-inl.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070023#include "class_linker.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080024#include "common_compiler_test.h"
Igor Murashkin367f3dd2016-09-01 17:00:24 -070025#include "compiler.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070026#include "dex_file.h"
Elliott Hughes90a33692011-08-30 13:27:07 -070027#include "gtest/gtest.h"
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070028#include "indirect_reference_table.h"
Ian Rogerscdd1d2d2011-08-18 09:58:17 -070029#include "jni_internal.h"
Brian Carlstromdb4d5402011-08-09 12:18:28 -070030#include "mem_map.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070031#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "mirror/class_loader.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "mirror/object_array-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070034#include "mirror/object-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "mirror/stack_trace_element.h"
Dimitry Ivanov5edb0632016-04-29 11:14:25 -070036#include "nativeloader/native_loader.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070037#include "runtime.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070038#include "ScopedLocalRef.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070039#include "scoped_thread_state_change-inl.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070040#include "thread.h"
Ian Rogersb033c752011-07-20 12:22:35 -070041
Elliott Hughesb264f082012-04-06 17:10:10 -070042extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_bar(JNIEnv*, jobject, jint count) {
Brian Carlstromb9cc1ca2012-01-27 00:57:42 -080043 return count + 1;
44}
45
Elliott Hughesb264f082012-04-06 17:10:10 -070046extern "C" JNIEXPORT jint JNICALL Java_MyClassNatives_sbar(JNIEnv*, jclass, jint count) {
Ian Rogers1cefdbd2012-02-29 09:34:50 -080047 return count + 1;
48}
49
Ian Rogersb033c752011-07-20 12:22:35 -070050namespace art {
51
Igor Murashkin367f3dd2016-09-01 17:00:24 -070052enum class JniKind {
53 kNormal = Compiler::kNone, // Regular kind of un-annotated natives.
54 kFast = Compiler::kFastNative, // Native method annotated with @FastNative.
55 kCritical = Compiler::kCriticalNative, // Native method annotated with @CriticalNative.
56 kCount = Compiler::kCriticalNative + 1 // How many different types of JNIs we can have.
57};
58
59// Used to initialize array sizes that want to have different state per current jni.
60static constexpr size_t kJniKindCount = static_cast<size_t>(JniKind::kCount);
61// Do not use directly, use the helpers instead.
62uint32_t gCurrentJni = static_cast<uint32_t>(JniKind::kNormal);
63
64// Is the current native method under test @CriticalNative?
65static bool IsCurrentJniCritical() {
66 return gCurrentJni == static_cast<uint32_t>(JniKind::kCritical);
67}
68
69// Is the current native method a plain-old non-annotated native?
70static bool IsCurrentJniNormal() {
71 return gCurrentJni == static_cast<uint32_t>(JniKind::kNormal);
72}
73
74// Signifify that a different kind of JNI is about to be tested.
75static void UpdateCurrentJni(JniKind kind) {
76 gCurrentJni = static_cast<uint32_t>(kind);
77}
78
79// (Match the name suffixes of native methods in MyClassNatives.java)
80static std::string CurrentJniStringSuffix() {
81 switch (gCurrentJni) {
82 case static_cast<uint32_t>(JniKind::kNormal): {
83 return "";
84 }
85 case static_cast<uint32_t>(JniKind::kFast): {
86 return "_Fast";
87 }
88 case static_cast<uint32_t>(JniKind::kCritical): {
89 return "_Critical";
90 }
91 default:
92 LOG(FATAL) << "Invalid current JNI value: " << gCurrentJni;
93 UNREACHABLE();
94 }
95}
96
97// Dummy values passed to our JNI handlers when we enter @CriticalNative.
98// Normally @CriticalNative calling convention strips out the "JNIEnv*, jclass" parameters.
99// However to avoid duplicating every single test method we have a templated handler
100// that inserts dummy parameters (0,1) to make it compatible with a regular JNI handler.
101static JNIEnv* const kCriticalDummyJniEnv = reinterpret_cast<JNIEnv*>(0xDEADFEAD);
102static jclass const kCriticalDummyJniClass = reinterpret_cast<jclass>(0xBEAFBEEF);
103
104// Type trait. Returns true if "T" is the same type as one of the types in Args...
105//
106// Logically equal to OR(std::same_type<T, U> for all U in Args).
107template <typename T, typename ... Args>
108struct is_any_of;
109
110template <typename T, typename U, typename ... Args>
111struct is_any_of<T, U, Args ...> {
112 using value_type = bool;
113 static constexpr const bool value = std::is_same<T, U>::value || is_any_of<T, Args ...>::value;
114};
115
116template <typename T, typename U>
117struct is_any_of<T, U> {
118 using value_type = bool;
119 static constexpr const bool value = std::is_same<T, U>::value;
120};
121
122// Type traits for JNI types.
123template <typename T>
124struct jni_type_traits {
125 // True if type T ends up holding an object reference. False otherwise.
126 // (Non-JNI types will also be false).
127 static constexpr const bool is_ref =
128 is_any_of<T, jclass, jobject, jstring, jobjectArray, jintArray,
129 jcharArray, jfloatArray, jshortArray, jdoubleArray, jlongArray>::value;
130};
131
132template <typename ... Args>
133struct count_refs_helper {
134 using value_type = size_t;
135 static constexpr const size_t value = 0;
136};
137
138template <typename Arg, typename ... Args>
139struct count_refs_helper<Arg, Args ...> {
140 using value_type = size_t;
141 static constexpr size_t value =
142 (jni_type_traits<Arg>::is_ref ? 1 : 0) + count_refs_helper<Args ...>::value;
143};
144
145template <typename T, T fn>
146struct count_refs_fn_helper;
147
148template <typename R, typename ... Args, R fn(Args...)>
149struct count_refs_fn_helper<R(Args...), fn> : public count_refs_helper<Args...> {};
150
151// Given a function type 'T' figure out how many of the parameter types are a reference.
152// -- The implicit jclass and thisObject also count as 1 reference.
153//
154// Fields:
155// * value - the result counting # of refs
156// * value_type - the type of value (size_t)
157template <typename T, T fn>
158struct count_refs : public count_refs_fn_helper<T, fn> {};
159
160// Base case: No parameters = 0 refs.
161size_t count_nonnull_refs_helper() {
162 return 0;
163}
164
165// SFINAE for ref types. 1 if non-null, 0 otherwise.
166template <typename T>
167size_t count_nonnull_refs_single_helper(T arg,
168 typename std::enable_if<jni_type_traits<T>::is_ref>::type*
169 = nullptr) {
170 return ((arg == NULL) ? 0 : 1);
171}
172
173// SFINAE for non-ref-types. Always 0.
174template <typename T>
175size_t count_nonnull_refs_single_helper(T arg ATTRIBUTE_UNUSED,
176 typename std::enable_if<!jni_type_traits<T>::is_ref>::type*
177 = nullptr) {
178 return 0;
179}
180
181// Recursive case.
182template <typename T, typename ... Args>
183size_t count_nonnull_refs_helper(T arg, Args ... args) {
184 return count_nonnull_refs_single_helper(arg) + count_nonnull_refs_helper(args...);
185}
186
187// Given any list of parameters, check how many object refs there are and only count
188// them if their runtime value is non-null.
189//
190// For example given (jobject, jint, jclass) we can get (2) if both #0/#2 are non-null,
191// (1) if either #0/#2 are null but not both, and (0) if all parameters are null.
192// Primitive parameters (including JNIEnv*, if present) are ignored.
193template <typename ... Args>
194size_t count_nonnull_refs(Args ... args) {
195 return count_nonnull_refs_helper(args...);
196}
197
198template <typename T, T fn>
199struct remove_extra_parameters_helper;
200
201template <typename R, typename Arg1, typename Arg2, typename ... Args, R fn(Arg1, Arg2, Args...)>
202struct remove_extra_parameters_helper<R(Arg1, Arg2, Args...), fn> {
203 // Note: Do not use Args&& here to maintain C-style parameter types.
204 static R apply(Args... args) {
205 JNIEnv* env = kCriticalDummyJniEnv;
206 jclass kls = kCriticalDummyJniClass;
207 return fn(env, kls, args...);
208 }
209};
210
211// Given a function 'fn' create a function 'apply' which will omit the JNIEnv/jklass parameters
212//
213// i.e. if fn(JNIEnv*,jklass,a,b,c,d,e...) then apply(a,b,c,d,e,...)
214template <typename T, T fn>
215struct jni_remove_extra_parameters : public remove_extra_parameters_helper<T, fn> {};
216
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -0800217class JniCompilerTest : public CommonCompilerTest {
Ian Rogersb033c752011-07-20 12:22:35 -0700218 protected:
Andreas Gampe6e498692014-08-18 16:43:12 -0700219 void SetUp() OVERRIDE {
220 CommonCompilerTest::SetUp();
221 check_generic_jni_ = false;
222 }
223
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700224 void TearDown() OVERRIDE {
225 android::ResetNativeLoader();
226 CommonCompilerTest::TearDown();
227 }
228
Andreas Gampe6e498692014-08-18 16:43:12 -0700229 void SetCheckGenericJni(bool generic) {
230 check_generic_jni_ = generic;
231 }
232
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700233 private:
234 void CompileForTest(jobject class_loader,
235 bool direct,
236 const char* method_name,
237 const char* method_sig) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700238 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700239 StackHandleScope<1> hs(soa.Self());
240 Handle<mirror::ClassLoader> loader(
Mathieu Chartier0795f232016-09-27 18:43:30 -0700241 hs.NewHandle(soa.Decode<mirror::ClassLoader>(class_loader)));
Brian Carlstrom25c33252011-09-18 15:58:35 -0700242 // Compile the native method before starting the runtime
Ian Rogers98379392014-02-24 16:53:16 -0800243 mirror::Class* c = class_linker_->FindClass(soa.Self(), "LMyClassNatives;", loader);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700244 const auto pointer_size = class_linker_->GetImagePointerSize();
245 ArtMethod* method = direct ? c->FindDirectMethod(method_name, method_sig, pointer_size) :
246 c->FindVirtualMethod(method_name, method_sig, pointer_size);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700247 ASSERT_TRUE(method != nullptr) << method_name << " " << method_sig;
Andreas Gampe6e498692014-08-18 16:43:12 -0700248 if (check_generic_jni_) {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700249 method->SetEntryPointFromQuickCompiledCode(class_linker_->GetRuntimeQuickGenericJniStub());
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100250 } else {
Ian Rogers6f3dbba2014-10-14 17:41:57 -0700251 const void* code = method->GetEntryPointFromQuickCompiledCode();
252 if (code == nullptr || class_linker_->IsQuickGenericJniStub(code)) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100253 CompileMethod(method);
254 ASSERT_TRUE(method->GetEntryPointFromQuickCompiledCode() != nullptr)
255 << method_name << " " << method_sig;
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100256 }
Brian Carlstrom25c33252011-09-18 15:58:35 -0700257 }
Brian Carlstrom25c33252011-09-18 15:58:35 -0700258 }
259
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700260 protected:
261 void CompileForTestWithCurrentJni(jobject class_loader,
262 bool direct,
263 const char* method_name_orig,
264 const char* method_sig) {
265 // Append the JNI kind to the method name, so that we automatically get the
266 // fast or critical versions of the same method.
267 std::string method_name_str = std::string(method_name_orig) + CurrentJniStringSuffix();
268 const char* method_name = method_name_str.c_str();
269
270 CompileForTest(class_loader, direct, method_name, method_sig);
271 }
272
273 void SetUpForTest(bool direct,
274 const char* method_name_orig,
275 const char* method_sig,
Andreas Gampe6e498692014-08-18 16:43:12 -0700276 void* native_fnptr) {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700277 // Append the JNI kind to the method name, so that we automatically get the
278 // fast or critical versions of the same method.
279 std::string method_name_str = std::string(method_name_orig) + CurrentJniStringSuffix();
280 const char* method_name = method_name_str.c_str();
281
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700282 // Initialize class loader and compile method when runtime not started.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700283 if (!runtime_->IsStarted()) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700284 {
285 ScopedObjectAccess soa(Thread::Current());
286 class_loader_ = LoadDex("MyClassNatives");
287 }
Andreas Gampe6e498692014-08-18 16:43:12 -0700288 CompileForTest(class_loader_, direct, method_name, method_sig);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700289 // Start runtime.
290 Thread::Current()->TransitionFromSuspendedToRunnable();
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700291 android::InitializeNativeLoader();
Dimitry Ivanovc544f342016-05-09 16:26:13 -0700292 bool started = runtime_->Start();
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700293 CHECK(started);
Brian Carlstrom25c33252011-09-18 15:58:35 -0700294 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700295 // JNI operations after runtime start.
Brian Carlstrom25c33252011-09-18 15:58:35 -0700296 env_ = Thread::Current()->GetJniEnv();
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700297 library_search_path_ = env_->NewStringUTF("");
Elliott Hughesb264f082012-04-06 17:10:10 -0700298 jklass_ = env_->FindClass("MyClassNatives");
Andreas Gampecf4035a2014-05-28 22:43:01 -0700299 ASSERT_TRUE(jklass_ != nullptr) << method_name << " " << method_sig;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700300
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700301 if (direct) {
302 jmethod_ = env_->GetStaticMethodID(jklass_, method_name, method_sig);
303 } else {
304 jmethod_ = env_->GetMethodID(jklass_, method_name, method_sig);
305 }
Andreas Gampecf4035a2014-05-28 22:43:01 -0700306 ASSERT_TRUE(jmethod_ != nullptr) << method_name << " " << method_sig;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700307
Andreas Gampecf4035a2014-05-28 22:43:01 -0700308 if (native_fnptr != nullptr) {
Elliott Hughesb25c3f62012-03-26 16:35:06 -0700309 JNINativeMethod methods[] = { { method_name, method_sig, native_fnptr } };
Brian Carlstromfc7120c2012-08-27 13:43:25 -0700310 ASSERT_EQ(JNI_OK, env_->RegisterNatives(jklass_, methods, 1))
311 << method_name << " " << method_sig;
Ian Rogersbdb03912011-09-14 00:55:44 -0700312 } else {
313 env_->UnregisterNatives(jklass_);
Shih-wei Liao31384c52011-09-06 15:27:45 -0700314 }
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700315
316 jmethodID constructor = env_->GetMethodID(jklass_, "<init>", "()V");
317 jobj_ = env_->NewObject(jklass_, constructor);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700318 ASSERT_TRUE(jobj_ != nullptr) << method_name << " " << method_sig;
Ian Rogersb033c752011-07-20 12:22:35 -0700319 }
320
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700321 public:
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700322 // Available as statics so our JNI handlers can access these.
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700323 static jclass jklass_;
324 static jobject jobj_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700325 static jobject class_loader_;
326
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700327 protected:
Andreas Gampe6e498692014-08-18 16:43:12 -0700328 // We have to list the methods here so we can share them between default and generic JNI.
329 void CompileAndRunNoArgMethodImpl();
330 void CompileAndRunIntMethodThroughStubImpl();
331 void CompileAndRunStaticIntMethodThroughStubImpl();
332 void CompileAndRunIntMethodImpl();
333 void CompileAndRunIntIntMethodImpl();
334 void CompileAndRunLongLongMethodImpl();
335 void CompileAndRunDoubleDoubleMethodImpl();
336 void CompileAndRun_fooJJ_synchronizedImpl();
337 void CompileAndRunIntObjectObjectMethodImpl();
338 void CompileAndRunStaticIntIntMethodImpl();
339 void CompileAndRunStaticDoubleDoubleMethodImpl();
340 void RunStaticLogDoubleMethodImpl();
341 void RunStaticLogFloatMethodImpl();
342 void RunStaticReturnTrueImpl();
343 void RunStaticReturnFalseImpl();
344 void RunGenericStaticReturnIntImpl();
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700345 void RunGenericStaticReturnDoubleImpl();
346 void RunGenericStaticReturnLongImpl();
Andreas Gampe6e498692014-08-18 16:43:12 -0700347 void CompileAndRunStaticIntObjectObjectMethodImpl();
348 void CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl();
349 void ExceptionHandlingImpl();
350 void NativeStackTraceElementImpl();
351 void ReturnGlobalRefImpl();
352 void LocalReferenceTableClearingTestImpl();
353 void JavaLangSystemArrayCopyImpl();
354 void CompareAndSwapIntImpl();
355 void GetTextImpl();
356 void GetSinkPropertiesNativeImpl();
357 void UpcallReturnTypeChecking_InstanceImpl();
358 void UpcallReturnTypeChecking_StaticImpl();
359 void UpcallArgumentTypeChecking_InstanceImpl();
360 void UpcallArgumentTypeChecking_StaticImpl();
361 void CompileAndRunFloatFloatMethodImpl();
362 void CheckParameterAlignImpl();
363 void MaxParamNumberImpl();
364 void WithoutImplementationImpl();
Andreas Gampe48ee3562015-04-10 19:57:29 -0700365 void WithoutImplementationRefReturnImpl();
Andreas Gampe6e498692014-08-18 16:43:12 -0700366 void StackArgsIntsFirstImpl();
367 void StackArgsFloatsFirstImpl();
368 void StackArgsMixedImpl();
Lazar Trsicf652d602015-06-24 16:30:21 +0200369 void StackArgsSignExtendedMips64Impl();
Andreas Gampe6e498692014-08-18 16:43:12 -0700370
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700371 void NormalNativeImpl();
372 void FastNativeImpl();
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700373 void CriticalNativeImpl();
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700374
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700375 JNIEnv* env_;
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700376 jstring library_search_path_;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700377 jmethodID jmethod_;
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700378
379 private:
Andreas Gampe6e498692014-08-18 16:43:12 -0700380 bool check_generic_jni_;
Ian Rogersb033c752011-07-20 12:22:35 -0700381};
382
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700383jclass JniCompilerTest::jklass_;
384jobject JniCompilerTest::jobj_;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700385jobject JniCompilerTest::class_loader_;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700386
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700387// Test the normal compiler and normal generic JNI only.
388// The following features are unsupported in @FastNative:
389// 1) JNI stubs (lookup via dlsym) when methods aren't explicitly registered
390// 2) Returning objects from the JNI function
391// 3) synchronized keyword
392// -- TODO: We can support (1) if we remove the mutator lock assert during stub lookup.
393# define JNI_TEST_NORMAL_ONLY(TestName) \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700394 TEST_F(JniCompilerTest, TestName ## NormalCompiler) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700395 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700396 SCOPED_TRACE("Normal JNI with compiler"); \
397 gCurrentJni = static_cast<uint32_t>(JniKind::kNormal); \
Andreas Gampe6e498692014-08-18 16:43:12 -0700398 TestName ## Impl(); \
399 } \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700400 TEST_F(JniCompilerTest, TestName ## NormalGeneric) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700401 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700402 SCOPED_TRACE("Normal JNI with generic"); \
403 gCurrentJni = static_cast<uint32_t>(JniKind::kNormal); \
Andreas Gampe6e498692014-08-18 16:43:12 -0700404 SetCheckGenericJni(true); \
405 TestName ## Impl(); \
406 }
Andreas Gampecf4035a2014-05-28 22:43:01 -0700407
Igor Murashkin06a04e02016-09-13 15:57:37 -0700408// Test (normal, @FastNative) x (compiler, generic).
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700409#define JNI_TEST(TestName) \
410 JNI_TEST_NORMAL_ONLY(TestName) \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700411 TEST_F(JniCompilerTest, TestName ## FastCompiler) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700412 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700413 SCOPED_TRACE("@FastNative JNI with compiler"); \
414 gCurrentJni = static_cast<uint32_t>(JniKind::kFast); \
415 TestName ## Impl(); \
416 } \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700417 \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700418 TEST_F(JniCompilerTest, TestName ## FastGeneric) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700419 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700420 SCOPED_TRACE("@FastNative JNI with generic"); \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700421 gCurrentJni = static_cast<uint32_t>(JniKind::kFast); \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700422 SetCheckGenericJni(true); \
423 TestName ## Impl(); \
424 }
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700425
Igor Murashkin06a04e02016-09-13 15:57:37 -0700426// Test (@CriticalNative) x (compiler, generic) only.
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700427#define JNI_TEST_CRITICAL_ONLY(TestName) \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700428 TEST_F(JniCompilerTest, TestName ## CriticalCompiler) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700429 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700430 SCOPED_TRACE("@CriticalNative JNI with compiler"); \
431 gCurrentJni = static_cast<uint32_t>(JniKind::kCritical); \
432 TestName ## Impl(); \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700433 } \
434 TEST_F(JniCompilerTest, TestName ## CriticalGeneric) { \
Igor Murashkina51d8b72016-10-05 14:33:30 -0700435 ScopedCheckHandleScope top_handle_scope_check; \
Igor Murashkin06a04e02016-09-13 15:57:37 -0700436 SCOPED_TRACE("@CriticalNative JNI with generic"); \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700437 gCurrentJni = static_cast<uint32_t>(JniKind::kCritical); \
Igor Murashkin294a9152016-09-28 13:23:19 -0700438 SetCheckGenericJni(true); \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700439 TestName ## Impl(); \
440 }
Igor Murashkin06a04e02016-09-13 15:57:37 -0700441
442// Test everything: (normal, @FastNative, @CriticalNative) x (compiler, generic).
443#define JNI_TEST_CRITICAL(TestName) \
444 JNI_TEST(TestName) \
445 JNI_TEST_CRITICAL_ONLY(TestName) \
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700446
447static void expectValidThreadState() {
448 // Normal JNI always transitions to "Native". Other JNIs stay in the "Runnable" state.
449 if (IsCurrentJniNormal()) {
450 EXPECT_EQ(kNative, Thread::Current()->GetState());
451 } else {
452 EXPECT_EQ(kRunnable, Thread::Current()->GetState());
453 }
454}
455
456#define EXPECT_THREAD_STATE_FOR_CURRENT_JNI() expectValidThreadState()
457
458static void expectValidMutatorLockHeld() {
459 if (IsCurrentJniNormal()) {
460 Locks::mutator_lock_->AssertNotHeld(Thread::Current());
461 } else {
462 Locks::mutator_lock_->AssertSharedHeld(Thread::Current());
463 }
464}
465
466#define EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI() expectValidMutatorLockHeld()
467
468static void expectValidJniEnvAndObject(JNIEnv* env, jobject thisObj) {
469 if (!IsCurrentJniCritical()) {
470 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
471 ASSERT_TRUE(thisObj != nullptr);
472 EXPECT_TRUE(env->IsInstanceOf(thisObj, JniCompilerTest::jklass_));
473 } else {
474 LOG(FATAL) << "Objects are not supported for @CriticalNative, why is this being tested?";
475 UNREACHABLE();
476 }
477}
478
479// Validates the JNIEnv to be the same as the current thread's JNIEnv, and makes sure
480// that the object here is an instance of the class we registered the method with.
481//
482// Hard-fails if this somehow gets invoked for @CriticalNative since objects are unsupported.
483#define EXPECT_JNI_ENV_AND_OBJECT_FOR_CURRENT_JNI(env, thisObj) \
484 expectValidJniEnvAndObject(env, thisObj)
485
486static void expectValidJniEnvAndClass(JNIEnv* env, jclass kls) {
487 if (!IsCurrentJniCritical()) {
488 EXPECT_EQ(Thread::Current()->GetJniEnv(), env);
489 ASSERT_TRUE(kls != nullptr);
490 EXPECT_TRUE(env->IsSameObject(static_cast<jobject>(JniCompilerTest::jklass_),
491 static_cast<jobject>(kls)));
492 } else {
493 // This is pretty much vacuously true but catch any testing setup mistakes.
494 EXPECT_EQ(env, kCriticalDummyJniEnv);
495 EXPECT_EQ(kls, kCriticalDummyJniClass);
496 }
497}
498
499// Validates the JNIEnv is the same as the current thread's JNIenv, and makes sure
500// that the jclass we got in the JNI handler is the same one as the class the method was looked
501// up for.
502//
503// (Checks are skipped for @CriticalNative since the two values are dummy).
504#define EXPECT_JNI_ENV_AND_CLASS_FOR_CURRENT_JNI(env, kls) expectValidJniEnvAndClass(env, kls)
505
506// Temporarily disable the EXPECT_NUM_STACK_REFERENCES check (for a single test).
507struct ScopedDisableCheckNumStackReferences {
508 ScopedDisableCheckNumStackReferences() {
Igor Murashkin06a04e02016-09-13 15:57:37 -0700509 CHECK(sCheckNumStackReferences); // No nested support.
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700510 sCheckNumStackReferences = false;
511 }
512
513 ~ScopedDisableCheckNumStackReferences() {
514 sCheckNumStackReferences = true;
515 }
516
517 static bool sCheckNumStackReferences;
518};
519
520bool ScopedDisableCheckNumStackReferences::sCheckNumStackReferences = true;
521
Igor Murashkina51d8b72016-10-05 14:33:30 -0700522// Check that the handle scope at the start of this block is the same as the handle scope at the end of the block.
523struct ScopedCheckHandleScope {
Igor Murashkin42298112016-10-06 10:51:11 -0700524 ScopedCheckHandleScope() : handle_scope_(Thread::Current()->GetTopHandleScope()) {
Igor Murashkina51d8b72016-10-05 14:33:30 -0700525 }
526
527 ~ScopedCheckHandleScope() {
528 EXPECT_EQ(handle_scope_, Thread::Current()->GetTopHandleScope())
529 << "Top-most handle scope must be the same after all the JNI "
530 << "invocations have finished (as before they were invoked).";
531 }
532
Mathieu Chartiere8a3c572016-10-11 16:52:17 -0700533 BaseHandleScope* const handle_scope_;
Igor Murashkina51d8b72016-10-05 14:33:30 -0700534};
535
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700536static void expectNumStackReferences(size_t val1, size_t val2) {
537 // In rare cases when JNI functions call themselves recursively,
538 // disable this test because it will have a false negative.
539 if (!IsCurrentJniCritical() && ScopedDisableCheckNumStackReferences::sCheckNumStackReferences) {
540 /* @CriticalNative doesn't build a HandleScope, so this test is meaningless then. */
541 ScopedObjectAccess soa(Thread::Current());
542
543 size_t actual_num = Thread::Current()->NumStackReferences();
544 // XX: Not too sure what's going on.
545 // Sometimes null references get placed and sometimes they don't?
546 EXPECT_TRUE(val1 == actual_num || val2 == actual_num)
547 << "expected either " << val1 << " or " << val2
548 << " number of stack references, but got: " << actual_num;
549 }
550}
551
552#define EXPECT_NUM_STACK_REFERENCES(val1, val2) expectNumStackReferences(val1, val2)
553
554template <typename T, T fn>
555struct make_jni_test_decorator;
556
557// Decorator for "static" JNI callbacks.
558template <typename R, typename ... Args, R fn(JNIEnv*, jclass, Args...)>
559struct make_jni_test_decorator<R(JNIEnv*, jclass kls, Args...), fn> {
560 static R apply(JNIEnv* env, jclass kls, Args ... args) {
561 EXPECT_THREAD_STATE_FOR_CURRENT_JNI();
562 EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI();
563 EXPECT_JNI_ENV_AND_CLASS_FOR_CURRENT_JNI(env, kls);
564 // All incoming parameters + the jclass get put into the transition's StackHandleScope.
565 EXPECT_NUM_STACK_REFERENCES(count_nonnull_refs(kls, args...),
566 (count_refs_helper<jclass, Args...>::value));
567
568 return fn(env, kls, args...);
569 }
570};
571
572// Decorator for instance JNI callbacks.
573template <typename R, typename ... Args, R fn(JNIEnv*, jobject, Args...)>
574struct make_jni_test_decorator<R(JNIEnv*, jobject, Args...), fn> {
575 static R apply(JNIEnv* env, jobject thisObj, Args ... args) {
576 EXPECT_THREAD_STATE_FOR_CURRENT_JNI();
577 EXPECT_MUTATOR_LOCK_FOR_CURRENT_JNI();
578 EXPECT_JNI_ENV_AND_OBJECT_FOR_CURRENT_JNI(env, thisObj);
579 // All incoming parameters + the implicit 'this' get put into the transition's StackHandleScope.
580 EXPECT_NUM_STACK_REFERENCES(count_nonnull_refs(thisObj, args...),
581 (count_refs_helper<jobject, Args...>::value));
582
583 return fn(env, thisObj, args...);
584 }
585};
586
587// Decorate the regular JNI callee with the extra gtest checks.
588// This way we can have common test logic for everything generic like checking if a lock is held,
589// checking handle scope state, etc.
590#define MAKE_JNI_TEST_DECORATOR(fn) make_jni_test_decorator<decltype(fn), (fn)>::apply
591
592// Convert function f(JNIEnv*,jclass,a,b,c,d...) into f2(a,b,c,d...)
593// -- This way we don't have to write out each implementation twice for @CriticalNative.
594#define JNI_CRITICAL_WRAPPER(func) jni_remove_extra_parameters<decltype(func), (func)>::apply
595// Get a function pointer whose calling convention either matches a regular native
596// or a critical native depending on which kind of jni is currently under test.
597// -- This also has the benefit of genering a compile time error if the 'func' doesn't properly
598// have JNIEnv and jclass parameters first.
599#define CURRENT_JNI_WRAPPER(func) \
600 (IsCurrentJniCritical() \
601 ? reinterpret_cast<void*>(&JNI_CRITICAL_WRAPPER(MAKE_JNI_TEST_DECORATOR(func))) \
602 : reinterpret_cast<void*>(&MAKE_JNI_TEST_DECORATOR(func)))
603
604// Do the opposite of the above. Do *not* wrap the function, instead just cast it to a void*.
605// Only for "TEST_JNI_NORMAL_ONLY" configs, and it inserts a test assert to ensure this is the case.
606#define NORMAL_JNI_ONLY_NOWRAP(func) \
607 ({ ASSERT_TRUE(IsCurrentJniNormal()); reinterpret_cast<void*>(&(func)); })
608// Same as above, but with nullptr. When we want to test the stub functionality.
609#define NORMAL_JNI_ONLY_NULLPTR \
610 ({ ASSERT_TRUE(IsCurrentJniNormal()); nullptr; })
611
612
613int gJava_MyClassNatives_foo_calls[kJniKindCount] = {};
614void Java_MyClassNatives_foo(JNIEnv*, jobject) {
615 gJava_MyClassNatives_foo_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -0700616}
617
Andreas Gampe6e498692014-08-18 16:43:12 -0700618void JniCompilerTest::CompileAndRunNoArgMethodImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700619 SetUpForTest(false, "foo", "()V", CURRENT_JNI_WRAPPER(Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700620
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700621 EXPECT_EQ(0, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700622 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700623 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700624 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700625 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700626
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700627 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700628}
629
Andreas Gampe6e498692014-08-18 16:43:12 -0700630JNI_TEST(CompileAndRunNoArgMethod)
631
632void JniCompilerTest::CompileAndRunIntMethodThroughStubImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700633 SetUpForTest(false, "bar", "(I)I", NORMAL_JNI_ONLY_NULLPTR);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700634 // calling through stub will link with &Java_MyClassNatives_bar
Shih-wei Liao31384c52011-09-06 15:27:45 -0700635
Shih-wei Liao31384c52011-09-06 15:27:45 -0700636 std::string reason;
Dmitriy Ivanovf5a30992015-11-11 14:18:55 -0800637 ASSERT_TRUE(Runtime::Current()->GetJavaVM()->
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700638 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason))
Ian Rogers68d8b422014-07-17 11:09:10 -0700639 << reason;
Shih-wei Liao31384c52011-09-06 15:27:45 -0700640
641 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 24);
642 EXPECT_EQ(25, result);
643}
644
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700645// TODO: Support @FastNative and @CriticalNative through stubs.
646JNI_TEST_NORMAL_ONLY(CompileAndRunIntMethodThroughStub)
Andreas Gampe6e498692014-08-18 16:43:12 -0700647
648void JniCompilerTest::CompileAndRunStaticIntMethodThroughStubImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700649 SetUpForTest(true, "sbar", "(I)I", NORMAL_JNI_ONLY_NULLPTR);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700650 // calling through stub will link with &Java_MyClassNatives_sbar
Ian Rogers1cefdbd2012-02-29 09:34:50 -0800651
652 std::string reason;
Dmitriy Ivanovf5a30992015-11-11 14:18:55 -0800653 ASSERT_TRUE(Runtime::Current()->GetJavaVM()->
Dimitry Ivanov5edb0632016-04-29 11:14:25 -0700654 LoadNativeLibrary(env_, "", class_loader_, library_search_path_, &reason))
Ian Rogers68d8b422014-07-17 11:09:10 -0700655 << reason;
Ian Rogers1cefdbd2012-02-29 09:34:50 -0800656
657 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42);
658 EXPECT_EQ(43, result);
659}
660
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700661// TODO: Support @FastNative and @CriticalNative through stubs.
662JNI_TEST_NORMAL_ONLY(CompileAndRunStaticIntMethodThroughStub)
Andreas Gampe6e498692014-08-18 16:43:12 -0700663
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700664int gJava_MyClassNatives_fooI_calls[kJniKindCount] = {};
665jint Java_MyClassNatives_fooI(JNIEnv*, jobject, jint x) {
666 gJava_MyClassNatives_fooI_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -0700667 return x;
668}
669
Andreas Gampe6e498692014-08-18 16:43:12 -0700670void JniCompilerTest::CompileAndRunIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700671 SetUpForTest(false, "fooI", "(I)I",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700672 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooI));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700673
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700674 EXPECT_EQ(0, gJava_MyClassNatives_fooI_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700675 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 42);
676 EXPECT_EQ(42, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700677 EXPECT_EQ(1, gJava_MyClassNatives_fooI_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700678 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFED00D);
679 EXPECT_EQ(static_cast<jint>(0xCAFED00D), result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700680 EXPECT_EQ(2, gJava_MyClassNatives_fooI_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700681
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700682 gJava_MyClassNatives_fooI_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700683}
684
Andreas Gampe6e498692014-08-18 16:43:12 -0700685JNI_TEST(CompileAndRunIntMethod)
686
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700687int gJava_MyClassNatives_fooII_calls[kJniKindCount] = {};
688jint Java_MyClassNatives_fooII(JNIEnv*, jobject, jint x, jint y) {
689 gJava_MyClassNatives_fooII_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -0700690 return x - y; // non-commutative operator
691}
692
Andreas Gampe6e498692014-08-18 16:43:12 -0700693void JniCompilerTest::CompileAndRunIntIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700694 SetUpForTest(false, "fooII", "(II)I",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700695 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooII));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700696
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700697 EXPECT_EQ(0, gJava_MyClassNatives_fooII_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700698 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 99, 10);
699 EXPECT_EQ(99 - 10, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700700 EXPECT_EQ(1, gJava_MyClassNatives_fooII_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700701 result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 0xCAFEBABE,
702 0xCAFED00D);
703 EXPECT_EQ(static_cast<jint>(0xCAFEBABE - 0xCAFED00D), result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700704 EXPECT_EQ(2, gJava_MyClassNatives_fooII_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700705
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700706 gJava_MyClassNatives_fooII_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700707}
708
Andreas Gampe6e498692014-08-18 16:43:12 -0700709JNI_TEST(CompileAndRunIntIntMethod)
710
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700711int gJava_MyClassNatives_fooJJ_calls[kJniKindCount] = {};
712jlong Java_MyClassNatives_fooJJ(JNIEnv*, jobject, jlong x, jlong y) {
713 gJava_MyClassNatives_fooJJ_calls[gCurrentJni]++;
Ian Rogers9b269d22011-09-04 14:06:05 -0700714 return x - y; // non-commutative operator
715}
716
Andreas Gampe6e498692014-08-18 16:43:12 -0700717void JniCompilerTest::CompileAndRunLongLongMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700718 SetUpForTest(false, "fooJJ", "(JJ)J",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700719 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooJJ));
Ian Rogers9b269d22011-09-04 14:06:05 -0700720
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700721 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]);
Ian Rogers0f678472014-03-10 16:18:37 -0700722 jlong a = INT64_C(0x1234567890ABCDEF);
723 jlong b = INT64_C(0xFEDCBA0987654321);
Ian Rogers9b269d22011-09-04 14:06:05 -0700724 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b);
725 EXPECT_EQ(a - b, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700726 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]);
Ian Rogers9b269d22011-09-04 14:06:05 -0700727 result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, b, a);
728 EXPECT_EQ(b - a, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700729 EXPECT_EQ(2, gJava_MyClassNatives_fooJJ_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700730
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700731 gJava_MyClassNatives_fooJJ_calls[gCurrentJni] = 0;
Ian Rogers9b269d22011-09-04 14:06:05 -0700732}
733
Andreas Gampe6e498692014-08-18 16:43:12 -0700734JNI_TEST(CompileAndRunLongLongMethod)
735
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700736int gJava_MyClassNatives_fooDD_calls[kJniKindCount] = {};
737jdouble Java_MyClassNatives_fooDD(JNIEnv*, jobject, jdouble x, jdouble y) {
738 gJava_MyClassNatives_fooDD_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -0700739 return x - y; // non-commutative operator
740}
741
Andreas Gampe6e498692014-08-18 16:43:12 -0700742void JniCompilerTest::CompileAndRunDoubleDoubleMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700743 SetUpForTest(false, "fooDD", "(DD)D",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700744 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooDD));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700745
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700746 EXPECT_EQ(0, gJava_MyClassNatives_fooDD_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700747 jdouble result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_,
748 99.0, 10.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700749 EXPECT_DOUBLE_EQ(99.0 - 10.0, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700750 EXPECT_EQ(1, gJava_MyClassNatives_fooDD_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700751 jdouble a = 3.14159265358979323846;
752 jdouble b = 0.69314718055994530942;
753 result = env_->CallNonvirtualDoubleMethod(jobj_, jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -0700754 EXPECT_DOUBLE_EQ(a - b, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700755 EXPECT_EQ(2, gJava_MyClassNatives_fooDD_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700756
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700757 gJava_MyClassNatives_fooDD_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700758}
759
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700760int gJava_MyClassNatives_fooJJ_synchronized_calls[kJniKindCount] = {};
761jlong Java_MyClassNatives_fooJJ_synchronized(JNIEnv*, jobject, jlong x, jlong y) {
762 gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]++;
Elliott Hughes3e778f72012-05-21 15:29:52 -0700763 return x | y;
764}
765
Andreas Gampe6e498692014-08-18 16:43:12 -0700766void JniCompilerTest::CompileAndRun_fooJJ_synchronizedImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700767 SetUpForTest(false, "fooJJ_synchronized", "(JJ)J",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700768 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooJJ_synchronized));
Elliott Hughes3e778f72012-05-21 15:29:52 -0700769
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700770 EXPECT_EQ(0, gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]);
Elliott Hughes3e778f72012-05-21 15:29:52 -0700771 jlong a = 0x1000000020000000ULL;
772 jlong b = 0x00ff000000aa0000ULL;
773 jlong result = env_->CallNonvirtualLongMethod(jobj_, jklass_, jmethod_, a, b);
774 EXPECT_EQ(a | b, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700775 EXPECT_EQ(1, gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700776
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700777 gJava_MyClassNatives_fooJJ_synchronized_calls[gCurrentJni] = 0;
Elliott Hughes3e778f72012-05-21 15:29:52 -0700778}
779
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700780JNI_TEST_NORMAL_ONLY(CompileAndRun_fooJJ_synchronized)
Andreas Gampe6e498692014-08-18 16:43:12 -0700781
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700782int gJava_MyClassNatives_fooIOO_calls[kJniKindCount] = {};
783jobject Java_MyClassNatives_fooIOO(JNIEnv*, jobject thisObj, jint x, jobject y,
Ian Rogersb033c752011-07-20 12:22:35 -0700784 jobject z) {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700785 gJava_MyClassNatives_fooIOO_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -0700786 switch (x) {
787 case 1:
788 return y;
789 case 2:
790 return z;
791 default:
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700792 return thisObj;
Ian Rogersb033c752011-07-20 12:22:35 -0700793 }
794}
795
Andreas Gampe6e498692014-08-18 16:43:12 -0700796void JniCompilerTest::CompileAndRunIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700797 SetUpForTest(false, "fooIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700798 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700799 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooIOO));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700800
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700801 EXPECT_EQ(0, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700802 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700803 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700804 EXPECT_EQ(1, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700805
Andreas Gampecf4035a2014-05-28 22:43:01 -0700806 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, nullptr, jklass_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700807 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700808 EXPECT_EQ(2, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700809 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, nullptr, jklass_);
810 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700811 EXPECT_EQ(3, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700812 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, nullptr, jklass_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700813 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700814 EXPECT_EQ(4, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700815
Andreas Gampecf4035a2014-05-28 22:43:01 -0700816 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 0, jklass_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700817 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700818 EXPECT_EQ(5, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700819 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 1, jklass_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700820 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700821 EXPECT_EQ(6, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -0700822 result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, 2, jklass_, nullptr);
823 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700824 EXPECT_EQ(7, gJava_MyClassNatives_fooIOO_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700825
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700826 gJava_MyClassNatives_fooIOO_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -0700827}
828
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700829// TODO: Maybe. @FastNative support for returning Objects?
830JNI_TEST_NORMAL_ONLY(CompileAndRunIntObjectObjectMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -0700831
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700832int gJava_MyClassNatives_fooSII_calls[kJniKindCount] = {};
833jint Java_MyClassNatives_fooSII(JNIEnv* env ATTRIBUTE_UNUSED,
834 jclass klass ATTRIBUTE_UNUSED,
835 jint x,
836 jint y) {
837 gJava_MyClassNatives_fooSII_calls[gCurrentJni]++;
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700838 return x + y;
839}
840
Andreas Gampe6e498692014-08-18 16:43:12 -0700841void JniCompilerTest::CompileAndRunStaticIntIntMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700842 SetUpForTest(true, "fooSII", "(II)I",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700843 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSII));
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700844
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700845 EXPECT_EQ(0, gJava_MyClassNatives_fooSII_calls[gCurrentJni]);
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700846 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 20, 30);
847 EXPECT_EQ(50, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700848 EXPECT_EQ(1, gJava_MyClassNatives_fooSII_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700849
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700850 gJava_MyClassNatives_fooSII_calls[gCurrentJni] = 0;
Shih-wei Liao82da44b2011-09-01 00:38:04 -0700851}
852
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700853JNI_TEST_CRITICAL(CompileAndRunStaticIntIntMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -0700854
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700855int gJava_MyClassNatives_fooSDD_calls[kJniKindCount] = {};
856jdouble Java_MyClassNatives_fooSDD(JNIEnv* env ATTRIBUTE_UNUSED,
857 jclass klass ATTRIBUTE_UNUSED,
858 jdouble x,
859 jdouble y) {
860 gJava_MyClassNatives_fooSDD_calls[gCurrentJni]++;
Ian Rogers7a99c112011-09-07 12:48:27 -0700861 return x - y; // non-commutative operator
862}
863
Andreas Gampe6e498692014-08-18 16:43:12 -0700864void JniCompilerTest::CompileAndRunStaticDoubleDoubleMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700865 SetUpForTest(true, "fooSDD", "(DD)D",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700866 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSDD));
Ian Rogers7a99c112011-09-07 12:48:27 -0700867
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700868 EXPECT_EQ(0, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]);
Ian Rogers7a99c112011-09-07 12:48:27 -0700869 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 99.0, 10.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700870 EXPECT_DOUBLE_EQ(99.0 - 10.0, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700871 EXPECT_EQ(1, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]);
Ian Rogers7a99c112011-09-07 12:48:27 -0700872 jdouble a = 3.14159265358979323846;
873 jdouble b = 0.69314718055994530942;
874 result = env_->CallStaticDoubleMethod(jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -0700875 EXPECT_DOUBLE_EQ(a - b, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700876 EXPECT_DOUBLE_EQ(2, gJava_MyClassNatives_fooSDD_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -0700877
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700878 gJava_MyClassNatives_fooSDD_calls[gCurrentJni] = 0;
Ian Rogers7a99c112011-09-07 12:48:27 -0700879}
880
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700881JNI_TEST_CRITICAL(CompileAndRunStaticDoubleDoubleMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -0700882
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100883// The x86 generic JNI code had a bug where it assumed a floating
884// point return value would be in xmm0. We use log, to somehow ensure
885// the compiler will use the floating point stack.
886
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700887jdouble Java_MyClassNatives_logD(JNIEnv*, jclass, jdouble x) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100888 return log(x);
889}
890
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700891jdouble Java_MyClassNatives_logD_notNormal(JNIEnv*, jclass, jdouble x) {
892 EXPECT_DOUBLE_EQ(2.0, x);
893 return log(x);
894}
895
Andreas Gampe6e498692014-08-18 16:43:12 -0700896void JniCompilerTest::RunStaticLogDoubleMethodImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700897 void* jni_handler;
898 if (IsCurrentJniNormal()) {
899 // This test seems a bit special, don't use a JNI wrapper here.
900 jni_handler = NORMAL_JNI_ONLY_NOWRAP(Java_MyClassNatives_logD);
901 } else {
902 jni_handler = CURRENT_JNI_WRAPPER(Java_MyClassNatives_logD_notNormal);
903 }
904 SetUpForTest(true, "logD", "(D)D", jni_handler);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100905
906 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_, 2.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700907 EXPECT_DOUBLE_EQ(log(2.0), result);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100908}
909
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700910JNI_TEST_CRITICAL(RunStaticLogDoubleMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -0700911
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700912jfloat Java_MyClassNatives_logF(JNIEnv*, jclass, jfloat x) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100913 return logf(x);
914}
915
Andreas Gampe6e498692014-08-18 16:43:12 -0700916void JniCompilerTest::RunStaticLogFloatMethodImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700917 void* jni_handler;
918 if (IsCurrentJniNormal()) {
919 // This test seems a bit special, don't use a JNI wrapper here.
920 jni_handler = NORMAL_JNI_ONLY_NOWRAP(Java_MyClassNatives_logF);
921 } else {
922 jni_handler = CURRENT_JNI_WRAPPER(Java_MyClassNatives_logF);
923 }
924
925 SetUpForTest(true, "logF", "(F)F", jni_handler);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100926
927 jfloat result = env_->CallStaticFloatMethod(jklass_, jmethod_, 2.0);
Ian Rogers647b1a82014-10-10 11:02:11 -0700928 EXPECT_FLOAT_EQ(logf(2.0), result);
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100929}
930
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700931JNI_TEST_CRITICAL(RunStaticLogFloatMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -0700932
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700933jboolean Java_MyClassNatives_returnTrue(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100934 return JNI_TRUE;
935}
936
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700937jboolean Java_MyClassNatives_returnFalse(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100938 return JNI_FALSE;
939}
940
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700941jint Java_MyClassNatives_returnInt(JNIEnv*, jclass) {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100942 return 42;
943}
944
Andreas Gampe6e498692014-08-18 16:43:12 -0700945void JniCompilerTest::RunStaticReturnTrueImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700946 SetUpForTest(true, "returnTrue", "()Z", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnTrue));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100947
948 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_);
949 EXPECT_TRUE(result);
950}
951
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700952JNI_TEST_CRITICAL(RunStaticReturnTrue)
Andreas Gampe6e498692014-08-18 16:43:12 -0700953
954void JniCompilerTest::RunStaticReturnFalseImpl() {
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100955 SetUpForTest(true, "returnFalse", "()Z",
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700956 CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnFalse));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100957
958 jboolean result = env_->CallStaticBooleanMethod(jklass_, jmethod_);
959 EXPECT_FALSE(result);
960}
961
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700962JNI_TEST_CRITICAL(RunStaticReturnFalse)
Andreas Gampe6e498692014-08-18 16:43:12 -0700963
964void JniCompilerTest::RunGenericStaticReturnIntImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700965 SetUpForTest(true, "returnInt", "()I", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnInt));
Nicolas Geoffray54accbc2014-08-13 03:40:45 +0100966
967 jint result = env_->CallStaticIntMethod(jklass_, jmethod_);
968 EXPECT_EQ(42, result);
969}
970
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700971JNI_TEST_CRITICAL(RunGenericStaticReturnInt)
Andreas Gampe6e498692014-08-18 16:43:12 -0700972
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700973int gJava_MyClassNatives_returnDouble_calls[kJniKindCount] = {};
974jdouble Java_MyClassNatives_returnDouble(JNIEnv*, jclass) {
975 gJava_MyClassNatives_returnDouble_calls[gCurrentJni]++;
976 return 4.0;
977}
978
979void JniCompilerTest::RunGenericStaticReturnDoubleImpl() {
980 SetUpForTest(true, "returnDouble", "()D", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnDouble));
981
982 jdouble result = env_->CallStaticDoubleMethod(jklass_, jmethod_);
983 EXPECT_DOUBLE_EQ(4.0, result);
984 EXPECT_EQ(1, gJava_MyClassNatives_returnDouble_calls[gCurrentJni]);
985
986 gJava_MyClassNatives_returnDouble_calls[gCurrentJni] = 0;
987}
988
989JNI_TEST_CRITICAL(RunGenericStaticReturnDouble)
990
991jlong Java_MyClassNatives_returnLong(JNIEnv*, jclass) {
992 return 0xFEEDDEADFEEDL;
993}
994
995void JniCompilerTest::RunGenericStaticReturnLongImpl() {
996 SetUpForTest(true, "returnLong", "()J", CURRENT_JNI_WRAPPER(Java_MyClassNatives_returnLong));
997
998 jlong result = env_->CallStaticLongMethod(jklass_, jmethod_);
999 EXPECT_EQ(0xFEEDDEADFEEDL, result);
1000}
1001
1002JNI_TEST_CRITICAL(RunGenericStaticReturnLong)
1003
1004int gJava_MyClassNatives_fooSIOO_calls[kJniKindCount] = {};
1005jobject Java_MyClassNatives_fooSIOO(JNIEnv*, jclass klass, jint x, jobject y, jobject z) {
1006 gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]++;
Ian Rogersb033c752011-07-20 12:22:35 -07001007 switch (x) {
1008 case 1:
1009 return y;
1010 case 2:
1011 return z;
1012 default:
1013 return klass;
1014 }
1015}
1016
Andreas Gampe6e498692014-08-18 16:43:12 -07001017void JniCompilerTest::CompileAndRunStaticIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001018 SetUpForTest(true, "fooSIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001019 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001020 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSIOO));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001021
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001022 EXPECT_EQ(0, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001023 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001024 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001025 EXPECT_EQ(1, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001026
Andreas Gampecf4035a2014-05-28 22:43:01 -07001027 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001028 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001029 EXPECT_EQ(2, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001030 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_);
1031 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001032 EXPECT_EQ(3, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001033 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001034 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001035 EXPECT_EQ(4, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001036
Andreas Gampecf4035a2014-05-28 22:43:01 -07001037 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001038 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001039 EXPECT_EQ(5, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001040 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001041 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001042 EXPECT_EQ(6, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001043 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr);
1044 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001045 EXPECT_EQ(7, gJava_MyClassNatives_fooSIOO_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -07001046
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001047 gJava_MyClassNatives_fooSIOO_calls[gCurrentJni] = 0;
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001048}
1049
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001050// TODO: Maybe. @FastNative support for returning Objects?
1051JNI_TEST_NORMAL_ONLY(CompileAndRunStaticIntObjectObjectMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -07001052
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001053int gJava_MyClassNatives_fooSSIOO_calls[kJniKindCount] = {};
1054jobject Java_MyClassNatives_fooSSIOO(JNIEnv*, jclass klass, jint x, jobject y, jobject z) {
1055 gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]++;
Ian Rogersdf20fe02011-07-20 20:34:16 -07001056 switch (x) {
1057 case 1:
1058 return y;
1059 case 2:
1060 return z;
1061 default:
1062 return klass;
1063 }
1064}
1065
Andreas Gampe6e498692014-08-18 16:43:12 -07001066void JniCompilerTest::CompileAndRunStaticSynchronizedIntObjectObjectMethodImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001067 SetUpForTest(true, "fooSSIOO",
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001068 "(ILjava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001069 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooSSIOO));
Carl Shapiro419ec7b2011-08-03 14:48:33 -07001070
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001071 EXPECT_EQ(0, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001072 jobject result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001073 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001074 EXPECT_EQ(1, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001075
Andreas Gampecf4035a2014-05-28 22:43:01 -07001076 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001077 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001078 EXPECT_EQ(2, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001079 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, nullptr, jobj_);
1080 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001081 EXPECT_EQ(3, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001082 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, nullptr, jobj_);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001083 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001084 EXPECT_EQ(4, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001085
Andreas Gampecf4035a2014-05-28 22:43:01 -07001086 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 0, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001087 EXPECT_TRUE(env_->IsSameObject(jklass_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001088 EXPECT_EQ(5, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001089 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 1, jobj_, nullptr);
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001090 EXPECT_TRUE(env_->IsSameObject(jobj_, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001091 EXPECT_EQ(6, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001092 result = env_->CallStaticObjectMethod(jklass_, jmethod_, 2, jobj_, nullptr);
1093 EXPECT_TRUE(env_->IsSameObject(nullptr, result));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001094 EXPECT_EQ(7, gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -07001095
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001096 gJava_MyClassNatives_fooSSIOO_calls[gCurrentJni] = 0;
Ian Rogersdf20fe02011-07-20 20:34:16 -07001097}
1098
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001099// TODO: Maybe. @FastNative support for returning Objects?
1100JNI_TEST_NORMAL_ONLY(CompileAndRunStaticSynchronizedIntObjectObjectMethod)
Andreas Gampe6e498692014-08-18 16:43:12 -07001101
Elliott Hughesb264f082012-04-06 17:10:10 -07001102void Java_MyClassNatives_throwException(JNIEnv* env, jobject) {
Elliott Hughesa2501992011-08-26 19:39:54 -07001103 jclass c = env->FindClass("java/lang/RuntimeException");
1104 env->ThrowNew(c, "hello");
1105}
Ian Rogers45a76cb2011-07-21 22:00:15 -07001106
Andreas Gampe6e498692014-08-18 16:43:12 -07001107void JniCompilerTest::ExceptionHandlingImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001108 {
1109 ASSERT_FALSE(runtime_->IsStarted());
1110 ScopedObjectAccess soa(Thread::Current());
1111 class_loader_ = LoadDex("MyClassNatives");
Brian Carlstrom40381fb2011-10-19 14:13:40 -07001112
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001113 // all compilation needs to happen before Runtime::Start
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001114 CompileForTestWithCurrentJni(class_loader_, false, "foo", "()V");
1115 CompileForTestWithCurrentJni(class_loader_, false, "throwException", "()V");
1116 CompileForTestWithCurrentJni(class_loader_, false, "foo", "()V");
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001117 }
1118 // Start runtime to avoid re-initialization in SetupForTest.
1119 Thread::Current()->TransitionFromSuspendedToRunnable();
Brian Carlstrombd86bcc2013-03-10 20:26:16 -07001120 bool started = runtime_->Start();
1121 CHECK(started);
Brian Carlstrom25c33252011-09-18 15:58:35 -07001122
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001123 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0;
Elliott Hughesa2501992011-08-26 19:39:54 -07001124
Ian Rogers67375ac2011-09-14 00:55:44 -07001125 // Check a single call of a JNI method is ok
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001126 SetUpForTest(false, "foo", "()V", CURRENT_JNI_WRAPPER(Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001127 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001128 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Ian Rogers67375ac2011-09-14 00:55:44 -07001129 EXPECT_FALSE(Thread::Current()->IsExceptionPending());
Elliott Hughesa2501992011-08-26 19:39:54 -07001130
Ian Rogers67375ac2011-09-14 00:55:44 -07001131 // Get class for exception we expect to be thrown
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001132 ScopedLocalRef<jclass> jlre(env_, env_->FindClass("java/lang/RuntimeException"));
1133 SetUpForTest(false, "throwException", "()V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001134 CURRENT_JNI_WRAPPER(Java_MyClassNatives_throwException));
Elliott Hughesb264f082012-04-06 17:10:10 -07001135 // Call Java_MyClassNatives_throwException (JNI method that throws exception)
Elliott Hughesa2501992011-08-26 19:39:54 -07001136 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001137 EXPECT_EQ(1, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001138 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE);
1139 ScopedLocalRef<jthrowable> exception(env_, env_->ExceptionOccurred());
1140 env_->ExceptionClear();
1141 EXPECT_TRUE(env_->IsInstanceOf(exception.get(), jlre.get()));
Elliott Hughesa2501992011-08-26 19:39:54 -07001142
Ian Rogers67375ac2011-09-14 00:55:44 -07001143 // Check a single call of a JNI method is ok
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001144 SetUpForTest(false, "foo", "()V", reinterpret_cast<void*>(&Java_MyClassNatives_foo));
Ian Rogerscdd1d2d2011-08-18 09:58:17 -07001145 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001146 EXPECT_EQ(2, gJava_MyClassNatives_foo_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -07001147
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001148 gJava_MyClassNatives_foo_calls[gCurrentJni] = 0;
Ian Rogers45a76cb2011-07-21 22:00:15 -07001149}
1150
Andreas Gampe6e498692014-08-18 16:43:12 -07001151JNI_TEST(ExceptionHandling)
1152
Elliott Hughesb264f082012-04-06 17:10:10 -07001153jint Java_MyClassNatives_nativeUpCall(JNIEnv* env, jobject thisObj, jint i) {
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001154 if (i <= 0) {
Andreas Gampecf4035a2014-05-28 22:43:01 -07001155 // We want to check raw Object* / Array* below
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001156 ScopedObjectAccess soa(env);
Ian Rogersaaa20802011-09-11 21:47:37 -07001157
1158 // Build stack trace
Sebastien Hertzee1d79a2014-02-21 15:46:30 +01001159 jobject internal = Thread::Current()->CreateInternalStackTrace<false>(soa);
Ian Rogers53b8b092014-03-13 23:45:53 -07001160 jobjectArray ste_array = Thread::InternalStackTraceToStackTraceElementArray(soa, internal);
Mathieu Chartier0795f232016-09-27 18:43:30 -07001161 ObjPtr<mirror::ObjectArray<mirror::StackTraceElement>> trace_array =
1162 soa.Decode<mirror::ObjectArray<mirror::StackTraceElement>>(ste_array);
Andreas Gampecf4035a2014-05-28 22:43:01 -07001163 EXPECT_TRUE(trace_array != nullptr);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001164 EXPECT_EQ(11, trace_array->GetLength());
1165
Ian Rogersaaa20802011-09-11 21:47:37 -07001166 // Check stack trace entries have expected values
Andreas Gampe277ccbd2014-11-03 21:36:10 -08001167 for (int32_t j = 0; j < trace_array->GetLength(); ++j) {
1168 EXPECT_EQ(-2, trace_array->Get(j)->GetLineNumber());
1169 mirror::StackTraceElement* ste = trace_array->Get(j);
Ian Rogersaaa20802011-09-11 21:47:37 -07001170 EXPECT_STREQ("MyClassNatives.java", ste->GetFileName()->ToModifiedUtf8().c_str());
Elliott Hughesb264f082012-04-06 17:10:10 -07001171 EXPECT_STREQ("MyClassNatives", ste->GetDeclaringClass()->ToModifiedUtf8().c_str());
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001172 EXPECT_EQ(("fooI" + CurrentJniStringSuffix()), ste->GetMethodName()->ToModifiedUtf8());
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001173 }
Ian Rogersaaa20802011-09-11 21:47:37 -07001174
1175 // end recursion
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001176 return 0;
1177 } else {
Elliott Hughesb264f082012-04-06 17:10:10 -07001178 jclass jklass = env->FindClass("MyClassNatives");
Andreas Gampecf4035a2014-05-28 22:43:01 -07001179 EXPECT_TRUE(jklass != nullptr);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001180 jmethodID jmethod = env->GetMethodID(jklass,
1181 ("fooI" + CurrentJniStringSuffix()).c_str(),
1182 "(I)I");
Andreas Gampecf4035a2014-05-28 22:43:01 -07001183 EXPECT_TRUE(jmethod != nullptr);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001184
Ian Rogersaaa20802011-09-11 21:47:37 -07001185 // Recurse with i - 1
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001186 jint result = env->CallNonvirtualIntMethod(thisObj, jklass, jmethod, i - 1);
Ian Rogersaaa20802011-09-11 21:47:37 -07001187
1188 // Return sum of all depths
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001189 return i + result;
1190 }
1191}
1192
Andreas Gampe6e498692014-08-18 16:43:12 -07001193void JniCompilerTest::NativeStackTraceElementImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001194 SetUpForTest(false, "fooI", "(I)I",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001195 CURRENT_JNI_WRAPPER(Java_MyClassNatives_nativeUpCall));
1196
1197 // Usual # local references on stack check fails because nativeUpCall calls itself recursively,
1198 // each time the # of local references will therefore go up.
1199 ScopedDisableCheckNumStackReferences disable_num_stack_check;
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001200 jint result = env_->CallNonvirtualIntMethod(jobj_, jklass_, jmethod_, 10);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001201
Ian Rogersaaa20802011-09-11 21:47:37 -07001202 EXPECT_EQ(10+9+8+7+6+5+4+3+2+1, result);
Shih-wei Liaoff0f9be2011-08-29 15:43:53 -07001203}
1204
Andreas Gampe6e498692014-08-18 16:43:12 -07001205JNI_TEST(NativeStackTraceElement)
1206
Elliott Hughesb264f082012-04-06 17:10:10 -07001207jobject Java_MyClassNatives_fooO(JNIEnv* env, jobject, jobject x) {
Shih-wei Liao558788e2011-09-01 02:39:11 -07001208 return env->NewGlobalRef(x);
1209}
1210
Andreas Gampe6e498692014-08-18 16:43:12 -07001211void JniCompilerTest::ReturnGlobalRefImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001212 SetUpForTest(false, "fooO", "(Ljava/lang/Object;)Ljava/lang/Object;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001213 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fooO));
Shih-wei Liao558788e2011-09-01 02:39:11 -07001214 jobject result = env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, jobj_);
1215 EXPECT_EQ(JNILocalRefType, env_->GetObjectRefType(result));
1216 EXPECT_TRUE(env_->IsSameObject(result, jobj_));
1217}
1218
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001219// TODO: Maybe. @FastNative support for returning objects?
1220JNI_TEST_NORMAL_ONLY(ReturnGlobalRef)
Andreas Gampe6e498692014-08-18 16:43:12 -07001221
Ian Rogersdc51b792011-09-22 20:41:37 -07001222jint local_ref_test(JNIEnv* env, jobject thisObj, jint x) {
1223 // Add 10 local references
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001224 ScopedObjectAccess soa(env);
Ian Rogers5a7a74a2011-09-26 16:32:29 -07001225 for (int i = 0; i < 10; i++) {
Mathieu Chartier0795f232016-09-27 18:43:30 -07001226 soa.AddLocalReference<jobject>(soa.Decode<mirror::Object>(thisObj));
Ian Rogersdc51b792011-09-22 20:41:37 -07001227 }
1228 return x+1;
1229}
1230
Andreas Gampe6e498692014-08-18 16:43:12 -07001231void JniCompilerTest::LocalReferenceTableClearingTestImpl() {
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001232 SetUpForTest(false, "fooI", "(I)I", CURRENT_JNI_WRAPPER(local_ref_test));
Ian Rogersdc51b792011-09-22 20:41:37 -07001233 // 1000 invocations of a method that adds 10 local references
Elliott Hughesb25c3f62012-03-26 16:35:06 -07001234 for (int i = 0; i < 1000; i++) {
Ian Rogersdc51b792011-09-22 20:41:37 -07001235 jint result = env_->CallIntMethod(jobj_, jmethod_, i);
1236 EXPECT_TRUE(result == i + 1);
1237 }
1238}
1239
Andreas Gampe6e498692014-08-18 16:43:12 -07001240JNI_TEST(LocalReferenceTableClearingTest)
1241
Ian Rogersb9231c82011-09-05 22:13:19 -07001242void my_arraycopy(JNIEnv* env, jclass klass, jobject src, jint src_pos, jobject dst, jint dst_pos, jint length) {
1243 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, klass));
1244 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jklass_, dst));
Ian Rogers82f3e092011-09-05 22:54:45 -07001245 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, src));
Ian Rogersb9231c82011-09-05 22:13:19 -07001246 EXPECT_EQ(1234, src_pos);
1247 EXPECT_EQ(5678, dst_pos);
1248 EXPECT_EQ(9876, length);
1249}
1250
Andreas Gampe6e498692014-08-18 16:43:12 -07001251void JniCompilerTest::JavaLangSystemArrayCopyImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001252 SetUpForTest(true, "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001253 CURRENT_JNI_WRAPPER(my_arraycopy));
Ian Rogers82f3e092011-09-05 22:54:45 -07001254 env_->CallStaticVoidMethod(jklass_, jmethod_, jobj_, 1234, jklass_, 5678, 9876);
Ian Rogersb9231c82011-09-05 22:13:19 -07001255}
1256
Andreas Gampe6e498692014-08-18 16:43:12 -07001257JNI_TEST(JavaLangSystemArrayCopy)
1258
Ian Rogers67375ac2011-09-14 00:55:44 -07001259jboolean my_casi(JNIEnv* env, jobject unsafe, jobject obj, jlong offset, jint expected, jint newval) {
1260 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, unsafe));
1261 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj));
Ian Rogers0f678472014-03-10 16:18:37 -07001262 EXPECT_EQ(INT64_C(0x12345678ABCDEF88), offset);
Ian Rogers67375ac2011-09-14 00:55:44 -07001263 EXPECT_EQ(static_cast<jint>(0xCAFEF00D), expected);
1264 EXPECT_EQ(static_cast<jint>(0xEBADF00D), newval);
1265 return JNI_TRUE;
1266}
1267
Andreas Gampe6e498692014-08-18 16:43:12 -07001268void JniCompilerTest::CompareAndSwapIntImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001269 SetUpForTest(false, "compareAndSwapInt", "(Ljava/lang/Object;JII)Z",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001270 CURRENT_JNI_WRAPPER(my_casi));
Ian Rogers0f678472014-03-10 16:18:37 -07001271 jboolean result = env_->CallBooleanMethod(jobj_, jmethod_, jobj_, INT64_C(0x12345678ABCDEF88),
1272 0xCAFEF00D, 0xEBADF00D);
Ian Rogers67375ac2011-09-14 00:55:44 -07001273 EXPECT_EQ(result, JNI_TRUE);
1274}
1275
Andreas Gampe6e498692014-08-18 16:43:12 -07001276JNI_TEST(CompareAndSwapInt)
1277
Ian Rogersc7792842012-03-03 15:36:20 -08001278jint my_gettext(JNIEnv* env, jclass klass, jlong val1, jobject obj1, jlong val2, jobject obj2) {
1279 EXPECT_TRUE(env->IsInstanceOf(JniCompilerTest::jobj_, klass));
1280 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj1));
1281 EXPECT_TRUE(env->IsSameObject(JniCompilerTest::jobj_, obj2));
1282 EXPECT_EQ(0x12345678ABCDEF88ll, val1);
1283 EXPECT_EQ(0x7FEDCBA987654321ll, val2);
1284 return 42;
1285}
1286
Andreas Gampe6e498692014-08-18 16:43:12 -07001287void JniCompilerTest::GetTextImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001288 SetUpForTest(true, "getText", "(JLjava/lang/Object;JLjava/lang/Object;)I",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001289 CURRENT_JNI_WRAPPER(my_gettext));
Ian Rogersc7792842012-03-03 15:36:20 -08001290 jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 0x12345678ABCDEF88ll, jobj_,
Ian Rogers0f678472014-03-10 16:18:37 -07001291 INT64_C(0x7FEDCBA987654321), jobj_);
Ian Rogersc7792842012-03-03 15:36:20 -08001292 EXPECT_EQ(result, 42);
1293}
1294
Andreas Gampe6e498692014-08-18 16:43:12 -07001295JNI_TEST(GetText)
1296
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001297int gJava_MyClassNatives_GetSinkProperties_calls[kJniKindCount] = {};
1298jarray Java_MyClassNatives_GetSinkProperties(JNIEnv*, jobject thisObj, jstring s) {
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001299 EXPECT_EQ(s, nullptr);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001300 gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]++;
1301
1302 Thread* self = Thread::Current();
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001303 ScopedObjectAccess soa(self);
Mathieu Chartier1cc62e42016-10-03 18:01:28 -07001304 EXPECT_TRUE(self->HoldsLock(soa.Decode<mirror::Object>(thisObj).Ptr()));
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001305 return nullptr;
1306}
1307
Andreas Gampe6e498692014-08-18 16:43:12 -07001308void JniCompilerTest::GetSinkPropertiesNativeImpl() {
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001309 SetUpForTest(false, "getSinkPropertiesNative", "(Ljava/lang/String;)[Ljava/lang/Object;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001310 CURRENT_JNI_WRAPPER(Java_MyClassNatives_GetSinkProperties));
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001311
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001312 EXPECT_EQ(0, gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]);
Vladimir Marko4e24b9d2014-07-24 17:01:58 +01001313 jarray result = down_cast<jarray>(
1314 env_->CallNonvirtualObjectMethod(jobj_, jklass_, jmethod_, nullptr));
1315 EXPECT_EQ(nullptr, result);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001316 EXPECT_EQ(1, gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni]);
Andreas Gampe6e498692014-08-18 16:43:12 -07001317
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001318 gJava_MyClassNatives_GetSinkProperties_calls[gCurrentJni] = 0;
Brian Carlstromfc7120c2012-08-27 13:43:25 -07001319}
1320
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001321// @FastNative doesn't support 'synchronized' keyword and
1322// never will -- locking functions aren't fast.
1323JNI_TEST_NORMAL_ONLY(GetSinkPropertiesNative)
Andreas Gampe6e498692014-08-18 16:43:12 -07001324
Elliott Hughesb264f082012-04-06 17:10:10 -07001325// This should return jclass, but we're imitating a bug pattern.
1326jobject Java_MyClassNatives_instanceMethodThatShouldReturnClass(JNIEnv* env, jobject) {
1327 return env->NewStringUTF("not a class!");
1328}
1329
1330// This should return jclass, but we're imitating a bug pattern.
1331jobject Java_MyClassNatives_staticMethodThatShouldReturnClass(JNIEnv* env, jclass) {
1332 return env->NewStringUTF("not a class!");
1333}
1334
Andreas Gampe6e498692014-08-18 16:43:12 -07001335void JniCompilerTest::UpcallReturnTypeChecking_InstanceImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001336 SetUpForTest(false, "instanceMethodThatShouldReturnClass", "()Ljava/lang/Class;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001337 CURRENT_JNI_WRAPPER(Java_MyClassNatives_instanceMethodThatShouldReturnClass));
Elliott Hughesb264f082012-04-06 17:10:10 -07001338
1339 CheckJniAbortCatcher check_jni_abort_catcher;
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001340 // This native method is bad, and tries to return a jstring as a jclass.
1341 env_->CallObjectMethod(jobj_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001342 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " +
1343 "of java.lang.String from java.lang.Class " +
1344 "MyClassNatives.instanceMethodThatShouldReturnClass" +
1345 CurrentJniStringSuffix() + "()");
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001346
1347 // Here, we just call the method incorrectly; we should catch that too.
Ian Rogers68d8b422014-07-17 11:09:10 -07001348 env_->CallObjectMethod(jobj_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001349 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " +
1350 "of java.lang.String from java.lang.Class " +
1351 "MyClassNatives.instanceMethodThatShouldReturnClass" +
1352 CurrentJniStringSuffix() + "()");
Ian Rogers68d8b422014-07-17 11:09:10 -07001353 env_->CallStaticObjectMethod(jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001354 check_jni_abort_catcher.Check(std::string() + "calling non-static method " +
1355 "java.lang.Class " +
1356 "MyClassNatives.instanceMethodThatShouldReturnClass" +
1357 CurrentJniStringSuffix() + "() with CallStaticObjectMethodV");
Elliott Hughesb264f082012-04-06 17:10:10 -07001358}
1359
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001360// TODO: Maybe support returning objects for @FastNative?
1361JNI_TEST_NORMAL_ONLY(UpcallReturnTypeChecking_Instance)
Andreas Gampe6e498692014-08-18 16:43:12 -07001362
1363void JniCompilerTest::UpcallReturnTypeChecking_StaticImpl() {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001364 SetUpForTest(true, "staticMethodThatShouldReturnClass", "()Ljava/lang/Class;",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001365 CURRENT_JNI_WRAPPER(Java_MyClassNatives_staticMethodThatShouldReturnClass));
Elliott Hughesb264f082012-04-06 17:10:10 -07001366
1367 CheckJniAbortCatcher check_jni_abort_catcher;
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001368 // This native method is bad, and tries to return a jstring as a jclass.
1369 env_->CallStaticObjectMethod(jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001370 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " +
1371 "of java.lang.String from java.lang.Class " +
1372 "MyClassNatives.staticMethodThatShouldReturnClass" +
1373 CurrentJniStringSuffix() + "()");
Elliott Hughes3f6635a2012-06-19 13:37:49 -07001374
1375 // Here, we just call the method incorrectly; we should catch that too.
Ian Rogers68d8b422014-07-17 11:09:10 -07001376 env_->CallStaticObjectMethod(jklass_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001377 check_jni_abort_catcher.Check(std::string() + "attempt to return an instance " +
1378 "of java.lang.String from java.lang.Class " +
1379 "MyClassNatives.staticMethodThatShouldReturnClass" +
1380 CurrentJniStringSuffix() + "()");
Ian Rogers68d8b422014-07-17 11:09:10 -07001381 env_->CallObjectMethod(jobj_, jmethod_);
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001382 check_jni_abort_catcher.Check(std::string() + "calling static method " +
1383 "java.lang.Class " +
1384 "MyClassNatives.staticMethodThatShouldReturnClass" +
1385 CurrentJniStringSuffix() + "() with CallObjectMethodV");
Elliott Hughesb264f082012-04-06 17:10:10 -07001386}
1387
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001388// TODO: Maybe support returning objects for @FastNative?
1389JNI_TEST_NORMAL_ONLY(UpcallReturnTypeChecking_Static)
Andreas Gampe6e498692014-08-18 16:43:12 -07001390
Elliott Hughesb264f082012-04-06 17:10:10 -07001391// This should take jclass, but we're imitating a bug pattern.
1392void Java_MyClassNatives_instanceMethodThatShouldTakeClass(JNIEnv*, jobject, jclass) {
1393}
1394
1395// This should take jclass, but we're imitating a bug pattern.
1396void Java_MyClassNatives_staticMethodThatShouldTakeClass(JNIEnv*, jclass, jclass) {
1397}
1398
Andreas Gampe6e498692014-08-18 16:43:12 -07001399void JniCompilerTest::UpcallArgumentTypeChecking_InstanceImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -08001400 // This will lead to error messages in the log.
1401 ScopedLogSeverity sls(LogSeverity::FATAL);
1402
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001403 SetUpForTest(false, "instanceMethodThatShouldTakeClass", "(ILjava/lang/Class;)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001404 CURRENT_JNI_WRAPPER(Java_MyClassNatives_instanceMethodThatShouldTakeClass));
Elliott Hughesb264f082012-04-06 17:10:10 -07001405
1406 CheckJniAbortCatcher check_jni_abort_catcher;
1407 // We deliberately pass a bad second argument here.
1408 env_->CallVoidMethod(jobj_, jmethod_, 123, env_->NewStringUTF("not a class!"));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001409 check_jni_abort_catcher.Check(std::string() + "bad arguments passed to void " +
1410 "MyClassNatives.instanceMethodThatShouldTakeClass" +
1411 CurrentJniStringSuffix() + "(int, java.lang.Class)");
Elliott Hughesb264f082012-04-06 17:10:10 -07001412}
1413
Andreas Gampe6e498692014-08-18 16:43:12 -07001414JNI_TEST(UpcallArgumentTypeChecking_Instance)
1415
1416void JniCompilerTest::UpcallArgumentTypeChecking_StaticImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -08001417 // This will lead to error messages in the log.
1418 ScopedLogSeverity sls(LogSeverity::FATAL);
1419
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001420 SetUpForTest(true, "staticMethodThatShouldTakeClass", "(ILjava/lang/Class;)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001421 CURRENT_JNI_WRAPPER(Java_MyClassNatives_staticMethodThatShouldTakeClass));
Elliott Hughesb264f082012-04-06 17:10:10 -07001422
1423 CheckJniAbortCatcher check_jni_abort_catcher;
1424 // We deliberately pass a bad second argument here.
1425 env_->CallStaticVoidMethod(jklass_, jmethod_, 123, env_->NewStringUTF("not a class!"));
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001426 check_jni_abort_catcher.Check(std::string() + "bad arguments passed to void " +
1427 "MyClassNatives.staticMethodThatShouldTakeClass" +
1428 CurrentJniStringSuffix() + "(int, java.lang.Class)");
Elliott Hughesb264f082012-04-06 17:10:10 -07001429}
1430
Andreas Gampe6e498692014-08-18 16:43:12 -07001431JNI_TEST(UpcallArgumentTypeChecking_Static)
1432
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001433jfloat Java_MyClassNatives_checkFloats(JNIEnv*, jobject, jfloat f1, jfloat f2) {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001434 return f1 - f2; // non-commutative operator
1435}
1436
Andreas Gampe6e498692014-08-18 16:43:12 -07001437void JniCompilerTest::CompileAndRunFloatFloatMethodImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001438 SetUpForTest(false, "checkFloats", "(FF)F",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001439 CURRENT_JNI_WRAPPER(Java_MyClassNatives_checkFloats));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001440
1441 jfloat result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_,
1442 99.0F, 10.0F);
Ian Rogers647b1a82014-10-10 11:02:11 -07001443 EXPECT_FLOAT_EQ(99.0F - 10.0F, result);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001444 jfloat a = 3.14159F;
1445 jfloat b = 0.69314F;
1446 result = env_->CallNonvirtualFloatMethod(jobj_, jklass_, jmethod_, a, b);
Ian Rogers647b1a82014-10-10 11:02:11 -07001447 EXPECT_FLOAT_EQ(a - b, result);
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001448}
1449
Andreas Gampe6e498692014-08-18 16:43:12 -07001450JNI_TEST(CompileAndRunFloatFloatMethod)
1451
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001452void Java_MyClassNatives_checkParameterAlign(JNIEnv* env ATTRIBUTE_UNUSED,
1453 jobject thisObj ATTRIBUTE_UNUSED,
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001454 jint i1,
1455 jlong l1) {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001456 EXPECT_EQ(i1, 1234);
Ian Rogers0f678472014-03-10 16:18:37 -07001457 EXPECT_EQ(l1, INT64_C(0x12345678ABCDEF0));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001458}
1459
Andreas Gampe6e498692014-08-18 16:43:12 -07001460void JniCompilerTest::CheckParameterAlignImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001461 SetUpForTest(false, "checkParameterAlign", "(IJ)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001462 CURRENT_JNI_WRAPPER(Java_MyClassNatives_checkParameterAlign));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001463
Ian Rogers0f678472014-03-10 16:18:37 -07001464 env_->CallNonvirtualVoidMethod(jobj_, jklass_, jmethod_, 1234, INT64_C(0x12345678ABCDEF0));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001465}
1466
Andreas Gampe6e498692014-08-18 16:43:12 -07001467JNI_TEST(CheckParameterAlign)
1468
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001469void Java_MyClassNatives_maxParamNumber(JNIEnv* env, jobject,
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001470 jobject o0, jobject o1, jobject o2, jobject o3, jobject o4, jobject o5, jobject o6, jobject o7,
1471 jobject o8, jobject o9, jobject o10, jobject o11, jobject o12, jobject o13, jobject o14, jobject o15,
1472 jobject o16, jobject o17, jobject o18, jobject o19, jobject o20, jobject o21, jobject o22, jobject o23,
1473 jobject o24, jobject o25, jobject o26, jobject o27, jobject o28, jobject o29, jobject o30, jobject o31,
1474 jobject o32, jobject o33, jobject o34, jobject o35, jobject o36, jobject o37, jobject o38, jobject o39,
1475 jobject o40, jobject o41, jobject o42, jobject o43, jobject o44, jobject o45, jobject o46, jobject o47,
1476 jobject o48, jobject o49, jobject o50, jobject o51, jobject o52, jobject o53, jobject o54, jobject o55,
1477 jobject o56, jobject o57, jobject o58, jobject o59, jobject o60, jobject o61, jobject o62, jobject o63,
1478 jobject o64, jobject o65, jobject o66, jobject o67, jobject o68, jobject o69, jobject o70, jobject o71,
1479 jobject o72, jobject o73, jobject o74, jobject o75, jobject o76, jobject o77, jobject o78, jobject o79,
1480 jobject o80, jobject o81, jobject o82, jobject o83, jobject o84, jobject o85, jobject o86, jobject o87,
1481 jobject o88, jobject o89, jobject o90, jobject o91, jobject o92, jobject o93, jobject o94, jobject o95,
1482 jobject o96, jobject o97, jobject o98, jobject o99, jobject o100, jobject o101, jobject o102, jobject o103,
1483 jobject o104, jobject o105, jobject o106, jobject o107, jobject o108, jobject o109, jobject o110, jobject o111,
1484 jobject o112, jobject o113, jobject o114, jobject o115, jobject o116, jobject o117, jobject o118, jobject o119,
1485 jobject o120, jobject o121, jobject o122, jobject o123, jobject o124, jobject o125, jobject o126, jobject o127,
1486 jobject o128, jobject o129, jobject o130, jobject o131, jobject o132, jobject o133, jobject o134, jobject o135,
1487 jobject o136, jobject o137, jobject o138, jobject o139, jobject o140, jobject o141, jobject o142, jobject o143,
1488 jobject o144, jobject o145, jobject o146, jobject o147, jobject o148, jobject o149, jobject o150, jobject o151,
1489 jobject o152, jobject o153, jobject o154, jobject o155, jobject o156, jobject o157, jobject o158, jobject o159,
1490 jobject o160, jobject o161, jobject o162, jobject o163, jobject o164, jobject o165, jobject o166, jobject o167,
1491 jobject o168, jobject o169, jobject o170, jobject o171, jobject o172, jobject o173, jobject o174, jobject o175,
1492 jobject o176, jobject o177, jobject o178, jobject o179, jobject o180, jobject o181, jobject o182, jobject o183,
1493 jobject o184, jobject o185, jobject o186, jobject o187, jobject o188, jobject o189, jobject o190, jobject o191,
1494 jobject o192, jobject o193, jobject o194, jobject o195, jobject o196, jobject o197, jobject o198, jobject o199,
1495 jobject o200, jobject o201, jobject o202, jobject o203, jobject o204, jobject o205, jobject o206, jobject o207,
1496 jobject o208, jobject o209, jobject o210, jobject o211, jobject o212, jobject o213, jobject o214, jobject o215,
1497 jobject o216, jobject o217, jobject o218, jobject o219, jobject o220, jobject o221, jobject o222, jobject o223,
1498 jobject o224, jobject o225, jobject o226, jobject o227, jobject o228, jobject o229, jobject o230, jobject o231,
1499 jobject o232, jobject o233, jobject o234, jobject o235, jobject o236, jobject o237, jobject o238, jobject o239,
1500 jobject o240, jobject o241, jobject o242, jobject o243, jobject o244, jobject o245, jobject o246, jobject o247,
1501 jobject o248, jobject o249, jobject o250, jobject o251, jobject o252, jobject o253) {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001502 // two tests possible
1503 if (o0 == nullptr) {
1504 // 1) everything is null
1505 EXPECT_TRUE(o0 == nullptr && o1 == nullptr && o2 == nullptr && o3 == nullptr && o4 == nullptr
1506 && o5 == nullptr && o6 == nullptr && o7 == nullptr && o8 == nullptr && o9 == nullptr
1507 && o10 == nullptr && o11 == nullptr && o12 == nullptr && o13 == nullptr && o14 == nullptr
1508 && o15 == nullptr && o16 == nullptr && o17 == nullptr && o18 == nullptr && o19 == nullptr
1509 && o20 == nullptr && o21 == nullptr && o22 == nullptr && o23 == nullptr && o24 == nullptr
1510 && o25 == nullptr && o26 == nullptr && o27 == nullptr && o28 == nullptr && o29 == nullptr
1511 && o30 == nullptr && o31 == nullptr && o32 == nullptr && o33 == nullptr && o34 == nullptr
1512 && o35 == nullptr && o36 == nullptr && o37 == nullptr && o38 == nullptr && o39 == nullptr
1513 && o40 == nullptr && o41 == nullptr && o42 == nullptr && o43 == nullptr && o44 == nullptr
1514 && o45 == nullptr && o46 == nullptr && o47 == nullptr && o48 == nullptr && o49 == nullptr
1515 && o50 == nullptr && o51 == nullptr && o52 == nullptr && o53 == nullptr && o54 == nullptr
1516 && o55 == nullptr && o56 == nullptr && o57 == nullptr && o58 == nullptr && o59 == nullptr
1517 && o60 == nullptr && o61 == nullptr && o62 == nullptr && o63 == nullptr && o64 == nullptr
1518 && o65 == nullptr && o66 == nullptr && o67 == nullptr && o68 == nullptr && o69 == nullptr
1519 && o70 == nullptr && o71 == nullptr && o72 == nullptr && o73 == nullptr && o74 == nullptr
1520 && o75 == nullptr && o76 == nullptr && o77 == nullptr && o78 == nullptr && o79 == nullptr
1521 && o80 == nullptr && o81 == nullptr && o82 == nullptr && o83 == nullptr && o84 == nullptr
1522 && o85 == nullptr && o86 == nullptr && o87 == nullptr && o88 == nullptr && o89 == nullptr
1523 && o90 == nullptr && o91 == nullptr && o92 == nullptr && o93 == nullptr && o94 == nullptr
1524 && o95 == nullptr && o96 == nullptr && o97 == nullptr && o98 == nullptr && o99 == nullptr
1525 && o100 == nullptr && o101 == nullptr && o102 == nullptr && o103 == nullptr && o104 == nullptr
1526 && o105 == nullptr && o106 == nullptr && o107 == nullptr && o108 == nullptr && o109 == nullptr
1527 && o110 == nullptr && o111 == nullptr && o112 == nullptr && o113 == nullptr && o114 == nullptr
1528 && o115 == nullptr && o116 == nullptr && o117 == nullptr && o118 == nullptr && o119 == nullptr
1529 && o120 == nullptr && o121 == nullptr && o122 == nullptr && o123 == nullptr && o124 == nullptr
1530 && o125 == nullptr && o126 == nullptr && o127 == nullptr && o128 == nullptr && o129 == nullptr
1531 && o130 == nullptr && o131 == nullptr && o132 == nullptr && o133 == nullptr && o134 == nullptr
1532 && o135 == nullptr && o136 == nullptr && o137 == nullptr && o138 == nullptr && o139 == nullptr
1533 && o140 == nullptr && o141 == nullptr && o142 == nullptr && o143 == nullptr && o144 == nullptr
1534 && o145 == nullptr && o146 == nullptr && o147 == nullptr && o148 == nullptr && o149 == nullptr
1535 && o150 == nullptr && o151 == nullptr && o152 == nullptr && o153 == nullptr && o154 == nullptr
1536 && o155 == nullptr && o156 == nullptr && o157 == nullptr && o158 == nullptr && o159 == nullptr
1537 && o160 == nullptr && o161 == nullptr && o162 == nullptr && o163 == nullptr && o164 == nullptr
1538 && o165 == nullptr && o166 == nullptr && o167 == nullptr && o168 == nullptr && o169 == nullptr
1539 && o170 == nullptr && o171 == nullptr && o172 == nullptr && o173 == nullptr && o174 == nullptr
1540 && o175 == nullptr && o176 == nullptr && o177 == nullptr && o178 == nullptr && o179 == nullptr
1541 && o180 == nullptr && o181 == nullptr && o182 == nullptr && o183 == nullptr && o184 == nullptr
1542 && o185 == nullptr && o186 == nullptr && o187 == nullptr && o188 == nullptr && o189 == nullptr
1543 && o190 == nullptr && o191 == nullptr && o192 == nullptr && o193 == nullptr && o194 == nullptr
1544 && o195 == nullptr && o196 == nullptr && o197 == nullptr && o198 == nullptr && o199 == nullptr
1545 && o200 == nullptr && o201 == nullptr && o202 == nullptr && o203 == nullptr && o204 == nullptr
1546 && o205 == nullptr && o206 == nullptr && o207 == nullptr && o208 == nullptr && o209 == nullptr
1547 && o210 == nullptr && o211 == nullptr && o212 == nullptr && o213 == nullptr && o214 == nullptr
1548 && o215 == nullptr && o216 == nullptr && o217 == nullptr && o218 == nullptr && o219 == nullptr
1549 && o220 == nullptr && o221 == nullptr && o222 == nullptr && o223 == nullptr && o224 == nullptr
1550 && o225 == nullptr && o226 == nullptr && o227 == nullptr && o228 == nullptr && o229 == nullptr
1551 && o230 == nullptr && o231 == nullptr && o232 == nullptr && o233 == nullptr && o234 == nullptr
1552 && o235 == nullptr && o236 == nullptr && o237 == nullptr && o238 == nullptr && o239 == nullptr
1553 && o240 == nullptr && o241 == nullptr && o242 == nullptr && o243 == nullptr && o244 == nullptr
1554 && o245 == nullptr && o246 == nullptr && o247 == nullptr && o248 == nullptr && o249 == nullptr
1555 && o250 == nullptr && o251 == nullptr && o252 == nullptr && o253 == nullptr);
1556 } else {
1557 EXPECT_EQ(0, env->GetArrayLength(reinterpret_cast<jarray>(o0)));
1558 EXPECT_EQ(1, env->GetArrayLength(reinterpret_cast<jarray>(o1)));
1559 EXPECT_EQ(2, env->GetArrayLength(reinterpret_cast<jarray>(o2)));
1560 EXPECT_EQ(3, env->GetArrayLength(reinterpret_cast<jarray>(o3)));
1561 EXPECT_EQ(4, env->GetArrayLength(reinterpret_cast<jarray>(o4)));
1562 EXPECT_EQ(5, env->GetArrayLength(reinterpret_cast<jarray>(o5)));
1563 EXPECT_EQ(6, env->GetArrayLength(reinterpret_cast<jarray>(o6)));
1564 EXPECT_EQ(7, env->GetArrayLength(reinterpret_cast<jarray>(o7)));
1565 EXPECT_EQ(8, env->GetArrayLength(reinterpret_cast<jarray>(o8)));
1566 EXPECT_EQ(9, env->GetArrayLength(reinterpret_cast<jarray>(o9)));
1567 EXPECT_EQ(10, env->GetArrayLength(reinterpret_cast<jarray>(o10)));
1568 EXPECT_EQ(11, env->GetArrayLength(reinterpret_cast<jarray>(o11)));
1569 EXPECT_EQ(12, env->GetArrayLength(reinterpret_cast<jarray>(o12)));
1570 EXPECT_EQ(13, env->GetArrayLength(reinterpret_cast<jarray>(o13)));
1571 EXPECT_EQ(14, env->GetArrayLength(reinterpret_cast<jarray>(o14)));
1572 EXPECT_EQ(15, env->GetArrayLength(reinterpret_cast<jarray>(o15)));
1573 EXPECT_EQ(16, env->GetArrayLength(reinterpret_cast<jarray>(o16)));
1574 EXPECT_EQ(17, env->GetArrayLength(reinterpret_cast<jarray>(o17)));
1575 EXPECT_EQ(18, env->GetArrayLength(reinterpret_cast<jarray>(o18)));
1576 EXPECT_EQ(19, env->GetArrayLength(reinterpret_cast<jarray>(o19)));
1577 EXPECT_EQ(20, env->GetArrayLength(reinterpret_cast<jarray>(o20)));
1578 EXPECT_EQ(21, env->GetArrayLength(reinterpret_cast<jarray>(o21)));
1579 EXPECT_EQ(22, env->GetArrayLength(reinterpret_cast<jarray>(o22)));
1580 EXPECT_EQ(23, env->GetArrayLength(reinterpret_cast<jarray>(o23)));
1581 EXPECT_EQ(24, env->GetArrayLength(reinterpret_cast<jarray>(o24)));
1582 EXPECT_EQ(25, env->GetArrayLength(reinterpret_cast<jarray>(o25)));
1583 EXPECT_EQ(26, env->GetArrayLength(reinterpret_cast<jarray>(o26)));
1584 EXPECT_EQ(27, env->GetArrayLength(reinterpret_cast<jarray>(o27)));
1585 EXPECT_EQ(28, env->GetArrayLength(reinterpret_cast<jarray>(o28)));
1586 EXPECT_EQ(29, env->GetArrayLength(reinterpret_cast<jarray>(o29)));
1587 EXPECT_EQ(30, env->GetArrayLength(reinterpret_cast<jarray>(o30)));
1588 EXPECT_EQ(31, env->GetArrayLength(reinterpret_cast<jarray>(o31)));
1589 EXPECT_EQ(32, env->GetArrayLength(reinterpret_cast<jarray>(o32)));
1590 EXPECT_EQ(33, env->GetArrayLength(reinterpret_cast<jarray>(o33)));
1591 EXPECT_EQ(34, env->GetArrayLength(reinterpret_cast<jarray>(o34)));
1592 EXPECT_EQ(35, env->GetArrayLength(reinterpret_cast<jarray>(o35)));
1593 EXPECT_EQ(36, env->GetArrayLength(reinterpret_cast<jarray>(o36)));
1594 EXPECT_EQ(37, env->GetArrayLength(reinterpret_cast<jarray>(o37)));
1595 EXPECT_EQ(38, env->GetArrayLength(reinterpret_cast<jarray>(o38)));
1596 EXPECT_EQ(39, env->GetArrayLength(reinterpret_cast<jarray>(o39)));
1597 EXPECT_EQ(40, env->GetArrayLength(reinterpret_cast<jarray>(o40)));
1598 EXPECT_EQ(41, env->GetArrayLength(reinterpret_cast<jarray>(o41)));
1599 EXPECT_EQ(42, env->GetArrayLength(reinterpret_cast<jarray>(o42)));
1600 EXPECT_EQ(43, env->GetArrayLength(reinterpret_cast<jarray>(o43)));
1601 EXPECT_EQ(44, env->GetArrayLength(reinterpret_cast<jarray>(o44)));
1602 EXPECT_EQ(45, env->GetArrayLength(reinterpret_cast<jarray>(o45)));
1603 EXPECT_EQ(46, env->GetArrayLength(reinterpret_cast<jarray>(o46)));
1604 EXPECT_EQ(47, env->GetArrayLength(reinterpret_cast<jarray>(o47)));
1605 EXPECT_EQ(48, env->GetArrayLength(reinterpret_cast<jarray>(o48)));
1606 EXPECT_EQ(49, env->GetArrayLength(reinterpret_cast<jarray>(o49)));
1607 EXPECT_EQ(50, env->GetArrayLength(reinterpret_cast<jarray>(o50)));
1608 EXPECT_EQ(51, env->GetArrayLength(reinterpret_cast<jarray>(o51)));
1609 EXPECT_EQ(52, env->GetArrayLength(reinterpret_cast<jarray>(o52)));
1610 EXPECT_EQ(53, env->GetArrayLength(reinterpret_cast<jarray>(o53)));
1611 EXPECT_EQ(54, env->GetArrayLength(reinterpret_cast<jarray>(o54)));
1612 EXPECT_EQ(55, env->GetArrayLength(reinterpret_cast<jarray>(o55)));
1613 EXPECT_EQ(56, env->GetArrayLength(reinterpret_cast<jarray>(o56)));
1614 EXPECT_EQ(57, env->GetArrayLength(reinterpret_cast<jarray>(o57)));
1615 EXPECT_EQ(58, env->GetArrayLength(reinterpret_cast<jarray>(o58)));
1616 EXPECT_EQ(59, env->GetArrayLength(reinterpret_cast<jarray>(o59)));
1617 EXPECT_EQ(60, env->GetArrayLength(reinterpret_cast<jarray>(o60)));
1618 EXPECT_EQ(61, env->GetArrayLength(reinterpret_cast<jarray>(o61)));
1619 EXPECT_EQ(62, env->GetArrayLength(reinterpret_cast<jarray>(o62)));
1620 EXPECT_EQ(63, env->GetArrayLength(reinterpret_cast<jarray>(o63)));
1621 EXPECT_EQ(64, env->GetArrayLength(reinterpret_cast<jarray>(o64)));
1622 EXPECT_EQ(65, env->GetArrayLength(reinterpret_cast<jarray>(o65)));
1623 EXPECT_EQ(66, env->GetArrayLength(reinterpret_cast<jarray>(o66)));
1624 EXPECT_EQ(67, env->GetArrayLength(reinterpret_cast<jarray>(o67)));
1625 EXPECT_EQ(68, env->GetArrayLength(reinterpret_cast<jarray>(o68)));
1626 EXPECT_EQ(69, env->GetArrayLength(reinterpret_cast<jarray>(o69)));
1627 EXPECT_EQ(70, env->GetArrayLength(reinterpret_cast<jarray>(o70)));
1628 EXPECT_EQ(71, env->GetArrayLength(reinterpret_cast<jarray>(o71)));
1629 EXPECT_EQ(72, env->GetArrayLength(reinterpret_cast<jarray>(o72)));
1630 EXPECT_EQ(73, env->GetArrayLength(reinterpret_cast<jarray>(o73)));
1631 EXPECT_EQ(74, env->GetArrayLength(reinterpret_cast<jarray>(o74)));
1632 EXPECT_EQ(75, env->GetArrayLength(reinterpret_cast<jarray>(o75)));
1633 EXPECT_EQ(76, env->GetArrayLength(reinterpret_cast<jarray>(o76)));
1634 EXPECT_EQ(77, env->GetArrayLength(reinterpret_cast<jarray>(o77)));
1635 EXPECT_EQ(78, env->GetArrayLength(reinterpret_cast<jarray>(o78)));
1636 EXPECT_EQ(79, env->GetArrayLength(reinterpret_cast<jarray>(o79)));
1637 EXPECT_EQ(80, env->GetArrayLength(reinterpret_cast<jarray>(o80)));
1638 EXPECT_EQ(81, env->GetArrayLength(reinterpret_cast<jarray>(o81)));
1639 EXPECT_EQ(82, env->GetArrayLength(reinterpret_cast<jarray>(o82)));
1640 EXPECT_EQ(83, env->GetArrayLength(reinterpret_cast<jarray>(o83)));
1641 EXPECT_EQ(84, env->GetArrayLength(reinterpret_cast<jarray>(o84)));
1642 EXPECT_EQ(85, env->GetArrayLength(reinterpret_cast<jarray>(o85)));
1643 EXPECT_EQ(86, env->GetArrayLength(reinterpret_cast<jarray>(o86)));
1644 EXPECT_EQ(87, env->GetArrayLength(reinterpret_cast<jarray>(o87)));
1645 EXPECT_EQ(88, env->GetArrayLength(reinterpret_cast<jarray>(o88)));
1646 EXPECT_EQ(89, env->GetArrayLength(reinterpret_cast<jarray>(o89)));
1647 EXPECT_EQ(90, env->GetArrayLength(reinterpret_cast<jarray>(o90)));
1648 EXPECT_EQ(91, env->GetArrayLength(reinterpret_cast<jarray>(o91)));
1649 EXPECT_EQ(92, env->GetArrayLength(reinterpret_cast<jarray>(o92)));
1650 EXPECT_EQ(93, env->GetArrayLength(reinterpret_cast<jarray>(o93)));
1651 EXPECT_EQ(94, env->GetArrayLength(reinterpret_cast<jarray>(o94)));
1652 EXPECT_EQ(95, env->GetArrayLength(reinterpret_cast<jarray>(o95)));
1653 EXPECT_EQ(96, env->GetArrayLength(reinterpret_cast<jarray>(o96)));
1654 EXPECT_EQ(97, env->GetArrayLength(reinterpret_cast<jarray>(o97)));
1655 EXPECT_EQ(98, env->GetArrayLength(reinterpret_cast<jarray>(o98)));
1656 EXPECT_EQ(99, env->GetArrayLength(reinterpret_cast<jarray>(o99)));
1657 EXPECT_EQ(100, env->GetArrayLength(reinterpret_cast<jarray>(o100)));
1658 EXPECT_EQ(101, env->GetArrayLength(reinterpret_cast<jarray>(o101)));
1659 EXPECT_EQ(102, env->GetArrayLength(reinterpret_cast<jarray>(o102)));
1660 EXPECT_EQ(103, env->GetArrayLength(reinterpret_cast<jarray>(o103)));
1661 EXPECT_EQ(104, env->GetArrayLength(reinterpret_cast<jarray>(o104)));
1662 EXPECT_EQ(105, env->GetArrayLength(reinterpret_cast<jarray>(o105)));
1663 EXPECT_EQ(106, env->GetArrayLength(reinterpret_cast<jarray>(o106)));
1664 EXPECT_EQ(107, env->GetArrayLength(reinterpret_cast<jarray>(o107)));
1665 EXPECT_EQ(108, env->GetArrayLength(reinterpret_cast<jarray>(o108)));
1666 EXPECT_EQ(109, env->GetArrayLength(reinterpret_cast<jarray>(o109)));
1667 EXPECT_EQ(110, env->GetArrayLength(reinterpret_cast<jarray>(o110)));
1668 EXPECT_EQ(111, env->GetArrayLength(reinterpret_cast<jarray>(o111)));
1669 EXPECT_EQ(112, env->GetArrayLength(reinterpret_cast<jarray>(o112)));
1670 EXPECT_EQ(113, env->GetArrayLength(reinterpret_cast<jarray>(o113)));
1671 EXPECT_EQ(114, env->GetArrayLength(reinterpret_cast<jarray>(o114)));
1672 EXPECT_EQ(115, env->GetArrayLength(reinterpret_cast<jarray>(o115)));
1673 EXPECT_EQ(116, env->GetArrayLength(reinterpret_cast<jarray>(o116)));
1674 EXPECT_EQ(117, env->GetArrayLength(reinterpret_cast<jarray>(o117)));
1675 EXPECT_EQ(118, env->GetArrayLength(reinterpret_cast<jarray>(o118)));
1676 EXPECT_EQ(119, env->GetArrayLength(reinterpret_cast<jarray>(o119)));
1677 EXPECT_EQ(120, env->GetArrayLength(reinterpret_cast<jarray>(o120)));
1678 EXPECT_EQ(121, env->GetArrayLength(reinterpret_cast<jarray>(o121)));
1679 EXPECT_EQ(122, env->GetArrayLength(reinterpret_cast<jarray>(o122)));
1680 EXPECT_EQ(123, env->GetArrayLength(reinterpret_cast<jarray>(o123)));
1681 EXPECT_EQ(124, env->GetArrayLength(reinterpret_cast<jarray>(o124)));
1682 EXPECT_EQ(125, env->GetArrayLength(reinterpret_cast<jarray>(o125)));
1683 EXPECT_EQ(126, env->GetArrayLength(reinterpret_cast<jarray>(o126)));
1684 EXPECT_EQ(127, env->GetArrayLength(reinterpret_cast<jarray>(o127)));
1685 EXPECT_EQ(128, env->GetArrayLength(reinterpret_cast<jarray>(o128)));
1686 EXPECT_EQ(129, env->GetArrayLength(reinterpret_cast<jarray>(o129)));
1687 EXPECT_EQ(130, env->GetArrayLength(reinterpret_cast<jarray>(o130)));
1688 EXPECT_EQ(131, env->GetArrayLength(reinterpret_cast<jarray>(o131)));
1689 EXPECT_EQ(132, env->GetArrayLength(reinterpret_cast<jarray>(o132)));
1690 EXPECT_EQ(133, env->GetArrayLength(reinterpret_cast<jarray>(o133)));
1691 EXPECT_EQ(134, env->GetArrayLength(reinterpret_cast<jarray>(o134)));
1692 EXPECT_EQ(135, env->GetArrayLength(reinterpret_cast<jarray>(o135)));
1693 EXPECT_EQ(136, env->GetArrayLength(reinterpret_cast<jarray>(o136)));
1694 EXPECT_EQ(137, env->GetArrayLength(reinterpret_cast<jarray>(o137)));
1695 EXPECT_EQ(138, env->GetArrayLength(reinterpret_cast<jarray>(o138)));
1696 EXPECT_EQ(139, env->GetArrayLength(reinterpret_cast<jarray>(o139)));
1697 EXPECT_EQ(140, env->GetArrayLength(reinterpret_cast<jarray>(o140)));
1698 EXPECT_EQ(141, env->GetArrayLength(reinterpret_cast<jarray>(o141)));
1699 EXPECT_EQ(142, env->GetArrayLength(reinterpret_cast<jarray>(o142)));
1700 EXPECT_EQ(143, env->GetArrayLength(reinterpret_cast<jarray>(o143)));
1701 EXPECT_EQ(144, env->GetArrayLength(reinterpret_cast<jarray>(o144)));
1702 EXPECT_EQ(145, env->GetArrayLength(reinterpret_cast<jarray>(o145)));
1703 EXPECT_EQ(146, env->GetArrayLength(reinterpret_cast<jarray>(o146)));
1704 EXPECT_EQ(147, env->GetArrayLength(reinterpret_cast<jarray>(o147)));
1705 EXPECT_EQ(148, env->GetArrayLength(reinterpret_cast<jarray>(o148)));
1706 EXPECT_EQ(149, env->GetArrayLength(reinterpret_cast<jarray>(o149)));
1707 EXPECT_EQ(150, env->GetArrayLength(reinterpret_cast<jarray>(o150)));
1708 EXPECT_EQ(151, env->GetArrayLength(reinterpret_cast<jarray>(o151)));
1709 EXPECT_EQ(152, env->GetArrayLength(reinterpret_cast<jarray>(o152)));
1710 EXPECT_EQ(153, env->GetArrayLength(reinterpret_cast<jarray>(o153)));
1711 EXPECT_EQ(154, env->GetArrayLength(reinterpret_cast<jarray>(o154)));
1712 EXPECT_EQ(155, env->GetArrayLength(reinterpret_cast<jarray>(o155)));
1713 EXPECT_EQ(156, env->GetArrayLength(reinterpret_cast<jarray>(o156)));
1714 EXPECT_EQ(157, env->GetArrayLength(reinterpret_cast<jarray>(o157)));
1715 EXPECT_EQ(158, env->GetArrayLength(reinterpret_cast<jarray>(o158)));
1716 EXPECT_EQ(159, env->GetArrayLength(reinterpret_cast<jarray>(o159)));
1717 EXPECT_EQ(160, env->GetArrayLength(reinterpret_cast<jarray>(o160)));
1718 EXPECT_EQ(161, env->GetArrayLength(reinterpret_cast<jarray>(o161)));
1719 EXPECT_EQ(162, env->GetArrayLength(reinterpret_cast<jarray>(o162)));
1720 EXPECT_EQ(163, env->GetArrayLength(reinterpret_cast<jarray>(o163)));
1721 EXPECT_EQ(164, env->GetArrayLength(reinterpret_cast<jarray>(o164)));
1722 EXPECT_EQ(165, env->GetArrayLength(reinterpret_cast<jarray>(o165)));
1723 EXPECT_EQ(166, env->GetArrayLength(reinterpret_cast<jarray>(o166)));
1724 EXPECT_EQ(167, env->GetArrayLength(reinterpret_cast<jarray>(o167)));
1725 EXPECT_EQ(168, env->GetArrayLength(reinterpret_cast<jarray>(o168)));
1726 EXPECT_EQ(169, env->GetArrayLength(reinterpret_cast<jarray>(o169)));
1727 EXPECT_EQ(170, env->GetArrayLength(reinterpret_cast<jarray>(o170)));
1728 EXPECT_EQ(171, env->GetArrayLength(reinterpret_cast<jarray>(o171)));
1729 EXPECT_EQ(172, env->GetArrayLength(reinterpret_cast<jarray>(o172)));
1730 EXPECT_EQ(173, env->GetArrayLength(reinterpret_cast<jarray>(o173)));
1731 EXPECT_EQ(174, env->GetArrayLength(reinterpret_cast<jarray>(o174)));
1732 EXPECT_EQ(175, env->GetArrayLength(reinterpret_cast<jarray>(o175)));
1733 EXPECT_EQ(176, env->GetArrayLength(reinterpret_cast<jarray>(o176)));
1734 EXPECT_EQ(177, env->GetArrayLength(reinterpret_cast<jarray>(o177)));
1735 EXPECT_EQ(178, env->GetArrayLength(reinterpret_cast<jarray>(o178)));
1736 EXPECT_EQ(179, env->GetArrayLength(reinterpret_cast<jarray>(o179)));
1737 EXPECT_EQ(180, env->GetArrayLength(reinterpret_cast<jarray>(o180)));
1738 EXPECT_EQ(181, env->GetArrayLength(reinterpret_cast<jarray>(o181)));
1739 EXPECT_EQ(182, env->GetArrayLength(reinterpret_cast<jarray>(o182)));
1740 EXPECT_EQ(183, env->GetArrayLength(reinterpret_cast<jarray>(o183)));
1741 EXPECT_EQ(184, env->GetArrayLength(reinterpret_cast<jarray>(o184)));
1742 EXPECT_EQ(185, env->GetArrayLength(reinterpret_cast<jarray>(o185)));
1743 EXPECT_EQ(186, env->GetArrayLength(reinterpret_cast<jarray>(o186)));
1744 EXPECT_EQ(187, env->GetArrayLength(reinterpret_cast<jarray>(o187)));
1745 EXPECT_EQ(188, env->GetArrayLength(reinterpret_cast<jarray>(o188)));
1746 EXPECT_EQ(189, env->GetArrayLength(reinterpret_cast<jarray>(o189)));
1747 EXPECT_EQ(190, env->GetArrayLength(reinterpret_cast<jarray>(o190)));
1748 EXPECT_EQ(191, env->GetArrayLength(reinterpret_cast<jarray>(o191)));
1749 EXPECT_EQ(192, env->GetArrayLength(reinterpret_cast<jarray>(o192)));
1750 EXPECT_EQ(193, env->GetArrayLength(reinterpret_cast<jarray>(o193)));
1751 EXPECT_EQ(194, env->GetArrayLength(reinterpret_cast<jarray>(o194)));
1752 EXPECT_EQ(195, env->GetArrayLength(reinterpret_cast<jarray>(o195)));
1753 EXPECT_EQ(196, env->GetArrayLength(reinterpret_cast<jarray>(o196)));
1754 EXPECT_EQ(197, env->GetArrayLength(reinterpret_cast<jarray>(o197)));
1755 EXPECT_EQ(198, env->GetArrayLength(reinterpret_cast<jarray>(o198)));
1756 EXPECT_EQ(199, env->GetArrayLength(reinterpret_cast<jarray>(o199)));
1757 EXPECT_EQ(200, env->GetArrayLength(reinterpret_cast<jarray>(o200)));
1758 EXPECT_EQ(201, env->GetArrayLength(reinterpret_cast<jarray>(o201)));
1759 EXPECT_EQ(202, env->GetArrayLength(reinterpret_cast<jarray>(o202)));
1760 EXPECT_EQ(203, env->GetArrayLength(reinterpret_cast<jarray>(o203)));
1761 EXPECT_EQ(204, env->GetArrayLength(reinterpret_cast<jarray>(o204)));
1762 EXPECT_EQ(205, env->GetArrayLength(reinterpret_cast<jarray>(o205)));
1763 EXPECT_EQ(206, env->GetArrayLength(reinterpret_cast<jarray>(o206)));
1764 EXPECT_EQ(207, env->GetArrayLength(reinterpret_cast<jarray>(o207)));
1765 EXPECT_EQ(208, env->GetArrayLength(reinterpret_cast<jarray>(o208)));
1766 EXPECT_EQ(209, env->GetArrayLength(reinterpret_cast<jarray>(o209)));
1767 EXPECT_EQ(210, env->GetArrayLength(reinterpret_cast<jarray>(o210)));
1768 EXPECT_EQ(211, env->GetArrayLength(reinterpret_cast<jarray>(o211)));
1769 EXPECT_EQ(212, env->GetArrayLength(reinterpret_cast<jarray>(o212)));
1770 EXPECT_EQ(213, env->GetArrayLength(reinterpret_cast<jarray>(o213)));
1771 EXPECT_EQ(214, env->GetArrayLength(reinterpret_cast<jarray>(o214)));
1772 EXPECT_EQ(215, env->GetArrayLength(reinterpret_cast<jarray>(o215)));
1773 EXPECT_EQ(216, env->GetArrayLength(reinterpret_cast<jarray>(o216)));
1774 EXPECT_EQ(217, env->GetArrayLength(reinterpret_cast<jarray>(o217)));
1775 EXPECT_EQ(218, env->GetArrayLength(reinterpret_cast<jarray>(o218)));
1776 EXPECT_EQ(219, env->GetArrayLength(reinterpret_cast<jarray>(o219)));
1777 EXPECT_EQ(220, env->GetArrayLength(reinterpret_cast<jarray>(o220)));
1778 EXPECT_EQ(221, env->GetArrayLength(reinterpret_cast<jarray>(o221)));
1779 EXPECT_EQ(222, env->GetArrayLength(reinterpret_cast<jarray>(o222)));
1780 EXPECT_EQ(223, env->GetArrayLength(reinterpret_cast<jarray>(o223)));
1781 EXPECT_EQ(224, env->GetArrayLength(reinterpret_cast<jarray>(o224)));
1782 EXPECT_EQ(225, env->GetArrayLength(reinterpret_cast<jarray>(o225)));
1783 EXPECT_EQ(226, env->GetArrayLength(reinterpret_cast<jarray>(o226)));
1784 EXPECT_EQ(227, env->GetArrayLength(reinterpret_cast<jarray>(o227)));
1785 EXPECT_EQ(228, env->GetArrayLength(reinterpret_cast<jarray>(o228)));
1786 EXPECT_EQ(229, env->GetArrayLength(reinterpret_cast<jarray>(o229)));
1787 EXPECT_EQ(230, env->GetArrayLength(reinterpret_cast<jarray>(o230)));
1788 EXPECT_EQ(231, env->GetArrayLength(reinterpret_cast<jarray>(o231)));
1789 EXPECT_EQ(232, env->GetArrayLength(reinterpret_cast<jarray>(o232)));
1790 EXPECT_EQ(233, env->GetArrayLength(reinterpret_cast<jarray>(o233)));
1791 EXPECT_EQ(234, env->GetArrayLength(reinterpret_cast<jarray>(o234)));
1792 EXPECT_EQ(235, env->GetArrayLength(reinterpret_cast<jarray>(o235)));
1793 EXPECT_EQ(236, env->GetArrayLength(reinterpret_cast<jarray>(o236)));
1794 EXPECT_EQ(237, env->GetArrayLength(reinterpret_cast<jarray>(o237)));
1795 EXPECT_EQ(238, env->GetArrayLength(reinterpret_cast<jarray>(o238)));
1796 EXPECT_EQ(239, env->GetArrayLength(reinterpret_cast<jarray>(o239)));
1797 EXPECT_EQ(240, env->GetArrayLength(reinterpret_cast<jarray>(o240)));
1798 EXPECT_EQ(241, env->GetArrayLength(reinterpret_cast<jarray>(o241)));
1799 EXPECT_EQ(242, env->GetArrayLength(reinterpret_cast<jarray>(o242)));
1800 EXPECT_EQ(243, env->GetArrayLength(reinterpret_cast<jarray>(o243)));
1801 EXPECT_EQ(244, env->GetArrayLength(reinterpret_cast<jarray>(o244)));
1802 EXPECT_EQ(245, env->GetArrayLength(reinterpret_cast<jarray>(o245)));
1803 EXPECT_EQ(246, env->GetArrayLength(reinterpret_cast<jarray>(o246)));
1804 EXPECT_EQ(247, env->GetArrayLength(reinterpret_cast<jarray>(o247)));
1805 EXPECT_EQ(248, env->GetArrayLength(reinterpret_cast<jarray>(o248)));
1806 EXPECT_EQ(249, env->GetArrayLength(reinterpret_cast<jarray>(o249)));
1807 EXPECT_EQ(250, env->GetArrayLength(reinterpret_cast<jarray>(o250)));
1808 EXPECT_EQ(251, env->GetArrayLength(reinterpret_cast<jarray>(o251)));
1809 EXPECT_EQ(252, env->GetArrayLength(reinterpret_cast<jarray>(o252)));
1810 EXPECT_EQ(253, env->GetArrayLength(reinterpret_cast<jarray>(o253)));
1811 }
1812}
1813
1814const char* longSig =
1815 "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1816 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1817 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1818 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1819 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1820 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1821 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1822 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1823 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1824 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1825 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1826 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1827 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1828 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1829 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1830 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1831 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1832 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1833 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1834 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1835 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1836 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1837 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1838 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1839 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1840 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1841 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1842 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1843 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1844 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1845 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1846 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1847 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1848 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1849 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1850 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1851 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1852 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1853 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1854 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1855 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1856 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1857 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1858 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1859 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1860 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1861 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1862 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1863 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1864 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;"
1865 "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V";
1866
Andreas Gampe6e498692014-08-18 16:43:12 -07001867void JniCompilerTest::MaxParamNumberImpl() {
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001868 SetUpForTest(false, "maxParamNumber", longSig,
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001869 CURRENT_JNI_WRAPPER(Java_MyClassNatives_maxParamNumber));
Andreas Gampe7a0e5042014-03-07 13:03:19 -08001870
1871 jvalue args[254];
1872
1873 // First test: test with all arguments null.
1874 for (int i = 0; i < 254; ++i) {
1875 args[i].l = nullptr;
1876 }
1877
1878 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args);
1879
1880 // Second test: test with int[] objects with increasing lengths
1881 for (int i = 0; i < 254; ++i) {
1882 jintArray tmp = env_->NewIntArray(i);
1883 args[i].l = tmp;
1884 EXPECT_NE(args[i].l, nullptr);
1885 }
1886
1887 env_->CallNonvirtualVoidMethodA(jobj_, jklass_, jmethod_, args);
1888}
1889
Andreas Gampe6e498692014-08-18 16:43:12 -07001890JNI_TEST(MaxParamNumber)
1891
1892void JniCompilerTest::WithoutImplementationImpl() {
Andreas Gampe369810a2015-01-14 19:53:31 -08001893 // This will lead to error messages in the log.
1894 ScopedLogSeverity sls(LogSeverity::FATAL);
1895
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001896 SetUpForTest(false, "withoutImplementation", "()V", NORMAL_JNI_ONLY_NULLPTR);
Andreas Gampead615172014-04-04 16:20:13 -07001897
1898 env_->CallVoidMethod(jobj_, jmethod_);
1899
1900 EXPECT_TRUE(Thread::Current()->IsExceptionPending());
1901 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE);
1902}
1903
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001904// TODO: Don't test @FastNative here since it goes through a stub lookup (unsupported) which would
1905// normally fail with an exception, but fails with an assert.
1906JNI_TEST_NORMAL_ONLY(WithoutImplementation)
Andreas Gampe6e498692014-08-18 16:43:12 -07001907
Andreas Gampe48ee3562015-04-10 19:57:29 -07001908void JniCompilerTest::WithoutImplementationRefReturnImpl() {
1909 // This will lead to error messages in the log.
1910 ScopedLogSeverity sls(LogSeverity::FATAL);
1911
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001912 SetUpForTest(false,
1913 "withoutImplementationRefReturn",
1914 "()Ljava/lang/Object;",
1915 NORMAL_JNI_ONLY_NULLPTR);
Andreas Gampe48ee3562015-04-10 19:57:29 -07001916
1917 env_->CallObjectMethod(jobj_, jmethod_);
1918
1919 EXPECT_TRUE(Thread::Current()->IsExceptionPending());
1920 EXPECT_TRUE(env_->ExceptionCheck() == JNI_TRUE);
1921}
1922
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001923// TODO: Should work for @FastNative too.
1924JNI_TEST_NORMAL_ONLY(WithoutImplementationRefReturn)
Andreas Gampe48ee3562015-04-10 19:57:29 -07001925
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001926void Java_MyClassNatives_stackArgsIntsFirst(JNIEnv*, jclass, jint i1, jint i2, jint i3,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001927 jint i4, jint i5, jint i6, jint i7, jint i8, jint i9,
1928 jint i10, jfloat f1, jfloat f2, jfloat f3, jfloat f4,
1929 jfloat f5, jfloat f6, jfloat f7, jfloat f8, jfloat f9,
1930 jfloat f10) {
1931 EXPECT_EQ(i1, 1);
1932 EXPECT_EQ(i2, 2);
1933 EXPECT_EQ(i3, 3);
1934 EXPECT_EQ(i4, 4);
1935 EXPECT_EQ(i5, 5);
1936 EXPECT_EQ(i6, 6);
1937 EXPECT_EQ(i7, 7);
1938 EXPECT_EQ(i8, 8);
1939 EXPECT_EQ(i9, 9);
1940 EXPECT_EQ(i10, 10);
1941
Roland Levillainda4d79b2015-03-24 14:36:11 +00001942 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001943 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001944 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001945 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001946 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001947 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001948 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001949 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001950 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001951 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001952 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001953 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001954 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001955 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001956 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001957 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001958 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001959 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00001960 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001961 EXPECT_EQ(i20, 20);
1962}
1963
Andreas Gampe6e498692014-08-18 16:43:12 -07001964void JniCompilerTest::StackArgsIntsFirstImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001965 SetUpForTest(true, "stackArgsIntsFirst", "(IIIIIIIIIIFFFFFFFFFF)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001966 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsIntsFirst));
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001967
1968 jint i1 = 1;
1969 jint i2 = 2;
1970 jint i3 = 3;
1971 jint i4 = 4;
1972 jint i5 = 5;
1973 jint i6 = 6;
1974 jint i7 = 7;
1975 jint i8 = 8;
1976 jint i9 = 9;
1977 jint i10 = 10;
1978
Roland Levillainda4d79b2015-03-24 14:36:11 +00001979 jfloat f1 = bit_cast<jfloat, jint>(11);
1980 jfloat f2 = bit_cast<jfloat, jint>(12);
1981 jfloat f3 = bit_cast<jfloat, jint>(13);
1982 jfloat f4 = bit_cast<jfloat, jint>(14);
1983 jfloat f5 = bit_cast<jfloat, jint>(15);
1984 jfloat f6 = bit_cast<jfloat, jint>(16);
1985 jfloat f7 = bit_cast<jfloat, jint>(17);
1986 jfloat f8 = bit_cast<jfloat, jint>(18);
1987 jfloat f9 = bit_cast<jfloat, jint>(19);
1988 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001989
1990 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, f1, f2,
1991 f3, f4, f5, f6, f7, f8, f9, f10);
1992}
1993
Igor Murashkin367f3dd2016-09-01 17:00:24 -07001994JNI_TEST_CRITICAL(StackArgsIntsFirst)
Andreas Gampe6e498692014-08-18 16:43:12 -07001995
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001996void Java_MyClassNatives_stackArgsFloatsFirst(JNIEnv*, jclass, jfloat f1, jfloat f2,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07001997 jfloat f3, jfloat f4, jfloat f5, jfloat f6, jfloat f7,
1998 jfloat f8, jfloat f9, jfloat f10, jint i1, jint i2,
1999 jint i3, jint i4, jint i5, jint i6, jint i7, jint i8,
2000 jint i9, jint i10) {
2001 EXPECT_EQ(i1, 1);
2002 EXPECT_EQ(i2, 2);
2003 EXPECT_EQ(i3, 3);
2004 EXPECT_EQ(i4, 4);
2005 EXPECT_EQ(i5, 5);
2006 EXPECT_EQ(i6, 6);
2007 EXPECT_EQ(i7, 7);
2008 EXPECT_EQ(i8, 8);
2009 EXPECT_EQ(i9, 9);
2010 EXPECT_EQ(i10, 10);
2011
Roland Levillainda4d79b2015-03-24 14:36:11 +00002012 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002013 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002014 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002015 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002016 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002017 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002018 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002019 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002020 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002021 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002022 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002023 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002024 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002025 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002026 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002027 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002028 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002029 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002030 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002031 EXPECT_EQ(i20, 20);
2032}
2033
Andreas Gampe6e498692014-08-18 16:43:12 -07002034void JniCompilerTest::StackArgsFloatsFirstImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002035 SetUpForTest(true, "stackArgsFloatsFirst", "(FFFFFFFFFFIIIIIIIIII)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002036 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsFloatsFirst));
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002037
2038 jint i1 = 1;
2039 jint i2 = 2;
2040 jint i3 = 3;
2041 jint i4 = 4;
2042 jint i5 = 5;
2043 jint i6 = 6;
2044 jint i7 = 7;
2045 jint i8 = 8;
2046 jint i9 = 9;
2047 jint i10 = 10;
2048
Roland Levillainda4d79b2015-03-24 14:36:11 +00002049 jfloat f1 = bit_cast<jfloat, jint>(11);
2050 jfloat f2 = bit_cast<jfloat, jint>(12);
2051 jfloat f3 = bit_cast<jfloat, jint>(13);
2052 jfloat f4 = bit_cast<jfloat, jint>(14);
2053 jfloat f5 = bit_cast<jfloat, jint>(15);
2054 jfloat f6 = bit_cast<jfloat, jint>(16);
2055 jfloat f7 = bit_cast<jfloat, jint>(17);
2056 jfloat f8 = bit_cast<jfloat, jint>(18);
2057 jfloat f9 = bit_cast<jfloat, jint>(19);
2058 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002059
2060 env_->CallStaticVoidMethod(jklass_, jmethod_, f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, i1, i2, i3,
2061 i4, i5, i6, i7, i8, i9, i10);
2062}
2063
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002064JNI_TEST_CRITICAL(StackArgsFloatsFirst)
Andreas Gampe6e498692014-08-18 16:43:12 -07002065
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002066void Java_MyClassNatives_stackArgsMixed(JNIEnv*, jclass, jint i1, jfloat f1, jint i2,
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002067 jfloat f2, jint i3, jfloat f3, jint i4, jfloat f4, jint i5,
2068 jfloat f5, jint i6, jfloat f6, jint i7, jfloat f7, jint i8,
2069 jfloat f8, jint i9, jfloat f9, jint i10, jfloat f10) {
2070 EXPECT_EQ(i1, 1);
2071 EXPECT_EQ(i2, 2);
2072 EXPECT_EQ(i3, 3);
2073 EXPECT_EQ(i4, 4);
2074 EXPECT_EQ(i5, 5);
2075 EXPECT_EQ(i6, 6);
2076 EXPECT_EQ(i7, 7);
2077 EXPECT_EQ(i8, 8);
2078 EXPECT_EQ(i9, 9);
2079 EXPECT_EQ(i10, 10);
2080
Roland Levillainda4d79b2015-03-24 14:36:11 +00002081 jint i11 = bit_cast<jint, jfloat>(f1);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002082 EXPECT_EQ(i11, 11);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002083 jint i12 = bit_cast<jint, jfloat>(f2);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002084 EXPECT_EQ(i12, 12);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002085 jint i13 = bit_cast<jint, jfloat>(f3);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002086 EXPECT_EQ(i13, 13);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002087 jint i14 = bit_cast<jint, jfloat>(f4);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002088 EXPECT_EQ(i14, 14);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002089 jint i15 = bit_cast<jint, jfloat>(f5);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002090 EXPECT_EQ(i15, 15);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002091 jint i16 = bit_cast<jint, jfloat>(f6);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002092 EXPECT_EQ(i16, 16);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002093 jint i17 = bit_cast<jint, jfloat>(f7);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002094 EXPECT_EQ(i17, 17);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002095 jint i18 = bit_cast<jint, jfloat>(f8);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002096 EXPECT_EQ(i18, 18);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002097 jint i19 = bit_cast<jint, jfloat>(f9);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002098 EXPECT_EQ(i19, 19);
Roland Levillainda4d79b2015-03-24 14:36:11 +00002099 jint i20 = bit_cast<jint, jfloat>(f10);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002100 EXPECT_EQ(i20, 20);
2101}
2102
Andreas Gampe6e498692014-08-18 16:43:12 -07002103void JniCompilerTest::StackArgsMixedImpl() {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002104 SetUpForTest(true, "stackArgsMixed", "(IFIFIFIFIFIFIFIFIFIF)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002105 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsMixed));
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002106
2107 jint i1 = 1;
2108 jint i2 = 2;
2109 jint i3 = 3;
2110 jint i4 = 4;
2111 jint i5 = 5;
2112 jint i6 = 6;
2113 jint i7 = 7;
2114 jint i8 = 8;
2115 jint i9 = 9;
2116 jint i10 = 10;
2117
Roland Levillainda4d79b2015-03-24 14:36:11 +00002118 jfloat f1 = bit_cast<jfloat, jint>(11);
2119 jfloat f2 = bit_cast<jfloat, jint>(12);
2120 jfloat f3 = bit_cast<jfloat, jint>(13);
2121 jfloat f4 = bit_cast<jfloat, jint>(14);
2122 jfloat f5 = bit_cast<jfloat, jint>(15);
2123 jfloat f6 = bit_cast<jfloat, jint>(16);
2124 jfloat f7 = bit_cast<jfloat, jint>(17);
2125 jfloat f8 = bit_cast<jfloat, jint>(18);
2126 jfloat f9 = bit_cast<jfloat, jint>(19);
2127 jfloat f10 = bit_cast<jfloat, jint>(20);
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +07002128
2129 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, f1, i2, f2, i3, f3, i4, f4, i5, f5, i6, f6, i7,
2130 f7, i8, f8, i9, f9, i10, f10);
2131}
2132
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002133JNI_TEST_CRITICAL(StackArgsMixed)
Andreas Gampe6e498692014-08-18 16:43:12 -07002134
Lazar Trsicf652d602015-06-24 16:30:21 +02002135void Java_MyClassNatives_stackArgsSignExtendedMips64(JNIEnv*, jclass, jint i1, jint i2, jint i3,
2136 jint i4, jint i5, jint i6, jint i7, jint i8) {
2137 EXPECT_EQ(i1, 1);
2138 EXPECT_EQ(i2, 2);
2139 EXPECT_EQ(i3, 3);
2140 EXPECT_EQ(i4, 4);
2141 EXPECT_EQ(i5, 5);
2142 EXPECT_EQ(i6, 6);
2143 EXPECT_EQ(i7, 7);
2144 EXPECT_EQ(i8, -8);
2145
2146#if defined(__mips__) && defined(__LP64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2147 // Mips64 ABI requires that arguments passed through stack be sign-extended 8B slots.
2148 // First 8 arguments are passed through registers, check i7 and i8.
2149 uint32_t stack1_high = *(&i7 + 1);
2150 uint32_t stack2_high = *(&i8 + 1);
2151
2152 EXPECT_EQ(stack1_high, static_cast<uint32_t>(0));
2153 EXPECT_EQ(stack2_high, static_cast<uint32_t>(0xffffffff));
2154#else
2155 LOG(INFO) << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on "
2156 << kRuntimeISA;
2157 // Force-print to std::cout so it's also outside the logcat.
2158 std::cout << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on "
2159 << kRuntimeISA << std::endl;
2160#endif
2161}
2162
2163void JniCompilerTest::StackArgsSignExtendedMips64Impl() {
2164 SetUpForTest(true, "stackArgsSignExtendedMips64", "(IIIIIIII)V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002165 CURRENT_JNI_WRAPPER(Java_MyClassNatives_stackArgsSignExtendedMips64));
Lazar Trsicf652d602015-06-24 16:30:21 +02002166 jint i1 = 1;
2167 jint i2 = 2;
2168 jint i3 = 3;
2169 jint i4 = 4;
2170 jint i5 = 5;
2171 jint i6 = 6;
2172 jint i7 = 7;
2173 jint i8 = -8;
2174
2175 env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8);
2176}
2177
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002178JNI_TEST_CRITICAL(StackArgsSignExtendedMips64)
Lazar Trsicf652d602015-06-24 16:30:21 +02002179
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002180void Java_MyClassNatives_normalNative(JNIEnv*, jclass) {
2181 // Intentionally left empty.
2182}
2183
2184// Methods not annotated with anything are not considered "fast native"
2185// -- Check that the annotation lookup does not find it.
2186void JniCompilerTest::NormalNativeImpl() {
2187 SetUpForTest(/* direct */ true,
2188 "normalNative",
2189 "()V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002190 CURRENT_JNI_WRAPPER(Java_MyClassNatives_normalNative));
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002191
2192 ScopedObjectAccess soa(Thread::Current());
2193 ArtMethod* method = soa.DecodeMethod(jmethod_);
2194 ASSERT_TRUE(method != nullptr);
2195
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002196 EXPECT_FALSE(method->IsAnnotatedWithCriticalNative());
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002197 EXPECT_FALSE(method->IsAnnotatedWithFastNative());
2198}
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002199
2200// TODO: just rename the java functions to the standard convention and remove duplicated tests
2201JNI_TEST_NORMAL_ONLY(NormalNative)
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002202
2203// Methods annotated with @FastNative are considered "fast native"
2204// -- Check that the annotation lookup succeeds.
2205void Java_MyClassNatives_fastNative(JNIEnv*, jclass) {
2206 // Intentionally left empty.
2207}
2208
2209void JniCompilerTest::FastNativeImpl() {
2210 SetUpForTest(/* direct */ true,
2211 "fastNative",
2212 "()V",
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002213 CURRENT_JNI_WRAPPER(Java_MyClassNatives_fastNative));
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002214
2215 ScopedObjectAccess soa(Thread::Current());
2216 ArtMethod* method = soa.DecodeMethod(jmethod_);
2217 ASSERT_TRUE(method != nullptr);
2218
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002219 EXPECT_FALSE(method->IsAnnotatedWithCriticalNative());
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002220 EXPECT_TRUE(method->IsAnnotatedWithFastNative());
2221}
Igor Murashkin367f3dd2016-09-01 17:00:24 -07002222
2223// TODO: just rename the java functions to the standard convention and remove duplicated tests
2224JNI_TEST_NORMAL_ONLY(FastNative)
2225
2226int gJava_myClassNatives_criticalNative_calls[kJniKindCount] = {};
2227// Methods annotated with @CriticalNative are considered "critical native"
2228// -- Check that the annotation lookup succeeds.
2229void Java_MyClassNatives_criticalNative() {
2230 gJava_myClassNatives_criticalNative_calls[gCurrentJni]++;
2231}
2232
2233void JniCompilerTest::CriticalNativeImpl() {
2234 SetUpForTest(/* direct */ true,
2235 // Important: Don't change the "current jni" yet to avoid a method name suffix.
2236 "criticalNative",
2237 "()V",
2238 // TODO: Use CURRENT_JNI_WRAPPER instead which is more generic.
2239 reinterpret_cast<void*>(&Java_MyClassNatives_criticalNative));
2240
2241 // TODO: remove this manual updating of the current JNI. Merge with the other tests.
2242 UpdateCurrentJni(JniKind::kCritical);
2243 ASSERT_TRUE(IsCurrentJniCritical());
2244
2245 ScopedObjectAccess soa(Thread::Current());
2246 ArtMethod* method = soa.DecodeMethod(jmethod_);
2247 ASSERT_TRUE(method != nullptr);
2248
2249 EXPECT_TRUE(method->IsAnnotatedWithCriticalNative());
2250 EXPECT_FALSE(method->IsAnnotatedWithFastNative());
2251
2252 EXPECT_EQ(0, gJava_myClassNatives_criticalNative_calls[gCurrentJni]);
2253 env_->CallStaticVoidMethod(jklass_, jmethod_);
2254 EXPECT_EQ(1, gJava_myClassNatives_criticalNative_calls[gCurrentJni]);
2255
2256 gJava_myClassNatives_criticalNative_calls[gCurrentJni] = 0;
2257}
2258
2259// TODO: just rename the java functions to the standard convention and remove duplicated tests
2260JNI_TEST_NORMAL_ONLY(CriticalNative)
Igor Murashkin9d4b6da2016-07-29 09:51:58 -07002261
Ian Rogersb033c752011-07-20 12:22:35 -07002262} // namespace art