Skip to content

Commit 843f400

Browse files
committed
Improving GraalVM Integration
- Adds proper error handling when failures occur switching shell mode. - Updates the polyglot library to return the actual error codes in case of initialization failures and adds debugging support. - Updates the shell to print the initialization error codes coming from the polyglot library. Change-Id: Ie8a7bb0d51df44ee8b92d0d427d6a62b986e0eec
1 parent d9490b4 commit 843f400

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

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

Lines changed: 14 additions & 1 deletion
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..7006dbd44 100644
2+
index 1ed21c307..496663aec 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
@@ -2616,3 +2616,16 @@ index 1ed21c307..7006dbd44 100644
26162616
@CEntryPoint(name = "poly_context_builder_timezone", exceptionHandler = ExceptionHandler.class, documentation = {
26172617
"Sets timezone for a <code>poly_context_builder</code>.",
26182618
"",
2619+
diff --git a/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPIEntryPoints.java b/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPIEntryPoints.java
2620+
index a227d9c9e..58a723a15 100644
2621+
--- a/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPIEntryPoints.java
2622+
+++ b/src/main/java/org/graalvm/polyglot/nativeapi/PolyglotNativeAPIEntryPoints.java
2623+
@@ -104,7 +104,7 @@ public final class PolyglotNativeAPIEntryPoints {
2624+
"the thread is detached."})
2625+
@CEntryPointOptions(prologue = NoPrologue.class, epilogue = NoEpilogue.class, nameTransformation = UnchangedNameTransformation.class)
2626+
public static @CTypedef(name = "poly_status") int polyCreateIsolate(@CConst PolyglotIsolateParameters params, PolyglotIsolatePointer isolate, PolyglotIsolateThreadPointer thread) {
2627+
- return createIsolate(params, isolate, thread) == 0 ? Poly.ok() : Poly.generic_failure();
2628+
+ return createIsolate(params, isolate, thread);
2629+
}
2630+
2631+
@Uninterruptible(reason = UNINTERRUPTIBLE_REASON)

ext/polyglot/polyglot-nativeapi/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@
2121

2222
<dependencies>
2323

24-
<dependency>
25-
<groupId>org.graalvm.polyglot</groupId>
26-
<artifactId>polyglot</artifactId>
27-
<version>${graalvm.version}</version>
28-
</dependency>
29-
3024
<dependency>
3125
<groupId>org.graalvm.nativeimage</groupId>
3226
<artifactId>svm</artifactId>

ext/polyglot/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,34 @@
2222
</properties>
2323

2424
<dependencies>
25+
<dependency>
26+
<groupId>org.graalvm.polyglot</groupId>
27+
<artifactId>polyglot</artifactId>
28+
<version>${graalvm.version}</version>
29+
</dependency>
30+
2531
<dependency>
2632
<groupId>org.graalvm.polyglot</groupId>
2733
<artifactId>js-community</artifactId>
2834
<version>${graalvm.version}</version>
2935
<type>pom</type>
3036
</dependency>
37+
38+
<dependency>
39+
<groupId>org.graalvm.polyglot</groupId>
40+
<artifactId>dap-community</artifactId>
41+
<version>${graalvm.version}</version>
42+
<type>pom</type>
43+
<scope>runtime</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.graalvm.polyglot</groupId>
48+
<artifactId>inspect-community</artifactId>
49+
<version>${graalvm.version}</version>
50+
<type>pom</type>
51+
<scope>runtime</scope>
52+
</dependency>
3153
</dependencies>
3254

3355
<profiles>

mysqlshdk/scripting/polyglot/languages/polyglot_common_context.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mysqlshdk/scripting/polyglot/languages/polyglot_common_context.h"
2727

28+
#include "mysqlshdk/libs/utils/utils_string.h"
2829
#include "mysqlshdk/scripting/polyglot/native_wrappers/polyglot_collectable.h"
2930
#include "mysqlshdk/scripting/polyglot/utils/polyglot_error.h"
3031
#include "mysqlshdk/scripting/polyglot/utils/polyglot_scope.h"
@@ -34,8 +35,10 @@ namespace shcore {
3435
namespace polyglot {
3536

3637
void Polyglot_common_context::initialize() {
37-
if (poly_ok != poly_create_isolate(NULL, &m_isolate, &m_thread)) {
38-
throw Polyglot_generic_error("Error creating polyglot isolate");
38+
if (const auto rc = poly_create_isolate(NULL, &m_isolate, &m_thread);
39+
poly_ok != rc) {
40+
throw Polyglot_generic_error(
41+
shcore::str_format("Error creating polyglot isolate: %d", rc));
3942
}
4043

4144
m_garbage_collector.start(gc_config(), m_isolate);

mysqlshdk/shellcore/shell_core.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ bool Shell_core::switch_mode(Mode mode) {
178178
m_help.set_mode(mode);
179179

180180
if (_mode != mode) {
181+
Mode backup_mode = _mode;
181182
_mode = mode;
182-
init_mode(_mode);
183+
try {
184+
init_mode(_mode);
185+
} catch (...) {
186+
_mode = backup_mode;
187+
throw;
188+
}
183189
return true;
184190
}
185191
return false;

0 commit comments

Comments
 (0)