8380579: C2: Intermittent fastdebug assert in Parse::sharpen_type_after_if: missing type check info

Reviewed-by: rcastanedalo, vlivanov
This commit is contained in:
Guanqiang Han 2026-04-01 06:20:26 +00:00 committed by Roberto Castañeda Lozano
parent 52fd46d3a6
commit 2e0ce34d3c
2 changed files with 63 additions and 0 deletions

View File

@ -1757,6 +1757,12 @@ static bool match_type_check(PhaseGVN& gvn,
// Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq])
// or the narrowOop equivalent.
(*obj) = extract_obj_from_klass_load(&gvn, val);
// Some klass comparisons are not directly in the form
// Bool(CmpP(LoadKlass(obj._klass), ConP(Foo.klass)), [eq]),
// e.g. Bool(CmpP(CastPP(LoadKlass(...)), ConP(klass)), [eq]).
// These patterns with nullable klasses arise from example from
// load_array_klass_from_mirror.
if (*obj == nullptr) { return false; }
(*cast_type) = tcon->isa_klassptr()->as_instance_type();
return true; // found
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8380579
* @summary Test that C2 match_type_check handles Bool(CmpP(CastPP(LoadKlass(...)), ConP(klass)), eq)
* @run main/othervm
* -XX:-TieredCompilation
* -Xcomp
* -XX:CompileCommand=compileonly,${test.main.class}::test
* ${test.main.class}
*/
package compiler.reflection;
import java.lang.reflect.Array;
public class TestSharpenTypeAfterIfMissingTypeCheckInfo {
public static void main(String[] args) {
for (int i = 0; i < 20_000; i++) {
test(i);
}
}
static boolean test(int i) {
Class componentType;
if (i % 2 == 0) {
componentType = Object.class;
} else {
componentType = Integer.class;
}
Object array = Array.newInstance(componentType, 1);
return array.getClass() == Object[].class;
}
}