diff --git a/src/hotspot/share/ci/ciKlass.hpp b/src/hotspot/share/ci/ciKlass.hpp index 58a62b248a4..de2d3701f3e 100644 --- a/src/hotspot/share/ci/ciKlass.hpp +++ b/src/hotspot/share/ci/ciKlass.hpp @@ -107,6 +107,13 @@ public: return false; } + bool is_in_encoding_range() { + Klass* k = get_Klass(); + bool is_in_encoding_range = CompressedKlassPointers::is_in_encoding_range(k); + assert(is_in_encoding_range || k->is_interface() || k->is_abstract(), "sanity"); + return is_in_encoding_range; + } + // Attempt to get a klass using this ciKlass's loader. ciKlass* find_klass(ciSymbol* klass_name); // Note: To find a class from its name string, use ciSymbol::make, diff --git a/src/hotspot/share/oops/compressedKlass.inline.hpp b/src/hotspot/share/oops/compressedKlass.inline.hpp index 87ef2102b38..9cfef964f18 100644 --- a/src/hotspot/share/oops/compressedKlass.inline.hpp +++ b/src/hotspot/share/oops/compressedKlass.inline.hpp @@ -51,7 +51,7 @@ inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v, address na assert(!is_null(v), "klass value can never be zero"); assert(check_alignment(v), "Address not aligned"); uint64_t pd = (uint64_t)(pointer_delta(v, narrow_base, 1)); - assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding"); + assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding (Klass " PTR_FORMAT ", Base " PTR_FORMAT ")", p2i(v), p2i(narrow_base)); uint64_t result = pd >> shift; assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow"); assert(decode_not_null((narrowKlass)result, narrow_base, shift) == v, "reversibility"); diff --git a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp index 58a716abd21..143189d7eba 100644 --- a/src/hotspot/share/opto/compile.cpp +++ b/src/hotspot/share/opto/compile.cpp @@ -3324,7 +3324,7 @@ void Compile::final_graph_reshaping_main_switch(Node* n, Final_Reshape_Counts& f bool is_klass = t->isa_klassptr() != nullptr; if ((is_oop && Matcher::const_oop_prefer_decode() ) || - (is_klass && Matcher::const_klass_prefer_decode())) { + (is_klass && Matcher::const_klass_prefer_decode() && t->isa_klassptr()->exact_klass()->is_in_encoding_range())) { Node* nn = nullptr; int op = is_oop ? Op_ConN : Op_ConNKlass;