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

Tue, 18 Mar 2014 19:07:22 +0100

author
pliden
date
Tue, 18 Mar 2014 19:07:22 +0100
changeset 6413
595c0f60d50d
child 6690
1772223a25a2
permissions
-rw-r--r--

8029075: String deduplication in G1
Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192
Reviewed-by: brutisso, tschatzl, coleenp

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

mercurial