History

Various work for tool support in the VM. Update some type names (i.e. _t) and alter API signatures to be more consistent.

arr committed 10 years ago

Commit e5d3f861 parent bcb413516 files · +514 −45Browse files

Showing the changes to src/vm/thread.cpp (1 of 16 files). Show all

Unified · Split

src/vm/thread.cpp+18−7
@@ -133,6 +133,7 @@ vm_registers_t::vm_registers_t( · 132 unmodified lines
133133 , thread{ thread }
134134 , pc{ entry.module->header.entry_pc }
135135 , stack{ entry.module->header.stack_extent }
136+ , tool_dispatch{ nullptr }
136137 , src{ nullptr }
137138 , mid{ nullptr }
138139 , dest{ nullptr }
@@ -203,9 +204,9 @@ vm_thread_t::vm_thread_t( · 64 unmodified lines
203204
204205 vm_thread_t::vm_thread_t(
205206 vm_module_ref_t &entry,
207+ uint32_t parent_thread_id,
206208 const vm_frame_t &initial_frame,
207− vm_pc_t start_pc,
208− uint32_t parent_thread_id)
209+ vm_pc_t start_pc)
209210 : vm_alloc_t(vm_thread_t::type_desc())
210211 , _parent_thread_id{ parent_thread_id }
211212 , _registers{ *this, entry }
@@ -236,7 +237,7 @@ vm_thread_t::~vm_thread_t() · 24 unmodified lines
236237 debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "destroy: vm thread: %d %d\n", _thread_id, _parent_thread_id);
237238 }
238239
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)
240241 {
241242 _registers.current_thread_state = vm_thread_state_t::running;
242243 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
249250 {
250251 if (_registers.stack.peek_frame() == nullptr)
251252 {
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+
253256 _registers.current_thread_state = vm_thread_state_t::empty_stack;
254257 break;
255258 }
@@ -257,14 +260,16 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 1 unmodified line
257260 const auto &code_section = _registers.module_ref->code_section;
258261 assert(static_cast<std::size_t>(_registers.pc) < code_section.size());
259262
263+ assert(!_registers.module_ref->is_builtin_module() && "Interpreter thread is unable to execute native instructions");
260264 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)
263267 throw vm_system_exception{ "Unknown op-code" };
264268
269+ // Instruction is valid, decode and update registers for operation
265270 decode_address(inst, _registers);
266271 _registers.pc++;
267− vm_exec_table[op_code](_registers, virtual_machine);
272+ vm_exec_table[opcode](_registers, vm);
268273
269274 if (_registers.current_thread_state != vm_thread_state_t::running)
270275 break;
@@ -307,6 +312,12 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 36 unmodified lines
307312 return _registers.current_thread_state;
308313 }
309314
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+
310321 vm_thread_state_t vm_thread_t::get_state() const
311322 {
312323 return _registers.current_thread_state;