diff --git a/substratevm/mx.substratevm/macro-svmjfr.properties b/substratevm/mx.substratevm/macro-svmjfr.properties new file mode 100644 index 000000000000..b811a353413d --- /dev/null +++ b/substratevm/mx.substratevm/macro-svmjfr.properties @@ -0,0 +1,2 @@ +# This file contains support for building images with JFR support +ImageBuilderModulePath = ${.}/builder/svm-jfr.jar \ No newline at end of file diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 087ba1336595..a2c087379599 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1668,6 +1668,20 @@ def prevent_build_path_in_libgraal(): mx_sdk_vm.register_graalvm_component(libsvmjdwp) +mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVMSvmMacro( + suite=suite, + name='SubstrateVM JFR Support', + short_name='svmjfr', + dir_name="svmjfr", + license_files=[], + third_party_license_files=[], + dependencies=['SubstrateVM'], + builder_jar_distributions=['substratevm:SVM_JFR'], + support_distributions=['substratevm:SVM_JFR_SUPPORT'], + stability="experimental", + jlink=False, +)) + def _native_image_configure_extra_jvm_args(): packages = ['jdk.graal.compiler/jdk.graal.compiler.phases.common', 'jdk.internal.vm.ci/jdk.vm.ci.meta', 'jdk.internal.vm.ci/jdk.vm.ci.services', 'jdk.graal.compiler/jdk.graal.compiler.core.common.util'] args = ['--add-exports=' + packageName + '=ALL-UNNAMED' for packageName in packages] diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index 348697aae502..2a26269a289a 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -787,6 +787,21 @@ "spotbugs" : "false", }, + "com.oracle.svm.core.jfr": { + "subDir": "src", + "sourceDirs": ["src"], + "dependencies": [ + "com.oracle.svm.core" + ], + "javaCompliance" : "21+", + "annotationProcessors": [ + "compiler:GRAAL_PROCESSOR", + "SVM_PROCESSOR", + ], + "checkstyle": "com.oracle.svm.hosted", + "workingSets": "SVM", + }, + "com.oracle.svm.hosted.foreign": { "subDir": "src", "sourceDirs": ["src"], @@ -2513,6 +2528,36 @@ "maven" : False, }, + "SVM_JFR": { + "subDir": "src", + "description" : "SubstrateVM support for the JFR", + "dependencies": [ + "com.oracle.svm.core.jfr", + ], + "distDependencies": [ + "compiler:GRAAL", + "SVM" + ], + "moduleInfo" : { + "name" : "org.graalvm.nativeimage.jfr", + "requires" : [ + "org.graalvm.nativeimage.builder" + ], + # "exports" : [ + # "* to org.graalvm.nativeimage.builder" + # ], + }, + "maven" : False, + }, + + "SVM_JFR_SUPPORT" : { + "native" : True, + "description" : "JFR support", + "layout" : { + "native-image.properties" : "file:mx.substratevm/macro-svmjfr.properties", + }, + }, + "SVM_LLVM" : { "subDir" : "src", "description" : "LLVM backend for Native Image", diff --git a/substratevm/src/com.oracle.svm.core.jfr/src/com/oracle/svm/core/jfr/package-info.java b/substratevm/src/com.oracle.svm.core.jfr/src/com/oracle/svm/core/jfr/package-info.java new file mode 100644 index 000000000000..fd87f9e8b715 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core.jfr/src/com/oracle/svm/core/jfr/package-info.java @@ -0,0 +1 @@ +package com.oracle.svm.core.jfr; \ No newline at end of file diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java index 114c811bafa1..9847de50eed1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java @@ -50,7 +50,7 @@ import jdk.graal.compiler.options.OptionType; public final class VMInspectionOptions { - private static final String ENABLE_MONITORING_OPTION = "enable-monitoring"; + public static final String ENABLE_MONITORING_OPTION = "enable-monitoring"; private static final String MONITORING_DEFAULT_NAME = ""; private static final String MONITORING_ALL_NAME = "all"; private static final String MONITORING_HEAPDUMP_NAME = "heapdump"; @@ -146,6 +146,10 @@ private static Set getEnabledMonitoringFeatures() { private static boolean hasAllOrKeywordMonitoringSupport(String keyword) { Set enabledFeatures = getEnabledMonitoringFeatures(); + return includesAllOrKeywordMonitoringSupport(enabledFeatures, keyword); + } + + public static boolean includesAllOrKeywordMonitoringSupport(Set enabledFeatures, String keyword) { return enabledFeatures.contains(MONITORING_ALL_NAME) || enabledFeatures.contains(MONITORING_DEFAULT_NAME) || enabledFeatures.contains(keyword); } diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/CmdLineOptionHandler.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/CmdLineOptionHandler.java index 0110eb07df67..6132d1edb677 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/CmdLineOptionHandler.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/CmdLineOptionHandler.java @@ -25,14 +25,21 @@ package com.oracle.svm.driver; import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import com.oracle.svm.core.SubstrateOptions; +import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.VM; +import com.oracle.svm.core.VMInspectionOptions; import com.oracle.svm.core.option.OptionOrigin; import com.oracle.svm.core.util.ExitStatus; import com.oracle.svm.driver.NativeImage.ArgumentQueue; @@ -54,6 +61,7 @@ class CmdLineOptionHandler extends NativeImage.OptionHandler { /* Defunct legacy options that we have to accept to maintain backward compatibility */ private static final String VERBOSE_SERVER_OPTION = "--verbose-server"; private static final String SERVER_OPTION_PREFIX = "--server-"; + private static final String ENABLE_MONITORING_OPTION = "--" + VMInspectionOptions.ENABLE_MONITORING_OPTION; private static final String LAUNCHER_NAME = "native-image"; @@ -190,6 +198,21 @@ private boolean consume(ArgumentQueue args, String headArg) { return true; } + if (headArg.startsWith(ENABLE_MONITORING_OPTION)) { + String argValue; + if (headArg.length() == ENABLE_MONITORING_OPTION.length()) { + assert ENABLE_MONITORING_OPTION.equals(headArg); + argValue = "all"; + } else { + argValue = args.peek().substring(ENABLE_MONITORING_OPTION.length() + 1); + } + Set monitoringArg = Set.of(argValue.split(",")); + if (VMInspectionOptions.includesAllOrKeywordMonitoringSupport(monitoringArg, "jfr")) { + args.add("--macro:svmjfr"); + } + return false; + } + return false; }