Skip to content

Commit 072eb60

Browse files
committed
[GR-68613] Add wasm language into JavaScript polyglot isolate library.
PullRequest: graal/21390
2 parents 5c83e4f + 912c528 commit 072eb60

File tree

8 files changed

+57
-22
lines changed

8 files changed

+57
-22
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
88
* GR-63588 A new entry (`Invalidated`) was added to the `opt deopt` truffle compilation logs. It is `true` or `false` depending on whether the compilation was also invalidated.
99
* GR-66817 Make `--polyglot` the default for language launchers, so there is no need to specify it anymore to use other languages in standalones. As a result, `AbstractLanguageLauncher#getDefaultLanguages()` and `Launcher#canPolyglot()` have been deprecated.
1010
* GR-65404 Remove `PolyglotLauncher` as it is no longer used.
11+
* GR-68613: JavaScript polyglot isolate now includes support for the WebAssembly (Wasm) language.
1112

1213
## Version 25.0.0
1314
* GR-60636 Truffle now stops compiling when the code cache fills up on HotSpot. A warning is printed when that happens.

truffle/mx.truffle/mx_truffle.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,11 +1365,11 @@ class _PolyglotIsolateResourceProject(mx.JavaProject):
13651365
and the resource ID is `<language_id>-isolate-<os>-<arch>`.
13661366
"""
13671367

1368-
def __init__(self, language_suite, subDir, language_id, resource_id, os_name, cpu_architecture, placeholder):
1368+
def __init__(self, language_suite, subDir, language_id, all_language_ids, resource_id, os_name, cpu_architecture, placeholder):
13691369
name = f'com.oracle.truffle.isolate.resource.{language_id}.{os_name}.{cpu_architecture}'
13701370
javaCompliance = str(mx.distribution('truffle:TRUFFLE_API').javaCompliance) + '+'
13711371
project_dir = os.path.join(language_suite.dir, subDir, name)
1372-
deps = ['truffle:TRUFFLE_API']
1372+
deps = ['truffle:TRUFFLE_API', 'truffle-enterprise:TRUFFLE_ENTERPRISE']
13731373
if placeholder:
13741374
deps += ['sdk:NATIVEIMAGE']
13751375
super(_PolyglotIsolateResourceProject, self).__init__(language_suite, name, subDir=subDir, srcDirs=[], deps=deps,
@@ -1379,6 +1379,7 @@ def __init__(self, language_suite, subDir, language_id, resource_id, os_name, cp
13791379
self.srcDirs.append(src_gen_dir)
13801380
self.declaredAnnotationProcessors = ['truffle:TRUFFLE_DSL_PROCESSOR']
13811381
self.language_id = language_id
1382+
self.all_language_ids = all_language_ids
13821383
self.resource_id = resource_id
13831384
self.os_name = os_name
13841385
self.cpu_architecture = cpu_architecture
@@ -1456,6 +1457,7 @@ def build(self):
14561457
subst_eng = mx_subst.SubstitutionEngine()
14571458
subst_eng.register_no_arg('package', pkg_name)
14581459
subst_eng.register_no_arg('languageId', prj.language_id)
1460+
subst_eng.register_no_arg('languageIds', ', '.join([f'"{l}"' for l in prj.all_language_ids]))
14591461
subst_eng.register_no_arg('resourceId', prj.resource_id)
14601462
subst_eng.register_no_arg('os', prj.os_name)
14611463
subst_eng.register_no_arg('arch', prj.cpu_architecture)
@@ -1468,9 +1470,10 @@ def build(self):
14681470

14691471

14701472

1471-
def register_polyglot_isolate_distributions(language_suite, register_project, register_distribution, language_id,
1473+
def register_polyglot_isolate_distributions(language_suite, register_project, register_distribution, main_language_id,
14721474
subDir, language_pom_distribution, maven_group_id, language_license,
1473-
isolate_build_options=None, platforms=None):
1475+
isolate_build_options=None, platforms=None, additional_image_path_artifacts=None,
1476+
additional_language_ids=None):
14741477
"""
14751478
Creates and registers the polyglot isolate resource distribution and isolate resource meta-POM distribution.
14761479
The created polyglot isolate resource distribution is named `<ID>_ISOLATE_RESOURCES`, inheriting the Maven group ID
@@ -1483,25 +1486,27 @@ def register_polyglot_isolate_distributions(language_suite, register_project, re
14831486
:type register_project: (mx.Project) -> None
14841487
:param register_distribution: A callback to dynamically register the distribution, obtained as a parameter from `mx_register_dynamic_suite_constituents`.
14851488
:type register_distribution: (mx.Distribution) -> None
1486-
:param str language_id: The language ID.
1489+
:param str main_language_id: The language ID.
14871490
:param str subDir: a path relative to `suite.dir` in which the IDE project configuration for this distribution is generated
14881491
:param POMDistribution language_pom_distribution: The language meta pom distribution used to set the image builder module-path.
14891492
:param str maven_group_id: The maven language group id.
14901493
:param str | list | language_license: Language licence(s).
14911494
:param list isolate_build_options: additional options passed to a native image to build the isolate library.
14921495
:param list platforms: supported platforms, defaults to ['linux-amd64', 'linux-aarch64', 'darwin-amd64', 'darwin-aarch64', 'windows-amd64']
1496+
:param list additional_image_path_artifacts: additional artifacts to include in the polyglot isolate library image path
1497+
:param list additional_language_ids: language ids of additional languages added into polyglot isolate library
14931498
"""
14941499
assert language_suite
14951500
assert register_project
14961501
assert register_distribution
1497-
assert language_id
1502+
assert main_language_id
14981503
assert subDir
14991504
assert language_pom_distribution
15001505
assert maven_group_id
15011506
assert language_license
15021507

15031508
polyglot_isolates_value = mx_sdk_vm_impl._parse_cmd_arg('polyglot_isolates')
1504-
if not polyglot_isolates_value or not (polyglot_isolates_value is True or (isinstance(polyglot_isolates_value, list) and language_id in polyglot_isolates_value)):
1509+
if not polyglot_isolates_value or not (polyglot_isolates_value is True or (isinstance(polyglot_isolates_value, list) and main_language_id in polyglot_isolates_value)):
15051510
return False
15061511

15071512
if not isinstance(language_license, list):
@@ -1514,7 +1519,18 @@ def _qualname(distribution_name):
15141519
language_pom_distribution = _qualname(language_pom_distribution)
15151520
if isolate_build_options is None:
15161521
isolate_build_options = []
1517-
language_id_upper_case = language_id.upper()
1522+
if additional_image_path_artifacts:
1523+
additional_image_path_artifacts = [_qualname(d) for d in additional_image_path_artifacts]
1524+
else:
1525+
additional_image_path_artifacts = []
1526+
if additional_language_ids:
1527+
if main_language_id in additional_language_ids:
1528+
all_language_ids = additional_language_ids
1529+
else:
1530+
all_language_ids = [main_language_id] + additional_language_ids
1531+
else:
1532+
all_language_ids = [main_language_id]
1533+
language_id_upper_case = main_language_id.upper()
15181534
if platforms is None:
15191535
platforms = [
15201536
'linux-amd64',
@@ -1530,12 +1546,12 @@ def _qualname(distribution_name):
15301546
platform_meta_poms = []
15311547
for platform in platforms:
15321548
build_for_current_platform = platform == current_platform
1533-
resource_id = f'{language_id}-isolate-{platform}'
1549+
resource_id = f'{main_language_id}-isolate-{platform}'
15341550
os_name, cpu_architecture = platform.split('-')
15351551
os_name_upper_case = os_name.upper()
15361552
cpu_architecture_upper_case = cpu_architecture.upper()
15371553
# 1. Register a project generating and building an internal resource for polyglot isolate library
1538-
build_internal_resource = _PolyglotIsolateResourceProject(language_suite, subDir, language_id, resource_id,
1554+
build_internal_resource = _PolyglotIsolateResourceProject(language_suite, subDir, main_language_id, all_language_ids, resource_id,
15391555
os_name, cpu_architecture, not build_for_current_platform)
15401556
register_project(build_internal_resource)
15411557
resources_dist_dependencies = [
@@ -1544,14 +1560,14 @@ def _qualname(distribution_name):
15441560

15451561
if build_for_current_platform:
15461562
# 2. Register a project building the isolate library
1547-
isolate_deps = [language_pom_distribution, 'truffle-enterprise:TRUFFLE_ENTERPRISE']
1548-
build_library = PolyglotIsolateProject(language_suite, language_id, isolate_deps, isolate_build_options)
1563+
isolate_deps = [language_pom_distribution, 'truffle-enterprise:TRUFFLE_ENTERPRISE'] + additional_image_path_artifacts
1564+
build_library = PolyglotIsolateProject(language_suite, main_language_id, isolate_deps, isolate_build_options)
15491565
register_project(build_library)
15501566

15511567
# 3. Register layout distribution with isolate library and isolate resources
15521568
resource_base_folder = f'META-INF/resources/engine/{resource_id}/libvm'
15531569
attrs = {
1554-
'description': f'Contains {language_id} language library resources.',
1570+
'description': f'Contains {main_language_id} language library resources.',
15551571
'hashEntry': f'{resource_base_folder}/sha256',
15561572
'fileListEntry': f'{resource_base_folder}/files',
15571573
'maven': False,
@@ -1561,7 +1577,7 @@ def _qualname(distribution_name):
15611577
name=f'{language_id_upper_case}_ISOLATE_LAYOUT_{os_name_upper_case}_{cpu_architecture_upper_case}',
15621578
deps=[],
15631579
layout={
1564-
f'{resource_base_folder}/': f'dependency:{build_library.name}',
1580+
f'{resource_base_folder}/{mx.add_lib_suffix("libpolyglotisolate")}': f'dependency:{build_library.name}',
15651581
f'{resource_base_folder}/resources/': {"source_type": "dependency",
15661582
"dependency": f'{build_library.name}',
15671583
"path": 'language_resources/resources/*',
@@ -1590,7 +1606,7 @@ def _qualname(distribution_name):
15901606
# We pass directly the license id
15911607
licenses.update(['GFTC'])
15921608
attrs = {
1593-
'description': f'Polyglot isolate resources for {language_id} for {platform}.',
1609+
'description': f'Polyglot isolate resources for {main_language_id} for {platform}.',
15941610
'moduleInfo': {
15951611
'name': build_internal_resource.name,
15961612
},
@@ -1611,7 +1627,7 @@ def _qualname(distribution_name):
16111627
deps=resources_dist_dependencies,
16121628
mainClass=None,
16131629
excludedLibs=[],
1614-
distDependencies=['truffle:TRUFFLE_API'],
1630+
distDependencies=['truffle:TRUFFLE_API', 'truffle-enterprise:TRUFFLE_ENTERPRISE'],
16151631
javaCompliance=str(build_internal_resource.javaCompliance)+'+',
16161632
platformDependent=True,
16171633
theLicense=sorted(list(licenses)),
@@ -1623,7 +1639,7 @@ def _qualname(distribution_name):
16231639
# 5. Register meta POM distribution for the isolate library jar file for a specific platform.
16241640
isolate_dist_name = f'{language_id_upper_case}_ISOLATE_{os_name_upper_case}_{cpu_architecture_upper_case}'
16251641
attrs = {
1626-
'description': f'The {language_id} polyglot isolate for {platform}.',
1642+
'description': f'The {main_language_id} polyglot isolate for {platform}.',
16271643
'maven': {
16281644
'groupId': 'org.graalvm.polyglot',
16291645
'artifactId': maven_artifact_id,
@@ -1645,10 +1661,10 @@ def _qualname(distribution_name):
16451661
# 6. Register meta POM distribution listing all platform specific meta-POMS.
16461662
isolate_dist_name = f'{language_id_upper_case}_ISOLATE'
16471663
attrs = {
1648-
'description': f'The {language_id} polyglot isolate.',
1664+
'description': f'The {main_language_id} polyglot isolate.',
16491665
'maven': {
16501666
'groupId': 'org.graalvm.polyglot',
1651-
'artifactId': f'{language_id}-isolate',
1667+
'artifactId': f'{main_language_id}-isolate',
16521668
'tag': ['default', 'public'],
16531669
},
16541670
}

truffle/mx.truffle/polyglot_isolate_resource.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ package <package>;
4343
import com.oracle.truffle.api.CompilerDirectives;
4444
import com.oracle.truffle.api.InternalResource;
4545

46+
import com.oracle.truffle.polyglot.enterprise.isolate.PolyglotIsolateLanguages;
47+
4648
import java.io.IOException;
4749
import java.nio.file.Path;
4850

4951
@InternalResource.Id(value = PolyglotIsolateResource.ID, componentId = "engine", optional = true)
52+
@PolyglotIsolateLanguages({<languageIds>})
5053
public final class PolyglotIsolateResource implements InternalResource {
5154

5255
static final String ID = "<resourceId>";

truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/SandboxPolicyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
@RunWith(Parameterized.class)
8787
public class SandboxPolicyTest {
8888

89-
private static final String MISSING_ISOLATE_LIBRARY_MESSAGE = "No native isolate library found for language";
89+
private static final String MISSING_ISOLATE_LIBRARY_MESSAGE = "No native isolate library is available for the requested language(s)";
9090
private static final String UNSUPPORTED_ISOLATE_POLICY_MESSAGE = "but the current Truffle runtime only supports the TRUSTED or CONSTRAINED sandbox policies.";
9191

9292
private final Configuration configuration;

truffle/src/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ public abstract <T, G> Iterator<T> mergeHostGuestFrames(Object polyglotEngine, S
802802

803803
public abstract TruffleFile getInternalResource(Object owner, String resourceId) throws IOException;
804804

805+
public abstract Map<String, InternalResource> getEngineInternalResources();
806+
805807
public abstract Path getEngineResource(Object polyglotEngine, String resourceId) throws IOException;
806808

807809
public abstract Collection<String> getResourceIds(String componentId);

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/EngineAccessor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,15 @@ private static TruffleFile getInternalResource(Object owner, String resourceId,
21912191
return EngineAccessor.LANGUAGE.getTruffleFile(rootPath.toString(), languageContext.getInternalFileSystemContext());
21922192
}
21932193

2194+
@Override
2195+
public Map<String, InternalResource> getEngineInternalResources() {
2196+
Map<String, InternalResource> result = new HashMap<>();
2197+
for (InternalResourceCache cache : InternalResourceCache.getEngineResources()) {
2198+
result.put(cache.getResourceId(), cache.getInternalResource());
2199+
}
2200+
return result;
2201+
}
2202+
21942203
@Override
21952204
public Path getEngineResource(Object polyglotEngine, String resourceId) throws IOException {
21962205
InternalResourceCache resourceCache = InternalResourceCache.getEngineResource(resourceId);

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/InternalResourceCache.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ Path getPath(PolyglotEngineImpl polyglotEngine) throws IOException {
154154
}
155155
}
156156

157+
InternalResource getInternalResource() {
158+
return resourceFactory.get();
159+
}
160+
157161
void initializeOwningRoot(InternalResourceRoots.Root root) {
158162
assert owningRoot == null;
159163
assert path == null;

vm/mx.vm/suite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"name": "graal-nodejs",
3434
"subdir": True,
3535
"dynamic": True,
36-
"version": "ee39e01d5a836169615ca7e3626bed7119e03c18",
36+
"version": "672e298c28d2a82e4b1ee65d29523c3fff2b3309",
3737
"urls" : [
3838
{"url" : "https://github.com/graalvm/graaljs.git", "kind" : "git"},
3939
]
@@ -42,7 +42,7 @@
4242
"name": "graal-js",
4343
"subdir": True,
4444
"dynamic": True,
45-
"version": "ee39e01d5a836169615ca7e3626bed7119e03c18",
45+
"version": "672e298c28d2a82e4b1ee65d29523c3fff2b3309",
4646
"urls": [
4747
{"url": "https://github.com/graalvm/graaljs.git", "kind" : "git"},
4848
]

0 commit comments

Comments
 (0)