Skip to content

Commit fb1dfc6

Browse files
author
Ivan Walulya
committed
8267185: Add string deduplication support to ParallelGC
Reviewed-by: kbarrett, ayang
1 parent d874e96 commit fb1dfc6

17 files changed

+182
-1
lines changed

src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "gc/shared/gcInitLogger.hpp"
4242
#include "gc/shared/locationPrinter.inline.hpp"
4343
#include "gc/shared/scavengableNMethods.hpp"
44+
#include "gc/shared/suspendibleThreadSet.hpp"
4445
#include "logging/log.hpp"
4546
#include "memory/iterator.hpp"
4647
#include "memory/metaspaceCounters.hpp"
@@ -162,6 +163,17 @@ void ParallelScavengeHeap::initialize_serviceability() {
162163

163164
}
164165

166+
void ParallelScavengeHeap::safepoint_synchronize_begin() {
167+
if (UseStringDeduplication) {
168+
SuspendibleThreadSet::synchronize();
169+
}
170+
}
171+
172+
void ParallelScavengeHeap::safepoint_synchronize_end() {
173+
if (UseStringDeduplication) {
174+
SuspendibleThreadSet::desynchronize();
175+
}
176+
}
165177
class PSIsScavengable : public BoolObjectClosure {
166178
bool do_object_b(oop obj) {
167179
return ParallelScavengeHeap::heap()->is_in_young(obj);

src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class ParallelScavengeHeap : public CollectedHeap {
139139
// Returns JNI_OK on success
140140
virtual jint initialize();
141141

142+
virtual void safepoint_synchronize_begin();
143+
virtual void safepoint_synchronize_end();
144+
142145
void post_initialize();
143146
void update_counters();
144147

src/hotspot/share/gc/parallel/psCompactionManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ void ParCompactionManager::reset_all_bitmap_query_caches() {
103103
}
104104
}
105105

106+
void ParCompactionManager::flush_all_string_dedup_requests() {
107+
uint parallel_gc_threads = ParallelScavengeHeap::heap()->workers().total_workers();
108+
for (uint i=0; i<=parallel_gc_threads; i++) {
109+
_manager_array[i]->flush_string_dedup_requests();
110+
}
111+
}
106112

107113
ParCompactionManager*
108114
ParCompactionManager::gc_thread_compaction_manager(uint index) {

src/hotspot/share/gc/parallel/psCompactionManager.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define SHARE_GC_PARALLEL_PSCOMPACTIONMANAGER_HPP
2727

2828
#include "gc/parallel/psParallelCompact.hpp"
29+
#include "gc/shared/stringdedup/stringDedup.hpp"
2930
#include "gc/shared/taskqueue.hpp"
3031
#include "gc/shared/taskTerminator.hpp"
3132
#include "memory/allocation.hpp"
@@ -88,6 +89,8 @@ class ParCompactionManager : public CHeapObj<mtGC> {
8889
oop _last_query_obj;
8990
size_t _last_query_ret;
9091

92+
StringDedup::Requests _string_dedup_requests;
93+
9194
static PSOldGen* old_gen() { return _old_gen; }
9295
static ObjectStartArray* start_array() { return _start_array; }
9396
static OopTaskQueueSet* oop_task_queues() { return _oop_task_queues; }
@@ -125,6 +128,10 @@ class ParCompactionManager : public CHeapObj<mtGC> {
125128
_last_query_ret = 0;
126129
}
127130

131+
void flush_string_dedup_requests() {
132+
_string_dedup_requests.flush();
133+
}
134+
128135
// Bitmap query support, cache last query and result
129136
HeapWord* last_query_begin() { return _last_query_beg; }
130137
oop last_query_object() { return _last_query_obj; }
@@ -136,6 +143,8 @@ class ParCompactionManager : public CHeapObj<mtGC> {
136143

137144
static void reset_all_bitmap_query_caches();
138145

146+
static void flush_all_string_dedup_requests();
147+
139148
RegionTaskQueue* region_stack() { return &_region_stack; }
140149

141150
static ParCompactionManager* get_vmthread_cm() { return _manager_array[ParallelGCThreads]; }

src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "classfile/javaClasses.inline.hpp"
3232
#include "gc/parallel/parMarkBitMap.hpp"
3333
#include "gc/parallel/psParallelCompact.inline.hpp"
34+
#include "gc/parallel/psStringDedup.hpp"
3435
#include "gc/shared/taskqueue.inline.hpp"
3536
#include "oops/access.inline.hpp"
3637
#include "oops/arrayOop.hpp"
@@ -108,6 +109,12 @@ inline void ParCompactionManager::mark_and_push(T* p) {
108109

109110
if (mark_bitmap()->is_unmarked(obj) && PSParallelCompact::mark_obj(obj)) {
110111
push(obj);
112+
113+
if (StringDedup::is_enabled() &&
114+
java_lang_String::is_instance_inlined(obj) &&
115+
psStringDedup::is_candidate_from_mark(obj)) {
116+
_string_dedup_requests.add(obj);
117+
}
111118
}
112119
}
113120
}

src/hotspot/share/gc/parallel/psParallelCompact.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "gc/parallel/psPromotionManager.inline.hpp"
4141
#include "gc/parallel/psRootType.hpp"
4242
#include "gc/parallel/psScavenge.hpp"
43+
#include "gc/parallel/psStringDedup.hpp"
4344
#include "gc/parallel/psYoungGen.hpp"
4445
#include "gc/shared/gcCause.hpp"
4546
#include "gc/shared/gcHeapSummary.hpp"
@@ -1021,6 +1022,8 @@ void PSParallelCompact::post_compact()
10211022
_space_info[id].publish_new_top();
10221023
}
10231024

1025+
ParCompactionManager::flush_all_string_dedup_requests();
1026+
10241027
MutableSpace* const eden_space = _space_info[eden_space_id].space();
10251028
MutableSpace* const from_space = _space_info[from_space_id].space();
10261029
MutableSpace* const to_space = _space_info[to_space_id].space();

src/hotspot/share/gc/parallel/psPromotionManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ bool PSPromotionManager::post_scavenge(YoungGCTracer& gc_tracer) {
121121
promotion_failure_occurred = true;
122122
}
123123
manager->flush_labs();
124+
manager->flush_string_dedup_requests();
124125
}
125126
if (!promotion_failure_occurred) {
126127
// If there was no promotion failure, the preserved mark stacks

src/hotspot/share/gc/parallel/psPromotionManager.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gc/shared/copyFailedInfo.hpp"
3030
#include "gc/shared/gcTrace.hpp"
3131
#include "gc/shared/preservedMarks.hpp"
32+
#include "gc/shared/stringdedup/stringDedup.hpp"
3233
#include "gc/shared/taskqueue.hpp"
3334
#include "memory/padded.hpp"
3435
#include "utilities/globalDefinitions.hpp"
@@ -91,6 +92,8 @@ class PSPromotionManager {
9192
PreservedMarks* _preserved_marks;
9293
PromotionFailedInfo _promotion_failed_info;
9394

95+
StringDedup::Requests _string_dedup_requests;
96+
9497
// Accessors
9598
static PSOldGen* old_gen() { return _old_gen; }
9699
static MutableSpace* young_space() { return _young_space; }
@@ -145,6 +148,8 @@ class PSPromotionManager {
145148
static void restore_preserved_marks();
146149

147150
void flush_labs();
151+
void flush_string_dedup_requests() { _string_dedup_requests.flush(); }
152+
148153
void drain_stacks(bool totally_drain) {
149154
drain_stacks_depth(totally_drain);
150155
}

src/hotspot/share/gc/parallel/psPromotionManager.inline.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "gc/parallel/psOldGen.hpp"
3333
#include "gc/parallel/psPromotionLAB.inline.hpp"
3434
#include "gc/parallel/psScavenge.inline.hpp"
35+
#include "gc/parallel/psStringDedup.hpp"
3536
#include "gc/shared/taskqueue.inline.hpp"
3637
#include "gc/shared/tlab_globals.hpp"
3738
#include "logging/log.hpp"
@@ -284,6 +285,12 @@ inline oop PSPromotionManager::copy_unmarked_to_survivor_space(oop o,
284285
} else {
285286
// we'll just push its contents
286287
push_contents(new_obj);
288+
289+
if (StringDedup::is_enabled() &&
290+
java_lang_String::is_instance_inlined(new_obj) &&
291+
psStringDedup::is_candidate_from_evacuation(new_obj, new_obj_is_tenured)) {
292+
_string_dedup_requests.add(o);
293+
}
287294
}
288295
return new_obj;
289296
} else {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2021, 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_PARALLEL_PSSTRINGDEDUP_HPP
26+
#define SHARE_GC_PARALLEL_PSSTRINGDEDUP_HPP
27+
28+
#include "gc/parallel/psScavenge.hpp"
29+
#include "gc/shared/stringdedup/stringDedup.hpp"
30+
#include "memory/allStatic.hpp"
31+
#include "oops/oopsHierarchy.hpp"
32+
33+
class psStringDedup : AllStatic {
34+
public:
35+
static bool is_candidate_from_mark(oop java_string) {
36+
// Candidate if string is being evacuated from young to old but has not
37+
// reached the deduplication age threshold, i.e. has not previously been a
38+
// candidate during its life in the young generation.
39+
return PSScavenge::is_obj_in_young(java_string) &&
40+
StringDedup::is_below_threshold_age(java_string->age());
41+
}
42+
43+
static bool is_candidate_from_evacuation(oop obj,
44+
bool obj_is_tenured) {
45+
return obj_is_tenured ?
46+
StringDedup::is_below_threshold_age(obj->age()) :
47+
StringDedup::is_threshold_age(obj->age());
48+
}
49+
};
50+
#endif // SHARE_GC_PARALLEL_PSSTRINGDEDUP_HPP

0 commit comments

Comments
 (0)