From 8b6a11f7e05ee0cece798c5ff6646bddbee04900 Mon Sep 17 00:00:00 2001 From: Calvin Cheung Date: Mon, 2 Jun 2025 16:51:44 +0000 Subject: [PATCH] 8352187: Don't start management agent during AOT cache creation Reviewed-by: shade, iklam, kvn --- src/hotspot/share/runtime/threads.cpp | 21 ++++-- .../cds/appcds/aotCache/ManagementAgent.java | 64 +++++++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 test/hotspot/jtreg/runtime/cds/appcds/aotCache/ManagementAgent.java diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index 987db37e9d5..8d8d4782e94 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -847,13 +847,22 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { JFR_ONLY(Jfr::on_create_vm_3();) #if INCLUDE_MANAGEMENT - Management::initialize(THREAD); + bool start_agent = true; +#if INCLUDE_CDS + start_agent = !CDSConfig::is_dumping_final_static_archive(); + if (!start_agent) { + log_info(aot)("Not starting management agent during creation of AOT cache."); + } +#endif // INCLUDE_CDS + if (start_agent) { + Management::initialize(THREAD); - if (HAS_PENDING_EXCEPTION) { - // management agent fails to start possibly due to - // configuration problem and is responsible for printing - // stack trace if appropriate. Simply exit VM. - vm_exit(1); + if (HAS_PENDING_EXCEPTION) { + // management agent fails to start possibly due to + // configuration problem and is responsible for printing + // stack trace if appropriate. Simply exit VM. + vm_exit(1); + } } #endif // INCLUDE_MANAGEMENT diff --git a/test/hotspot/jtreg/runtime/cds/appcds/aotCache/ManagementAgent.java b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/ManagementAgent.java new file mode 100644 index 00000000000..abbdd3551b7 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/aotCache/ManagementAgent.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 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 + * @bug 8352187 + * @summary ManagementAgent will not be started during AOT cache creation. + * @requires vm.cds.supports.aot.class.linking + * @comment work around JDK-8345635 + * @requires !vm.jvmci.enabled + * @library /test/lib + * @build HelloAOTCache + * @run driver jdk.test.lib.helpers.ClassFileInstaller -jar app.jar HelloAOTCacheApp + * @run driver ManagementAgent + */ + +import jdk.test.lib.cds.SimpleCDSAppTester; +import jdk.test.lib.process.OutputAnalyzer; + +public class ManagementAgent { + public static void main(String... args) throws Exception { + SimpleCDSAppTester.of("HelloAOTCache-with-management-agent") + // test with the initialization of a management agent + .addVmArgs("-Xlog:class+load", "-Dcom.sun.management.jmxremote=true") + .classpath("app.jar") + .appCommandLine("HelloAOTCacheApp") + .setAssemblyChecker((OutputAnalyzer out) -> { + out.shouldContain("Not starting management agent during creation of AOT cache."); + }) + .setProductionChecker((OutputAnalyzer out) -> { + out.shouldMatch("class,load.*HelloAOTCacheApp.*shared objects"); + out.shouldContain("HelloWorld"); + }) + .runAOTWorkflow(); + } +} + +class HelloAOTCacheApp { + public static void main(String[] args) { + System.out.println("HelloWorld"); + } +}