* tests/gc/NativeGlobalRef.java: Added testcase for global references.
authormichi <none@none>
Fri, 30 Mar 2007 00:20:05 +0000 (00:20 +0000)
committermichi <none@none>
Fri, 30 Mar 2007 00:20:05 +0000 (00:20 +0000)
* tests/gc/native.c: Added native library for all testcases.
* tests/gc/Makefile: Added for easy handling of native testcases.

--HG--
branch : exact-gc

tests/gc/Makefile [new file with mode: 0644]
tests/gc/NativeGlobalRef.java [new file with mode: 0644]
tests/gc/native.c [new file with mode: 0644]

diff --git a/tests/gc/Makefile b/tests/gc/Makefile
new file mode 100644 (file)
index 0000000..ac126fe
--- /dev/null
@@ -0,0 +1,9 @@
+CC=gcc
+JAVAC=javac
+
+all:
+       $(JAVAC) NativeGlobalRef.java
+       $(CC) -shared -O2 native.c -o libnative.so -fPIC
+
+clean:
+       rm -rf NativeGlobalRef.class libnative.so
diff --git a/tests/gc/NativeGlobalRef.java b/tests/gc/NativeGlobalRef.java
new file mode 100644 (file)
index 0000000..1ee8949
--- /dev/null
@@ -0,0 +1,32 @@
+public class NativeGlobalRef {
+       public native static void setReference(Object o);
+       public native static Object getReference();
+
+       public static void main(String args[]) {
+               Object o;
+               System.loadLibrary("native");
+
+               /* create the object we want to deal with */
+               o = new String("I am an important object, don't forget me!");
+               //String s = "";
+               //for (int i=0; i<100; i++)
+               //      s = s + "I am an important object, don't forget me!";
+               //o = s;
+               //s = null;
+
+               /* pass the object to the native world */
+               setReference(o);
+
+               /* now forget about it and see if it gets collected */
+               o = null;
+               System.gc();
+
+               /* fill up the heap */
+               //for (long i=0; i<100000000l; i++)
+               //      o = new String("I am simply an heap filler!");
+
+               /* is the object still there? */
+               o = getReference();
+               System.out.println(o);
+       }
+}
diff --git a/tests/gc/native.c b/tests/gc/native.c
new file mode 100644 (file)
index 0000000..cc0a0e6
--- /dev/null
@@ -0,0 +1,21 @@
+#include <jni.h>
+#include <stdio.h>
+
+static jobject ref = NULL;
+
+JNIEXPORT void JNICALL Java_NativeGlobalRef_setReference(JNIEnv *env, jclass c, jobject o)
+{
+       printf("Native-World: setReference()\n");
+
+       //ref = o;
+       ref = (*env)->NewGlobalRef(env, o);
+
+       return;
+}
+
+JNIEXPORT jobject JNICALL Java_NativeGlobalRef_getReference(JNIEnv *env, jclass c)
+{
+       printf("Native-World: getReference()\n");
+
+       return ref;
+}