Skip to content

Commit ee1ad8e

Browse files
committed
Replacing the usage of the polyglot library in favor of jit-executor.
This patch updates the code to use the new jit-executor library dependency for JavaScript support. Additionally, the sources to build the jit-executor library have been updated to match the project used for the MySQL Middleware Clients. Change-Id: Ic29b5cd478b801fa57417dff4ea7abaaa5e671c7
1 parent e7e47a9 commit ee1ad8e

File tree

16 files changed

+98
-91
lines changed

16 files changed

+98
-91
lines changed

CMakeLists.txt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2014, 2025, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -755,31 +755,30 @@ if(HAVE_PYTHON)
755755
ENDIF()
756756
endif()
757757

758-
IF (BUNDLED_POLYGLOT_DIR)
759-
FIND_LIBRARY(POLYGLOT_LIBRARY
758+
IF (JIT_EXECUTOR_LIB)
759+
FIND_LIBRARY(JIT_EXECUTOR_LIBRARY
760760
NAMES
761-
polyglot
762-
libpolyglot
761+
jitexecutor
763762
HINTS
764-
"${BUNDLED_POLYGLOT_DIR}"
763+
"${JIT_EXECUTOR_LIB}"
765764
NO_DEFAULT_PATH)
766765

767766
IF(APPLE)
768767
# reset the ID to something predictible
769-
get_filename_component(POLYGLOT_LIBRARY_NAME "${POLYGLOT_LIBRARY}" NAME)
770-
EXECUTE_PROCESS(COMMAND install_name_tool -id "${POLYGLOT_LIBRARY_NAME}" "${POLYGLOT_LIBRARY}" RESULT_VARIABLE COMMAND_RESULT)
768+
get_filename_component(JIT_EXECUTOR_LIBRARY_NAME "${JIT_EXECUTOR_LIBRARY}" NAME)
769+
EXECUTE_PROCESS(COMMAND install_name_tool -id "${JIT_EXECUTOR_LIBRARY_NAME}" "${JIT_EXECUTOR_LIBRARY}" RESULT_VARIABLE COMMAND_RESULT)
771770

772771
IF(NOT "${COMMAND_RESULT}" STREQUAL "0")
773-
MESSAGE(FATAL_ERROR "Failed to execute: install_name_tool -id ${POLYGLOT_LIBRARY_NAME} ${POLYGLOT_LIBRARY}")
772+
MESSAGE(FATAL_ERROR "Failed to execute: install_name_tool -id ${JIT_EXECUTOR_LIBRARY_NAME} ${JIT_EXECUTOR_LIBRARY}")
774773
ENDIF()
775774
ENDIF()
776775

777-
INCLUDE_DIRECTORIES(SYSTEM "${BUNDLED_POLYGLOT_DIR}")
778-
MESSAGE(STATUS "Polyglot Library: ${POLYGLOT_LIBRARY}")
776+
INCLUDE_DIRECTORIES(SYSTEM "${JIT_EXECUTOR_LIB}")
777+
MESSAGE(STATUS "Jit Executor library: ${JIT_EXECUTOR_LIBRARY}")
779778
SET(HAVE_JS 1)
780-
SET(HAVE_POLYGLOT 1)
779+
SET(HAVE_JIT_EXECUTOR 1)
781780
ADD_DEFINITIONS(-DHAVE_JS)
782-
ADD_DEFINITIONS(-DHAVE_POLYGLOT)
781+
ADD_DEFINITIONS(-DHAVE_JIT_EXECUTOR)
783782
ENDIF()
784783

785784

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ext/polyglot/README.txt
9595

9696
To support JavaScript on the MySQL Shell add the following flag to the CMake call:
9797

98-
-DBUNDLED_POLYGLOT_DIR=<Path>
98+
-DJIT_EXECUTOR_LIB=<Path>
9999

100100
Where Path is the path to the folder containing the native Polyglot API library
101101
and headers

cmake/exeutils.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2019, 2025, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -89,10 +89,10 @@ function(add_shell_executable)
8989
"${ANTLR4_LIB_FILENAME}" "@loader_path/../${INSTALL_LIBDIR}/${ANTLR4_LIB_FILENAME}"
9090
$<TARGET_FILE:${ARGV0}>)
9191
endif()
92-
if(BUNDLED_POLYGLOT_DIR)
92+
if(JIT_EXECUTOR_LIB)
9393
add_custom_command(TARGET "${ARGV0}" POST_BUILD
9494
COMMAND install_name_tool -change
95-
"${POLYGLOT_LIBRARY_NAME}" "@loader_path/../${INSTALL_LIBDIR}/${POLYGLOT_LIBRARY_NAME}"
95+
"${JIT_EXECUTOR_LIBRARY_NAME}" "@loader_path/../${INSTALL_LIBDIR}/${JIT_EXECUTOR_LIBRARY_NAME}"
9696
$<TARGET_FILE:${ARGV0}>
9797
)
9898
endif()

ext/polyglot/README.txt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
This project builds a native version of the GraalVM Polyglot Native API Library
2-
with some enhancements required for the proper integration of GraalVM as a
3-
JavaScript runtime on the MySQL Middleware Clients.
1+
This project builds the JIT Executor library based on the GraalVM Polyglot
2+
Native API Library with some enhancements required for the proper integration of
3+
GraalVM as a JavaScript runtime on the MySQL Middleware Clients.
44

55
The library is assembled by taking the official code for the GraalVM Polyglot
66
Native API Library sources and exporting additional functionality through the
77
use of a patch file contained in the polyglot-nativeapi/patches directory.
88

99
For details about how to update this library to meet additional requirements on
10-
the MySQL Middleware clients, refer to the README.txt file at the
11-
polyglot-nativeapi folder.
10+
the MySQL Middleware clients, refer to polyglot-nativeapi folder.
1211

1312
BUILD REQUIREMENTS
1413
------------------
1514

16-
To build the native version of the GraalVM Polyglot Native API created with
17-
this project the following requirements should be met:
15+
To build the JIT Executor library created with this project the following
16+
requirements should be met:
1817

1918
- GraalVM 23.0.1 Installed and in PATH (to execute the native-image command)
2019
- The GraalVM 23.0.1 source code.
@@ -36,10 +35,9 @@ This command will execute the following steps:
3635
- 1) Copy the GraalVM Polyglot API sources from GRAALJDK_ROOT to this project.
3736
- 2) Apply the patches in the polyglot-nativeapi/patches folder to the copied
3837
sources.
39-
- 3) Build the native library for the GraalVM Polyglot Native API
38+
- 3) Build the JIT Executor library
4039

41-
The native library for the GraalVM Polyglot Native API library will be built at
42-
the following path:
40+
The JIT Executor library library will be built at the following path:
4341

4442
polyglot-nativeapi-native-library/target
4543

ext/polyglot/polyglot-nativeapi-native-library/pom.xml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,9 @@
1313
<groupId>org.graalvm.polyglot.library</groupId>
1414
<artifactId>polyglot-nativeapi-native-library</artifactId>
1515
<version>1.0-SNAPSHOT</version>
16-
<packaging>pom</packaging>
17-
18-
<properties>
19-
<maven.compiler.target>22</maven.compiler.target>
20-
<maven.compiler.source>22</maven.compiler.source>
21-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22-
</properties>
2316

2417
<dependencies>
2518

26-
<dependency>
27-
<groupId>org.graalvm.polyglot</groupId>
28-
<artifactId>polyglot</artifactId>
29-
<version>${graalvm.version}</version>
30-
</dependency>
31-
3219
<dependency>
3320
<groupId>org.graalvm.polyglot.library</groupId>
3421
<artifactId>polyglot-nativeapi</artifactId>
@@ -65,7 +52,7 @@
6552
</configuration>
6653
</execution>
6754
<execution>
68-
<id>build-polyglot-library</id>
55+
<id>build-jit-executor-library</id>
6956
<phase>package</phase>
7057
<goals>
7158
<goal>exec</goal>
@@ -77,7 +64,7 @@
7764
<commandlineArgs>
7865
-p %classpath
7966
-H:+ReportExceptionStackTraces
80-
-o ${project.build.directory}${file.separator}libpolyglot
67+
-o ${project.build.directory}${file.separator}libjitexecutor
8168
--no-fallback
8269
--shared
8370
-H:+UnlockExperimentalVMOptions
@@ -96,6 +83,7 @@
9683
-J-Xmx20g
9784
--initialize-at-run-time=org.graalvm.polyglot.nativeapi.PolyglotNativeAPI$NativeDataHolder
9885
--verbose
86+
-march=compatibility
9987
</commandlineArgs>
10088
</configuration>
10189
</execution>

ext/polyglot/polyglot-nativeapi/patches/enhancements.patch

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPI.java b/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPI.java
2-
index 1ed21c307..496663aec 100644
2+
index 1ed21c307..7301ff355 100644
33
--- a/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPI.java
44
+++ b/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPI.java
55
@@ -28,23 +28,60 @@ import static org.graalvm.polyglot.nativeapi.types.PolyglotNativeAPITypes.Polygl
@@ -189,7 +189,7 @@ index 1ed21c307..496663aec 100644
189189
@CEntryPoint(name = "poly_context_builder_build", exceptionHandler = ExceptionHandler.class, documentation = {
190190
"Builds a <code>context</code> from a <code>context_builder</code>. The same builder can be used to ",
191191
"produce multiple <code>poly_context</code> instances.",
192-
@@ -808,6 +935,138 @@ public final class PolyglotNativeAPI {
192+
@@ -808,6 +935,160 @@ public final class PolyglotNativeAPI {
193193
return poly_ok;
194194
}
195195

@@ -215,6 +215,28 @@ index 1ed21c307..496663aec 100644
215215
+ return poly_ok;
216216
+ }
217217
+
218+
+ @CEntryPoint(name = "poly_create_source", exceptionHandler = ExceptionHandler.class, documentation = {
219+
+ "Creates a Source object.",
220+
+ "",
221+
+ "@param language_id_utf8 0 terminated and UTF-8 encoded language identifier.",
222+
+ "@param name_utf8 0 terminated and UTF-8 encoded name given to the evaluate source code.",
223+
+ "@param source_utf8 0 terminated and UTF-8 encoded source code to be evaluated.",
224+
+ "@param result <code>poly_value</code> that is the Source Builder object.",
225+
+ "@return poly_ok if all works, poly_generic_error if there is a failure.",
226+
+ })
227+
+ public static PolyglotStatus poly_create_source(PolyglotIsolateThread thread, @CConst CCharPointer language_id_utf8, @CConst CCharPointer path_utf8,
228+
+ PolyglotValuePointer result) throws Exception {
229+
+ resetErrorState();
230+
+ nullCheck(language_id_utf8, "language_id_utf8");
231+
+ nullCheck(path_utf8, "path_utf8");
232+
+ String languageName = CTypeConversion.utf8ToJavaString(language_id_utf8);
233+
+ String jPath = CTypeConversion.utf8ToJavaString(path_utf8);
234+
+
235+
+ Source source = Source.newBuilder(languageName, new File(jPath)).build();
236+
+ result.write(createHandle(source));
237+
+ return poly_ok;
238+
+ }
239+
+
218240
+ @CEntryPoint(name = "poly_create_source_builder", exceptionHandler = ExceptionHandler.class, documentation = {
219241
+ "Creates a Source object.",
220242
+ "",
@@ -328,7 +350,7 @@ index 1ed21c307..496663aec 100644
328350
@CEntryPoint(name = "poly_context_get_engine", exceptionHandler = ExceptionHandler.class, documentation = {
329351
"Returns the engine this context belongs to.",
330352
"",
331-
@@ -954,6 +1213,36 @@ public final class PolyglotNativeAPI {
353+
@@ -954,6 +1235,36 @@ public final class PolyglotNativeAPI {
332354
return poly_ok;
333355
}
334356

@@ -365,7 +387,7 @@ index 1ed21c307..496663aec 100644
365387
@CEntryPoint(name = "poly_value_put_member", exceptionHandler = ExceptionHandler.class, documentation = {
366388
"Sets the value of a member with the `identifier_utf8`.",
367389
"",
368-
@@ -975,6 +1264,25 @@ public final class PolyglotNativeAPI {
390+
@@ -975,6 +1286,25 @@ public final class PolyglotNativeAPI {
369391
return poly_ok;
370392
}
371393

@@ -391,7 +413,7 @@ index 1ed21c307..496663aec 100644
391413
@CEntryPoint(name = "poly_value_has_member", exceptionHandler = ExceptionHandler.class, documentation = {
392414
"Returns `true` if such a member exists for the given `identifier_utf8`. If the value has no members ",
393415
"then it returns `false`.",
394-
@@ -1174,86 +1482,1769 @@ public final class PolyglotNativeAPI {
416+
@@ -1174,86 +1504,1769 @@ public final class PolyglotNativeAPI {
395417
return poly_ok;
396418
}
397419

@@ -2212,7 +2234,7 @@ index 1ed21c307..496663aec 100644
22122234
@CEntryPoint(name = "poly_create_array", exceptionHandler = ExceptionHandler.class, documentation = {
22132235
"Creates a polyglot array from the C array of polyglot values.",
22142236
"",
2215-
@@ -1396,6 +3387,60 @@ public final class PolyglotNativeAPI {
2237+
@@ -1396,6 +3409,60 @@ public final class PolyglotNativeAPI {
22162238
return poly_ok;
22172239
}
22182240

@@ -2273,7 +2295,7 @@ index 1ed21c307..496663aec 100644
22732295
@CEntryPoint(name = "poly_value_is_null", exceptionHandler = ExceptionHandler.class, documentation = {
22742296
"Returns `true` if this value is `null` like.",
22752297
"",
2276-
@@ -1668,6 +3713,71 @@ public final class PolyglotNativeAPI {
2298+
@@ -1668,6 +3735,71 @@ public final class PolyglotNativeAPI {
22772299
return poly_ok;
22782300
}
22792301

@@ -2345,7 +2367,7 @@ index 1ed21c307..496663aec 100644
23452367
@CEntryPoint(name = "poly_value_to_string_utf8", exceptionHandler = ExceptionHandler.class, documentation = {
23462368
"Writes a <code>toString</code> representation of a <code>poly_value</code> as a 0 terminated and UTF-8 encoded string.",
23472369
"",
2348-
@@ -1985,14 +4095,14 @@ public final class PolyglotNativeAPI {
2370+
@@ -1985,14 +4117,14 @@ public final class PolyglotNativeAPI {
23492371
for (int i = 0; i < arguments.length; i++) {
23502372
handleArgs[i] = createHandle(arguments[i]);
23512373
}
@@ -2366,7 +2388,7 @@ index 1ed21c307..496663aec 100644
23662388
} finally {
23672389
threadLocals.get().callbackException = null;
23682390
getHandles().popFramesIncluding(frame);
2369-
@@ -2003,6 +4113,81 @@ public final class PolyglotNativeAPI {
2391+
@@ -2003,6 +4135,81 @@ public final class PolyglotNativeAPI {
23702392
return poly_ok;
23712393
}
23722394

@@ -2448,7 +2470,7 @@ index 1ed21c307..496663aec 100644
24482470
@CEntryPoint(name = "poly_get_callback_info", exceptionHandler = ExceptionHandler.class, documentation = {
24492471
"Retrieves details about the call within a callback (e.g., the arguments from a given callback info).",
24502472
"",
2451-
@@ -2020,20 +4205,43 @@ public final class PolyglotNativeAPI {
2473+
@@ -2020,20 +4227,43 @@ public final class PolyglotNativeAPI {
24522474
nullCheck(data, "data");
24532475
PolyglotCallbackInfoInternal callbackInfo = fetchHandle(callback_info);
24542476
UnsignedWord numberOfArguments = WordFactory.unsigned(callbackInfo.arguments.length);
@@ -2501,7 +2523,7 @@ index 1ed21c307..496663aec 100644
25012523
@CEntryPoint(name = "poly_throw_exception", exceptionHandler = ExceptionHandler.class, documentation = {
25022524
"Raises an exception in a C callback.",
25032525
"",
2504-
@@ -2052,6 +4260,25 @@ public final class PolyglotNativeAPI {
2526+
@@ -2052,6 +4282,25 @@ public final class PolyglotNativeAPI {
25052527
return poly_ok;
25062528
}
25072529

@@ -2527,7 +2549,7 @@ index 1ed21c307..496663aec 100644
25272549
@CEntryPoint(name = "poly_delete_reference", exceptionHandler = ExceptionHandler.class, documentation = {
25282550
"Deletes a poly_reference. After this point, the reference must not be used anymore.",
25292551
"",
2530-
@@ -2171,6 +4398,26 @@ public final class PolyglotNativeAPI {
2552+
@@ -2171,6 +4420,26 @@ public final class PolyglotNativeAPI {
25312553
return poly_ok;
25322554
}
25332555

@@ -2554,7 +2576,7 @@ index 1ed21c307..496663aec 100644
25542576
@CEntryPoint(name = "poly_exception_is_internal_error", exceptionHandler = ExceptionHandler.class, documentation = {
25552577
"Checks if this exception was caused by an internal implementation error.",
25562578
"",
2557-
@@ -2649,6 +4896,61 @@ public final class PolyglotNativeAPI {
2579+
@@ -2649,6 +4918,61 @@ public final class PolyglotNativeAPI {
25582580
}
25592581
}
25602582

@@ -2627,5 +2649,5 @@ index a227d9c9e..58a723a15 100644
26272649
- return createIsolate(params, isolate, thread) == 0 ? Poly.ok() : Poly.generic_failure();
26282650
+ return createIsolate(params, isolate, thread);
26292651
}
2630-
2652+
26312653
@Uninterruptible(reason = UNINTERRUPTIBLE_REASON)

mysqlshdk/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2017, 2025, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -84,6 +84,6 @@ target_link_libraries(mysqlshdk-static PUBLIC
8484
${SSL_LIBRARIES}
8585
${ANTLR4_LIBRARIES})
8686

87-
IF(HAVE_POLYGLOT)
88-
target_link_libraries(mysqlshdk-static PUBLIC ${POLYGLOT_LIBRARY})
87+
IF(HAVE_JIT_EXECUTOR)
88+
target_link_libraries(mysqlshdk-static PUBLIC ${JIT_EXECUTOR_LIBRARY})
8989
ENDIF()

mysqlshdk/scripting/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2014, 2025, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -34,7 +34,7 @@ set(SCRIPTING_SOURCES
3434
type_info/custom.cc)
3535

3636

37-
if (HAVE_POLYGLOT)
37+
if (HAVE_JIT_EXECUTOR)
3838
set(SCRIPTING_SOURCES
3939
${SCRIPTING_SOURCES}
4040
polyglot/native_wrappers/polyglot_collectable.cc

mysqlshdk/shellcore/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2014, 2024, Oracle and/or its affiliates.
1+
# Copyright (c) 2014, 2025, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0,
@@ -55,7 +55,7 @@ set(SHELLCORE_SOURCES
5555
utils_help.cc
5656
wizard.cc)
5757

58-
if(HAVE_POLYGLOT)
58+
if(HAVE_JIT_EXECUTOR)
5959
set(SHELLCORE_SOURCES
6060
${SHELLCORE_SOURCES}
6161
provider_polyglot.cc

mysqlshdk/shellcore/base_shell.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0,
@@ -44,7 +44,7 @@
4444
#include "mysqlshdk/shellcore/provider_python.h"
4545
#include "shellcore/shell_python.h"
4646
#endif
47-
#ifdef HAVE_POLYGLOT
47+
#ifdef HAVE_JIT_EXECUTOR
4848
#include "mysqlshdk/include/shellcore/shell_polyglot.h"
4949
#include "mysqlshdk/shellcore/provider_polyglot.h"
5050
#endif

mysqlshdk/shellcore/shell_core.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License, version 2.0,
@@ -32,7 +32,7 @@
3232
#include <unistd.h>
3333
#endif
3434
#include "mysqlshdk/include/shellcore/base_shell.h"
35-
#ifdef HAVE_POLYGLOT
35+
#ifdef HAVE_JIT_EXECUTOR
3636
#include "mysqlshdk/include/shellcore/shell_polyglot.h"
3737
#include "mysqlshdk/scripting/polyglot/utils/polyglot_utils.h"
3838
#endif

0 commit comments

Comments
 (0)