src/share/vm/gc_implementation/g1/dirtyCardQueue.hpp

changeset 777
37f87013dfd8
child 1051
4f360ec815ba
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/dirtyCardQueue.hpp	Thu Jun 05 15:57:56 2008 -0700
     1.3 @@ -0,0 +1,152 @@
     1.4 +/*
     1.5 + * Copyright 2001-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +class FreeIdSet;
    1.29 +
    1.30 +// A closure class for processing card table entries.  Note that we don't
    1.31 +// require these closure objects to be stack-allocated.
    1.32 +class CardTableEntryClosure: public CHeapObj {
    1.33 +public:
    1.34 +  // Process the card whose card table entry is "card_ptr".  If returns
    1.35 +  // "false", terminate the iteration early.
    1.36 +  virtual bool do_card_ptr(jbyte* card_ptr, int worker_i = 0) = 0;
    1.37 +};
    1.38 +
    1.39 +// A ptrQueue whose elements are "oops", pointers to object heads.
    1.40 +class DirtyCardQueue: public PtrQueue {
    1.41 +public:
    1.42 +  DirtyCardQueue(PtrQueueSet* qset_, bool perm = false) :
    1.43 +    PtrQueue(qset_, perm)
    1.44 +  {
    1.45 +    // Dirty card queues are always active.
    1.46 +    _active = true;
    1.47 +  }
    1.48 +  // Apply the closure to all elements, and reset the index to make the
    1.49 +  // buffer empty.  If a closure application returns "false", return
    1.50 +  // "false" immediately, halting the iteration.  If "consume" is true,
    1.51 +  // deletes processed entries from logs.
    1.52 +  bool apply_closure(CardTableEntryClosure* cl,
    1.53 +                     bool consume = true,
    1.54 +                     size_t worker_i = 0);
    1.55 +
    1.56 +  // Apply the closure to all elements of "buf", down to "index"
    1.57 +  // (inclusive.)  If returns "false", then a closure application returned
    1.58 +  // "false", and we return immediately.  If "consume" is true, entries are
    1.59 +  // set to NULL as they are processed, so they will not be processed again
    1.60 +  // later.
    1.61 +  static bool apply_closure_to_buffer(CardTableEntryClosure* cl,
    1.62 +                                      void** buf, size_t index, size_t sz,
    1.63 +                                      bool consume = true,
    1.64 +                                      int worker_i = 0);
    1.65 +  void **get_buf() { return _buf;}
    1.66 +  void set_buf(void **buf) {_buf = buf;}
    1.67 +  size_t get_index() { return _index;}
    1.68 +  void reinitialize() { _buf = 0; _sz = 0; _index = 0;}
    1.69 +};
    1.70 +
    1.71 +
    1.72 +
    1.73 +class DirtyCardQueueSet: public PtrQueueSet {
    1.74 +  CardTableEntryClosure* _closure;
    1.75 +
    1.76 +  DirtyCardQueue _shared_dirty_card_queue;
    1.77 +
    1.78 +  // Override.
    1.79 +  bool mut_process_buffer(void** buf);
    1.80 +
    1.81 +  // Protected by the _cbl_mon.
    1.82 +  FreeIdSet* _free_ids;
    1.83 +
    1.84 +  // The number of completed buffers processed by mutator and rs thread,
    1.85 +  // respectively.
    1.86 +  jint _processed_buffers_mut;
    1.87 +  jint _processed_buffers_rs_thread;
    1.88 +
    1.89 +public:
    1.90 +  DirtyCardQueueSet();
    1.91 +
    1.92 +  void initialize(Monitor* cbl_mon, Mutex* fl_lock,
    1.93 +                  int max_completed_queue = 0,
    1.94 +                  Mutex* lock = NULL);
    1.95 +
    1.96 +  // The number of parallel ids that can be claimed to allow collector or
    1.97 +  // mutator threads to do card-processing work.
    1.98 +  static size_t num_par_ids();
    1.99 +
   1.100 +  static void handle_zero_index_for_thread(JavaThread* t);
   1.101 +
   1.102 +  // Register "blk" as "the closure" for all queues.  Only one such closure
   1.103 +  // is allowed.  The "apply_closure_to_completed_buffer" method will apply
   1.104 +  // this closure to a completed buffer, and "iterate_closure_all_threads"
   1.105 +  // applies it to partially-filled buffers (the latter should only be done
   1.106 +  // with the world stopped).
   1.107 +  void set_closure(CardTableEntryClosure* closure);
   1.108 +
   1.109 +  // If there is a registered closure for buffers, apply it to all entries
   1.110 +  // in all currently-active buffers.  This should only be applied at a
   1.111 +  // safepoint.  (Currently must not be called in parallel; this should
   1.112 +  // change in the future.)  If "consume" is true, processed entries are
   1.113 +  // discarded.
   1.114 +  void iterate_closure_all_threads(bool consume = true,
   1.115 +                                   size_t worker_i = 0);
   1.116 +
   1.117 +  // If there exists some completed buffer, pop it, then apply the
   1.118 +  // registered closure to all its elements, nulling out those elements
   1.119 +  // processed.  If all elements are processed, returns "true".  If no
   1.120 +  // completed buffers exist, returns false.  If a completed buffer exists,
   1.121 +  // but is only partially completed before a "yield" happens, the
   1.122 +  // partially completed buffer (with its processed elements set to NULL)
   1.123 +  // is returned to the completed buffer set, and this call returns false.
   1.124 +  bool apply_closure_to_completed_buffer(int worker_i = 0,
   1.125 +                                         int stop_at = 0,
   1.126 +                                         bool with_CAS = false);
   1.127 +  bool apply_closure_to_completed_buffer_helper(int worker_i,
   1.128 +                                                CompletedBufferNode* nd);
   1.129 +
   1.130 +  CompletedBufferNode* get_completed_buffer_CAS();
   1.131 +  CompletedBufferNode* get_completed_buffer_lock(int stop_at);
   1.132 +  // Applies the current closure to all completed buffers,
   1.133 +  // non-consumptively.
   1.134 +  void apply_closure_to_all_completed_buffers();
   1.135 +
   1.136 +  DirtyCardQueue* shared_dirty_card_queue() {
   1.137 +    return &_shared_dirty_card_queue;
   1.138 +  }
   1.139 +
   1.140 +  // If a full collection is happening, reset partial logs, and ignore
   1.141 +  // completed ones: the full collection will make them all irrelevant.
   1.142 +  void abandon_logs();
   1.143 +
   1.144 +  // If any threads have partial logs, add them to the global list of logs.
   1.145 +  void concatenate_logs();
   1.146 +  void clear_n_completed_buffers() { _n_completed_buffers = 0;}
   1.147 +
   1.148 +  jint processed_buffers_mut() {
   1.149 +    return _processed_buffers_mut;
   1.150 +  }
   1.151 +  jint processed_buffers_rs_thread() {
   1.152 +    return _processed_buffers_rs_thread;
   1.153 +  }
   1.154 +
   1.155 +};

mercurial