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

Thu, 14 Jun 2018 09:15:08 -0700

author
kevinw
date
Thu, 14 Jun 2018 09:15:08 -0700
changeset 9327
f96fcd9e1e1b
parent 7658
c3fcc09c9239
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
Summary: Need to add a space between macro identifier and string literal
Reviewed-by: bpittore, stefank, dholmes, kbarrett

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

mercurial