src/hotspot/share/gc/shared/stringdedup/stringDedupThread.cpp
author tschatzl
Tue, 29 May 2018 09:26:00 +0200
changeset 50605 7f63c74f0974
parent 50574 fa727a4d7934
child 51491 187c84a5efe1
permissions -rw-r--r--
8202845: Refactor reference processing for improved parallelism Summary: Fold reference processing's nine phases into four to decrease startup and termination time of this phase. Reviewed-by: kbarrett, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50574
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     1
/*
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     2
 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     4
 *
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     8
 *
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    13
 * accompanied this code).
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    14
 *
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    18
 *
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    21
 * questions.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    22
 *
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    23
 */
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    24
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    25
#include "precompiled.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    26
#include "classfile/stringTable.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    27
#include "gc/shared/stringdedup/stringDedup.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    28
#include "gc/shared/stringdedup/stringDedupQueue.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    29
#include "gc/shared/stringdedup/stringDedupQueue.inline.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    30
#include "gc/shared/stringdedup/stringDedupTable.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    31
#include "gc/shared/stringdedup/stringDedupThread.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    32
#include "gc/shared/suspendibleThreadSet.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    33
#include "logging/log.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    34
#include "oops/access.inline.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    35
#include "oops/oop.inline.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    36
#include "runtime/atomic.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    37
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    38
StringDedupThread* StringDedupThread::_thread = NULL;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    39
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    40
StringDedupThread::StringDedupThread() :
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    41
  ConcurrentGCThread() {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    42
  set_name("StrDedup");
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    43
  create_and_start();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    44
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    45
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    46
StringDedupThread::~StringDedupThread() {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    47
  ShouldNotReachHere();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    48
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    49
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    50
StringDedupThread* StringDedupThread::thread() {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    51
  assert(_thread != NULL, "String deduplication thread not created");
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    52
  return _thread;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    53
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    54
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    55
class StringDedupSharedClosure: public OopClosure {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    56
 private:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    57
  StringDedupStat* _stat;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    58
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    59
 public:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    60
  StringDedupSharedClosure(StringDedupStat* stat) : _stat(stat) {}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    61
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    62
  virtual void do_oop(oop* p) { ShouldNotReachHere(); }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    63
  virtual void do_oop(narrowOop* p) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    64
    oop java_string = RawAccess<>::oop_load(p);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    65
    StringDedupTable::deduplicate(java_string, _stat);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    66
  }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    67
};
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    68
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    69
// The CDS archive does not include the string dedupication table. Only the string
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    70
// table is saved in the archive. The shared strings from CDS archive need to be
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    71
// added to the string dedupication table before deduplication occurs. That is
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    72
// done in the begining of the StringDedupThread (see StringDedupThread::do_deduplication()).
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    73
void StringDedupThread::deduplicate_shared_strings(StringDedupStat* stat) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    74
  StringDedupSharedClosure sharedStringDedup(stat);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    75
  StringTable::shared_oops_do(&sharedStringDedup);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    76
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    77
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    78
void StringDedupThread::stop_service() {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    79
  StringDedupQueue::cancel_wait();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    80
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    81
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    82
void StringDedupThread::print_start(const StringDedupStat* last_stat) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    83
  StringDedupStat::print_start(last_stat);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    84
}
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    85
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    86
void StringDedupThread::print_end(const StringDedupStat* last_stat, const StringDedupStat* total_stat) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    87
  StringDedupStat::print_end(last_stat, total_stat);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    88
  if (log_is_enabled(Debug, gc, stringdedup)) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    89
    last_stat->print_statistics(false);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    90
    total_stat->print_statistics(true);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    91
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    92
    StringDedupTable::print_statistics();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    93
    StringDedupQueue::print_statistics();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    94
  }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    95
}