10#include <unordered_map>
43 std::vector<std::reference_wrapper<const idx::IndexBase>>
indexes;
67 static inline std::unordered_map<unsigned, std::unique_ptr<WasmContext>>
contexts_;
76 auto wasm_context = std::make_unique<WasmContext>(
id, plan, configuration, size);
77 auto [it, inserted] =
contexts_.emplace(
id, std::move(wasm_context));
78 M_insist(inserted,
"WasmContext with that ID already exists");
83 static std::pair<std::reference_wrapper<WasmContext>,
bool>
90 [&](){
return std::make_unique<WasmContext>(
id, plan, configuration, size); }
92 return { std::ref(*it->second), inserted };
99 M_insist(res == 1,
"There is no context with the given ID to erase");
Defines the interface of all execution Backends.
The physical optimizer interface.
A table is a sorted set of attributes.
A Backend to execute a plan on a specific WasmEngine.
void register_operators(PhysicalOptimizer &phys_opt) const override
Registers all physical operators of this Backend in phys_opt.
WasmBackend(std::unique_ptr< WasmEngine > engine)
const WasmEngine & engine() const
Returns this backend's WasmEngine.
void execute(const MatchBase &plan) const override
Executes the already computed physical covering represented by plan using this Backend.
std::unique_ptr< WasmEngine > engine_
the WasmEngine of this backend
A WasmContext holds associated information of a WebAssembly module instance.
const MatchBase & plan
current plan
void install_guard_page()
Installs a guard page at the current heap and increments heap to the next page.
std::unique_ptr< const storage::DataLayoutFactory > result_set_factory
factory used to create the result set data layout
uint32_t heap
beginning of the heap, encoded as offset from the beginning of the virtual address space
@ TRAP_GUARD_PAGES
map guard pages with PROT_NONE to trap any accesses
uint32_t map_table(const Table &table)
Maps a table at the current start of heap and advances heap past the mapped region.
std::size_t add_index(const idx::IndexBase &index)
Adds an index to the WasmContext and returns its position in the vector as id.
bool config(config_t cfg) const
memory::AddressSpace vm
WebAssembly module instance's virtual address space aka. linear memory
std::vector< std::reference_wrapper< const idx::IndexBase > > indexes
the indexes used in the query
A WasmEngine provides an environment to compile and execute WebAssembly modules.
WasmEngine(WasmEngine &&)=default
static WasmContext & Create_Wasm_Context_For_ID(unsigned id, const MatchBase &plan, WasmContext::config_t configuration=WasmContext::config_t(0x0), std::size_t size=WASM_MAX_MEMORY)
Creates a new WasmContext for ID id with size bytes of virtual address space.
static std::pair< std::reference_wrapper< WasmContext >, bool > Ensure_Wasm_Context_For_ID(unsigned id, const MatchBase &plan, WasmContext::config_t configuration=WasmContext::config_t(0x0), std::size_t size=WASM_MAX_MEMORY)
If none exists, creates a new WasmContext for ID id with size bytes of virtual address space.
static constexpr std::size_t WASM_ALIGNMENT
The alignment that is suitable for all built-in types.
static bool Has_Wasm_Context(unsigned id)
Tests if the WasmContext with ID id exists.
static constexpr std::size_t WASM_PAGE_SIZE
the size of a WebAssembly memory page, 64 KiB.
virtual void execute(const MatchBase &plan)=0
Executes the already computed physical covering represented by plan using this WasmEngine.
WasmEngine(const WasmEngine &)=delete
static void Dispose_Wasm_Context(const WasmContext &ctx)
Disposes the WasmContext ctx.
static std::unordered_map< unsigned, std::unique_ptr< WasmContext > > contexts_
maps unique IDs to WasmContext instances
static WasmContext & Get_Wasm_Context_By_ID(unsigned id)
Returns a reference to the WasmContext with ID id.
static constexpr std::size_t WASM_MAX_MEMORY
The maximum memory of a WebAssembly module: 2^32 - 2^16 bytes ≈ 4 GiB.
virtual void compile(const MatchBase &plan) const =0
Compiles the already computed physical covering represented by plan using this WasmEngine.
static void Dispose_Wasm_Context(unsigned id)
Disposes the WasmContext with ID id.
The base class for indexes.
This class represents a reserved address space in virtual memory.