diff --git a/src/hotspot/share/opto/graphKit.cpp b/src/hotspot/share/opto/graphKit.cpp index 702eddbdb1f6f..48a1d245709ef 100644 --- a/src/hotspot/share/opto/graphKit.cpp +++ b/src/hotspot/share/opto/graphKit.cpp @@ -3359,8 +3359,12 @@ Node* GraphKit::gen_checkcast(Node *obj, Node* superklass, if (cast_obj == nullptr) { // Generate the subtype check Node* improved_superklass = superklass; - if (improved_klass_ptr_type != klass_ptr_type && improved_klass_ptr_type->singleton()) { - improved_superklass = makecon(improved_klass_ptr_type); + if (improved_klass_ptr_type != klass_ptr_type) { + if (improved_klass_ptr_type->singleton()) { + improved_superklass = makecon(improved_klass_ptr_type); + } else { + improved_superklass = _gvn.transform(new CastPPNode(nullptr, superklass, improved_klass_ptr_type)); + } } Node* not_subtype_ctrl = gen_subtype_check(not_null_obj, improved_superklass);