def run_stage_instrument_image(self, config, stages, out, i, instrumentation_image_name, image_path, image_path_latest, instrumented_iterations): executable_name_args = ['-H:Name=' + instrumentation_image_name] pgo_verification_output_path = os.path.join( config.output_dir, instrumentation_image_name + '-probabilities.log') pgo_args = [ '--pgo=' + config.latest_profile_path, '-H:+VerifyPGOProfiles', '-H:VerificationDumpFile=' + pgo_verification_output_path ] pgo_args += [ '-H:' + ('+' if self.pgo_context_sensitive else '-') + 'EnablePGOContextSensitivity' ] pgo_args += ['-H:+AOTInliner' ] if self.pgo_aot_inline else ['-H:-AOTInliner'] instrument_args = ['--pgo-instrument'] + ([] if i == 0 else pgo_args) instrument_args += ['-H:+InlineAllExplored' ] if self.pgo_inline_explored else [] with stages.set_command(config.base_image_build_args + executable_name_args + instrument_args) as s: s.execute_command() if s.exit_code == 0: mx.copyfile(image_path, image_path_latest) if i + 1 == instrumented_iterations and s.exit_code == 0: image_size = os.stat(image_path).st_size out('Instrumented image size: ' + str(image_size) + ' B')
def run_stage_agent(self, config, stages): profile_path = config.profile_path_no_extension + '-agent' + config.profile_file_extension hotspot_vm_args = [ '-ea', '-esa' ] if self.is_gate and not config.skip_agent_assertions else [] hotspot_run_args = [] hotspot_vm_args += [ '-agentlib:native-image-agent=config-output-dir=' + str(config.config_dir), '-XX:-UseJVMCINativeLibrary' ] if self.hotspot_pgo: hotspot_vm_args += ['-Dgraal.PGOInstrument=' + profile_path] if self.hotspot_pgo and not self.is_gate and config.extra_agent_profile_run_args: hotspot_run_args += config.extra_agent_profile_run_args elif config.extra_agent_run_args: hotspot_run_args += config.extra_agent_run_args else: hotspot_run_args += config.image_run_args hotspot_args = hotspot_vm_args + config.classpath_arguments + config.executable + config.system_properties + hotspot_run_args java_command = os.path.join( mx_sdk_vm_impl.graalvm_home(fatalIfMissing=True), 'bin', 'java') with stages.set_command([java_command] + hotspot_args) as s: s.execute_command() if self.hotspot_pgo and s.exit_code == 0: mx.copyfile(profile_path, config.latest_profile_path)
def run_stage_instrument_run(self, config, stages, image_path, profile_path): image_run_cmd = [image_path, '-XX:ProfilesDumpFile=' + profile_path] if config.extra_profile_run_args: image_run_cmd += config.extra_profile_run_args else: image_run_cmd += config.image_run_args + config.extra_run_args with stages.set_command(image_run_cmd) as s: s.execute_command() if s.exit_code == 0: mx.copyfile(profile_path, config.latest_profile_path)
def build(self): super(GraalVmWatBuildTask, self).build() output_dir = self.subject.getOutputDir() for root, filename in self.subject.getProgramSources(): src = join( output_dir, mx_wasm.remove_extension(filename) + ".wasm") dst = join( root, mx_wasm.remove_extension(filename) + ".wasm") if mx.is_windows(): mx.copyfile(src, dst) else: os.symlink(src, dst)
def run_java(self, args, out=None, err=None, cwd=None, nonZeroIsFatal=False): if '-version' in args: return super(NativeImageVM, self).run_java(args, out=out, err=err, cwd=cwd, nonZeroIsFatal=nonZeroIsFatal) else: # never fatal, we handle it ourselves config = NativeImageVM.BenchmarkConfig() original_java_run_args = config.parse(args) executable, classpath_arguments, system_properties, image_run_args = NativeImageVM.extract_benchmark_arguments( original_java_run_args) executable_suffix = ( '-' + config.benchmark_name) if config.benchmark_name else '' executable_name = ( os.path.splitext(os.path.basename(executable[1]))[0] + executable_suffix if executable[0] == '-jar' else executable[0] + executable_suffix).lower() final_image_name = executable_name + '-' + self.config_name() stages = NativeImageVM.Stages( config, out, err, final_image_name, self.is_gate, True if self.is_gate else nonZeroIsFatal, os.path.abspath(cwd if cwd else os.getcwd())) bench_suite = mx.suite('vm') root_dir = config.benchmark_output_dir if config.benchmark_output_dir else mx.join( bench_suite.dir, 'mxbuild') config.output_dir = mx.join( os.path.abspath(root_dir), 'native-image-bench-' + executable_name + '-' + self.config_name()) if not os.path.exists(config.output_dir): os.makedirs(config.output_dir) config.profile_dir = config.output_dir profile_path_no_extension = os.path.join(config.profile_dir, executable_name) profile_file_extension = '.iprof' latest_profile_path = profile_path_no_extension + '-latest' + profile_file_extension config.config_dir = os.path.join(config.output_dir, 'config') if not os.path.exists(config.config_dir): os.makedirs(config.config_dir) config.log_dir = config.output_dir if stages.change_stage('agent'): profile_path = profile_path_no_extension + '-agent' + profile_file_extension hotspot_vm_args = [ '-ea', '-esa' ] if self.is_gate and not config.skip_agent_assertions else [] hotspot_run_args = [] hotspot_vm_args += [ '-agentlib:native-image-agent=config-output-dir=' + str(config.config_dir), '-XX:-UseJVMCINativeLibrary' ] if self.hotspot_pgo: hotspot_vm_args += [ '-Dgraal.PGOInstrument=' + profile_path ] if self.hotspot_pgo and not self.is_gate and config.extra_agent_profile_run_args: hotspot_run_args += config.extra_agent_profile_run_args elif config.extra_agent_run_args: hotspot_run_args += config.extra_agent_run_args else: hotspot_run_args += image_run_args hotspot_args = hotspot_vm_args + classpath_arguments + executable + system_properties + hotspot_run_args java_command = os.path.join( mx_sdk_vm_impl.graalvm_home(fatalIfMissing=True), 'bin', 'java') with stages.set_command([java_command] + hotspot_args) as s: s.execute_command() if self.hotspot_pgo and s.exit_code == 0: mx.copyfile(profile_path, latest_profile_path) base_image_build_args = [ os.path.join(mx_sdk_vm_impl.graalvm_home(fatalIfMissing=True), 'bin', 'native-image') ] base_image_build_args += [ '--no-fallback', '--no-server', '-g', '--allow-incomplete-classpath' ] base_image_build_args += [ '-J-ea', '-J-esa', '-H:+VerifyGraalGraphs', '-H:+VerifyPhases', '-H:+TraceClassInitialization' ] if self.is_gate else [] base_image_build_args += system_properties base_image_build_args += classpath_arguments base_image_build_args += executable base_image_build_args += ['-H:Path=' + config.output_dir] base_image_build_args += [ '-H:ConfigurationFileDirectories=' + config.config_dir ] if self.is_llvm: base_image_build_args += [ '-H:CompilerBackend=llvm', '-H:Features=org.graalvm.home.HomeFinderFeature', '-H:DeadlockWatchdogInterval=0' ] base_image_build_args += config.extra_image_build_arguments if not self.hotspot_pgo: # Native Image profile collection i = 0 instrumented_iterations = self.pgo_instrumented_iterations if config.pgo_iteration_num is None else int( config.pgo_iteration_num) while i < instrumented_iterations: profile_path = profile_path_no_extension + '-' + str( i) + profile_file_extension instrumentation_image_name = executable_name + '-instrument-' + str( i) instrumentation_image_latest = executable_name + '-instrument-latest' image_path = os.path.join(config.output_dir, instrumentation_image_name) image_path_latest = os.path.join( config.output_dir, instrumentation_image_latest) if stages.change_stage('instrument-image', str(i)): executable_name_args = [ '-H:Name=' + instrumentation_image_name ] pgo_verification_output_path = os.path.join( config.output_dir, instrumentation_image_name + '-probabilities.log') pgo_args = [ '--pgo=' + latest_profile_path, '-H:+VerifyPGOProfiles', '-H:VerificationDumpFile=' + pgo_verification_output_path ] instrument_args = ['--pgo-instrument' ] + ([] if i == 0 else pgo_args) instrument_args += [ '-H:+InlineAllExplored' ] if self.pgo_inline_explored else [] instrument_args += [ '-H:' + ('+' if self.pgo_context_sensitive else '-') + 'EnablePGOContextSensitivity' ] with stages.set_command(base_image_build_args + executable_name_args + instrument_args) as s: s.execute_command() if s.exit_code == 0: mx.copyfile(image_path, image_path_latest) if i + 1 == instrumented_iterations and s.exit_code == 0: image_size = os.stat(image_path).st_size out('Instrumented image size: ' + str(image_size) + ' B') if stages.change_stage('instrument-run', str(i)): image_run_cmd = [image_path] image_run_cmd += [ '-XX:ProfilesDumpFile=' + profile_path ] if config.extra_profile_run_args: image_run_cmd += config.extra_profile_run_args else: image_run_cmd += image_run_args + config.extra_run_args with stages.set_command(image_run_cmd) as s: s.execute_command() if s.exit_code == 0: mx.copyfile(profile_path, latest_profile_path) i += 1 image_path = mx.join(config.output_dir, final_image_name) # Build the final image if stages.change_stage('image'): executable_name_args = ['-H:Name=' + final_image_name] pgo_verification_output_path = os.path.join( config.output_dir, final_image_name + '-probabilities.log') pgo_args = ['--pgo=' + latest_profile_path, '-H:+VerifyPGOProfiles', '-H:VerificationDumpFile=' + pgo_verification_output_path] if self.pgo_instrumented_iterations > 0 or self.hotspot_pgo else [] final_image_command = base_image_build_args + executable_name_args + pgo_args with stages.set_command(final_image_command) as s: s.execute_command() if s.exit_code == 0: image_size = os.stat(image_path).st_size out('Final image size: ' + str(image_size) + ' B') # Execute the benchmark if stages.change_stage('run'): image_path = os.path.join(config.output_dir, final_image_name) image_run_cmd = [image_path ] + image_run_args + config.extra_run_args with stages.set_command(image_run_cmd) as s: s.execute_command(True)