2

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にとってどれほど役に立ちますか?

4

1 に答える 1

1

コードの作者であるDougLea教授に聞いたところ、GCが浮遊ゴミを残す可能性が低くなるとのことでした。

浮遊ゴミに関するいくつかの有用なリソース:

http://www.memorymanagement.org/glossary/f.html#floating.garbage

http://java.sun.com/docs/hotspot/gc1.4.2/#4.4.4.%20Floating%20Garbage|outline

http://blog.johantibell.com/2010/04/generational-garbage-collection-and.html

于 2012-06-14T02:15:16.523 に答える