MySQL 9.4.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
31#include <atomic>
32
36
37namespace jit_executor {
38
39/**
40 * Specialization of the Polyglot_common_context to provide MRS specific
41 * logging functions as well as the MRS specific engine to be used across the
42 * different contexts.
43 *
44 * NOTE: Using a shared engine across contexts is meant to enable code sharing,
45 * however, even it is enabled, the module files are being loaded on every
46 * created context.
47 */
49 public:
50 CommonContext(const std::shared_ptr<shcore::polyglot::IFile_system> &fs,
51 const std::vector<std::string> &module_files,
53 const shcore::polyglot::IsolateArgs &isolate_args);
54 ~CommonContext() override;
55
56 void initialize(const shcore::polyglot::IsolateArgs &isolate_args) override;
57 void finalize() override;
58 bool start();
59 bool got_fatal_error() const { return m_fatal_error; }
60 std::string error() const {
61 return m_fatal_error_description.empty()
62 ? "Got fatal error initializing GraalVM"
64 }
65
66 const std::shared_ptr<shcore::polyglot::IFile_system> &file_system() const {
67 return m_file_system;
68 }
69 const shcore::Dictionary_t &globals() const { return m_globals; }
70
71 private:
72 void life_cycle_thread();
73 void fatal_error() override;
74 void flush() override;
75 void log(const char *bytes, size_t length) override;
76
78 return {10, {}, 10};
79 }
80
81 /**
82 * Creates the shared engine for the different contexts created with this
83 * handler.
84 *
85 * Returning nullptr (or removing this implementation) would enable the
86 * default behavior for Graal which is to create an engine for every context.
87 */
88 poly_engine create_engine() override;
89
90 std::shared_ptr<JavaScript> m_base_context;
91 std::shared_ptr<shcore::polyglot::IFile_system> m_file_system;
92 std::vector<std::string> m_module_files;
93 std::vector<shcore::polyglot::Store> m_cached_sources;
95
96 std::unique_ptr<std::thread> m_life_cycle_thread;
97 std::mutex m_mutex;
98 std::condition_variable m_init_condition;
99
100 bool m_initialized = false;
101 bool m_terminated = false;
102
103 std::mutex m_finish_mutex;
104 std::condition_variable m_finish_condition;
105
106 // Global fatal error flag to indicate when the VM was ended
108 std::atomic_bool m_fatal_error = false;
111};
112
113} // namespace jit_executor
114
115#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:48
void fatal_error() override
Definition: jit_executor_common_context.cc:67
std::string m_fatal_error_description
Definition: jit_executor_common_context.h:109
void life_cycle_thread()
When persisting objects in GraalVM (creating references so they are available across threads/contexts...
Definition: jit_executor_common_context.cc:166
std::mutex m_mutex
Definition: jit_executor_common_context.h:97
std::string error() const
Definition: jit_executor_common_context.h:60
std::mutex m_finish_mutex
Definition: jit_executor_common_context.h:103
void log(const char *bytes, size_t length) override
Definition: jit_executor_common_context.cc:80
std::unique_ptr< std::thread > m_life_cycle_thread
Definition: jit_executor_common_context.h:96
std::atomic_bool m_fatal_error
Definition: jit_executor_common_context.h:108
std::vector< std::string > m_module_files
Definition: jit_executor_common_context.h:92
CommonContext(const std::shared_ptr< shcore::polyglot::IFile_system > &fs, const std::vector< std::string > &module_files, const shcore::Dictionary_t &globals, const shcore::polyglot::IsolateArgs &isolate_args)
Definition: jit_executor_common_context.cc:43
bool m_terminated
Definition: jit_executor_common_context.h:101
bool start()
Definition: jit_executor_common_context.cc:144
std::shared_ptr< JavaScript > m_base_context
Definition: jit_executor_common_context.h:90
const std::shared_ptr< shcore::polyglot::IFile_system > & file_system() const
Definition: jit_executor_common_context.h:66
bool got_fatal_error() const
Definition: jit_executor_common_context.h:59
std::condition_variable m_finish_condition
Definition: jit_executor_common_context.h:104
const shcore::Dictionary_t & globals() const
Definition: jit_executor_common_context.h:69
std::shared_ptr< shcore::polyglot::IFile_system > m_file_system
Definition: jit_executor_common_context.h:91
static bool m_global_fatal_error
Definition: jit_executor_common_context.h:107
std::condition_variable m_init_condition
Definition: jit_executor_common_context.h:98
std::vector< shcore::polyglot::Store > m_cached_sources
Definition: jit_executor_common_context.h:93
shcore::Dictionary_t m_globals
Definition: jit_executor_common_context.h:94
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
void initialize(const shcore::polyglot::IsolateArgs &isolate_args) override
Definition: jit_executor_common_context.cc:128
shcore::polyglot::Garbage_collector::Config gc_config() override
Definition: jit_executor_common_context.h:77
shcore::polyglot::IsolateArgs m_isolate_args
Definition: jit_executor_common_context.h:110
void finalize() override
Definition: jit_executor_common_context.cc:199
bool m_initialized
Definition: jit_executor_common_context.h:100
Common context for GraalVM Languages.
Definition: polyglot_common_context.h:65
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
Definition: polyglot_common_context.h:42