Showing the changes to src/vm/thread.cpp (1 of 16 files). Show all
Unified · Split
| @@ -133,6 +133,7 @@ vm_registers_t::vm_registers_t( · 132 unmodified lines | ||
| 133 | 133 | , thread{ thread } |
| 134 | 134 | , pc{ entry.module->header.entry_pc } |
| 135 | 135 | , stack{ entry.module->header.stack_extent } |
| 136 | + , tool_dispatch{ nullptr } | |
| 136 | 137 | , src{ nullptr } |
| 137 | 138 | , mid{ nullptr } |
| 138 | 139 | , dest{ nullptr } |
| @@ -203,9 +204,9 @@ vm_thread_t::vm_thread_t( · 64 unmodified lines | ||
| 203 | 204 | |
| 204 | 205 | vm_thread_t::vm_thread_t( |
| 205 | 206 | vm_module_ref_t &entry, |
| 207 | + uint32_t parent_thread_id, | |
| 206 | 208 | const vm_frame_t &initial_frame, |
| 207 | − vm_pc_t start_pc, | |
| 208 | − uint32_t parent_thread_id) | |
| 209 | + vm_pc_t start_pc) | |
| 209 | 210 | : vm_alloc_t(vm_thread_t::type_desc()) |
| 210 | 211 | , _parent_thread_id{ parent_thread_id } |
| 211 | 212 | , _registers{ *this, entry } |
| @@ -236,7 +237,7 @@ vm_thread_t::~vm_thread_t() · 24 unmodified lines | ||
| 236 | 237 | debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "destroy: vm thread: %d %d\n", _thread_id, _parent_thread_id); |
| 237 | 238 | } |
| 238 | 239 | |
| 239 | −vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t quanta) | |
| 240 | +vm_thread_state_t vm_thread_t::execute(vm_t &vm, const uint32_t quanta) | |
| 240 | 241 | { |
| 241 | 242 | _registers.current_thread_state = vm_thread_state_t::running; |
| 242 | 243 | assert(_registers.pc != runtime_constants::invalid_program_counter); |
| @@ -249,7 +250,9 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 6 unmodified lines | ||
| 249 | 250 | { |
| 250 | 251 | if (_registers.stack.peek_frame() == nullptr) |
| 251 | 252 | { |
| 252 | − debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "exit: vm thread: stack exhausted: %d\n", _thread_id); | |
| 253 | + if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>()) | |
| 254 | + debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "exit: vm thread: stack exhausted: %d\n", _thread_id); | |
| 255 | + | |
| 253 | 256 | _registers.current_thread_state = vm_thread_state_t::empty_stack; |
| 254 | 257 | break; |
| 255 | 258 | } |
| @@ -257,14 +260,16 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 1 unmodified line | ||
| 257 | 260 | const auto &code_section = _registers.module_ref->code_section; |
| 258 | 261 | assert(static_cast<std::size_t>(_registers.pc) < code_section.size()); |
| 259 | 262 | |
| 263 | + assert(!_registers.module_ref->is_builtin_module() && "Interpreter thread is unable to execute native instructions"); | |
| 260 | 264 | const auto &inst = code_section[_registers.pc].op; |
| 261 | − const auto op_code = static_cast<std::size_t>(inst.opcode); | |
| 262 | − if (static_cast<std::size_t>(opcode_t::last_opcode) < op_code) | |
| 265 | + const auto opcode = static_cast<std::size_t>(inst.opcode); | |
| 266 | + if (static_cast<std::size_t>(opcode_t::last_opcode) < opcode) | |
| 263 | 267 | throw vm_system_exception{ "Unknown op-code" }; |
| 264 | 268 | |
| 269 | + // Instruction is valid, decode and update registers for operation | |
| 265 | 270 | decode_address(inst, _registers); |
| 266 | 271 | _registers.pc++; |
| 267 | − vm_exec_table[op_code](_registers, virtual_machine); | |
| 272 | + vm_exec_table[opcode](_registers, vm); | |
| 268 | 273 | |
| 269 | 274 | if (_registers.current_thread_state != vm_thread_state_t::running) |
| 270 | 275 | break; |
| @@ -307,6 +312,12 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 36 unmodified lines | ||
| 307 | 312 | return _registers.current_thread_state; |
| 308 | 313 | } |
| 309 | 314 | |
| 315 | +void vm_thread_t::set_tool_dispatch(vm_tool_dispatch_t *dispatch) | |
| 316 | +{ | |
| 317 | + assert((_registers.tool_dispatch.load() == nullptr) != (dispatch == nullptr) && "Dispatch value should toggle between null and non-null"); | |
| 318 | + _registers.tool_dispatch = dispatch; | |
| 319 | +} | |
| 320 | + | |
| 310 | 321 | vm_thread_state_t vm_thread_t::get_state() const |
| 311 | 322 | { |
| 312 | 323 | return _registers.current_thread_state; |