1/*
2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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_GC_G1_G1STRINGDEDUPQUEUE_HPP
26#define SHARE_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
33class StringDedupUnlinkOrOopsDoClosure;
34
35//
36// G1 enqueues candidates during the stop-the-world mark/evacuation phase.
37//
38
39class G1StringDedupQueue : public StringDedupQueue {
40private:
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
59public:
60 G1StringDedupQueue();
61
62protected:
63
64 // Blocks and waits for the queue to become non-empty.
65 void wait_impl();
66
67 // Wakes up any thread blocked waiting for the queue to become non-empty.
68 void cancel_wait_impl();
69
70 // Pushes a deduplication candidate onto a specific GC worker queue.
71 void push_impl(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 pop_impl();
76
77 size_t num_queues() const {
78 return _nqueues;
79 }
80
81 void unlink_or_oops_do_impl(StringDedupUnlinkOrOopsDoClosure* cl, size_t queue);
82
83 void print_statistics_impl();
84 void verify_impl();
85};
86
87#endif // SHARE_GC_G1_G1STRINGDEDUPQUEUE_HPP
88