You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Ian Rogers <ro...@gmail.com> on 2008/06/25 14:48:21 UTC

java.lang.ref.ReferenceQueue.enqueue allocates array during GC

Hi,

I'm having a problem with java.lang.ref.ReferenceQueue.enqueue in that 
it queues references onto an array during GC, and that this array may 
need to be grown during the GC. Generating new objects during GC is 
something of a gray area, in the VM I'm working with it is not allowed. 
An alternative is to have a field in Reference that allows references to 
be linked together. Should this approach be adopted for all of Harmony 
or just within our VM?

Thanks,
Ian Rogers
--
http://www.cs.man.ac.uk/~irogers/

Re: java.lang.ref.ReferenceQueue.enqueue allocates array during GC

Posted by Aleksey Shipilev <al...@gmail.com>.
Hi, Ian!

IMO, linked list is bad for performance, though it solves the problem.
How about accumulating the enqueued objects in some (native,
resizable) VM buffer and flush it after the GC is over?

Thanks,
Aleksey.

On Wed, Jun 25, 2008 at 4:48 PM, Ian Rogers <ro...@gmail.com> wrote:
> Hi,
>
> I'm having a problem with java.lang.ref.ReferenceQueue.enqueue in that it
> queues references onto an array during GC, and that this array may need to
> be grown during the GC. Generating new objects during GC is something of a
> gray area, in the VM I'm working with it is not allowed. An alternative is
> to have a field in Reference that allows references to be linked together.
> Should this approach be adopted for all of Harmony or just within our VM?
>
> Thanks,
> Ian Rogers
> --
> http://www.cs.man.ac.uk/~irogers/
>

Re: java.lang.ref.ReferenceQueue.enqueue allocates array during GC

Posted by Tim Ellison <t....@gmail.com>.
Ian Rogers wrote:
> I'm having a problem with java.lang.ref.ReferenceQueue.enqueue in that 
> it queues references onto an array during GC, and that this array may 
> need to be grown during the GC. Generating new objects during GC is 
> something of a gray area, in the VM I'm working with it is not allowed. 
> An alternative is to have a field in Reference that allows references to 
> be linked together. Should this approach be adopted for all of Harmony 
> or just within our VM?

This is the approach taken by Harmony's DRLVM too.  DRLVM doesn't use 
the implementation of ReferenceQueue in the classlib code [1], it has 
it's own implementation in the kernel classes [2].

This is (another) case where the contract between VM implementor and the 
class library code would need to be changed if we were to adopt the 
'linked list' implementation of the queue.

[1] 
http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/ref/ReferenceQueue.java?view=markup
[2] 
http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ref/ReferenceQueue.java?view=markup

Regards,
Tim

Re: java.lang.ref.ReferenceQueue.enqueue allocates array during GC

Posted by Ligang Wang <wa...@gmail.com>.
As Tim said the implementation of ReferenceQueue in DRLVM kernel classes
uses linked list rather than array. What Xiao-Feng said is also the case. In
DRLVM, VM finds out those references that need enqueue and put them into a
VM queue during GC. The VM queue is implemented in array. Immediately after
GC the enqueue() method is invoked. This action detaches the according
reference from the VM queue and linkes it into ReferenceQueue.

Thanks,
ligang


On 6/25/08, Xiao-Feng Li <xi...@gmail.com> wrote:
>
> IIRC, Harmony enqueues the objects into a VM queue (C structure); then
> after GC, the enqueue() methods are really invoked for all of them in
> the VM queue. This is similar to the finalization processing. I need
> double check.
>
> Thanks,
> xiaofeng
>
> On Wed, Jun 25, 2008 at 8:48 PM, Ian Rogers <ro...@gmail.com>
> wrote:
> > Hi,
> >
> > I'm having a problem with java.lang.ref.ReferenceQueue.enqueue in that it
> > queues references onto an array during GC, and that this array may need
> to
> > be grown during the GC. Generating new objects during GC is something of
> a
> > gray area, in the VM I'm working with it is not allowed. An alternative
> is
> > to have a field in Reference that allows references to be linked
> together.
> > Should this approach be adopted for all of Harmony or just within our VM?
> >
> > Thanks,
> > Ian Rogers
> > --
> > http://www.cs.man.ac.uk/~irogers/
> >
>
>
>
> --
> http://xiao-feng.blogspot.com
>

Re: java.lang.ref.ReferenceQueue.enqueue allocates array during GC

Posted by Xiao-Feng Li <xi...@gmail.com>.
IIRC, Harmony enqueues the objects into a VM queue (C structure); then
after GC, the enqueue() methods are really invoked for all of them in
the VM queue. This is similar to the finalization processing. I need
double check.

Thanks,
xiaofeng

On Wed, Jun 25, 2008 at 8:48 PM, Ian Rogers <ro...@gmail.com> wrote:
> Hi,
>
> I'm having a problem with java.lang.ref.ReferenceQueue.enqueue in that it
> queues references onto an array during GC, and that this array may need to
> be grown during the GC. Generating new objects during GC is something of a
> gray area, in the VM I'm working with it is not allowed. An alternative is
> to have a field in Reference that allows references to be linked together.
> Should this approach be adopted for all of Harmony or just within our VM?
>
> Thanks,
> Ian Rogers
> --
> http://www.cs.man.ac.uk/~irogers/
>



-- 
http://xiao-feng.blogspot.com