jdk

Форк
0
/
stringDedupConfig.cpp 
166 строк · 6.3 Кб
1
/*
2
 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 *
23
 */
24

25
#include "precompiled.hpp"
26
#include "classfile/altHashing.hpp"
27
#include "gc/shared/stringdedup/stringDedupConfig.hpp"
28
#include "logging/log.hpp"
29
#include "runtime/flags/jvmFlag.hpp"
30
#include "runtime/globals.hpp"
31
#include "runtime/globals_extension.hpp"
32
#include "utilities/debug.hpp"
33
#include "utilities/globalDefinitions.hpp"
34

35
size_t StringDedup::Config::_initial_table_size;
36
int StringDedup::Config::_age_threshold;
37
double StringDedup::Config::_load_factor_for_growth;
38
double StringDedup::Config::_load_factor_for_shrink;
39
double StringDedup::Config::_load_factor_target;
40
size_t StringDedup::Config::_minimum_dead_for_cleanup;
41
double StringDedup::Config::_dead_factor_for_cleanup;
42
uint64_t StringDedup::Config::_hash_seed;
43

44
size_t StringDedup::Config::initial_table_size() {
45
  return _initial_table_size;
46
}
47

48
int StringDedup::Config::age_threshold() {
49
  return _age_threshold;
50
}
51

52
bool StringDedup::Config::should_cleanup_table(size_t entry_count, size_t dead_count) {
53
  return (dead_count > _minimum_dead_for_cleanup) &&
54
         (dead_count > (entry_count * _dead_factor_for_cleanup));
55
}
56

57
uint64_t StringDedup::Config::hash_seed() {
58
  return _hash_seed;
59
}
60

61
static uint64_t initial_hash_seed() {
62
  if (StringDeduplicationHashSeed != 0) {
63
    return StringDeduplicationHashSeed;
64
  } else {
65
    return AltHashing::compute_seed();
66
  }
67
}
68

69
// Primes after 500 * 2^N and 500 * (2^N + 2^(N-1)) for integer N.
70
const size_t StringDedup::Config::good_sizes[] = {
71
  503, 751, 1009, 1511, 2003, 3001, 4001, 6007, 8009, 12007, 16001, 24001,
72
  32003, 48017, 64007, 96001, 128021, 192007, 256019, 384001, 512009, 768013,
73
  1024021, 1536011, 2048003, 3072001, 4096013, 6144001, 8192003, 12288011,
74
  16384001, 24576001, 32768011, 49152001, 65536043, 98304053,
75
  131072003, 196608007, 262144009, 393216007, 524288057, 786432001,
76
  1048576019, 1572864001 };
77

78
const size_t StringDedup::Config::min_good_size = good_sizes[0];
79
const size_t StringDedup::Config::max_good_size = good_sizes[ARRAY_SIZE(good_sizes) - 1];
80

81
size_t StringDedup::Config::good_size(size_t n) {
82
  size_t result = good_sizes[ARRAY_SIZE(good_sizes) - 1];
83
  for (size_t i = 0; i < ARRAY_SIZE(good_sizes); ++i) {
84
    if (n <= good_sizes[i]) {
85
      result = good_sizes[i];
86
      break;
87
    }
88
  }
89
  return result;
90
}
91

92
size_t StringDedup::Config::grow_threshold(size_t table_size) {
93
  return (table_size < max_good_size) ?
94
         static_cast<size_t>(table_size * _load_factor_for_growth) :
95
         SIZE_MAX;
96
}
97

98
size_t StringDedup::Config::shrink_threshold(size_t table_size) {
99
    return (table_size > min_good_size) ?
100
           static_cast<size_t>(table_size * _load_factor_for_shrink) :
101
           0;
102
}
103

104
bool StringDedup::Config::should_grow_table(size_t table_size, size_t entry_count) {
105
  return entry_count > grow_threshold(table_size);
106
}
107

108
bool StringDedup::Config::should_shrink_table(size_t table_size, size_t entry_count) {
109
  return entry_count < shrink_threshold(table_size);
110
}
111

112
size_t StringDedup::Config::desired_table_size(size_t entry_count) {
113
  return good_size(static_cast<size_t>(entry_count / _load_factor_target));
114
}
115

116
bool StringDedup::Config::ergo_initialize() {
117
  if (!UseStringDeduplication) {
118
    return true;
119
  } else if (!UseG1GC && !UseShenandoahGC && !UseZGC && !UseParallelGC && !UseSerialGC) {
120
    // String deduplication requested but not supported by the selected GC.
121
    // Warn and force disable, but don't error except in debug build with
122
    // incorrect default.
123
    assert(!FLAG_IS_DEFAULT(UseStringDeduplication),
124
           "Enabled by default for GC that doesn't support it");
125
    log_warning(stringdedup)("String Deduplication disabled: "
126
                             "not supported by selected GC");
127
    FLAG_SET_ERGO(UseStringDeduplication, false);
128
    return true;
129
  }
130

131
  // UseStringDeduplication is enabled.  Check parameters.  These checks are
132
  // in addition to any range or constraint checks directly associated with
133
  // the parameters.
134
  bool result = true;
135

136
  // ShrinkTableLoad <= TargetTableLoad <= GrowTableLoad.
137
  if (StringDeduplicationShrinkTableLoad > StringDeduplicationTargetTableLoad) {
138
    JVMFlag::printError(true,
139
                        "StringDeduplicationShrinkTableLoad (%f) must not exceed "
140
                        "StringDeduplicationTargetTableLoad (%f)",
141
                        StringDeduplicationShrinkTableLoad,
142
                        StringDeduplicationTargetTableLoad);
143
    result = false;
144
  }
145
  if (StringDeduplicationTargetTableLoad > StringDeduplicationGrowTableLoad) {
146
    JVMFlag::printError(true,
147
                        "StringDeduplicationTargetTableLoad (%f) must not exceed "
148
                        "StringDeduplicationGrowTableLoad (%f)",
149
                        StringDeduplicationTargetTableLoad,
150
                        StringDeduplicationGrowTableLoad);
151
    result = false;
152
  }
153

154
  return result;
155
}
156

157
void StringDedup::Config::initialize() {
158
  _initial_table_size = good_size(StringDeduplicationInitialTableSize);
159
  _age_threshold = StringDeduplicationAgeThreshold;
160
  _load_factor_for_growth = StringDeduplicationGrowTableLoad;
161
  _load_factor_for_shrink = StringDeduplicationShrinkTableLoad;
162
  _load_factor_target = StringDeduplicationTargetTableLoad;
163
  _minimum_dead_for_cleanup = StringDeduplicationCleanupDeadMinimum;
164
  _dead_factor_for_cleanup = StringDeduplicationCleanupDeadPercent / 100.0;
165
  _hash_seed = initial_hash_seed();
166
}
167

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.