RFR 8135188: RunFinalizationTest.java Exception java.lang.Error: Test failure: Object was not finalized

Jaroslav Bachorik jaroslav.bachorik at oracle.com
Wed Oct 14 06:47:23 UTC 2015


On 13.10.2015 20:12, Martin Buchholz wrote:
> blockFinalizerThread looks buggy to me.
>
>   103     private static void blockFinalizerThread() throws
> InterruptedException {
>   104         System.out.println("trying to block the finalizer thread");
>   105         o1 = new MyObject();
>   106         o1 = null;
>   107         System.gc();
>   108         System.runFinalization();
>   109         finRunLatch.await();
>   110     }
> Why are you calling System.runFinalization() ?  You are trying to block
> the primary finalizer thread; you definitely don't want the object to be
> handled by the secondary finalizer thread.

Indeed. Even though this seems unlikely (didn't hit the problem in 500 
repetitions) it will be better not to call System.runFinalization() and 
just let System.gc() do its job finalizing the collected instance.

>
> ---
>
>    51             } else {
>    52                 System.out.println("finalizing the test instance");
> I would check :
>
> else if (Thread.currentThread().getName().equals("Secondary finalizer")) {
>    ....
> else fail(unexpected finalizer thread name)

If this ever happens it would mean that the finalizer logic has been 
changed. Adding this check will make the test fail in such case and 
force re-examination of the test logic. Sounds fair.

http://cr.openjdk.java.net/~jbachorik/8135188/webrev.04

Thanks!

-JB-

>
>



More information about the serviceability-dev mailing list