1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Revert "LibWasm: Some more performance stuff (#8812)"

This reverts commit 35394dbfaa.
I pushed the wrong button again, hopefully this will be the last of
such incidents.
This commit is contained in:
Ali Mohammad Pur 2021-07-17 01:11:28 +04:30
parent 35394dbfaa
commit 23b48f8fe1
8 changed files with 27 additions and 49 deletions

View file

@ -34,7 +34,6 @@ public:
explicit WebAssemblyModule(JS::Object& prototype) explicit WebAssemblyModule(JS::Object& prototype)
: JS::Object(prototype) : JS::Object(prototype)
{ {
m_machine.enable_instruction_count_limit();
} }
static Wasm::AbstractMachine& machine() { return m_machine; } static Wasm::AbstractMachine& machine() { return m_machine; }

View file

@ -128,8 +128,6 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
module.for_each_section_of_type<GlobalSection>([&](auto& global_section) { module.for_each_section_of_type<GlobalSection>([&](auto& global_section) {
for (auto& entry : global_section.entries()) { for (auto& entry : global_section.entries()) {
Configuration config { m_store }; Configuration config { m_store };
if (m_should_limit_instruction_count)
config.enable_instruction_count_limit();
config.set_frame(Frame { config.set_frame(Frame {
auxiliary_instance, auxiliary_instance,
Vector<Value> {}, Vector<Value> {},
@ -155,8 +153,6 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
Vector<Reference> references; Vector<Reference> references;
for (auto& entry : segment.init) { for (auto& entry : segment.init) {
Configuration config { m_store }; Configuration config { m_store };
if (m_should_limit_instruction_count)
config.enable_instruction_count_limit();
config.set_frame(Frame { config.set_frame(Frame {
main_module_instance, main_module_instance,
Vector<Value> {}, Vector<Value> {},
@ -208,8 +204,6 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
return IterationDecision::Break; return IterationDecision::Break;
} }
Configuration config { m_store }; Configuration config { m_store };
if (m_should_limit_instruction_count)
config.enable_instruction_count_limit();
config.set_frame(Frame { config.set_frame(Frame {
main_module_instance, main_module_instance,
Vector<Value> {}, Vector<Value> {},
@ -268,8 +262,6 @@ InstantiationResult AbstractMachine::instantiate(Module const& module, Vector<Ex
segment.value().visit( segment.value().visit(
[&](DataSection::Data::Active const& data) { [&](DataSection::Data::Active const& data) {
Configuration config { m_store }; Configuration config { m_store };
if (m_should_limit_instruction_count)
config.enable_instruction_count_limit();
config.set_frame(Frame { config.set_frame(Frame {
main_module_instance, main_module_instance,
Vector<Value> {}, Vector<Value> {},
@ -447,8 +439,6 @@ Result AbstractMachine::invoke(FunctionAddress address, Vector<Value> arguments)
Result AbstractMachine::invoke(Interpreter& interpreter, FunctionAddress address, Vector<Value> arguments) Result AbstractMachine::invoke(Interpreter& interpreter, FunctionAddress address, Vector<Value> arguments)
{ {
Configuration configuration { m_store }; Configuration configuration { m_store };
if (m_should_limit_instruction_count)
configuration.enable_instruction_count_limit();
return configuration.call(interpreter, address, move(arguments)); return configuration.call(interpreter, address, move(arguments));
} }

View file

@ -130,26 +130,26 @@ public:
} }
} }
ALWAYS_INLINE Value(Value const& value) Value(Value const& value)
: m_value(AnyValueType { value.m_value }) : m_value(AnyValueType { value.m_value })
, m_type(value.m_type) , m_type(value.m_type)
{ {
} }
ALWAYS_INLINE Value(Value&& value) Value(Value&& value)
: m_value(move(value.m_value)) : m_value(move(value.m_value))
, m_type(move(value.m_type)) , m_type(move(value.m_type))
{ {
} }
ALWAYS_INLINE Value& operator=(Value&& value) Value& operator=(Value&& value)
{ {
m_value = move(value.m_value); m_value = move(value.m_value);
m_type = move(value.m_type); m_type = move(value.m_type);
return *this; return *this;
} }
ALWAYS_INLINE Value& operator=(Value const& value) Value& operator=(Value const& value)
{ {
m_value = value.m_value; m_value = value.m_value;
m_type = value.m_type; m_type = value.m_type;
@ -157,7 +157,7 @@ public:
} }
template<typename T> template<typename T>
ALWAYS_INLINE Optional<T> to() Optional<T> to()
{ {
Optional<T> result; Optional<T> result;
m_value.visit( m_value.visit(
@ -505,13 +505,10 @@ public:
auto& store() const { return m_store; } auto& store() const { return m_store; }
auto& store() { return m_store; } auto& store() { return m_store; }
void enable_instruction_count_limit() { m_should_limit_instruction_count = true; }
private: private:
Optional<InstantiationError> allocate_all_initial_phase(Module const&, ModuleInstance&, Vector<ExternValue>&, Vector<Value>& global_values); Optional<InstantiationError> allocate_all_initial_phase(Module const&, ModuleInstance&, Vector<ExternValue>&, Vector<Value>& global_values);
Optional<InstantiationError> allocate_all_final_phase(Module const&, ModuleInstance&, Vector<Vector<Reference>>& elements); Optional<InstantiationError> allocate_all_final_phase(Module const&, ModuleInstance&, Vector<Vector<Reference>>& elements);
Store m_store; Store m_store;
bool m_should_limit_instruction_count { false };
}; };
class Linker { class Linker {

View file

@ -37,15 +37,12 @@ void BytecodeInterpreter::interpret(Configuration& configuration)
auto& instructions = configuration.frame().expression().instructions(); auto& instructions = configuration.frame().expression().instructions();
auto max_ip_value = InstructionPointer { instructions.size() }; auto max_ip_value = InstructionPointer { instructions.size() };
auto& current_ip_value = configuration.ip(); auto& current_ip_value = configuration.ip();
auto const should_limit_instruction_count = configuration.should_limit_instruction_count();
u64 executed_instructions = 0; u64 executed_instructions = 0;
while (current_ip_value < max_ip_value) { while (current_ip_value < max_ip_value) {
if (should_limit_instruction_count) { if (executed_instructions++ >= Constants::max_allowed_executed_instructions_per_call) [[unlikely]] {
if (executed_instructions++ >= Constants::max_allowed_executed_instructions_per_call) [[unlikely]] { m_trap = Trap { "Exceeded maximum allowed number of instructions" };
m_trap = Trap { "Exceeded maximum allowed number of instructions" }; return;
return;
}
} }
auto& instruction = instructions[current_ip_value.value()]; auto& instruction = instructions[current_ip_value.value()];
auto old_ip = current_ip_value; auto old_ip = current_ip_value;
@ -1126,15 +1123,17 @@ void DebuggerBytecodeInterpreter::interpret(Configuration& configuration, Instru
} }
} }
BytecodeInterpreter::interpret(configuration, ip, instruction); ScopeGuard guard { [&] {
if (post_interpret_hook) {
if (post_interpret_hook) { auto result = post_interpret_hook(configuration, ip, instruction, *this);
auto result = post_interpret_hook(configuration, ip, instruction, *this); if (!result) {
if (!result) { m_trap = Trap { "Trapped by user request" };
m_trap = Trap { "Trapped by user request" }; return;
return; }
} }
} } };
BytecodeInterpreter::interpret(configuration, ip, instruction);
} }
} }

View file

@ -50,7 +50,7 @@ protected:
T read_value(ReadonlyBytes data); T read_value(ReadonlyBytes data);
Vector<Value> pop_values(Configuration& configuration, size_t count); Vector<Value> pop_values(Configuration& configuration, size_t count);
ALWAYS_INLINE bool trap_if_not(bool value, StringView reason) bool trap_if_not(bool value, StringView reason)
{ {
if (!value) if (!value)
m_trap = Trap { reason }; m_trap = Trap { reason };

View file

@ -61,9 +61,6 @@ public:
Result call(Interpreter&, FunctionAddress, Vector<Value> arguments); Result call(Interpreter&, FunctionAddress, Vector<Value> arguments);
Result execute(Interpreter&); Result execute(Interpreter&);
void enable_instruction_count_limit() { m_should_limit_instruction_count = true; }
bool should_limit_instruction_count() const { return m_should_limit_instruction_count; }
void dump_stack(); void dump_stack();
private: private:
@ -72,7 +69,6 @@ private:
Stack m_stack; Stack m_stack;
size_t m_depth { 0 }; size_t m_depth { 0 };
InstructionPointer m_ip; InstructionPointer m_ip;
bool m_should_limit_instruction_count { false };
}; };
} }

View file

@ -25,7 +25,6 @@ namespace Web::Bindings {
WebAssemblyObject::WebAssemblyObject(JS::GlobalObject& global_object) WebAssemblyObject::WebAssemblyObject(JS::GlobalObject& global_object)
: Object(*global_object.object_prototype()) : Object(*global_object.object_prototype())
{ {
s_abstract_machine.enable_instruction_count_limit();
} }
void WebAssemblyObject::initialize(JS::GlobalObject& global_object) void WebAssemblyObject::initialize(JS::GlobalObject& global_object)

View file

@ -512,16 +512,14 @@ int main(int argc, char* argv[])
if (debug) if (debug)
launch_repl(); launch_repl();
if (result.is_trap()) { if (result.is_trap())
warnln("Execution trapped: {}", result.trap().reason); warnln("Execution trapped!");
} else { if (!result.values().is_empty())
if (!result.values().is_empty()) warnln("Returned:");
warnln("Returned:"); for (auto& value : result.values()) {
for (auto& value : result.values()) { Wasm::Printer printer { stream };
Wasm::Printer printer { stream }; g_stdout.write(" -> "sv.bytes());
g_stdout.write(" -> "sv.bytes()); g_printer.print(value);
g_printer.print(value);
}
} }
} }
} }