diff --git a/src/hotspot/share/cds/filemap.cpp b/src/hotspot/share/cds/filemap.cpp index e82313bb84d..15e2dfb2d92 100644 --- a/src/hotspot/share/cds/filemap.cpp +++ b/src/hotspot/share/cds/filemap.cpp @@ -2524,6 +2524,13 @@ bool FileMapInfo::validate_aot_class_linking() { log_error(cds)("CDS archive has aot-linked classes. It cannot be used with -Djava.security.manager=%s.", prop); return false; } + +#if INCLUDE_JVMTI + if (Arguments::has_jdwp_agent()) { + log_error(cds)("CDS archive has aot-linked classes. It cannot be used with JDWP agent"); + return false; + } +#endif } return true; diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index 620b67b023d..baeb591ef1a 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -102,6 +102,7 @@ bool Arguments::_ClipInlining = ClipInlining; size_t Arguments::_default_SharedBaseAddress = SharedBaseAddress; bool Arguments::_enable_preview = false; +bool Arguments::_has_jdwp_agent = false; LegacyGCLogging Arguments::_legacyGCLogging = { nullptr, 0 }; @@ -2007,7 +2008,7 @@ jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args, return JNI_OK; } -#if !INCLUDE_JVMTI +#if !INCLUDE_JVMTI || INCLUDE_CDS // Checks if name in command-line argument -agent{lib,path}:name[=options] // represents a valid JDWP agent. is_path==true denotes that we // are dealing with -agentpath (case where name is a path), otherwise with @@ -2305,6 +2306,10 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin "Debugging agents are not supported in this VM\n"); return JNI_ERR; } +#elif INCLUDE_CDS + if (valid_jdwp_agent(name, is_absolute_path)) { + _has_jdwp_agent = true; + } #endif // !INCLUDE_JVMTI JvmtiAgentList::add(name, options, is_absolute_path); os::free(name); diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index dec3970e20a..741c3e18082 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -253,6 +253,9 @@ class Arguments : AllStatic { // preview features static bool _enable_preview; + // jdwp + static bool _has_jdwp_agent; + // Used to save default settings static bool _AlwaysCompileLoopMethods; static bool _UseOnStackReplacement; @@ -505,6 +508,9 @@ class Arguments : AllStatic { static void set_enable_preview() { _enable_preview = true; } static bool enable_preview() { return _enable_preview; } + // jdwp + static bool has_jdwp_agent() { return _has_jdwp_agent; } + // Utility: copies src into buf, replacing "%%" with "%" and "%p" with pid. static bool copy_expand_pid(const char* src, size_t srclen, char* buf, size_t buflen);