src/hotspot/share/gc/g1/g1RedirtyCardsQueue.hpp
changeset 55752 8ae33203d600
child 57507 f6b30bd6804e
equal deleted inserted replaced
55751:014decdb5086 55752:8ae33203d600
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #ifndef SHARE_GC_G1_G1REDIRTYCARDSQUEUE_HPP
       
    26 #define SHARE_GC_G1_G1REDIRTYCARDSQUEUE_HPP
       
    27 
       
    28 #include "gc/shared/ptrQueue.hpp"
       
    29 #include "memory/allocation.hpp"
       
    30 #include "memory/padded.hpp"
       
    31 
       
    32 class G1CardTableEntryClosure;
       
    33 class G1RedirtyCardsQueue;
       
    34 class G1RedirtyCardsQueueSet;
       
    35 
       
    36 struct G1RedirtyCardsBufferList {
       
    37   BufferNode* _head;
       
    38   BufferNode* _tail;
       
    39   size_t _count;
       
    40 
       
    41   G1RedirtyCardsBufferList();
       
    42   G1RedirtyCardsBufferList(BufferNode* head, BufferNode* tail, size_t count);
       
    43 };
       
    44 
       
    45 // Provide G1RedirtyCardsQueue with a thread-local qset.  It provides an
       
    46 // uncontended staging area for completed buffers, to be flushed to the
       
    47 // shared qset en masse.  Using the "base from member" idiom so the local
       
    48 // qset is constructed before being passed to the PtrQueue constructor.
       
    49 class G1RedirtyCardsQueueBase {
       
    50   friend class G1RedirtyCardsQueue;
       
    51   friend class G1RedirtyCardsQueueSet;
       
    52 
       
    53   class LocalQSet : public PtrQueueSet {
       
    54     G1RedirtyCardsQueueSet* _shared_qset;
       
    55     G1RedirtyCardsBufferList _buffers;
       
    56 
       
    57   public:
       
    58     LocalQSet(G1RedirtyCardsQueueSet* shared_qset);
       
    59     ~LocalQSet();
       
    60 
       
    61     // Add the buffer to the local list.
       
    62     virtual void enqueue_completed_buffer(BufferNode* node);
       
    63 
       
    64     // Transfer all completed buffers to the shared qset.
       
    65     void flush();
       
    66 
       
    67     G1RedirtyCardsBufferList take_all_completed_buffers();
       
    68   };
       
    69 
       
    70   G1RedirtyCardsQueueBase(G1RedirtyCardsQueueSet* shared_qset) :
       
    71     _local_qset(shared_qset) {}
       
    72 
       
    73   ~G1RedirtyCardsQueueBase() {}
       
    74 
       
    75   LocalQSet _local_qset;
       
    76 };
       
    77 
       
    78 // Worker-local queues of card table entries.
       
    79 class G1RedirtyCardsQueue : private G1RedirtyCardsQueueBase, public PtrQueue {
       
    80 protected:
       
    81   virtual void handle_completed_buffer();
       
    82 
       
    83 public:
       
    84   G1RedirtyCardsQueue(G1RedirtyCardsQueueSet* qset);
       
    85 
       
    86   // Flushes the queue.
       
    87   ~G1RedirtyCardsQueue();
       
    88 
       
    89   // Flushes all enqueued cards to qset.
       
    90   void flush();
       
    91 };
       
    92 
       
    93 // Card table entries to be redirtied and the cards reprocessed later.
       
    94 // Has two phases, collecting and processing.  During the collecting
       
    95 // phase buffers are added to the set.  Once collecting is complete and
       
    96 // processing starts, buffers can no longer be added.  Taking all the
       
    97 // collected (and processed) buffers reverts back to collecting, allowing
       
    98 // the set to be reused for another round of redirtying.
       
    99 class G1RedirtyCardsQueueSet : public PtrQueueSet {
       
   100   DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE, 0);
       
   101   BufferNode::Stack _list;
       
   102   DEFINE_PAD_MINUS_SIZE(2, DEFAULT_CACHE_LINE_SIZE, sizeof(size_t));
       
   103   volatile size_t _count;
       
   104   DEFINE_PAD_MINUS_SIZE(3, DEFAULT_CACHE_LINE_SIZE, sizeof(BufferNode*));
       
   105   BufferNode* _tail;
       
   106   DEBUG_ONLY(mutable bool _collecting;)
       
   107 
       
   108   typedef G1RedirtyCardsQueueBase::LocalQSet LocalQSet;
       
   109 
       
   110   void update_tail(BufferNode* node);
       
   111 
       
   112 public:
       
   113   G1RedirtyCardsQueueSet();
       
   114   ~G1RedirtyCardsQueueSet();
       
   115 
       
   116   using PtrQueueSet::initialize;
       
   117 
       
   118   void verify_empty() const NOT_DEBUG_RETURN;
       
   119 
       
   120   // Collect buffers.  These functions are thread-safe.
       
   121   // precondition: Must not be concurrent with buffer processing.
       
   122   virtual void enqueue_completed_buffer(BufferNode* node);
       
   123   void merge_bufferlist(LocalQSet* src);
       
   124 
       
   125   // Processing phase operations.
       
   126   // precondition: Must not be concurrent with buffer collection.
       
   127   BufferNode* all_completed_buffers() const;
       
   128   G1RedirtyCardsBufferList take_all_completed_buffers();
       
   129 };
       
   130 
       
   131 #endif // SHARE_GC_G1_G1REDIRTYCARDSQUEUE_HPP