Skip to content

Commit

Permalink
Introduce vm suite
Browse files Browse the repository at this point in the history
wip
  • Loading branch information
ansalond authored and gilles-duboscq committed Apr 16, 2018
1 parent 07b2560 commit d111dc7
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 2 deletions.
19 changes: 17 additions & 2 deletions compiler/mx.compiler/mx_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,22 @@
import subprocess
import tempfile
import shutil

import mx_truffle
import mx_sdk

import mx
import mx_gate
from mx_gate import Task

import mx_unittest
from mx_unittest import unittest

from mx_javamodules import as_java_module
import mx_gate
import mx_unittest

import mx_graal_benchmark # pylint: disable=unused-import
import mx_graal_tools #pylint: disable=unused-import

import argparse
import shlex
import glob
Expand Down Expand Up @@ -1081,6 +1085,17 @@ def makegraaljdk(args):
else:
mx.abort('Can only make GraalJDK for JDK 8 currently')


mx_sdk.register_component(mx_sdk.GraalVmJvmciComponent(
name='Graal compiler',
id='graal',
documentation_files=[],
license_files=[],
third_party_license_files=[],
jvmci_jars=['dependency:compiler:GRAAL'],
))


mx.update_commands(_suite, {
'sl' : [sl, '[SL args|@VM options]'],
'vm': [run_vm, '[-options] class [args...]'],
Expand Down
109 changes: 109 additions & 0 deletions sdk/mx.sdk/mx_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,115 @@ def javadoc(args, vm=None):
shutil.move(os.sep.join([javadoc_dir, 'index.html']), os.sep.join([javadoc_dir, 'overview-frames.html']))
shutil.copy(os.sep.join([javadoc_dir, 'overview-summary.html']), os.sep.join([javadoc_dir, 'index.html']))


class LauncherConfig(object):
def __init__(self, jar_distributions, main_class, build_args):
"""
:type jar_distributions: list[str]
:type main_class: str
:type build_args: list[str]
"""
self.jar_distributions = jar_distributions
self.main_class = main_class
self.build_args = build_args

assert isinstance(self.jar_distributions, list)
assert isinstance(self.build_args, list)


class GraalVmComponent(object):
def __init__(self, name, id, documentation_files, license_files, third_party_license_files,
provided_executables=None, boot_jars=None):
"""
:type name: str
:type id: str
:type documentation_files: list[str]
:type license_files: list[str]
:type third_party_license_files: list[str]
:type provided_executables: list[str]
:type boot_jars: list[str]
"""
self.name = name
self.id = id
self.documentation_files = documentation_files
self.license_files = license_files
self.third_party_license_files = third_party_license_files
self.provided_executables = provided_executables or []
self.boot_jars = boot_jars or []

assert isinstance(self.documentation_files, list)
assert isinstance(self.license_files, list)
assert isinstance(self.third_party_license_files, list)
assert isinstance(self.provided_executables, list)
assert isinstance(self.boot_jars, list)


class GraalVmTruffleComponent(GraalVmComponent):
def __init__(self, name, id, documentation_files, license_files, third_party_license_files, truffle_jars,
support_distributions=None, launcher_configs=None, provided_executables=None,
polyglot_library_build_args=None, boot_jars=None):
"""
:type truffle_jars: list[str]
:type support_distributions: list[str]
:type launcher_configs: list[LauncherConfig]
:type polyglot_library_build_args: list[str]
"""
super(GraalVmTruffleComponent, self).__init__(name, id, documentation_files, license_files,
third_party_license_files, provided_executables, boot_jars)

self.truffle_jars = truffle_jars
self.support_distributions = support_distributions or []
self.launcher_configs = launcher_configs or []
self.polyglot_library_build_args = polyglot_library_build_args or []

assert isinstance(self.truffle_jars, list)
assert isinstance(self.support_distributions, list)
assert isinstance(self.launcher_configs, list)
assert isinstance(self.polyglot_library_build_args, list)

class GraalVmLanguage(GraalVmTruffleComponent):
pass


class GraalVmTool(GraalVmTruffleComponent):
pass


class GraalVmJvmciComponent(GraalVmComponent):
def __init__(self, name, id, documentation_files, license_files, third_party_license_files, jvmci_jars,
provided_executables=None, boot_jars=None):
"""
:type jvmci_jars: list[str]
"""
super(GraalVmJvmciComponent, self).__init__(name, id, documentation_files, license_files,
third_party_license_files, provided_executables, boot_jars)

self.jvmci_jars = jvmci_jars or []

assert isinstance(jvmci_jars, list)


class GraalVmJdkComponent(GraalVmComponent):
pass


_graalvm_components = []

def register_component(component):
"""
:type component: GraalVmComponent
"""
assert not any((c for c in _graalvm_components if c.name == component.name and isinstance(component, c.__class__)))
_graalvm_components.append(component)


def graalvm_components():
"""
:rtype: list[GraalVmComponent]
"""
return _graalvm_components


mx.update_commands(_suite, {
'javadoc' : [javadoc, '[SL args|@VM options]'],
})
Empty file added vm/LICENSE
Empty file.
13 changes: 13 additions & 0 deletions vm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Graal VM

Graal VM is an ecosystem for compiling and running applications written in most modern programming languages and offers the following benefits:

* **Performance**: Graal VM leverages years of research into compiler technology to give you better peak performance on average than any other JVM.
* **Polyglot Interoperability**: Combining programming languages in the same runtime maximizes your resources and increases code efficiency. Use whichever programming language is best fit for purpose, in any combination. Match the correct code to the use case you need.
* **Embeddable**: The Graal Polyglot SDK removes isolation between programming languages and gives you a next-generation runtime environment where you no longer need to write separate applications to use different languages.
* **Native**: Ahead-of-time (AOT) compiled native images improve application start-up time and reduce memory footprint.
* **Tooling**: Graal VM takes advantage of JVM-based tooling and provides a common set of tools, such as debugging and profiling, that you can use for all your code.

## Using Graal VM
You can use Graal VM like a Java Development Kit (JDK) in your IDE.

Empty file added vm/THIRDPARTYLICENSE
Empty file.
108 changes: 108 additions & 0 deletions vm/mx.vm/mx_vm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------

import mx, mx_subst, mx_sdk
import os

_suite = mx.suite('vm')

class GraalVmLayoutDistribution(mx.LayoutTARDistribution):
def __init__(self, suite, name, deps, exclLibs, platformDependent, theLicense, testDistribution, layout=None, path=None, **kwArgs):
def _get_component_id(self, comp=None, **kwargs):
return comp.id

def _get_languages_or_tool(self, comp=None, **kwargs):
if isinstance(comp, mx_sdk.GraalVmLanguage):
return 'languages'
if isinstance(comp, mx_sdk.GraalVmTool):
return 'tools'
return None

def _get_support(self, comp=None, start=None, **kwargs):
foo = os.path.relpath(os.path.join('jre', _get_languages_or_tool(None, comp=comp), _get_component_id(None, comp=comp)), start=start)
return foo

_layout_value_subst = mx_subst.SubstitutionEngine()
_layout_value_subst.register_with_arg('comp_id', _get_component_id, keywordArgs=True)
_layout_value_subst.register_with_arg('languages_or_tools', _get_languages_or_tool, keywordArgs=True)

_component_path_subst = mx_subst.SubstitutionEngine()
_component_path_subst.register_with_arg('support', _get_support, keywordArgs=True)

# Add base JDK
_add(layout, './', 'file:{}/*'.format(_get_jdk_dir()))

# Add compiler_name file
_compiler_name = 'graal-enterprise' if mx.suite('graal-enterprise', fatalIfMissing=False) else 'graal'
_add(layout, './jre/lib/jvmci/compiler_name', 'string:{}'.format(_compiler_name))

# Add the rest of the GraalVM
_layout_dict = {
'documentation_files': ['docs/<comp_id>/'],
'license_files': ['./'],
'third_party_license_files': ['./'],
'provided_executables': ['bin/', 'jre/bin/'],
'boot_jars': ['jre/lib/boot/'],
'truffle_jars': ['jre/<languages_or_tools>/<comp_id>/'],
'support_distributions': ['jre/<languages_or_tools>/<comp_id>/'],
'jvmci_jars': ['jre/lib/jvmci/'],
}

_layout_types_adding_deps = ['dependency', 'extracted-dependency']

for _component in mx_sdk.graalvm_components():
mx.log('Adding {} to the {} {}'.format(_component.name, name, self.__class__.__name__))
for _layout_key, _layout_values in _layout_dict.iteritems():
assert isinstance(_layout_values, list), 'Layout value of \'{}\' has the wrong type. Expected: \'list\'; got \'{}\''.format(_layout_key, _layout_values)
_component_paths = getattr(_component, _layout_key, [])
for _component_path in _component_paths:
for _layout_value in _layout_values:
_dest = _layout_value_subst.substitute(_layout_value, comp=_component)
_path = _component_path_subst.substitute(_component_path, comp=_component, start=os.path.dirname(_dest))
_add(layout, _dest, _path)

super(GraalVmLayoutDistribution, self).__init__(suite, name, deps, layout, path, platformDependent, theLicense, exclLibs, testDistribution=testDistribution, **kwArgs)
mx.logv('\'{}\' has layout \'{}\''.format(self.name, self.layout))

def _get_jdk_dir():
java_home = mx.get_jdk(tag='default').home
jdk_dir = java_home
if jdk_dir.endswith(os.path.sep):
jdk_dir = jdk_dir[:-len(os.path.sep)]
if jdk_dir.endswith("/Contents/Home"):
jdk_dir = jdk_dir[:-len("/Contents/Home")]
return jdk_dir

def _add(layout, key, value):
"""
:rtype layout: dict[str, list[str]]
:rtype key: str
:rtype value: list[str] or str
"""
_val = value if isinstance(value, list) else [value] if value else []
mx.logv('Adding \'{}: {}\' to the layout'.format(key, _val))
layout.setdefault(key, []).extend(_val)
mx.logvv('Layout: \'{}\''.format(layout))
69 changes: 69 additions & 0 deletions vm/mx.vm/suite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
suite = {
"name" : "vm",
"mxversion" : "5.144.0",
"imports" : {
"suites": [
{
"name" : "compiler",
"subdir": True,
"urls" : [
{"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},
]
},
]
},

"libraries" : {},

"projects" : {
"com.oracle.graalvm.locator" : {
"subDir" : "src",
"sourceDirs" : ["src"],
"dependencies" : [
"truffle:TRUFFLE_API",
],
"javaCompliance" : "1.8",
"checkstyle" : "org.graalvm.word",
"license" : "GPLv2-CPE",
},
},

"distributions" : {
"GRAALVM" : {
"native" : True,
"class" : "GraalVmLayoutDistribution",
"platformDependent" : True,
"description" : "GraalVM distribution",
"layout" : {
"./" : [
"file:LICENSE",
"file:THIRDPARTYLICENSE",
"file:README.md",
],
"jre/lib/boot/" : [
"dependency:sdk:GRAAL_SDK",
],
"jre/lib/graalvm/" : [
"dependency:sdk:LAUNCHER_COMMON",
],
"jre/lib/jvmci/parentClassLoader.classpath" : [
"string:../truffle/truffle-api.jar:../truffle/locator.jar:../truffle/truffle-nfi.jar",
],
"jre/lib/truffle/" : [
"dependency:truffle:TRUFFLE_API",
"dependency:truffle:TRUFFLE_DSL_PROCESSOR",
"dependency:truffle:TRUFFLE_NFI",
"dependency:truffle:TRUFFLE_TCK",
"dependency:LOCATOR",
"extracted-dependency:truffle:TRUFFLE_NFI_NATIVE/include",
],
},
},
"LOCATOR": {
"dependencies": ["com.oracle.graalvm.locator"],
"distDependencies" : [
"truffle:TRUFFLE_API",
],
},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.oracle.graalvm.locator.GraalVMLocator
Loading

0 comments on commit d111dc7

Please sign in to comment.