How could self link help GC?
Bernd Eckenfels
ecki at zusammenkunft.net
Mon Jun 22 04:33:44 UTC 2020
It is probably not needed here, since the slot is freed up quite quickly (at the end of the method) and the remaining queue is also kept alive anyway.
Setting it to selve instead of null is typically used to reduce the risk of NPEs (but it might on the other hand increase the risk of lovelocks)
Not sure if it's a good idea to remove the setting for concurrency reasons, but it seems not really be beneficial for GC.
Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Von: hotspot-gc-use <hotspot-gc-use-bounces at openjdk.java.net> im Auftrag von Robert Lu <robberphex at gmail.com>
Gesendet: Monday, June 22, 2020 5:40:08 AM
An: Damon Hart-Davis <dhd at exnet.com>
Cc: hotspot-gc-use at openjdk.java.net <hotspot-gc-use at openjdk.java.net>
Betreff: Re: How could self link help GC?
Hi, Damon.
But once dequeued, old node is dead object. The pointer(h.next) from dead object to alive/dead object makes no difference to GC.
So I thinks h.next=h is meaningless.
And, why isn't it h.next=null ?
On Mon, Jun 22, 2020 at 12:18 AM Damon Hart-Davis <dhd at exnet.com<mailto:dhd at exnet.com>> wrote:
By avoiding spurious pointers to h.next keeping the ’next’ item alive longer than necessary.
Rgds
Damon
On 21 Jun 2020, at 12:59, Robert Lu <robberphex at gmail.com<mailto:robberphex at gmail.com>> wrote:
Hi,
On java.util.concurrent.LinkedBlockingQueue#dequeue https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/concurrent/LinkedBlockingQueue.java#L217 :
private E dequeue() {
// assert takeLock.isHeldByCurrentThread();
// assert head.item == null;
Node<E> h = head;
Node<E> first = h.next;
h.next = h; // help GC
head = first;
E x = first.item;
first.item = null;
return x;
}
Why does h.next = h help GC?
--
Robert Lu <robberphex at gmail.com<mailto:robberphex at gmail.com>>
About me: https://www.robberphex.com/about-me
_______________________________________________
hotspot-gc-use mailing list
hotspot-gc-use at openjdk.java.net<mailto:hotspot-gc-use at openjdk.java.net>
https://mail.openjdk.java.net/mailman/listinfo/hotspot-gc-use
--
Robert Lu <robberphex at gmail.com<mailto:robberphex at gmail.com>>
About me: https://www.robberphex.com/about-me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/hotspot-gc-use/attachments/20200622/15408983/attachment.htm>
More information about the hotspot-gc-use
mailing list