harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Deakin <oliver.dea...@googlemail.com>
Subject Re: [classlib][testcase] should weakreference be queued in runFinalization()?
Date Fri, 13 Apr 2007 08:49:44 GMT
The 5.0 spec for runFinalization() says:

"Calling this method suggests that the Java Virtual Machine expend 
effort toward running the finalize methods of objects that have been 
found to be discarded but whose finalize methods have not yet been run."

and for gc():

"Calling the gc method suggests that the Java Virtual Machine expend 
effort toward recycling unused objects"

The key word in both those specs is /suggests/. There is *no* guarantee 
that any finalizers are run or that a gc actually occurs when these 
calls are made - it is only a hint to the VM.

If a test is expecting these calls to definitely gc and run finalizers, 
then IMO the test is in error.

Regards,
Oliver


Xiao-Feng Li wrote:
> In classlib tests "gc.PhantomReferenceTest" and
> "tests.api.java.lang.ref.ReferenceTest", they expect weakreference
> objects be queued after System.runFinalization(). Is this correct? In
> my understanding of the spec, there is no requirement on this
> behavior.
>
> The tests do like this:
>
> =========================
> //wr is the weakreference, whose referent is only weakly reachable.
> //rq is the reference queue
>
> System.gc();
> System.runFinalization();
>
> ref = rq.poll();
>
> assertTrue("Unexpected ref2", ref == wr);
> assertNotNull("Object not garbage collected.", ref);
> assertNull("Object could not be reclaimed.", ref.get());
> =========================
>
> After runFinalization(), it requires the queue has the weakreference.
> Actually it has requirement on System.gc() as well, requiring it to
> identify the weakly reachable object accurately.
>
> In my understanding of the spec, this kind of tests are wrong. It
> forces the GC to do something not required by spec.
>
> How do you think?
>
> Thanks,
> xiaofeng
>

-- 
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. 
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU


Mime
View raw message