Skip to content

Commit

Permalink
aot -> interp
Browse files Browse the repository at this point in the history
  • Loading branch information
sakria9 committed Nov 3, 2023
1 parent e299eae commit cf9fd25
Show file tree
Hide file tree
Showing 14 changed files with 1,189 additions and 500 deletions.
9 changes: 6 additions & 3 deletions include/wamr.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "wasm_runtime.h"
#include <ranges>

enum ArchType { x86_64 };
enum ArchType { x86_64, arm64 };

struct MVVMAotMetadata {
std::vector<std::size_t> nops;
Expand All @@ -28,6 +28,8 @@ class WAMRInstance {
WASMFunctionInstanceCommon *func{};

public:
std::string aot_file_path;
std::string wasm_file_path;
std::map<ArchType, MVVMAotMetadata> mvvm_aot_metadatas;
std::vector<const char *> dir_;
std::vector<const char *> map_dir_;
Expand All @@ -37,7 +39,7 @@ class WAMRInstance {
std::vector<const char *> ns_pool_;
std::map<int, std::pair<std::string, int>> fd_map_;
bool is_jit;
char *buffer{};
bool is_aot{};
char error_buf[128]{};
uint32 buf_size{}, stack_size = 8092, heap_size = 8092;
typedef struct ThreadArgs {
Expand All @@ -53,7 +55,7 @@ class WAMRInstance {

void instantiate();
void recover(std::vector<std::unique_ptr<WAMRExecEnv>> *execEnv);
bool load_wasm_binary(const char *wasm_path);
bool load_wasm_binary(const char *wasm_path, char** buffer_ptr);
bool load_mvvm_aot_metadata(const char *file_path);
WASMFunction *get_func();
void set_func(WASMFunction *);
Expand All @@ -64,6 +66,7 @@ class WAMRInstance {
WASMExecEnv *get_exec_env();
WASMModuleInstance *get_module_instance();
AOTModule *get_module();
WASMModuleInstance *get_wasm_module_instance(); // for dump func
void set_wasi_args(WAMRWASIContext &addrs);
void set_wasi_args(const std::vector<std::string> &dir_list, const std::vector<std::string> &map_dir_list,
const std::vector<std::string> &env_list, const std::vector<std::string> &arg_list,
Expand Down
23 changes: 0 additions & 23 deletions include/wamr_block_addr.h

This file was deleted.

63 changes: 4 additions & 59 deletions include/wamr_exec_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#ifndef MVVM_WAMR_EXEC_ENV_H
#define MVVM_WAMR_EXEC_ENV_H
#include "wamr_block_addr.h"
#include "wamr_interp_frame.h"
#include "wamr_module_instance.h"
#include "wasm_runtime.h"
Expand Down Expand Up @@ -108,10 +107,6 @@ struct WAMRExecEnv { // multiple
/* The native thread handle of current thread */
// korp_tid handle;

#if WASM_ENABLE_AOT == 0
WAMRBlockAddr block_addr_cache[BLOCK_ADDR_CACHE_SIZE][BLOCK_ADDR_CONFLICT_SIZE];
#endif

// #ifdef OS_ENABLE_HW_BOUND_CHECK
// WASMJmpBuf *jmpbuf_stack_top;
// /* One guard page for the exception check */
Expand Down Expand Up @@ -139,60 +134,10 @@ struct WAMRExecEnv { // multiple
// uint8 bottom[1];
// } s;
// } wasm_stack;
std::vector<uint8_t> wasm_stack; // not known in the compile time

void dump_impl(WASMExecEnv *env) {
dump(&this->module_inst, reinterpret_cast<WASMModuleInstance *>(env->module_inst));
flags = env->suspend_flags.flags;
aux_boundary = env->aux_stack_boundary.boundary;
aux_bottom = env->aux_stack_bottom.bottom;
#if WASM_ENABLE_AOT == 0
for (int i = 0; i < BLOCK_ADDR_CACHE_SIZE; i++) {
for (int j = 0; j < 2; j++) {
dump(&(block_addr_cache[i][j]), &(env->block_addr_cache[i][j]));
}
}
#endif
auto cur_frame = env->cur_frame;
while (cur_frame) {
auto dumped_frame = new WAMRInterpFrame();
dump(dumped_frame, cur_frame);
this->frames.emplace_back(dumped_frame);
cur_frame = cur_frame->prev_frame;
}
wasm_stack = std::vector(env->wasm_stack.s.bottom, env->wasm_stack.s.top);
};

void restore_impl(WASMExecEnv *env) {
restore(&this->module_inst, reinterpret_cast<WASMModuleInstance *>(env->module_inst));
env->suspend_flags.flags = flags;
env->aux_stack_boundary.boundary = aux_boundary;
env->aux_stack_bottom.bottom = aux_bottom;
/** Need to make sure up to this point wasm_stack is allocated */
memcpy(env->wasm_stack.s.bottom, wasm_stack.data(), wasm_stack.size());
env->wasm_stack.s.top = env->wasm_stack.s.bottom + wasm_stack.size();
/** Should comply to the original wasm_stack */
LOGV(DEBUG) << (uint32)offsetof(WASMInterpFrame, lp);
env->cur_frame = (WASMInterpFrame *)((uint8 *)env->wasm_stack.s.bottom + this->frames[0]->lp -
(uint32)offsetof(WASMInterpFrame, lp));
auto cur_frame = env->cur_frame;
for (int i=0; i<this->frames.size(); i++) {
restore(this->frames[i].get(), cur_frame);
if (i != this->frames.size()-1) {
cur_frame->prev_frame = (WASMInterpFrame *)((uint8 *)env->wasm_stack.s.bottom + this->frames[i+1]->lp -
(uint32)offsetof(WASMInterpFrame, lp));
LOGV(DEBUG) << "cur_frame" << (void *)cur_frame << " " << this->frames[i+1]->lp;
cur_frame = cur_frame->prev_frame;
}
}
#if WASM_ENABLE_AOT == 0
for (int i = 0; i < BLOCK_ADDR_CACHE_SIZE; i++) {
for (int j = 0; j < BLOCK_ADDR_CONFLICT_SIZE; j++) {
restore(&(block_addr_cache[i][j]), &(env->block_addr_cache[i][j]));
}
}
#endif
};

void dump_impl(WASMExecEnv *env);

void restore_impl(WASMExecEnv *env);
};

template <SerializerTrait<WASMExecEnv *> T> void dump(T t, WASMExecEnv *env) { t->dump_impl(env); }
Expand Down
138 changes: 0 additions & 138 deletions include/wamr_function_instance.h

This file was deleted.

15 changes: 11 additions & 4 deletions include/wamr_interp_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#ifndef MVVM_WAMR_INTERP_FRAME_H
#define MVVM_WAMR_INTERP_FRAME_H
#include "aot_runtime.h"
#include "wamr_branch_block.h"
#include "wamr_function_instance.h"
#include "wasm_interp.h"
#include "wasm_runtime.h"
#include <memory>
Expand All @@ -17,7 +17,7 @@ struct WAMRInterpFrame {
// #if WASM_ENABLE_FAST_JIT != 0
// uint8 *jitted_return_addr;
// #endif
WAMRFunctionInstance function{};
size_t function_index{};

// #if WASM_ENABLE_PERF_PROFILING != 0
// uint64 time_started;
Expand All @@ -33,7 +33,6 @@ struct WAMRInterpFrame {
/* Operand stack top pointer of the current frame. The bottom of
the stack is the next cell after the last local variable. */
uint32 sp{}; // all the sp that can be restart
std::vector<std::unique_ptr<WAMRBranchBlock>> csp;

/*
* Frame data, the layout is:
Expand All @@ -42,14 +41,22 @@ struct WAMRInterpFrame {
* csp_bottom to csp_boundary: wasm label stack
* jit spill cache: only available for fast jit
*/
uint32 lp{}; // this thing is dynamic allocated
// #endif

std::vector<uint32> stack_frame;

void dump_impl(WASMInterpFrame *env);
void restore_impl(WASMInterpFrame *env);


void dump_impl(AOTFrame *env);
void restore_impl(AOTFrame *env);
};

template <SerializerTrait<WASMInterpFrame *> T> void dump(T t, WASMInterpFrame *env) { t->dump_impl(env); }
template <SerializerTrait<WASMInterpFrame *> T> void restore(T t, WASMInterpFrame *env) { t->restore_impl(env); }

template <SerializerTrait<AOTFrame *> T> void dump(T t, AOTFrame *env) { t->dump_impl(env); }
template <SerializerTrait<AOTFrame *> T> void restore(T t, AOTFrame *env) { t->restore_impl(env); }

#endif // MVVM_WAMR_INTERP_FRAME_H
Loading

0 comments on commit cf9fd25

Please sign in to comment.