From 559b1cc279deb9299414ddd46595bb8bca7fa090 Mon Sep 17 00:00:00 2001 From: Lazar Trsic Date: Wed, 24 Jun 2015 16:30:21 +0200 Subject: [MIPS64] JNI Compiler: Sign-extend int function arguments MIPS n64 ABI differs from arm64. Arguments smaller than the 8B stack slot need to be sign-extended. Use combination (lw,sd), instead of (lw,sw) for 4B values. Change fixes software keyboard crash on mips64. Bug: 21555893 (cherry picked from commit f652d605753f1387e7797461b47116c5dcdf928d) Change-Id: I7574d37f6039e9e8c9e0047254be71d28d4c829a --- compiler/jni/jni_compiler_test.cc | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'compiler/jni') diff --git a/compiler/jni/jni_compiler_test.cc b/compiler/jni/jni_compiler_test.cc index e98e5724d0..f3bda2fa72 100644 --- a/compiler/jni/jni_compiler_test.cc +++ b/compiler/jni/jni_compiler_test.cc @@ -165,6 +165,7 @@ class JniCompilerTest : public CommonCompilerTest { void StackArgsIntsFirstImpl(); void StackArgsFloatsFirstImpl(); void StackArgsMixedImpl(); + void StackArgsSignExtendedMips64Impl(); JNIEnv* env_; jmethodID jmethod_; @@ -1715,4 +1716,49 @@ void JniCompilerTest::StackArgsMixedImpl() { JNI_TEST(StackArgsMixed) +void Java_MyClassNatives_stackArgsSignExtendedMips64(JNIEnv*, jclass, jint i1, jint i2, jint i3, + jint i4, jint i5, jint i6, jint i7, jint i8) { + EXPECT_EQ(i1, 1); + EXPECT_EQ(i2, 2); + EXPECT_EQ(i3, 3); + EXPECT_EQ(i4, 4); + EXPECT_EQ(i5, 5); + EXPECT_EQ(i6, 6); + EXPECT_EQ(i7, 7); + EXPECT_EQ(i8, -8); + +#if defined(__mips__) && defined(__LP64__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + // Mips64 ABI requires that arguments passed through stack be sign-extended 8B slots. + // First 8 arguments are passed through registers, check i7 and i8. + uint32_t stack1_high = *(&i7 + 1); + uint32_t stack2_high = *(&i8 + 1); + + EXPECT_EQ(stack1_high, static_cast(0)); + EXPECT_EQ(stack2_high, static_cast(0xffffffff)); +#else + LOG(INFO) << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on " + << kRuntimeISA; + // Force-print to std::cout so it's also outside the logcat. + std::cout << "Skipping stackArgsSignExtendedMips64 as there is nothing to be done on " + << kRuntimeISA << std::endl; +#endif +} + +void JniCompilerTest::StackArgsSignExtendedMips64Impl() { + SetUpForTest(true, "stackArgsSignExtendedMips64", "(IIIIIIII)V", + reinterpret_cast(&Java_MyClassNatives_stackArgsSignExtendedMips64)); + jint i1 = 1; + jint i2 = 2; + jint i3 = 3; + jint i4 = 4; + jint i5 = 5; + jint i6 = 6; + jint i7 = 7; + jint i8 = -8; + + env_->CallStaticVoidMethod(jklass_, jmethod_, i1, i2, i3, i4, i5, i6, i7, i8); +} + +JNI_TEST(StackArgsSignExtendedMips64) + } // namespace art -- cgit v1.2.3