1 /* 2 * Copyright (c) 2014, 2017, 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 #include "precompiled.hpp" 26 #include "classfile/stringTable.hpp" 27 #include "gc/g1/g1StringDedup.hpp" 28 #include "gc/g1/g1StringDedupQueue.hpp" 29 #include "gc/g1/g1StringDedupTable.hpp" 30 #include "gc/g1/g1StringDedupThread.hpp" 31 #include "gc/shared/suspendibleThreadSet.hpp" 32 #include "logging/log.hpp" 33 #include "oops/access.inline.hpp" 34 #include "oops/oop.inline.hpp" 35 #include "runtime/atomic.hpp" 36 37 G1StringDedupThread* G1StringDedupThread::_thread = NULL; 38 39 G1StringDedupThread::G1StringDedupThread() : 40 ConcurrentGCThread() { 41 set_name("G1 StrDedup"); 42 create_and_start(); 43 } 44 45 G1StringDedupThread::~G1StringDedupThread() { 46 ShouldNotReachHere(); 47 } 48 49 void G1StringDedupThread::create() { 50 assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); 51 assert(_thread == NULL, "One string deduplication thread allowed"); 52 _thread = new G1StringDedupThread(); 53 } 54 55 G1StringDedupThread* G1StringDedupThread::thread() { 56 assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); 57 assert(_thread != NULL, "String deduplication thread not created"); 58 return _thread; 59 } 60 61 class G1StringDedupSharedClosure: public OopClosure { 62 private: 63 G1StringDedupStat& _stat; 64 65 public: 66 G1StringDedupSharedClosure(G1StringDedupStat& stat) : _stat(stat) {} 67 68 virtual void do_oop(oop* p) { ShouldNotReachHere(); } 69 virtual void do_oop(narrowOop* p) { 70 oop java_string = RawAccess<>::oop_load(p); 71 G1StringDedupTable::deduplicate(java_string, _stat); 72 } 73 }; 74 75 // The CDS archive does not include the string dedupication table. Only the string 76 // table is saved in the archive. The shared strings from CDS archive need to be 77 // added to the string dedupication table before deduplication occurs. That is 78 // done in the begining of the G1StringDedupThread (see G1StringDedupThread::run() 79 // below). 80 void G1StringDedupThread::deduplicate_shared_strings(G1StringDedupStat& stat) { 81 G1StringDedupSharedClosure sharedStringDedup(stat); 82 StringTable::shared_oops_do(&sharedStringDedup); 83 } 84 85 void G1StringDedupThread::run_service() { 86 G1StringDedupStat total_stat; 87 88 deduplicate_shared_strings(total_stat); 89 90 // Main loop 91 for (;;) { 92 G1StringDedupStat stat; 93 94 stat.mark_idle(); 95 96 // Wait for the queue to become non-empty 97 G1StringDedupQueue::wait(); 98 if (should_terminate()) { 99 break; 100 } 101 102 { 103 // Include thread in safepoints 104 SuspendibleThreadSetJoiner sts_join; 105 106 stat.mark_exec(); 107 print_start(stat); 108 109 // Process the queue 110 for (;;) { 111 oop java_string = G1StringDedupQueue::pop(); 112 if (java_string == NULL) { 113 break; 114 } 115 116 G1StringDedupTable::deduplicate(java_string, stat); 117 118 // Safepoint this thread if needed 119 if (sts_join.should_yield()) { 120 stat.mark_block(); 121 sts_join.yield(); 122 stat.mark_unblock(); 123 } 124 } 125 126 stat.mark_done(); 127 128 total_stat.add(stat); 129 print_end(stat, total_stat); 130 } 131 132 G1StringDedupTable::clean_entry_cache(); 133 } 134 } 135 136 void G1StringDedupThread::stop_service() { 137 G1StringDedupQueue::cancel_wait(); 138 } 139 140 void G1StringDedupThread::print_start(const G1StringDedupStat& last_stat) { 141 G1StringDedupStat::print_start(last_stat); 142 } 143 144 void G1StringDedupThread::print_end(const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) { 145 G1StringDedupStat::print_end(last_stat, total_stat); 146 if (log_is_enabled(Debug, gc, stringdedup)) { 147 G1StringDedupStat::print_statistics(last_stat, false); 148 G1StringDedupStat::print_statistics(total_stat, true); 149 G1StringDedupTable::print_statistics(); 150 G1StringDedupQueue::print_statistics(); 151 } 152 } | 1 /* 2 * Copyright (c) 2014, 2018, 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 #include "precompiled.hpp" 26 #include "classfile/stringTable.hpp" 27 #include "gc/shared/stringdedup/stringDedup.hpp" 28 #include "gc/shared/stringdedup/stringDedupQueue.hpp" 29 #include "gc/shared/stringdedup/stringDedupQueue.inline.hpp" 30 #include "gc/shared/stringdedup/stringDedupTable.hpp" 31 #include "gc/shared/stringdedup/stringDedupThread.hpp" 32 #include "gc/shared/suspendibleThreadSet.hpp" 33 #include "logging/log.hpp" 34 #include "oops/access.inline.hpp" 35 #include "oops/oop.inline.hpp" 36 #include "runtime/atomic.hpp" 37 38 StringDedupThread* StringDedupThread::_thread = NULL; 39 40 StringDedupThread::StringDedupThread() : 41 ConcurrentGCThread() { 42 set_name("StrDedup"); 43 create_and_start(); 44 } 45 46 StringDedupThread::~StringDedupThread() { 47 ShouldNotReachHere(); 48 } 49 50 StringDedupThread* StringDedupThread::thread() { 51 assert(_thread != NULL, "String deduplication thread not created"); 52 return _thread; 53 } 54 55 class StringDedupSharedClosure: public OopClosure { 56 private: 57 StringDedupStat* _stat; 58 59 public: 60 StringDedupSharedClosure(StringDedupStat* stat) : _stat(stat) {} 61 62 virtual void do_oop(oop* p) { ShouldNotReachHere(); } 63 virtual void do_oop(narrowOop* p) { 64 oop java_string = RawAccess<>::oop_load(p); 65 StringDedupTable::deduplicate(java_string, _stat); 66 } 67 }; 68 69 // The CDS archive does not include the string dedupication table. Only the string 70 // table is saved in the archive. The shared strings from CDS archive need to be 71 // added to the string dedupication table before deduplication occurs. That is 72 // done in the begining of the StringDedupThread (see StringDedupThread::do_deduplication()). 73 void StringDedupThread::deduplicate_shared_strings(StringDedupStat* stat) { 74 StringDedupSharedClosure sharedStringDedup(stat); 75 StringTable::shared_oops_do(&sharedStringDedup); 76 } 77 78 void StringDedupThread::stop_service() { 79 StringDedupQueue::cancel_wait(); 80 } 81 82 void StringDedupThread::print_start(const StringDedupStat* last_stat) { 83 StringDedupStat::print_start(last_stat); 84 } 85 86 void StringDedupThread::print_end(const StringDedupStat* last_stat, const StringDedupStat* total_stat) { 87 StringDedupStat::print_end(last_stat, total_stat); 88 if (log_is_enabled(Debug, gc, stringdedup)) { 89 last_stat->print_statistics(false); 90 total_stat->print_statistics(true); 91 92 StringDedupTable::print_statistics(); 93 StringDedupQueue::print_statistics(); 94 } 95 } |