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

changeset 6413
595c0f60d50d
child 6690
1772223a25a2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/g1StringDedupQueue.hpp	Tue Mar 18 19:07:22 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, 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_G1STRINGDEDUPQUEUE_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "oops/oop.hpp"
    1.33 +#include "utilities/stack.hpp"
    1.34 +
    1.35 +class G1StringDedupUnlinkOrOopsDoClosure;
    1.36 +
    1.37 +//
    1.38 +// The deduplication queue acts as the communication channel between the stop-the-world
    1.39 +// mark/evacuation phase and the concurrent deduplication phase. Deduplication candidates
    1.40 +// found during mark/evacuation are placed on this queue for later processing in the
    1.41 +// deduplication thread. A queue entry is an oop pointing to a String object (as opposed
    1.42 +// to entries in the deduplication hashtable which points to character arrays).
    1.43 +//
    1.44 +// While users of the queue treat it as a single queue, it is implemented as a set of
    1.45 +// queues, one queue per GC worker thread, to allow lock-free and cache-friendly enqueue
    1.46 +// operations by the GC workers.
    1.47 +//
    1.48 +// The oops in the queue are treated as weak pointers, meaning the objects they point to
    1.49 +// can become unreachable and pruned (cleared) before being popped by the deduplication
    1.50 +// thread.
    1.51 +//
    1.52 +// Pushing to the queue is thread safe (this relies on each thread using a unique worker
    1.53 +// id), but only allowed during a safepoint. Popping from the queue is NOT thread safe
    1.54 +// and can only be done by the deduplication thread outside a safepoint.
    1.55 +//
    1.56 +// The StringDedupQueue_lock is only used for blocking and waking up the deduplication
    1.57 +// thread in case the queue is empty or becomes non-empty, respectively. This lock does
    1.58 +// not otherwise protect the queue content.
    1.59 +//
    1.60 +class G1StringDedupQueue : public CHeapObj<mtGC> {
    1.61 +private:
    1.62 +  typedef Stack<oop, mtGC> G1StringDedupWorkerQueue;
    1.63 +
    1.64 +  static G1StringDedupQueue* _queue;
    1.65 +  static const size_t        _max_size;
    1.66 +  static const size_t        _max_cache_size;
    1.67 +
    1.68 +  G1StringDedupWorkerQueue*  _queues;
    1.69 +  size_t                     _nqueues;
    1.70 +  size_t                     _cursor;
    1.71 +  volatile bool              _empty;
    1.72 +
    1.73 +  // Statistics counter, only used for logging.
    1.74 +  uintx                      _dropped;
    1.75 +
    1.76 +  G1StringDedupQueue();
    1.77 +  ~G1StringDedupQueue();
    1.78 +
    1.79 +  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl, size_t queue);
    1.80 +
    1.81 +public:
    1.82 +  static void create();
    1.83 +
    1.84 +  // Blocks and waits for the queue to become non-empty.
    1.85 +  static void wait();
    1.86 +
    1.87 +  // Pushes a deduplication candidate onto a specific GC worker queue.
    1.88 +  static void push(uint worker_id, oop java_string);
    1.89 +
    1.90 +  // Pops a deduplication candidate from any queue, returns NULL if
    1.91 +  // all queues are empty.
    1.92 +  static oop pop();
    1.93 +
    1.94 +  static void unlink_or_oops_do(G1StringDedupUnlinkOrOopsDoClosure* cl);
    1.95 +
    1.96 +  static void print_statistics(outputStream* st);
    1.97 +  static void verify();
    1.98 +};
    1.99 +
   1.100 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1STRINGDEDUPQUEUE_HPP

mercurial