src/hotspot/share/gc/shared/stringdedup/stringDedup.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 50607 af94bdd511cd
child 53536 482109fae02b
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50574
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50607
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
50574
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50607
diff changeset
    25
#ifndef SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50607
diff changeset
    26
#define SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP
50574
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    27
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    28
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    29
// String Deduplication
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    30
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    31
// String deduplication aims to reduce the heap live-set by deduplicating identical
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    32
// instances of String so that they share the same backing character array.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    33
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    34
// The deduplication process is divided in two main parts, 1) finding the objects to
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    35
// deduplicate, and 2) deduplicating those objects. The first part is done as part of
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    36
// a normal GC cycle when objects are marked or evacuated. At this time a check is
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    37
// applied on each object to check if it is a candidate for deduplication. If so, the
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    38
// object is placed on the deduplication queue for later processing. The second part,
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    39
// processing the objects on the deduplication queue, is a concurrent phase which
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    40
// starts right after the stop-the-wold marking/evacuation phase. This phase is
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    41
// executed by the deduplication thread, which pulls deduplication candidates of the
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    42
// deduplication queue and tries to deduplicate them.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    43
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    44
// A deduplication hashtable is used to keep track of all unique character arrays
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    45
// used by String objects. When deduplicating, a lookup is made in this table to see
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    46
// if there is already an identical character array somewhere on the heap. If so, the
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    47
// String object is adjusted to point to that character array, releasing the reference
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    48
// to the original array allowing it to eventually be garbage collected. If the lookup
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    49
// fails the character array is instead inserted into the hashtable so that this array
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    50
// can be shared at some point in the future.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    51
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    52
// Candidate selection criteria is GC specific.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    53
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    54
// Interned strings are a bit special. They are explicitly deduplicated just before
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    55
// being inserted into the StringTable (to avoid counteracting C2 optimizations done
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    56
// on string literals), then they also become deduplication candidates if they reach
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    57
// the deduplication age threshold or are evacuated to an old heap region. The second
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    58
// attempt to deduplicate such strings will be in vain, but we have no fast way of
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    59
// filtering them out. This has not shown to be a problem, as the number of interned
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    60
// strings is usually dwarfed by the number of normal (non-interned) strings.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    61
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    62
// For additional information on string deduplication, please see JEP 192,
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    63
// http://openjdk.java.net/jeps/192
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    64
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    65
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    66
#include "gc/shared/stringdedup/stringDedupQueue.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    67
#include "gc/shared/stringdedup/stringDedupStat.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    68
#include "gc/shared/stringdedup/stringDedupTable.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    69
#include "memory/allocation.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    70
#include "runtime/thread.hpp"
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    71
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    72
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    73
// Main interface for interacting with string deduplication.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    74
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    75
class StringDedup : public AllStatic {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    76
private:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    77
  // Single state for checking if string deduplication is enabled.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    78
  static bool _enabled;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    79
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    80
public:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    81
  // Returns true if string deduplication is enabled.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    82
  static bool is_enabled() {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    83
    return _enabled;
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
  // Stop the deduplication thread.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    87
  static void stop();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    88
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    89
  // Immediately deduplicates the given String object, bypassing the
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    90
  // the deduplication queue.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    91
  static void deduplicate(oop java_string);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    92
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    93
  static void parallel_unlink(StringDedupUnlinkOrOopsDoClosure* unlink, uint worker_id);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    94
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    95
  static void threads_do(ThreadClosure* tc);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    96
  static void print_worker_threads_on(outputStream* st);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    97
  static void verify();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    98
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
    99
  // GC support
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   100
  static void gc_prologue(bool resize_and_rehash_table);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   101
  static void gc_epilogue();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   102
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   103
protected:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   104
  // Initialize string deduplication.
50607
af94bdd511cd 8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents: 50574
diff changeset
   105
  // Q: String Dedup Queue implementation
af94bdd511cd 8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents: 50574
diff changeset
   106
  // S: String Dedup Stat implementation
af94bdd511cd 8205091: AIX: build errors in hotspot after 8203641: Refactor String Deduplication into shared
mbaesken
parents: 50574
diff changeset
   107
  template <typename Q, typename S>
50574
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   108
  static void initialize_impl();
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   109
};
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   110
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   111
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   112
// This closure encapsulates the closures needed when scanning
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   113
// the deduplication queue and table during the unlink_or_oops_do() operation.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   114
//
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   115
class StringDedupUnlinkOrOopsDoClosure : public StackObj {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   116
private:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   117
  BoolObjectClosure*  _is_alive;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   118
  OopClosure*         _keep_alive;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   119
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   120
public:
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   121
  StringDedupUnlinkOrOopsDoClosure(BoolObjectClosure* is_alive,
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   122
                                     OopClosure* keep_alive);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   123
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   124
  // Applies and returns the result from the is_alive closure, or
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   125
  // returns true if no such closure was provided.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   126
  bool is_alive(oop o) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   127
    if (_is_alive != NULL) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   128
      return _is_alive->do_object_b(o);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   129
    }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   130
    return true;
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   131
  }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   132
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   133
  // Applies the keep_alive closure, or does nothing if no such
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   134
  // closure was provided.
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   135
  void keep_alive(oop* p) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   136
    if (_keep_alive != NULL) {
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   137
      _keep_alive->do_oop(p);
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   138
    }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   139
  }
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   140
};
fa727a4d7934 8203641: Refactor String Deduplication into shared
zgu
parents:
diff changeset
   141
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 50607
diff changeset
   142
#endif // SHARE_GC_SHARED_STRINGDEDUP_STRINGDEDUP_HPP