Skip to content

Commit

Permalink
[GR-37582] Default to running image-builder on module path.
Browse files Browse the repository at this point in the history
PullRequest: graal/11488
  • Loading branch information
olpaw committed Jun 9, 2022
2 parents 7f8211c + bfb082e commit eac2590
Show file tree
Hide file tree
Showing 40 changed files with 382 additions and 278 deletions.
2 changes: 1 addition & 1 deletion compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@
"org.graalvm.compiler.core.common to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.objectfile",
"org.graalvm.compiler.debug to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.objectfile",
"org.graalvm.compiler.hotspot to jdk.internal.vm.compiler.management",
"org.graalvm.compiler.nodes.graphbuilderconf to org.graalvm.nativeimage.driver",
"org.graalvm.compiler.nodes.graphbuilderconf to org.graalvm.nativeimage.driver,org.graalvm.nativeimage.librarysupport",
"org.graalvm.compiler.options to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.junitsupport",
"org.graalvm.compiler.phases.common to org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure",
"org.graalvm.compiler.serviceprovider to jdk.internal.vm.compiler.management,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.diagnostics",
Expand Down
10 changes: 10 additions & 0 deletions java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ def extra_image_build_argument(self, benchmark, args):
'-H:EnableURLProtocols=http',
'-H:NativeLinkerOption=-no-pie',
'-H:-UseServiceLoaderFeature',
'--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.configure=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.localization=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED',
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.threadlocal=ALL-UNNAMED',
'-H:+StackTrace'] + super(BaseQuarkusBenchmarkSuite, self).extra_image_build_argument(benchmark, args)


Expand Down Expand Up @@ -460,6 +465,11 @@ def build_assertions(self, benchmark, is_gate):
# This method overrides NativeImageMixin.build_assertions
return [] # We are skipping build assertions due to some failed asserts while building Micronaut apps.

def extra_image_build_argument(self, benchmark, args):
return [
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED',
] + super(BaseMicronautBenchmarkSuite, self).extra_image_build_argument(benchmark, args)

def default_stages(self):
return ['instrument-image', 'instrument-run', 'image', 'run']

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Args = --features=com.oracle.svm.thirdparty.jline.JLine3Feature \
Args = --add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED \
--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED \
--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jni=ALL-UNNAMED \
--features=com.oracle.svm.thirdparty.jline.JLine3Feature \
--initialize-at-build-time=org.graalvm.launcher \
-H:JNIConfigurationResources=${.}/launcher.jniconfig \
--add-modules=java.scripting \
Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-37606) Add support for URLs and short descriptions to `Feature`. This info is shown as part of the build output.
* (GR-38965) Heap dumps are now supported in Community Edition.
* (GR-38951) Add `-XX:+DumpHeapAndExit` option to dump the initial heap of a native executable.
* (GR-37582) Run image-builder on module-path per default. Opt-out with env setting `USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false`.

## Version 22.1.0
* (GR-36568) Add "Quick build" mode, enabled through option `-Ob`, for quicker native image builds.
Expand Down
2 changes: 1 addition & 1 deletion substratevm/mx.substratevm/macro-junitcp.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Args = -H:Features=com.oracle.svm.junit.JUnitFeature \
-H:Class=com.oracle.svm.junit.SVMJUnitRunner \
-H:TestFile=${*} \
--initialize-at-build-time=org.junit,com.oracle.mxtool.junit \
[email protected]
[email protected]
45 changes: 33 additions & 12 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def image_demo_task(extra_image_args=None, flightrecorder=True):


def truffle_unittest_task(quickbuild=False):
truffle_build_args = ['--build-args', '--macro:truffle',
truffle_build_args = ['--force-builder-on-cp', '--build-args', '--macro:truffle',
'-H:MaxRuntimeCompileMethods=5000',
'-H:+TruffleCheckBlackListedMethods']
if quickbuild:
Expand Down Expand Up @@ -407,7 +407,7 @@ def svm_gate_body(args, tasks):
with native_image_context(IMAGE_ASSERTION_FLAGS) as native_image:
testlib = mx_subst.path_substitutions.substitute('-Dnative.test.lib=<path:truffle:TRUFFLE_TEST_NATIVE>/<lib:nativetest>')
isolation_testlib = mx_subst.path_substitutions.substitute('-Dnative.isolation.test.lib=<path:truffle:TRUFFLE_TEST_NATIVE>/<lib:isolationtest>')
native_unittest_args = ['com.oracle.truffle.nfi.test', '--build-args', '--language:nfi',
native_unittest_args = ['com.oracle.truffle.nfi.test', '--force-builder-on-cp', '--build-args', '--language:nfi',
'-H:MaxRuntimeCompileMethods=2000',
'-H:+TruffleCheckBlackListedMethods',
'--run-args', testlib, isolation_testlib, '--very-verbose', '--enable-timing']
Expand All @@ -418,7 +418,7 @@ def svm_gate_body(args, tasks):
with native_image_context(IMAGE_ASSERTION_FLAGS) as native_image:
testlib = mx_subst.path_substitutions.substitute('-Dnative.test.lib=<path:truffle:TRUFFLE_TEST_NATIVE>/<lib:nativetest>')
isolation_testlib = mx_subst.path_substitutions.substitute('-Dnative.isolation.test.lib=<path:truffle:TRUFFLE_TEST_NATIVE>/<lib:isolationtest>')
native_unittest_args = ['com.oracle.truffle.nfi.test', '--build-args', '--language:nfi',
native_unittest_args = ['com.oracle.truffle.nfi.test', '--force-builder-on-cp', '--build-args', '--language:nfi',
'-H:MaxRuntimeCompileMethods=2000',
'-H:+TruffleCheckBlackListedMethods'] + DEVMODE_FLAGS + [
'--run-args', testlib, isolation_testlib, '--very-verbose', '--enable-timing']
Expand Down Expand Up @@ -484,7 +484,7 @@ def native_unittests_task(extra_build_args=None):
if mx.is_windows():
mx_unittest.add_global_ignore_glob('com.oracle.svm.test.SecurityServiceTest')

native_unittest(['--builder-on-modulepath', '--build-args', _native_unittest_features] + additional_build_args)
native_unittest(['--build-args', _native_unittest_features] + additional_build_args)


def conditional_config_task(native_image):
Expand Down Expand Up @@ -564,7 +564,7 @@ def javac_image_command(javac_path):
)


def _native_junit(native_image, unittest_args, build_args=None, run_args=None, blacklist=None, whitelist=None, preserve_image=False, builder_on_modulepath=False):
def _native_junit(native_image, unittest_args, build_args=None, run_args=None, blacklist=None, whitelist=None, preserve_image=False, force_builder_on_cp=False):
build_args = build_args or []
javaProperties = {}
for dist in suite.dists:
Expand All @@ -591,8 +591,14 @@ def dummy_harness(test_deps, vm_launcher, vm_args):
with open(unittest_file, 'r') as f:
mx.log('Building junit image for matching: ' + ' '.join(l.rstrip() for l in f))
extra_image_args = mx.get_runtime_jvm_args(unittest_deps, jdk=mx_compiler.jdk, exclude_names=['substratevm:LIBRARY_SUPPORT'])
macro_junit = '--macro:junit' + ('' if builder_on_modulepath else 'cp')
unittest_image = native_image(['-ea', '-esa'] + build_args + extra_image_args + [macro_junit + '=' + unittest_file, '-H:Path=' + junit_test_dir])
macro_junit = '--macro:junit'
if force_builder_on_cp:
macro_junit += 'cp'
custom_env = os.environ.copy()
custom_env['USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM'] = 'false'
else:
custom_env = None
unittest_image = native_image(['-ea', '-esa'] + build_args + extra_image_args + [macro_junit + '=' + unittest_file, '-H:Path=' + junit_test_dir], env=custom_env)
image_pattern_replacement = unittest_image + ".exe" if mx.is_windows() else unittest_image
run_args = [arg.replace('${unittest.image}', image_pattern_replacement) for arg in run_args]
mx.log('Running: ' + ' '.join(map(pipes.quote, [unittest_image] + run_args)))
Expand All @@ -617,14 +623,14 @@ def unmask(args):

def _native_unittest(native_image, cmdline_args):
parser = ArgumentParser(prog='mx native-unittest', description='Run unittests as native image.')
all_args = ['--build-args', '--run-args', '--blacklist', '--whitelist', '-p', '--preserve-image', '--builder-on-modulepath']
all_args = ['--build-args', '--run-args', '--blacklist', '--whitelist', '-p', '--preserve-image', '--force-builder-on-cp']
cmdline_args = [_mask(arg, all_args) for arg in cmdline_args]
parser.add_argument(all_args[0], metavar='ARG', nargs='*', default=[])
parser.add_argument(all_args[1], metavar='ARG', nargs='*', default=[])
parser.add_argument('--blacklist', help='run all testcases not specified in <file>', metavar='<file>')
parser.add_argument('--whitelist', help='run testcases specified in <file> only', metavar='<file>')
parser.add_argument('-p', '--preserve-image', help='do not delete the generated native image', action='store_true')
parser.add_argument('--builder-on-modulepath', help='perform image build with builder on module-path', action='store_true')
parser.add_argument('--force-builder-on-cp', help='force image builder to run on classpath', action='store_true')
parser.add_argument('unittest_args', metavar='TEST_ARG', nargs='*')
pargs = parser.parse_args(cmdline_args)

Expand All @@ -645,8 +651,7 @@ def _native_unittest(native_image, cmdline_args):
mx.log('warning: could not read blacklist: ' + blacklist)

unittest_args = unmask(pargs.unittest_args) if unmask(pargs.unittest_args) else ['com.oracle.svm.test', 'com.oracle.svm.configure.test']
builder_on_modulepath = pargs.builder_on_modulepath
_native_junit(native_image, unittest_args, unmask(pargs.build_args), unmask(pargs.run_args), blacklist, whitelist, pargs.preserve_image, builder_on_modulepath)
_native_junit(native_image, unittest_args, unmask(pargs.build_args), unmask(pargs.run_args), blacklist, whitelist, pargs.preserve_image, pargs.force_builder_on_cp)


def jvm_unittest(args):
Expand Down Expand Up @@ -728,7 +733,7 @@ def _cinterfacetutorial(native_image, args=None):
mkpath(build_dir)

# Build the shared library from Java code
native_image(['--shared', '-H:Path=' + build_dir, '-H:Name=libcinterfacetutorial',
native_image(['--shared', '-H:Path=' + build_dir, '-H:Name=libcinterfacetutorial', '-Dcom.oracle.svm.tutorial.headerfile=' + join(c_source_dir, 'mydata.h'),
'-H:CLibraryPath=' + tutorial_proj.dir, '-cp', tutorial_proj.output_dir()] + args)

# Build the C executable
Expand Down Expand Up @@ -1090,6 +1095,22 @@ def _native_image_launcher_extra_jvm_args():
'compiler:GRAAL_MANAGEMENT_LIBGRAAL']

libgraal_build_args = [
## Pass via JVM args opening up of packages needed for image builder early on
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.hotspot=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.options=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.common.hotspot=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.compiler.truffle.common=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.jniutils=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.libgraal.jni.annotation=ALL-UNNAMED',
'-J--add-exports=jdk.internal.vm.compiler/org.graalvm.libgraal.jni=ALL-UNNAMED',
'-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.annotate=ALL-UNNAMED',
'-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.option=ALL-UNNAMED',
## Packages used after option-processing can be opened by the builder (`-J`-prefix not needed)
# LibGraalFeature implements com.oracle.svm.core.graal.GraalFeature (needed to be able to instantiate LibGraalFeature)
'--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.graal=ALL-UNNAMED',
# Make ModuleSupport accessible to do the remaining opening-up in LibGraalFeature constructor
'--add-exports=org.graalvm.nativeimage.base/com.oracle.svm.util=ALL-UNNAMED',

'--initialize-at-build-time=org.graalvm.compiler,org.graalvm.libgraal,com.oracle.truffle',
'-H:-UseServiceLoaderFeature',
'-H:+AllowFoldMethods',
Expand Down
13 changes: 3 additions & 10 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@
"com.oracle.svm.tutorial" : {
"subDir": "src",
"sourceDirs" : ["src"],
"dependencies" : ["com.oracle.svm.core"],
"dependencies" : ["sdk:GRAAL_SDK"],
"checkstyle" : "com.oracle.svm.hosted",
"javaCompliance": "11+",
"annotationProcessors" : [
Expand Down Expand Up @@ -1126,13 +1126,6 @@
"moduleInfo" : {
"name" : "org.graalvm.nativeimage.builder",
"exports" : [
"com.oracle.svm.core.configure", # even Feature impls on class-path need access, thus unqualified
"com.oracle.svm.core.jdk", # Uses of com.oracle.svm.core.jdk.StackTraceUtils
"com.oracle.svm.core.snippets", # Uses of com.oracle.svm.core.snippets.KnownIntrinsics
"com.oracle.svm.core", # Uses of com.oracle.svm.core.TypeResult
"com.oracle.svm.core.util", # Uses of com.oracle.svm.core.util.VMError
"com.oracle.svm.core.jni", # Uses of com.oracle.svm.core.jni.JNIRuntimeAccess
"com.oracle.svm.core.jfr", # Uses of com.oracle.svm.core.jfr.HasJfrSupport
"com.oracle.svm.hosted to java.base",
"com.oracle.svm.hosted.agent to java.instrument",
"com.oracle.svm.truffle.api to org.graalvm.truffle",
Expand Down Expand Up @@ -1467,8 +1460,8 @@
"moduleInfo" : {
"name" : "org.graalvm.nativeimage.base",
"exports" : [
"com.oracle.svm.util",
"com.oracle.svm.common.option",
"com.oracle.svm.util to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.driver,org.graalvm.nativeimage.llvm,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.junitsupport,com.oracle.svm.svm_enterprise",
"com.oracle.svm.common.option to org.graalvm.nativeimage.pointsto,org.graalvm.nativeimage.builder,org.graalvm.nativeimage.driver",
],
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class SignatureUtilFeature implements Feature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
if (!access.getApplicationClassPath().isEmpty()) {
ModuleSupport.exportAndOpenPackageToClass("jdk.internal.vm.ci", "jdk.vm.ci.meta", false, SignatureUtil.class);
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, SignatureUtil.class, false, "jdk.internal.vm.ci", "jdk.vm.ci.meta");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import com.oracle.svm.core.graal.llvm.lowering.LLVMLoadExceptionObjectLowering;
import com.oracle.svm.core.graal.llvm.lowering.SubstrateLLVMLoweringProvider;
import com.oracle.svm.core.graal.llvm.replacements.LLVMGraphBuilderPlugins;
import com.oracle.svm.core.graal.llvm.replacements.LLVMIntrinsicNode;
import com.oracle.svm.core.graal.llvm.runtime.LLVMExceptionUnwind;
import com.oracle.svm.core.graal.llvm.util.LLVMOptions;
import com.oracle.svm.core.graal.llvm.util.LLVMToolchain;
Expand Down Expand Up @@ -90,7 +89,8 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
if (ModuleSupport.modulePathBuild) {
ModuleSupport.openModuleByClass(LLVMIntrinsicNode.class, NodeClass.class);
ModuleSupport.accessModuleByClass(ModuleSupport.Access.EXPORT, NodeClass.class, LLVMGraphBuilderPlugins.class);
ModuleSupport.accessModuleByClass(ModuleSupport.Access.EXPORT, NodeClass.class, SubstrateLLVMLoweringProvider.class);
}

ImageSingletons.add(SubstrateBackendFactory.class, new SubstrateBackendFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ public List<Class<? extends Feature>> getRequiredFeatures() {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
ModuleSupport.exportAndOpenAllPackagesToUnnamed("jdk.jfr", false);
ModuleSupport.exportAndOpenAllPackagesToUnnamed("java.base", false);
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "jdk.jfr");
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base");

// Initialize some parts of JFR/JFC at image build time.
List<Configuration> knownConfigurations = JFC.getConfigurations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.oracle.svm.driver.NativeImage.ArgumentQueue;
import com.oracle.svm.hosted.FeatureImpl;
import com.oracle.svm.hosted.option.HostedOptionParser;
import com.oracle.svm.util.ModuleSupport;
import com.oracle.svm.util.ReflectionUtil;
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;

Expand Down Expand Up @@ -474,6 +475,12 @@ final class APIOptionSupport {
@AutomaticFeature
final class APIOptionFeature implements Feature {

@Override
public void afterRegistration(AfterRegistrationAccess access) {
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.EXPORT, APIOptionFeature.class, true,
"jdk.internal.vm.compiler", "org.graalvm.compiler.options");
}

@Override
public void duringSetup(DuringSetupAccess access) {
FeatureImpl.DuringSetupAccessImpl accessImpl = (FeatureImpl.DuringSetupAccessImpl) access;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ private void applyEnabled(MacroOption.EnabledOption enabledOption, String argume
}

BuildConfiguration config = nativeImage.config;

String propertyName = "BuilderOnClasspath";
String propertyValue = enabledOption.getProperty(config, propertyName);
if (propertyValue != null) {
boolean modulePathBuild = !Boolean.valueOf(propertyValue);
String imageBuilderModeEnforcer = enabledOption.getOption().toString();
if (config.imageBuilderModeEnforcer != null && modulePathBuild != config.modulePathBuild) {
NativeImage.showError(String.format("Conflicting %s property values. %s (%b) vs %s (%b)", propertyName,
imageBuilderModeEnforcer, modulePathBuild, config.imageBuilderModeEnforcer, config.modulePathBuild));
}
config.imageBuilderModeEnforcer = imageBuilderModeEnforcer;
config.modulePathBuild = modulePathBuild;
}

enabledOption.forEachPropertyValue(config, "ImageBuilderClasspath", entry -> nativeImage.addImageBuilderClasspath(ClasspathUtils.stringToClasspath(entry)), PATH_SEPARATOR_REGEX);

boolean explicitImageModulePath = enabledOption.forEachPropertyValue(
Expand Down
Loading

0 comments on commit eac2590

Please sign in to comment.