From 7e1debef4495c0eaef53d2a4ce9c9db3334add07 Mon Sep 17 00:00:00 2001 From: tarotanaka0 Date: Thu, 4 Jun 2015 16:02:29 +0900 Subject: [PATCH 1/2] fix JNI stack alignment --- src/avian/arm.h | 4 ++-- test/JNI.java | 21 +++++++++++++++++++++ test/jni.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/avian/arm.h b/src/avian/arm.h index 98f60d1ed0..4a0797207b 100644 --- a/src/avian/arm.h +++ b/src/avian/arm.h @@ -388,11 +388,11 @@ inline uint64_t dynamicCall(void* function, vfpIndex = VfpCount; } - unsigned stackSize = pad(stackIndex * BytesPerWord, 16); + unsigned stackSize = pad(stackIndex * BytesPerWord + stackSubIndex, 16); return vmNativeCall(function, stackSize, RUNTIME_ARRAY_BODY(stack), - stackIndex * BytesPerWord, + pad(stackIndex * BytesPerWord + stackSubIndex, BytesPerWord), (gprIndex ? gprTable : 0), (vfpIndex ? vfpTable : 0), returnType); diff --git a/test/JNI.java b/test/JNI.java index a7fb40c62d..b0583b6606 100644 --- a/test/JNI.java +++ b/test/JNI.java @@ -43,6 +43,21 @@ public class JNI { float a13, float a14, float a15, double a16, float a17, float a18, float a19, float a20); + private static native int addStackBoundary2 + (Object o1, Object o2, Object o3, int i1, int i2); + + private static native int addStackBoundary3 + (Object o1, Object o2, Object o3, int i1, int i2, int i3); + + private static native int addStackBoundary4 + (Object o1, Object o2, Object o3, int i1, int i2, int i3, int i4); + + private static native int addStackBoundary5 + (Object o1, Object o2, Object o3, int i1, int i2, int i3, int i4, int i5); + + private static native int addStackBoundary6 + (Object o1, Object o2, Object o3, int i1, int i2, int i3, int i4, int i5, int i6); + private static native long fromReflectedMethod(Object m); private static native Object toReflectedMethod(Class c, long id, @@ -83,6 +98,12 @@ public class JNI { 12.0f, 13.0f, 14.0f, 15.0f, 16.0d, 17.0f, 18.0f, 19.0f, 20.0f) == 210.0d); + expect(addStackBoundary2(null, null, null, 1, 10) == 11); + expect(addStackBoundary3(null, null, null, 1, 10, 100) == 111); + expect(addStackBoundary4(null, null, null, 1, 10, 100, 1000) == 1111); + expect(addStackBoundary5(null, null, null, 1, 10, 100, 1000, 10000) == 11111); + expect(addStackBoundary6(null, null, null, 1, 10, 100, 1000, 10000, 100000) == 111111); + expect(doEcho(42.0f) == 42.0f); expect(doEcho(42.0d) == 42.0d); diff --git a/test/jni.cpp b/test/jni.cpp index 70d5b63ed3..76131dbe2b 100644 --- a/test/jni.cpp +++ b/test/jni.cpp @@ -100,6 +100,41 @@ extern "C" JNIEXPORT jdouble JNICALL Java_JNI_addMix(JNIEnv*, + a14 + a15 + a16 + a17 + a18 + a19 + a20; } +extern "C" JNIEXPORT jint JNICALL + Java_JNI_addStackBoundary2(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + jint i1, jint i2) +{ + return i1 + i2; +} + +extern "C" JNIEXPORT jint JNICALL + Java_JNI_addStackBoundary3(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + jint i1, jint i2, jint i3) +{ + return i1 + i2 + i3; +} + +extern "C" JNIEXPORT jint JNICALL + Java_JNI_addStackBoundary4(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + jint i1, jint i2, jint i3, jint i4) +{ + return i1 + i2 + i3 + i4; +} + +extern "C" JNIEXPORT jint JNICALL + Java_JNI_addStackBoundary5(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + jint i1, jint i2, jint i3, jint i4, jint i5) +{ + return i1 + i2 + i3 + i4 + i5; +} + +extern "C" JNIEXPORT jint JNICALL + Java_JNI_addStackBoundary6(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + jint i1, jint i2, jint i3, jint i4, jint i5, jint i6) +{ + return i1 + i2 + i3 + i4 + i5 + i6; +} + extern "C" JNIEXPORT jfloat JNICALL Java_JNI_doEcho__F(JNIEnv* e, jclass c, jfloat f) { From 85463c693eaf3e6d71ecfdf3bb187f9f0f8518ab Mon Sep 17 00:00:00 2001 From: tarotanaka0 Date: Thu, 4 Jun 2015 23:01:19 +0900 Subject: [PATCH 2/2] fix for -Wunused-parameters --- test/jni.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/jni.cpp b/test/jni.cpp index 76131dbe2b..18e418ab92 100644 --- a/test/jni.cpp +++ b/test/jni.cpp @@ -101,35 +101,35 @@ extern "C" JNIEXPORT jdouble JNICALL Java_JNI_addMix(JNIEnv*, } extern "C" JNIEXPORT jint JNICALL - Java_JNI_addStackBoundary2(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + Java_JNI_addStackBoundary2(JNIEnv*, jclass, jobject, jobject, jobject, jint i1, jint i2) { return i1 + i2; } extern "C" JNIEXPORT jint JNICALL - Java_JNI_addStackBoundary3(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + Java_JNI_addStackBoundary3(JNIEnv*, jclass, jobject, jobject, jobject, jint i1, jint i2, jint i3) { return i1 + i2 + i3; } extern "C" JNIEXPORT jint JNICALL - Java_JNI_addStackBoundary4(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + Java_JNI_addStackBoundary4(JNIEnv*, jclass, jobject, jobject, jobject, jint i1, jint i2, jint i3, jint i4) { return i1 + i2 + i3 + i4; } extern "C" JNIEXPORT jint JNICALL - Java_JNI_addStackBoundary5(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + Java_JNI_addStackBoundary5(JNIEnv*, jclass, jobject, jobject, jobject, jint i1, jint i2, jint i3, jint i4, jint i5) { return i1 + i2 + i3 + i4 + i5; } extern "C" JNIEXPORT jint JNICALL - Java_JNI_addStackBoundary6(JNIEnv* e, jclass c, jobject o1, jobject o2, jobject o3, + Java_JNI_addStackBoundary6(JNIEnv*, jclass, jobject, jobject, jobject, jint i1, jint i2, jint i3, jint i4, jint i5, jint i6) { return i1 + i2 + i3 + i4 + i5 + i6;