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_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP 26 #define SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP 27 28 #include "memory/allocation.hpp" 29 #include "oops/oop.hpp" 30 #include "utilities/stack.hpp" 31 32 class G1StringDedupUnlinkOrOopsDoClosure; 33 34 // 35 // The deduplication queue acts as the communication channel between the stop-the-world 36 // mark/evacuation phase and the concurrent deduplication phase. Deduplication candidates 37 // found during mark/evacuation are placed on this queue for later processing in the 38 // deduplication thread. A queue entry is an oop pointing to a String object (as opposed 39 // to entries in the deduplication hashtable which points to character arrays). 40 // 41 // While users of the queue treat it as a single queue, it is implemented as a set of 42 // queues, one queue per GC worker thread, to allow lock-free and cache-friendly enqueue 43 // operations by the GC workers. 44 // 45 // The oops in the queue are treated as weak pointers, meaning the objects they point to 46 // can become unreachable and pruned (cleared) before being popped by the deduplication 47 // thread. 48 // 49 // Pushing to the queue is thread safe (this relies on each thread using a unique worker 50 // id), but only allowed during a safepoint. Popping from the queue is NOT thread safe 51 // and can only be done by the deduplication thread outside a safepoint. 52 // 53 // The StringDedupQueue_lock is only used for blocking and waking up the deduplication 54 // thread in case the queue is empty or becomes non-empty, respectively. This lock does 55 // not otherwise protect the queue content. 56 // 57 class G1StringDedupQueue : public CHeapObj<mtGC> { 58 private: 59 typedef Stack<oop, mtGC> G1StringDedupWorkerQueue; 60 61 static G1StringDedupQueue* _queue; 62 static const size_t _max_size; 63 static const size_t _max_cache_size; 64 65 G1StringDedupWorkerQueue* _queues; 66 size_t _nqueues; 67 size_t _cursor; 68 bool _cancel; 69 volatile bool _empty; 70 71 // Statistics counter, only used for logging. 72 uintx _dropped; 73 74 G1StringDedupQueue(); 75 ~G1StringDedupQueue(); 76 77 static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue); 78 79 public: 80 static void create(); 81 82 // Blocks and waits for the queue to become non-empty. 83 static void wait(); 84 85 // Wakes up any thread blocked waiting for the queue to become non-empty. 86 static void cancel_wait(); 87 88 // Pushes a deduplication candidate onto a specific GC worker queue. 89 static void push(uint worker_id, oop java_string); 90 91 // Pops a deduplication candidate from any queue, returns NULL if 92 // all queues are empty. 93 static oop pop(); 94 95 static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl); 96 97 static void print_statistics(); 98 static void verify(); 99 }; 100 101 #endif // SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP | 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_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP 26 #define SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP 27 28 #include "gc/shared/stringdedup/stringDedupQueue.hpp" 29 #include "memory/allocation.hpp" 30 #include "oops/oop.hpp" 31 #include "utilities/stack.hpp" 32 33 class StringDedupUnlinkOrOopsDoClosure; 34 35 // 36 // G1 enqueues candidates during the stop-the-world mark/evacuation phase. 37 // 38 39 class G1StringDedupQueue : public StringDedupQueue { 40 private: 41 typedef Stack<oop, mtGC> G1StringDedupWorkerQueue; 42 43 static const size_t _max_size; 44 static const size_t _max_cache_size; 45 46 G1StringDedupWorkerQueue* _queues; 47 size_t _nqueues; 48 size_t _cursor; 49 bool _cancel; 50 volatile bool _empty; 51 52 // Statistics counter, only used for logging. 53 uintx _dropped; 54 55 ~G1StringDedupQueue(); 56 57 void unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl, size_t queue); 58 59 public: 60 G1StringDedupQueue(); 61 62 protected: 63 64 // Blocks and waits for the queue to become non-empty. 65 void queue_wait(); 66 67 // Wakes up any thread blocked waiting for the queue to become non-empty. 68 void queue_cancel_wait(); 69 70 // Pushes a deduplication candidate onto a specific GC worker queue. 71 void queue_push(uint worker_id, oop java_string); 72 73 // Pops a deduplication candidate from any queue, returns NULL if 74 // all queues are empty. 75 oop queue_pop(); 76 77 size_t num_queues() const { 78 return _nqueues; 79 } 80 81 void queue_unlink_or_oops_do(StringDedupUnlinkOrOopsDoClosure* cl, size_t queue); 82 83 void queue_print_statistics(); 84 void queue_verify(); 85 }; 86 87 #endif // SHARE_VM_GC_G1_G1STRINGDEDUPQUEUE_HPP |