author | coleenp |
Thu, 10 Jan 2019 15:13:51 -0500 | |
changeset 53244 | 9807daeb47c4 |
parent 50607 | af94bdd511cd |
child 53536 | 482109fae02b |
permissions | -rw-r--r-- |
50574 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50607
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
50574 | 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50607
diff
changeset
|
25 |
#ifndef SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50607
diff
changeset
|
26 |
#define SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP |
50574 | 27 |
|
28 |
// |
|
29 |
// String Deduplication |
|
30 |
// |
|
31 |
// String deduplication aims to reduce the heap live-set by deduplicating identical |
|
32 |
// instances of String so that they share the same backing character array. |
|
33 |
// |
|
34 |
// The deduplication process is divided in two main parts, 1) finding the objects to |
|
35 |
// deduplicate, and 2) deduplicating those objects. The first part is done as part of |
|
36 |
// a normal GC cycle when objects are marked or evacuated. At this time a check is |
|
37 |
// applied on each object to check if it is a candidate for deduplication. If so, the |
|
38 |
// object is placed on the deduplication queue for later processing. The second part, |
|
39 |
// processing the objects on the deduplication queue, is a concurrent phase which |
|
40 |
// starts right after the stop-the-wold marking/evacuation phase. This phase is |
|
41 |
// executed by the deduplication thread, which pulls deduplication candidates of the |
|
42 |
// deduplication queue and tries to deduplicate them. |
|
43 |
// |
|
44 |
// A deduplication hashtable is used to keep track of all unique character arrays |
|
45 |
// used by String objects. When deduplicating, a lookup is made in this table to see |
|
46 |
// if there is already an identical character array somewhere on the heap. If so, the |
|
47 |
// String object is adjusted to point to that character array, releasing the reference |
|
48 |
// to the original array allowing it to eventually be garbage collected. If the lookup |
|
49 |
// fails the character array is instead inserted into the hashtable so that this array |
|
50 |
// can be shared at some point in the future. |
|
51 |
// |
|
52 |
// Candidate selection criteria is GC specific. |
|
53 |
// |
|
54 |
// Interned strings are a bit special. They are explicitly deduplicated just before |
|
55 |
// being inserted into the StringTable (to avoid counteracting C2 optimizations done |
|
56 |
// on string literals), then they also become deduplication candidates if they reach |
|
57 |
// the deduplication age threshold or are evacuated to an old heap region. The second |
|
58 |
// attempt to deduplicate such strings will be in vain, but we have no fast way of |
|
59 |
// filtering them out. This has not shown to be a problem, as the number of interned |
|
60 |
// strings is usually dwarfed by the number of normal (non-interned) strings. |
|
61 |
// |
|
62 |
// For additional information on string deduplication, please see JEP 192, |
|
63 |
// http://openjdk.java.net/jeps/192 |
|
64 |
// |
|
65 |
||
66 |
#include "gc/shared/stringdedup/stringDedupQueue.hpp" |
|
67 |
#include "gc/shared/stringdedup/stringDedupStat.hpp" |
|
68 |
#include "gc/shared/stringdedup/stringDedupTable.hpp" |
|
69 |
#include "memory/allocation.hpp" |
|
70 |
#include "runtime/thread.hpp" |
|
71 |
||
72 |
// |
|
73 |
// Main interface for interacting with string deduplication. |
|
74 |
// |
|
75 |
class StringDedup : public AllStatic { |
|
76 |
private: |
|
77 |
// Single state for checking if string deduplication is enabled. |
|
78 |
static bool _enabled; |
|
79 |
||
80 |
public: |
|
81 |
// Returns true if string deduplication is enabled. |
|
82 |
static bool is_enabled() { |
|
83 |
return _enabled; |
|
84 |
} |
|
85 |
||
86 |
// Stop the deduplication thread. |
|
87 |
static void stop(); |
|
88 |
||
89 |
// Immediately deduplicates the given String object, bypassing the |
|
90 |
// the deduplication queue. |
|
91 |
static void deduplicate(oop java_string); |
|
92 |
||
93 |
static void parallel_unlink(StringDedupUnlinkOrOopsDoClosure* unlink, uint worker_id); |
|
94 |
||
95 |
static void threads_do(ThreadClosure* tc); |
|
96 |
static void print_worker_threads_on(outputStream* st); |
|
97 |
static void verify(); |
|
98 |
||
99 |
// GC support |
|
100 |
static void gc_prologue(bool resize_and_rehash_table); |
|
101 |
static void gc_epilogue(); |
|
102 |
||
103 |
protected: |
|
104 |
// Initialize string deduplication. |
|
50607
af94bdd511cd
8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents:
50574
diff
changeset
|
105 |
// Q: String Dedup Queue implementation |
af94bdd511cd
8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents:
50574
diff
changeset
|
106 |
// S: String Dedup Stat implementation |
af94bdd511cd
8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents:
50574
diff
changeset
|
107 |
template <typename Q, typename S> |
50574 | 108 |
static void initialize_impl(); |
109 |
}; |
|
110 |
||
111 |
// |
|
112 |
// This closure encapsulates the closures needed when scanning |
|
113 |
// the deduplication queue and table during the unlink_or_oops_do() operation. |
|
114 |
// |
|
115 |
class StringDedupUnlinkOrOopsDoClosure : public StackObj { |
|
116 |
private: |
|
117 |
BoolObjectClosure* _is_alive; |
|
118 |
OopClosure* _keep_alive; |
|
119 |
||
120 |
public: |
|
121 |
StringDedupUnlinkOrOopsDoClosure(BoolObjectClosure* is_alive, |
|
122 |
OopClosure* keep_alive); |
|
123 |
||
124 |
// Applies and returns the result from the is_alive closure, or |
|
125 |
// returns true if no such closure was provided. |
|
126 |
bool is_alive(oop o) { |
|
127 |
if (_is_alive != NULL) { |
|
128 |
return _is_alive->do_object_b(o); |
|
129 |
} |
|
130 |
return true; |
|
131 |
} |
|
132 |
||
133 |
// Applies the keep_alive closure, or does nothing if no such |
|
134 |
// closure was provided. |
|
135 |
void keep_alive(oop* p) { |
|
136 |
if (_keep_alive != NULL) { |
|
137 |
_keep_alive->do_oop(p); |
|
138 |
} |
|
139 |
} |
|
140 |
}; |
|
141 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50607
diff
changeset
|
142 |
#endif // SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP |