Skip to content

Commit 9318e3e

Browse files
committed
BUG#37712944 Improve jit-executor error handling and remove custom GC
This patch updates the shell integration code of the jit-executor to match the one used in the MySQL Router where error handling was improved. Additionally, removes the unnecessary Garbage Collection logic in favor of the default provided in the jit-executor. Change-Id: Idf84e8ea5a1e873d93ab69f706b16b84546b7f3e
1 parent 7a66b87 commit 9318e3e

18 files changed

+357
-480
lines changed

mysqlshdk/scripting/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ if (HAVE_JIT_EXECUTOR)
5353
polyglot/polyglot_type_conversion.cc
5454
polyglot/languages/polyglot_language.cc
5555
polyglot/languages/polyglot_common_context.cc
56-
polyglot/languages/polyglot_garbage_collector.cc
5756
polyglot/polyglot_context.cc
5857
polyglot/shell_polyglot_common_context.cc
5958
polyglot/shell_javascript.cc

mysqlshdk/scripting/polyglot/languages/polyglot_common_context.cc

+36-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2024, 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,
@@ -25,6 +25,7 @@
2525

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

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

37-
void Polyglot_common_context::initialize() {
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));
38+
void Polyglot_common_context::initialize(
39+
const std::vector<std::string> &isolate_args) {
40+
if (!isolate_args.empty()) {
41+
std::vector<char *> raw_isolate_args = {nullptr};
42+
for (const auto &arg : isolate_args) {
43+
raw_isolate_args.push_back(const_cast<char *>(arg.data()));
44+
}
45+
46+
auto params = raw_isolate_args.data();
47+
poly_isolate_params isolate_params;
48+
if (poly_ok != poly_set_isolate_params(&isolate_params,
49+
isolate_args.size() + 1, params)) {
50+
throw Polyglot_generic_error("Error creating polyglot isolate params");
51+
}
52+
53+
if (const auto rc =
54+
poly_create_isolate(&isolate_params, &m_isolate, &m_thread);
55+
rc != poly_ok) {
56+
throw Polyglot_generic_error(
57+
shcore::str_format("Error creating polyglot isolate: %d", rc));
58+
}
59+
} else {
60+
if (const auto rc = poly_create_isolate(NULL, &m_isolate, &m_thread);
61+
rc != poly_ok) {
62+
throw Polyglot_generic_error(
63+
shcore::str_format("Error creating polyglot isolate: %d", rc));
64+
}
4265
}
4366

44-
m_garbage_collector.start(gc_config(), m_isolate);
45-
4667
m_scope = std::make_unique<Polyglot_scope>(m_thread);
4768

4869
if (const auto rc = poly_register_log_handler_callbacks(
@@ -64,11 +85,13 @@ void Polyglot_common_context::finalize() {
6485

6586
m_scope.reset();
6687

67-
m_garbage_collector.stop();
68-
69-
if (const auto rc = poly_tear_down_isolate(m_thread); rc != poly_ok) {
70-
std::string error{"polyglot error while tearing down the isolate"};
71-
log(error.data(), error.size());
88+
if (m_isolate && m_thread) {
89+
if (const auto rc = poly_detach_all_threads_and_tear_down_isolate(m_thread);
90+
rc != poly_ok) {
91+
const auto error = shcore::str_format(
92+
"Polyglot error while tearing down the isolate: %d", rc);
93+
log(error.data(), error.size());
94+
}
7295
}
7396

7497
clean_collectables();

mysqlshdk/scripting/polyglot/languages/polyglot_common_context.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates.
2+
* Copyright (c) 2024, 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,
@@ -30,7 +30,6 @@
3030

3131
#include <memory>
3232

33-
#include "mysqlshdk/scripting/polyglot/languages/polyglot_garbage_collector.h"
3433
#include "mysqlshdk/scripting/polyglot/native_wrappers/polyglot_collectable.h"
3534
#include "mysqlshdk/scripting/polyglot/utils/polyglot_scope.h"
3635
#include "mysqlshdk/scripting/polyglot/utils/polyglot_store.h"
@@ -59,22 +58,20 @@ class Polyglot_common_context {
5958
Polyglot_common_context() = default;
6059
virtual ~Polyglot_common_context() = default;
6160

62-
virtual void initialize();
61+
virtual void initialize(const std::vector<std::string> &isolate_args);
6362
virtual void finalize();
6463

6564
poly_reference engine() const { return m_engine.get(); }
6665
poly_isolate isolate() const { return m_isolate; }
6766
poly_thread thread() const { return m_thread; }
6867

69-
Garbage_collector &garbage_collector() { return m_garbage_collector; }
70-
7168
void clean_collectables();
7269

7370
Collectable_registry *collectable_registry() { return &m_registry; }
7471

7572
protected:
76-
poly_isolate m_isolate;
77-
poly_thread m_thread;
73+
poly_isolate m_isolate = nullptr;
74+
poly_thread m_thread = nullptr;
7875

7976
private:
8077
void init_engine();
@@ -85,11 +82,9 @@ class Polyglot_common_context {
8582
virtual void flush() = 0;
8683
virtual void log(const char *bytes, size_t length) = 0;
8784
virtual poly_engine create_engine() { return nullptr; }
88-
virtual Garbage_collector::Config gc_config() { return {}; }
8985

9086
Store m_engine;
9187
std::unique_ptr<Polyglot_scope> m_scope;
92-
Garbage_collector m_garbage_collector;
9388
Collectable_registry m_registry;
9489
};
9590

mysqlshdk/scripting/polyglot/languages/polyglot_garbage_collector.cc

-141
This file was deleted.

mysqlshdk/scripting/polyglot/languages/polyglot_garbage_collector.h

-113
This file was deleted.

0 commit comments

Comments
 (0)