hotspot/src/share/vm/gc_implementation/g1/g1StringDedupThread.cpp
author pliden
Fri, 11 Apr 2014 11:00:12 +0200
changeset 24093 095cc0a63ed9
parent 23472 35e93890ed88
child 24094 5dbf1f44de18
permissions -rw-r--r--
8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV Reviewed-by: brutisso, 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
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
    // Include this thread in safepoints
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
    stsJoin();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
    stat.mark_exec();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
    // Process the queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
    for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
      oop java_string = G1StringDedupQueue::pop();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
      if (java_string == NULL) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
        break;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
      G1StringDedupTable::deduplicate(java_string, stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
      // Safepoint this thread if needed
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
      if (stsShouldYield()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
        stat.mark_block();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
        stsYield(NULL);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
        stat.mark_unblock();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   100
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
    G1StringDedupTable::trim_entry_cache();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   103
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   104
    stat.mark_done();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   105
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
    // Print statistics
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   107
    total_stat.add(stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   108
    print(gclog_or_tty, stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   109
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   110
    // Exclude this thread from safepoints
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   111
    stsLeave();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   112
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   113
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   114
  terminate();
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
void G1StringDedupThread::stop() {
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
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   120
    _thread->_should_terminate = true;
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
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   123
  G1StringDedupQueue::cancel_wait();
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
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   126
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   127
    while (!_thread->_has_terminated) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   128
      ml.wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   129
    }
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   130
  }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   131
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   132
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   133
void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   134
  if (G1Log::fine() || PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   135
    G1StringDedupStat::print_summary(st, last_stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   136
    if (PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   137
      G1StringDedupStat::print_statistics(st, last_stat, false);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   138
      G1StringDedupStat::print_statistics(st, total_stat, true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   139
      G1StringDedupTable::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   140
      G1StringDedupQueue::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   141
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   142
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   143
}