annotate src/share/vm/gc_implementation/g1/g1StringDedupQueue.hpp @ 17935:7384f6a12fc1

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