v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-interpreter-objects.h
Go to the documentation of this file.
1// Copyright 2024 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_WASM_INTERPRETER_WASM_INTERPRETER_OBJECTS_H_
6#define V8_WASM_INTERPRETER_WASM_INTERPRETER_OBJECTS_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
12#include "src/objects/struct.h"
13#include "src/wasm/wasm-value.h"
14
15namespace v8 {
16namespace internal {
17class Isolate;
18class WasmInstanceObject;
19
20namespace wasm {
21class InterpreterHandle;
22} // namespace wasm
23
28
29// This class should declare a heap Object, and should derive from Struct. But,
30// in order to avoid issues in static-roots.h with the DrumBrake build flag,
31// it is better not to introduce DrumBrake-specific types. Therefore we use a
32// Tuple2 as WasmInterpreterObject and class WasmInterpreterObject only has
33// static methods that receive a Tagged<Tuple2> or DirectHandle<Tuple2> as
34// argument.
35//
37 public:
39 Tagged<Tuple2> interpreter_object);
40 static inline void set_wasm_instance(
41 Tagged<Tuple2> interpreter_object,
42 Tagged<WasmInstanceObject> wasm_instance);
43
45 Tagged<Tuple2> interpreter_object);
46 static inline void set_interpreter_handle(Tagged<Tuple2> interpreter_object,
47 Tagged<Object> interpreter_handle);
48
50
51 // Execute the specified function in the interpreter. Read arguments from the
52 // {argument_values} vector and write to {return_values} on regular exit.
53 // The frame_pointer will be used to identify the new activation of the
54 // interpreter for unwinding and frame inspection.
55 // Returns true if exited regularly, false if a trap occurred. In the latter
56 // case, a pending exception will have been set on the isolate.
57 static bool RunInterpreter(
58 Isolate* isolate, Address frame_pointer,
59 DirectHandle<WasmInstanceObject> instance, int func_index,
60 const std::vector<wasm::WasmValue>& argument_values,
61 std::vector<wasm::WasmValue>& return_values);
62 static bool RunInterpreter(Isolate* isolate, Address frame_pointer,
64 int func_index, uint8_t* interpreter_sp);
65
66 // Get the stack of the wasm interpreter as pairs of {function index, byte
67 // offset}. The list is ordered bottom-to-top, i.e. caller before callee.
68 static std::vector<WasmInterpreterStackEntry> GetInterpretedStack(
69 Tagged<Tuple2> interpreter_object, Address frame_pointer);
70
71 // Get the function index for the index-th frame in the Activation identified
72 // by a given frame_pointer.
73 static int GetFunctionIndex(Tagged<Tuple2> interpreter_object,
74 Address frame_pointer, int index);
75};
76
77namespace wasm {
79 Isolate* isolate, DirectHandle<Tuple2> interpreter_object);
81 Isolate* isolate, DirectHandle<Tuple2> interpreter_object);
82} // namespace wasm
83
84} // namespace internal
85} // namespace v8
86
87#endif // V8_WASM_INTERPRETER_WASM_INTERPRETER_OBJECTS_H_
static Tagged< Object > get_interpreter_handle(Tagged< Tuple2 > interpreter_object)
static int GetFunctionIndex(Tagged< Tuple2 > interpreter_object, Address frame_pointer, int index)
static void set_interpreter_handle(Tagged< Tuple2 > interpreter_object, Tagged< Object > interpreter_handle)
static Tagged< WasmInstanceObject > get_wasm_instance(Tagged< Tuple2 > interpreter_object)
static DirectHandle< Tuple2 > New(DirectHandle< WasmInstanceObject >)
static std::vector< WasmInterpreterStackEntry > GetInterpretedStack(Tagged< Tuple2 > interpreter_object, Address frame_pointer)
static void set_wasm_instance(Tagged< Tuple2 > interpreter_object, Tagged< WasmInstanceObject > wasm_instance)
static bool RunInterpreter(Isolate *isolate, Address frame_pointer, DirectHandle< WasmInstanceObject > instance, int func_index, const std::vector< wasm::WasmValue > &argument_values, std::vector< wasm::WasmValue > &return_values)
V8_EXPORT_PRIVATE InterpreterHandle * GetInterpreterHandle(Isolate *isolate, DirectHandle< Tuple2 > interpreter_object)
V8_EXPORT_PRIVATE InterpreterHandle * GetOrCreateInterpreterHandle(Isolate *isolate, DirectHandle< Tuple2 > interpreter_object)
Definition c-api.cc:87
#define V8_EXPORT_PRIVATE
Definition macros.h:460