Skip to content

Commit 01e8f78

Browse files
committed
Improved polyglot isolate library lookup.
1 parent 0b72fce commit 01e8f78

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
1010
* GR-65404 Remove `PolyglotLauncher` as it is no longer used.
1111
* GR-63009: The WebAssembly (Wasm) language is now available as a polyglot isolate.
1212
* GR-63009: JavaScript polyglot isolate now includes support for the WebAssembly (Wasm) language.
13+
* GR-68613: JavaScript polyglot isolate now includes support for the WebAssembly (Wasm) language.
1314

1415
## Version 25.0.0
1516
* 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: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,11 +1366,11 @@ class _PolyglotIsolateResourceProject(mx.JavaProject):
13661366
and the resource ID is `<language_id>-isolate-<os>-<arch>`.
13671367
"""
13681368

1369-
def __init__(self, language_suite, subDir, language_id, resource_id, os_name, cpu_architecture, placeholder):
1369+
def __init__(self, language_suite, subDir, language_id, all_language_ids, resource_id, os_name, cpu_architecture, placeholder):
13701370
name = f'com.oracle.truffle.isolate.resource.{language_id}.{os_name}.{cpu_architecture}'
13711371
javaCompliance = str(mx.distribution('truffle:TRUFFLE_API').javaCompliance) + '+'
13721372
project_dir = os.path.join(language_suite.dir, subDir, name)
1373-
deps = ['truffle:TRUFFLE_API']
1373+
deps = ['truffle:TRUFFLE_API', 'truffle-enterprise:TRUFFLE_ENTERPRISE']
13741374
if placeholder:
13751375
deps += ['sdk:NATIVEIMAGE']
13761376
super(_PolyglotIsolateResourceProject, self).__init__(language_suite, name, subDir=subDir, srcDirs=[], deps=deps,
@@ -1380,6 +1380,7 @@ def __init__(self, language_suite, subDir, language_id, resource_id, os_name, cp
13801380
self.srcDirs.append(src_gen_dir)
13811381
self.declaredAnnotationProcessors = ['truffle:TRUFFLE_DSL_PROCESSOR']
13821382
self.language_id = language_id
1383+
self.all_language_ids = all_language_ids
13831384
self.resource_id = resource_id
13841385
self.os_name = os_name
13851386
self.cpu_architecture = cpu_architecture
@@ -1457,6 +1458,7 @@ def build(self):
14571458
subst_eng = mx_subst.SubstitutionEngine()
14581459
subst_eng.register_no_arg('package', pkg_name)
14591460
subst_eng.register_no_arg('languageId', prj.language_id)
1461+
subst_eng.register_no_arg('languageIds', ', '.join([f'"{l}"' for l in prj.all_language_ids]))
14601462
subst_eng.register_no_arg('resourceId', prj.resource_id)
14611463
subst_eng.register_no_arg('os', prj.os_name)
14621464
subst_eng.register_no_arg('arch', prj.cpu_architecture)
@@ -1469,9 +1471,10 @@ def build(self):
14691471

14701472

14711473

1472-
def register_polyglot_isolate_distributions(language_suite, register_project, register_distribution, language_id,
1474+
def register_polyglot_isolate_distributions(language_suite, register_project, register_distribution, main_language_id,
14731475
subDir, language_pom_distribution, maven_group_id, language_license,
1474-
isolate_build_options=None, platforms=None, additional_image_path_artifacts=None):
1476+
isolate_build_options=None, platforms=None, additional_image_path_artifacts=None,
1477+
additional_language_ids=None):
14751478
"""
14761479
Creates and registers the polyglot isolate resource distribution and isolate resource meta-POM distribution.
14771480
The created polyglot isolate resource distribution is named `<ID>_ISOLATE_RESOURCES`, inheriting the Maven group ID
@@ -1484,26 +1487,27 @@ def register_polyglot_isolate_distributions(language_suite, register_project, re
14841487
:type register_project: (mx.Project) -> None
14851488
:param register_distribution: A callback to dynamically register the distribution, obtained as a parameter from `mx_register_dynamic_suite_constituents`.
14861489
:type register_distribution: (mx.Distribution) -> None
1487-
:param str language_id: The language ID.
1490+
:param str main_language_id: The language ID.
14881491
:param str subDir: a path relative to `suite.dir` in which the IDE project configuration for this distribution is generated
14891492
:param POMDistribution language_pom_distribution: The language meta pom distribution used to set the image builder module-path.
14901493
:param str maven_group_id: The maven language group id.
14911494
:param str | list | language_license: Language licence(s).
14921495
:param list isolate_build_options: additional options passed to a native image to build the isolate library.
14931496
:param list platforms: supported platforms, defaults to ['linux-amd64', 'linux-aarch64', 'darwin-amd64', 'darwin-aarch64', 'windows-amd64']
14941497
:param list additional_image_path_artifacts: additional artifacts to include in the polyglot isolate library image path
1498+
:param list additional_language_ids: language ids of additional languages added into polyglot isolate library
14951499
"""
14961500
assert language_suite
14971501
assert register_project
14981502
assert register_distribution
1499-
assert language_id
1503+
assert main_language_id
15001504
assert subDir
15011505
assert language_pom_distribution
15021506
assert maven_group_id
15031507
assert language_license
15041508

15051509
polyglot_isolates_value = mx_sdk_vm_impl._parse_cmd_arg('polyglot_isolates')
1506-
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)):
1510+
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)):
15071511
return False
15081512

15091513
if not isinstance(language_license, list):
@@ -1520,7 +1524,14 @@ def _qualname(distribution_name):
15201524
additional_image_path_artifacts = [_qualname(d) for d in additional_image_path_artifacts]
15211525
else:
15221526
additional_image_path_artifacts = []
1523-
language_id_upper_case = language_id.upper()
1527+
if additional_language_ids:
1528+
if main_language_id in additional_language_ids:
1529+
all_language_ids = additional_language_ids
1530+
else:
1531+
all_language_ids = [main_language_id] + additional_language_ids
1532+
else:
1533+
all_language_ids = [main_language_id]
1534+
language_id_upper_case = main_language_id.upper()
15241535
if platforms is None:
15251536
platforms = [
15261537
'linux-amd64',
@@ -1536,12 +1547,12 @@ def _qualname(distribution_name):
15361547
platform_meta_poms = []
15371548
for platform in platforms:
15381549
build_for_current_platform = platform == current_platform
1539-
resource_id = f'{language_id}-isolate-{platform}'
1550+
resource_id = f'{main_language_id}-isolate-{platform}'
15401551
os_name, cpu_architecture = platform.split('-')
15411552
os_name_upper_case = os_name.upper()
15421553
cpu_architecture_upper_case = cpu_architecture.upper()
15431554
# 1. Register a project generating and building an internal resource for polyglot isolate library
1544-
build_internal_resource = _PolyglotIsolateResourceProject(language_suite, subDir, language_id, resource_id,
1555+
build_internal_resource = _PolyglotIsolateResourceProject(language_suite, subDir, main_language_id, all_language_ids, resource_id,
15451556
os_name, cpu_architecture, not build_for_current_platform)
15461557
register_project(build_internal_resource)
15471558
resources_dist_dependencies = [
@@ -1551,13 +1562,13 @@ def _qualname(distribution_name):
15511562
if build_for_current_platform:
15521563
# 2. Register a project building the isolate library
15531564
isolate_deps = [language_pom_distribution, 'truffle-enterprise:TRUFFLE_ENTERPRISE'] + additional_image_path_artifacts
1554-
build_library = PolyglotIsolateProject(language_suite, language_id, isolate_deps, isolate_build_options)
1565+
build_library = PolyglotIsolateProject(language_suite, main_language_id, isolate_deps, isolate_build_options)
15551566
register_project(build_library)
15561567

15571568
# 3. Register layout distribution with isolate library and isolate resources
15581569
resource_base_folder = f'META-INF/resources/engine/{resource_id}/libvm'
15591570
attrs = {
1560-
'description': f'Contains {language_id} language library resources.',
1571+
'description': f'Contains {main_language_id} language library resources.',
15611572
'hashEntry': f'{resource_base_folder}/sha256',
15621573
'fileListEntry': f'{resource_base_folder}/files',
15631574
'maven': False,
@@ -1567,7 +1578,7 @@ def _qualname(distribution_name):
15671578
name=f'{language_id_upper_case}_ISOLATE_LAYOUT_{os_name_upper_case}_{cpu_architecture_upper_case}',
15681579
deps=[],
15691580
layout={
1570-
f'{resource_base_folder}/': f'dependency:{build_library.name}',
1581+
f'{resource_base_folder}/{mx.add_lib_suffix("libpolyglotisolate")}': f'dependency:{build_library.name}',
15711582
f'{resource_base_folder}/resources/': {"source_type": "dependency",
15721583
"dependency": f'{build_library.name}',
15731584
"path": 'language_resources/resources/*',
@@ -1596,7 +1607,7 @@ def _qualname(distribution_name):
15961607
# We pass directly the license id
15971608
licenses.update(['GFTC'])
15981609
attrs = {
1599-
'description': f'Polyglot isolate resources for {language_id} for {platform}.',
1610+
'description': f'Polyglot isolate resources for {main_language_id} for {platform}.',
16001611
'moduleInfo': {
16011612
'name': build_internal_resource.name,
16021613
},
@@ -1617,7 +1628,7 @@ def _qualname(distribution_name):
16171628
deps=resources_dist_dependencies,
16181629
mainClass=None,
16191630
excludedLibs=[],
1620-
distDependencies=['truffle:TRUFFLE_API'],
1631+
distDependencies=['truffle:TRUFFLE_API', 'truffle-enterprise:TRUFFLE_ENTERPRISE'],
16211632
javaCompliance=str(build_internal_resource.javaCompliance)+'+',
16221633
platformDependent=True,
16231634
theLicense=sorted(list(licenses)),
@@ -1629,7 +1640,7 @@ def _qualname(distribution_name):
16291640
# 5. Register meta POM distribution for the isolate library jar file for a specific platform.
16301641
isolate_dist_name = f'{language_id_upper_case}_ISOLATE_{os_name_upper_case}_{cpu_architecture_upper_case}'
16311642
attrs = {
1632-
'description': f'The {language_id} polyglot isolate for {platform}.',
1643+
'description': f'The {main_language_id} polyglot isolate for {platform}.',
16331644
'maven': {
16341645
'groupId': 'org.graalvm.polyglot',
16351646
'artifactId': maven_artifact_id,
@@ -1651,10 +1662,10 @@ def _qualname(distribution_name):
16511662
# 6. Register meta POM distribution listing all platform specific meta-POMS.
16521663
isolate_dist_name = f'{language_id_upper_case}_ISOLATE'
16531664
attrs = {
1654-
'description': f'The {language_id} polyglot isolate.',
1665+
'description': f'The {main_language_id} polyglot isolate.',
16551666
'maven': {
16561667
'groupId': 'org.graalvm.polyglot',
1657-
'artifactId': f'{language_id}-isolate',
1668+
'artifactId': f'{main_language_id}-isolate',
16581669
'tag': ['default', 'public'],
16591670
},
16601671
}

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/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;

0 commit comments

Comments
 (0)