hotspot/src/share/vm/gc_implementation/g1/g1StringDedupThread.cpp
author pliden
Fri, 11 Apr 2014 12:29:24 +0200
changeset 24094 5dbf1f44de18
parent 24093 095cc0a63ed9
child 24331 c0bc7e5653fb
permissions -rw-r--r--
8039147: Cleanup SuspendibleThreadSet Reviewed-by: brutisso, tschatzl, mgerdin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     1
/*
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     4
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     8
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    13
 * accompanied this code).
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    14
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    18
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    21
 * questions.
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    22
 *
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    23
 */
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    24
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    25
#include "precompiled.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    26
#include "gc_implementation/g1/g1Log.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    27
#include "gc_implementation/g1/g1StringDedup.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    28
#include "gc_implementation/g1/g1StringDedupTable.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    29
#include "gc_implementation/g1/g1StringDedupThread.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    30
#include "gc_implementation/g1/g1StringDedupQueue.hpp"
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    31
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    32
G1StringDedupThread* G1StringDedupThread::_thread = NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    33
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    34
G1StringDedupThread::G1StringDedupThread() :
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
  ConcurrentGCThread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
  set_name("String Deduplication Thread");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
  create_and_start();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    40
G1StringDedupThread::~G1StringDedupThread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
  ShouldNotReachHere();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    42
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    43
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    44
void G1StringDedupThread::create() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    45
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
  assert(_thread == NULL, "One string deduplication thread allowed");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
  _thread = new G1StringDedupThread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
G1StringDedupThread* G1StringDedupThread::thread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
  assert(_thread != NULL, "String deduplication thread not created");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
  return _thread;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
void G1StringDedupThread::print_on(outputStream* st) const {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
  st->print("\"%s\" ", name());
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
  Thread::print_on(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
  st->cr();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    60
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    61
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    62
void G1StringDedupThread::run() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    63
  G1StringDedupStat total_stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    64
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    65
  initialize_in_thread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    66
  wait_for_universe_init();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    67
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    68
  // Main loop
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    69
  for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    70
    G1StringDedupStat stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    71
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    72
    stat.mark_idle();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    73
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
    // Wait for the queue to become non-empty
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    75
    G1StringDedupQueue::wait();
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    76
    if (_should_terminate) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    77
      break;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    78
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    80
    {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    81
      // Include thread in safepoints
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    82
      SuspendibleThreadSetJoiner sts;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    84
      stat.mark_exec();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    86
      // Process the queue
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    87
      for (;;) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    88
        oop java_string = G1StringDedupQueue::pop();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    89
        if (java_string == NULL) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    90
          break;
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    91
        }
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    92
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    93
        G1StringDedupTable::deduplicate(java_string, stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    94
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    95
        // Safepoint this thread if needed
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    96
        if (sts.should_yield()) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    97
          stat.mark_block();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    98
          sts.yield();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    99
          stat.mark_unblock();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   100
        }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   103
      G1StringDedupTable::trim_entry_cache();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   104
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   105
      stat.mark_done();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   107
      // Print statistics
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   108
      total_stat.add(stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   109
      print(gclog_or_tty, stat, total_stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   110
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   111
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   112
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   113
  terminate();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   114
}
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   115
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   116
void G1StringDedupThread::stop() {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   117
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   118
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   119
    _thread->_should_terminate = true;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   120
  }
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   121
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   122
  G1StringDedupQueue::cancel_wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   123
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   124
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   125
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   126
    while (!_thread->_has_terminated) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   127
      ml.wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   128
    }
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   129
  }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   130
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   131
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   132
void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   133
  if (G1Log::fine() || PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   134
    G1StringDedupStat::print_summary(st, last_stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   135
    if (PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   136
      G1StringDedupStat::print_statistics(st, last_stat, false);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   137
      G1StringDedupStat::print_statistics(st, total_stat, true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   138
      G1StringDedupTable::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   139
      G1StringDedupQueue::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   140
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   141
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   142
}