@@ -388,7 +388,7 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
388
388
389
389
if vm .is_quickbuild :
390
390
base_image_build_args += ['-Ob' ]
391
- if vm .graalos :
391
+ if vm .graalos or vm . graalhost_graalos :
392
392
base_image_build_args += ['-H:+GraalOS' ]
393
393
if vm .use_string_inlining :
394
394
base_image_build_args += ['-H:+UseStringInlining' ]
@@ -728,8 +728,10 @@ def __init__(self, name, config_name, extra_java_args=None, extra_launcher_args=
728
728
self .pgo_perf_invoke_profile_collection_strategy : Optional [PerfInvokeProfileCollectionStrategy ] = None
729
729
self .is_gate = False
730
730
self .is_quickbuild = False
731
- self .layered = False
732
731
self .graalos = False
732
+ self .graalhost_graalos = False
733
+ self .pie = False
734
+ self .layered = False
733
735
self .use_string_inlining = False
734
736
self .is_llvm = False
735
737
self .gc = None
@@ -785,6 +787,14 @@ def config_name(self):
785
787
config += ["preserve-all" ]
786
788
if self .preserve_classpath is True :
787
789
config += ["preserve-classpath" ]
790
+ if self .graalos is True :
791
+ config += ["graalos" ]
792
+ if self .graalhost_graalos is True :
793
+ config += ["graalhost-graalos" ]
794
+ if self .pie is True :
795
+ config += ["pie" ]
796
+ if self .layered is True :
797
+ config += ["layered" ]
788
798
if self .future_defaults_all is True :
789
799
config += ["future-defaults-all" ]
790
800
if self .is_gate is True :
@@ -793,10 +803,6 @@ def config_name(self):
793
803
config += ["upx" ]
794
804
if self .is_quickbuild is True :
795
805
config += ["quickbuild" ]
796
- if self .layered is True :
797
- config += ["layered" ]
798
- if self .graalos is True :
799
- config += ["graalos" ]
800
806
if self .gc == "G1" :
801
807
config += ["g1gc" ]
802
808
if self .is_llvm is True :
@@ -862,7 +868,8 @@ def _configure_from_name(self, config_name):
862
868
# This defines the allowed config names for NativeImageVM. The ones registered will be available via --jvm-config
863
869
# Note: the order of entries here must match the order of statements in NativeImageVM.config_name()
864
870
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-)?' \
865
- 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-)?' \
871
+ r'(?P<graalos>graalos-)?(?P<graalhost_graalos>graalhost-graalos-)?(?P<pie>pie-)?(?P<layered>layered-)?' \
872
+ r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?' \
866
873
r'(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-sampler-|pgo-perf-sampler-invoke-multiple-|pgo-perf-sampler-invoke-|pgo-perf-sampler-)?(?P<inliner>inline-)?' \
867
874
r'(?P<analysis_context_sensitivity>insens-|allocsens-|1obj-|2obj1h-|3obj2h-|4obj3h-)?(?P<jdk_profiles>jdk-profiles-collect-|adopted-jdk-pgo-)?' \
868
875
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-)?$'
@@ -885,6 +892,22 @@ def _configure_from_name(self, config_name):
885
892
mx .logv (f"'preserve-classpath' is enabled for { config_name } " )
886
893
self .preserve_classpath = True
887
894
895
+ if matching .group ("graalos" ) is not None :
896
+ mx .logv (f"'graalos' is enabled for { config_name } " )
897
+ self .graalos = True
898
+
899
+ if matching .group ("graalhost_graalos" ) is not None :
900
+ mx .logv (f"'graalhost-graalos' is enabled for { config_name } " )
901
+ self .graalhost_graalos = True
902
+
903
+ if matching .group ("pie" ) is not None :
904
+ mx .logv (f"'pie' is enabled for { config_name } " )
905
+ self .pie = True
906
+
907
+ if matching .group ("layered" ) is not None :
908
+ mx .logv (f"'layered' is enabled for { config_name } " )
909
+ self .layered = True
910
+
888
911
if matching .group ("future_defaults_all" ) is not None :
889
912
mx .logv (f"'future-defaults-all' is enabled for { config_name } " )
890
913
self .future_defaults_all = True
@@ -913,14 +936,6 @@ def _configure_from_name(self, config_name):
913
936
mx .logv (f"'quickbuild' is enabled for { config_name } " )
914
937
self .is_quickbuild = True
915
938
916
- if matching .group ("layered" ) is not None :
917
- mx .logv (f"'layered' is enabled for { config_name } " )
918
- self .layered = True
919
-
920
- if matching .group ("graalos" ) is not None :
921
- mx .logv (f"'graalos' is enabled for { config_name } " )
922
- self .graalos = True
923
-
924
939
if matching .group ("gc" ) is not None :
925
940
gc = matching .group ("gc" )[:- 1 ]
926
941
if gc == "g1gc" :
@@ -1571,42 +1586,45 @@ def run_stage_instrument_run(self):
1571
1586
print (
1572
1587
f"Profile file { self .config .profile_path } not dumped. Instrument run failed with exit code { exit_code } " )
1573
1588
1574
- def get_layered_build_args (self ) -> List [str ]:
1575
- """Return extra options that are necessary when building a layered image ."""
1589
+ def get_layer_aware_build_args (self ) -> List [str ]:
1590
+ """Return extra build options that are dependent on layer information ."""
1576
1591
current_stage = self .stages_info .current_stage
1577
- if not self .layered or current_stage .layer_info .is_shared_library :
1578
- # No extra options are necessary if we are not building a layered image
1579
- # No extra options are necessary when building shared layers
1580
- return []
1581
-
1582
- # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1583
- shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1584
- if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1585
- if len (shared_library_stages ) == 0 :
1586
- mx .abort ("Failed to find any shared library layer image stages!" )
1587
- layer_output_dirs = []
1588
- for stage in shared_library_stages :
1589
- _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1590
- layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1591
- linker_r_path = "," .join (layer_output_dirs )
1592
- layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1593
-
1594
- # Set LayerUse to point to the .nil archive of the preceeding layer
1595
- last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1596
- nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1597
- if len (nil_archives ) == 0 :
1598
- mx .abort (
1599
- f"Could not determine the .nil archive of the preceding shared library layer!"
1600
- f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1601
- )
1602
- if len (nil_archives ) > 1 :
1603
- mx .abort (
1604
- f"Could not determine the .nil archive of the preceding shared library layer!"
1605
- f" Multiple files found: { nil_archives } "
1606
- )
1607
- layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1592
+ layer_aware_build_args = []
1593
+
1594
+ if self .pie and (not self .layered or not current_stage .layer_info .is_shared_library ):
1595
+ # This option should not be applied to base layers
1596
+ layer_aware_build_args += ["-H:NativeLinkerOption=-pie" ]
1597
+
1598
+ if self .layered and not current_stage .layer_info .is_shared_library :
1599
+ # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1600
+ shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1601
+ if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1602
+ if len (shared_library_stages ) == 0 :
1603
+ mx .abort ("Failed to find any shared library layer image stages!" )
1604
+ layer_output_dirs = []
1605
+ for stage in shared_library_stages :
1606
+ _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1607
+ layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1608
+ linker_r_path = "," .join (layer_output_dirs )
1609
+ app_layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1610
+
1611
+ # Set LayerUse to point to the .nil archive of the preceeding layer
1612
+ last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1613
+ nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1614
+ if len (nil_archives ) == 0 :
1615
+ mx .abort (
1616
+ f"Could not determine the .nil archive of the preceding shared library layer!"
1617
+ f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1618
+ )
1619
+ if len (nil_archives ) > 1 :
1620
+ mx .abort (
1621
+ f"Could not determine the .nil archive of the preceding shared library layer!"
1622
+ f" Multiple files found: { nil_archives } "
1623
+ )
1624
+ app_layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1625
+ layer_aware_build_args += app_layer_build_args
1608
1626
1609
- return layer_build_args
1627
+ return layer_aware_build_args
1610
1628
1611
1629
def run_stage_image (self ):
1612
1630
executable_name_args = ['-o' , self .config .final_image_name ]
@@ -1653,7 +1671,7 @@ def run_stage_image(self):
1653
1671
[f"-H:BuildOutputJSONFile={ self .config .get_build_output_json_file (StageName .IMAGE )} " ])
1654
1672
final_image_command = (self .config .base_image_build_args + executable_name_args
1655
1673
+ (pgo_args if self .pgo_instrumentation else []) + jdk_profiles_args + ml_args + ml_debug_args
1656
- + collection_args + self .get_layered_build_args ())
1674
+ + collection_args + self .get_layer_aware_build_args ())
1657
1675
with self .get_stage_runner () as s :
1658
1676
exit_code = s .execute_command (self , final_image_command )
1659
1677
NativeImageVM .move_bundle_output (self .config , self .config .image_path )
0 commit comments