5656from mx_substratevm_benchmark import run_js , host_vm_tuple , output_processors , rule_snippets # pylint: disable=unused-import
5757from mx_unittest import _run_tests , _VMLauncher
5858
59- GRAAL_COMPILER_FLAGS = [
59+ GRAAL_COMPILER_FLAGS_BASE = [
60+ '-XX:+UnlockExperimentalVMOptions' ,
61+ '-XX:+EnableJVMCI' ,
6062 '-XX:-UseJVMCICompiler' , # GR-8656: Do not run with Graal as JIT compiler until libgraal is available.
6163 '-Dtruffle.TrustAllTruffleRuntimeProviders=true' , # GR-7046
6264]
6365
64- if mx .get_jdk (tag = 'default' ).javaCompliance <= mx .JavaCompliance ('1.8' ):
65- GRAAL_COMPILER_FLAGS += ['-XX:-UseJVMCIClassLoader' ]
66+ GRAAL_COMPILER_FLAGS_MAP = dict ()
67+ GRAAL_COMPILER_FLAGS_MAP ['1.8' ] = ['-d64' , '-noverify' , '-XX:-UseJVMCIClassLoader' ]
68+ GRAAL_COMPILER_FLAGS_MAP ['11' ] = []
69+ # Disable the check for JDK-8 graal version.
70+ GRAAL_COMPILER_FLAGS_MAP ['11' ] += ['-Dsubstratevm.IgnoreGraalVersionCheck=true' ]
71+ # GR-11937: Use bytecodes instead of invoke-dynamic for string concatenation.
72+ GRAAL_COMPILER_FLAGS_MAP ['11' ] += ['-Djava.lang.invoke.stringConcat=BC_SB' ]
73+
74+
75+ # Turn a list of package names into a list of `--add-exports` command line arguments.
76+ def add_exports_from_packages (packageNameList ):
77+ # Return one command line argument (pair) for one package name.
78+ def add_exports_to_all_unnamed (packageName ):
79+ return ['--add-exports' , packageName + '=ALL-UNNAMED' ]
80+
81+ return itertools .chain .from_iterable (add_exports_to_all_unnamed (package ) for package in packageNameList )
82+
83+
84+ # Turn a list of package names into a list of `--add-opens` command line arguments.
85+ def add_opens_from_packages (packageNameList ):
86+ # Return one command line argument (pair) for one package name.
87+ def add_opens_to_all_unnamed (packageName ):
88+ return ['--add-opens' , packageName + '=ALL-UNNAMED' ]
89+
90+ return itertools .chain .from_iterable (add_opens_to_all_unnamed (package ) for package in packageNameList )
91+
92+
93+ # JVMCI access
94+ graal_compiler_export_packages = [
95+ 'jdk.internal.vm.ci/jdk.vm.ci.runtime' ,
96+ 'jdk.internal.vm.ci/jdk.vm.ci.code' ,
97+ 'jdk.internal.vm.ci/jdk.vm.ci.amd64' ,
98+ 'jdk.internal.vm.ci/jdk.vm.ci.meta' ,
99+ 'jdk.internal.vm.ci/jdk.vm.ci.hotspot' ,
100+ 'jdk.internal.vm.ci/jdk.vm.ci.common' ]
101+ GRAAL_COMPILER_FLAGS_MAP ['11' ].extend (add_exports_from_packages (graal_compiler_export_packages ))
102+
103+ # Packages to open to allow reflective access at runtime.
104+ jdk_opens_packages = [
105+ # Reflective access
106+ 'jdk.unsupported/sun.reflect' ,
107+ # Reflective access to jdk.internal.module.Modules, using which I can export and open other modules.
108+ 'java.base/jdk.internal.module'
109+ ]
110+ GRAAL_COMPILER_FLAGS_MAP ['11' ].extend (add_opens_from_packages (jdk_opens_packages ))
111+
112+ # These packages should be opened at runtime calls to Modules.addOpens, if they are still needed.
113+ java_base_opens_packages = [
114+ # Reflective access to jdk.internal.ref.CleanerImpl$PhantomCleanableRef.
115+ 'java.base/jdk.internal.ref' ,
116+ # Reflective access to private fields of java.lang.Class.
117+ 'java.base/java.lang' ,
118+ # Reflective access to java.lang.invoke.VarHandle*.
119+ 'java.base/java.lang.invoke' ,
120+ # Reflective access to java.lang.Reference.referent.
121+ 'java.base/java.lang.ref' ,
122+ # Reflective access to java.net.URL.getURLStreamHandler.
123+ 'java.base/java.net' ,
124+ # Reflective access to java.nio.MappedByteBuffer.fd.
125+ 'java.base/java.nio' ,
126+ # Reflective access to java.util.Bits.words.
127+ 'java.base/java.util' ]
128+ GRAAL_COMPILER_FLAGS_MAP ['11' ].extend (add_opens_from_packages (java_base_opens_packages ))
129+
130+ # Reflective access to org.graalvm.nativeimage.impl.ImageSingletonsSupport.
131+ graal_sdk_opens_packages = [
132+ 'org.graalvm.sdk/org.graalvm.nativeimage.impl' ]
133+ GRAAL_COMPILER_FLAGS_MAP ['11' ].extend (add_opens_from_packages (graal_sdk_opens_packages ))
134+
135+ def svm_java_compliance ():
136+ return mx .get_jdk (tag = 'default' ).javaCompliance
137+
138+ def svm_java80 ():
139+ return svm_java_compliance () <= mx .JavaCompliance ('1.8' )
140+
141+ if svm_java80 ():
142+ GRAAL_COMPILER_FLAGS = GRAAL_COMPILER_FLAGS_BASE + GRAAL_COMPILER_FLAGS_MAP ['1.8' ]
66143else :
67- # Disable the check for JDK-8 graal version.
68- GRAAL_COMPILER_FLAGS += ['-Dsubstratevm.IgnoreGraalVersionCheck=true' ]
69- # GR-11937: Use bytecodes instead of invoke-dynamic for string concatenation.
70- GRAAL_COMPILER_FLAGS += ['-Djava.lang.invoke.stringConcat=BC_SB' ]
71-
72- # Turn a list of package names into a list of `--add-exports` command line arguments.
73- def add_exports_from_packages (packageNameList ):
74- # Return one command line argument (pair) for one package name.
75- def add_exports_to_all_unnamed (packageName ):
76- return ['--add-exports' , packageName + '=ALL-UNNAMED' ]
77- return itertools .chain .from_iterable (add_exports_to_all_unnamed (package ) for package in packageNameList )
78-
79- # Turn a list of package names into a list of `--add-opens` command line arguments.
80- def add_opens_from_packages (packageNameList ):
81- # Return one command line argument (pair) for one package name.
82- def add_opens_to_all_unnamed (packageName ):
83- return ['--add-opens' , packageName + '=ALL-UNNAMED' ]
84- return itertools .chain .from_iterable (add_opens_to_all_unnamed (package ) for package in packageNameList )
85-
86- # JVMCI access
87- graal_compiler_export_packages = [
88- 'jdk.internal.vm.ci/jdk.vm.ci.runtime' ,
89- 'jdk.internal.vm.ci/jdk.vm.ci.code' ,
90- 'jdk.internal.vm.ci/jdk.vm.ci.amd64' ,
91- 'jdk.internal.vm.ci/jdk.vm.ci.meta' ,
92- 'jdk.internal.vm.ci/jdk.vm.ci.hotspot' ,
93- 'jdk.internal.vm.ci/jdk.vm.ci.common' ]
94- GRAAL_COMPILER_FLAGS .extend (add_exports_from_packages (graal_compiler_export_packages ))
95-
96- # Packages to open to allow reflective access at runtime.
97- jdk_opens_packages = [
98- # Reflective access
99- 'jdk.unsupported/sun.reflect' ,
100- # Reflective access to jdk.internal.module.Modules, using which I can export and open other modules.
101- 'java.base/jdk.internal.module'
102- ]
103- GRAAL_COMPILER_FLAGS .extend (add_opens_from_packages (jdk_opens_packages ))
104-
105- # These packages should be opened at runtime calls to Modules.addOpens, if they are still needed.
106- java_base_opens_packages = [
107- # Reflective access to jdk.internal.ref.CleanerImpl$PhantomCleanableRef.
108- 'java.base/jdk.internal.ref' ,
109- # Reflective access to private fields of java.lang.Class.
110- 'java.base/java.lang' ,
111- # Reflective access to java.lang.invoke.VarHandle*.
112- 'java.base/java.lang.invoke' ,
113- # Reflective access to java.lang.Reference.referent.
114- 'java.base/java.lang.ref' ,
115- # Reflective access to java.net.URL.getURLStreamHandler.
116- 'java.base/java.net' ,
117- # Reflective access to java.nio.MappedByteBuffer.fd.
118- 'java.base/java.nio' ,
119- # Reflective access to java.util.Bits.words.
120- 'java.base/java.util' ]
121- GRAAL_COMPILER_FLAGS .extend (add_opens_from_packages (java_base_opens_packages ))
122-
123- # Reflective access to org.graalvm.nativeimage.impl.ImageSingletonsSupport.
124- graal_sdk_opens_packages = [
125- 'org.graalvm.sdk/org.graalvm.nativeimage.impl' ]
126- GRAAL_COMPILER_FLAGS .extend (add_opens_from_packages (graal_sdk_opens_packages ))
144+ GRAAL_COMPILER_FLAGS = GRAAL_COMPILER_FLAGS_BASE + GRAAL_COMPILER_FLAGS_MAP ['11' ]
127145
128146IMAGE_ASSERTION_FLAGS = ['-H:+VerifyGraalGraphs' , '-H:+VerifyGraalGraphEdges' , '-H:+VerifyPhases' ]
129147suite = mx .suite ('substratevm' )
@@ -167,7 +185,7 @@ def svmbuild_dir(suite=None):
167185def suite_native_image_root (suite = None ):
168186 if not suite :
169187 suite = svm_suite ()
170- root_dir = join (svmbuild_dir (suite ), 'native-image-root' )
188+ root_dir = join (svmbuild_dir (suite ), 'native-image-root-' + str ( svm_java_compliance ()) )
171189 rev_file_name = join (root_dir , 'rev' )
172190 rev_value = suite .vc .parent (suite .vc_dir )
173191 def write_rev_file ():
@@ -344,17 +362,24 @@ def native_image_layout_dists(subdir, dist_names):
344362 def native_image_extract_dists (subdir , dist_names ):
345363 native_image_extract (names_to_dists (dist_names ), subdir , native_image_root )
346364
347- # Create native-image layout for sdk parts
348- native_image_layout_dists (join ('lib' , 'boot' ), ['sdk:GRAAL_SDK' ])
349365 native_image_layout_dists (join ('lib' , 'graalvm' ), ['substratevm:SVM_DRIVER' , 'sdk:LAUNCHER_COMMON' ])
350366
367+ # Create native-image layout for sdk parts
368+ graal_sdk_dists = ['sdk:GRAAL_SDK' ]
369+ if svm_java80 ():
370+ native_image_layout_dists (join ('lib' , 'boot' ), graal_sdk_dists )
371+ jvmci_dists = graalDistribution
372+ else :
373+ jvmci_dists = graalDistribution + graal_sdk_dists
374+
351375 # Create native-image layout for compiler & jvmci parts
352- native_image_layout_dists (join ('lib' , 'jvmci' ), graalDistribution )
353- jdk_config = mx .get_jdk ()
354- jvmci_path = join (jdk_config .home , 'jre' , 'lib' , 'jvmci' )
355- if os .path .isdir (jvmci_path ):
356- for symlink_name in os .listdir (jvmci_path ):
357- symlink_or_copy (join (jvmci_path , symlink_name ), join (native_image_root , 'lib' , 'jvmci' , symlink_name ))
376+ native_image_layout_dists (join ('lib' , 'jvmci' ), jvmci_dists )
377+ if svm_java80 ():
378+ jdk_config = mx .get_jdk ()
379+ jvmci_path = join (jdk_config .home , 'jre' , 'lib' , 'jvmci' )
380+ if os .path .isdir (jvmci_path ):
381+ for symlink_name in os .listdir (jvmci_path ):
382+ symlink_or_copy (join (jvmci_path , symlink_name ), join (native_image_root , 'lib' , 'jvmci' , symlink_name ))
358383
359384 # Create native-image layout for truffle parts
360385 native_image_layout_dists (join ('lib' , 'truffle' ), ['truffle:TRUFFLE_API' , 'truffle:TRUFFLE_NFI' ])
@@ -901,6 +926,28 @@ def build(args, vm=None):
901926 if not _host_os_supported ():
902927 mx .abort ('build: SubstrateVM can be built only on Darwin, Linux and Windows platforms' )
903928
929+ graal_compiler_flags_dir = join (mx .dependency ('substratevm:com.oracle.svm.driver' ).dir , 'resources' )
930+
931+ def update_if_needed (version_tag , graal_compiler_flags ):
932+ flags_filename = 'graal-compiler-flags-' + version_tag + '.config'
933+ flags_path = join (graal_compiler_flags_dir , flags_filename )
934+ flags_contents = '\n ' .join (graal_compiler_flags )
935+ needs_update = True
936+ try :
937+ with open (flags_path , 'r' ) as flags_file :
938+ if flags_file .read () == flags_contents :
939+ needs_update = False
940+ except :
941+ pass
942+
943+ if needs_update :
944+ with open (flags_path , 'w' ) as f :
945+ print ('Write file ' + flags_path )
946+ f .write (flags_contents )
947+
948+ for version_tag in GRAAL_COMPILER_FLAGS_MAP :
949+ update_if_needed (version_tag , GRAAL_COMPILER_FLAGS_BASE + GRAAL_COMPILER_FLAGS_MAP [version_tag ])
950+
904951 orig_command_build (args , vm )
905952
906953
@@ -918,8 +965,11 @@ def native_image_on_jvm(args, **kwargs):
918965 driver_cp = list (itertools .chain .from_iterable (glob .glob (cp ) for cp in driver_cp ))
919966
920967 svm_version = suite .release_version (snapshotSuffix = 'SNAPSHOT' )
921- run_java (['-Dorg.graalvm.version=' + svm_version , '-Dnative-image.root=' + suite_native_image_root (), '-cp' , os .pathsep .join (driver_cp ),
922- mx .dependency ('substratevm:SVM_DRIVER' ).mainClass ] + save_args , ** kwargs )
968+ run_java ([
969+ '-Dorg.graalvm.version=' + svm_version ,
970+ '-Dnative-image.root=' + suite_native_image_root (),
971+ '-cp' , os .pathsep .join (driver_cp ),
972+ mx .dependency ('substratevm:SVM_DRIVER' ).mainClass ] + save_args , ** kwargs )
923973
924974
925975@mx .command (suite .name , 'native-unittest' )
0 commit comments