From 79824c344ee36bcf9f3434ccb3b44d2d24defc5c Mon Sep 17 00:00:00 2001 From: Jiangli Zhou Date: Thu, 27 Mar 2025 14:40:02 +0000 Subject: [PATCH] 8352184: Jtreg tests using CommandLineOptionTest.getVMTypeOption() and optionsvalidation.JVMOptionsUtils fail on static JDK Reviewed-by: dholmes, shade --- .../share/runtime/abstract_vm_version.cpp | 42 ++++++++++++------- .../optionsvalidation/JVMOptionsUtils.java | 7 +++- ...stMutuallyExclusivePlatformPredicates.java | 4 +- test/lib/jdk/test/lib/Platform.java | 6 ++- .../test/lib/cli/CommandLineOptionTest.java | 10 +++-- 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/src/hotspot/share/runtime/abstract_vm_version.cpp b/src/hotspot/share/runtime/abstract_vm_version.cpp index 05cccd4fe45..763e441fe54 100644 --- a/src/hotspot/share/runtime/abstract_vm_version.cpp +++ b/src/hotspot/share/runtime/abstract_vm_version.cpp @@ -138,31 +138,41 @@ const char* Abstract_VM_Version::vm_vendor() { const char* Abstract_VM_Version::vm_info_string() { + const char* mode; switch (Arguments::mode()) { case Arguments::_int: - return CDSConfig::is_using_archive() ? "interpreted mode, sharing" : "interpreted mode"; + mode = "interpreted mode"; + break; case Arguments::_mixed: - if (CDSConfig::is_using_archive()) { - if (CompilationModeFlag::quick_only()) { - return "mixed mode, emulated-client, sharing"; - } else { - return "mixed mode, sharing"; - } + if (CompilationModeFlag::quick_only()) { + mode = "mixed mode, emulated-client"; } else { - if (CompilationModeFlag::quick_only()) { - return "mixed mode, emulated-client"; - } else { - return "mixed mode"; - } + mode = "mixed mode"; } + break; case Arguments::_comp: if (CompilationModeFlag::quick_only()) { - return CDSConfig::is_using_archive() ? "compiled mode, emulated-client, sharing" : "compiled mode, emulated-client"; + mode = "compiled mode, emulated-client"; + } else { + mode = "compiled mode"; } - return CDSConfig::is_using_archive() ? "compiled mode, sharing" : "compiled mode"; + break; + default: + ShouldNotReachHere(); } - ShouldNotReachHere(); - return ""; + + const char* static_info = ", static"; + const char* sharing_info = ", sharing"; + size_t len = strlen(mode) + + (is_vm_statically_linked() ? strlen(static_info) : 0) + + (CDSConfig::is_using_archive() ? strlen(sharing_info) : 0) + + 1; + char* vm_info = NEW_C_HEAP_ARRAY(char, len, mtInternal); + // jio_snprintf places null character in the last character. + jio_snprintf(vm_info, len, "%s%s%s", mode, + is_vm_statically_linked() ? static_info : "", + CDSConfig::is_using_archive() ? sharing_info : ""); + return vm_info; } // NOTE: do *not* use stringStream. this function is called by diff --git a/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java b/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java index 031d30bf2bd..ef74dc41846 100644 --- a/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java +++ b/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOptionsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -61,7 +61,10 @@ public class JVMOptionsUtils { private static Map optionsAsMap; static { - if (Platform.isServer()) { + if (Platform.isStatic()) { + // -server|-client|-minimal flags are not supported on static JDK. + VMType = null; + } else if (Platform.isServer()) { VMType = "-server"; } else if (Platform.isClient()) { VMType = "-client"; diff --git a/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java b/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java index e78e200ac24..8047b81c1e6 100644 --- a/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java +++ b/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -51,7 +51,7 @@ public class TestMutuallyExclusivePlatformPredicates { VM_TYPE("isClient", "isServer", "isMinimal", "isZero", "isEmbedded"), MODE("isInt", "isMixed", "isComp"), IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isMusl", - "isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported", + "isStatic", "isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported", "areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported", "isHardenedOSX", "hasOSXPlistEntries", "isOracleLinux7", "isOnWayland"); diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index 682d9c90685..75fdef048bc 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -70,6 +70,10 @@ public class Platform { return vmName.contains("Embedded"); } + public static boolean isStatic() { + return vmInfo.contains("static"); + } + public static boolean isEmulatedClient() { return vmInfo.contains(" emulated-client"); } diff --git a/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java b/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java index 31cff4b8c25..57779b7d9fa 100644 --- a/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java +++ b/test/lib/jdk/test/lib/cli/CommandLineOptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -199,7 +199,9 @@ public abstract class CommandLineOptionTest { String wrongWarningMessage, ExitCode exitCode, String... options) throws Throwable { List finalOptions = new ArrayList<>(); - finalOptions.add(CommandLineOptionTest.getVMTypeOption()); + if (!Platform.isStatic()) { + finalOptions.add(CommandLineOptionTest.getVMTypeOption()); + } String extraFlagForEmulated = CommandLineOptionTest.getVMTypeOptionForEmulated(); if (extraFlagForEmulated != null) { finalOptions.add(extraFlagForEmulated); @@ -394,7 +396,9 @@ public abstract class CommandLineOptionTest { String expectedValue, String optionErrorString, String... additionalVMOpts) throws Throwable { List finalOptions = new ArrayList<>(); - finalOptions.add(CommandLineOptionTest.getVMTypeOption()); + if (!Platform.isStatic()) { + finalOptions.add(CommandLineOptionTest.getVMTypeOption()); + } String extraFlagForEmulated = CommandLineOptionTest.getVMTypeOptionForEmulated(); if (extraFlagForEmulated != null) { finalOptions.add(extraFlagForEmulated);