1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1StringDedupThread.cpp Tue Mar 18 19:07:22 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/g1/g1Log.hpp" 1.30 +#include "gc_implementation/g1/g1StringDedup.hpp" 1.31 +#include "gc_implementation/g1/g1StringDedupTable.hpp" 1.32 +#include "gc_implementation/g1/g1StringDedupThread.hpp" 1.33 +#include "gc_implementation/g1/g1StringDedupQueue.hpp" 1.34 + 1.35 +G1StringDedupThread* G1StringDedupThread::_thread = NULL; 1.36 + 1.37 +G1StringDedupThread::G1StringDedupThread() : 1.38 + ConcurrentGCThread() { 1.39 + set_name("String Deduplication Thread"); 1.40 + create_and_start(); 1.41 +} 1.42 + 1.43 +G1StringDedupThread::~G1StringDedupThread() { 1.44 + ShouldNotReachHere(); 1.45 +} 1.46 + 1.47 +void G1StringDedupThread::create() { 1.48 + assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); 1.49 + assert(_thread == NULL, "One string deduplication thread allowed"); 1.50 + _thread = new G1StringDedupThread(); 1.51 +} 1.52 + 1.53 +G1StringDedupThread* G1StringDedupThread::thread() { 1.54 + assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); 1.55 + assert(_thread != NULL, "String deduplication thread not created"); 1.56 + return _thread; 1.57 +} 1.58 + 1.59 +void G1StringDedupThread::print_on(outputStream* st) const { 1.60 + st->print("\"%s\" ", name()); 1.61 + Thread::print_on(st); 1.62 + st->cr(); 1.63 +} 1.64 + 1.65 +void G1StringDedupThread::run() { 1.66 + G1StringDedupStat total_stat; 1.67 + 1.68 + initialize_in_thread(); 1.69 + wait_for_universe_init(); 1.70 + 1.71 + // Main loop 1.72 + for (;;) { 1.73 + G1StringDedupStat stat; 1.74 + 1.75 + stat.mark_idle(); 1.76 + 1.77 + // Wait for the queue to become non-empty 1.78 + G1StringDedupQueue::wait(); 1.79 + 1.80 + // Include this thread in safepoints 1.81 + stsJoin(); 1.82 + 1.83 + stat.mark_exec(); 1.84 + 1.85 + // Process the queue 1.86 + for (;;) { 1.87 + oop java_string = G1StringDedupQueue::pop(); 1.88 + if (java_string == NULL) { 1.89 + break; 1.90 + } 1.91 + 1.92 + G1StringDedupTable::deduplicate(java_string, stat); 1.93 + 1.94 + // Safepoint this thread if needed 1.95 + if (stsShouldYield()) { 1.96 + stat.mark_block(); 1.97 + stsYield(NULL); 1.98 + stat.mark_unblock(); 1.99 + } 1.100 + } 1.101 + 1.102 + G1StringDedupTable::trim_entry_cache(); 1.103 + 1.104 + stat.mark_done(); 1.105 + 1.106 + // Print statistics 1.107 + total_stat.add(stat); 1.108 + print(gclog_or_tty, stat, total_stat); 1.109 + 1.110 + // Exclude this thread from safepoints 1.111 + stsLeave(); 1.112 + } 1.113 + 1.114 + ShouldNotReachHere(); 1.115 +} 1.116 + 1.117 +void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) { 1.118 + if (G1Log::fine() || PrintStringDeduplicationStatistics) { 1.119 + G1StringDedupStat::print_summary(st, last_stat, total_stat); 1.120 + if (PrintStringDeduplicationStatistics) { 1.121 + G1StringDedupStat::print_statistics(st, last_stat, false); 1.122 + G1StringDedupStat::print_statistics(st, total_stat, true); 1.123 + G1StringDedupTable::print_statistics(st); 1.124 + G1StringDedupQueue::print_statistics(st); 1.125 + } 1.126 + } 1.127 +}