Skip to content

Commit

Permalink
CompressedKlassPointers::is_encodable shall be callable with -UseCCP
Browse files Browse the repository at this point in the history
  • Loading branch information
tstuefe committed Sep 17, 2024
1 parent 352e708 commit 612d304
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/hotspot/share/oops/compressedKlass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,13 @@ class CompressedKlassPointers : public AllStatic {
// Returns whether the pointer is in the memory region used for encoding compressed
// class pointers. This includes CDS.
static inline bool is_encodable(const void* addr) {
check_init(_base);
// An address can only be encoded if:
//
// 1) the address lies within the klass range.
// 2) It is suitably aligned to 2^encoding_shift. This only really matters for
// +UseCompactObjectHeaders, since the encoding shift can be large (max 10 bits -> 1KB).
return is_aligned(addr, klass_alignment_in_bytes()) &&
(address)addr >= _klass_range_start && (address)addr < _klass_range_end;
return (address)addr >= _klass_range_start && (address)addr < _klass_range_end &&
is_aligned(addr, klass_alignment_in_bytes());
}

};
Expand Down
12 changes: 12 additions & 0 deletions test/hotspot/gtest/oops/test_compressedKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ TEST_VM(CompressedKlass, basics) {
}
}

TEST_VM(CompressedKlass, ccp_off) {
if (UseCompressedClassPointers) {
return;
}
ASSERT_EQ(CompressedKlassPointers::klass_range_start(), (address)nullptr);
ASSERT_EQ(CompressedKlassPointers::klass_range_end(), (address)nullptr);
// We should be able to call CompressedKlassPointers::is_encodable, and it should
// always return false
ASSERT_FALSE(CompressedKlassPointers::is_encodable((address)0x12345));
}


TEST_VM(CompressedKlass, test_too_low_address) {
if (!UseCompressedClassPointers) {
return;
Expand Down
7 changes: 7 additions & 0 deletions test/hotspot/jtreg/gtest/CompressedKlassGtest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
* @run main/native GTestWrapper --gtest_filter=CompressedKlass* -XX:+UnlockExperimentalVMOptions -XX:-UseCompactObjectHeaders -Xlog:metaspace* -Xmx6g -Xms128m -Xshare:off -XX:CompressedClassSpaceSize=128m
*/

/* @test id=ccp_off
* @library /test/lib
* @modules java.base/jdk.internal.misc
* java.xml
* @run main/native GTestWrapper --gtest_filter=CompressedKlass* -XX:-UseCompressedClassPointers -Xlog:metaspace* -Xmx6g -Xms128m
*/

/* @test id=use-zero-based-encoding-coh
* @library /test/lib
* @modules java.base/jdk.internal.misc
Expand Down

0 comments on commit 612d304

Please sign in to comment.