hotspot/src/share/vm/gc/g1/g1StringDedupThread.cpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 31345 1bba15125d8d
child 35061 be6025ebffea
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
     1
/*
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 25351
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
23472
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"
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    26
#include "classfile/stringTable.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    27
#include "gc/g1/g1Log.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    28
#include "gc/g1/g1StringDedup.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    29
#include "gc/g1/g1StringDedupQueue.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    30
#include "gc/g1/g1StringDedupTable.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30613
diff changeset
    31
#include "gc/g1/g1StringDedupThread.hpp"
30770
5ba2d9f2084d 8080585: concurrentGCThread.hpp should not include suspendibleThreadSet.hpp
pliden
parents: 30764
diff changeset
    32
#include "gc/g1/suspendibleThreadSet.hpp"
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    33
#include "oops/oop.inline.hpp"
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24331
diff changeset
    34
#include "runtime/atomic.inline.hpp"
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    35
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    36
G1StringDedupThread* G1StringDedupThread::_thread = NULL;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    37
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    38
G1StringDedupThread::G1StringDedupThread() :
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    39
  ConcurrentGCThread() {
29464
02c245ad3ec9 8073545: Use shorter and more descriptive names for GC worker threads
david
parents: 25351
diff changeset
    40
  set_name("G1 StrDedup");
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    41
  create_and_start();
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
G1StringDedupThread::~G1StringDedupThread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    45
  ShouldNotReachHere();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    46
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    47
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    48
void G1StringDedupThread::create() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    49
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    50
  assert(_thread == NULL, "One string deduplication thread allowed");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    51
  _thread = new G1StringDedupThread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    52
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    53
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    54
G1StringDedupThread* G1StringDedupThread::thread() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    55
  assert(G1StringDedup::is_enabled(), "String deduplication not enabled");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    56
  assert(_thread != NULL, "String deduplication thread not created");
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    57
  return _thread;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    58
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    59
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    60
class G1StringDedupSharedClosure: public OopClosure {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    61
 private:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    62
  G1StringDedupStat& _stat;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    63
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    64
 public:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    65
  G1StringDedupSharedClosure(G1StringDedupStat& stat) : _stat(stat) {}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    66
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    67
  virtual void do_oop(oop* p) { ShouldNotReachHere(); }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    68
  virtual void do_oop(narrowOop* p) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    69
    oop java_string = oopDesc::load_decode_heap_oop(p);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    70
    G1StringDedupTable::deduplicate(java_string, _stat);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    71
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    72
};
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    73
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    74
// The CDS archive does not include the string dedupication table. Only the string
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    75
// table is saved in the archive. The shared strings from CDS archive need to be
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    76
// added to the string dedupication table before deduplication occurs. That is
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    77
// done in the begining of the G1StringDedupThread (see G1StringDedupThread::run()
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    78
// below).
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    79
void G1StringDedupThread::deduplicate_shared_strings(G1StringDedupStat& stat) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    80
  G1StringDedupSharedClosure sharedStringDedup(stat);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    81
  StringTable::shared_oops_do(&sharedStringDedup);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    82
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    83
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    84
void G1StringDedupThread::run() {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    85
  G1StringDedupStat total_stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    86
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    87
  initialize_in_thread();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    88
  wait_for_universe_init();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30770
diff changeset
    89
  deduplicate_shared_strings(total_stat);
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    90
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    91
  // Main loop
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    92
  for (;;) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    93
    G1StringDedupStat stat;
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    94
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    95
    stat.mark_idle();
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    96
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    97
    // Wait for the queue to become non-empty
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
    98
    G1StringDedupQueue::wait();
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
    99
    if (_should_terminate) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   100
      break;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   101
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   102
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   103
    {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   104
      // Include thread in safepoints
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
   105
      SuspendibleThreadSetJoiner sts_join;
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   106
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   107
      stat.mark_exec();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   108
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   109
      // Process the queue
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   110
      for (;;) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   111
        oop java_string = G1StringDedupQueue::pop();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   112
        if (java_string == NULL) {
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   113
          break;
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   114
        }
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   115
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   116
        G1StringDedupTable::deduplicate(java_string, stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   117
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   118
        // Safepoint this thread if needed
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
   119
        if (sts_join.should_yield()) {
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   120
          stat.mark_block();
30613
a7815bb05ae2 8079579: Add SuspendibleThreadSetLeaver and make SuspendibleThreadSet::joint()/leave() private
pliden
parents: 29464
diff changeset
   121
          sts_join.yield();
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   122
          stat.mark_unblock();
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   123
        }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   124
      }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   125
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   126
      G1StringDedupTable::trim_entry_cache();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   127
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   128
      stat.mark_done();
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   129
24094
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   130
      // Print statistics
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   131
      total_stat.add(stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   132
      print(gclog_or_tty, stat, total_stat);
5dbf1f44de18 8039147: Cleanup SuspendibleThreadSet
pliden
parents: 24093
diff changeset
   133
    }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   134
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   135
24093
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   136
  terminate();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   137
}
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   138
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   139
void G1StringDedupThread::stop() {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   140
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   141
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   142
    _thread->_should_terminate = true;
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   143
  }
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   144
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   145
  G1StringDedupQueue::cancel_wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   146
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   147
  {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   148
    MonitorLockerEx ml(Terminator_lock);
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   149
    while (!_thread->_has_terminated) {
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   150
      ml.wait();
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   151
    }
095cc0a63ed9 8037112: gc/g1/TestHumongousAllocInitialMark.java caused SIGSEGV
pliden
parents: 23472
diff changeset
   152
  }
23472
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   153
}
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   154
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   155
void G1StringDedupThread::print(outputStream* st, const G1StringDedupStat& last_stat, const G1StringDedupStat& total_stat) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   156
  if (G1Log::fine() || PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   157
    G1StringDedupStat::print_summary(st, last_stat, total_stat);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   158
    if (PrintStringDeduplicationStatistics) {
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   159
      G1StringDedupStat::print_statistics(st, last_stat, false);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   160
      G1StringDedupStat::print_statistics(st, total_stat, true);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   161
      G1StringDedupTable::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   162
      G1StringDedupQueue::print_statistics(st);
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   163
    }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   164
  }
35e93890ed88 8029075: String deduplication in G1
pliden
parents:
diff changeset
   165
}