1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/dirtyCardQueue.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,178 @@ 1.4 +/* 1.5 + * Copyright (c) 2001, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_DIRTYCARDQUEUE_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_DIRTYCARDQUEUE_HPP 1.30 + 1.31 +#include "gc_implementation/g1/ptrQueue.hpp" 1.32 +#include "memory/allocation.hpp" 1.33 + 1.34 +class FreeIdSet; 1.35 + 1.36 +// A closure class for processing card table entries. Note that we don't 1.37 +// require these closure objects to be stack-allocated. 1.38 +class CardTableEntryClosure: public CHeapObj<mtGC> { 1.39 +public: 1.40 + // Process the card whose card table entry is "card_ptr". If returns 1.41 + // "false", terminate the iteration early. 1.42 + virtual bool do_card_ptr(jbyte* card_ptr, uint worker_i = 0) = 0; 1.43 +}; 1.44 + 1.45 +// A ptrQueue whose elements are "oops", pointers to object heads. 1.46 +class DirtyCardQueue: public PtrQueue { 1.47 +public: 1.48 + DirtyCardQueue(PtrQueueSet* qset_, bool perm = false) : 1.49 + // Dirty card queues are always active, so we create them with their 1.50 + // active field set to true. 1.51 + PtrQueue(qset_, perm, true /* active */) { } 1.52 + 1.53 + // Apply the closure to all elements, and reset the index to make the 1.54 + // buffer empty. If a closure application returns "false", return 1.55 + // "false" immediately, halting the iteration. If "consume" is true, 1.56 + // deletes processed entries from logs. 1.57 + bool apply_closure(CardTableEntryClosure* cl, 1.58 + bool consume = true, 1.59 + uint worker_i = 0); 1.60 + 1.61 + // Apply the closure to all elements of "buf", down to "index" 1.62 + // (inclusive.) If returns "false", then a closure application returned 1.63 + // "false", and we return immediately. If "consume" is true, entries are 1.64 + // set to NULL as they are processed, so they will not be processed again 1.65 + // later. 1.66 + static bool apply_closure_to_buffer(CardTableEntryClosure* cl, 1.67 + void** buf, size_t index, size_t sz, 1.68 + bool consume = true, 1.69 + uint worker_i = 0); 1.70 + void **get_buf() { return _buf;} 1.71 + void set_buf(void **buf) {_buf = buf;} 1.72 + size_t get_index() { return _index;} 1.73 + void reinitialize() { _buf = 0; _sz = 0; _index = 0;} 1.74 +}; 1.75 + 1.76 + 1.77 + 1.78 +class DirtyCardQueueSet: public PtrQueueSet { 1.79 + CardTableEntryClosure* _closure; 1.80 + 1.81 + DirtyCardQueue _shared_dirty_card_queue; 1.82 + 1.83 + // Override. 1.84 + bool mut_process_buffer(void** buf); 1.85 + 1.86 + // Protected by the _cbl_mon. 1.87 + FreeIdSet* _free_ids; 1.88 + 1.89 + // The number of completed buffers processed by mutator and rs thread, 1.90 + // respectively. 1.91 + jint _processed_buffers_mut; 1.92 + jint _processed_buffers_rs_thread; 1.93 + 1.94 +public: 1.95 + DirtyCardQueueSet(bool notify_when_complete = true); 1.96 + 1.97 + void initialize(Monitor* cbl_mon, Mutex* fl_lock, 1.98 + int process_completed_threshold, 1.99 + int max_completed_queue, 1.100 + Mutex* lock, PtrQueueSet* fl_owner = NULL); 1.101 + 1.102 + // The number of parallel ids that can be claimed to allow collector or 1.103 + // mutator threads to do card-processing work. 1.104 + static uint num_par_ids(); 1.105 + 1.106 + static void handle_zero_index_for_thread(JavaThread* t); 1.107 + 1.108 + // Register "blk" as "the closure" for all queues. Only one such closure 1.109 + // is allowed. The "apply_closure_to_completed_buffer" method will apply 1.110 + // this closure to a completed buffer, and "iterate_closure_all_threads" 1.111 + // applies it to partially-filled buffers (the latter should only be done 1.112 + // with the world stopped). 1.113 + void set_closure(CardTableEntryClosure* closure); 1.114 + 1.115 + // If there is a registered closure for buffers, apply it to all entries 1.116 + // in all currently-active buffers. This should only be applied at a 1.117 + // safepoint. (Currently must not be called in parallel; this should 1.118 + // change in the future.) If "consume" is true, processed entries are 1.119 + // discarded. 1.120 + void iterate_closure_all_threads(bool consume = true, 1.121 + uint worker_i = 0); 1.122 + 1.123 + // If there exists some completed buffer, pop it, then apply the 1.124 + // registered closure to all its elements, nulling out those elements 1.125 + // processed. If all elements are processed, returns "true". If no 1.126 + // completed buffers exist, returns false. If a completed buffer exists, 1.127 + // but is only partially completed before a "yield" happens, the 1.128 + // partially completed buffer (with its processed elements set to NULL) 1.129 + // is returned to the completed buffer set, and this call returns false. 1.130 + bool apply_closure_to_completed_buffer(uint worker_i = 0, 1.131 + int stop_at = 0, 1.132 + bool during_pause = false); 1.133 + 1.134 + // If there exists some completed buffer, pop it, then apply the 1.135 + // specified closure to all its elements, nulling out those elements 1.136 + // processed. If all elements are processed, returns "true". If no 1.137 + // completed buffers exist, returns false. If a completed buffer exists, 1.138 + // but is only partially completed before a "yield" happens, the 1.139 + // partially completed buffer (with its processed elements set to NULL) 1.140 + // is returned to the completed buffer set, and this call returns false. 1.141 + bool apply_closure_to_completed_buffer(CardTableEntryClosure* cl, 1.142 + uint worker_i = 0, 1.143 + int stop_at = 0, 1.144 + bool during_pause = false); 1.145 + 1.146 + // Helper routine for the above. 1.147 + bool apply_closure_to_completed_buffer_helper(CardTableEntryClosure* cl, 1.148 + uint worker_i, 1.149 + BufferNode* nd); 1.150 + 1.151 + BufferNode* get_completed_buffer(int stop_at); 1.152 + 1.153 + // Applies the current closure to all completed buffers, 1.154 + // non-consumptively. 1.155 + void apply_closure_to_all_completed_buffers(); 1.156 + 1.157 + DirtyCardQueue* shared_dirty_card_queue() { 1.158 + return &_shared_dirty_card_queue; 1.159 + } 1.160 + 1.161 + // Deallocate any completed log buffers 1.162 + void clear(); 1.163 + 1.164 + // If a full collection is happening, reset partial logs, and ignore 1.165 + // completed ones: the full collection will make them all irrelevant. 1.166 + void abandon_logs(); 1.167 + 1.168 + // If any threads have partial logs, add them to the global list of logs. 1.169 + void concatenate_logs(); 1.170 + void clear_n_completed_buffers() { _n_completed_buffers = 0;} 1.171 + 1.172 + jint processed_buffers_mut() { 1.173 + return _processed_buffers_mut; 1.174 + } 1.175 + jint processed_buffers_rs_thread() { 1.176 + return _processed_buffers_rs_thread; 1.177 + } 1.178 + 1.179 +}; 1.180 + 1.181 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_DIRTYCARDQUEUE_HPP