Skip to content

Commit

Permalink
8344568: Renaming ceil_log2 to log2i_ceil
Browse files Browse the repository at this point in the history
Reviewed-by: kbarrett
  • Loading branch information
Sonia Zaldana Calles committed Nov 22, 2024
1 parent 51763b6 commit 079f503
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const size_t REHASH_LEN = 100;
Dictionary::Dictionary(ClassLoaderData* loader_data, size_t table_size)
: _number_of_entries(0), _loader_data(loader_data) {

size_t start_size_log_2 = MAX2(ceil_log2(table_size), 2); // 2 is minimum size even though some dictionaries only have one entry
size_t start_size_log_2 = MAX2(log2i_ceil(table_size), 2); // 2 is minimum size even though some dictionaries only have one entry
size_t current_size = ((size_t)1) << start_size_log_2;
log_info(class, loader, data)("Dictionary start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
current_size, start_size_log_2);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/stringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class StringTableLookupOop : public StringTableLookup {
};

void StringTable::create_table() {
size_t start_size_log_2 = ceil_log2(StringTableSize);
size_t start_size_log_2 = log2i_ceil(StringTableSize);
_current_size = ((size_t)1) << start_size_log_2;
log_trace(stringtable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
_current_size, start_size_log_2);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/symbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class SymbolTableConfig : public AllStatic {
};

void SymbolTable::create_table () {
size_t start_size_log_2 = ceil_log2(SymbolTableSize);
size_t start_size_log_2 = log2i_ceil(SymbolTableSize);
_current_size = ((size_t)1) << start_size_log_2;
log_trace(symboltable)("Start size: " SIZE_FORMAT " (" SIZE_FORMAT ")",
_current_size, start_size_log_2);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/services/finalizerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void FinalizerService::do_concurrent_work(JavaThread* service_thread) {

void FinalizerService::init() {
assert(_table == nullptr, "invariant");
const size_t start_size_log_2 = ceil_log2(DEFAULT_TABLE_SIZE);
const size_t start_size_log_2 = log2i_ceil(DEFAULT_TABLE_SIZE);
_table = new FinalizerHashtable(start_size_log_2, MAX_SIZE, FinalizerHashtable::DEFAULT_GROW_HINT);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/services/threadIdTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void ThreadIdTable::lazy_initialize(const ThreadsList *threads) {

void ThreadIdTable::create_table(size_t size) {
assert(_local_table == nullptr, "Thread table is already created");
size_t size_log = ceil_log2(size);
size_t size_log = log2i_ceil(size);
size_t start_size_log =
size_log > DEFAULT_TABLE_SIZE_LOG ? size_log : DEFAULT_TABLE_SIZE_LOG;
_current_size = (size_t)1 << start_size_log;
Expand Down
14 changes: 7 additions & 7 deletions src/hotspot/share/utilities/powerOfTwo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ inline int log2i_exact(T value) {
return count_trailing_zeros(value);
}

// Ceiling of log2 of a positive, integral value, i.e., smallest i such that value <= 2^i.
template <typename T, ENABLE_IF(std::is_integral<T>::value)>
inline int log2i_ceil(T value) {
assert(value > 0, "Invalid value");
return log2i_graceful(value - 1) + 1;
}

// Preconditions: value != 0, and the unsigned representation of value is a power of two
inline int exact_log2(intptr_t value) {
return log2i_exact((uintptr_t)value);
Expand Down Expand Up @@ -120,13 +127,6 @@ inline T next_power_of_2(T value) {
return T(round_up_power_of_2(value + 1));
}

// Find log2 value greater than this input
template <typename T, ENABLE_IF(std::is_integral<T>::value)>
inline int ceil_log2(T value) {
assert(value > 0, "Invalid value");
return log2i_graceful(value - 1) + 1;
}

// Return the largest power of two that is a submultiple of the given value.
// This is the same as the numeric value of the least-significant set bit.
// For unsigned values, it replaces the old trick of (value & -value).
Expand Down
48 changes: 24 additions & 24 deletions test/hotspot/gtest/utilities/test_powerOfTwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,43 +306,43 @@ TEST(power_of_2, log2i) {
check_log2i_variants_for((jlong)0);
}

template <typename T> void test_ceil_log2() {
EXPECT_EQ(ceil_log2(T(1)), 0) << "value = " << T(1);
EXPECT_EQ(ceil_log2(T(2)), 1) << "value = " << T(2);
EXPECT_EQ(ceil_log2(T(3)), 2) << "value = " << T(3);
EXPECT_EQ(ceil_log2(T(4)), 2) << "value = " << T(4);
EXPECT_EQ(ceil_log2(T(5)), 3) << "value = " << T(5);
EXPECT_EQ(ceil_log2(T(6)), 3) << "value = " << T(6);
EXPECT_EQ(ceil_log2(T(7)), 3) << "value = " << T(7);
EXPECT_EQ(ceil_log2(T(8)), 3) << "value = " << T(8);
EXPECT_EQ(ceil_log2(T(9)), 4) << "value = " << T(9);
EXPECT_EQ(ceil_log2(T(10)), 4) << "value = " << T(10);
template <typename T> void test_log2i_ceil() {
EXPECT_EQ(log2i_ceil(T(1)), 0) << "value = " << T(1);
EXPECT_EQ(log2i_ceil(T(2)), 1) << "value = " << T(2);
EXPECT_EQ(log2i_ceil(T(3)), 2) << "value = " << T(3);
EXPECT_EQ(log2i_ceil(T(4)), 2) << "value = " << T(4);
EXPECT_EQ(log2i_ceil(T(5)), 3) << "value = " << T(5);
EXPECT_EQ(log2i_ceil(T(6)), 3) << "value = " << T(6);
EXPECT_EQ(log2i_ceil(T(7)), 3) << "value = " << T(7);
EXPECT_EQ(log2i_ceil(T(8)), 3) << "value = " << T(8);
EXPECT_EQ(log2i_ceil(T(9)), 4) << "value = " << T(9);
EXPECT_EQ(log2i_ceil(T(10)), 4) << "value = " << T(10);

// Test max values
if (std::is_unsigned<T>::value) {
EXPECT_EQ(ceil_log2(std::numeric_limits<T>::max()),
EXPECT_EQ(log2i_ceil(std::numeric_limits<T>::max()),
(int)(sizeof(T) * 8)) << "value = " << std::numeric_limits<T>::max();
} else {
EXPECT_EQ(ceil_log2(std::numeric_limits<T>::max()),
EXPECT_EQ(log2i_ceil(std::numeric_limits<T>::max()),
(int)(sizeof(T) * 8 - 1)) << "value = " << std::numeric_limits<T>::max();
}
}

TEST(power_of_2, ceil_log2) {
test_ceil_log2<int8_t>();
test_ceil_log2<int16_t>();
test_ceil_log2<int32_t>();
test_ceil_log2<int64_t>();
test_ceil_log2<uint8_t>();
test_ceil_log2<uint16_t>();
test_ceil_log2<uint32_t>();
test_ceil_log2<uint64_t>();
TEST(power_of_2, log2i_ceil) {
test_log2i_ceil<int8_t>();
test_log2i_ceil<int16_t>();
test_log2i_ceil<int32_t>();
test_log2i_ceil<int64_t>();
test_log2i_ceil<uint8_t>();
test_log2i_ceil<uint16_t>();
test_log2i_ceil<uint32_t>();
test_log2i_ceil<uint64_t>();
}

#ifdef ASSERT
TEST_VM_ASSERT_MSG(power_of_2, ceil_log2_invalid,
TEST_VM_ASSERT_MSG(power_of_2, log2i_ceil_invalid,
".*Invalid value") {
ceil_log2(0);
log2i_ceil(0);
}

#endif // ASSERT

1 comment on commit 079f503

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.