OpenJDKのLinkedBlockingQueueの実装(java.util.concurrent)のNodeクラスの構造に少し混乱しています。
以下にノードクラスの説明を再現しました。
static class Node<E> {
E item;
/**
* One of:
* - the real successor Node
* - this Node, meaning the successor is head.next
* - null, meaning there is no successor (this is the last node)
*/
Node<E> next;
Node(E x) { item = x; }
}
具体的には、nextの2番目の選択肢(「このノード、後継者はhead.nextを意味します」)で混乱しています。
これは、次のようなdequeueメソッドに直接関連しているようです。
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;
}
そのため、現在のヘッドを削除し、次のヘッドを「GCを支援」するように設定しています。
これはGCにどのように役立ちますか?GCにとってどれほど役に立ちますか?