Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "memory/allocation.hpp" |
aoqi@0 | 29 | #include "oops/oop.hpp" |
aoqi@0 | 30 | #include "utilities/stack.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | class G1StringDedupUnlinkOrOopsDoClosure; |
aoqi@0 | 33 | |
aoqi@0 | 34 | // |
aoqi@0 | 35 | // The deduplication queue acts as the communication channel between the stop-the-world |
aoqi@0 | 36 | // mark/evacuation phase and the concurrent deduplication phase. Deduplication candidates |
aoqi@0 | 37 | // found during mark/evacuation are placed on this queue for later processing in the |
aoqi@0 | 38 | // deduplication thread. A queue entry is an oop pointing to a String object (as opposed |
aoqi@0 | 39 | // to entries in the deduplication hashtable which points to character arrays). |
aoqi@0 | 40 | // |
aoqi@0 | 41 | // While users of the queue treat it as a single queue, it is implemented as a set of |
aoqi@0 | 42 | // queues, one queue per GC worker thread, to allow lock-free and cache-friendly enqueue |
aoqi@0 | 43 | // operations by the GC workers. |
aoqi@0 | 44 | // |
aoqi@0 | 45 | // The oops in the queue are treated as weak pointers, meaning the objects they point to |
aoqi@0 | 46 | // can become unreachable and pruned (cleared) before being popped by the deduplication |
aoqi@0 | 47 | // thread. |
aoqi@0 | 48 | // |
aoqi@0 | 49 | // Pushing to the queue is thread safe (this relies on each thread using a unique worker |
aoqi@0 | 50 | // id), but only allowed during a safepoint. Popping from the queue is NOT thread safe |
aoqi@0 | 51 | // and can only be done by the deduplication thread outside a safepoint. |
aoqi@0 | 52 | // |
aoqi@0 | 53 | // The StringDedupQueue_lock is only used for blocking and waking up the deduplication |
aoqi@0 | 54 | // thread in case the queue is empty or becomes non-empty, respectively. This lock does |
aoqi@0 | 55 | // not otherwise protect the queue content. |
aoqi@0 | 56 | // |
aoqi@0 | 57 | class G1StringDedupQueue : public CHeapObj<mtGC> { |
aoqi@0 | 58 | private: |
aoqi@0 | 59 | typedef Stack<oop, mtGC> G1StringDedupWorkerQueue; |
aoqi@0 | 60 | |
aoqi@0 | 61 | static G1StringDedupQueue* _queue; |
aoqi@0 | 62 | static const size_t _max_size; |
aoqi@0 | 63 | static const size_t _max_cache_size; |
aoqi@0 | 64 | |
aoqi@0 | 65 | G1StringDedupWorkerQueue* _queues; |
aoqi@0 | 66 | size_t _nqueues; |
aoqi@0 | 67 | size_t _cursor; |
aoqi@0 | 68 | bool _cancel; |
aoqi@0 | 69 | volatile bool _empty; |
aoqi@0 | 70 | |
aoqi@0 | 71 | // Statistics counter, only used for logging. |
aoqi@0 | 72 | uintx _dropped; |
aoqi@0 | 73 | |
aoqi@0 | 74 | G1StringDedupQueue(); |
aoqi@0 | 75 | ~G1StringDedupQueue(); |
aoqi@0 | 76 | |
aoqi@0 | 77 | static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue); |
aoqi@0 | 78 | |
aoqi@0 | 79 | public: |
aoqi@0 | 80 | static void create(); |
aoqi@0 | 81 | |
aoqi@0 | 82 | // Blocks and waits for the queue to become non-empty. |
aoqi@0 | 83 | static void wait(); |
aoqi@0 | 84 | |
aoqi@0 | 85 | // Wakes up any thread blocked waiting for the queue to become non-empty. |
aoqi@0 | 86 | static void cancel_wait(); |
aoqi@0 | 87 | |
aoqi@0 | 88 | // Pushes a deduplication candidate onto a specific GC worker queue. |
aoqi@0 | 89 | static void push(uint worker_id, oop java_string); |
aoqi@0 | 90 | |
aoqi@0 | 91 | // Pops a deduplication candidate from any queue, returns NULL if |
aoqi@0 | 92 | // all queues are empty. |
aoqi@0 | 93 | static oop pop(); |
aoqi@0 | 94 | |
aoqi@0 | 95 | static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl); |
aoqi@0 | 96 | |
aoqi@0 | 97 | static void print_statistics(outputStream* st); |
aoqi@0 | 98 | static void verify(); |
aoqi@0 | 99 | }; |
aoqi@0 | 100 | |
aoqi@0 | 101 | #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP |