Example #1
0
def check_aot(classpath,
              main_class,
              common_opts,
              expected_output,
              lib_module,
              program_args=None):
    aot_opts = [
        '-XX:+UnlockDiagnosticVMOptions', '-XX:+UseAOTStrictLoading',
        '-XX:AOTLibrary=' + lib_module.name
    ]

    program_args = program_args or []

    # Check AOT library is loaded.
    out = mx.OutputCapture()
    mx_compiler.run_vm(common_opts + aot_opts + ['-XX:+PrintAOT', '-version'],
                       out=out,
                       err=out,
                       nonZeroIsFatal=False)
    if 'aot library' not in out.data:
        mx.abort(
            "Missing expected 'aot library' in -XX:+PrintAOT -version output. VM Output:\n"
            + str(out.data))

    # Run main_class+AOT modules and check output.
    aot_out = mx.OutputCapture()
    mx_compiler.run_vm(common_opts + aot_opts +
                       ['-cp', classpath, main_class] + program_args,
                       out=aot_out)

    if expected_output != aot_out.data:
        mx.abort('Outputs differ, expected `{}` != `{}`'.format(
            expected_output, aot_out.data))
Example #2
0
def test_modules(opts_set, classpath, main_class, modules, vm_args, program_args, commands):
    """(jaotc-)Compiles `modules` and runs `main_class` + AOT library.
    Compares the output vs. standard JVM.
    """
    # Run on vanilla JVM.
    program_args = program_args or []
    vm_args = vm_args or []
    commands = commands or ''
    expected_out = mx.OutputCapture()

    mx_compiler.run_vm((['-cp', classpath] if classpath else []) +
                       vm_args +
                       [main_class] + program_args, out=expected_out)

    # jaotc uses ':' as separator.
    module_list = ':'.join(modules)

    for common_opts in opts_set:
        mx.log('(jaotc) Compiling module(s) {} with {}'.format(module_list, ' '.join(common_opts)))
        with mktemp_libfile() as lib_module:
            lib_module.file.close()
            with tempfile.NamedTemporaryFile(mode='w', prefix='cmds_', suffix='.txt') as cmd_file:
                cmd_file.write(commands)
                cmd_file.file.close()
                run_jaotc(['-J' + opt for opt in common_opts] +
                          ['--module', module_list] +
                          ['--compile-commands', cmd_file.name] +
                          ['--exit-on-error', '--info', '--output', lib_module.name])

            check_aot(classpath, main_class, common_opts, expected_out.data, lib_module, program_args)
Example #3
0
def test_modules(classpath, main_class, modules, program_args=None):
    """(jaotc-)Compiles `modules` and runs `main_class` + AOT library.
    Compares the output vs. standard JVM.
    """
    # Run on vanilla JVM.
    program_args = program_args or []
    expected_out = mx.OutputCapture()

    mx_compiler.run_vm((['-cp', classpath] if classpath else []) +
                       [main_class] + program_args,
                       out=expected_out)

    # jaotc uses ':' as separator.
    module_list = ':'.join(modules)

    for common_opts in common_opts_variants:
        mx.log('(jaotc) Compiling module(s) {} with {}'.format(
            module_list, ' '.join(common_opts)))
        with mktemp_libfile() as lib_module:
            run_jaotc(
                ['-J' + opt
                 for opt in common_opts] + ['--module', module_list] +
                ['--exit-on-error', '--info', '--output', lib_module.name])

            check_aot(classpath, main_class, common_opts, expected_out.data,
                      lib_module, program_args)
Example #4
0
def _test_libgraal_basic(extra_vm_arguments):
    """
    Tests basic libgraal execution by running a DaCapo benchmark, ensuring it has a 0 exit code
    and that the output for -DgraalShowConfiguration=info describes a libgraal execution.
    """
    expect = r"Using compiler configuration '[^']+' provided by [\.\w]+ loaded from[ \w]* JVMCI native library"
    compiler_log_file = abspath('graal-compiler.log')
    args = [
        '-Dgraal.ShowConfiguration=info',
        '-Dgraal.LogFile=' + compiler_log_file, '-jar',
        mx.library('DACAPO').get_path(True), 'avrora', '-n', '1'
    ]

    # Verify execution via raw java launcher in `mx graalvm-home`.
    try:
        mx.run([join(mx_sdk_vm_impl.graalvm_home(), 'bin', 'java')] + args)
    finally:
        _check_compiler_log(compiler_log_file, expect)

    # Verify execution via `mx vm`.
    import mx_compiler
    try:
        mx_compiler.run_vm(extra_vm_arguments + args)
    finally:
        _check_compiler_log(compiler_log_file, expect)
Example #5
0
def test_javac(project_name, opts_set):
    """(jaotc-)Compiles the `jdk.compiler` module and compiles (mx) project_name using `javac` (+ AOT module)."""
    # jaotc uses ':' as separator.
    modules = ':'.join(['jdk.compiler'])
    for common_opts in opts_set:
        out_dir = tempfile.mkdtemp()
        try:
            mx.log('(jaotc) Compiling module(s) {} with {}'.format(
                modules, ' '.join(common_opts)))
            with mktemp_libfile() as lib_module:
                lib_module.file.close()
                run_jaotc(['-J' + opt for opt in common_opts] + [
                    '--exit-on-error', '--info', '--module', modules,
                    '--output', lib_module.name
                ])

                aot_opts = [
                    '-XX:+UnlockDiagnosticVMOptions',
                    '-XX:+UseAOTStrictLoading',
                    '-XX:AOTLibrary=' + lib_module.name
                ]

                project = mx.project(project_name)
                java_files = collect_java_sources(project.source_dirs())
                javac_args = mx.JavacCompiler(jdk).prepare(
                    sourceFiles=java_files,
                    project=project,
                    outputDir=out_dir,
                    classPath=mx.classpath(project,
                                           includeSelf=False,
                                           jdk=jdk,
                                           ignoreStripped=True),
                    sourceGenDir=project.source_gen_dir(),
                    jnigenDir=project.jni_gen_dir(),
                    processorPath=project.annotation_processors_path(jdk),
                    disableApiRestrictions=True,
                    warningsAsErrors=False,
                    showTasks=False,
                    postCompileActions=[],
                    forceDeprecationAsWarning=False)

                mx_compiler.run_vm(common_opts + aot_opts +
                                   ['com.sun.tools.javac.Main'] + javac_args)

        finally:
            shutil.rmtree(out_dir)
Example #6
0
def test_class(classpath, main_class, program_args=None):
    """(jaotc-)Compiles simple HelloWorld program.
    Compares the output vs. standard JVM.
    """
    # Run on vanilla JVM.
    program_args = program_args or []
    expected_out = mx.OutputCapture()
    mx_compiler.run_vm((['-cp', classpath] if classpath else []) +
                       [main_class] + program_args, out=expected_out)

    for common_opts in common_opts_variants:
        mx.log('Running {} with {}'.format(main_class, ' '.join(common_opts)))

        with mktemp_libfile() as lib_module:
            run_jaotc(['-J' + opt for opt in common_opts] +
                      ['--exit-on-error', '--info', '--output', lib_module.name, main_class],
                      classpath=classpath)
            check_aot(classpath, main_class, common_opts, expected_out.data, lib_module, program_args)
Example #7
0
def test_class(classpath, main_class, program_args=None):
    """(jaotc-)Compiles simple HelloWorld program.
    Compares the output vs. standard JVM.
    """
    # Run on vanilla JVM.
    program_args = program_args or []
    expected_out = mx.OutputCapture()
    mx_compiler.run_vm((['-cp', classpath] if classpath else []) +
                       [main_class] + program_args, out=expected_out)

    for common_opts in common_opts_variants:
        mx.log('Running {} with {}'.format(main_class, ' '.join(common_opts)))

        with mktemp_libfile() as lib_module:
            run_jaotc(['-J' + opt for opt in common_opts] +
                      ['--info', '--output', lib_module.name, main_class],
                      classpath=classpath)
            check_aot(classpath, main_class, common_opts, expected_out.data, lib_module, program_args)
Example #8
0
def check_aot(classpath, main_class, common_opts, expected_output, lib_module, program_args=None):
    aot_opts = [
        '-XX:+UnlockDiagnosticVMOptions',
        '-XX:+UseAOTStrictLoading',
        '-XX:AOTLibrary=' + lib_module.name
    ]

    program_args = program_args or []

    # Check AOT library is loaded.
    out = mx.OutputCapture()
    mx_compiler.run_vm(common_opts + aot_opts + ['-XX:+PrintAOT', '-version'], out=out, err=out, nonZeroIsFatal=False)
    if 'aot library' not in out.data:
        mx.abort("Missing expected 'aot library' in -XX:+PrintAOT -version output. VM Output:\n" + str(out.data))

    # Run main_class+AOT modules and check output.
    aot_out = mx.OutputCapture()
    mx_compiler.run_vm(common_opts + aot_opts + ['-cp', classpath, main_class] + program_args, out=aot_out)

    if expected_output != aot_out.data:
        mx.abort('Outputs differ, expected `{}` != `{}`'.format(expected_output, aot_out.data))
Example #9
0
def run_jaotc(args, classpath=None, cwd=None):
    """run AOT compiler with classes in this repo instead of those in the JDK"""
    if jdk.javaCompliance < '11':
        mx.abort(
            'jaotc command is only available if JAVA_HOME is JDK 11 or later')

    jaotc_entry = mx_compiler.JVMCIClasspathEntry('JAOTC')
    jvmci_classpath_adjusted = False
    if jaotc_entry not in mx_compiler._jvmci_classpath:
        mx_compiler.add_jvmci_classpath_entry(jaotc_entry)
        jvmci_classpath_adjusted = True

    vm_args = [a[2:] for a in args if a.startswith('-J')]
    args = [a for a in args if not a.startswith('-J')]

    verbose = ['--verbose'] if mx._opts.very_verbose else []
    cp = ['-cp', classpath] if classpath else []

    try:
        mx_compiler.run_vm([
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.sparc=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=jdk.internal.vm.compiler,jdk.aot',
            '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.sparc=jdk.internal.vm.compiler,jdk.aot',
            '-XX:+CalculateClassFingerprint'
        ] + vm_args + cp + ['-m', 'jdk.aot/jdk.tools.jaotc.Main'] + verbose +
                           args,
                           cwd=cwd)
    finally:
        if jvmci_classpath_adjusted:
            mx_compiler._jvmci_classpath.remove(jaotc_entry)
Example #10
0
def test_modules(classpath, main_class, modules, program_args=None):
    """(jaotc-)Compiles `modules` and runs `main_class` + AOT library.
    Compares the output vs. standard JVM.
    """
    # Run on vanilla JVM.
    program_args = program_args or []
    expected_out = mx.OutputCapture()

    mx_compiler.run_vm((['-cp', classpath] if classpath else []) +
                       [main_class] + program_args, out=expected_out)

    # jaotc uses ':' as separator.
    module_list = ':'.join(modules)

    for common_opts in common_opts_variants:
        mx.log('(jaotc) Compiling module(s) {} with {}'.format(module_list, ' '.join(common_opts)))
        with mktemp_libfile() as lib_module:
            run_jaotc(['-J' + opt for opt in common_opts] +
                      ['--module', module_list] +
                      ['--info', '--output', lib_module.name])

            check_aot(classpath, main_class, common_opts, expected_out.data, lib_module, program_args)
Example #11
0
def test_javac(project_name):
    """(jaotc-)Compiles the `jdk.compiler` module and compiles (mx) project_name using `javac` (+ AOT module)."""
    # jaotc uses ':' as separator.
    modules = ':'.join(['jdk.compiler'])
    for common_opts in common_opts_variants:
        out_dir = tempfile.mkdtemp()
        try:
            mx.log('(jaotc) Compiling module(s) {} with {}'.format(modules, ' '.join(common_opts)))
            with mktemp_libfile() as lib_module:
                run_jaotc(['-J' + opt for opt in common_opts] +
                          ['--info', '--module', modules, '--output', lib_module.name])

                aot_opts = [
                    '-XX:+UnlockDiagnosticVMOptions',
                    '-XX:+UseAOTStrictLoading',
                    '-XX:AOTLibrary=' + lib_module.name
                ]

                project = mx.project(project_name)
                java_files = collect_java_sources(project.source_dirs())
                javac_args = mx.JavacCompiler(jdk).prepare(
                    sourceFiles=java_files,
                    project=project,
                    outputDir=out_dir,
                    classPath=mx.classpath(project, includeSelf=False, jdk=jdk, ignoreStripped=True),
                    sourceGenDir=project.source_gen_dir(),
                    jnigenDir=project.jni_gen_dir(),
                    processorPath=project.annotation_processors_path(jdk),
                    disableApiRestrictions=True,
                    warningsAsErrors=False,
                    showTasks=False,
                    postCompileActions=[],
                    forceDeprecationAsWarning=False)

                mx_compiler.run_vm(common_opts + aot_opts + ['com.sun.tools.javac.Main'] + javac_args)

        finally:
            shutil.rmtree(out_dir)
Example #12
0
def run_jaotc(args, classpath=None, cwd=None):
    """run AOT compiler with classes in this repo instead of those in the JDK"""
    if jdk.javaCompliance < '11':
        mx.abort('jaotc command is only available if JAVA_HOME is JDK 11 or later')

    jaotc_entry = mx_compiler.JVMCIClasspathEntry('JAOTC')
    jvmci_classpath_adjusted = False
    if jaotc_entry not in mx_compiler._jvmci_classpath:
        mx_compiler.add_jvmci_classpath_entry(jaotc_entry)
        jvmci_classpath_adjusted = True

    vm_args = [a[2:] for a in args if a.startswith('-J')]
    args = [a for a in args if not a.startswith('-J')]

    verbose = ['--verbose'] if mx._opts.very_verbose else []
    cp = ['-cp', classpath] if classpath else []

    try:
        mx_compiler.run_vm(
            ['--add-exports=jdk.internal.vm.ci/jdk.vm.ci.aarch64=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.amd64=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.site=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.code.stack=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.common=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.aarch64=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.amd64=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.hotspot.sparc=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.meta=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.runtime=jdk.internal.vm.compiler,jdk.aot',
             '--add-exports=jdk.internal.vm.ci/jdk.vm.ci.sparc=jdk.internal.vm.compiler,jdk.aot',
             '-XX:+CalculateClassFingerprint'] + vm_args + cp + ['-m', 'jdk.aot/jdk.tools.jaotc.Main'] + verbose + args,
            cwd=cwd)
    finally:
        if jvmci_classpath_adjusted:
            mx_compiler._jvmci_classpath.remove(jaotc_entry)