RFR 8135188: RunFinalizationTest.java Exception java.lang.Error: Test failure: Object was not finalized
Martin Buchholz
martinrb at google.com
Fri Oct 9 18:05:18 UTC 2015
On Thu, Oct 8, 2015 at 11:51 PM, Jaroslav Bachorik <
jaroslav.bachorik at oracle.com> wrote:
> On 8.10.2015 18:56, Martin Buchholz wrote:
>
>> Hi Jaroslav,
>>
>> we all keep writing finalization code like this... welcome to the club!
>>
>> I think it would be better :
>> - never use currentTimeMillis to measure elapsed time; use nanoTime
>> instead
>>
>
> Ok. I suppose this would be because currentTimeMillis() is dependent on
> the OS time, right?
>
> - why use complex Phaser when simple CountDownLatch will do?
>>
>
> The logic is more complex than just waiting for the finalization to
> happen. I need to make sure the finalization happened due to
> GC.run_finalization command and not because of an ordinary GC run or JVM
> shutdown. I will update the test comments to make this clear.
Oh, now I see what you're doing - you need to block the regular finalizer
thread to make sure there will be objects available for the secondary
finalizer thread to process. Although Phaser works for this, I like using
simple latches - CountDownLatch(1) - because they are easier to understand.
CountDownLatch done = new CountDownLatch(1);
in primary finalizer thread, call done.await
in secondary finalizer thread, call done.countDown to release the primary
finalizer thread
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20151009/c2f44c42/attachment.html>
More information about the serviceability-dev
mailing list