hotspot/src/share/vm/gc_implementation/g1/g1StringDedupThread.cpp
author sjohanss
Tue, 09 Sep 2014 04:48:41 +0200
changeset 26840 f3c7613a7bbb
parent 25351 7c198a690050
child 29464 02c245ad3ec9
permissions -rw-r--r--
8057710: Refactor G1 heap region default sizes Summary: Refactored the defines to instead be static const in a HeapRegionBounds class. Reviewed-by: mgerdin, tschatzl
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"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24331
diff changeset
    31
#include "runtime/atomic.inline.hpp"
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    32
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    33
G1StringDedupThread* G1StringDedupThread::_thread = NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    34
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
G1StringDedupThread::G1StringDedupThread() :
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
  ConcurrentGCThread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
  set_name("String Deduplication Thread");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
  create_and_start();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    40
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
G1StringDedupThread::~G1StringDedupThread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    42
  ShouldNotReachHere();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    43
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    44
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    45
void G1StringDedupThread::create() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
  assert(_thread == NULL, "One string deduplication thread allowed");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
  _thread = new G1StringDedupThread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
G1StringDedupThread* G1StringDedupThread::thread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
  assert(_thread != NULL, "String deduplication thread not created");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
  return _thread;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
void G1StringDedupThread::run() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
  G1StringDedupStat total_stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    60
  initialize_in_thread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    61
  wait_for_universe_init();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    62
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    63
  // Main loop
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    64
  for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    65
    G1StringDedupStat stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    66
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    67
    stat.mark_idle();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    68
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    69
    // Wait for the queue to become non-empty
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    70
    G1StringDedupQueue::wait();
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    71
    if (_should_terminate) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    72
      break;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    73
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    74
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    75
    {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    76
      // Include thread in safepoints
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    77
      SuspendibleThreadSetJoiner sts;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    79
      stat.mark_exec();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    81
      // Process the queue
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    82
      for (;;) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    83
        oop java_string = G1StringDedupQueue::pop();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    84
        if (java_string == NULL) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    85
          break;
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    86
        }
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    87
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    88
        G1StringDedupTable::deduplicate(java_string, stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    89
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    90
        // Safepoint this thread if needed
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    91
        if (sts.should_yield()) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    92
          stat.mark_block();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    93
          sts.yield();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    94
          stat.mark_unblock();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    95
        }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
    98
      G1StringDedupTable::trim_entry_cache();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   100
      stat.mark_done();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   102
      // Print statistics
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   103
      total_stat.add(stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   104
      print(gclog_or_tty, stat, total_stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   105
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   107
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   108
  terminate();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   109
}
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   110
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   111
void G1StringDedupThread::stop() {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   112
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   113
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   114
    _thread->_should_terminate = true;
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
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   117
  G1StringDedupQueue::cancel_wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   118
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   119
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   120
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   121
    while (!_thread->_has_terminated) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   122
      ml.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
  }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   125
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   126
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   127
void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   128
  if (G1Log::fine() || PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   129
    G1StringDedupStat::print_summary(st, last_stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   130
    if (PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   131
      G1StringDedupStat::print_statistics(st, last_stat, false);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   132
      G1StringDedupStat::print_statistics(st, total_stat, true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   133
      G1StringDedupTable::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   134
      G1StringDedupQueue::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   135
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   136
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   137
}