hotspot/src/share/vm/gc_implementation/g1/g1StringDedupThread.cpp
author pliden
Tue, 18 Mar 2014 19:07:22 +0100
changeset 23472 35e93890ed88
child 24093 095cc0a63ed9
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
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();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    76
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    77
    // Include this thread in safepoints
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    78
    stsJoin();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    79
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    80
    stat.mark_exec();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    81
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    82
    // Process the queue
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    83
    for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
      oop java_string = G1StringDedupQueue::pop();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
      if (java_string == NULL) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
        break;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    89
      G1StringDedupTable::deduplicate(java_string, stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
      // Safepoint this thread if needed
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
      if (stsShouldYield()) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
        stat.mark_block();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
        stsYield(NULL);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
        stat.mark_unblock();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    99
    G1StringDedupTable::trim_entry_cache();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   100
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   101
    stat.mark_done();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   103
    // Print statistics
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   104
    total_stat.add(stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   105
    print(gclog_or_tty, stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   107
    // Exclude this thread from safepoints
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   108
    stsLeave();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   109
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   110
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   111
  ShouldNotReachHere();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   112
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   113
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   114
void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   115
  if (G1Log::fine() || PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   116
    G1StringDedupStat::print_summary(st, last_stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   117
    if (PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   118
      G1StringDedupStat::print_statistics(st, last_stat, false);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   119
      G1StringDedupStat::print_statistics(st, total_stat, true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   120
      G1StringDedupTable::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   121
      G1StringDedupQueue::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   122
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   123
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   124
}