pliden@6413: /* pliden@6413: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. pliden@6413: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. pliden@6413: * pliden@6413: * This code is free software; you can redistribute it and/or modify it pliden@6413: * under the terms of the GNU General Public License version 2 only, as pliden@6413: * published by the Free Software Foundation. pliden@6413: * pliden@6413: * This code is distributed in the hope that it will be useful, but WITHOUT pliden@6413: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or pliden@6413: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License pliden@6413: * version 2 for more details (a copy is included in the LICENSE file that pliden@6413: * accompanied this code). pliden@6413: * pliden@6413: * You should have received a copy of the GNU General Public License version pliden@6413: * 2 along with this work; if not, write to the Free Software Foundation, pliden@6413: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. pliden@6413: * pliden@6413: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA pliden@6413: * or visit www.oracle.com if you need additional information or have any pliden@6413: * questions. pliden@6413: * pliden@6413: */ pliden@6413: pliden@6413: #include "precompiled.hpp" pliden@6413: #include "gc_implementation/g1/g1Log.hpp" pliden@6413: #include "gc_implementation/g1/g1StringDedup.hpp" pliden@6413: #include "gc_implementation/g1/g1StringDedupTable.hpp" pliden@6413: #include "gc_implementation/g1/g1StringDedupThread.hpp" pliden@6413: #include "gc_implementation/g1/g1StringDedupQueue.hpp" pliden@6413: pliden@6413: G1StringDedupThread* G1StringDedupThread::_thread = NULL; pliden@6413: pliden@6413: G1StringDedupThread::G1StringDedupThread() : pliden@6413: ConcurrentGCThread() { pliden@6413: set_name("String Deduplication Thread"); pliden@6413: create_and_start(); pliden@6413: } pliden@6413: pliden@6413: G1StringDedupThread::~G1StringDedupThread() { pliden@6413: ShouldNotReachHere(); pliden@6413: } pliden@6413: pliden@6413: void G1StringDedupThread::create() { pliden@6413: assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); pliden@6413: assert(_thread == NULL, "One string deduplication thread allowed"); pliden@6413: _thread = new G1StringDedupThread(); pliden@6413: } pliden@6413: pliden@6413: G1StringDedupThread* G1StringDedupThread::thread() { pliden@6413: assert(G1StringDedup::is_enabled(), "String deduplication not enabled"); pliden@6413: assert(_thread != NULL, "String deduplication thread not created"); pliden@6413: return _thread; pliden@6413: } pliden@6413: pliden@6413: void G1StringDedupThread::print_on(outputStream* st) const { pliden@6413: st->print("\"%s\" ", name()); pliden@6413: Thread::print_on(st); pliden@6413: st->cr(); pliden@6413: } pliden@6413: pliden@6413: void G1StringDedupThread::run() { pliden@6413: G1StringDedupStat total_stat; pliden@6413: pliden@6413: initialize_in_thread(); pliden@6413: wait_for_universe_init(); pliden@6413: pliden@6413: // Main loop pliden@6413: for (;;) { pliden@6413: G1StringDedupStat stat; pliden@6413: pliden@6413: stat.mark_idle(); pliden@6413: pliden@6413: // Wait for the queue to become non-empty pliden@6413: G1StringDedupQueue::wait(); pliden@6413: pliden@6413: // Include this thread in safepoints pliden@6413: stsJoin(); pliden@6413: pliden@6413: stat.mark_exec(); pliden@6413: pliden@6413: // Process the queue pliden@6413: for (;;) { pliden@6413: oop java_string = G1StringDedupQueue::pop(); pliden@6413: if (java_string == NULL) { pliden@6413: break; pliden@6413: } pliden@6413: pliden@6413: G1StringDedupTable::deduplicate(java_string, stat); pliden@6413: pliden@6413: // Safepoint this thread if needed pliden@6413: if (stsShouldYield()) { pliden@6413: stat.mark_block(); pliden@6413: stsYield(NULL); pliden@6413: stat.mark_unblock(); pliden@6413: } pliden@6413: } pliden@6413: pliden@6413: G1StringDedupTable::trim_entry_cache(); pliden@6413: pliden@6413: stat.mark_done(); pliden@6413: pliden@6413: // Print statistics pliden@6413: total_stat.add(stat); pliden@6413: print(gclog_or_tty, stat, total_stat); pliden@6413: pliden@6413: // Exclude this thread from safepoints pliden@6413: stsLeave(); pliden@6413: } pliden@6413: pliden@6413: ShouldNotReachHere(); pliden@6413: } pliden@6413: pliden@6413: void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) { pliden@6413: if (G1Log::fine() || PrintStringDeduplicationStatistics) { pliden@6413: G1StringDedupStat::print_summary(st, last_stat, total_stat); pliden@6413: if (PrintStringDeduplicationStatistics) { pliden@6413: G1StringDedupStat::print_statistics(st, last_stat, false); pliden@6413: G1StringDedupStat::print_statistics(st, total_stat, true); pliden@6413: G1StringDedupTable::print_statistics(st); pliden@6413: G1StringDedupQueue::print_statistics(st); pliden@6413: } pliden@6413: } pliden@6413: }