Merged with tip.
[cacao.git] / tests / gc / NativeGlobalRef.java
1 public class NativeGlobalRef {
2         public native static void setReference(Object o);
3         public native static Object getReference();
4         public native static void delReference();
5
6         public static void main(String args[]) {
7                 Object o;
8                 System.loadLibrary("native");
9
10                 /* create the object we want to deal with */
11                 o = new String("I am an important object, don't forget me!");
12                 //String s = "";
13                 //for (int i=0; i<100; i++)
14                 //      s = s + "I am an important object, don't forget me!";
15                 //o = s;
16                 //s = null;
17
18                 /* pass the object to the native world */
19                 setReference(o);
20
21                 /* now forget about it and see if it gets collected */
22                 o = null;
23                 System.gc();
24
25                 /* fill up the heap */
26                 //for (long i=0; i<100000000l; i++)
27                 //      o = new String("I am simply an heap filler!");
28
29                 /* is the object still there? */
30                 o = getReference();
31                 System.out.println(o);
32
33                 /* delete the reference inside the native world */
34                 delReference();
35         }
36 }