diff --git a/src/hotspot/share/oops/compressedKlass.hpp b/src/hotspot/share/oops/compressedKlass.hpp index 954c8263546d9..0a429e7cb71a4 100644 --- a/src/hotspot/share/oops/compressedKlass.hpp +++ b/src/hotspot/share/oops/compressedKlass.hpp @@ -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()); } }; diff --git a/test/hotspot/gtest/oops/test_compressedKlass.cpp b/test/hotspot/gtest/oops/test_compressedKlass.cpp index 835d4de44dc78..48026f4685223 100644 --- a/test/hotspot/gtest/oops/test_compressedKlass.cpp +++ b/test/hotspot/gtest/oops/test_compressedKlass.cpp @@ -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; diff --git a/test/hotspot/jtreg/gtest/CompressedKlassGtest.java b/test/hotspot/jtreg/gtest/CompressedKlassGtest.java index 8ee0d2ed879a5..fce30285312ef 100644 --- a/test/hotspot/jtreg/gtest/CompressedKlassGtest.java +++ b/test/hotspot/jtreg/gtest/CompressedKlassGtest.java @@ -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