Skip to content

Commit 502f8b7

Browse files
committed
Polyglot sandbox on GraalOS.
1 parent f5e16b2 commit 502f8b7

File tree

232 files changed

+16097
-5071
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

232 files changed

+16097
-5071
lines changed

docs/reference-manual/embedding/embed-languages.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,17 @@ public class PolyglotIsolate {
745745
}
746746
```
747747
748+
Starting from GraalVM 25.0, a polyglot isolate can be launched in a separate external sub-process by setting the `--engine.IsolateMode=external` option.
749+
This allows the isolate to run in a fully separate OS process, providing an additional level of isolation. The default mode remains `internal`, which uses a Native Image isolate embedded in the same process.
750+
751+
```java
752+
Context context = Context.newBuilder("js")
753+
.allowHostAccess(HostAccess.SCOPED)
754+
.option("engine.SpawnIsolate", "true")
755+
.option("engine.IsolateMode", "external")
756+
.build()
757+
```
758+
748759
Currently, the following languages are available as polyglot isolates:
749760
750761
| Language | Available from |

sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
1111
* GR-61448 Compilation id (`CompId`) was added to the `opt done` truffle compilation logs. This id matches the compilation id in the output of deoptimization, compilation and code cache logs on HotSpot and SubstrateVM.
1212
* GR-31495 Added the ability to specify language and instrument specific options using `Source.Builder.option(String, String)`. See the language and or tool specific documentation for available options. Available source options may also be reflected using `Instrument.getSourceOptions()` and `Language.getSourceOptions()`.
1313
* GR-55223 The option sandbox.MaxStackFrames is no longer mandatory for the UNTRUSTED polyglot sandbox policy thanks to improved deoptimization handling of compiled code.
14+
* GR-22699(EE-only) Added the ability to spawn `Engine` or `Context` isolated in a separate process by setting `Context.Builder.option("engine.IsolateMode", "external").`.
1415

1516
## Version 24.2.0
1617
* GR-54905 When using Truffle NFI with the Panama backend, native access must now be granted to the Truffle module instead of the NFI Panama module. Use the `--enable-native-access=org.graalvm.truffle` Java command line option to enable the native access for the NFI Panama backend.

sdk/mx.sdk/mx_sdk.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
import pathlib
5151
import mx_sdk_benchmark # pylint: disable=unused-import
5252
import mx_sdk_clangformat # pylint: disable=unused-import
53+
import argparse
5354
import datetime
55+
import shutil
56+
import tempfile
5457
from mx_bisect import define_bisect_default_build_steps
5558
from mx_bisect_strategy import BuildStepsGraalVMStrategy
5659

@@ -366,3 +369,52 @@ def maven_deploy_public(args, licenses=None, deploy_snapshots=True):
366369
mx.maven_deploy(deploy_args)
367370
mx.log(f'Deployed Maven artefacts to {path}')
368371
return path
372+
373+
@mx.command(_suite.name, 'nativebridge-benchmark')
374+
def nativebridge_benchmark(args):
375+
parser = argparse.ArgumentParser(prog='mx nativebridge-benchmark', description='Executes nativebridge benchmarks',
376+
usage='mx nativebridge-benchmark [--target-folder <folder> | --isolate-library <isolate-library> | mode+]')
377+
parser.add_argument('--target-folder', help='Folder where the benchmark isolate library will be generated.', default=None)
378+
parser.add_argument('--isolate-library', help='Use the given isolate library.', default=None)
379+
parsed_args, args = parser.parse_known_args(args)
380+
381+
jdk = mx.get_jdk(tag='graalvm')
382+
benchmark_dist = mx.distribution('NATIVEBRIDGE_BENCHMARK')
383+
isolate_library = parsed_args.isolate_library if parsed_args.isolate_library else None
384+
try:
385+
if not isolate_library:
386+
native_image_path = jdk.exe_path('native-image')
387+
if not os.path.exists(native_image_path):
388+
native_image_path = os.path.join(jdk.home, 'bin', mx.cmd_suffix('native-image'))
389+
if not os.path.exists(native_image_path):
390+
mx.abort(f"No native-image installed in GraalVM {jdk.home}. Switch to an environment that has an installed native-image command.")
391+
392+
target_dir = parsed_args.target_folder if parsed_args.target_folder else tempfile.mkdtemp()
393+
target = os.path.join(target_dir, "bench")
394+
native_image_args = mx.get_runtime_jvm_args(benchmark_dist, jdk=jdk) + [
395+
'--shared',
396+
'--initialize-at-build-time=org.graalvm.processisolate.api,org.graalvm.processisolate.common,org.graalvm.processisolate.impl',
397+
'',
398+
'-o',
399+
target
400+
]
401+
mx.run([native_image_path] + native_image_args)
402+
for n in os.listdir(target_dir):
403+
_, ext = os.path.splitext(n)
404+
if ext in ('.so', '.dylib', '.dll'):
405+
isolate_library = os.path.join(target_dir, n)
406+
break
407+
408+
launcher_project = mx.project('org.graalvm.nativebridge.launcher')
409+
launcher = next(launcher_project.getArchivableResults(single=True))[0]
410+
java_args = mx.get_runtime_jvm_args(benchmark_dist, jdk=jdk) + [
411+
'--enable-native-access=ALL-UNNAMED',
412+
'org.graalvm.nativebridge.benchmark.Main',
413+
launcher,
414+
isolate_library
415+
] + args
416+
mx.run_java(java_args, jdk=jdk)
417+
finally:
418+
if not parsed_args.isolate_library and not parsed_args.target_folder:
419+
shutil.rmtree(target_dir)
420+

sdk/mx.sdk/suite.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,51 @@
622622
"testProject" : True,
623623
"graalCompilerSourceEdition": "ignore",
624624
},
625+
"org.graalvm.nativebridge.benchmark": {
626+
"subDir" : "src",
627+
"sourceDirs" : ["src"],
628+
"dependencies" : [
629+
"NATIVEBRIDGE",
630+
],
631+
"annotationProcessors" : [
632+
"NATIVEBRIDGE_PROCESSOR",
633+
],
634+
"checkstyle" : "org.graalvm.word",
635+
"javaCompliance" : "17+",
636+
"workingSets" : "Graal,Test",
637+
"jacoco" : "exclude",
638+
"testProject" : True,
639+
"graalCompilerSourceEdition": "ignore",
640+
},
641+
"org.graalvm.nativebridge.launcher": {
642+
"subDir": "src",
643+
"native": "executable",
644+
"deliverable": "launcher",
645+
"use_jdk_headers": True,
646+
"buildDependencies": [
647+
],
648+
"os_arch": {
649+
"windows": {
650+
"<others>": {
651+
"cflags": ["/std:c++17"]
652+
}
653+
},
654+
"linux": {
655+
"<others>": {
656+
"toolchain": "sdk:LLVM_NINJA_TOOLCHAIN",
657+
"cflags": ["-std=c++17", "-g", "-Wall", "-Werror", "-D_GNU_SOURCE", "-stdlib=libc++"],
658+
"ldlibs": ["-ldl", "-pthread", "-stdlib=libc++", "-static-libstdc++", "-l:libc++abi.a"],
659+
},
660+
},
661+
"darwin": {
662+
"<others>": {
663+
"cflags": ["-std=c++17", "-g", "-Wall", "-Werror", "-pthread", "-ObjC++"],
664+
"ldlibs": ["-ldl", "-pthread", "-framework", "Foundation"],
665+
},
666+
},
667+
},
668+
"graalCompilerSourceEdition": "ignore",
669+
},
625670
"org.graalvm.toolchain.test" : {
626671
"class" : "ToolchainTestProject",
627672
"subDir" : "src",
@@ -1192,6 +1237,24 @@ class UniversalDetector {
11921237
"distDependencies" : [],
11931238
"maven": False,
11941239
},
1240+
"NATIVEBRIDGE_LAUNCHER_RESOURCES": {
1241+
"type": "dir",
1242+
"platformDependent": True,
1243+
"platforms": [
1244+
"linux-amd64",
1245+
"linux-aarch64",
1246+
"darwin-amd64",
1247+
"darwin-aarch64",
1248+
"windows-amd64",
1249+
"windows-aarch64",
1250+
],
1251+
"layout": {
1252+
"external_isolate/": "dependency:org.graalvm.nativebridge.launcher",
1253+
},
1254+
"description": "Contains a launcher for process isolated polyglot.",
1255+
"maven": False,
1256+
"graalCompilerSourceEdition": "ignore",
1257+
},
11951258
"NATIVEBRIDGE_PROCESSOR_TEST" : {
11961259
"subDir" : "src",
11971260
"dependencies" : [
@@ -1210,6 +1273,18 @@ class UniversalDetector {
12101273
"testDistribution" : True,
12111274
"graalCompilerSourceEdition": "ignore",
12121275
},
1276+
"NATIVEBRIDGE_BENCHMARK": {
1277+
"subDir" : "src",
1278+
"dependencies" : [
1279+
"org.graalvm.nativebridge.benchmark"
1280+
],
1281+
"distDependencies" : [
1282+
"NATIVEBRIDGE"
1283+
],
1284+
"maven": False,
1285+
"testDistribution" : True,
1286+
"graalCompilerSourceEdition": "ignore",
1287+
},
12131288
"RESOURCECOPY" : {
12141289
"subDir" : "src",
12151290
"dependencies" : [
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"name": "org.graalvm.nativebridge.benchmark.ProcessIsolate",
4+
"allDeclaredMethods": true
5+
}
6+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Args = --features=org.graalvm.nativebridge.benchmark.BenchmarkFeature
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.nativebridge.benchmark;
42+
43+
import org.graalvm.nativebridge.GenerateHotSpotToNativeFactory;
44+
import org.graalvm.nativebridge.GenerateNativeToNativeFactory;
45+
import org.graalvm.nativebridge.GenerateProcessToProcessFactory;
46+
import org.graalvm.nativebridge.IsolateCreateException;
47+
import org.graalvm.nativebridge.NativeIsolateConfig;
48+
import org.graalvm.nativebridge.ProcessIsolateConfig;
49+
50+
@GenerateHotSpotToNativeFactory(marshallers = BenchmarkMarshallerConfig.class, initialService = ForeignService.class)
51+
@GenerateNativeToNativeFactory(marshallers = BenchmarkMarshallerConfig.class, initialService = ForeignService.class)
52+
@GenerateProcessToProcessFactory(marshallers = BenchmarkMarshallerConfig.class, initialService = ForeignService.class, services = {
53+
ForeignService.class
54+
})
55+
final class BenchmarkFactory {
56+
57+
static Service createNonIsolated() {
58+
return new ServiceImplementation();
59+
}
60+
61+
public static ForeignService createInternallyIsolated(NativeIsolateConfig config) throws IsolateCreateException {
62+
return BenchmarkFactoryGen.create(config);
63+
}
64+
65+
public static ForeignService createExternallyIsolated(ProcessIsolateConfig config) throws IsolateCreateException {
66+
return BenchmarkFactoryGen.create(config);
67+
}
68+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.nativebridge.benchmark;
42+
43+
import org.graalvm.jniutils.NativeBridgeSupport;
44+
import org.graalvm.nativeimage.ImageSingletons;
45+
import org.graalvm.nativeimage.hosted.Feature;
46+
47+
public final class BenchmarkFeature implements Feature {
48+
49+
@Override
50+
public void afterRegistration(AfterRegistrationAccess access) {
51+
ImageSingletons.add(NativeBridgeSupport.class, new NativeBridgeSupportImpl());
52+
}
53+
54+
}

0 commit comments

Comments
 (0)