src/share/vm/gc_implementation/g1/g1StringDedup.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7658
c3fcc09c9239
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "classfile/javaClasses.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 28 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
aoqi@0 29 #include "gc_implementation/g1/g1StringDedup.hpp"
aoqi@0 30 #include "gc_implementation/g1/g1StringDedupQueue.hpp"
aoqi@0 31 #include "gc_implementation/g1/g1StringDedupStat.hpp"
aoqi@0 32 #include "gc_implementation/g1/g1StringDedupTable.hpp"
aoqi@0 33 #include "gc_implementation/g1/g1StringDedupThread.hpp"
aoqi@0 34
aoqi@0 35 bool G1StringDedup::_enabled = false;
aoqi@0 36
aoqi@0 37 void G1StringDedup::initialize() {
aoqi@0 38 assert(UseG1GC, "String deduplication only available with G1");
aoqi@0 39 if (UseStringDeduplication) {
aoqi@0 40 _enabled = true;
aoqi@0 41 G1StringDedupQueue::create();
aoqi@0 42 G1StringDedupTable::create();
aoqi@0 43 G1StringDedupThread::create();
aoqi@0 44 }
aoqi@0 45 }
aoqi@0 46
aoqi@0 47 void G1StringDedup::stop() {
aoqi@0 48 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 49 G1StringDedupThread::stop();
aoqi@0 50 }
aoqi@0 51
aoqi@0 52 bool G1StringDedup::is_candidate_from_mark(oop obj) {
aoqi@0 53 if (java_lang_String::is_instance(obj)) {
aoqi@0 54 bool from_young = G1CollectedHeap::heap()->heap_region_containing_raw(obj)->is_young();
aoqi@0 55 if (from_young && obj->age() < StringDeduplicationAgeThreshold) {
aoqi@0 56 // Candidate found. String is being evacuated from young to old but has not
aoqi@0 57 // reached the deduplication age threshold, i.e. has not previously been a
aoqi@0 58 // candidate during its life in the young generation.
aoqi@0 59 return true;
aoqi@0 60 }
aoqi@0 61 }
aoqi@0 62
aoqi@0 63 // Not a candidate
aoqi@0 64 return false;
aoqi@0 65 }
aoqi@0 66
aoqi@0 67 void G1StringDedup::enqueue_from_mark(oop java_string) {
aoqi@0 68 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 69 if (is_candidate_from_mark(java_string)) {
aoqi@0 70 G1StringDedupQueue::push(0 /* worker_id */, java_string);
aoqi@0 71 }
aoqi@0 72 }
aoqi@0 73
aoqi@0 74 bool G1StringDedup::is_candidate_from_evacuation(bool from_young, bool to_young, oop obj) {
aoqi@0 75 if (from_young && java_lang_String::is_instance(obj)) {
aoqi@0 76 if (to_young && obj->age() == StringDeduplicationAgeThreshold) {
aoqi@0 77 // Candidate found. String is being evacuated from young to young and just
aoqi@0 78 // reached the deduplication age threshold.
aoqi@0 79 return true;
aoqi@0 80 }
aoqi@0 81 if (!to_young && obj->age() < StringDeduplicationAgeThreshold) {
aoqi@0 82 // Candidate found. String is being evacuated from young to old but has not
aoqi@0 83 // reached the deduplication age threshold, i.e. has not previously been a
aoqi@0 84 // candidate during its life in the young generation.
aoqi@0 85 return true;
aoqi@0 86 }
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 // Not a candidate
aoqi@0 90 return false;
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 void G1StringDedup::enqueue_from_evacuation(bool from_young, bool to_young, uint worker_id, oop java_string) {
aoqi@0 94 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 95 if (is_candidate_from_evacuation(from_young, to_young, java_string)) {
aoqi@0 96 G1StringDedupQueue::push(worker_id, java_string);
aoqi@0 97 }
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 void G1StringDedup::deduplicate(oop java_string) {
aoqi@0 101 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 102 G1StringDedupStat dummy; // Statistics from this path is never used
aoqi@0 103 G1StringDedupTable::deduplicate(java_string, dummy);
aoqi@0 104 }
aoqi@0 105
aoqi@0 106 void G1StringDedup::oops_do(OopClosure* keep_alive) {
aoqi@0 107 assert(is_enabled(), "String deduplication not enabled");
brutisso@7658 108 unlink_or_oops_do(NULL, keep_alive, true /* allow_resize_and_rehash */);
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 void G1StringDedup::unlink(BoolObjectClosure* is_alive) {
aoqi@0 112 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 113 // Don't allow a potential resize or rehash during unlink, as the unlink
aoqi@0 114 // operation itself might remove enough entries to invalidate such a decision.
aoqi@0 115 unlink_or_oops_do(is_alive, NULL, false /* allow_resize_and_rehash */);
aoqi@0 116 }
aoqi@0 117
aoqi@0 118 //
aoqi@0 119 // Task for parallel unlink_or_oops_do() operation on the deduplication queue
aoqi@0 120 // and table.
aoqi@0 121 //
aoqi@0 122 class G1StringDedupUnlinkOrOopsDoTask : public AbstractGangTask {
aoqi@0 123 private:
aoqi@0 124 G1StringDedupUnlinkOrOopsDoClosure _cl;
brutisso@7658 125 G1GCPhaseTimes* _phase_times;
aoqi@0 126
aoqi@0 127 public:
aoqi@0 128 G1StringDedupUnlinkOrOopsDoTask(BoolObjectClosure* is_alive,
aoqi@0 129 OopClosure* keep_alive,
brutisso@7658 130 bool allow_resize_and_rehash,
brutisso@7658 131 G1GCPhaseTimes* phase_times) :
aoqi@0 132 AbstractGangTask("G1StringDedupUnlinkOrOopsDoTask"),
brutisso@7658 133 _cl(is_alive, keep_alive, allow_resize_and_rehash), _phase_times(phase_times) { }
aoqi@0 134
aoqi@0 135 virtual void work(uint worker_id) {
brutisso@7658 136 {
brutisso@7658 137 G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupQueueFixup, worker_id);
brutisso@7658 138 G1StringDedupQueue::unlink_or_oops_do(&_cl);
brutisso@7658 139 }
brutisso@7658 140 {
brutisso@7658 141 G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupTableFixup, worker_id);
brutisso@7658 142 G1StringDedupTable::unlink_or_oops_do(&_cl, worker_id);
brutisso@7658 143 }
aoqi@0 144 }
aoqi@0 145 };
aoqi@0 146
brutisso@7658 147 void G1StringDedup::unlink_or_oops_do(BoolObjectClosure* is_alive,
brutisso@7658 148 OopClosure* keep_alive,
brutisso@7658 149 bool allow_resize_and_rehash,
brutisso@7658 150 G1GCPhaseTimes* phase_times) {
aoqi@0 151 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 152
brutisso@7658 153 G1StringDedupUnlinkOrOopsDoTask task(is_alive, keep_alive, allow_resize_and_rehash, phase_times);
aoqi@0 154 if (G1CollectedHeap::use_parallel_gc_threads()) {
aoqi@0 155 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 156 g1h->set_par_threads();
aoqi@0 157 g1h->workers()->run_task(&task);
aoqi@0 158 g1h->set_par_threads(0);
aoqi@0 159 } else {
aoqi@0 160 task.work(0);
aoqi@0 161 }
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 void G1StringDedup::threads_do(ThreadClosure* tc) {
aoqi@0 165 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 166 tc->do_thread(G1StringDedupThread::thread());
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 void G1StringDedup::print_worker_threads_on(outputStream* st) {
aoqi@0 170 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 171 G1StringDedupThread::thread()->print_on(st);
aoqi@0 172 st->cr();
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 void G1StringDedup::verify() {
aoqi@0 176 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 177 G1StringDedupQueue::verify();
aoqi@0 178 G1StringDedupTable::verify();
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 G1StringDedupUnlinkOrOopsDoClosure::G1StringDedupUnlinkOrOopsDoClosure(BoolObjectClosure* is_alive,
aoqi@0 182 OopClosure* keep_alive,
aoqi@0 183 bool allow_resize_and_rehash) :
aoqi@0 184 _is_alive(is_alive),
aoqi@0 185 _keep_alive(keep_alive),
aoqi@0 186 _resized_table(NULL),
aoqi@0 187 _rehashed_table(NULL),
aoqi@0 188 _next_queue(0),
aoqi@0 189 _next_bucket(0) {
aoqi@0 190 if (allow_resize_and_rehash) {
aoqi@0 191 // If both resize and rehash is needed, only do resize. Rehash of
aoqi@0 192 // the table will eventually happen if the situation persists.
aoqi@0 193 _resized_table = G1StringDedupTable::prepare_resize();
aoqi@0 194 if (!is_resizing()) {
aoqi@0 195 _rehashed_table = G1StringDedupTable::prepare_rehash();
aoqi@0 196 }
aoqi@0 197 }
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 G1StringDedupUnlinkOrOopsDoClosure::~G1StringDedupUnlinkOrOopsDoClosure() {
aoqi@0 201 assert(!is_resizing() || !is_rehashing(), "Can not both resize and rehash");
aoqi@0 202 if (is_resizing()) {
aoqi@0 203 G1StringDedupTable::finish_resize(_resized_table);
aoqi@0 204 } else if (is_rehashing()) {
aoqi@0 205 G1StringDedupTable::finish_rehash(_rehashed_table);
aoqi@0 206 }
aoqi@0 207 }

mercurial