From a6cc37fdbe77ff3c1bd8e2332f67f48e3850e56b Mon Sep 17 00:00:00 2001 From: Ioi Lam Date: Tue, 25 Feb 2025 05:38:39 +0000 Subject: [PATCH] 8349888: AOTMode=create crashes with EpsilonGC Reviewed-by: shade, kvn --- src/hotspot/share/cds/classListParser.cpp | 8 ++ .../LambdaInExcludedClass.java | 103 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java diff --git a/src/hotspot/share/cds/classListParser.cpp b/src/hotspot/share/cds/classListParser.cpp index 9a5ac12b475..e0c008678ca 100644 --- a/src/hotspot/share/cds/classListParser.cpp +++ b/src/hotspot/share/cds/classListParser.cpp @@ -846,6 +846,14 @@ void ClassListParser::parse_constant_pool_tag() { } } + if (SystemDictionaryShared::should_be_excluded(ik)) { + if (log_is_enabled(Warning, cds, resolve)) { + ResourceMark rm; + log_warning(cds, resolve)("Cannot aot-resolve constants for %s because it is excluded", ik->external_name()); + } + return; + } + if (preresolve_class) { AOTConstantPoolResolver::preresolve_class_cp_entries(THREAD, ik, &preresolve_list); } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java new file mode 100644 index 00000000000..9ed2524bff1 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotClassLinking/LambdaInExcludedClass.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2024, 2025, 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 id=static Lambda expressions in excluded classes shouldn't be resolved during the assembly phase. + * @bug 8349888 + * @requires vm.cds.supports.aot.class.linking + * @requires vm.gc.Epsilon + * @comment work around JDK-8345635 + * @requires !vm.jvmci.enabled + * @library /test/jdk/lib/testlibrary /test/lib + * @build LambdaInExcludedClass + * @run driver jdk.test.lib.helpers.ClassFileInstaller LambdaInExcludedClassApp + * @run driver LambdaInExcludedClass STATIC + */ + +import jdk.test.lib.cds.CDSAppTester; +import jdk.test.lib.helpers.ClassFileInstaller; +import jdk.test.lib.process.OutputAnalyzer; + +public class LambdaInExcludedClass { + static final String mainClass = "LambdaInExcludedClassApp"; + + public static void main(String[] args) throws Exception { + Tester t = new Tester(); + t.run(args); + } + + static class Tester extends CDSAppTester { + public Tester() { + super(mainClass); + } + + @Override + public String classpath(RunMode runMode) { + // Using "." as the classpath allows the LambdaInExcludedClassApp to be loaded in + // the assembly phase, but this class will be excluded from the AOT cache. + return "."; + } + + @Override + public String[] vmArgs(RunMode runMode) { + return new String[] { + "-Xmx128m", + "-XX:+AOTClassLinking", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseEpsilonGC", + }; + } + + @Override + public String[] appCommandLine(RunMode runMode) { + return new String[] { + mainClass, + }; + } + + @Override + public void checkExecution(OutputAnalyzer out, RunMode runMode) throws Exception { + if (runMode == RunMode.DUMP_STATIC) { + out.shouldContain("Skipping LambdaInExcludedClassApp: Unsupported location"); + out.shouldContain("Cannot aot-resolve constants for LambdaInExcludedClassApp because it is excluded"); + } else { + out.shouldContain("Hello LambdaInExcludedClassApp"); + } + } + } +} + +class LambdaInExcludedClassApp { + public static void main(String args[]) throws Exception { + // LambdaInExcludedClassApp is excluded, so aot-linking of lambda call sites + // should not happen for this class. Otherwise Epsilon GC may crash due + // to 8349888. + Runnable r = LambdaInExcludedClassApp::doit; + r.run(); + } + + static void doit() { + System.out.println("Hello LambdaInExcludedClassApp"); + } +}