Skip to content

Commit df4292a

Browse files
committed
[GR-9382] Backport removal of Graal.nodejs from the base GraalVM image.
PullRequest: js/1953
2 parents 73a6f6a + a561c6e commit df4292a

File tree

12 files changed

+58
-26
lines changed

12 files changed

+58
-26
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local common = import 'common.jsonnet';
66
// Used to run fewer jobs
77
local debug = false,
88

9-
local overlay = '04474738e2bad47ebb898aae9f2d6b34447f59eb',
9+
local overlay = 'b9c0e1bac06788784342afd8917abb7cc7557042',
1010

1111
local no_overlay = 'cb733e564850cd37b685fcef6f3c16b59802b22c',
1212

graal-js/mx.graal-js/mx_graal_js.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ def is_included(path):
324324
)
325325
],
326326
boot_jars=['graal-js:GRAALJS_SCRIPTENGINE'],
327-
supported=True,
327+
installable=True,
328+
stability="supported",
328329
))
329330

330331
def verify_ci(args):

graal-js/mx.graal-js/native-image.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ JavaArgs = -Xmx3G \
77
-Dpolyglot.image-build-time.PreinitializeContexts=js
88

99
Args = -H:MaxRuntimeCompileMethods=9200 \
10-
--initialize-at-build-time=com.oracle.truffle.js,com.oracle.js.parser,com.oracle.truffle.trufflenode,com.oracle.truffle.regex \
10+
--initialize-at-build-time=com.oracle.truffle.js,com.oracle.js.parser,com.oracle.truffle.regex \
1111
--initialize-at-run-time=com.ibm.icu \
1212
-H:ReflectionConfigurationResources=com/oracle/truffle/js/runtime/resources/reflect-config.json \
1313
-H:ResourceConfigurationResources=com/oracle/truffle/js/runtime/resources/resource-config.json

graal-nodejs/deps/v8/src/graal/graal_isolate.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
#endif
7878

7979
#ifdef __APPLE__
80-
#define LIBNODESVM_RELPATH "/lib/polyglot/libpolyglot.dylib"
80+
#define LIBNODESVM_RELPATH "/languages/nodejs/lib/libgraal-nodejs.dylib"
81+
#define LIBPOLYGLOT_RELPATH "/lib/polyglot/libpolyglot.dylib"
8182
#define LIBJVM_RELPATH "/lib/server/libjvm.dylib"
8283
#define LIBJLI_RELPATH "/lib/jli/libjli.dylib"
8384
// libjli.dylib has moved in JDK 12, see https://bugs.openjdk.java.net/browse/JDK-8210931
@@ -87,10 +88,12 @@
8788
#define LIBJVM_RELPATH "/lib/server/libjvm.so"
8889
#define LIBJVM_RELPATH2 "/lib/sparcv9/server/libjvm.so"
8990
#elif defined(_WIN32)
90-
#define LIBNODESVM_RELPATH "\\lib\\polyglot\\polyglot.dll"
91+
#define LIBNODESVM_RELPATH "\\languages\\nodejs\\lib\\graal-nodejs.dll"
92+
#define LIBPOLYGLOT_RELPATH "\\lib\\polyglot\\polyglot.dll"
9193
#define LIBJVM_RELPATH "\\bin\\server\\jvm.dll"
9294
#else
93-
#define LIBNODESVM_RELPATH "/lib/polyglot/libpolyglot.so"
95+
#define LIBNODESVM_RELPATH "/languages/nodejs/lib/libgraal-nodejs.so"
96+
#define LIBPOLYGLOT_RELPATH "/lib/polyglot/libpolyglot.so"
9497
#define LIBJVM_RELPATH "/lib/server/libjvm.so"
9598
#define LIBJVM_RELPATH2 "/lib/amd64/server/libjvm.so"
9699
#endif
@@ -237,8 +240,8 @@ v8::Isolate* GraalIsolate::New(v8::Isolate::CreateParams const& params, v8::Isol
237240
std::string node = nodeExe();
238241

239242
std::string node_path = up(node);
240-
bool graalvm8 = ends_with(node_path, file_separator + "jre" + file_separator + "languages" + file_separator + "js" + file_separator + "bin");
241-
bool graalvm11plus = ends_with(node_path, file_separator + "languages" + file_separator + "js" + file_separator + "bin");
243+
bool graalvm8 = ends_with(node_path, file_separator + "jre" + file_separator + "languages" + file_separator + "nodejs" + file_separator + "bin");
244+
bool graalvm11plus = ends_with(node_path, file_separator + "languages" + file_separator + "nodejs" + file_separator + "bin");
242245
if (graalvm8 || graalvm11plus) {
243246
// Part of GraalVM: take precedence over any JAVA_HOME.
244247
// We set environment variables to ensure these values are correctly
@@ -248,7 +251,7 @@ v8::Isolate* GraalIsolate::New(v8::Isolate::CreateParams const& params, v8::Isol
248251

249252
# ifdef LIBNODESVM_RELPATH
250253
bool force_native = false;
251-
std::string node_jvm_lib = graalvm_home + (graalvm8 ? file_separator + "jre" : "") + LIBNODESVM_RELPATH;
254+
std::string node_jvm_lib = graalvm_home + (graalvm8 ? file_separator + "jre" : "") + (polyglot ? LIBPOLYGLOT_RELPATH : LIBNODESVM_RELPATH);
252255
if (mode == kModeJVM) {
253256
// will be set to appropriate libjvm path below
254257
UnsetEnv("NODE_JVM_LIB");
@@ -290,7 +293,7 @@ v8::Isolate* GraalIsolate::New(v8::Isolate::CreateParams const& params, v8::Isol
290293
SetEnv("NODE_JVM_LIB", jvmlib_path.c_str());
291294
}
292295
if (access(jvmlib_path.c_str(), F_OK) == -1) {
293-
fprintf(stderr, "Cannot find %s. Specify JAVA_HOME so $JAVA_HOME%s exists, or specify NODE_JVM_LIB directly.\n", jvmlib_path.c_str(), LIBJVM_RELPATH);
296+
fprintf(stderr, "Cannot find %s. Rebuild the polyglot library with `gu rebuild-images libpolyglot`, specify JAVA_HOME so that $JAVA_HOME%s exists, or specify NODE_JVM_LIB directly.\n", jvmlib_path.c_str(), LIBJVM_RELPATH);
294297
exit(1);
295298
}
296299

@@ -1262,6 +1265,7 @@ jobject GraalIsolate::CorrectReturnValue(GraalValue* value, jobject null_replace
12621265
int GraalIsolate::argc = 0;
12631266
char** GraalIsolate::argv = nullptr;
12641267
int GraalIsolate::mode = GraalIsolate::kModeDefault;
1268+
bool GraalIsolate::polyglot = false;
12651269
bool GraalIsolate::use_classpath_env_var = false;
12661270

12671271
void GraalIsolate::SetPromiseHook(v8::PromiseHook promise_hook) {

graal-nodejs/deps/v8/src/graal/graal_isolate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,9 @@ class GraalIsolate {
675675
}
676676
}
677677

678-
static void SetMode(int mode) {
678+
static void SetMode(int mode, bool polyglot) {
679679
GraalIsolate::mode = mode;
680+
GraalIsolate::polyglot = polyglot;
680681
}
681682

682683
static void InitThreadLocals();
@@ -767,6 +768,7 @@ class GraalIsolate {
767768
static int argc;
768769
static char** argv;
769770
static int mode;
771+
static bool polyglot;
770772
static bool use_classpath_env_var;
771773
friend v8::V8;
772774

graal-nodejs/deps/v8/src/graal/v8.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ namespace v8 {
11111111
bool show_help = false;
11121112
bool use_jvm = false;
11131113
bool use_native = false;
1114+
bool use_polyglot = false;
11141115
bool show_jvm_warning = false;
11151116
bool show_native_warning = false;
11161117
std::string vm_args;
@@ -1170,6 +1171,8 @@ namespace v8 {
11701171
} else {
11711172
if (!strcmp(arg, "--help")) {
11721173
show_help = true;
1174+
} else if (!strcmp(arg, "--polyglot")) {
1175+
use_polyglot = true;
11731176
}
11741177
argv[++unprocessed] = arg;
11751178
}
@@ -1195,7 +1198,7 @@ namespace v8 {
11951198
GraalIsolate::SetEnv("NODE_JVM_OPTIONS", vm_args.c_str());
11961199
}
11971200

1198-
GraalIsolate::SetMode(use_jvm ? GraalIsolate::kModeJVM : (use_native ? GraalIsolate::kModeNative : GraalIsolate::kModeDefault));
1201+
GraalIsolate::SetMode(use_jvm ? GraalIsolate::kModeJVM : (use_native ? GraalIsolate::kModeNative : GraalIsolate::kModeDefault), use_polyglot);
11991202
GraalIsolate::SetFlags(unprocessed, argv + 1);
12001203
if (remove_flags) {
12011204
// claim that we understood and processed all command line options

graal-nodejs/mx.graal-nodejs/com.oracle.truffle.trufflenode/src/com/oracle/truffle/trufflenode/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static Class<Function<String[], Object[]>> loadOptionsParser() throws Ex
8585
String javaHome = System.getProperty("java.home");
8686
String truffleNodePath = System.getenv("TRUFFLENODE_JAR_PATH");
8787
if (truffleNodePath == null) {
88-
truffleNodePath = javaHome + "/languages/js/trufflenode.jar";
88+
truffleNodePath = javaHome + "/languages/nodejs/trufflenode.jar";
8989
}
9090
String launcherCommonPath = System.getenv("LAUNCHER_COMMON_JAR_PATH");
9191
if (launcherCommonPath == null) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Requires = language:js
2+
3+
Args = -H:MaxRuntimeCompileMethods=500 \
4+
-H:+ReportExceptionStackTraces \
5+
-H:JNIConfigurationResources=svmnodejs.jniconfig,svmnodejs_jdkspecific.jniconfig \
6+
-H:ReflectionConfigurationResources=svmnodejs.reflectconfig \
7+
--initialize-at-build-time=com.oracle.truffle.trufflenode

graal-nodejs/mx.graal-nodejs/mx_graal_nodejs.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,28 +588,42 @@ def mx_post_parse_cmd_line(args):
588588
suite=_suite,
589589
name='Graal.nodejs',
590590
short_name='njs',
591-
dir_name='js',
591+
dir_name='nodejs',
592592
license_files=[],
593593
third_party_license_files=[],
594-
dependencies=['Graal.js'],
594+
# TODO (GR-30451): generate gu metadata for installable components that are included in the base image and make the
595+
# Graal.nodejs component depend on Graal.js.
596+
# To generate the Graal.js standalone, the Graal.js component must have `installable=True`. However:
597+
# 1. Graal.js is part of all base GraalVM images that we publish;
598+
# 2. We do not generate gu metadata for installable components that are part of the base image (GR-30451);
599+
# 3. We do not publish a Graal.js installable.
600+
# As a consequence, if the Graal.nodejs component depended on Graal.js, gu would not be able to resolve the
601+
# dependency at component-installation time.
602+
dependencies=[],
595603
truffle_jars=['graal-nodejs:TRUFFLENODE'],
596604
support_distributions=['graal-nodejs:TRUFFLENODE_GRAALVM_SUPPORT'],
597605
provided_executables=[
598606
'bin/<exe:node>',
599607
'bin/<cmd:npm>',
600608
'bin/<cmd:npx>',
601609
],
602-
polyglot_lib_build_args=[
603-
"-H:+ReportExceptionStackTraces",
604-
"-H:JNIConfigurationResources=svmnodejs.jniconfig,svmnodejs_jdkspecific.jniconfig",
605-
"-H:ReflectionConfigurationResources=svmnodejs.reflectconfig",
606-
],
607-
polyglot_lib_jar_dependencies=[
608-
"graal-nodejs:TRUFFLENODE"
610+
polyglot_lib_build_args=['--language:nodejs'],
611+
polyglot_lib_jar_dependencies=['graal-nodejs:TRUFFLENODE'],
612+
library_configs=[
613+
mx_sdk_vm.LibraryConfig(
614+
destination='lib/<lib:graal-nodejs>',
615+
jar_distributions=['graal-nodejs:TRUFFLENODE'],
616+
build_args=[
617+
'--tool:all',
618+
'--language:nodejs',
619+
'-Dgraalvm.libpolyglot=true', # `lib:graal-nodejs` should be initialized like `lib:polyglot` (GR-10038)
620+
],
621+
home_finder=True,
622+
),
609623
],
610624
has_polyglot_lib_entrypoints=True,
611-
installable=False,
612-
supported=True,
625+
installable=True,
626+
stability="supported",
613627
))
614628

615629
# pylint: disable=line-too-long

graal-nodejs/mx.graal-nodejs/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
"dependency:trufflenodeNative/headers/include",
180180
],
181181
"NODE_README.md" : "file:README.md",
182+
"native-image.properties": "file:mx.graal-nodejs/graal-nodejs-native-image.properties",
182183
"bin/" : [
183184
"dependency:trufflenodeNative/Release/<exe:node>",
184185
"file:mx.graal-nodejs/graalvm_launchers/<cmd:npm>",

0 commit comments

Comments
 (0)