Permalink
Browse files

implement JNIEnv::NewLocalRef

  • Loading branch information...
1 parent 1094483 commit b75497c8ffbfae5eed0c1372530d8c412cb4feff @dicej dicej committed Dec 20, 2012
Showing with 21 additions and 0 deletions.
  1. +9 −0 src/jnienv.cpp
  2. +6 −0 test/JNI.java
  3. +6 −0 test/jni.cpp
View
@@ -396,6 +396,14 @@ Throw(Thread* t, jthrowable throwable)
return 0;
}
+jobject JNICALL
+NewLocalRef(Thread* t, jobject o)
+{
+ ENTER(t, Thread::ActiveState);
+
+ return makeLocalReference(t, *o);
+}
+
void JNICALL
DeleteLocalRef(Thread* t, jobject r)
{
@@ -3513,6 +3521,7 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable)
envTable->NewDirectByteBuffer = local::NewDirectByteBuffer;
envTable->GetDirectBufferAddress = local::GetDirectBufferAddress;
envTable->GetDirectBufferCapacity = local::GetDirectBufferCapacity;
+ envTable->NewLocalRef = local::NewLocalRef;
envTable->DeleteLocalRef = local::DeleteLocalRef;
envTable->GetObjectClass = local::GetObjectClass;
envTable->GetSuperclass = local::GetSuperclass;
View
@@ -57,6 +57,8 @@ private static native Field toReflectedField(Class c, long id,
private static native int getStaticIntField(Class c, long id);
+ private static native Object testLocalRef(Object o);
+
public static int method242() { return 242; }
public static final int field950 = 950;
@@ -106,5 +108,9 @@ public static void main(String[] args) throws Exception {
(JNI.class, fromReflectedField
(JNI.class.getField("field950")), true)
.getName().equals("field950"));
+
+ { Object o = new Object();
+ expect(testLocalRef(o) == o);
+ }
}
}
View
@@ -102,6 +102,12 @@ Java_JNI_getStaticIntField(JNIEnv* e, jclass, jclass c, jlong id)
}
extern "C" JNIEXPORT jobject JNICALL
+Java_JNI_testLocalRef(JNIEnv* e, jclass, jobject o)
+{
+ return e->NewLocalRef(o);
+}
+
+extern "C" JNIEXPORT jobject JNICALL
Java_Buffers_allocateNative(JNIEnv* e, jclass, jint capacity)
{
void* p = allocate(e, capacity);

0 comments on commit b75497c

Please sign in to comment.