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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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");
aoqi@0 108 unlink_or_oops_do(NULL, keep_alive);
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;
aoqi@0 125
aoqi@0 126 public:
aoqi@0 127 G1StringDedupUnlinkOrOopsDoTask(BoolObjectClosure* is_alive,
aoqi@0 128 OopClosure* keep_alive,
aoqi@0 129 bool allow_resize_and_rehash) :
aoqi@0 130 AbstractGangTask("G1StringDedupUnlinkOrOopsDoTask"),
aoqi@0 131 _cl(is_alive, keep_alive, allow_resize_and_rehash) {
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 virtual void work(uint worker_id) {
aoqi@0 135 double queue_fixup_start = os::elapsedTime();
aoqi@0 136 G1StringDedupQueue::unlink_or_oops_do(&_cl);
aoqi@0 137
aoqi@0 138 double table_fixup_start = os::elapsedTime();
aoqi@0 139 G1StringDedupTable::unlink_or_oops_do(&_cl, worker_id);
aoqi@0 140
aoqi@0 141 double queue_fixup_time_ms = (table_fixup_start - queue_fixup_start) * 1000.0;
aoqi@0 142 double table_fixup_time_ms = (os::elapsedTime() - table_fixup_start) * 1000.0;
aoqi@0 143 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy();
aoqi@0 144 g1p->phase_times()->record_string_dedup_queue_fixup_worker_time(worker_id, queue_fixup_time_ms);
aoqi@0 145 g1p->phase_times()->record_string_dedup_table_fixup_worker_time(worker_id, table_fixup_time_ms);
aoqi@0 146 }
aoqi@0 147 };
aoqi@0 148
aoqi@0 149 void G1StringDedup::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive, bool allow_resize_and_rehash) {
aoqi@0 150 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 151 G1CollectorPolicy* g1p = G1CollectedHeap::heap()->g1_policy();
aoqi@0 152 g1p->phase_times()->note_string_dedup_fixup_start();
aoqi@0 153 double fixup_start = os::elapsedTime();
aoqi@0 154
aoqi@0 155 G1StringDedupUnlinkOrOopsDoTask task(is_alive, keep_alive, allow_resize_and_rehash);
aoqi@0 156 if (G1CollectedHeap::use_parallel_gc_threads()) {
aoqi@0 157 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 158 g1h->set_par_threads();
aoqi@0 159 g1h->workers()->run_task(&task);
aoqi@0 160 g1h->set_par_threads(0);
aoqi@0 161 } else {
aoqi@0 162 task.work(0);
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 double fixup_time_ms = (os::elapsedTime() - fixup_start) * 1000.0;
aoqi@0 166 g1p->phase_times()->record_string_dedup_fixup_time(fixup_time_ms);
aoqi@0 167 g1p->phase_times()->note_string_dedup_fixup_end();
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 void G1StringDedup::threads_do(ThreadClosure* tc) {
aoqi@0 171 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 172 tc->do_thread(G1StringDedupThread::thread());
aoqi@0 173 }
aoqi@0 174
aoqi@0 175 void G1StringDedup::print_worker_threads_on(outputStream* st) {
aoqi@0 176 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 177 G1StringDedupThread::thread()->print_on(st);
aoqi@0 178 st->cr();
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 void G1StringDedup::verify() {
aoqi@0 182 assert(is_enabled(), "String deduplication not enabled");
aoqi@0 183 G1StringDedupQueue::verify();
aoqi@0 184 G1StringDedupTable::verify();
aoqi@0 185 }
aoqi@0 186
aoqi@0 187 G1StringDedupUnlinkOrOopsDoClosure::G1StringDedupUnlinkOrOopsDoClosure(BoolObjectClosure* is_alive,
aoqi@0 188 OopClosure* keep_alive,
aoqi@0 189 bool allow_resize_and_rehash) :
aoqi@0 190 _is_alive(is_alive),
aoqi@0 191 _keep_alive(keep_alive),
aoqi@0 192 _resized_table(NULL),
aoqi@0 193 _rehashed_table(NULL),
aoqi@0 194 _next_queue(0),
aoqi@0 195 _next_bucket(0) {
aoqi@0 196 if (allow_resize_and_rehash) {
aoqi@0 197 // If both resize and rehash is needed, only do resize. Rehash of
aoqi@0 198 // the table will eventually happen if the situation persists.
aoqi@0 199 _resized_table = G1StringDedupTable::prepare_resize();
aoqi@0 200 if (!is_resizing()) {
aoqi@0 201 _rehashed_table = G1StringDedupTable::prepare_rehash();
aoqi@0 202 }
aoqi@0 203 }
aoqi@0 204 }
aoqi@0 205
aoqi@0 206 G1StringDedupUnlinkOrOopsDoClosure::~G1StringDedupUnlinkOrOopsDoClosure() {
aoqi@0 207 assert(!is_resizing() || !is_rehashing(), "Can not both resize and rehash");
aoqi@0 208 if (is_resizing()) {
aoqi@0 209 G1StringDedupTable::finish_resize(_resized_table);
aoqi@0 210 } else if (is_rehashing()) {
aoqi@0 211 G1StringDedupTable::finish_rehash(_rehashed_table);
aoqi@0 212 }
aoqi@0 213 }

mercurial