harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Salikh Zakirov <Salikh.Zaki...@Intel.com>
Subject Re: [drlvm][opt] Two JIRAs created. Please take a look!
Date Wed, 14 Mar 2007 17:25:07 GMT
Elena Semukhina wrote:
> The 'ref' object in the test is a PhantomReference object. The spec for
> PhantomReference reads:
> "Unlike soft and weak references, phantom references are not automatically
> cleared by the garbage collector as they are enqueued."

PhantomReference.get() always returns null.
The line that fails the test is different one:

      enqueued = queue.poll();
      if (enqueued == null) {
          System.out.println("FAIL: reference was not enqueued");
          return;
      }

> I think they should not be automatically cleared even because all its
> methods are inlined since we must ensure that their get() method always
> returns null after the referents of phantom references are reclaimed.

the problem in this particular test is in the fact, that OPT was able to inline
all uses of local variable 'ref' and eliminate them, thus making the
PhantomReference object itself unreachable.

Reading the javadoc of weak references (java.lang.ref package description),

> The relationship between a registered reference object and its queue is
> one-sided. That is, a queue does not keep track of the references that are
> registered with it. If a registered reference becomes unreachable itself,
> then it will never be enqueued. It is the responsibility of the program
> using reference objects to ensure that the objects remain reachable for as
> long as the program is interested in their referents.

we see the exact reason why the reference object is never enqueued.

The simplest way to fix the test is to declare PhantomReference variable as static:

	static Reference ref;

	public static void main(String[] args) {
		
		// ...

		ref = new PhantomReference(referent, queue);



Mime
View raw message