Skip to content

Commit 45e9b6e

Browse files
author
Andrija Kolic
committed
Add 'graalhost-graalos' and 'pie' VM config modifiers; move 'graalos' and 'layered' VM config registration to EE; change deployment for 'graalhost-graalos' VM config; apply run args last.
1 parent eca7e0b commit 45e9b6e

File tree

3 files changed

+73
-53
lines changed

3 files changed

+73
-53
lines changed

sdk/mx.sdk/mx_sdk_benchmark.py

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
381381

382382
if vm.is_quickbuild:
383383
base_image_build_args += ['-Ob']
384-
if vm.graalos:
384+
if vm.graalos or vm.graalhost_graalos:
385385
base_image_build_args += ['-H:+GraalOS']
386386
if vm.use_string_inlining:
387387
base_image_build_args += ['-H:+UseStringInlining']
@@ -717,8 +717,10 @@ def __init__(self, name, config_name, extra_java_args=None, extra_launcher_args=
717717
self.pgo_sampler_only = False
718718
self.is_gate = False
719719
self.is_quickbuild = False
720-
self.layered = False
721720
self.graalos = False
721+
self.graalhost_graalos = False
722+
self.pie = False
723+
self.layered = False
722724
self.use_string_inlining = False
723725
self.is_llvm = False
724726
self.gc = None
@@ -774,6 +776,14 @@ def config_name(self):
774776
config += ["preserve-all"]
775777
if self.preserve_classpath is True:
776778
config += ["preserve-classpath"]
779+
if self.graalos is True:
780+
config += ["graalos"]
781+
if self.graalhost_graalos is True:
782+
config += ["graalhost-graalos"]
783+
if self.pie is True:
784+
config += ["pie"]
785+
if self.layered is True:
786+
config += ["layered"]
777787
if self.future_defaults_all is True:
778788
config += ["future-defaults-all"]
779789
if self.is_gate is True:
@@ -782,10 +792,6 @@ def config_name(self):
782792
config += ["upx"]
783793
if self.is_quickbuild is True:
784794
config += ["quickbuild"]
785-
if self.layered is True:
786-
config += ["layered"]
787-
if self.graalos is True:
788-
config += ["graalos"]
789795
if self.gc == "G1":
790796
config += ["g1gc"]
791797
if self.is_llvm is True:
@@ -847,7 +853,8 @@ def _configure_from_name(self, config_name):
847853
# This defines the allowed config names for NativeImageVM. The ones registered will be available via --jvm-config
848854
# Note: the order of entries here must match the order of statements in NativeImageVM.config_name()
849855
rule = r'^(?P<native_architecture>native-architecture-)?(?P<string_inlining>string-inlining-)?(?P<otw>otw-)?(?P<compacting_gc>compacting-gc-)?(?P<preserve_all>preserve-all-)?(?P<preserve_classpath>preserve-classpath-)?' \
850-
r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<layered>layered-)?(?P<graalos>graalos-)?(?P<gc>g1gc-)?' \
856+
r'(?P<graalos>graalos-)?(?P<graalhost_graalos>graalhost-graalos-)?(?P<pie>pie-)?(?P<layered>layered-)?' \
857+
r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?' \
851858
r'(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-sampler-)?(?P<inliner>inline-)?' \
852859
r'(?P<analysis_context_sensitivity>insens-|allocsens-|1obj-|2obj1h-|3obj2h-|4obj3h-)?(?P<jdk_profiles>jdk-profiles-collect-|adopted-jdk-pgo-)?' \
853860
r'(?P<profile_inference>profile-inference-feature-extraction-|profile-inference-call-count-|profile-inference-pgo-|profile-inference-debug-)?(?P<sampler>safepoint-sampler-|async-sampler-)?(?P<optimization_level>O0-|O1-|O2-|O3-|Os-)?(default-)?(?P<edition>ce-|ee-)?$'
@@ -870,6 +877,22 @@ def _configure_from_name(self, config_name):
870877
mx.logv(f"'preserve-classpath' is enabled for {config_name}")
871878
self.preserve_classpath = True
872879

880+
if matching.group("graalos") is not None:
881+
mx.logv(f"'graalos' is enabled for {config_name}")
882+
self.graalos = True
883+
884+
if matching.group("graalhost_graalos") is not None:
885+
mx.logv(f"'graalhost-graalos' is enabled for {config_name}")
886+
self.graalhost_graalos = True
887+
888+
if matching.group("pie") is not None:
889+
mx.logv(f"'pie' is enabled for {config_name}")
890+
self.pie = True
891+
892+
if matching.group("layered") is not None:
893+
mx.logv(f"'layered' is enabled for {config_name}")
894+
self.layered = True
895+
873896
if matching.group("future_defaults_all") is not None:
874897
mx.logv(f"'future-defaults-all' is enabled for {config_name}")
875898
self.future_defaults_all = True
@@ -898,14 +921,6 @@ def _configure_from_name(self, config_name):
898921
mx.logv(f"'quickbuild' is enabled for {config_name}")
899922
self.is_quickbuild = True
900923

901-
if matching.group("layered") is not None:
902-
mx.logv(f"'layered' is enabled for {config_name}")
903-
self.layered = True
904-
905-
if matching.group("graalos") is not None:
906-
mx.logv(f"'graalos' is enabled for {config_name}")
907-
self.graalos = True
908-
909924
if matching.group("gc") is not None:
910925
gc = matching.group("gc")[:-1]
911926
if gc == "g1gc":
@@ -1503,42 +1518,45 @@ def run_stage_instrument_run(self):
15031518
print(
15041519
f"Profile file {self.config.profile_path} not dumped. Instrument run failed with exit code {exit_code}")
15051520

1506-
def get_layered_build_args(self) -> List[str]:
1507-
"""Return extra options that are necessary when building a layered image."""
1521+
def get_layer_aware_build_args(self) -> List[str]:
1522+
"""Return extra build options that are dependent on layer information."""
15081523
current_stage = self.stages_info.current_stage
1509-
if not self.layered or current_stage.layer_info.is_shared_library:
1510-
# No extra options are necessary if we are not building a layered image
1511-
# No extra options are necessary when building shared layers
1512-
return []
1513-
1514-
# Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1515-
shared_library_stages = [stage for stage in self.stages_info.complete_stage_list
1516-
if current_stage.stage_name == stage.stage_name and stage.is_layered() and stage.layer_info.is_shared_library]
1517-
if len(shared_library_stages) == 0:
1518-
mx.abort("Failed to find any shared library layer image stages!")
1519-
layer_output_dirs = []
1520-
for stage in shared_library_stages:
1521-
_, stage_output_dir = self.config.get_executable_name_and_output_dir_for_stage(stage, self)
1522-
layer_output_dirs.append(stage_output_dir.absolute().as_posix())
1523-
linker_r_path = ",".join(layer_output_dirs)
1524-
layer_build_args = [f"-H:LinkerRPath={linker_r_path}"]
1525-
1526-
# Set LayerUse to point to the .nil archive of the preceeding layer
1527-
last_shared_library_stage_output_dir = Path(layer_output_dirs[-1])
1528-
nil_archives = list(last_shared_library_stage_output_dir.glob("*.nil"))
1529-
if len(nil_archives) == 0:
1530-
mx.abort(
1531-
f"Could not determine the .nil archive of the preceding shared library layer!"
1532-
f" No .nil archives located in '{last_shared_library_stage_output_dir}' directory!"
1533-
)
1534-
if len(nil_archives) > 1:
1535-
mx.abort(
1536-
f"Could not determine the .nil archive of the preceding shared library layer!"
1537-
f" Multiple files found: {nil_archives}"
1538-
)
1539-
layer_build_args.append(f"-H:LayerUse={nil_archives[0]}")
1524+
layer_aware_build_args = []
1525+
1526+
if self.pie and (not self.layered or not current_stage.layer_info.is_shared_library):
1527+
# This option should not be applied to base layers
1528+
layer_aware_build_args += ["-H:NativeLinkerOption=-pie"]
1529+
1530+
if self.layered and not current_stage.layer_info.is_shared_library:
1531+
# Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1532+
shared_library_stages = [stage for stage in self.stages_info.complete_stage_list
1533+
if current_stage.stage_name == stage.stage_name and stage.is_layered() and stage.layer_info.is_shared_library]
1534+
if len(shared_library_stages) == 0:
1535+
mx.abort("Failed to find any shared library layer image stages!")
1536+
layer_output_dirs = []
1537+
for stage in shared_library_stages:
1538+
_, stage_output_dir = self.config.get_executable_name_and_output_dir_for_stage(stage, self)
1539+
layer_output_dirs.append(stage_output_dir.absolute().as_posix())
1540+
linker_r_path = ",".join(layer_output_dirs)
1541+
app_layer_build_args = [f"-H:LinkerRPath={linker_r_path}"]
1542+
1543+
# Set LayerUse to point to the .nil archive of the preceeding layer
1544+
last_shared_library_stage_output_dir = Path(layer_output_dirs[-1])
1545+
nil_archives = list(last_shared_library_stage_output_dir.glob("*.nil"))
1546+
if len(nil_archives) == 0:
1547+
mx.abort(
1548+
f"Could not determine the .nil archive of the preceding shared library layer!"
1549+
f" No .nil archives located in '{last_shared_library_stage_output_dir}' directory!"
1550+
)
1551+
if len(nil_archives) > 1:
1552+
mx.abort(
1553+
f"Could not determine the .nil archive of the preceding shared library layer!"
1554+
f" Multiple files found: {nil_archives}"
1555+
)
1556+
app_layer_build_args.append(f"-H:LayerUse={nil_archives[0]}")
1557+
layer_aware_build_args += app_layer_build_args
15401558

1541-
return layer_build_args
1559+
return layer_aware_build_args
15421560

15431561
def run_stage_image(self):
15441562
executable_name_args = ['-o', self.config.final_image_name]
@@ -1578,7 +1596,7 @@ def run_stage_image(self):
15781596
[f"-H:BuildOutputJSONFile={self.config.get_build_output_json_file(StageName.IMAGE)}"])
15791597
final_image_command = (self.config.base_image_build_args + executable_name_args
15801598
+ (pgo_args if self.pgo_instrumentation else []) + jdk_profiles_args + ml_args + ml_debug_args
1581-
+ collection_args + self.get_layered_build_args())
1599+
+ collection_args + self.get_layer_aware_build_args())
15821600
with self.get_stage_runner() as s:
15831601
exit_code = s.execute_command(self, final_image_command)
15841602
NativeImageVM.move_bundle_output(self.config, self.config.image_path)

substratevm/mx.substratevm/mx_substratevm_benchmark.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,11 @@ def produceHarnessCommand(self, cmd: List[str], suite: BenchmarkSuite) -> List[s
989989
timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
990990
gos_log_file_name = f"{timestamp}-gos-out.log"
991991
gos_cmd += ["--log-to", f"stdout,file:{gos_log_file_name}"]
992-
gos_cmd += suite.runArgs(bmSuiteArgs)
992+
if suite.execution_context.virtual_machine.graalhost_graalos:
993+
gos_cmd += ["-p", f"deployment=\"nginx-tinyinit-graalhost\""]
993994
app_cmd_str = " ".join(app_cmd)
994995
gos_cmd += ["-p", f"command=\"{app_cmd_str}\""]
996+
gos_cmd += suite.runArgs(bmSuiteArgs)
995997
mx.log(f"Produced 'gos-scenario' command: '{' '.join(gos_cmd)}'")
996998
return gos_cmd
997999

vm/mx.vm/mx_vm_benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def register_graalvm_vms():
533533
for short_name, config_suffix in [('niee', 'ee'), ('ni', 'ce')]:
534534
if any(component.short_name == short_name for component in mx_sdk_vm_impl.registered_graalvm_components(stage1=False)):
535535
config_names = list()
536-
for main_config in ['default', 'gate', 'llvm', 'native-architecture', 'future-defaults-all', 'preserve-all', 'preserve-classpath', 'layered', 'graalos'] + analysis_context_sensitivity:
536+
for main_config in ['default', 'gate', 'llvm', 'native-architecture', 'future-defaults-all', 'preserve-all', 'preserve-classpath'] + analysis_context_sensitivity:
537537
config_names.append(f'{main_config}-{config_suffix}')
538538

539539
for optimization_level in optimization_levels:
@@ -545,7 +545,7 @@ def register_graalvm_vms():
545545
mx_benchmark.add_java_vm(NativeImageVM('native-image', config_name, ['--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED']), _suite, 10)
546546

547547
# Adding JAVA_HOME VMs to be able to run benchmarks on GraalVM binaries without the need of building it first
548-
for java_home_config in ['default', 'pgo', 'g1gc', 'g1gc-pgo', 'upx', 'upx-g1gc', 'quickbuild', 'quickbuild-g1gc', 'layered', 'graalos']:
548+
for java_home_config in ['default', 'pgo', 'g1gc', 'g1gc-pgo', 'upx', 'upx-g1gc', 'quickbuild', 'quickbuild-g1gc']:
549549
mx_benchmark.add_java_vm(NativeImageVM('native-image-java-home', java_home_config), _suite, 5)
550550

551551

0 commit comments

Comments
 (0)