Patch review request - Test bug 7123972 test/java/lang/annotation/loaderLeak/Main.java fails intermittently

Eric Wang yiming.wang at oracle.com
Thu Jun 21 06:05:11 UTC 2012


Hi All,

I come from Java SQE team who are interested in regression test bug fix. 
Here is the first simple fix for bug 7123972 
<http://monaco.us.oracle.com/detail.jsf?cr=7123972>, Can you please help 
to review and comment? Attachment is the patch Thanks!

This bug is caused by wrong assumption that the GC is started 
immediately to recycle un-referenced objects after System.gc() called 
one or two times.

The proposed solution is to make sure the un-referenced object is 
recycled by GC before checking if the reference is null.

Regards,
Eric
-------------- next part --------------
--- old/test/java/lang/annotation/loaderLeak/Main.java	2012-06-21 11:30:28.242617920 +0800
+++ new/test/java/lang/annotation/loaderLeak/Main.java	2012-06-21 11:30:26.828522968 +0800
@@ -36,6 +36,8 @@
 import java.io.*;
 
 public class Main {
+    static volatile boolean GCIndicator = false;
+    
     public static void main(String[] args) throws Exception {
         for (int i=0; i<100; i++)
             doTest(args.length != 0);
@@ -57,8 +59,10 @@
         System.gc();
         System.gc();
         loader = null;
-        System.gc();
-        System.gc();
+        while(false == GCIndicator) {
+            System.gc();
+            Thread.sleep(5);
+        }
         if (c.get() != null) throw new AssertionError();
     }
 }
@@ -67,6 +71,7 @@
     private Hashtable classes = new Hashtable();
 
     public SimpleClassLoader() {
+        Main.GCIndicator = false;
     }
     private byte getClassImplFromDataBase(String className)[] {
         byte result[];
@@ -124,4 +129,8 @@
         classes.put(className, result);
         return result;
     }
+    
+    protected void finalize() {
+        Main.GCIndicator = true;
+    }
 }


More information about the core-libs-dev mailing list