From 2e0ce34d3cbb2abca4efbf8d5598cdc679b72e90 Mon Sep 17 00:00:00 2001 From: Guanqiang Han Date: Wed, 1 Apr 2026 06:20:26 +0000 Subject: [PATCH] 8380579: C2: Intermittent fastdebug assert in Parse::sharpen_type_after_if: missing type check info Reviewed-by: rcastanedalo, vlivanov --- src/hotspot/share/opto/parse2.cpp | 6 ++ ...harpenTypeAfterIfMissingTypeCheckInfo.java | 57 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/reflection/TestSharpenTypeAfterIfMissingTypeCheckInfo.java diff --git a/src/hotspot/share/opto/parse2.cpp b/src/hotspot/share/opto/parse2.cpp index 7f41870ccea..a7c5398171b 100644 --- a/src/hotspot/share/opto/parse2.cpp +++ b/src/hotspot/share/opto/parse2.cpp @@ -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 } diff --git a/test/hotspot/jtreg/compiler/reflection/TestSharpenTypeAfterIfMissingTypeCheckInfo.java b/test/hotspot/jtreg/compiler/reflection/TestSharpenTypeAfterIfMissingTypeCheckInfo.java new file mode 100644 index 00000000000..7199ad74717 --- /dev/null +++ b/test/hotspot/jtreg/compiler/reflection/TestSharpenTypeAfterIfMissingTypeCheckInfo.java @@ -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; + } +} \ No newline at end of file