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

Tue, 18 Mar 2014 19:07:22 +0100

author
pliden
date
Tue, 18 Mar 2014 19:07:22 +0100
changeset 6413
595c0f60d50d
child 6690
1772223a25a2
permissions
-rw-r--r--

8029075: String deduplication in G1
Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192
Reviewed-by: brutisso, tschatzl, coleenp

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 "gc_implementation/g1/g1Log.hpp"
pliden@6413 27 #include "gc_implementation/g1/g1StringDedup.hpp"
pliden@6413 28 #include "gc_implementation/g1/g1StringDedupTable.hpp"
pliden@6413 29 #include "gc_implementation/g1/g1StringDedupThread.hpp"
pliden@6413 30 #include "gc_implementation/g1/g1StringDedupQueue.hpp"
pliden@6413 31
pliden@6413 32 G1StringDedupThread* G1StringDedupThread::_thread = NULL;
pliden@6413 33
pliden@6413 34 G1StringDedupThread::G1StringDedupThread() :
pliden@6413 35 ConcurrentGCThread() {
pliden@6413 36 set_name("String Deduplication Thread");
pliden@6413 37 create_and_start();
pliden@6413 38 }
pliden@6413 39
pliden@6413 40 G1StringDedupThread::~G1StringDedupThread() {
pliden@6413 41 ShouldNotReachHere();
pliden@6413 42 }
pliden@6413 43
pliden@6413 44 void G1StringDedupThread::create() {
pliden@6413 45 assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
pliden@6413 46 assert(_thread == NULL, "One string deduplication thread allowed");
pliden@6413 47 _thread = new G1StringDedupThread();
pliden@6413 48 }
pliden@6413 49
pliden@6413 50 G1StringDedupThread* G1StringDedupThread::thread() {
pliden@6413 51 assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
pliden@6413 52 assert(_thread != NULL, "String deduplication thread not created");
pliden@6413 53 return _thread;
pliden@6413 54 }
pliden@6413 55
pliden@6413 56 void G1StringDedupThread::print_on(outputStream* st) const {
pliden@6413 57 st->print("\"%s\" ", name());
pliden@6413 58 Thread::print_on(st);
pliden@6413 59 st->cr();
pliden@6413 60 }
pliden@6413 61
pliden@6413 62 void G1StringDedupThread::run() {
pliden@6413 63 G1StringDedupStat total_stat;
pliden@6413 64
pliden@6413 65 initialize_in_thread();
pliden@6413 66 wait_for_universe_init();
pliden@6413 67
pliden@6413 68 // Main loop
pliden@6413 69 for (;;) {
pliden@6413 70 G1StringDedupStat stat;
pliden@6413 71
pliden@6413 72 stat.mark_idle();
pliden@6413 73
pliden@6413 74 // Wait for the queue to become non-empty
pliden@6413 75 G1StringDedupQueue::wait();
pliden@6413 76
pliden@6413 77 // Include this thread in safepoints
pliden@6413 78 stsJoin();
pliden@6413 79
pliden@6413 80 stat.mark_exec();
pliden@6413 81
pliden@6413 82 // Process the queue
pliden@6413 83 for (;;) {
pliden@6413 84 oop java_string = G1StringDedupQueue::pop();
pliden@6413 85 if (java_string == NULL) {
pliden@6413 86 break;
pliden@6413 87 }
pliden@6413 88
pliden@6413 89 G1StringDedupTable::deduplicate(java_string, stat);
pliden@6413 90
pliden@6413 91 // Safepoint this thread if needed
pliden@6413 92 if (stsShouldYield()) {
pliden@6413 93 stat.mark_block();
pliden@6413 94 stsYield(NULL);
pliden@6413 95 stat.mark_unblock();
pliden@6413 96 }
pliden@6413 97 }
pliden@6413 98
pliden@6413 99 G1StringDedupTable::trim_entry_cache();
pliden@6413 100
pliden@6413 101 stat.mark_done();
pliden@6413 102
pliden@6413 103 // Print statistics
pliden@6413 104 total_stat.add(stat);
pliden@6413 105 print(gclog_or_tty, stat, total_stat);
pliden@6413 106
pliden@6413 107 // Exclude this thread from safepoints
pliden@6413 108 stsLeave();
pliden@6413 109 }
pliden@6413 110
pliden@6413 111 ShouldNotReachHere();
pliden@6413 112 }
pliden@6413 113
pliden@6413 114 void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
pliden@6413 115 if (G1Log::fine() || PrintStringDeduplicationStatistics) {
pliden@6413 116 G1StringDedupStat::print_summary(st, last_stat, total_stat);
pliden@6413 117 if (PrintStringDeduplicationStatistics) {
pliden@6413 118 G1StringDedupStat::print_statistics(st, last_stat, false);
pliden@6413 119 G1StringDedupStat::print_statistics(st, total_stat, true);
pliden@6413 120 G1StringDedupTable::print_statistics(st);
pliden@6413 121 G1StringDedupQueue::print_statistics(st);
pliden@6413 122 }
pliden@6413 123 }
pliden@6413 124 }

mercurial