Hi David,

Thanks for your review, I have updated the code by following your suggestion. please see the attachment. I'm not sure whether there's a better way to guarantee object finalized by GC definitely within the given time. The proposed fix may work in most cases but may still throw InterruptException if execution is timeout (2 minutes of JTreg by default).

Regards,
Eric

On 2012/6/21 14:32, David Holmes wrote:
Hi Eric,

On 21/06/2012 4:05 PM, Eric Wang wrote:
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.

Your patch makes its own assumptions - specifically that finalization must eventually run. At a minimum you should add System.runFinalization() calls after the System.gc() inside the loop. Even that is no guarantee in a general sense, though it should work for hotspot.

David


Regards,
Eric

--- old/test/java/lang/annotation/loaderLeak/Main.java  2012-06-21 
18:49:27.668543285 +0800
+++ new/test/java/lang/annotation/loaderLeak/Main.java  2012-06-21 
18:49:26.493507985 +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,11 @@
         System.gc();
         System.gc();
         loader = null;
-        System.gc();
-        System.gc();
+        while(false == GCIndicator) {
+            System.gc();
+            System.runFinalization();
+            Thread.sleep(5);
+        }
         if (c.get() != null) throw new AssertionError();
     }
 }
@@ -67,6 +72,7 @@
     private Hashtable classes = new Hashtable();
 
     public SimpleClassLoader() {
+        Main.GCIndicator = false;
     }
     private byte getClassImplFromDataBase(String className)[] {
         byte result[];
@@ -124,4 +130,8 @@
         classes.put(className, result);
         return result;
     }
+    
+    protected void finalize() {
+        Main.GCIndicator = true;
+    }
 }

Reply via email to