MySQL 9.3.0
Source Code Documentation
jit_executor_common_context.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_SRC_JIT_EXECUTOR_COMMON_CONTEXT_H_
27#define ROUTER_SRC_JIT_EXECUTOR_SRC_JIT_EXECUTOR_COMMON_CONTEXT_H_
28
30
34
35namespace jit_executor {
36
37/**
38 * Specialization of the Polyglot_common_context to provide MRS specific
39 * logging functions as well as the MRS specific engine to be used across the
40 * different contexts.
41 *
42 * NOTE: Using a shared engine across contexts is meant to enable code sharing,
43 * however, even it is enabled, the module files are being loaded on every
44 * created context.
45 */
47 public:
48 CommonContext(const std::shared_ptr<shcore::polyglot::IFile_system> &fs,
49 const std::vector<std::string> &module_files,
51 const std::vector<std::string> &isolate_args);
52 ~CommonContext() override;
53
54 void initialize(const std::vector<std::string> &isolate_args) override;
55 void finalize() override;
56 bool start();
57 bool got_fatal_error() const { return m_fatal_error; }
58 std::string error() const {
59 return m_fatal_error_description.empty()
60 ? "Got fatal error initializing GraalVM"
62 }
63
64 const std::shared_ptr<shcore::polyglot::IFile_system> &file_system() const {
65 return m_file_system;
66 }
67 const shcore::Dictionary_t &globals() const { return m_globals; }
68
69 private:
70 void life_cycle_thread();
71 void fatal_error() override;
72 void flush() override;
73 void log(const char *bytes, size_t length) override;
74
76 return {10, {}, 10};
77 }
78
79 /**
80 * Creates the shared engine for the different contexts created with this
81 * handler.
82 *
83 * Returning nullptr (or removing this implementation) would enable the
84 * default behavior for Graal which is to create an engine for every context.
85 */
86 poly_engine create_engine() override;
87
88 std::shared_ptr<JavaScript> m_base_context;
89 std::shared_ptr<shcore::polyglot::IFile_system> m_file_system;
90 std::vector<std::string> m_module_files;
91 std::vector<shcore::polyglot::Store> m_cached_sources;
93
94 std::unique_ptr<std::thread> m_life_cycle_thread;
95 std::mutex m_mutex;
96 std::condition_variable m_init_condition;
97
98 bool m_initialized = false;
99 bool m_terminated = false;
100
101 std::mutex m_finish_mutex;
102 std::condition_variable m_finish_condition;
103
104 // Global fatal error flag to indicate when the VM was ended
108 std::vector<std::string> m_isolate_args;
109};
110
111} // namespace jit_executor
112
113#endif // ROUTER_SRC_JIT_EXECUTOR_SRC_JIT_EXECUTOR_COMMON_CONTEXT_H_
Specialization of the Polyglot_common_context to provide MRS specific logging functions as well as th...
Definition: jit_executor_common_context.h:46
void fatal_error() override
Definition: jit_executor_common_context.cc:67
std::string m_fatal_error_description
Definition: jit_executor_common_context.h:107
void life_cycle_thread()
When persisting objects in GraalVM (creating references so they are available across threads/contexts...
Definition: jit_executor_common_context.cc:165
std::mutex m_mutex
Definition: jit_executor_common_context.h:95
std::string error() const
Definition: jit_executor_common_context.h:58
std::vector< std::string > m_isolate_args
Definition: jit_executor_common_context.h:108
std::mutex m_finish_mutex
Definition: jit_executor_common_context.h:101
void log(const char *bytes, size_t length) override
Definition: jit_executor_common_context.cc:80
bool m_fatal_error
Definition: jit_executor_common_context.h:106
std::unique_ptr< std::thread > m_life_cycle_thread
Definition: jit_executor_common_context.h:94
std::vector< std::string > m_module_files
Definition: jit_executor_common_context.h:90
bool m_terminated
Definition: jit_executor_common_context.h:99
bool start()
Definition: jit_executor_common_context.cc:143
std::shared_ptr< JavaScript > m_base_context
Definition: jit_executor_common_context.h:88
const std::shared_ptr< shcore::polyglot::IFile_system > & file_system() const
Definition: jit_executor_common_context.h:64
bool got_fatal_error() const
Definition: jit_executor_common_context.h:57
CommonContext(const std::shared_ptr< shcore::polyglot::IFile_system > &fs, const std::vector< std::string > &module_files, const shcore::Dictionary_t &globals, const std::vector< std::string > &isolate_args)
Definition: jit_executor_common_context.cc:43
std::condition_variable m_finish_condition
Definition: jit_executor_common_context.h:102
const shcore::Dictionary_t & globals() const
Definition: jit_executor_common_context.h:67
std::shared_ptr< shcore::polyglot::IFile_system > m_file_system
Definition: jit_executor_common_context.h:89
static bool m_global_fatal_error
Definition: jit_executor_common_context.h:105
std::condition_variable m_init_condition
Definition: jit_executor_common_context.h:96
std::vector< shcore::polyglot::Store > m_cached_sources
Definition: jit_executor_common_context.h:91
shcore::Dictionary_t m_globals
Definition: jit_executor_common_context.h:92
void flush() override
Definition: jit_executor_common_context.cc:78
poly_engine create_engine() override
Creates the shared engine for the different contexts created with this handler.
Definition: jit_executor_common_context.cc:84
~CommonContext() override
Definition: jit_executor_common_context.cc:53
shcore::polyglot::Garbage_collector::Config gc_config() override
Definition: jit_executor_common_context.h:75
void initialize(const std::vector< std::string > &isolate_args) override
Definition: jit_executor_common_context.cc:128
void finalize() override
Definition: jit_executor_common_context.cc:198
bool m_initialized
Definition: jit_executor_common_context.h:98
Common context for GraalVM Languages.
Definition: polyglot_common_context.h:57
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: jit_executor_callbacks.h:36
Value::Map_type_ref Dictionary_t
Definition: jit_executor_value.h:430
Definition: polyglot_garbage_collector.h:81