Skip to content

Commit

Permalink
use new jlink options from JDK-8232080
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Nov 4, 2019
1 parent da65dd0 commit fd91dd2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
18 changes: 12 additions & 6 deletions compiler/mx.compiler/mx_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
from mx_javamodules import as_java_module
from mx_updategraalinopenjdk import updategraalinopenjdk
from mx_renamegraalpackages import renamegraalpackages
from mx_sdk_vm import jdk_enables_jvmci_by_default, jlink_new_jdk
from mx_sdk_vm import jlink_new_jdk

import mx_jaotc

Expand Down Expand Up @@ -1149,8 +1149,9 @@ def makegraaljdk_cli(args):
if args.bootstrap:
map_file = join(dst_jdk_dir, 'proguard.map')
with StdoutUnstripping(args=[], out=None, err=None, mapFiles=[map_file]) as u:
select_graal = [] if jdk_enables_jvmci_by_default(dst_jdk) else ['-XX:+UnlockExperimentalVMOptions', '-XX:+UseJVMCICompiler']
mx.run([dst_jdk.java] + select_graal + ['-XX:+BootstrapJVMCI', '-version'], out=u.out, err=u.err)
# Just use a set of flags that will work on all JVMCI enabled VMs without trying
# to remove flags that are unnecessary for a specific VM.
mx.run([dst_jdk.java, '-XX:+UnlockExperimentalVMOptions', '-XX:+UseJVMCICompiler', '-XX:+BootstrapJVMCI', '-version'], out=u.out, err=u.err)
if args.archive:
mx.log('Archiving {}'.format(args.archive))
create_archive(dst_jdk_dir, args.archive, basename(args.dest) + '/')
Expand Down Expand Up @@ -1226,6 +1227,12 @@ def _copy_file(src, dst):
mx.log('Copying {} to {}'.format(src, dst))
shutil.copyfile(src, dst)

vm_name = 'Graal'
for d in _graal_config().jvmci_dists:
s = ':' + d.suite.name + '_' + d.suite.version()
if s not in vm_name:
vm_name = vm_name + s

if isJDK8:
jre_dir = join(tmp_dst_jdk_dir, 'jre')
shutil.copytree(src_jdk.home, tmp_dst_jdk_dir)
Expand Down Expand Up @@ -1253,7 +1260,8 @@ def _copy_file(src, dst):
else:
module_dists = _graal_config().dists
_check_using_latest_jars(module_dists)
jlink_new_jdk(jdk, tmp_dst_jdk_dir, module_dists, root_module_names=root_module_names)
vendor_info = {'vendor-version' : vm_name}
jlink_new_jdk(jdk, tmp_dst_jdk_dir, module_dists, root_module_names=root_module_names, vendor_info=vendor_info)
jre_dir = tmp_dst_jdk_dir
jvmci_dir = mx.ensure_dir_exists(join(jre_dir, 'lib', 'jvmci'))
if export_truffle:
Expand Down Expand Up @@ -1284,12 +1292,10 @@ def _copy_file(src, dst):
mx.ensure_dir_exists(libjvm_dir)
jvmlib = join(libjvm_dir, mx.add_lib_prefix(mx.add_lib_suffix('jvm')))

vm_name = 'Graal'
with open(join(tmp_dst_jdk_dir, 'release.jvmci'), 'w') as fp:
for d in _graal_config().jvmci_dists:
s = d.suite
print('{}={}'.format(d.name, s.vc.parent(s.dir)), file=fp)
vm_name = vm_name + ':' + s.name + '_' + s.version()
for d in _graal_config().boot_dists + _graal_config().truffle_dists:
s = d.suite
print('{}={}'.format(d.name, s.vc.parent(s.dir)), file=fp)
Expand Down
8 changes: 6 additions & 2 deletions sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,9 @@ def jdk_enables_jvmci_by_default(jdk):
return mx_sdk_vm.jdk_enables_jvmci_by_default(jdk)


def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missing_export_target_action='create', with_source=lambda x: True):
return mx_sdk_vm.jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=root_module_names, missing_export_target_action=missing_export_target_action, with_source=with_source)
def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missing_export_target_action='create', with_source=lambda x: True, vendor_info=None):
return mx_sdk_vm.jlink_new_jdk(jdk, dst_jdk_dir, module_dists,
root_module_names=root_module_names,
missing_export_target_action=missing_export_target_action,
with_source=with_source,
vendor_info=vendor_info)
14 changes: 13 additions & 1 deletion sdk/mx.sdk/mx_sdk_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def jdk_enables_jvmci_by_default(jdk):
return getattr(jdk, '.enables_jvmci_by_default')


def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missing_export_target_action='create', with_source=lambda x: True):
def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missing_export_target_action='create', with_source=lambda x: True, vendor_info=None):
"""
Uses jlink from `jdk` to create a new JDK image in `dst_jdk_dir` with `module_dists` and
their dependencies added to the JDK image, replacing any existing modules of the same name.
Expand All @@ -454,6 +454,7 @@ def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missin
"error" - raise an error
None - do nothing
:param lambda with_source: returns True if the sources of a module distribution must be included in the new JDK
:param dict vendor_info: values for the jlink vendor options added by JDK-8232080
"""
assert callable(with_source)

Expand Down Expand Up @@ -555,6 +556,7 @@ def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missin
dst_src_zip_contents[jmd.name + '/module-info.java'] = jmd.as_module_info(extras_as_comments=False)

# Now build the new JDK image with jlink
jlink_exe = jdk.javac.replace('javac', 'jlink')
jlink = [jdk.javac.replace('javac', 'jlink')]

if jdk_enables_jvmci_by_default(jdk):
Expand All @@ -580,6 +582,16 @@ def jlink_new_jdk(jdk, dst_jdk_dir, module_dists, root_module_names=None, missin
jlink.append('--dedup-legal-notices=error-if-not-same-content')
jlink.append('--keep-packaged-modules=' + join(dst_jdk_dir, 'jmods'))

# https://bugs.openjdk.java.net/browse/JDK-8232080
output = mx.OutputCapture()
mx.run([jlink_exe, '--list-plugins'], out=output)
if '--add-options=' in output.data:
assert '--vendor-version=' in output.data
jlink.append('--add-options=-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:-UnlockExperimentalVMOptions')
if vendor_info is not None:
for name, value in vendor_info.items():
jlink.append('--' + name + '=' + value)

# TODO: investigate the options below used by OpenJDK to see if they should be used:
# --release-info: this allow extra properties to be written to the <jdk>/release file
# --order-resources: specifies order of resources in generated lib/modules file.
Expand Down
16 changes: 11 additions & 5 deletions sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,8 @@ def __init__(self, subject, args):

def build(self):
with_source = lambda dep: not isinstance(dep, mx.Dependency) or (_include_sources() and dep.isJARDistribution() and not dep.is_stripped())
mx_sdk.jlink_new_jdk(_src_jdk, self.subject.output_directory(), self.subject.deps, with_source=with_source)
vendor_info = {'vendor-version' : graalvm_vendor_version(get_final_graalvm_distribution())}
mx_sdk.jlink_new_jdk(_src_jdk, self.subject.output_directory(), self.subject.deps, with_source=with_source, vendor_info=vendor_info)
with open(self._config_file(), 'w') as f:
f.write('\n'.join(self._config()))

Expand Down Expand Up @@ -2493,7 +2494,6 @@ def log_graalvm_vm_name(args):
_ = parser.parse_args(args)
mx.log(graalvm_vm_name(get_final_graalvm_distribution(), _src_jdk))


def graalvm_vm_name(graalvm_dist, jdk):
"""
:type jdk_home: str
Expand All @@ -2502,10 +2502,16 @@ def graalvm_vm_name(graalvm_dist, jdk):
out = _decode(subprocess.check_output([jdk.java, '-version'], stderr=subprocess.STDOUT)).rstrip()
match = re.search(r'^(?P<base_vm_name>[a-zA-Z() ]+64-Bit )Server VM', out.split('\n')[-1])
vm_name = match.group('base_vm_name') if match else ''
vm_name += '{} {}'.format(graalvm_dist.base_name, graalvm_dist.vm_config_name.upper()) if graalvm_dist.vm_config_name else graalvm_dist.base_name
vm_name += ' {}'.format(graalvm_version())
return vm_name
return vm_name + graalvm_vendor_version(graalvm_dist)

def graalvm_vendor_version(graalvm_dist):
"""
:type jdk_home: str
:rtype str:
"""
vendor_version = '{} {}'.format(graalvm_dist.base_name, graalvm_dist.vm_config_name.upper()) if graalvm_dist.vm_config_name else graalvm_dist.base_name
vendor_version += ' {}'.format(graalvm_version())
return vendor_version

mx.add_argument('--components', action='store', help='Comma-separated list of component names to build. Only those components and their dependencies are built.')
mx.add_argument('--exclude-components', action='store', help='Comma-separated list of component names to be excluded from the build.')
Expand Down

0 comments on commit fd91dd2

Please sign in to comment.