From 0cdb2549427a02c6d77adbbf29ba5ed1d1d38293 Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Mon, 19 Jan 2026 15:18:57 +0100 Subject: [PATCH] 8375548: [lworld] C2: Compiler replay fails with an assertion due to not loading object array klasses with ArrayProperties::DEFAULT --- src/hotspot/share/ci/ciReplay.cpp | 4 + .../ciReplay/TestLoadObjArrayKlass.java | 84 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/ciReplay/TestLoadObjArrayKlass.java diff --git a/src/hotspot/share/ci/ciReplay.cpp b/src/hotspot/share/ci/ciReplay.cpp index 3a69bed4780..e8f7e1d1779 100644 --- a/src/hotspot/share/ci/ciReplay.cpp +++ b/src/hotspot/share/ci/ciReplay.cpp @@ -556,6 +556,10 @@ class CompileReplay : public StackObj { } else { k = SystemDictionary::resolve_or_fail(klass_name, _loader, true, THREAD); } + if (Arguments::is_valhalla_enabled() && k->is_objArray_klass()) { + // Create ref or flat array klass. + k = ObjArrayKlass::cast(k)->klass_with_properties(ArrayKlass::ArrayProperties::DEFAULT, THREAD); + } if (HAS_PENDING_EXCEPTION) { oop throwable = PENDING_EXCEPTION; java_lang_Throwable::print(throwable, tty); diff --git a/test/hotspot/jtreg/compiler/ciReplay/TestLoadObjArrayKlass.java b/test/hotspot/jtreg/compiler/ciReplay/TestLoadObjArrayKlass.java new file mode 100644 index 00000000000..8f2f00b0a4f --- /dev/null +++ b/test/hotspot/jtreg/compiler/ciReplay/TestLoadObjArrayKlass.java @@ -0,0 +1,84 @@ +/* + * 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 8375548 + * @enablePreview + * @library / /test/lib + * @summary Testing that compiler replay correctly loads sub classes of ObjArrayKlass. + * @requires vm.flightRecorder != true & vm.compMode != "Xint" & vm.compMode != "Xcomp" & vm.debug == true & + * vm.compiler2.enabled + * @modules java.base/jdk.internal.misc + * @build jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI + * compiler.ciReplay.TestLoadObjArrayKlass + */ + +package compiler.ciReplay; + +public class TestLoadObjArrayKlass extends DumpReplayBase { + + public static void main(String[] args) { + new TestLoadObjArrayKlass().runTest("-XX:CompileCommand=dontinline,*::test", "--enable-preview", TIERED_DISABLED_VM_OPTION); + } + + @Override + public void testAction() { + positiveTest(TIERED_DISABLED_VM_OPTION, "-XX:+ReplayIgnoreInitErrors", "--enable-preview"); + } + + @Override + public String getTestClass() { + return TestLoadObjArrayKlassTest.class.getName(); + } +} + +class TestLoadObjArrayKlassTest { + static Object[] oArr = new A[100]; + + public static void main(String[] args) { + oArr[0] = new A(); + for (int i = 0; i < 10000; i++) { + test(); + } + } + + static void test() { + Object[] oA = oArr; + Object o = oA[0]; + // Use the object with its speculated type. This triggers the code path to call + // + // Parse::create_speculative_inline_type_array_checks() + // ... + // ciArrayKlass::is_elem_null_free() + // + // which tries to directly query a ObjectArrayKlass instance in compiler replay instead of one of its subclasses + // (i.e. RefArrayKlass or FlatArrayKlass). This is unexpected and results in an assertion failure. + o.toString(); + } + + static value class A { + } +}