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

Fri, 11 Apr 2014 11:00:12 +0200

author
pliden
date
Fri, 11 Apr 2014 11:00:12 +0200
changeset 6690
1772223a25a2
parent 6413
595c0f60d50d
child 6876
710a3c8b516e
child 6906
581e70386ec9
permissions
-rw-r--r--

8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
Reviewed-by: brutisso, mgerdin

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@6690 76 if (_should_terminate) {
pliden@6690 77 break;
pliden@6690 78 }
pliden@6413 79
pliden@6413 80 // Include this thread in safepoints
pliden@6413 81 stsJoin();
pliden@6413 82
pliden@6413 83 stat.mark_exec();
pliden@6413 84
pliden@6413 85 // Process the queue
pliden@6413 86 for (;;) {
pliden@6413 87 oop java_string = G1StringDedupQueue::pop();
pliden@6413 88 if (java_string == NULL) {
pliden@6413 89 break;
pliden@6413 90 }
pliden@6413 91
pliden@6413 92 G1StringDedupTable::deduplicate(java_string, stat);
pliden@6413 93
pliden@6413 94 // Safepoint this thread if needed
pliden@6413 95 if (stsShouldYield()) {
pliden@6413 96 stat.mark_block();
pliden@6413 97 stsYield(NULL);
pliden@6413 98 stat.mark_unblock();
pliden@6413 99 }
pliden@6413 100 }
pliden@6413 101
pliden@6413 102 G1StringDedupTable::trim_entry_cache();
pliden@6413 103
pliden@6413 104 stat.mark_done();
pliden@6413 105
pliden@6413 106 // Print statistics
pliden@6413 107 total_stat.add(stat);
pliden@6413 108 print(gclog_or_tty, stat, total_stat);
pliden@6413 109
pliden@6413 110 // Exclude this thread from safepoints
pliden@6413 111 stsLeave();
pliden@6413 112 }
pliden@6413 113
pliden@6690 114 terminate();
pliden@6690 115 }
pliden@6690 116
pliden@6690 117 void G1StringDedupThread::stop() {
pliden@6690 118 {
pliden@6690 119 MonitorLockerEx ml(Terminator_lock);
pliden@6690 120 _thread->_should_terminate = true;
pliden@6690 121 }
pliden@6690 122
pliden@6690 123 G1StringDedupQueue::cancel_wait();
pliden@6690 124
pliden@6690 125 {
pliden@6690 126 MonitorLockerEx ml(Terminator_lock);
pliden@6690 127 while (!_thread->_has_terminated) {
pliden@6690 128 ml.wait();
pliden@6690 129 }
pliden@6690 130 }
pliden@6413 131 }
pliden@6413 132
pliden@6413 133 void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
pliden@6413 134 if (G1Log::fine() || PrintStringDeduplicationStatistics) {
pliden@6413 135 G1StringDedupStat::print_summary(st, last_stat, total_stat);
pliden@6413 136 if (PrintStringDeduplicationStatistics) {
pliden@6413 137 G1StringDedupStat::print_statistics(st, last_stat, false);
pliden@6413 138 G1StringDedupStat::print_statistics(st, total_stat, true);
pliden@6413 139 G1StringDedupTable::print_statistics(st);
pliden@6413 140 G1StringDedupQueue::print_statistics(st);
pliden@6413 141 }
pliden@6413 142 }
pliden@6413 143 }

mercurial