Merge "Test invocation of static methods through JNI stub" into dalvik-dev
diff --git a/src/jni_compiler_test.cc b/src/jni_compiler_test.cc
index cf70685..2166d37 100644
--- a/src/jni_compiler_test.cc
+++ b/src/jni_compiler_test.cc
@@ -36,6 +36,11 @@
return count + 1;
}
+extern "C"
+JNIEXPORT jint JNICALL Java_MyClass_sbar(JNIEnv* env, jclass myClass, jint count) {
+ return count + 1;
+}
+
namespace art {
class JniCompilerTest : public CommonTest {
@@ -128,7 +133,7 @@
TEST_F(JniCompilerTest, CompileAndRunIntMethodThroughStub) {
SirtRef<ClassLoader> class_loader(LoadDex("MyClassNatives"));
SetupForTest(class_loader.get(), false, "bar", "(I)I",
- NULL /* calling through stub will load &Java_MyClass_bar */);
+ NULL /* calling through stub will link with &Java_MyClass_bar */);
std::string reason;
ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary("", class_loader.get(), reason))
@@ -138,6 +143,19 @@
EXPECT_EQ(25, result);
}
+TEST_F(JniCompilerTest, CompileAndRunStaticIntMethodThroughStub) {
+ SirtRef<ClassLoader> class_loader(LoadDex("MyClassNatives"));
+ SetupForTest(class_loader.get(), true, "sbar", "(I)I",
+ NULL /* calling through stub will link with &Java_MyClass_sbar */);
+
+ std::string reason;
+ ASSERT_TRUE(Runtime::Current()->GetJavaVM()->LoadNativeLibrary("", class_loader.get(), reason))
+ << reason;
+
+ jint result = env_->CallStaticIntMethod(jklass_, jmethod_, 42);
+ EXPECT_EQ(43, result);
+}
+
int gJava_MyClass_fooI_calls = 0;
jint Java_MyClass_fooI(JNIEnv* env, jobject thisObj, jint x) {
// 2 = SirtRef<ClassLoader> + thisObj
diff --git a/test/MyClassNatives/MyClassNatives.java b/test/MyClassNatives/MyClassNatives.java
index d8df19b..55ec0bd 100644
--- a/test/MyClassNatives/MyClassNatives.java
+++ b/test/MyClassNatives/MyClassNatives.java
@@ -18,6 +18,7 @@
native void throwException();
native void foo();
native int bar(int count);
+ static native int sbar(int count);
native int fooI(int x);
native int fooII(int x, int y);
native long fooJJ(long x, long y);