8352187: Don't start management agent during AOT cache creation

Reviewed-by: shade, iklam, kvn
This commit is contained in:
Calvin Cheung 2025-06-02 16:51:44 +00:00
parent ab5de45636
commit 8b6a11f7e0
2 changed files with 79 additions and 6 deletions

View File

@ -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

View File

@ -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");
}
}