Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [GR-61757] Load Native Image JFR support conditionally #10743

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions substratevm/mx.substratevm/macro-svmjfr.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file contains support for building images with JFR support
ImageBuilderModulePath = ${.}/builder/svm-jfr.jar
14 changes: 14 additions & 0 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@
_run_graalvm_cmd(['build'], config)
native_image_cmd = vm_native_image_path(config)
if not exists(native_image_cmd):
raise mx.abort('The built GraalVM for config ' + str(config) + ' does not contain a native-image command')

Check failure on line 281 in substratevm/mx.substratevm/mx_substratevm.py

View workflow job for this annotation

GitHub Actions / /substratevm build,helloworld,native_unittests JDKlatest

The built GraalVM for config ' + str(config) + ' does not contain a native-image command

Check failure on line 281 in substratevm/mx.substratevm/mx_substratevm.py

View workflow job for this annotation

GitHub Actions / /substratevm build,helloworld,native_unittests JDKlatest

The built GraalVM for config ' + str(config) + ' does not contain a native-image command

Check failure on line 281 in substratevm/mx.substratevm/mx_substratevm.py

View workflow job for this annotation

GitHub Actions / /substratevm build,debuginfotest JDKlatest

The built GraalVM for config ' + str(config) + ' does not contain a native-image command

Check failure on line 281 in substratevm/mx.substratevm/mx_substratevm.py

View workflow job for this annotation

GitHub Actions / /substratevm build,debuginfotest JDKlatest

The built GraalVM for config ' + str(config) + ' does not contain a native-image command

def _native_image(args, **kwargs):
return mx.run([native_image_cmd] + _maybe_convert_to_args_file(args), **kwargs)
Expand Down Expand Up @@ -1668,6 +1668,20 @@

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]
Expand Down
45 changes: 45 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.oracle.svm.core.jfr;
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<deprecated-default>";
private static final String MONITORING_ALL_NAME = "all";
private static final String MONITORING_HEAPDUMP_NAME = "heapdump";
Expand Down Expand Up @@ -146,6 +146,10 @@ private static Set<String> getEnabledMonitoringFeatures() {

private static boolean hasAllOrKeywordMonitoringSupport(String keyword) {
Set<String> enabledFeatures = getEnabledMonitoringFeatures();
return includesAllOrKeywordMonitoringSupport(enabledFeatures, keyword);
}

public static boolean includesAllOrKeywordMonitoringSupport(Set<String> enabledFeatures, String keyword) {
return enabledFeatures.contains(MONITORING_ALL_NAME) || enabledFeatures.contains(MONITORING_DEFAULT_NAME) || enabledFeatures.contains(keyword);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +61,7 @@ class CmdLineOptionHandler extends NativeImage.OptionHandler<NativeImage> {
/* 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";

Expand Down Expand Up @@ -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<String> monitoringArg = Set.of(argValue.split(","));
if (VMInspectionOptions.includesAllOrKeywordMonitoringSupport(monitoringArg, "jfr")) {
args.add("--macro:svmjfr");
}
return false;
}

return false;
}

Expand Down
Loading