/* * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
if (obj->klass() == vmClasses::String_klass()) { // This may overcount if String.value arrays are shared.
word_size += java_lang_String::value(obj)->size();
}
constdouble _resize_factor = 2.0; // by how much we will resize using current number of entries constint _small_table_sizes[] = { 107, 1009, 2017, 4049, 5051, 10103, 20201, 40423 } ; constint _small_array_size = sizeof(_small_table_sizes)/sizeof(int);
// possible hashmap sizes - odd primes that roughly double in size. // To avoid excessive resizing the odd primes from 4801-76831 and // 76831-307261 have been removed. constint _large_table_sizes[] = { 4801, 76831, 307261, 614563, 1228891,
2457733, 4915219, 9830479, 19660831, 39321619, 78643219 }; constint _large_array_size = sizeof(_large_table_sizes)/sizeof(int);
// Calculate next "good" hashtable size based on requested count template <MEMFLAGS F> int BasicHashtable<F>::calculate_resize(bool use_large_table_sizes) const { int requested = (int)(_resize_factor*number_of_entries()); constint* primelist = use_large_table_sizes ? _large_table_sizes : _small_table_sizes; int arraysize = use_large_table_sizes ? _large_array_size : _small_array_size; int newsize; for (int i = 0; i < arraysize; i++) {
newsize = primelist[i]; if (newsize >= requested) break;
} return newsize;
}
// Allocate new buckets
HashtableBucket<F>* buckets_new = NEW_C_HEAP_ARRAY2_RETURN_NULL(HashtableBucket<F>, new_size, F, CURRENT_PC); if (buckets_new == NULL) { returnfalse;
}
// Clear the new buckets for (int i = 0; i < new_size; i++) {
buckets_new[i].clear();
}
int table_size_old = _table_size; // hash_to_index() uses _table_size, so switch the sizes now
_table_size = new_size;
// Move entries from the old table to a new table for (int index_old = 0; index_old < table_size_old; index_old++) { for (BasicHashtableEntry<F>* p = _buckets[index_old].get_entry(); p != NULL; ) {
BasicHashtableEntry<F>* next = p->next(); int index_new = hash_to_index(p->hash());
p->set_next(buckets_new[index_new].get_entry());
buckets_new[index_new].set_entry(p);
p = next;
}
}
// The old backets now can be released
BasicHashtable<F>::free_buckets();
// Switch to the new storage
_buckets = buckets_new;
returntrue;
}
template <MEMFLAGS F> bool BasicHashtable<F>::maybe_grow(int max_size, int load_factor) {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.