History

Merged in remove_usings (pull request #15)

Remove using statements and minor GC improvement

Aaron R Robinson committed 9 years ago

Commit dd16d0c2 parents 36183b4 4697a6a32 files · +780 −480Browse files

Unified · Split

32 files
  1. src/asm/print_to_stream.cpp +0 −2
  2. src/asm/sbl_reader.cpp +32 −25
  3. src/asm/type_signature.cpp +5 −1
  4. src/exec/debugger.cpp +52 −24
  5. src/exec/main.cpp +50 −21
  6. src/include/runtime.h +15 −15
  7. src/vm/array.cpp +19 −11
  8. src/vm/builtin_module.cpp +2 −2
  9. src/vm/channel.cpp +27 −18
  10. src/vm/execution_table.cpp +13 −13
  11. src/vm/garbage_collector.cpp +78 −64
  12. src/vm/garbage_collector.h +3 −2
  13. src/vm/list.cpp +12 −5
  14. src/vm/math/Mathmod.cpp +15 −4
  15. src/vm/math/Mathmod.h +9 −2
  16. src/vm/module_reader.cpp +52 −28
  17. src/vm/module_ref.cpp +26 −12
  18. src/vm/module_resolver.cpp +10 −5
  19. src/vm/scheduler.cpp +33 −24
  20. src/vm/stack.cpp +27 −19
  21. src/vm/string.cpp +24 −19
  22. src/vm/sys/Sysmod.cpp +62 −47
  23. src/vm/sys/Sysmod.h +9 −2
  24. src/vm/sys/fd_manager.cpp +2 −1
  25. src/vm/sys/file_system.cpp +0 −2
  26. src/vm/sys/print.cpp +4 −2
  27. src/vm/thread.cpp +38 −19
  28. src/vm/tool_dispatch.cpp +36 −17
  29. src/vm/utf8.cpp +21 −20
  30. src/vm/vm.cpp +51 −26
  31. src/vm/vm_exception_handler.cpp +10 −6
  32. src/vm/vm_memory.cpp +43 −22
src/asm/print_to_stream.cpp+0−2
@@ -7,8 +7,6 @@ · 6 unmodified lines
7#include <ostream>7#include <ostream>
8#include <vm_asm.h>8#include <vm_asm.h>
9 9
10using namespace disvm::runtime;
11
12std::ostream& disvm::runtime::operator<<(std::ostream &ss, const inst_data_generic_t &m)10std::ostream& disvm::runtime::operator<<(std::ostream &ss, const inst_data_generic_t &m)
13{11{
14 switch (m.mode)12 switch (m.mode)
src/asm/sbl_reader.cpp+32−25
@@ -13,8 +13,15 @@ · 12 unmodified lines
13#include <utils.h>13#include <utils.h>
14#include <buffered_reader.h>14#include <buffered_reader.h>
15 15
16using namespace disvm;16using disvm::runtime::vm_pc_t;
17using namespace disvm::symbol;17
18using disvm::symbol::advance_pc_t;
19using disvm::symbol::function_data_t;
20using disvm::symbol::function_name_format_t;
21using disvm::symbol::source_ref_t;
22using disvm::symbol::symbol_data_t;
23using disvm::symbol::symbol_pc_iter_t;
24using disvm::symbol::type_class_t;
18 25
19namespace26namespace
20{27{
@@ -67,8 +74,8 @@ namespace · 46 unmodified lines
67 74
68 struct func_item_t75 struct func_item_t
69 {76 {
70 runtime::vm_pc_t entry_pc;77 vm_pc_t entry_pc;
71 runtime::vm_pc_t limit_pc;78 vm_pc_t limit_pc;
72 std::string name;79 std::string name;
73 id_table_t args;80 id_table_t args;
74 id_table_t locals;81 id_table_t locals;
@@ -195,7 +202,7 @@ namespace · 120 unmodified lines
195 202
196 // header: <magic> '\n' module '\n'203 // header: <magic> '\n' module '\n'
197 // module: <string>204 // module: <string>
198 header_t read_header(util::buffered_reader_t &r)205 header_t read_header(disvm::util::buffered_reader_t &r)
199 {206 {
200 header_t header;207 header_t header;
201 auto v = r.get_as_string_until('\n');208 auto v = r.get_as_string_until('\n');
@@ -213,7 +220,7 @@ namespace · 11 unmodified lines
213 220
214 // file-table: <count> '\n' file*221 // file-table: <count> '\n' file*
215 // file: <string> '\n'222 // file: <string> '\n'
216 file_table_t read_file_table(util::buffered_reader_t &r)223 file_table_t read_file_table(disvm::util::buffered_reader_t &r)
217 {224 {
218 auto count_str = r.get_as_string_until('\n');225 auto count_str = r.get_as_string_until('\n');
219 226
@@ -236,7 +243,7 @@ namespace · 16 unmodified lines
236 // char: <int>243 // char: <int>
237 source_ref_t read_src_entry(const std::string &src_str, sbl_read_context_t &fc)244 source_ref_t read_src_entry(const std::string &src_str, sbl_read_context_t &fc)
238 {245 {
239 auto src_parts = util::split(src_str, ",");246 auto src_parts = disvm::util::split(src_str, ",");
240 if (src_parts.size() != 2)247 if (src_parts.size() != 2)
241 throw std::runtime_error{ "Invalid source item" };248 throw std::runtime_error{ "Invalid source item" };
242 249
@@ -289,7 +296,7 @@ namespace · 46 unmodified lines
289 // pc-table: <count> '\n' pc-item*296 // pc-table: <count> '\n' pc-item*
290 // pc-item: src ' ' stmt '\n'297 // pc-item: src ' ' stmt '\n'
291 // stmt: <int>298 // stmt: <int>
292 pc_table_t read_pc_table(util::buffered_reader_t &r, sbl_read_context_t &fc)299 pc_table_t read_pc_table(disvm::util::buffered_reader_t &r, sbl_read_context_t &fc)
293 {300 {
294 auto count_str = r.get_as_string_until('\n');301 auto count_str = r.get_as_string_until('\n');
295 302
@@ -303,7 +310,7 @@ namespace · 7 unmodified lines
303 {310 {
304 auto item = r.get_as_string_until('\n');311 auto item = r.get_as_string_until('\n');
305 312
306 auto pc_item_parts = util::split(item);313 auto pc_item_parts = disvm::util::split(item);
307 if (pc_item_parts.size() != 2)314 if (pc_item_parts.size() != 2)
308 throw std::runtime_error{ "Invalid PC item" };315 throw std::runtime_error{ "Invalid PC item" };
309 316
@@ -323,13 +330,13 @@ namespace · 13 unmodified lines
323 }330 }
324 331
325 // Forward declaration332 // Forward declaration
326 type_t read_type(util::buffered_reader_t &, type_table_t &, sbl_read_context_t &);333 type_t read_type(disvm::util::buffered_reader_t &, type_table_t &, sbl_read_context_t &);
327 334
328 // id-table: <count> '\n' id-item*335 // id-table: <count> '\n' id-item*
329 // id-item: id-offset ':' id-name ':' src ' ' type '\n'336 // id-item: id-offset ':' id-name ':' src ' ' type '\n'
330 // id-offset: <int>337 // id-offset: <int>
331 // id-name: <string>338 // id-name: <string>
332 id_table_t read_id_table(util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)339 id_table_t read_id_table(disvm::util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)
333 {340 {
334 auto count_str = r.get_as_string_until('\n');341 auto count_str = r.get_as_string_until('\n');
335 int32_t count = std::stoi(count_str);342 int32_t count = std::stoi(count_str);
@@ -376,7 +383,7 @@ namespace · 40 unmodified lines
376 // tag-item: tag-name ':' src ' ' size '\n' id-table383 // tag-item: tag-name ':' src ' ' size '\n' id-table
377 // | tag-name ':' src '\n'384 // | tag-name ':' src '\n'
378 // tag-name: <string>385 // tag-name: <string>
379 name_source_size_t create_name_source_size(std::vector<std::string> &parts, util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)386 name_source_size_t create_name_source_size(std::vector<std::string> &parts, disvm::util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)
380 {387 {
381 assert(parts.size() == 2 || parts.size() == 3);388 assert(parts.size() == 2 || parts.size() == 3);
382 name_source_size_t item;389 name_source_size_t item;
@@ -411,7 +418,7 @@ namespace · 28 unmodified lines
411 // 'f' # Real418 // 'f' # Real
412 // 's' # String419 // 's' # String
413 // type-index: <int>420 // type-index: <int>
414 type_t read_type(util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)421 type_t read_type(disvm::util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)
415 {422 {
416 bool success;423 bool success;
417 uint8_t tc_byte;424 uint8_t tc_byte;
@@ -452,7 +459,7 @@ namespace · 34 unmodified lines
452 case type_class_t::adt_pick:459 case type_class_t::adt_pick:
453 {460 {
454 auto adt_line = r.get_as_string_until('\n');461 auto adt_line = r.get_as_string_until('\n');
455 auto adt_parts = util::split(adt_line);462 auto adt_parts = disvm::util::split(adt_line);
456 if (adt_parts.size() != 3)463 if (adt_parts.size() != 3)
457 throw std::runtime_error{ "Invalid adt item" };464 throw std::runtime_error{ "Invalid adt item" };
458 465
@@ -468,7 +475,7 @@ namespace · 9 unmodified lines
468 for (auto i = 0; i < count; ++i)475 for (auto i = 0; i < count; ++i)
469 {476 {
470 tmp = r.get_as_string_until('\n');477 tmp = r.get_as_string_until('\n');
471 auto tag_parts = util::split(tmp, " :");478 auto tag_parts = disvm::util::split(tmp, " :");
472 if (tag_parts.size() != 2 && tag_parts.size() != 3)479 if (tag_parts.size() != 2 && tag_parts.size() != 3)
473 throw std::runtime_error{ "Invalid tag item" };480 throw std::runtime_error{ "Invalid tag item" };
474 481
@@ -530,7 +537,7 @@ namespace · 55 unmodified lines
530 }537 }
531 538
532 // type-table: <count> '\n' type*539 // type-table: <count> '\n' type*
533 type_table_t read_type_table(util::buffered_reader_t &r, sbl_read_context_t &fc)540 type_table_t read_type_table(disvm::util::buffered_reader_t &r, sbl_read_context_t &fc)
534 {541 {
535 auto count_str = r.get_as_string_until('\n');542 auto count_str = r.get_as_string_until('\n');
536 543
@@ -550,7 +557,7 @@ namespace · 13 unmodified lines
550 // args: id-table557 // args: id-table
551 // locals: id-table558 // locals: id-table
552 // return: type559 // return: type
553 func_table_t read_func_table(util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)560 func_table_t read_func_table(disvm::util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)
554 {561 {
555 auto count_str = r.get_as_string_until('\n');562 auto count_str = r.get_as_string_until('\n');
556 563
@@ -582,7 +589,7 @@ namespace · 25 unmodified lines
582 }589 }
583 590
584 // data-table: id-table591 // data-table: id-table
585 id_table_t read_data_table(util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)592 id_table_t read_data_table(disvm::util::buffered_reader_t &r, type_table_t &tt, sbl_read_context_t &fc)
586 {593 {
587 return read_id_table(r, tt, fc);594 return read_id_table(r, tt, fc);
588 }595 }
@@ -662,11 +669,11 @@ namespace · 73 unmodified lines
662 {669 {
663 std::stringstream ss;670 std::stringstream ss;
664 671
665 const auto inc_name = util::has_flag(fmt, function_name_format_t::name);672 const auto inc_name = disvm::util::has_flag(fmt, function_name_format_t::name);
666 if (inc_name)673 if (inc_name)
667 ss << f.name;674 ss << f.name;
668 675
669 const auto inc_arguments = util::has_flag(fmt, function_name_format_t::arguments);676 const auto inc_arguments = disvm::util::has_flag(fmt, function_name_format_t::arguments);
670 if (inc_arguments)677 if (inc_arguments)
671 {678 {
672 ss << '(';679 ss << '(';
@@ -685,7 +692,7 @@ namespace · 12 unmodified lines
685 }692 }
686 693
687 // Only add the return value if it is not 'none'694 // Only add the return value if it is not 'none'
688 if (util::has_flag(fmt, function_name_format_t::return_type)695 if (disvm::util::has_flag(fmt, function_name_format_t::return_type)
689 && f.return_type.type_class != type_class_t::none)696 && f.return_type.type_class != type_class_t::none)
690 {697 {
691 if (inc_name || inc_arguments)698 if (inc_name || inc_arguments)
@@ -714,9 +721,9 @@ namespace · 22 unmodified lines
714 _current_pc = pc;721 _current_pc = pc;
715 }722 }
716 723
717 bool try_advance_pc(advance_pc_t adv, disvm::runtime::vm_pc_t *pc_after_advance) override724 bool try_advance_pc(advance_pc_t adv, vm_pc_t *pc_after_advance) override
718 {725 {
719 runtime::vm_pc_t new_pc = _current_pc;726 vm_pc_t new_pc = _current_pc;
720 switch (adv)727 switch (adv)
721 {728 {
722 case advance_pc_t::next_debug_statement:729 case advance_pc_t::next_debug_statement:
@@ -738,7 +745,7 @@ namespace · 15 unmodified lines
738 }745 }
739 746
740 case advance_pc_t::next_pc:747 case advance_pc_t::next_pc:
741 if (new_pc + 1 >= static_cast<runtime::vm_pc_t>(_file->pc_table.size()))748 if (new_pc + 1 >= static_cast<vm_pc_t>(_file->pc_table.size()))
742 return false;749 return false;
743 ++new_pc;750 ++new_pc;
744 break;751 break;
@@ -791,7 +798,7 @@ namespace · 46 unmodified lines
791 }798 }
792 799
793 private:800 private:
794 runtime::vm_pc_t _current_pc;801 vm_pc_t _current_pc;
795 std::shared_ptr<const sbl_file_t> _file;802 std::shared_ptr<const sbl_file_t> _file;
796 };803 };
797 804
src/asm/type_signature.cpp+5−1
@@ -9,7 +9,11 @@ · 8 unmodified lines
9#include "rfc1321/global.h"9#include "rfc1321/global.h"
10#include "rfc1321/md5.h"10#include "rfc1321/md5.h"
11 11
12using namespace disvm::assembly::sigkind;12using disvm::assembly::sigkind::sig_stream_t;
13using disvm::assembly::sigkind::Tadt_pick_tag;
14using disvm::assembly::sigkind::Tfixed;
15using disvm::assembly::sigkind::Tm;
16using disvm::assembly::sigkind::Ttype_ref;
13 17
14namespace18namespace
15{19{
src/exec/debugger.cpp+52−24
@@ -18,8 +18,36 @@ · 17 unmodified lines
18#include <exceptions.h>18#include <exceptions.h>
19#include "exec.h"19#include "exec.h"
20 20
21using namespace disvm;21using disvm::vm_t;
22using namespace disvm::runtime;22using disvm::loaded_vm_module_t;
23using disvm::opcode_t;
24
25using disvm::runtime::type_descriptor_t;
26using disvm::runtime::intrinsic_type_desc;
27using disvm::runtime::word_t;
28using disvm::runtime::pointer_t;
29using disvm::runtime::module_id_t;
30using disvm::runtime::runtime_flags_t;
31using disvm::runtime::cookie_t;
32using disvm::runtime::vm_pc_t;
33using disvm::runtime::vm_registers_t;
34using disvm::runtime::vm_module_t;
35using disvm::runtime::vm_module_ref_t;
36using disvm::runtime::vm_alloc_t;
37using disvm::runtime::vm_string_t;
38using disvm::runtime::vm_array_t;
39using disvm::runtime::vm_list_t;
40using disvm::runtime::vm_channel_t;
41using disvm::runtime::vm_thread_state_t;
42using disvm::runtime::vm_trap_flags_t;
43using disvm::runtime::vm_term_request;
44using disvm::runtime::vm_tool_controller_t;
45using disvm::runtime::vm_event_t;
46using disvm::runtime::vm_event_context_t;
47
48using disvm::symbol::function_name_format_t;
49using disvm::symbol::advance_pc_t;
50using disvm::symbol::symbol_data_t;
23 51
24namespace52namespace
25{53{
@@ -146,7 +174,7 @@ namespace · 120 unmodified lines
146 auto msg = std::stringstream{};174 auto msg = std::stringstream{};
147 walk_stack(r, [&msg, &dbg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref)175 walk_stack(r, [&msg, &dbg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref)
148 {176 {
149 auto func_maybe = dbg.resolve_to_function_source_line(module_ref.module->vm_id, pc, pc, symbol::function_name_format_t::name);177 auto func_maybe = dbg.resolve_to_function_source_line(module_ref.module->vm_id, pc, pc, function_name_format_t::name);
150 if (!func_maybe.empty())178 if (!func_maybe.empty())
151 {179 {
152 assert(func_maybe.size() == 1);180 assert(func_maybe.size() == 1);
@@ -507,7 +535,7 @@ namespace · 354 unmodified lines
507 {535 {
508 throw debug_cmd_error_t{ "Invalid module ID" };536 throw debug_cmd_error_t{ "Invalid module ID" };
509 }537 }
510 else if (util::has_flag(module->header.runtime_flag, runtime_flags_t::builtin))538 else if (disvm::util::has_flag(module->header.runtime_flag, runtime_flags_t::builtin))
511 {539 {
512 throw debug_cmd_error_t{ "Unable to set breakpoint in built-in module" };540 throw debug_cmd_error_t{ "Unable to set breakpoint in built-in module" };
513 }541 }
@@ -569,7 +597,7 @@ namespace · 55 unmodified lines
569 << std::setw(16) << details.module->module_name->str()597 << std::setw(16) << details.module->module_name->str()
570 << std::setw(0);598 << std::setw(0);
571 599
572 auto func_maybe = cxt.dbg.resolve_to_function_source_line(details.module->vm_id, details.pc, details.pc, symbol::function_name_format_t::name);600 auto func_maybe = cxt.dbg.resolve_to_function_source_line(details.module->vm_id, details.pc, details.pc, function_name_format_t::name);
573 if (!func_maybe.empty())601 if (!func_maybe.empty())
574 {602 {
575 assert(func_maybe.size() == 1);603 assert(func_maybe.size() == 1);
@@ -720,7 +748,7 @@ namespace · 144 unmodified lines
720 end_pc = std::min(end_maybe, static_cast<int32_t>(code_section.size() - 1));748 end_pc = std::min(end_maybe, static_cast<int32_t>(code_section.size() - 1));
721 }749 }
722 750
723 auto resolved_pc = dbg.resolve_to_function_source_line(r.module_ref->module->vm_id, begin_pc, end_pc, symbol::function_name_format_t::name);751 auto resolved_pc = dbg.resolve_to_function_source_line(r.module_ref->module->vm_id, begin_pc, end_pc, function_name_format_t::name);
724 assert(resolved_pc.empty() || resolved_pc.size() == (end_pc - begin_pc + 1) && "Resolved PCs should have failed or match the PC count");752 assert(resolved_pc.empty() || resolved_pc.size() == (end_pc - begin_pc + 1) && "Resolved PCs should have failed or match the PC count");
725 753
726 auto msg = std::stringstream{};754 auto msg = std::stringstream{};
@@ -817,7 +845,7 @@ namespace · 90 unmodified lines
817 auto value_is_pointer = bool{ false };845 auto value_is_pointer = bool{ false };
818 const auto pointer_offset1 = byte_offset1 / pointer_size;846 const auto pointer_offset1 = byte_offset1 / pointer_size;
819 auto value_to_examine = reinterpret_cast<pointer_t>(base_pointer[pointer_offset1]);847 auto value_to_examine = reinterpret_cast<pointer_t>(base_pointer[pointer_offset1]);
820 if (runtime::is_offset_pointer(*base_type, pointer_offset1))848 if (disvm::runtime::is_offset_pointer(*base_type, pointer_offset1))
821 {849 {
822 value_is_pointer = true;850 value_is_pointer = true;
823 auto alloc_to_examine = vm_alloc_t::from_allocation(value_to_examine);851 auto alloc_to_examine = vm_alloc_t::from_allocation(value_to_examine);
@@ -835,7 +863,7 @@ namespace · 11 unmodified lines
835 863
836 const auto pointer_offset2 = byte_offset2 / pointer_size;864 const auto pointer_offset2 = byte_offset2 / pointer_size;
837 value_to_examine = reinterpret_cast<pointer_t>(base_pointer[pointer_offset2]);865 value_to_examine = reinterpret_cast<pointer_t>(base_pointer[pointer_offset2]);
838 value_is_pointer = runtime::is_offset_pointer(*base_type, pointer_offset2);866 value_is_pointer = disvm::runtime::is_offset_pointer(*base_type, pointer_offset2);
839 }867 }
840 }868 }
841 869
@@ -1022,7 +1050,7 @@ namespace · 180 unmodified lines
1022 1050
1023 void execute_single_command(dbg_cmd_cxt_t &cxt, std::string cmd)1051 void execute_single_command(dbg_cmd_cxt_t &cxt, std::string cmd)
1024 {1052 {
1025 const auto cmd_tokens = util::split(cmd);1053 const auto cmd_tokens = disvm::util::split(cmd);
1026 if (cmd_tokens.empty())1054 if (cmd_tokens.empty())
1027 return;1055 return;
1028 1056
@@ -1081,9 +1109,9 @@ namespace · 52 unmodified lines
1081 1109
1082std::ostream& operator<<(std::ostream &ss, const debugger_options o)1110std::ostream& operator<<(std::ostream &ss, const debugger_options o)
1083{1111{
1084 ss << "Break on enter: " << std::boolalpha << util::has_flag(o, debugger_options::break_on_enter) << "\n"1112 ss << "Break on enter: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_enter) << "\n"
1085 << "Break on module load: " << std::boolalpha << util::has_flag(o, debugger_options::break_on_module_load) << "\n"1113 << "Break on module load: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_module_load) << "\n"
1086 << "Break on exception: " << std::boolalpha << util::has_flag(o, debugger_options::break_on_exception) << "\n";1114 << "Break on exception: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_exception) << "\n";
1087 1115
1088 return ss;1116 return ss;
1089}1117}
@@ -1096,10 +1124,10 @@ debugger::debugger(const debugger_options opt) · 6 unmodified lines
1096{ }1124{ }
1097 1125
1098std::vector<std::string> debugger::resolve_to_function_source_line(1126std::vector<std::string> debugger::resolve_to_function_source_line(
1099 disvm::runtime::module_id_t vm_id,1127 module_id_t vm_id,
1100 vm_pc_t begin_pc,1128 vm_pc_t begin_pc,
1101 vm_pc_t end_pc,1129 vm_pc_t end_pc,
1102 symbol::function_name_format_t fmt) const1130 function_name_format_t fmt) const
1103{1131{
1104 auto iter = _vm_id_to_symbol_info.find(vm_id);1132 auto iter = _vm_id_to_symbol_info.find(vm_id);
1105 if (iter == std::cend(_vm_id_to_symbol_info))1133 if (iter == std::cend(_vm_id_to_symbol_info))
@@ -1129,18 +1157,18 @@ std::vector<std::string> debugger::resolve_to_function_source_line( · 23 unmodified lines
1129 1157
1130 resolved_functions_by_pc[next_pc - begin_pc] = std::move(ss.str());1158 resolved_functions_by_pc[next_pc - begin_pc] = std::move(ss.str());
1131 1159
1132 } while (d.try_advance_pc(symbol::advance_pc_t::next_debug_statement, &next_pc));1160 } while (d.try_advance_pc(advance_pc_t::next_debug_statement, &next_pc));
1133 1161
1134 return resolved_functions_by_pc;1162 return resolved_functions_by_pc;
1135}1163}
1136 1164
1137std::vector<std::string> debugger::get_module_functions(disvm::runtime::module_id_t vm_id, const char *match) const1165std::vector<std::string> debugger::get_module_functions(module_id_t vm_id, const char *match) const
1138{1166{
1139 std::vector<std::string> funcs;1167 std::vector<std::string> funcs;
1140 auto iter = _vm_id_to_symbol_info.find(vm_id);1168 auto iter = _vm_id_to_symbol_info.find(vm_id);
1141 if (iter != std::cend(_vm_id_to_symbol_info))1169 if (iter != std::cend(_vm_id_to_symbol_info))
1142 {1170 {
1143 auto f_infos = iter->second.data->get_functions(symbol::function_name_format_t::declaration);1171 auto f_infos = iter->second.data->get_functions(function_name_format_t::declaration);
1144 for (auto &fi : f_infos)1172 for (auto &fi : f_infos)
1145 {1173 {
1146 // Only return functions that match the supplied string1174 // Only return functions that match the supplied string
@@ -1163,7 +1191,7 @@ std::vector<std::string> debugger::get_module_functions(disvm::runtime::module_i · 16 unmodified lines
1163 return funcs;1191 return funcs;
1164}1192}
1165 1193
1166bool debugger::symbols_exist(disvm::runtime::module_id_t vm_id) const1194bool debugger::symbols_exist(module_id_t vm_id) const
1167{1195{
1168 return _vm_id_to_symbol_info.find(vm_id) != std::cend(_vm_id_to_symbol_info);1196 return _vm_id_to_symbol_info.find(vm_id) != std::cend(_vm_id_to_symbol_info);
1169}1197}
@@ -1220,7 +1248,7 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 50 unmodified lines
1220 1248
1221 debug_print_info(ss.str());1249 debug_print_info(ss.str());
1222 1250
1223 if (util::has_flag(_options, debugger_options::break_on_exception))1251 if (disvm::util::has_flag(_options, debugger_options::break_on_exception))
1224 prompt(*this, *cxt.value1.registers);1252 prompt(*this, *cxt.value1.registers);
1225 }));1253 }));
1226 1254
@@ -1250,14 +1278,14 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 23 unmodified lines
1250 << m->module_name->str()1278 << m->module_name->str()
1251 << " loaded";1279 << " loaded";
1252 1280
1253 if (util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin))1281 if (disvm::util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin))
1254 ss << " (built-in)";1282 ss << " (built-in)";
1255 1283
1256 debug_print_info(ss.str());1284 debug_print_info(ss.str());
1257 1285
1258 // If the break on enter flag was set, it will be true1286 // If the break on enter flag was set, it will be true
1259 // and the first module load will be the user entry module.1287 // and the first module load will be the user entry module.
1260 if (util::has_flag(_options, debugger_options::break_on_enter))1288 if (disvm::util::has_flag(_options, debugger_options::break_on_enter))
1261 {1289 {
1262 // Reset the break on enter flag and set a breakpoint1290 // Reset the break on enter flag and set a breakpoint
1263 // on the entry PC for the module - 'break on enter'1291 // on the entry PC for the module - 'break on enter'
@@ -1265,7 +1293,7 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 1 unmodified line
1265 breakpoint_cookies.emplace(controller->set_breakpoint(m, m->header.entry_pc));1293 breakpoint_cookies.emplace(controller->set_breakpoint(m, m->header.entry_pc));
1266 }1294 }
1267 1295
1268 if (util::has_flag(_options, debugger_options::break_on_module_load))1296 if (disvm::util::has_flag(_options, debugger_options::break_on_module_load))
1269 prompt(*this, *cxt.value1.registers);1297 prompt(*this, *cxt.value1.registers);
1270 }));1298 }));
1271 1299
@@ -1334,10 +1362,10 @@ void debugger::load_symbols(const disvm::loaded_vm_module_t &loaded_mod) · 62 unmodified lines
1334 if (!sbl_file.is_open())1362 if (!sbl_file.is_open())
1335 return;1363 return;
1336 1364
1337 std::unique_ptr<symbol::symbol_data_t> symbol_data;1365 std::unique_ptr<symbol_data_t> symbol_data;
1338 try1366 try
1339 {1367 {
1340 symbol_data = symbol::read(sbl_file);1368 symbol_data = disvm::symbol::read(sbl_file);
1341 }1369 }
1342 catch (const std::runtime_error &e)1370 catch (const std::runtime_error &e)
1343 {1371 {
src/exec/main.cpp+50−21
@@ -15,9 +15,38 @@ · 14 unmodified lines
15#include <vm_version.h>15#include <vm_version.h>
16#include "exec.h"16#include "exec.h"
17 17
18using namespace disvm;18using disvm::vm_t;
19using namespace disvm::runtime;19using disvm::vm_config_t;
20using namespace disvm::assembly::sigkind;20using disvm::opcode_t;
21
22using disvm::assembly::sigkind::sig_stream_t;
23using disvm::assembly::sigkind::Tfunction;
24using disvm::assembly::sigkind::Tlist;
25using disvm::assembly::sigkind::Tstring;
26using disvm::assembly::sigkind::Tnone;
27
28using disvm::debug::component_trace_t;
29using disvm::debug::log_level_t;
30
31using disvm::runtime::type_descriptor_t;
32using disvm::runtime::intrinsic_type_desc;
33using disvm::runtime::byte_t;
34using disvm::runtime::word_t;
35using disvm::runtime::pointer_t;
36using disvm::runtime::runtime_flags_t;
37using disvm::runtime::vm_module_t;
38using disvm::runtime::vm_alloc_t;
39using disvm::runtime::vm_string_t;
40using disvm::runtime::vm_list_t;
41using disvm::runtime::vm_frame_base_alloc_t;
42using disvm::runtime::vm_frame_constants;
43using disvm::runtime::vm_exec_op_t;
44using disvm::runtime::address_mode_t;
45using disvm::runtime::address_mode_middle_t;
46using disvm::runtime::import_function_t;
47using disvm::runtime::import_vm_module_t;
48using disvm::runtime::vm_user_exception;
49using disvm::runtime::vm_system_exception;
21 50
22namespace51namespace
23{52{
@@ -62,7 +91,7 @@ namespace · 38 unmodified lines
62 last = new_tail;91 last = new_tail;
63 }92 }
64 93
65 pt_ref(last->value()) = curr_arg->get_allocation();94 disvm::runtime::pt_ref(last->value()) = curr_arg->get_allocation();
66 }95 }
67 96
68 if (command_module_path == nullptr)97 if (command_module_path == nullptr)
@@ -107,7 +136,7 @@ namespace · 38 unmodified lines
107 { vm_exec_op_t136 { vm_exec_op_t
108 {137 {
109 opcode_t::load,138 opcode_t::load,
110 assembly::construct_address_code(address_mode_t::offset_indirect_mp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),139 disvm::assembly::construct_address_code(address_mode_t::offset_indirect_mp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),
111 { address_mode_t::offset_indirect_mp, 0, 0 }, // command module path140 { address_mode_t::offset_indirect_mp, 0, 0 }, // command module path
112 { address_mode_middle_t::small_immediate, 0 }, // import table index141 { address_mode_middle_t::small_immediate, 0 }, // import table index
113 { address_mode_t::offset_indirect_fp, 20, 0 } // module reference142 { address_mode_t::offset_indirect_fp, 20, 0 } // module reference
@@ -116,7 +145,7 @@ namespace · 2 unmodified lines
116 { vm_exec_op_t145 { vm_exec_op_t
117 {146 {
118 opcode_t::mframe,147 opcode_t::mframe,
119 assembly::construct_address_code(address_mode_t::offset_indirect_fp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),148 disvm::assembly::construct_address_code(address_mode_t::offset_indirect_fp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),
120 { address_mode_t::offset_indirect_fp, 20, 0 }, // module reference149 { address_mode_t::offset_indirect_fp, 20, 0 }, // module reference
121 { address_mode_middle_t::small_immediate, 0 }, // function index into module150 { address_mode_middle_t::small_immediate, 0 }, // function index into module
122 { address_mode_t::offset_indirect_fp, 24, 0 } // module call frame151 { address_mode_t::offset_indirect_fp, 24, 0 } // module call frame
@@ -125,7 +154,7 @@ namespace · 2 unmodified lines
125 { vm_exec_op_t154 { vm_exec_op_t
126 {155 {
127 opcode_t::movp,156 opcode_t::movp,
128 assembly::construct_address_code(address_mode_t::offset_indirect_mp, address_mode_middle_t::none, address_mode_t::offset_double_indirect_fp),157 disvm::assembly::construct_address_code(address_mode_t::offset_indirect_mp, address_mode_middle_t::none, address_mode_t::offset_double_indirect_fp),
129 { address_mode_t::offset_indirect_mp, 4, 0 }, // Argument list158 { address_mode_t::offset_indirect_mp, 4, 0 }, // Argument list
130 { address_mode_middle_t::none },159 { address_mode_middle_t::none },
131 { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> argument list offset160 { address_mode_t::offset_double_indirect_fp, 24, first_arg_offset } // module call frame -> argument list offset
@@ -134,7 +163,7 @@ namespace · 2 unmodified lines
134 { vm_exec_op_t163 { vm_exec_op_t
135 {164 {
136 opcode_t::mcall,165 opcode_t::mcall,
137 assembly::construct_address_code(address_mode_t::offset_indirect_fp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),166 disvm::assembly::construct_address_code(address_mode_t::offset_indirect_fp, address_mode_middle_t::small_immediate, address_mode_t::offset_indirect_fp),
138 { address_mode_t::offset_indirect_fp, 24, 0 }, // module call frame167 { address_mode_t::offset_indirect_fp, 24, 0 }, // module call frame
139 { address_mode_middle_t::small_immediate, 0 }, // function index into module168 { address_mode_middle_t::small_immediate, 0 }, // function index into module
140 { address_mode_t::offset_indirect_fp, 20, 0 } // module reference169 { address_mode_t::offset_indirect_fp, 20, 0 } // module reference
@@ -143,7 +172,7 @@ namespace · 2 unmodified lines
143 { vm_exec_op_t172 { vm_exec_op_t
144 {173 {
145 opcode_t::ret,174 opcode_t::ret,
146 assembly::construct_address_code(address_mode_t::none, address_mode_middle_t::none, address_mode_t::none),175 disvm::assembly::construct_address_code(address_mode_t::none, address_mode_middle_t::none, address_mode_t::none),
147 { address_mode_t::none },176 { address_mode_t::none },
148 { address_mode_middle_t::none },177 { address_mode_middle_t::none },
149 { address_mode_t::none }178 { address_mode_t::none }
@@ -248,16 +277,16 @@ void print_help() · 98 unmodified lines
248 " h - Print help (alternative: '?')\n";277 " h - Print help (alternative: '?')\n";
249}278}
250 279
251void log_callback(const debug::component_trace_t origin, const debug::log_level_t level, const char *msg_fmt, std::va_list args)280void log_callback(const component_trace_t origin, const log_level_t level, const char *msg_fmt, std::va_list args)
252{281{
253 std::stringstream ss;282 std::stringstream ss;
254 283
255 switch (level)284 switch (level)
256 {285 {
257 case debug::log_level_t::warning:286 case log_level_t::warning:
258 ss << "w: ";287 ss << "w: ";
259 break;288 break;
260 case debug::log_level_t::debug:289 case log_level_t::debug:
261 ss << "d: ";290 ss << "d: ";
262 break;291 break;
263 }292 }
@@ -323,26 +352,26 @@ void process_arg(char* arg, std::function<char *()> next, exec_options &options) · 59 unmodified lines
323 352
324 case 'l':353 case 'l':
325 // Set the callback354 // Set the callback
326 debug::set_logging_callback(log_callback);355 disvm::debug::set_logging_callback(log_callback);
327 for (auto i = std::size_t{ 2 }; i < arg_len; ++i)356 for (auto i = std::size_t{ 2 }; i < arg_len; ++i)
328 {357 {
329 switch (arg[i])358 switch (arg[i])
330 {359 {
331 case 's': debug::set_component_tracing(debug::component_trace_t::scheduler, true);360 case 's': disvm::debug::set_component_tracing(component_trace_t::scheduler, true);
332 break;361 break;
333 case 'S': debug::set_component_tracing(debug::component_trace_t::stack, true);362 case 'S': disvm::debug::set_component_tracing(component_trace_t::stack, true);
334 break;363 break;
335 case 't': debug::set_component_tracing(debug::component_trace_t::thread, true);364 case 't': disvm::debug::set_component_tracing(component_trace_t::thread, true);
336 break;365 break;
337 case 'T': debug::set_component_tracing(debug::component_trace_t::tool, true);366 case 'T': disvm::debug::set_component_tracing(component_trace_t::tool, true);
338 break;367 break;
339 case 'e': debug::set_component_tracing(debug::component_trace_t::exception, true);368 case 'e': disvm::debug::set_component_tracing(component_trace_t::exception, true);
340 break;369 break;
341 case 'g': debug::set_component_tracing(debug::component_trace_t::garbage_collector, true);370 case 'g': disvm::debug::set_component_tracing(component_trace_t::garbage_collector, true);
342 break;371 break;
343 case 'm': debug::set_component_tracing(debug::component_trace_t::memory, true);372 case 'm': disvm::debug::set_component_tracing(component_trace_t::memory, true);
344 break;373 break;
345 case 'd': debug::set_component_tracing(debug::component_trace_t::duration, true);374 case 'd': disvm::debug::set_component_tracing(component_trace_t::duration, true);
346 break;375 break;
347 }376 }
348 }377 }
src/include/runtime.h+15−15
@@ -519,30 +519,30 @@ namespace disvm · 518 unmodified lines
519 };519 };
520 520
521 // Exception entry for handler521 // Exception entry for handler
522 struct exception_t522 struct exception_entry_t
523 {523 {
524 exception_t() = default;524 exception_entry_t() = default;
525 exception_t(exception_t &&);525 exception_entry_t(exception_entry_t &&);
526 526
527 exception_t(const exception_t &) = delete;527 exception_entry_t(const exception_entry_t &) = delete;
528 exception_t &operator=(const exception_t &) = delete;528 exception_entry_t &operator=(const exception_entry_t &) = delete;
529 529
530 ~exception_t();530 ~exception_entry_t();
531 531
532 vm_pc_t pc;532 vm_pc_t pc;
533 std::unique_ptr<vm_string_t> name;533 std::unique_ptr<vm_string_t> name;
534 };534 };
535 535
536 // Exception handler536 // Exception handler
537 struct handler_t537 struct handler_entry_t
538 {538 {
539 handler_t() = default;539 handler_entry_t() = default;
540 handler_t(handler_t &&);540 handler_entry_t(handler_entry_t &&);
541 541
542 handler_t(const handler_t &) = delete;542 handler_entry_t(const handler_entry_t &) = delete;
543 handler_t &operator=(const handler_t &) = delete;543 handler_entry_t &operator=(const handler_entry_t &) = delete;
544 544
545 ~handler_t() = default;545 ~handler_entry_t() = default;
546 546
547 // Byte offset in the handling frame the exception should be placed.547 // Byte offset in the handling frame the exception should be placed.
548 word_t exception_offset;548 word_t exception_offset;
@@ -554,14 +554,14 @@ namespace disvm · 5 unmodified lines
554 word_t exception_type_count;554 word_t exception_type_count;
555 555
556 std::shared_ptr<const type_descriptor_t> type_desc;556 std::shared_ptr<const type_descriptor_t> type_desc;
557 std::vector<exception_t> exception_table;557 std::vector<exception_entry_t> exception_table;
558 };558 };
559 559
560 using code_section_t = std::vector<vm_instruction_t>;560 using code_section_t = std::vector<vm_instruction_t>;
561 using type_section_map_t = std::vector<std::shared_ptr<const type_descriptor_t>>;561 using type_section_map_t = std::vector<std::shared_ptr<const type_descriptor_t>>;
562 using export_section_t = std::unordered_multimap<word_t, const export_function_t>;562 using export_section_t = std::unordered_multimap<word_t, const export_function_t>;
563 using import_section_t = std::vector<import_vm_module_t>;563 using import_section_t = std::vector<import_vm_module_t>;
564 using handler_section_t = std::vector<handler_t>;564 using handler_section_t = std::vector<handler_entry_t>;
565 565
566 using module_id_t = std::size_t;566 using module_id_t = std::size_t;
567 567
@@ -696,7 +696,7 @@ namespace disvm · 128 unmodified lines
696 696
697 // Walk the supplied stack and faulting module find the handler, handling stack frame, and program counter for the supplied exception ID.697 // Walk the supplied stack and faulting module find the handler, handling stack frame, and program counter for the supplied exception ID.
698 // If an exception handler cannot be found, {null, null, invalid_program_counter} will be returned.698 // If an exception handler cannot be found, {null, null, invalid_program_counter} will be returned.
699 std::tuple<const handler_t *, vm_frame_t *, vm_pc_t> find_exception_handler(699 std::tuple<const handler_entry_t *, vm_frame_t *, vm_pc_t> find_exception_handler(
700 const vm_stack_t &stack,700 const vm_stack_t &stack,
701 const vm_module_ref_t &faulting_module,701 const vm_module_ref_t &faulting_module,
702 const vm_pc_t faulting_pc,702 const vm_pc_t faulting_pc,
src/vm/array.cpp+19−11
@@ -9,8 +9,16 @@ · 8 unmodified lines
9#include <debug.h>9#include <debug.h>
10#include <exceptions.h>10#include <exceptions.h>
11 11
12using namespace disvm;12using disvm::debug::component_trace_t;
13using namespace disvm::runtime;13using disvm::debug::log_level_t;
14
15using disvm::runtime::intrinsic_type_desc;
16using disvm::runtime::pointer_t;
17using disvm::runtime::type_descriptor_t;
18using disvm::runtime::vm_alloc_t;
19using disvm::runtime::vm_array_t;
20using disvm::runtime::vm_string_t;
21using disvm::runtime::word_t;
14 22
15std::shared_ptr<const type_descriptor_t> vm_array_t::type_desc()23std::shared_ptr<const type_descriptor_t> vm_array_t::type_desc()
16{24{
@@ -27,7 +35,7 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t lengt · 10 unmodified lines
27 assert(_element_type != nullptr);35 assert(_element_type != nullptr);
28 assert(_length >= 0);36 assert(_length >= 0);
29 _arr = alloc_memory<byte_t>(_length * _element_type->size_in_bytes);37 _arr = alloc_memory<byte_t>(_length * _element_type->size_in_bytes);
30 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: %d", _length);38 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm array: %d", _length);
31 39
32 // [SPEC] Element memory is already initialized to zero based on the alloc_memory contract40 // [SPEC] Element memory is already initialized to zero based on the alloc_memory contract
33}41}
@@ -41,8 +49,8 @@ vm_array_t::vm_array_t(vm_array_t &original, word_t begin_index, word_t length) · 7 unmodified lines
41{49{
42 assert(0 <= begin_index && (begin_index < _original->get_length() || (begin_index == _original->get_length() && length == 0)));50 assert(0 <= begin_index && (begin_index < _original->get_length() || (begin_index == _original->get_length() && length == 0)));
43 51
44 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())52 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
45 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length);53 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length);
46 54
47 // Set the data to reference the original array55 // Set the data to reference the original array
48 _arr = _original->_arr + (begin_index * _element_type->size_in_bytes);56 _arr = _original->_arr + (begin_index * _element_type->size_in_bytes);
@@ -77,8 +85,8 @@ vm_array_t::vm_array_t(const vm_string_t *s) · 28 unmodified lines
77 std::memcpy(_arr, str, _length);85 std::memcpy(_arr, str, _length);
78 }86 }
79 87
80 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())88 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
81 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: vm string: %d", _length);89 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm array: vm string: %d", _length);
82}90}
83 91
84vm_array_t::~vm_array_t()92vm_array_t::~vm_array_t()
@@ -92,7 +100,7 @@ vm_array_t::~vm_array_t() · 7 unmodified lines
92 dec_ref_count_and_free(_original);100 dec_ref_count_and_free(_original);
93 debug::assign_debug_pointer(&_original);101 debug::assign_debug_pointer(&_original);
94 102
95 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm array: slice");103 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm array: slice");
96 }104 }
97 else105 else
98 {106 {
@@ -100,19 +108,19 @@ vm_array_t::~vm_array_t() · 1 unmodified line
100 auto arr_local = _arr;108 auto arr_local = _arr;
101 const auto array_len = _length;109 const auto array_len = _length;
102 const auto &element_type = *_element_type;110 const auto &element_type = *_element_type;
103 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "begin: destroy: elements: %d", array_len);111 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "begin: destroy: elements: %d", array_len);
104 for (word_t i = 0; i < array_len; ++i)112 for (word_t i = 0; i < array_len; ++i)
105 {113 {
106 destroy_memory(element_type, arr_local);114 destroy_memory(element_type, arr_local);
107 arr_local += element_type.size_in_bytes;115 arr_local += element_type.size_in_bytes;
108 }116 }
109 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: destroy: elements: %d", array_len);117 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "end: destroy: elements: %d", array_len);
110 118
111 // Free array memory119 // Free array memory
112 free_memory(_arr);120 free_memory(_arr);
113 121
114 debug::assign_debug_pointer(&_arr);122 debug::assign_debug_pointer(&_arr);
115 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm array");123 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm array");
116 }124 }
117 125
118}126}
src/vm/builtin_module.cpp+2−2
@@ -14,8 +14,8 @@ · 13 unmodified lines
14#include <debug.h>14#include <debug.h>
15#include <exceptions.h>15#include <exceptions.h>
16 16
17using namespace disvm::runtime;17using disvm::runtime::type_descriptor_t;
18using namespace disvm::runtime::builtin;18using disvm::runtime::vm_module_t;
19 19
20namespace20namespace
21{21{
src/vm/channel.cpp+27−18
@@ -9,8 +9,17 @@ · 8 unmodified lines
9#include <debug.h>9#include <debug.h>
10#include <exceptions.h>10#include <exceptions.h>
11 11
12using namespace disvm;12using disvm::debug::component_trace_t;
13using namespace disvm::runtime;13using disvm::debug::log_level_t;
14
15using disvm::runtime::intrinsic_type_desc;
16using disvm::runtime::type_descriptor_t;
17using disvm::runtime::vm_alloc_t;
18using disvm::runtime::vm_array_t;
19using disvm::runtime::vm_channel_t;
20using disvm::runtime::vm_channel_request_t;
21using disvm::runtime::vm_request_mutex_t;
22using disvm::runtime::word_t;
14 23
15vm_request_mutex_t::vm_request_mutex_t()24vm_request_mutex_t::vm_request_mutex_t()
16 : pending_request{ false }25 : pending_request{ false }
@@ -44,13 +53,13 @@ vm_channel_t::vm_channel_t( · 27 unmodified lines
44 if (buffer_len > 0)53 if (buffer_len > 0)
45 _data_buffer = new vm_array_t{ td, buffer_len };54 _data_buffer = new vm_array_t{ td, buffer_len };
46 55
47 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm channel");56 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm channel");
48}57}
49 58
50vm_channel_t::~vm_channel_t()59vm_channel_t::~vm_channel_t()
51{60{
52 dec_ref_count_and_free(_data_buffer);61 dec_ref_count_and_free(_data_buffer);
53 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm channel");62 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm channel");
54}63}
55 64
56std::shared_ptr<const type_descriptor_t> vm_channel_t::get_data_type() const65std::shared_ptr<const type_descriptor_t> vm_channel_t::get_data_type() const
@@ -87,8 +96,8 @@ bool vm_channel_t::send_data(vm_channel_request_t &send_request) · 30 unmodified lines
87 return true;96 return true;
88 }97 }
89 98
90 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())99 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
91 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: send: queue: %d", send_request.thread_id);100 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: send: queue: %d", send_request.thread_id);
92 101
93 _data_senders.emplace_back(std::move(send_request));102 _data_senders.emplace_back(std::move(send_request));
94 return false;103 return false;
@@ -121,8 +130,8 @@ bool vm_channel_t::send_data(vm_channel_request_t &send_request) · 26 unmodified lines
121 pending_req_lock.unlock();130 pending_req_lock.unlock();
122 data_lock.unlock();131 data_lock.unlock();
123 132
124 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())133 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
125 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: send: %d %d", send_request.thread_id, receiver.thread_id);134 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: send: %d %d", send_request.thread_id, receiver.thread_id);
126 135
127 receiver.request_handled_callback(*this);136 receiver.request_handled_callback(*this);
128 137
@@ -158,8 +167,8 @@ bool vm_channel_t::receive_data(vm_channel_request_t &receive_request) · 29 unmodified lines
158 return true;167 return true;
159 }168 }
160 169
161 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())170 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
162 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: receive: queue: %d", receive_request.thread_id);171 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: receive: queue: %d", receive_request.thread_id);
163 172
164 _data_receivers.emplace_back(std::move(receive_request));173 _data_receivers.emplace_back(std::move(receive_request));
165 return false;174 return false;
@@ -200,8 +209,8 @@ bool vm_channel_t::receive_data(vm_channel_request_t &receive_request) · 34 unmodified lines
200 // Transfer data since there wasn't anything in the buffer209 // Transfer data since there wasn't anything in the buffer
201 _data_transfer(receive_request.data, sender.data, _data_type.get());210 _data_transfer(receive_request.data, sender.data, _data_type.get());
202 211
203 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())212 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
204 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: receive: %d %d", receive_request.thread_id, sender.thread_id);213 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: receive: %d %d", receive_request.thread_id, sender.thread_id);
205 }214 }
206 215
207 // Release channel and pending request lock after data transfer216 // Release channel and pending request lock after data transfer
@@ -234,8 +243,8 @@ void vm_channel_t::cancel_request(uint32_t thread_id) · 26 unmodified lines
234 _data_senders.erase(sender_iter);243 _data_senders.erase(sender_iter);
235 }244 }
236 245
237 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())246 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
238 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: cancel: request: %d", thread_id);247 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: cancel: request: %d", thread_id);
239}248}
240 249
241word_t vm_channel_t::get_buffer_size() const250word_t vm_channel_t::get_buffer_size() const
@@ -266,8 +275,8 @@ bool vm_channel_t::try_send_to_buffer(vm_channel_request_t &send_request) · 24 unmodified lines
266 _data_transfer(dest, send_request.data, _data_type.get());275 _data_transfer(dest, send_request.data, _data_type.get());
267 send_request.request_mutex.get().pending_request = false;276 send_request.request_mutex.get().pending_request = false;
268 277
269 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())278 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
270 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: send: buffer: %d", send_request.thread_id);279 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: send: buffer: %d", send_request.thread_id);
271 280
272 return true;281 return true;
273}282}
@@ -293,8 +302,8 @@ bool vm_channel_t::try_receive_from_buffer(vm_channel_request_t &receive_request · 19 unmodified lines
293 302
294 receive_request.request_mutex.get().pending_request = false;303 receive_request.request_mutex.get().pending_request = false;
295 304
296 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())305 if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>())
297 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: receive: buffer: %d", receive_request.thread_id);306 disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: receive: buffer: %d", receive_request.thread_id);
298 307
299 return true;308 return true;
300}309}
src/vm/execution_table.cpp+13−13
@@ -1286,8 +1286,8 @@ namespace · 1285 unmodified lines
1286 {1286 {
1287 r.request_mutex.pending_request = false;1287 r.request_mutex.pending_request = false;
1288 1288
1289 if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>())1289 if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::channel>())
1290 debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "alt: request: non-blocking");1290 disvm::debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "alt: request: non-blocking");
1291 1291
1292 // Cancel request in all channels.1292 // Cancel request in all channels.
1293 for (auto i = word_t{ 0 }; i < channel_count; ++i)1293 for (auto i = word_t{ 0 }; i < channel_count; ++i)
@@ -1482,8 +1482,8 @@ namespace · 188 unmodified lines
1482 if (new_frame == nullptr)1482 if (new_frame == nullptr)
1483 r.current_thread_state = vm_thread_state_t::empty_stack;1483 r.current_thread_state = vm_thread_state_t::empty_stack;
1484 1484
1485 if (debug::is_component_tracing_enabled<debug::component_trace_t::stack>())1485 if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::stack>())
1486 debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "exit: function");1486 disvm::debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "exit: function");
1487 }1487 }
1488 1488
1489 EXEC_DECL(call)1489 EXEC_DECL(call)
@@ -1500,7 +1500,7 @@ namespace · 10 unmodified lines
1500 1500
1501 r.next_pc = vt_ref<vm_pc_t>(r.dest);1501 r.next_pc = vt_ref<vm_pc_t>(r.dest);
1502 1502
1503 debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "enter: function");1503 disvm::debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "enter: function");
1504 }1504 }
1505 1505
1506 EXEC_DECL(mcall)1506 EXEC_DECL(mcall)
@@ -1529,9 +1529,9 @@ namespace · 22 unmodified lines
1529 top_frame->prev_pc() = r.next_pc;1529 top_frame->prev_pc() = r.next_pc;
1530 top_frame->prev_module_ref() = r.module_ref;1530 top_frame->prev_module_ref() = r.module_ref;
1531 1531
1532 if (debug::is_component_tracing_enabled<debug::component_trace_t::stack>())1532 if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::stack>())
1533 {1533 {
1534 debug::log_msg(1534 disvm::debug::log_msg(
1535 debug::component_trace_t::stack,1535 debug::component_trace_t::stack,
1536 debug::log_level_t::debug,1536 debug::log_level_t::debug,
1537 "enter: function: inter-module: %d >>%s<< %d %s",1537 "enter: function: inter-module: %d >>%s<< %d %s",
@@ -1660,8 +1660,8 @@ namespace · 122 unmodified lines
1660 // String1660 // String
1661 exception_id = static_cast<vm_string_t *>(e);1661 exception_id = static_cast<vm_string_t *>(e);
1662 1662
1663 if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>())1663 if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::exception>())
1664 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<", exception_id->str());1664 disvm::debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<", exception_id->str());
1665 }1665 }
1666 else1666 else
1667 {1667 {
@@ -1673,8 +1673,8 @@ namespace · 5 unmodified lines
1673 exception_id = at_val<vm_string_t>(content);1673 exception_id = at_val<vm_string_t>(content);
1674 assert(exception_id != nullptr);1674 assert(exception_id != nullptr);
1675 1675
1676 if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>())1676 if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::exception>())
1677 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: exception: >>%s<<", exception_id->str());1677 disvm::debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: exception: >>%s<<", exception_id->str());
1678 }1678 }
1679 1679
1680 // Check if the tool dispatcher has been supplied1680 // Check if the tool dispatcher has been supplied
@@ -1682,7 +1682,7 @@ namespace · 1 unmodified line
1682 if (tool_dispatch != nullptr)1682 if (tool_dispatch != nullptr)
1683 tool_dispatch->on_exception_raised(r, *exception_id, *e);1683 tool_dispatch->on_exception_raised(r, *exception_id, *e);
1684 1684
1685 const handler_t *handler;1685 const handler_entry_t *handler;
1686 vm_frame_t *target_frame;1686 vm_frame_t *target_frame;
1687 vm_pc_t handler_pc;1687 vm_pc_t handler_pc;
1688 1688
@@ -1783,7 +1783,7 @@ namespace · 94 unmodified lines
1783 }1783 }
1784 catch (const vm_module_exception &e)1784 catch (const vm_module_exception &e)
1785 {1785 {
1786 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "exception: load: >>%s<<", e.what());1786 disvm::debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "exception: load: >>%s<<", e.what());
1787 return;1787 return;
1788 }1788 }
1789 }1789 }
src/vm/garbage_collector.cpp+78−64
@@ -12,8 +12,22 @@ · 11 unmodified lines
12#include <exceptions.h>12#include <exceptions.h>
13#include "garbage_collector.h"13#include "garbage_collector.h"
14 14
15using namespace disvm;15using disvm::vm_t;
16using namespace disvm::runtime;16
17using disvm::debug::component_trace_t;
18using disvm::debug::log_level_t;
19
20using disvm::runtime::default_garbage_collector_t;
21using disvm::runtime::intrinsic_type_desc;
22using disvm::runtime::pointer_t;
23using disvm::runtime::type_descriptor_t;
24using disvm::runtime::vm_alloc_t;
25using disvm::runtime::vm_alloc_callback_t;
26using disvm::runtime::vm_garbage_collector_t;
27using disvm::runtime::vm_memory_allocator_t;
28using disvm::runtime::vm_string_t;
29using disvm::runtime::vm_thread_t;
30using disvm::runtime::vm_tool_controller_t;
17 31
18// Empty destructors for vm garbage collector 'interfaces'32// Empty destructors for vm garbage collector 'interfaces'
19vm_garbage_collector_t::~vm_garbage_collector_t()33vm_garbage_collector_t::~vm_garbage_collector_t()
@@ -47,19 +61,6 @@ std::unique_ptr<vm_garbage_collector_t> disvm::runtime::create_no_op_gc(vm_t &) · 27 unmodified lines
47 return std::make_unique<no_op_gc>();61 return std::make_unique<no_op_gc>();
48}62}
49 63
50default_garbage_collector_t::default_garbage_collector_t(vm_t &vm)
51 : _collection_epoch{ 0 }
52 , _vm{ vm }
53{
54}
55
56default_garbage_collector_t::~default_garbage_collector_t()
57{
58 std::lock_guard<std::mutex> lock{ _tracking_allocs_lock };
59 for (auto a : _tracking_allocs)
60 dec_ref_count_and_free(a);
61}
62
63namespace64namespace
64{65{
65 enum class gc_colour_t66 enum class gc_colour_t
@@ -91,6 +92,42 @@ namespace · 25 unmodified lines
91 {92 {
92 a->gc_reserved = reinterpret_cast<pointer_t>(c);93 a->gc_reserved = reinterpret_cast<pointer_t>(c);
93 }94 }
95
96 class mark_cxt_t final : public std::stack<vm_alloc_t *, std::vector<vm_alloc_t *>>
97 {
98 public:
99 mark_cxt_t()
100 : string_type{ intrinsic_type_desc::type<vm_string_t>().get() } // Using raw pointer since it is a built-in type and has unlimited lifetime
101 , curr_colour{ gc_colour_t::white }
102 { }
103
104 const type_descriptor_t *string_type;
105 gc_colour_t curr_colour;
106
107 vm_alloc_t *pop()
108 {
109 auto a = top();
110 std::stack<vm_alloc_t *, std::vector<vm_alloc_t *>>::pop();
111 return a;
112 }
113 };
114}
115
116default_garbage_collector_t::default_garbage_collector_t(vm_t &vm)
117 : _collection_epoch{ 0 }
118 , _mark_cxt{ new mark_cxt_t{} }
119 , _vm{ vm }
120{
121}
122
123default_garbage_collector_t::~default_garbage_collector_t()
124{
125 std::lock_guard<std::mutex> lock{ _tracking_allocs_lock };
126 for (auto a : _tracking_allocs)
127 dec_ref_count_and_free(a);
128
129 auto cxt = static_cast<mark_cxt_t *>(_mark_cxt);
130 delete cxt;
94}131}
95 132
96vm_memory_allocator_t default_garbage_collector_t::get_allocator() const133vm_memory_allocator_t default_garbage_collector_t::get_allocator() const
@@ -102,14 +139,14 @@ void default_garbage_collector_t::track_allocation(vm_alloc_t *alloc) · 5 unmodified lines
102{139{
103 assert(alloc != nullptr);140 assert(alloc != nullptr);
104 141
105 if (debug::is_component_tracing_enabled<debug::component_trace_t::garbage_collector>())142 if (disvm::debug::is_component_tracing_enabled<component_trace_t::garbage_collector>())
106 debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: track: %#" PRIxPTR, alloc);143 disvm::debug::log_msg(component_trace_t::garbage_collector, log_level_t::debug, "gc: track: %#" PRIxPTR, alloc);
107 144
108 alloc->add_ref();145 alloc->add_ref();
109 set_gc_colour(alloc, get_current_colour(_collection_epoch));146 set_gc_colour(alloc, get_current_colour(_collection_epoch));
110 147
111 std::lock_guard<std::mutex> lock{ _tracking_allocs_lock };148 std::lock_guard<std::mutex> lock{ _tracking_allocs_lock };
112 _tracking_allocs.push_back(alloc);149 _tracking_allocs.emplace_front(alloc);
113}150}
114 151
115void default_garbage_collector_t::enum_tracked_allocations(vm_alloc_callback_t callback) const152void default_garbage_collector_t::enum_tracked_allocations(vm_alloc_callback_t callback) const
@@ -124,38 +161,20 @@ void default_garbage_collector_t::enum_tracked_allocations(vm_alloc_callback_t c · 8 unmodified lines
124 161
125namespace162namespace
126{163{
127 struct mark_cxt_t final : public std::stack<vm_alloc_t *, std::vector<vm_alloc_t *>>
128 {
129 mark_cxt_t(const type_descriptor_t *string_type, const gc_colour_t curr_colour)
130 : std::stack<vm_alloc_t *, std::vector<vm_alloc_t *>>{}
131 , string_type{ string_type }
132 , curr_colour{ curr_colour }
133 { }
134
135 const type_descriptor_t *string_type;
136 const gc_colour_t curr_colour;
137 };
138
139 void mark_pointers(pointer_t p, void *cxt)164 void mark_pointers(pointer_t p, void *cxt)
140 {165 {
141 auto a = vm_alloc_t::from_allocation(p);166 auto a = vm_alloc_t::from_allocation(p);
142 167
143 assert(cxt != nullptr);168 assert(cxt != nullptr);
144 auto c = reinterpret_cast<mark_cxt_t *>(cxt);169 auto c = static_cast<mark_cxt_t *>(cxt);
145 170
146 // Don't examine vm strings or allocations with the current colour171 // Don't examine vm strings or allocations with the current colour
147 if (c->curr_colour != get_gc_colour(a) && a->alloc_type.get() != c->string_type)172 if (c->curr_colour != get_gc_colour(a) && a->alloc_type.get() != c->string_type)
148 c->push(a);173 c->push(a);
149 }174 }
150 175
151 void mark(const std::vector<std::shared_ptr<const vm_thread_t>> &threads, const gc_colour_t curr_colour)176 void mark(std::vector<std::shared_ptr<const vm_thread_t>> threads, mark_cxt_t &mark_cxt)
152 {177 {
153 mark_cxt_t mark_cxt
154 {
155 intrinsic_type_desc::type<vm_string_t>().get(), // Using raw pointer since it is a built-in type and has unlimited lifetime
156 curr_colour
157 };
158
159 // Get roots from threads178 // Get roots from threads
160 for (auto &t : threads)179 for (auto &t : threads)
161 {180 {
@@ -179,42 +198,32 @@ namespace · 17 unmodified lines
179 }198 }
180 }199 }
181 200
182 const auto log_enabled = debug::is_component_tracing_enabled<debug::component_trace_t::garbage_collector>();201 if (disvm::debug::is_component_tracing_enabled<component_trace_t::garbage_collector>())
183 if (log_enabled)202 disvm::debug::log_msg(component_trace_t::garbage_collector, log_level_t::debug, "gc: roots found: %" PRIuPTR, mark_cxt.size());
184 debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: roots found: %" PRIuPTR, mark_cxt.size());
185 203
186 // Traverse the graph204 // Traverse the graph
187 while (!mark_cxt.empty())205 while (!mark_cxt.empty())
188 {206 {
189 auto curr = mark_cxt.top();207 auto curr = mark_cxt.pop();
190 mark_cxt.pop();208 set_gc_colour(curr, mark_cxt.curr_colour);
191
192 if (log_enabled)
193 debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: mark: alloc: %#" PRIxPTR, curr);
194 209
195 if (curr->alloc_type->map_in_bytes > 0)210 if (curr->alloc_type->map_in_bytes > 0)
196 enum_pointer_fields(*curr->alloc_type, curr->get_allocation(), mark_pointers, &mark_cxt);211 enum_pointer_fields(*curr->alloc_type, curr->get_allocation(), mark_pointers, &mark_cxt);
197
198 set_gc_colour(curr, curr_colour);
199 }212 }
200 }213 }
201 214
202 void sweep(std::deque<vm_alloc_t *> &tracking_allocs, const gc_colour_t sweeper_colour)215 void sweep(std::forward_list<vm_alloc_t *> &tracking_allocs, const gc_colour_t sweeper_colour)
203 {216 {
204 auto allocs_local = std::move(tracking_allocs);217 // Remove sweeper colour allocations.
205 218 tracking_allocs.remove_if([sweeper_colour](vm_alloc_t *a)
206 const auto starting_size = allocs_local.size();
207 for (auto a : allocs_local)
208 {219 {
209 const auto colour = get_gc_colour(a);220 const auto colour = get_gc_colour(a);
210 if (colour == sweeper_colour)221 const auto remove = (colour == sweeper_colour);
222 if (remove)
211 dec_ref_count_and_free(a);223 dec_ref_count_and_free(a);
212 else
213 tracking_allocs.push_back(a);
214 }
215 224
216 if (debug::is_component_tracing_enabled<debug::component_trace_t::garbage_collector>())225 return remove;
217 debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: sweep: %u", starting_size - tracking_allocs.size());226 });
218 }227 }
219}228}
220 229
@@ -228,15 +237,20 @@ bool default_garbage_collector_t::collect(std::vector<std::shared_ptr<const vm_t · 7 unmodified lines
228 return false;237 return false;
229 238
230 std::chrono::high_resolution_clock::time_point start;239 std::chrono::high_resolution_clock::time_point start;
231 const auto log_enabled = debug::is_component_tracing_enabled<debug::component_trace_t::duration>();240 const auto log_enabled = debug::is_component_tracing_enabled<component_trace_t::duration>();
232 if (log_enabled)241 if (log_enabled)
233 {242 {
234 start = std::chrono::high_resolution_clock::now();243 start = std::chrono::high_resolution_clock::now();
235 debug::log_msg(debug::component_trace_t::duration, debug::log_level_t::debug, "gc: begin: collect");244 disvm::debug::log_msg(component_trace_t::duration, log_level_t::debug, "gc: begin: collect");
236 }245 }
237 246
238 const auto curr_colour = get_current_colour(_collection_epoch);247 auto mark_cxt = static_cast<mark_cxt_t *>(_mark_cxt);
239 mark(threads, curr_colour);248 assert(mark_cxt != nullptr);
249 mark_cxt->curr_colour = get_current_colour(_collection_epoch);
250
251 assert(mark_cxt->empty() && "Marking context should be empty before mark phase");
252 mark(std::move(threads), *mark_cxt);
253 assert(mark_cxt->empty() && "Marking context should be empty after mark phase");
240 254
241 const auto sweeper_colour = get_sweeper_colour(_collection_epoch);255 const auto sweeper_colour = get_sweeper_colour(_collection_epoch);
242 sweep(_tracking_allocs, sweeper_colour);256 sweep(_tracking_allocs, sweeper_colour);
@@ -244,7 +258,7 @@ bool default_garbage_collector_t::collect(std::vector<std::shared_ptr<const vm_t · 1 unmodified line
244 if (log_enabled)258 if (log_enabled)
245 {259 {
246 const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start);260 const auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start);
247 debug::log_msg(debug::component_trace_t::duration, debug::log_level_t::debug, "gc: end: collect: %lld us", elapsed.count());261 disvm::debug::log_msg(component_trace_t::duration, log_level_t::debug, "gc: end: collect: %lld us", elapsed.count());
248 }262 }
249 263
250 ++_collection_epoch;264 ++_collection_epoch;
src/vm/garbage_collector.h+3−2
@@ -9,7 +9,7 @@ · 8 unmodified lines
9 9
10#include <cstdint>10#include <cstdint>
11#include <mutex>11#include <mutex>
12#include <deque>12#include <forward_list>
13#include <vector>13#include <vector>
14#include <disvm.h>14#include <disvm.h>
15 15
@@ -37,9 +37,10 @@ namespace disvm · 21 unmodified lines
37 private:37 private:
38 vm_t &_vm;38 vm_t &_vm;
39 39
40 void *_mark_cxt;
40 std::size_t _collection_epoch;41 std::size_t _collection_epoch;
41 mutable std::mutex _tracking_allocs_lock;42 mutable std::mutex _tracking_allocs_lock;
42 std::deque<vm_alloc_t *> _tracking_allocs;43 std::forward_list<vm_alloc_t *> _tracking_allocs;
43 };44 };
44 }45 }
45}46}
src/vm/list.cpp+12−5
@@ -9,8 +9,15 @@ · 8 unmodified lines
9#include <vm_memory.h>9#include <vm_memory.h>
10#include <debug.h>10#include <debug.h>
11 11
12using namespace disvm;12using disvm::debug::component_trace_t;
13using namespace disvm::runtime;13using disvm::debug::log_level_t;
14
15using disvm::runtime::intrinsic_type_desc;
16using disvm::runtime::pointer_t;
17using disvm::runtime::type_descriptor_t;
18using disvm::runtime::vm_alloc_t;
19using disvm::runtime::vm_list_t;
20using disvm::runtime::word_t;
14 21
15std::shared_ptr<const type_descriptor_t> vm_list_t::type_desc()22std::shared_ptr<const type_descriptor_t> vm_list_t::type_desc()
16{23{
@@ -32,8 +39,8 @@ vm_list_t::vm_list_t(std::shared_ptr<const type_descriptor_t> td, vm_list_t *tai · 15 unmodified lines
32 if (_is_alloc)39 if (_is_alloc)
33 _mem.alloc = static_cast<pointer_t>(alloc_memory(_element_type->size_in_bytes));40 _mem.alloc = static_cast<pointer_t>(alloc_memory(_element_type->size_in_bytes));
34 41
35 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())42 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
36 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm list");43 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm list");
37}44}
38 45
39vm_list_t::~vm_list_t()46vm_list_t::~vm_list_t()
@@ -54,7 +61,7 @@ vm_list_t::~vm_list_t() · 14 unmodified lines
54 }61 }
55 62
56 debug::assign_debug_pointer(&_mem.alloc);63 debug::assign_debug_pointer(&_mem.alloc);
57 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm list");64 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm list");
58}65}
59 66
60std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const67std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const
src/vm/math/Mathmod.cpp+15−4
@@ -7,8 +7,19 @@ · 6 unmodified lines
7#include <debug.h>7#include <debug.h>
8#include "Mathmod.h"8#include "Mathmod.h"
9 9
10using namespace disvm;10using disvm::vm_t;
11using namespace disvm::runtime;11
12using disvm::debug::component_trace_t;
13using disvm::debug::log_level_t;
14
15using disvm::runtime::dereference_nil;
16using disvm::runtime::intrinsic_type_desc;
17using disvm::runtime::real_t;
18using disvm::runtime::vm_alloc_t;
19using disvm::runtime::vm_array_t;
20using disvm::runtime::vm_user_exception;
21using disvm::runtime::vm_system_exception;
22using disvm::runtime::word_t;
12 23
13namespace24namespace
14{25{
@@ -90,7 +101,7 @@ namespace · 75 unmodified lines
90void101void
91Mathmodinit(void)102Mathmodinit(void)
92{103{
93 builtin::register_module_exports(Math_PATH, Mathmodlen, Mathmodtab);104 disvm::runtime::builtin::register_module_exports(Math_PATH, Mathmodlen, Mathmodtab);
94}105}
95 106
96void107void
@@ -99,7 +110,7 @@ Math_FPcontrol(vm_registers_t &r, vm_t &vm) · 2 unmodified lines
99 auto &fp = r.stack.peek_frame()->base<F_Math_FPcontrol>();110 auto &fp = r.stack.peek_frame()->base<F_Math_FPcontrol>();
100 111
101 // [PAL] Properly implement floating point control112 // [PAL] Properly implement floating point control
102 debug::log_msg(debug::component_trace_t::builtin, debug::log_level_t::warning, "FPControl is not properly implemented");113 disvm::debug::log_msg(component_trace_t::builtin, log_level_t::warning, "FPControl is not properly implemented");
103 114
104 *fp.ret = fp.mask;115 *fp.ret = fp.mask;
105}116}
src/vm/math/Mathmod.h+9−2
@@ -11,8 +11,15 @@ · 10 unmodified lines
11#include <disvm.h>11#include <disvm.h>
12#include <builtin_module.h>12#include <builtin_module.h>
13 13
14using namespace disvm;14using disvm::vm_t;
15using namespace disvm::runtime;15
16using disvm::runtime::byte_t;
17using disvm::runtime::word_t;
18using disvm::runtime::big_t;
19using disvm::runtime::real_t;
20using disvm::runtime::pointer_t;
21using disvm::runtime::vm_registers_t;
22using disvm::runtime::vm_frame_base_alloc_t;
16 23
17void Math_FPcontrol(vm_registers_t &r, vm_t &vm);24void Math_FPcontrol(vm_registers_t &r, vm_t &vm);
18struct F_Math_FPcontrol : public vm_frame_base_alloc_t25struct F_Math_FPcontrol : public vm_frame_base_alloc_t
src/vm/module_reader.cpp+52−28
@@ -18,9 +18,33 @@ · 17 unmodified lines
18#include <module_reader.h>18#include <module_reader.h>
19#include "buffered_reader.h"19#include "buffered_reader.h"
20 20
21using namespace disvm;21using disvm::opcode_t;
22using namespace disvm::runtime;22
23using namespace disvm::format;23using disvm::format::operand_t;
24
25using disvm::runtime::addr_code_t;
26using disvm::runtime::address_mode_t;
27using disvm::runtime::address_mode_middle_t;
28using disvm::runtime::big_t;
29using disvm::runtime::byte_t;
30using disvm::runtime::word_t;
31using disvm::runtime::real_t;
32using disvm::runtime::pointer_t;
33using disvm::runtime::runtime_flags_t;
34using disvm::runtime::type_descriptor_t;
35using disvm::runtime::vm_module_t;
36using disvm::runtime::vm_alloc_t;
37using disvm::runtime::vm_array_t;
38using disvm::runtime::vm_string_t;
39using disvm::runtime::vm_pc_t;
40using disvm::runtime::import_function_t;
41using disvm::runtime::export_function_t;
42using disvm::runtime::import_vm_module_t;
43using disvm::runtime::handler_entry_t;
44using disvm::runtime::exception_entry_t;
45using disvm::runtime::vm_instruction_t;
46using disvm::runtime::vm_module_exception;
47using disvm::runtime::module_reader_exception;
24 48
25namespace49namespace
26{50{
@@ -49,7 +73,7 @@ namespace · 22 unmodified lines
49 };73 };
50 74
51 // Read the next operand as defined in the Dis VM specification.75 // Read the next operand as defined in the Dis VM specification.
52 std::tuple<bool, operand_t> read_next_operand(util::buffered_reader_t &reader)76 std::tuple<bool, operand_t> read_next_operand(disvm::util::buffered_reader_t &reader)
53 {77 {
54 operand_t result;78 operand_t result;
55 79
@@ -111,7 +135,7 @@ namespace · 55 unmodified lines
111 }135 }
112 136
113 // Read the next word as defined in the Dis VM specification.137 // Read the next word as defined in the Dis VM specification.
114 std::tuple<bool, word_t> read_next_word(util::buffered_reader_t &reader)138 std::tuple<bool, word_t> read_next_word(disvm::util::buffered_reader_t &reader)
115 {139 {
116 auto result = word_t{};140 auto result = word_t{};
117 141
@@ -141,7 +165,7 @@ namespace · 23 unmodified lines
141 return r;165 return r;
142 }166 }
143 167
144 byte_t *read_8byte_segments(util::buffered_reader_t &reader, datum_type_t type, uint32_t segment_count, byte_t *dest)168 byte_t *read_8byte_segments(disvm::util::buffered_reader_t &reader, datum_type_t type, uint32_t segment_count, byte_t *dest)
145 {169 {
146 assert(type == datum_type_t::value_real64 || type == datum_type_t::value_bit64);170 assert(type == datum_type_t::value_real64 || type == datum_type_t::value_bit64);
147 171
@@ -190,7 +214,7 @@ namespace · 42 unmodified lines
190 }214 }
191 215
192 // See header format definition in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)216 // See header format definition in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
193 void read_header(util::buffered_reader_t &reader, vm_module_t &modobj)217 void read_header(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
194 {218 {
195 auto success = bool{};219 auto success = bool{};
196 auto &header = modobj.header;220 auto &header = modobj.header;
@@ -200,7 +224,7 @@ namespace · 3 unmodified lines
200 throw module_reader_exception{ "Failed to read magic number" };224 throw module_reader_exception{ "Failed to read magic number" };
201 225
202 // If the object file is signed, read in the signature.226 // If the object file is signed, read in the signature.
203 if (header.magic_number == magic_number_constants::smagic)227 if (header.magic_number == disvm::format::magic_number_constants::smagic)
204 {228 {
205 std::tie(success, header.Signature.length) = read_next_operand(reader);229 std::tie(success, header.Signature.length) = read_next_operand(reader);
206 if (!success) throw module_reader_exception{ "Failed to read signature length" };230 if (!success) throw module_reader_exception{ "Failed to read signature length" };
@@ -209,7 +233,7 @@ namespace · 2 unmodified lines
209 const auto bytesRead = reader.get_next_bytes(header.Signature.length, header.Signature.signature.get());233 const auto bytesRead = reader.get_next_bytes(header.Signature.length, header.Signature.signature.get());
210 if (bytesRead != header.Signature.length) throw module_reader_exception{ "Failed to read full signature" };234 if (bytesRead != header.Signature.length) throw module_reader_exception{ "Failed to read full signature" };
211 }235 }
212 else if (header.magic_number == magic_number_constants::xmagic)236 else if (header.magic_number == disvm::format::magic_number_constants::xmagic)
213 {237 {
214 header.Signature.length = word_t{ 0 };238 header.Signature.length = word_t{ 0 };
215 }239 }
@@ -248,7 +272,7 @@ namespace · 32 unmodified lines
248 }272 }
249 273
250 // See code section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)274 // See code section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
251 void read_code_section(util::buffered_reader_t &reader, vm_module_t &modobj)275 void read_code_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
252 {276 {
253 auto success = bool{};277 auto success = bool{};
254 const auto instruction_count = modobj.header.code_size;278 const auto instruction_count = modobj.header.code_size;
@@ -320,7 +344,7 @@ namespace · 65 unmodified lines
320 }344 }
321 345
322 // See type section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)346 // See type section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
323 void read_type_section(util::buffered_reader_t &reader, vm_module_t &modobj)347 void read_type_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
324 {348 {
325 auto success = bool{};349 auto success = bool{};
326 const auto type_count = modobj.header.type_size;350 const auto type_count = modobj.header.type_size;
@@ -356,7 +380,7 @@ namespace · 29 unmodified lines
356 }380 }
357 381
358 // See data section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)382 // See data section layout in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
359 void read_data_section(util::buffered_reader_t &reader, vm_module_t &modobj)383 void read_data_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
360 {384 {
361 if (modobj.header.data_size != 0)385 if (modobj.header.data_size != 0)
362 {386 {
@@ -496,7 +520,7 @@ namespace · 133 unmodified lines
496 }520 }
497 521
498 // See module name in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)522 // See module name in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
499 void read_module_name(util::buffered_reader_t &reader, vm_module_t &modobj)523 void read_module_name(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
500 {524 {
501 auto string_buffer = std::vector<uint8_t>{};525 auto string_buffer = std::vector<uint8_t>{};
502 if (!reader.get_bytes_until(0, string_buffer))526 if (!reader.get_bytes_until(0, string_buffer))
@@ -507,7 +531,7 @@ namespace · 4 unmodified lines
507 }531 }
508 532
509 // See link section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)533 // See link section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
510 void read_link_section(util::buffered_reader_t &reader, vm_module_t &modobj)534 void read_link_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
511 {535 {
512 auto success = bool{};536 auto success = bool{};
513 const auto export_count = modobj.header.export_size;537 const auto export_count = modobj.header.export_size;
@@ -543,7 +567,7 @@ namespace · 29 unmodified lines
543 // See import section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)567 // See import section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
544 // [SPEC] The specification does not seem to match what is observed in an actual module. 568 // [SPEC] The specification does not seem to match what is observed in an actual module.
545 // The function is modeled after the disassembler (dis.b and libinterp/load.c) instead.569 // The function is modeled after the disassembler (dis.b and libinterp/load.c) instead.
546 void read_import_section(util::buffered_reader_t &reader, vm_module_t &modobj)570 void read_import_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
547 {571 {
548 auto success = bool{};572 auto success = bool{};
549 auto module_import_count = operand_t{};573 auto module_import_count = operand_t{};
@@ -592,7 +616,7 @@ namespace · 42 unmodified lines
592 }616 }
593 617
594 // See handler section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)618 // See handler section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html)
595 void read_handler_section(util::buffered_reader_t &reader, vm_module_t &modobj)619 void read_handler_section(disvm::util::buffered_reader_t &reader, vm_module_t &modobj)
596 {620 {
597 auto success = bool{};621 auto success = bool{};
598 auto handler_count = operand_t{};622 auto handler_count = operand_t{};
@@ -604,7 +628,7 @@ namespace · 5 unmodified lines
604 for (auto c = operand_t{ 0 }; c < handler_count; ++c)628 for (auto c = operand_t{ 0 }; c < handler_count; ++c)
605 {629 {
606 // Read in single handler630 // Read in single handler
607 handler_t handler{};631 handler_entry_t handler{};
608 632
609 std::tie(success, handler.exception_offset) = read_next_operand(reader);633 std::tie(success, handler.exception_offset) = read_next_operand(reader);
610 if (!success) throw module_reader_exception{ "Failed to read exception offset" };634 if (!success) throw module_reader_exception{ "Failed to read exception offset" };
@@ -643,7 +667,7 @@ namespace · 32 unmodified lines
643 for (auto k = operand_t{ 0 }; k < total_count; ++k)667 for (auto k = operand_t{ 0 }; k < total_count; ++k)
644 {668 {
645 // Read in single exception669 // Read in single exception
646 exception_t except{};670 exception_entry_t except{};
647 671
648 auto string_buffer = std::vector<uint8_t>{};672 auto string_buffer = std::vector<uint8_t>{};
649 if (!reader.get_bytes_until(0, string_buffer))673 if (!reader.get_bytes_until(0, string_buffer))
@@ -658,7 +682,7 @@ namespace · 8 unmodified lines
658 }682 }
659 683
660 // Read in wildcard exception684 // Read in wildcard exception
661 exception_t wildcard_exception{};685 exception_entry_t wildcard_exception{};
662 std::tie(success, wildcard_exception.pc) = read_next_operand(reader);686 std::tie(success, wildcard_exception.pc) = read_next_operand(reader);
663 if (!success) throw module_reader_exception{ "Failed to read wildcard exception pc" };687 if (!success) throw module_reader_exception{ "Failed to read wildcard exception pc" };
664 688
@@ -705,19 +729,19 @@ import_vm_module_t::import_vm_module_t(import_vm_module_t &&other) · 40 unmodified lines
705{729{
706}730}
707 731
708exception_t::exception_t(exception_t &&other)732exception_entry_t::exception_entry_t(exception_entry_t &&other)
709 : pc{ other.pc }733 : pc{ other.pc }
710 , name{ std::move(other.name) }734 , name{ std::move(other.name) }
711{735{
712}736}
713 737
714exception_t::~exception_t()738exception_entry_t::~exception_entry_t()
715{739{
716 if (name != nullptr)740 if (name != nullptr)
717 name->release();741 name->release();
718}742}
719 743
720handler_t::handler_t(handler_t &&other)744handler_entry_t::handler_entry_t(handler_entry_t &&other)
721 : exception_offset{ other.exception_offset }745 : exception_offset{ other.exception_offset }
722 , begin_pc{ other.begin_pc }746 , begin_pc{ other.begin_pc }
723 , end_pc{ other.end_pc }747 , end_pc{ other.end_pc }
@@ -736,15 +760,15 @@ vm_module_t::~vm_module_t() · 12 unmodified lines
736 original_mp->release();760 original_mp->release();
737}761}
738 762
739std::unique_ptr<runtime::vm_module_t> disvm::read_module(std::istream &data)763std::unique_ptr<vm_module_t> disvm::read_module(std::istream &data)
740{764{
741 util::buffered_reader_t reader{ data };765 disvm::util::buffered_reader_t reader{ data };
742 766
743 auto modobj = std::make_unique<vm_module_t>();767 auto modobj = std::make_unique<vm_module_t>();
744 768
745 read_header(reader, *modobj);769 read_header(reader, *modobj);
746 770
747 if (util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_import_deprecated))771 if (disvm::util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_import_deprecated))
748 throw module_reader_exception{ "Obsolete module" };772 throw module_reader_exception{ "Obsolete module" };
749 773
750 read_code_section(reader, *modobj);774 read_code_section(reader, *modobj);
@@ -753,14 +777,14 @@ std::unique_ptr<runtime::vm_module_t> disvm::read_module(std::istream &data) · 2 unmodified lines
753 read_module_name(reader, *modobj);777 read_module_name(reader, *modobj);
754 read_link_section(reader, *modobj);778 read_link_section(reader, *modobj);
755 779
756 if (util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_import))780 if (disvm::util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_import))
757 read_import_section(reader, *modobj);781 read_import_section(reader, *modobj);
758 782
759 if (util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_handler))783 if (disvm::util::has_flag(modobj->header.runtime_flag, runtime_flags_t::has_handler))
760 read_handler_section(reader, *modobj);784 read_handler_section(reader, *modobj);
761 785
762 // [TODO] Native code generation - runtime_flags_t::must_compile786 // [TODO] Native code generation - runtime_flags_t::must_compile
763 assert(!util::has_flag(modobj->header.runtime_flag, runtime_flags_t::must_compile));787 assert(!disvm::util::has_flag(modobj->header.runtime_flag, runtime_flags_t::must_compile));
764 788
765 return modobj;789 return modobj;
766}790}
src/vm/module_ref.cpp+26−12
@@ -10,8 +10,22 @@ · 9 unmodified lines
10#include <utils.h>10#include <utils.h>
11#include <debug.h>11#include <debug.h>
12 12
13using namespace disvm;13using disvm::debug::component_trace_t;
14using namespace disvm::runtime;14using disvm::debug::log_level_t;
15
16using disvm::runtime::type_descriptor_t;
17using disvm::runtime::intrinsic_type_desc;
18using disvm::runtime::byte_t;
19using disvm::runtime::word_t;
20using disvm::runtime::vm_array_t;
21using disvm::runtime::vm_string_t;
22using disvm::runtime::vm_module_t;
23using disvm::runtime::vm_module_ref_t;
24using disvm::runtime::export_section_t;
25using disvm::runtime::import_vm_module_t;
26using disvm::runtime::vm_module_function_ref_t;
27using disvm::runtime::vm_system_exception;
28using disvm::runtime::vm_user_exception;
15 29
16namespace30namespace
17{31{
@@ -47,11 +61,11 @@ namespace · 29 unmodified lines
47 ref.entry_pc = export_entry.pc;61 ref.entry_pc = export_entry.pc;
48 ref.frame_type = export_entry.frame_type;62 ref.frame_type = export_entry.frame_type;
49 63
50 if (debug::is_component_tracing_enabled<debug::component_trace_t::module>())64 if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>())
51 {65 {
52 debug::log_msg(66 disvm::debug::log_msg(
53 debug::component_trace_t::module,67 component_trace_t::module,
54 debug::log_level_t::debug,68 log_level_t::debug,
55 "export: %d %#08x >>%s<<",69 "export: %d %#08x >>%s<<",
56 index,70 index,
57 export_entry.sig,71 export_entry.sig,
@@ -79,8 +93,8 @@ vm_module_ref_t::vm_module_ref_t(std::shared_ptr<const vm_module_t> module) · 21 unmodified lines
79 if (module->original_mp != nullptr)93 if (module->original_mp != nullptr)
80 mp_base = vm_alloc_t::copy(*module->original_mp);94 mp_base = vm_alloc_t::copy(*module->original_mp);
81 95
82 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())96 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
83 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm module ref");97 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm module ref");
84}98}
85 99
86vm_module_ref_t::vm_module_ref_t(std::shared_ptr<const vm_module_t> module, const import_vm_module_t &imports)100vm_module_ref_t::vm_module_ref_t(std::shared_ptr<const vm_module_t> module, const import_vm_module_t &imports)
@@ -97,8 +111,8 @@ vm_module_ref_t::vm_module_ref_t(std::shared_ptr<const vm_module_t> module, cons · 10 unmodified lines
97 if (module->original_mp != nullptr)111 if (module->original_mp != nullptr)
98 mp_base = vm_alloc_t::copy(*module->original_mp);112 mp_base = vm_alloc_t::copy(*module->original_mp);
99 113
100 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())114 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
101 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm module ref: exported %d", _function_refs->get_length());115 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm module ref: exported %d", _function_refs->get_length());
102}116}
103 117
104vm_module_ref_t::~vm_module_ref_t()118vm_module_ref_t::~vm_module_ref_t()
@@ -108,8 +122,8 @@ vm_module_ref_t::~vm_module_ref_t() · 3 unmodified lines
108 if (_function_refs != nullptr)122 if (_function_refs != nullptr)
109 _function_refs->release();123 _function_refs->release();
110 124
111 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())125 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
112 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm module ref");126 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm module ref");
113}127}
114 128
115bool vm_module_ref_t::is_builtin_module() const129bool vm_module_ref_t::is_builtin_module() const
src/vm/module_resolver.cpp+10−5
@@ -12,7 +12,12 @@ · 11 unmodified lines
12#include <exceptions.h>12#include <exceptions.h>
13#include "module_resolver.h"13#include "module_resolver.h"
14 14
15using namespace disvm::runtime;15using disvm::debug::component_trace_t;
16using disvm::debug::log_level_t;
17
18using disvm::runtime::default_resolver_t;
19using disvm::runtime::vm_module_t;
20using disvm::runtime::vm_module_resolver_t;
16 21
17// Empty destructor for vm module resolver 'interface'22// Empty destructor for vm module resolver 'interface'
18vm_module_resolver_t::~vm_module_resolver_t()23vm_module_resolver_t::~vm_module_resolver_t()
@@ -34,9 +39,9 @@ bool default_resolver_t::try_resolve_module(const char *path, std::unique_ptr<vm · 15 unmodified lines
34{39{
35 assert(path != nullptr);40 assert(path != nullptr);
36 41
37 auto log = debug::is_component_tracing_enabled<debug::component_trace_t::module>();42 auto log = disvm::debug::is_component_tracing_enabled<component_trace_t::module>();
38 if (log)43 if (log)
39 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "resolve: try module path: >>%s<<", path);44 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "resolve: try module path: >>%s<<", path);
40 45
41 auto module_file = std::ifstream{ path, std::ifstream::binary };46 auto module_file = std::ifstream{ path, std::ifstream::binary };
42 if (!module_file.is_open())47 if (!module_file.is_open())
@@ -46,13 +51,13 @@ bool default_resolver_t::try_resolve_module(const char *path, std::unique_ptr<vm · 3 unmodified lines
46 {51 {
47 p.append(path);52 p.append(path);
48 if (log)53 if (log)
49 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "resolve: try module path: >>%s<<", p.c_str());54 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "resolve: try module path: >>%s<<", p.c_str());
50 55
51 module_file = std::ifstream{ p, std::ifstream::binary };56 module_file = std::ifstream{ p, std::ifstream::binary };
52 if (module_file.is_open())57 if (module_file.is_open())
53 {58 {
54 if (log)59 if (log)
55 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "resolve: successful modified module path: >>%s<< >>%s<<", path, p.c_str());60 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "resolve: successful modified module path: >>%s<< >>%s<<", path, p.c_str());
56 61
57 break;62 break;
58 }63 }
src/vm/scheduler.cpp+33−24
@@ -11,8 +11,17 @@ · 10 unmodified lines
11#include <exceptions.h>11#include <exceptions.h>
12#include "scheduler.h"12#include "scheduler.h"
13 13
14using namespace disvm;14using disvm::vm_t;
15using namespace disvm::runtime;15
16using disvm::debug::component_trace_t;
17using disvm::debug::log_level_t;
18
19using disvm::runtime::vm_thread_t;
20using disvm::runtime::vm_scheduler_t;
21using disvm::runtime::vm_scheduler_control_t;
22using disvm::runtime::vm_tool_dispatch_t;
23using disvm::runtime::vm_thread_state_t;
24using disvm::runtime::default_scheduler_t;
16 25
17// Empty destructors for vm scheduler 'interfaces'26// Empty destructors for vm scheduler 'interfaces'
18vm_scheduler_t::~vm_scheduler_t()27vm_scheduler_t::~vm_scheduler_t()
@@ -25,7 +34,7 @@ vm_scheduler_control_t::~vm_scheduler_control_t() · 6 unmodified lines
25 34
26void default_scheduler_t::worker_main(default_scheduler_t &instance)35void default_scheduler_t::worker_main(default_scheduler_t &instance)
27{36{
28 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: worker: start");37 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: worker: start");
29 38
30 register_system_thread(instance._vm);39 register_system_thread(instance._vm);
31 auto current_thread = std::shared_ptr<thread_instance_t>{};40 auto current_thread = std::shared_ptr<thread_instance_t>{};
@@ -37,12 +46,12 @@ void default_scheduler_t::worker_main(default_scheduler_t &instance) · 5 unmodified lines
37 current_thread = instance.next_thread(std::move(current_thread));46 current_thread = instance.next_thread(std::move(current_thread));
38 if (current_thread == nullptr)47 if (current_thread == nullptr)
39 {48 {
40 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: worker: stop");49 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: worker: stop");
41 break;50 break;
42 }51 }
43 52
44 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())53 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
45 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: worker: execute: %d", current_thread->vm_thread->get_thread_id());54 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: worker: execute: %d", current_thread->vm_thread->get_thread_id());
46 55
47 current_thread->vm_thread->execute(instance._vm, instance._vm_thread_quanta);56 current_thread->vm_thread->execute(instance._vm, instance._vm_thread_quanta);
48 }57 }
@@ -116,7 +125,7 @@ default_scheduler_t::~default_scheduler_t() · 67 unmodified lines
116 for (auto &w : _worker_pool)125 for (auto &w : _worker_pool)
117 w.join();126 w.join();
118 127
119 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: shutdown");128 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: shutdown");
120}129}
121 130
122bool default_scheduler_t::is_idle() const131bool default_scheduler_t::is_idle() const
@@ -130,14 +139,14 @@ vm_scheduler_control_t &default_scheduler_t::get_controller() const · 7 unmodified lines
130 return const_cast<default_scheduler_t&>(*this);139 return const_cast<default_scheduler_t&>(*this);
131}140}
132 141
133const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread)142const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<vm_thread_t> thread)
134{143{
135 assert(thread != nullptr);144 assert(thread != nullptr);
136 if (thread->get_registers().current_thread_state != vm_thread_state_t::ready)145 if (thread->get_registers().current_thread_state != vm_thread_state_t::ready)
137 throw vm_system_exception{ "Scheduled thread in invalid state" };146 throw vm_system_exception{ "Scheduled thread in invalid state" };
138 147
139 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())148 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
140 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: scheduled: %d", thread->get_thread_id());149 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: scheduled: %d", thread->get_thread_id());
141 150
142 std::unique_lock<std::mutex> lock{ _vm_threads_lock };151 std::unique_lock<std::mutex> lock{ _vm_threads_lock };
143 152
@@ -251,8 +260,8 @@ void default_scheduler_t::enqueue_blocked_thread(uint32_t thread_id) · 107 unmodified lines
251 260
252 _blocked_vm_thread_ids.erase(blocked_iter);261 _blocked_vm_thread_ids.erase(blocked_iter);
253 262
254 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())263 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
255 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: enqueue blocked: %d", thread_id);264 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: enqueue blocked: %d", thread_id);
256 265
257 const bool runnable_thread = enqueue_thread_unsafe(thread_container.get(), vm_thread_state_t::ready);266 const bool runnable_thread = enqueue_thread_unsafe(thread_container.get(), vm_thread_state_t::ready);
258 if (runnable_thread)267 if (runnable_thread)
@@ -335,15 +344,15 @@ std::shared_ptr<default_scheduler_t::thread_instance_t> default_scheduler_t::nex · 76 unmodified lines
335 344
336 if (!_all_vm_threads.empty() && _blocked_vm_thread_ids.size() == _all_vm_threads.size())345 if (!_all_vm_threads.empty() && _blocked_vm_thread_ids.size() == _all_vm_threads.size())
337 {346 {
338 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::warning, "scheduler: deadlock detected");347 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::warning, "scheduler: deadlock detected");
339 assert(false && "VM thread deadlock detected");348 assert(false && "VM thread deadlock detected");
340 }349 }
341 350
342 if (_terminating)351 if (_terminating)
343 return{};352 return{};
344 353
345 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())354 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
346 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: worker: waiting");355 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: worker: waiting");
347 356
348 _worker_event.wait(lock);357 _worker_event.wait(lock);
349 358
@@ -380,7 +389,7 @@ void default_scheduler_t::perform_gc(bool is_gc_thread, std::unique_lock<std::mu · 30 unmodified lines
380 }389 }
381}390}
382 391
383bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instance, runtime::vm_thread_state_t current_state)392bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instance, vm_thread_state_t current_state)
384{393{
385 assert(thread_instance != nullptr);394 assert(thread_instance != nullptr);
386 395
@@ -392,8 +401,8 @@ bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instan · 5 unmodified lines
392 {401 {
393 _runnable_vm_thread_ids.push_back(thread_id);402 _runnable_vm_thread_ids.push_back(thread_id);
394 403
395 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())404 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
396 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: enqueue: %d", thread_id);405 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: enqueue: %d", thread_id);
397 406
398 return true;407 return true;
399 }408 }
@@ -404,8 +413,8 @@ bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instan · 4 unmodified lines
404 {413 {
405 _blocked_vm_thread_ids.insert(thread_id);414 _blocked_vm_thread_ids.insert(thread_id);
406 415
407 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())416 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
408 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: blocked: %d", thread_id);417 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: blocked: %d", thread_id);
409 418
410 break;419 break;
411 }420 }
@@ -413,8 +422,8 @@ bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instan · 1 unmodified line
413 case vm_thread_state_t::empty_stack:422 case vm_thread_state_t::empty_stack:
414 case vm_thread_state_t::exiting:423 case vm_thread_state_t::exiting:
415 {424 {
416 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())425 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
417 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: exiting: %d", thread_id);426 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: exiting: %d", thread_id);
418 427
419 // Remove the thread428 // Remove the thread
420 auto thread_to_remove = _all_vm_threads.find(thread_id);429 auto thread_to_remove = _all_vm_threads.find(thread_id);
@@ -426,8 +435,8 @@ bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instan · 5 unmodified lines
426 435
427 case vm_thread_state_t::broken:436 case vm_thread_state_t::broken:
428 {437 {
429 if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>())438 if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>())
430 debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: broken: %d", thread_id);439 disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: broken: %d", thread_id);
431 440
432 auto err_msg = thread_instance->vm_thread->get_error_message();441 auto err_msg = thread_instance->vm_thread->get_error_message();
433 assert(err_msg != nullptr);442 assert(err_msg != nullptr);
src/vm/stack.cpp+27−19
@@ -11,8 +11,16 @@ · 10 unmodified lines
11#include <debug.h>11#include <debug.h>
12#include <exceptions.h>12#include <exceptions.h>
13 13
14using namespace disvm;14using disvm::debug::component_trace_t;
15using namespace disvm::runtime;15using disvm::debug::log_level_t;
16
17using disvm::runtime::type_descriptor_t;
18using disvm::runtime::pointer_t;
19using disvm::runtime::vm_pc_t;
20using disvm::runtime::vm_module_ref_t;
21using disvm::runtime::vm_frame_t;
22using disvm::runtime::vm_stack_t;
23using disvm::runtime::vm_alloc_t;
16 24
17namespace25namespace
18{26{
@@ -54,7 +62,7 @@ namespace · 35 unmodified lines
54 ~vm_stack_layout()62 ~vm_stack_layout()
55 {63 {
56 assert(top_page != nullptr);64 assert(top_page != nullptr);
57 free_memory(top_page);65 disvm::runtime::free_memory(top_page);
58 }66 }
59 67
60 const std::size_t stack_page_size;68 const std::size_t stack_page_size;
@@ -66,7 +74,7 @@ namespace · 5 unmodified lines
66 void *new_page()74 void *new_page()
67 {75 {
68 auto current_stack_page = top_page;76 auto current_stack_page = top_page;
69 top_page = alloc_memory<vm_stack_page>(sizeof(vm_stack_page) + stack_page_size);77 top_page = disvm::runtime::alloc_memory<vm_stack_page>(sizeof(vm_stack_page) + stack_page_size);
70 78
71 // Initialize the stack allocation.79 // Initialize the stack allocation.
72 top_page->prev_page = current_stack_page;80 top_page->prev_page = current_stack_page;
@@ -75,8 +83,8 @@ namespace · 2 unmodified lines
75 top_page->page_top_frame = nullptr;83 top_page->page_top_frame = nullptr;
76 top_page->page_limit_addr = reinterpret_cast<std::uintptr_t>(top_page)+stack_page_size;84 top_page->page_limit_addr = reinterpret_cast<std::uintptr_t>(top_page)+stack_page_size;
77 85
78 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())86 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
79 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: vm stack alloc: %#" PRIxPTR " %#" PRIxPTR, top_page, top_page->page_limit_addr);87 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "alloc: vm stack alloc: %#" PRIxPTR " %#" PRIxPTR, top_page, top_page->page_limit_addr);
80 88
81 return top_page->stack_data();89 return top_page->stack_data();
82 }90 }
@@ -87,10 +95,10 @@ namespace · 4 unmodified lines
87 auto current_stack_page = top_page->prev_page;95 auto current_stack_page = top_page->prev_page;
88 assert(current_stack_page != nullptr);96 assert(current_stack_page != nullptr);
89 97
90 free_memory(top_page);98 disvm::runtime::free_memory(top_page);
91 99
92 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())100 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
93 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: vm stack alloc");101 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "free: vm stack alloc");
94 102
95 // Set the top page103 // Set the top page
96 top_page = current_stack_page;104 top_page = current_stack_page;
@@ -110,8 +118,8 @@ vm_frame_t::vm_frame_t(std::shared_ptr<const type_descriptor_t> &td) · 13 unmodified lines
110 prev_frame() = nullptr;118 prev_frame() = nullptr;
111 prev_module_ref() = nullptr;119 prev_module_ref() = nullptr;
112 120
113 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())121 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
114 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm frame: %#" PRIxPTR " %d", this, frame_type->size_in_bytes);122 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm frame: %#" PRIxPTR " %d", this, frame_type->size_in_bytes);
115}123}
116 124
117vm_frame_t::~vm_frame_t()125vm_frame_t::~vm_frame_t()
@@ -120,8 +128,8 @@ vm_frame_t::~vm_frame_t() · 2 unmodified lines
120 128
121 destroy_memory(*frame_type, base());129 destroy_memory(*frame_type, base());
122 130
123 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())131 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
124 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm frame: %#" PRIxPTR, this);132 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm frame: %#" PRIxPTR, this);
125}133}
126 134
127void vm_frame_t::copy_frame_contents(const vm_frame_t &other)135void vm_frame_t::copy_frame_contents(const vm_frame_t &other)
@@ -181,7 +189,7 @@ vm_stack_t::vm_stack_t(std::size_t stack_extent) · 53 unmodified lines
181 : _mem{ std::make_unique<vm_stack_layout>(stack_extent) }189 : _mem{ std::make_unique<vm_stack_layout>(stack_extent) }
182{190{
183 assert(0 < stack_extent && stack_extent < static_cast<std::size_t>(std::numeric_limits<word_t>::max()));191 assert(0 < stack_extent && stack_extent < static_cast<std::size_t>(std::numeric_limits<word_t>::max()));
184 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm stack");192 log_msg(component_trace_t::memory, log_level_t::debug, "init: vm stack");
185}193}
186 194
187vm_stack_t::~vm_stack_t()195vm_stack_t::~vm_stack_t()
@@ -195,7 +203,7 @@ vm_stack_t::~vm_stack_t() · 7 unmodified lines
195 _mem->release();203 _mem->release();
196 _mem.reset();204 _mem.reset();
197 205
198 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm stack");206 log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm stack");
199}207}
200 208
201vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> frame_type)209vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> frame_type)
@@ -244,8 +252,8 @@ vm_frame_t *vm_stack_t::push_frame() · 42 unmodified lines
244 252
245 layout->top_frame = new_top_frame;253 layout->top_frame = new_top_frame;
246 254
247 if (debug::is_component_tracing_enabled<debug::component_trace_t::stack>())255 if (disvm::debug::is_component_tracing_enabled<component_trace_t::stack>())
248 debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "update: push vm frame: %#" PRIxPTR, new_top_frame);256 log_msg(component_trace_t::stack, log_level_t::debug, "update: push vm frame: %#" PRIxPTR, new_top_frame);
249 257
250 return new_top_frame;258 return new_top_frame;
251}259}
@@ -284,8 +292,8 @@ vm_frame_t *vm_stack_t::pop_frame() · 32 unmodified lines
284 }292 }
285 }293 }
286 294
287 if (debug::is_component_tracing_enabled<debug::component_trace_t::stack>())295 if (disvm::debug::is_component_tracing_enabled<component_trace_t::stack>())
288 debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "update: pop vm frame: %#" PRIxPTR, current_frame);296 log_msg(component_trace_t::stack, log_level_t::debug, "update: pop vm frame: %#" PRIxPTR, current_frame);
289 297
290 return current_frame;298 return current_frame;
291}299}
src/vm/string.cpp+24−19
@@ -11,8 +11,13 @@ · 10 unmodified lines
11#include <debug.h>11#include <debug.h>
12#include <exceptions.h>12#include <exceptions.h>
13 13
14using namespace disvm;14using disvm::debug::component_trace_t;
15using namespace disvm::runtime;15using disvm::debug::log_level_t;
16
17using disvm::runtime::intrinsic_type_desc;
18using disvm::runtime::type_descriptor_t;
19using disvm::runtime::vm_string_t;
20using disvm::runtime::word_t;
16 21
17std::shared_ptr<const type_descriptor_t> vm_string_t::type_desc()22std::shared_ptr<const type_descriptor_t> vm_string_t::type_desc()
18{23{
@@ -47,8 +52,8 @@ namespace · 28 unmodified lines
47 {52 {
48 for (auto i = word_t{ 0 }; i < len; ++i)53 for (auto i = word_t{ 0 }; i < len; ++i)
49 {54 {
50 const auto sc1 = static_cast<runtime::rune_t>(s1[i]);55 const auto sc1 = static_cast<disvm::runtime::rune_t>(s1[i]);
51 const auto sc2 = static_cast<runtime::rune_t>(s2[i]);56 const auto sc2 = static_cast<disvm::runtime::rune_t>(s2[i]);
52 57
53 if (sc1 != sc2)58 if (sc1 != sc2)
54 return (sc1 < sc2) ? (-1) : 1;59 return (sc1 < sc2) ? (-1) : 1;
@@ -128,10 +133,10 @@ namespace · 73 unmodified lines
128 }133 }
129 134
130 template<>135 template<>
131 void copy_characters_to(runtime::rune_t *dest, word_t dest_start, const runtime::rune_t *source, word_t source_length)136 void copy_characters_to(disvm::runtime::rune_t *dest, word_t dest_start, const disvm::runtime::rune_t *source, word_t source_length)
132 {137 {
133 assert(dest != nullptr && source != nullptr && dest != source);138 assert(dest != nullptr && source != nullptr && dest != source);
134 std::memcpy((dest + dest_start), source, (source_length * sizeof(runtime::rune_t)));139 std::memcpy((dest + dest_start), source, (source_length * sizeof(disvm::runtime::rune_t)));
135 }140 }
136 141
137 void combine(142 void combine(
@@ -146,14 +151,14 @@ namespace · 8 unmodified lines
146 {151 {
147 if (dest_is_rune)152 if (dest_is_rune)
148 {153 {
149 auto dest_rune = reinterpret_cast<runtime::rune_t *>(dest);154 auto dest_rune = reinterpret_cast<disvm::runtime::rune_t *>(dest);
150 if (source1_is_rune)155 if (source1_is_rune)
151 copy_characters_to(dest_rune, 0, reinterpret_cast<const runtime::rune_t *>(source1), source1_length);156 copy_characters_to(dest_rune, 0, reinterpret_cast<const disvm::runtime::rune_t *>(source1), source1_length);
152 else157 else
153 copy_characters_to(dest_rune, 0, source1, source1_length);158 copy_characters_to(dest_rune, 0, source1, source1_length);
154 159
155 if (source2_is_rune)160 if (source2_is_rune)
156 copy_characters_to(dest_rune, source1_length, reinterpret_cast<const runtime::rune_t *>(source2), source2_length);161 copy_characters_to(dest_rune, source1_length, reinterpret_cast<const disvm::runtime::rune_t *>(source2), source2_length);
157 else162 else
158 copy_characters_to(dest_rune, source1_length, source2, source2_length);163 copy_characters_to(dest_rune, source1_length, source2, source2_length);
159 }164 }
@@ -235,8 +240,8 @@ vm_string_t::vm_string_t(std::size_t encoded_str_len, const uint8_t *encoded_str · 75 unmodified lines
235 encoded_str += utf8::decode(encoded_str, rune_dest[i]);240 encoded_str += utf8::decode(encoded_str, rune_dest[i]);
236 }241 }
237 242
238 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())243 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
239 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm string: %d %d >>%s<<", _length, (_length_max * _character_size), dest);244 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm string: %d %d >>%s<<", _length, (_length_max * _character_size), dest);
240}245}
241 246
242vm_string_t::vm_string_t(const vm_string_t &s1, const vm_string_t &s2)247vm_string_t::vm_string_t(const vm_string_t &s1, const vm_string_t &s2)
@@ -297,8 +302,8 @@ vm_string_t::vm_string_t(const vm_string_t &other, word_t begin_index, word_t en · 54 unmodified lines
297 const auto length_in_bytes = _length * _character_size;302 const auto length_in_bytes = _length * _character_size;
298 std::memcpy(dest, (src + (begin_index * _character_size)), length_in_bytes);303 std::memcpy(dest, (src + (begin_index * _character_size)), length_in_bytes);
299 304
300 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())305 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
301 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm string: %#" PRIxPTR " %d %d %#" PRIxPTR, &other, begin_index, end_index, this);306 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "copy: vm string: %#" PRIxPTR " %d %d %#" PRIxPTR, &other, begin_index, end_index, this);
302}307}
303 308
304vm_string_t::~vm_string_t()309vm_string_t::~vm_string_t()
@@ -314,8 +319,8 @@ vm_string_t::~vm_string_t() · 9 unmodified lines
314 debug::assign_debug_pointer(&source);319 debug::assign_debug_pointer(&source);
315 debug::assign_debug_pointer(&_encoded_str);320 debug::assign_debug_pointer(&_encoded_str);
316 321
317 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())322 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
318 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm string");323 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm string");
319}324}
320 325
321vm_string_t &vm_string_t::append(const vm_string_t &other)326vm_string_t &vm_string_t::append(const vm_string_t &other)
@@ -389,7 +394,7 @@ word_t vm_string_t::get_length() const · 67 unmodified lines
389 return _length;394 return _length;
390}395}
391 396
392runtime::rune_t vm_string_t::get_rune(word_t index) const397disvm::runtime::rune_t vm_string_t::get_rune(word_t index) const
393{398{
394 if (index < 0 || _length <= index)399 if (index < 0 || _length <= index)
395 throw index_out_of_range_memory{ 0, _length - 1, index };400 throw index_out_of_range_memory{ 0, _length - 1, index };
@@ -401,12 +406,12 @@ runtime::rune_t vm_string_t::get_rune(word_t index) const · 5 unmodified lines
401 406
402 // Check if multi-byte or ASCII407 // Check if multi-byte or ASCII
403 if (_character_size != sizeof(char))408 if (_character_size != sizeof(char))
404 return reinterpret_cast<const rune_t *>(source)[index];409 return reinterpret_cast<const disvm::runtime::rune_t *>(source)[index];
405 else410 else
406 return static_cast<const rune_t>(source[index]);411 return static_cast<const disvm::runtime::rune_t>(source[index]);
407}412}
408 413
409void vm_string_t::set_rune(word_t index, rune_t value)414void vm_string_t::set_rune(word_t index, disvm::runtime::rune_t value)
410{415{
411 // This function does not adhere to the immutable string contract.416 // This function does not adhere to the immutable string contract.
412 // Therefore, it is unsafe to call this function if there is more417 // Therefore, it is unsafe to call this function if there is more
src/vm/sys/Sysmod.cpp+62−47
@@ -18,8 +18,23 @@ · 17 unmodified lines
18#include "Sysmod.h"18#include "Sysmod.h"
19#include "sys_utils.h"19#include "sys_utils.h"
20 20
21using namespace disvm;21using disvm::vm_t;
22using namespace disvm::runtime;22
23using disvm::debug::component_trace_t;
24using disvm::debug::log_level_t;
25
26using disvm::runtime::dereference_nil;
27using disvm::runtime::intrinsic_type_desc;
28using disvm::runtime::out_of_range_memory;
29using disvm::runtime::type_descriptor_t;
30using disvm::runtime::vm_alloc_t;
31using disvm::runtime::vm_array_t;
32using disvm::runtime::vm_list_t;
33using disvm::runtime::vm_string_t;
34using disvm::runtime::vm_syscall_exception;
35using disvm::runtime::vm_system_exception;
36using disvm::runtime::vm_user_exception;
37using disvm::runtime::word_t;
23 38
24namespace39namespace
25{40{
@@ -85,16 +100,16 @@ namespace · 59 unmodified lines
85 {100 {
86 auto fd = fileHandle->get_allocation<vm_fd_t>();101 auto fd = fileHandle->get_allocation<vm_fd_t>();
87 102
88 if (debug::is_component_tracing_enabled<debug::component_trace_t::builtin>())103 if (disvm::debug::is_component_tracing_enabled<component_trace_t::builtin>())
89 {104 {
90 debug::log_msg(105 disvm::debug::log_msg(
91 debug::component_trace_t::builtin,106 component_trace_t::builtin,
92 debug::log_level_t::debug,107 log_level_t::debug,
93 "sys: fd: finalize: %d",108 "sys: fd: finalize: %d",
94 fd->fd);109 fd->fd);
95 }110 }
96 111
97 sys::drop_fd_record(fd->fd);112 disvm::runtime::sys::drop_fd_record(fd->fd);
98 fd->~vm_fd_t();113 fd->~vm_fd_t();
99 }114 }
100 115
@@ -102,7 +117,7 @@ namespace · 1 unmodified line
102 {117 {
103 assert(s != nullptr);118 assert(s != nullptr);
104 auto alloc = vm_alloc_t::allocate(T_FD);119 auto alloc = vm_alloc_t::allocate(T_FD);
105 const auto fd = sys::create_fd_record(alloc);120 const auto fd = disvm::runtime::sys::create_fd_record(alloc);
106 auto vm_fd = ::new(alloc->get_allocation())vm_fd_t{ fd, std::move(s), fd_mode, fd_path };121 auto vm_fd = ::new(alloc->get_allocation())vm_fd_t{ fd, std::move(s), fd_mode, fd_path };
107 122
108 return std::make_tuple(vm_fd->fd, alloc);123 return std::make_tuple(vm_fd->fd, alloc);
@@ -143,8 +158,8 @@ namespace · 34 unmodified lines
143 158
144 ~vm_fd_t()159 ~vm_fd_t()
145 {160 {
146 debug::assign_debug_pointer(&_istream);161 disvm::debug::assign_debug_pointer(&_istream);
147 debug::assign_debug_pointer(&_ostream);162 disvm::debug::assign_debug_pointer(&_ostream);
148 if (_stream != nullptr)163 if (_stream != nullptr)
149 _stream.reset();164 _stream.reset();
150 165
@@ -153,7 +168,7 @@ namespace · 2 unmodified lines
153 std::remove(_fd_path->str());168 std::remove(_fd_path->str());
154 169
155 dec_ref_count_and_free(_fd_path);170 dec_ref_count_and_free(_fd_path);
156 debug::assign_debug_pointer(&_fd_path);171 disvm::debug::assign_debug_pointer(&_fd_path);
157 }172 }
158 173
159 word_t get_original_mode() const174 word_t get_original_mode() const
@@ -217,7 +232,7 @@ namespace · 57 unmodified lines
217 disvm::runtime::pointer_t base)232 disvm::runtime::pointer_t base)
218 {233 {
219 auto static_buffer = std::array<char, 1024>{};234 auto static_buffer = std::array<char, 1024>{};
220 auto written = sys::printf_to_buffer(vm, msg_fmt, msg_args, base, static_buffer.size(), static_buffer.data());235 auto written = disvm::runtime::sys::printf_to_buffer(vm, msg_fmt, msg_args, base, static_buffer.size(), static_buffer.data());
221 if (written >= 0)236 if (written >= 0)
222 {237 {
223 fd.write(vm, written, static_buffer.data());238 fd.write(vm, written, static_buffer.data());
@@ -225,7 +240,7 @@ namespace · 1 unmodified line
225 else240 else
226 {241 {
227 auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2);242 auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2);
228 written = sys::printf_to_dynamic_buffer(vm, msg_fmt, msg_args, base, dynamic_buffer);243 written = disvm::runtime::sys::printf_to_dynamic_buffer(vm, msg_fmt, msg_args, base, dynamic_buffer);
229 fd.write(vm, written, dynamic_buffer.data());244 fd.write(vm, written, dynamic_buffer.data());
230 }245 }
231 246
@@ -270,7 +285,7 @@ namespace · 38 unmodified lines
270void285void
271Sysmodinit(void)286Sysmodinit(void)
272{287{
273 builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab);288 disvm::runtime::builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab);
274 T_Qid = type_descriptor_t::create(sizeof(Sys_Qid), sizeof(Sys_Qid_map), Sys_Qid_map);289 T_Qid = type_descriptor_t::create(sizeof(Sys_Qid), sizeof(Sys_Qid_map), Sys_Qid_map);
275 T_Dir = type_descriptor_t::create(sizeof(Sys_Dir), sizeof(Sys_Dir_map), Sys_Dir_map);290 T_Dir = type_descriptor_t::create(sizeof(Sys_Dir), sizeof(Sys_Dir_map), Sys_Dir_map);
276 T_FD = type_descriptor_t::create(sizeof(vm_fd_t), sizeof(Sys_FD_map), Sys_FD_map, vm_fd_t::finalizer);291 T_FD = type_descriptor_t::create(sizeof(vm_fd_t), sizeof(Sys_FD_map), Sys_FD_map, vm_fd_t::finalizer);
@@ -281,23 +296,23 @@ Sysmodinit(void) · 4 unmodified lines
281 296
282 {297 {
283 auto vm_stdin = vm_alloc_t::allocate(T_FD);298 auto vm_stdin = vm_alloc_t::allocate(T_FD);
284 const auto fd = sys::create_fd_record(vm_stdin);299 const auto fd = disvm::runtime::sys::create_fd_record(vm_stdin);
285 fd_stdin = ::new(vm_stdin->get_allocation())vm_fd_t{ fd, std::cin };300 fd_stdin = ::new(vm_stdin->get_allocation())vm_fd_t{ fd, std::cin };
286 debug::log_msg(debug::component_trace_t::builtin, debug::log_level_t::debug, "sys: stdin: %d", fd);301 disvm::debug::log_msg(component_trace_t::builtin, log_level_t::debug, "sys: stdin: %d", fd);
287 }302 }
288 303
289 {304 {
290 auto vm_stdout = vm_alloc_t::allocate(T_FD);305 auto vm_stdout = vm_alloc_t::allocate(T_FD);
291 const auto fd = sys::create_fd_record(vm_stdout);306 const auto fd = disvm::runtime::sys::create_fd_record(vm_stdout);
292 fd_stdout = ::new(vm_stdout->get_allocation())vm_fd_t{ fd, std::cout };307 fd_stdout = ::new(vm_stdout->get_allocation())vm_fd_t{ fd, std::cout };
293 debug::log_msg(debug::component_trace_t::builtin, debug::log_level_t::debug, "sys: stdout: %d", fd);308 disvm::debug::log_msg(component_trace_t::builtin, log_level_t::debug, "sys: stdout: %d", fd);
294 }309 }
295 310
296 {311 {
297 auto vm_stderr = vm_alloc_t::allocate(T_FD);312 auto vm_stderr = vm_alloc_t::allocate(T_FD);
298 const auto fd = sys::create_fd_record(vm_stderr);313 const auto fd = disvm::runtime::sys::create_fd_record(vm_stderr);
299 fd_stderr = ::new(vm_stderr->get_allocation())vm_fd_t{ fd, std::cerr };314 fd_stderr = ::new(vm_stderr->get_allocation())vm_fd_t{ fd, std::cerr };
300 debug::log_msg(debug::component_trace_t::builtin, debug::log_level_t::debug, "sys: stderr: %d", fd);315 disvm::debug::log_msg(component_trace_t::builtin, log_level_t::debug, "sys: stderr: %d", fd);
301 }316 }
302}317}
303 318
@@ -339,21 +354,21 @@ Sys_byte2char(vm_registers_t &r, vm_t &vm) · 35 unmodified lines
339 fp.ret->t1 = 0;354 fp.ret->t1 = 0;
340 fp.ret->t2 = 0;355 fp.ret->t2 = 0;
341 356
342 auto state = utf8::decode_state_t::accept;357 auto state = disvm::runtime::utf8::decode_state_t::accept;
343 auto result = runtime::rune_t{};358 auto result = disvm::runtime::rune_t{};
344 const auto buffer_len = buffer->get_length();359 const auto buffer_len = buffer->get_length();
345 for (auto i = n; i < buffer_len; ++i)360 for (auto i = n; i < buffer_len; ++i)
346 {361 {
347 auto b = buffer->at<byte_t>(i);362 auto b = buffer->at<byte_t>(i);
348 state = utf8::decode_step(state, result, b);363 state = disvm::runtime::utf8::decode_step(state, result, b);
349 if (state == utf8::decode_state_t::accept)364 if (state == disvm::runtime::utf8::decode_state_t::accept)
350 {365 {
351 fp.ret->t0 = result;366 fp.ret->t0 = result;
352 fp.ret->t1 = (i - n) + 1; // Number of bytes consumed367 fp.ret->t1 = (i - n) + 1; // Number of bytes consumed
353 fp.ret->t2 = 1;368 fp.ret->t2 = 1;
354 return;369 return;
355 }370 }
356 else if (state == utf8::decode_state_t::reject)371 else if (state == disvm::runtime::utf8::decode_state_t::reject)
357 {372 {
358 fp.ret->t1 = 1;373 fp.ret->t1 = 1;
359 return;374 return;
@@ -373,13 +388,13 @@ Sys_char2byte(vm_registers_t &r, vm_t &vm) · 13 unmodified lines
373 if (buffer == nullptr || n >= buffer->get_length())388 if (buffer == nullptr || n >= buffer->get_length())
374 throw out_of_range_memory{};389 throw out_of_range_memory{};
375 390
376 const auto rune = static_cast<runtime::rune_t>(fp.c);391 const auto rune = static_cast<disvm::runtime::rune_t>(fp.c);
377 392
378 static_assert(Sys_UTFmax == sizeof(rune), "UTF max should be same size as rune");393 static_assert(Sys_UTFmax == sizeof(rune), "UTF max should be same size as rune");
379 uint8_t buffer_local[Sys_UTFmax];394 uint8_t buffer_local[Sys_UTFmax];
380 auto begin = buffer_local;395 auto begin = buffer_local;
381 396
382 auto end = utf8::encode(rune, begin);397 auto end = disvm::runtime::utf8::encode(rune, begin);
383 const auto count = static_cast<word_t>(end - begin);398 const auto count = static_cast<word_t>(end - begin);
384 399
385 const auto final_index = n + count;400 const auto final_index = n + count;
@@ -414,12 +429,12 @@ Sys_create(vm_registers_t &r, vm_t &vm) · 28 unmodified lines
414 auto path = vm_alloc_t::from_allocation<vm_string_t>(fp.s);429 auto path = vm_alloc_t::from_allocation<vm_string_t>(fp.s);
415 const auto open_mode = convert_to_openmode(fp.mode);430 const auto open_mode = convert_to_openmode(fp.mode);
416 431
417 auto cfs_flag = sys::cfs_flags_t::none;432 auto cfs_flag = disvm::runtime::sys::cfs_flags_t::none;
418 if (fp.mode & Sys_OEXCL)433 if (fp.mode & Sys_OEXCL)
419 cfs_flag = (sys::cfs_flags_t::atomic | sys::cfs_flags_t::ensure_create);434 cfs_flag = (disvm::runtime::sys::cfs_flags_t::atomic | disvm::runtime::sys::cfs_flags_t::ensure_create);
420 435
421 // [TODO] Apply the requested permissions to the file.436 // [TODO] Apply the requested permissions to the file.
422 auto file_stream = sys::create_file_stream(path->str(), (open_mode | std::ios::binary), cfs_flag);437 auto file_stream = disvm::runtime::sys::create_file_stream(path->str(), (open_mode | std::ios::binary), cfs_flag);
423 438
424 // Return null if file stream is not open.439 // Return null if file stream is not open.
425 if (file_stream == nullptr)440 if (file_stream == nullptr)
@@ -432,11 +447,11 @@ Sys_create(vm_registers_t &r, vm_t &vm) · 6 unmodified lines
432 auto fd = word_t{};447 auto fd = word_t{};
433 std::tie(fd, fd_alloc) = vm_fd_t::create(std::move(file_stream), fp.mode, path);448 std::tie(fd, fd_alloc) = vm_fd_t::create(std::move(file_stream), fp.mode, path);
434 449
435 if (debug::is_component_tracing_enabled<debug::component_trace_t::builtin>())450 if (disvm::debug::is_component_tracing_enabled<component_trace_t::builtin>())
436 {451 {
437 debug::log_msg(452 disvm::debug::log_msg(
438 debug::component_trace_t::builtin,453 component_trace_t::builtin,
439 debug::log_level_t::debug,454 log_level_t::debug,
440 "sys: create: %d >>%s<< %#x %#x",455 "sys: create: %d >>%s<< %#x %#x",
441 fd,456 fd,
442 path->str(),457 path->str(),
@@ -497,7 +512,7 @@ Sys_fildes(vm_registers_t &r, vm_t &vm) · 54 unmodified lines
497 dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret));512 dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret));
498 *fp.ret = nullptr;513 *fp.ret = nullptr;
499 514
500 auto fd = sys::fetch_fd_record(fp.fd);515 auto fd = disvm::runtime::sys::fetch_fd_record(fp.fd);
501 if (fd != nullptr)516 if (fd != nullptr)
502 {517 {
503 fd->add_ref();518 fd->add_ref();
@@ -588,7 +603,7 @@ Sys_open(vm_registers_t &r, vm_t &vm) · 84 unmodified lines
588 const auto open_mode = convert_to_openmode(fp.mode);603 const auto open_mode = convert_to_openmode(fp.mode);
589 604
590 // [TODO] Handle opening devices - not just files (i.e. /dev/random, /dev/source, /proc/1234)605 // [TODO] Handle opening devices - not just files (i.e. /dev/random, /dev/source, /proc/1234)
591 auto file_stream = sys::create_file_stream(path->str(), (open_mode | std::ios::binary));606 auto file_stream = disvm::runtime::sys::create_file_stream(path->str(), (open_mode | std::ios::binary));
592 607
593 // Return null if file stream is not open.608 // Return null if file stream is not open.
594 if (file_stream == nullptr)609 if (file_stream == nullptr)
@@ -601,11 +616,11 @@ Sys_open(vm_registers_t &r, vm_t &vm) · 6 unmodified lines
601 auto fd = word_t{};616 auto fd = word_t{};
602 std::tie(fd, fd_alloc) = vm_fd_t::create(std::move(file_stream), fp.mode, path);617 std::tie(fd, fd_alloc) = vm_fd_t::create(std::move(file_stream), fp.mode, path);
603 618
604 if (debug::is_component_tracing_enabled<debug::component_trace_t::builtin>())619 if (disvm::debug::is_component_tracing_enabled<component_trace_t::builtin>())
605 {620 {
606 debug::log_msg(621 disvm::debug::log_msg(
607 debug::component_trace_t::builtin,622 component_trace_t::builtin,
608 debug::log_level_t::debug,623 log_level_t::debug,
609 "sys: open: %d >>%s<< %#x",624 "sys: open: %d >>%s<< %#x",
610 fd,625 fd,
611 path->str(),626 path->str(),
@@ -746,7 +761,7 @@ Sys_sprint(vm_registers_t &r, vm_t &vm) · 134 unmodified lines
746 vm_string_t *new_string;761 vm_string_t *new_string;
747 auto static_buffer = std::array<char, 128>{};762 auto static_buffer = std::array<char, 128>{};
748 auto msg_args = &fp.vargs;763 auto msg_args = &fp.vargs;
749 auto written = sys::printf_to_buffer(vm, *str, msg_args, fp_base, static_buffer.size(), static_buffer.data());764 auto written = disvm::runtime::sys::printf_to_buffer(vm, *str, msg_args, fp_base, static_buffer.size(), static_buffer.data());
750 if (written >= 0)765 if (written >= 0)
751 {766 {
752 new_string = new vm_string_t{ static_cast<std::size_t>(written), reinterpret_cast<uint8_t *>(static_buffer.data()) };767 new_string = new vm_string_t{ static_cast<std::size_t>(written), reinterpret_cast<uint8_t *>(static_buffer.data()) };
@@ -754,7 +769,7 @@ Sys_sprint(vm_registers_t &r, vm_t &vm) · 1 unmodified line
754 else769 else
755 {770 {
756 auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2);771 auto dynamic_buffer = std::vector<char>(static_buffer.size() * 2);
757 written = sys::printf_to_dynamic_buffer(vm, *str, msg_args, fp_base, dynamic_buffer);772 written = disvm::runtime::sys::printf_to_dynamic_buffer(vm, *str, msg_args, fp_base, dynamic_buffer);
758 new_string = new vm_string_t{ static_cast<std::size_t>(written), reinterpret_cast<uint8_t *>(dynamic_buffer.data()) };773 new_string = new vm_string_t{ static_cast<std::size_t>(written), reinterpret_cast<uint8_t *>(dynamic_buffer.data()) };
759 }774 }
760 775
@@ -777,7 +792,7 @@ Sys_stream(vm_registers_t &r, vm_t &vm) · 16 unmodified lines
777 792
778namespace793namespace
779{794{
780 bool is_delim(const runtime::rune_t c, const vm_string_t &delim)795 bool is_delim(const disvm::runtime::rune_t c, const vm_string_t &delim)
781 {796 {
782 const auto max = delim.get_length();797 const auto max = delim.get_length();
783 798
@@ -837,7 +852,7 @@ Sys_tokenize(vm_registers_t &r, vm_t &vm) · 53 unmodified lines
837 if (delim == nullptr || delim->get_length() == 0)852 if (delim == nullptr || delim->get_length() == 0)
838 {853 {
839 // Add supplied string to list854 // Add supplied string to list
840 pt_ref(curr_node->value()) = s->get_allocation();855 disvm::runtime::pt_ref(curr_node->value()) = s->get_allocation();
841 s->add_ref();856 s->add_ref();
842 857
843 fp.ret->t0 = 1;858 fp.ret->t0 = 1;
@@ -881,7 +896,7 @@ Sys_tokenize(vm_registers_t &r, vm_t &vm) · 37 unmodified lines
881 curr_node = new vm_list_t{ intrinsic_type_desc::type<pointer_t>() };896 curr_node = new vm_list_t{ intrinsic_type_desc::type<pointer_t>() };
882 897
883 const auto token = new vm_string_t{ *s, begin, end };898 const auto token = new vm_string_t{ *s, begin, end };
884 pt_ref(curr_node->value()) = token->get_allocation();899 disvm::runtime::pt_ref(curr_node->value()) = token->get_allocation();
885 900
886 // Previous node is initially null901 // Previous node is initially null
887 if (prev_node != nullptr)902 if (prev_node != nullptr)
@@ -921,7 +936,7 @@ Sys_utfbytes(vm_registers_t &r, vm_t &vm) · 33 unmodified lines
921 936
922 auto raw_buffer = reinterpret_cast<uint8_t *>(buffer->at(0));937 auto raw_buffer = reinterpret_cast<uint8_t *>(buffer->at(0));
923 938
924 const auto len = utf8::count_codepoints(raw_buffer, n);939 const auto len = disvm::runtime::utf8::count_codepoints(raw_buffer, n);
925 *fp.ret = static_cast<word_t>(len.byte_count);940 *fp.ret = static_cast<word_t>(len.byte_count);
926 assert(*fp.ret <= n && "Code points should not exceed number of bytes processed");941 assert(*fp.ret <= n && "Code points should not exceed number of bytes processed");
927}942}
@@ -936,7 +951,7 @@ Sys_werrstr(vm_registers_t &r, vm_t &vm) · 8 unmodified lines
936 if (s != nullptr)951 if (s != nullptr)
937 new_err = s->str();952 new_err = s->str();
938 953
939 push_syscall_error_message(vm, new_err);954 disvm::runtime::push_syscall_error_message(vm, new_err);
940 *fp.ret = 0;955 *fp.ret = 0;
941}956}
942 957
src/vm/sys/Sysmod.h+9−2
@@ -11,8 +11,15 @@ · 10 unmodified lines
11#include <disvm.h>11#include <disvm.h>
12#include <builtin_module.h>12#include <builtin_module.h>
13 13
14using namespace disvm;14using disvm::vm_t;
15using namespace disvm::runtime;15
16using disvm::runtime::byte_t;
17using disvm::runtime::word_t;
18using disvm::runtime::big_t;
19using disvm::runtime::real_t;
20using disvm::runtime::pointer_t;
21using disvm::runtime::vm_registers_t;
22using disvm::runtime::vm_frame_base_alloc_t;
16 23
17struct Sys_Qid24struct Sys_Qid
18{25{
src/vm/sys/fd_manager.cpp+2−1
@@ -11,7 +11,8 @@ · 10 unmodified lines
11#include <vm_memory.h>11#include <vm_memory.h>
12#include "sys_utils.h"12#include "sys_utils.h"
13 13
14using namespace disvm::runtime;14using disvm::runtime::vm_alloc_t;
15using disvm::runtime::word_t;
15 16
16namespace17namespace
17{18{
src/vm/sys/file_system.cpp+0−2
@@ -10,8 +10,6 @@ · 9 unmodified lines
10#include <utils.h>10#include <utils.h>
11#include "sys_utils.h"11#include "sys_utils.h"
12 12
13using namespace disvm::runtime;
14
15namespace13namespace
16{14{
17 std::mutex _create_file_stream_mutex;15 std::mutex _create_file_stream_mutex;
src/vm/sys/print.cpp+4−2
@@ -9,8 +9,10 @@ · 8 unmodified lines
9#include <utf8.h>9#include <utf8.h>
10#include "sys_utils.h"10#include "sys_utils.h"
11 11
12using namespace disvm::runtime;12using disvm::runtime::byte_t;
13using namespace disvm::runtime::utf8;13using disvm::runtime::pointer_t;
14using disvm::runtime::vm_array_t;
15using disvm::runtime::word_t;
14 16
15namespace17namespace
16{18{
src/vm/thread.cpp+38−19
@@ -16,8 +16,28 @@ · 15 unmodified lines
16#include "execution_table.h"16#include "execution_table.h"
17#include "tool_dispatch.h"17#include "tool_dispatch.h"
18 18
19using namespace disvm;19using disvm::vm_t;
20using namespace disvm::runtime;20using disvm::opcode_t;
21
22using disvm::debug::component_trace_t;
23using disvm::debug::log_level_t;
24
25using disvm::runtime::type_descriptor_t;
26using disvm::runtime::word_t;
27using disvm::runtime::pointer_t;
28using disvm::runtime::vm_pc_t;
29using disvm::runtime::vm_exec_op_t;
30using disvm::runtime::vm_thread_t;
31using disvm::runtime::vm_frame_t;
32using disvm::runtime::vm_module_t;
33using disvm::runtime::vm_module_ref_t;
34using disvm::runtime::vm_registers_t;
35using disvm::runtime::address_mode_t;
36using disvm::runtime::address_mode_middle_t;
37using disvm::runtime::vm_trap_flags_t;
38using disvm::runtime::vm_thread_state_t;
39using disvm::runtime::vm_tool_dispatch_t;
40using disvm::runtime::vm_system_exception;
21 41
22namespace42namespace
23{43{
@@ -30,11 +50,11 @@ namespace · 6 unmodified lines
30 50
31#ifndef NDEBUG51#ifndef NDEBUG
32 // This is a perf critical function so logging is only available in debug builds52 // This is a perf critical function so logging is only available in debug builds
33 if (debug::is_component_tracing_enabled<debug::component_trace_t::addressing>())53 if (disvm::debug::is_component_tracing_enabled<component_trace_t::addressing>())
34 {54 {
35 debug::log_msg(55 disvm::debug::log_msg(
36 debug::component_trace_t::addressing,56 component_trace_t::addressing,
37 debug::log_level_t::debug,57 log_level_t::debug,
38 "decode: registers: %d (%#" PRIxPTR " %#" PRIxPTR " %#" PRIxPTR ")",58 "decode: registers: %d (%#" PRIxPTR " %#" PRIxPTR " %#" PRIxPTR ")",
39 inst.opcode,59 inst.opcode,
40 reg.src,60 reg.src,
@@ -130,7 +150,7 @@ vm_thread_t::vm_thread_t( · 89 unmodified lines
130 // Pushing the initial frame sets the FP register150 // Pushing the initial frame sets the FP register
131 _registers.stack.push_frame();151 _registers.stack.push_frame();
132 152
133 debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "init: vm thread: %d %d", _thread_id, _parent_thread_id);153 disvm::debug::log_msg(component_trace_t::thread, log_level_t::debug, "init: vm thread: %d %d", _thread_id, _parent_thread_id);
134}154}
135 155
136vm_thread_t::vm_thread_t(156vm_thread_t::vm_thread_t(
@@ -159,14 +179,14 @@ vm_thread_t::vm_thread_t( · 22 unmodified lines
159 // Copy over the frame into this thread - pass arguments to the thread179 // Copy over the frame into this thread - pass arguments to the thread
160 current_frame->copy_frame_contents(initial_frame);180 current_frame->copy_frame_contents(initial_frame);
161 181
162 if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>())182 if (disvm::debug::is_component_tracing_enabled<component_trace_t::thread>())
163 debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "init: vm thread: %d %d", _thread_id, _parent_thread_id);183 disvm::debug::log_msg(component_trace_t::thread, log_level_t::debug, "init: vm thread: %d %d", _thread_id, _parent_thread_id);
164}184}
165 185
166vm_thread_t::~vm_thread_t()186vm_thread_t::~vm_thread_t()
167{187{
168 if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>())188 if (disvm::debug::is_component_tracing_enabled<component_trace_t::thread>())
169 debug::log_msg(debug::component_trace_t::thread, debug::log_level_t::debug, "destroy: vm thread: %d %d", _thread_id, _parent_thread_id);189 disvm::debug::log_msg(component_trace_t::thread, log_level_t::debug, "destroy: vm thread: %d %d", _thread_id, _parent_thread_id);
170 190
171 free_memory(_error_message);191 free_memory(_error_message);
172 debug::assign_debug_pointer(&_error_message);192 debug::assign_debug_pointer(&_error_message);
@@ -187,7 +207,7 @@ namespace · 14 unmodified lines
187 static void after_exec(vm_registers_t &r, vm_t &)207 static void after_exec(vm_registers_t &r, vm_t &)
188 {208 {
189 if (r.trap_flags == vm_trap_flags_t::none209 if (r.trap_flags == vm_trap_flags_t::none
190 || !util::has_flag(r.trap_flags, vm_trap_flags_t::instruction))210 || !disvm::util::has_flag(r.trap_flags, vm_trap_flags_t::instruction))
191 return;211 return;
192 212
193 auto tool_dispatch = r.tool_dispatch.load();213 auto tool_dispatch = r.tool_dispatch.load();
@@ -217,13 +237,12 @@ namespace · 23 unmodified lines
217 assert(!r.module_ref->is_builtin_module() && "Interpreter thread is unable to execute native instructions");237 assert(!r.module_ref->is_builtin_module() && "Interpreter thread is unable to execute native instructions");
218 const auto &inst = code_section[r.pc].op;238 const auto &inst = code_section[r.pc].op;
219 const auto opcode = static_cast<std::size_t>(inst.opcode);239 const auto opcode = static_cast<std::size_t>(inst.opcode);
220 if (static_cast<std::size_t>(opcode_t::last_opcode) < opcode)240 assert(opcode <= static_cast<std::size_t>(opcode_t::last_opcode));
221 throw vm_system_exception{ "Unknown op-code" };
222 241
223 // Instruction is valid, decode and update registers for operation242 // Instruction is valid, decode and update registers for operation
224 decode_address(inst, r);243 decode_address(inst, r);
225 r.next_pc = (r.pc + 1);244 r.next_pc = (r.pc + 1);
226 vm_exec_table[opcode](r, vm);245 disvm::runtime::vm_exec_table[opcode](r, vm);
227 r.pc = r.next_pc;246 r.pc = r.next_pc;
228 247
229 EXEC_DETOUR::after_exec(r, vm);248 EXEC_DETOUR::after_exec(r, vm);
@@ -280,11 +299,11 @@ vm_thread_state_t vm_thread_t::execute(vm_t &vm, const uint32_t quanta) · 50 unmodified lines
280 }299 }
281 300
282 // Log the execution result301 // Log the execution result
283 if (debug::is_component_tracing_enabled<debug::component_trace_t::thread>())302 if (disvm::debug::is_component_tracing_enabled<component_trace_t::thread>())
284 {303 {
285 debug::log_msg(304 disvm::debug::log_msg(
286 debug::component_trace_t::thread,305 component_trace_t::thread,
287 debug::log_level_t::debug,306 log_level_t::debug,
288 "status: vm thread: execute: %d %d %d %d",307 "status: vm thread: execute: %d %d %d %d",
289 _thread_id,308 _thread_id,
290 (quanta - _registers.current_thread_quanta),309 (quanta - _registers.current_thread_quanta),
src/vm/tool_dispatch.cpp+36−17
@@ -14,8 +14,27 @@ · 13 unmodified lines
14#include <utils.h>14#include <utils.h>
15#include "tool_dispatch.h"15#include "tool_dispatch.h"
16 16
17using namespace disvm;17using disvm::vm_t;
18using namespace disvm::runtime;18using disvm::opcode_t;
19using disvm::loaded_vm_module_t;
20
21using disvm::debug::component_trace_t;
22using disvm::debug::log_level_t;
23
24using disvm::runtime::cookie_t;
25using disvm::runtime::vm_pc_t;
26using disvm::runtime::vm_module_t;
27using disvm::runtime::vm_thread_t;
28using disvm::runtime::vm_registers_t;
29using disvm::runtime::vm_alloc_t;
30using disvm::runtime::vm_string_t;
31using disvm::runtime::vm_tool_t;
32using disvm::runtime::vm_tool_dispatch_t;
33using disvm::runtime::vm_trap_flags_t;
34using disvm::runtime::vm_event_t;
35using disvm::runtime::vm_event_context_t;
36using disvm::runtime::vm_event_callback_t;
37using disvm::runtime::breakpoint_details_t;
19 38
20// Empty destructor for vm tool 'interface'39// Empty destructor for vm tool 'interface'
21vm_tool_t::~vm_tool_t()40vm_tool_t::~vm_tool_t()
@@ -38,7 +57,7 @@ vm_tool_dispatch_t::~vm_tool_dispatch_t() · 16 unmodified lines
38 t.second->on_unload();57 t.second->on_unload();
39}58}
40 59
41std::size_t vm_tool_dispatch_t::load_tool(std::shared_ptr<runtime::vm_tool_t> tool)60std::size_t vm_tool_dispatch_t::load_tool(std::shared_ptr<vm_tool_t> tool)
42{61{
43 static std::size_t _tool_id_counter{ 1 };62 static std::size_t _tool_id_counter{ 1 };
44 63
@@ -58,16 +77,16 @@ std::size_t vm_tool_dispatch_t::load_tool(std::shared_ptr<runtime::vm_tool_t> to · 13 unmodified lines
58 }77 }
59 catch (...)78 catch (...)
60 {79 {
61 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())80 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
62 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::warning, "load: tool: failure");81 disvm::debug::log_msg(component_trace_t::tool, log_level_t::warning, "load: tool: failure");
63 82
64 // The ID is tainted and will not be re-used83 // The ID is tainted and will not be re-used
65 _tools.erase(current_id);84 _tools.erase(current_id);
66 throw;85 throw;
67 }86 }
68 87
69 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())88 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
70 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "load: tool: %d", current_id);89 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "load: tool: %d", current_id);
71 90
72 return current_id;91 return current_id;
73}92}
@@ -83,8 +102,8 @@ std::size_t vm_tool_dispatch_t::unload_tool(std::size_t tool_id) · 9 unmodified lines
83 auto tool = iter->second;102 auto tool = iter->second;
84 _tools.erase(iter);103 _tools.erase(iter);
85 104
86 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())105 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
87 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "unload: tool: %d", tool_id);106 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "unload: tool: %d", tool_id);
88 107
89 assert(tool != nullptr);108 assert(tool != nullptr);
90 tool->on_unload();109 tool->on_unload();
@@ -222,8 +241,8 @@ cookie_t vm_tool_dispatch_t::subscribe_event(vm_event_t evt, vm_event_callback_t · 131 unmodified lines
222 // Store the cookie with the associate event241 // Store the cookie with the associate event
223 _events.cookie_to_event[cookie_id] = evt;242 _events.cookie_to_event[cookie_id] = evt;
224 243
225 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())244 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
226 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "subscribe: event: %d %d", evt, cookie_id);245 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "subscribe: event: %d %d", evt, cookie_id);
227 246
228 return cookie_id;247 return cookie_id;
229}248}
@@ -242,8 +261,8 @@ void vm_tool_dispatch_t::unsubscribe_event(cookie_t cookie_id) · 12 unmodified lines
242 event_callbacks.erase(cookie_id);261 event_callbacks.erase(cookie_id);
243 _events.cookie_to_event.erase(iter);262 _events.cookie_to_event.erase(iter);
244 263
245 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())264 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
246 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "unsubscribe: event: %d %d", evt, cookie_id);265 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "unsubscribe: event: %d %d", evt, cookie_id);
247}266}
248 267
249cookie_t vm_tool_dispatch_t::set_breakpoint(std::shared_ptr<vm_module_t> module, vm_pc_t pc)268cookie_t vm_tool_dispatch_t::set_breakpoint(std::shared_ptr<vm_module_t> module, vm_pc_t pc)
@@ -280,8 +299,8 @@ cookie_t vm_tool_dispatch_t::set_breakpoint(std::shared_ptr<vm_module_t> module, · 30 unmodified lines
280 // Replace the current opcode with breakpoint299 // Replace the current opcode with breakpoint
281 code_section[pc].op.opcode = opcode_t::brkpt;300 code_section[pc].op.opcode = opcode_t::brkpt;
282 301
283 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())302 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
284 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "breakpoint: set: %d %d >>%s<<", cookie_id, pc, module->module_name->str());303 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "breakpoint: set: %d %d >>%s<<", cookie_id, pc, module->module_name->str());
285 304
286 return cookie_id;305 return cookie_id;
287 }306 }
@@ -324,8 +343,8 @@ void vm_tool_dispatch_t::clear_breakpoint(cookie_t cookie_id) · 36 unmodified lines
324 assert(code_section[target_pc].op.opcode == opcode_t::brkpt);343 assert(code_section[target_pc].op.opcode == opcode_t::brkpt);
325 code_section[target_pc].op.opcode = original_opcode;344 code_section[target_pc].op.opcode = original_opcode;
326 345
327 if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>())346 if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>())
328 debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "breakpoint: unset: %d %d >>%s<<", cookie_id, target_pc, details.module->module_name->str());347 disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "breakpoint: unset: %d %d >>%s<<", cookie_id, target_pc, details.module->module_name->str());
329 348
330 // Clean-up the PC mapping to opcode349 // Clean-up the PC mapping to opcode
331 pc_map.erase(iter_pc);350 pc_map.erase(iter_pc);
src/vm/utf8.cpp+21−20
@@ -12,7 +12,8 @@ · 11 unmodified lines
12#include <utf8.h>12#include <utf8.h>
13#include <exceptions.h>13#include <exceptions.h>
14 14
15using namespace disvm::runtime;15using disvm::runtime::utf8::decode_state_t;
16using disvm::runtime::utf8::utf8_length_t;
16 17
17namespace18namespace
18{19{
@@ -40,21 +41,21 @@ namespace · 21 unmodified lines
40}41}
41 42
42// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.43// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
43utf8::decode_state_t disvm::runtime::utf8::decode_step(utf8::decode_state_t &state, rune_t &codepoint, uint8_t byte)44decode_state_t disvm::runtime::utf8::decode_step(decode_state_t &state, rune_t &codepoint, uint8_t byte)
44{45{
45 auto type = uint32_t{ utf8d[byte] };46 auto type = uint32_t{ utf8d[byte] };
46 47
47 codepoint = (state != utf8::decode_state_t::accept) ?48 codepoint = (state != decode_state_t::accept) ?
48 (byte & 0x3fu) | (codepoint << 6) :49 (byte & 0x3fu) | (codepoint << 6) :
49 (0xff >> type) & (byte);50 (0xff >> type) & (byte);
50 51
51 state = static_cast<utf8::decode_state_t>(utf8d[256 + static_cast<uint32_t>(state) + type]);52 state = static_cast<decode_state_t>(utf8d[256 + static_cast<uint32_t>(state) + type]);
52 return state;53 return state;
53}54}
54 55
55// Adopted from 'countCodePoints(uint8_t* s, size_t* count)'56// Adopted from 'countCodePoints(uint8_t* s, size_t* count)'
56// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.57// See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
57utf8::utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std::size_t max_len)58utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std::size_t max_len)
58{59{
59 if (str == nullptr)60 if (str == nullptr)
60 {61 {
@@ -64,12 +65,12 @@ utf8::utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, c · 3 unmodified lines
64 65
65 auto single_character = rune_t{};66 auto single_character = rune_t{};
66 auto points = std::size_t{ 0 };67 auto points = std::size_t{ 0 };
67 auto state = utf8::decode_state_t::accept;68 auto state = decode_state_t::accept;
68 69
69 auto last = str;70 auto last = str;
70 for (auto curr = last; curr < (str + max_len); ++curr)71 for (auto curr = last; curr < (str + max_len); ++curr)
71 {72 {
72 if (utf8::decode_state_t::accept == utf8::decode_step(state, single_character, *curr))73 if (decode_state_t::accept == decode_step(state, single_character, *curr))
73 {74 {
74 last = curr;75 last = curr;
75 points++;76 points++;
@@ -84,7 +85,7 @@ utf8::utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, c · 8 unmodified lines
84std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint)85std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint)
85{86{
86 assert(str != nullptr);87 assert(str != nullptr);
87 auto state = utf8::decode_state_t::accept;88 auto state = decode_state_t::accept;
88 89
89 codepoint = 0;90 codepoint = 0;
90 auto begin = str;91 auto begin = str;
@@ -93,8 +94,8 @@ std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint) · 2 unmodified lines
93 while (0 != (c = *curr))94 while (0 != (c = *curr))
94 {95 {
95 curr++;96 curr++;
96 state = utf8::decode_step(state, codepoint, c);97 state = decode_step(state, codepoint, c);
97 if (state == utf8::decode_state_t::accept)98 if (state == decode_state_t::accept)
98 return static_cast<std::size_t>(curr - begin);99 return static_cast<std::size_t>(curr - begin);
99 }100 }
100 101
@@ -108,34 +109,34 @@ std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint) · 7 unmodified lines
108uint8_t *disvm::runtime::utf8::encode(const rune_t rune, uint8_t *str)109uint8_t *disvm::runtime::utf8::encode(const rune_t rune, uint8_t *str)
109{110{
110 assert(str != nullptr);111 assert(str != nullptr);
111 if (rune <= utf8::constants::max_codepoint_ascii)112 if (rune <= constants::max_codepoint_ascii)
112 {113 {
113 // Layout: 0xxxxxxx114 // Layout: 0xxxxxxx
114 str[0] = static_cast<uint8_t>(rune);115 str[0] = static_cast<uint8_t>(rune);
115 return (str + 1);116 return (str + 1);
116 }117 }
117 else if (rune <= utf8::constants::max_codepoint_2_byte)118 else if (rune <= constants::max_codepoint_2_byte)
118 {119 {
119 // Layout: 110xxxxx 10xxxxxx120 // Layout: 110xxxxx 10xxxxxx
120 str[0] = static_cast<uint8_t>(0xc0 + (rune >> 6));121 str[0] = static_cast<uint8_t>(0xc0 + (rune >> 6));
121 str[1] = static_cast<uint8_t>(0x80 + (rune & utf8::constants::multi_byte_value_mask));122 str[1] = static_cast<uint8_t>(0x80 + (rune & constants::multi_byte_value_mask));
122 return (str + 2);123 return (str + 2);
123 }124 }
124 else if (rune <= utf8::constants::max_codepoint_3_byte)125 else if (rune <= constants::max_codepoint_3_byte)
125 {126 {
126 // Layout: 1110xxxx 10xxxxxx 10xxxxxx127 // Layout: 1110xxxx 10xxxxxx 10xxxxxx
127 str[0] = static_cast<uint8_t>(0xe0 + (rune >> 12));128 str[0] = static_cast<uint8_t>(0xe0 + (rune >> 12));
128 str[1] = static_cast<uint8_t>(0x80 + ((rune >> 6) & utf8::constants::multi_byte_value_mask));129 str[1] = static_cast<uint8_t>(0x80 + ((rune >> 6) & constants::multi_byte_value_mask));
129 str[2] = static_cast<uint8_t>(0x80 + (rune & utf8::constants::multi_byte_value_mask));130 str[2] = static_cast<uint8_t>(0x80 + (rune & constants::multi_byte_value_mask));
130 return (str + 3);131 return (str + 3);
131 }132 }
132 else if (rune <= utf8::constants::max_codepoint_4_byte)133 else if (rune <= constants::max_codepoint_4_byte)
133 {134 {
134 // Layout: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx135 // Layout: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
135 str[0] = static_cast<uint8_t>(0xf0 + (rune >> 18));136 str[0] = static_cast<uint8_t>(0xf0 + (rune >> 18));
136 str[1] = static_cast<uint8_t>(0x80 + ((rune >> 12) & utf8::constants::multi_byte_value_mask));137 str[1] = static_cast<uint8_t>(0x80 + ((rune >> 12) & constants::multi_byte_value_mask));
137 str[2] = static_cast<uint8_t>(0x80 + ((rune >> 6) & utf8::constants::multi_byte_value_mask));138 str[2] = static_cast<uint8_t>(0x80 + ((rune >> 6) & constants::multi_byte_value_mask));
138 str[3] = static_cast<uint8_t>(0x80 + (rune & utf8::constants::multi_byte_value_mask));139 str[3] = static_cast<uint8_t>(0x80 + (rune & constants::multi_byte_value_mask));
139 return (str + 4);140 return (str + 4);
140 }141 }
141 142
src/vm/vm.cpp+51−26
@@ -19,8 +19,33 @@ · 18 unmodified lines
19#include "tool_dispatch.h"19#include "tool_dispatch.h"
20#include "module_resolver.h"20#include "module_resolver.h"
21 21
22using namespace disvm;22using disvm::vm_t;
23using namespace disvm::runtime;23using disvm::vm_config_t;
24using disvm::vm_version_t;
25using disvm::loaded_vm_module_callback_t;
26
27using disvm::debug::component_trace_t;
28using disvm::debug::log_level_t;
29
30using disvm::runtime::vm_pc_t;
31using disvm::runtime::vm_thread_t;
32using disvm::runtime::vm_memory_allocator_t;
33using disvm::runtime::vm_string_t;
34using disvm::runtime::vm_frame_t;
35using disvm::runtime::vm_module_t;
36using disvm::runtime::vm_module_ref_t;
37using disvm::runtime::vm_module_resolver_t;
38using disvm::runtime::vm_garbage_collector_t;
39using disvm::runtime::vm_scheduler_t;
40using disvm::runtime::vm_scheduler_control_t;
41using disvm::runtime::vm_tool_t;
42using disvm::runtime::vm_tool_dispatch_t;
43using disvm::runtime::vm_user_exception;
44using disvm::runtime::vm_module_exception;
45using disvm::runtime::vm_system_exception;
46using disvm::runtime::default_garbage_collector_t;
47using disvm::runtime::default_scheduler_t;
48using disvm::runtime::default_resolver_t;
24 49
25namespace50namespace
26{51{
@@ -69,8 +94,8 @@ std::string disvm::runtime::pop_syscall_error_message(disvm::vm_t &vm) · 42 unmodified lines
69}94}
70 95
71// Consumed in vm_memory.cpp96// Consumed in vm_memory.cpp
72thread_local vm_memory_alloc_t vm_memory_alloc;97thread_local disvm::runtime::vm_memory_alloc_t vm_memory_alloc;
73thread_local vm_memory_free_t vm_memory_free;98thread_local disvm::runtime::vm_memory_free_t vm_memory_free;
74 99
75namespace100namespace
76{101{
@@ -140,7 +165,7 @@ vm_t::vm_t() · 63 unmodified lines
140 internal_register_system_thread(_gc->get_allocator());165 internal_register_system_thread(_gc->get_allocator());
141 166
142 // Initialize built-in modules.167 // Initialize built-in modules.
143 builtin::initialize_builtin_modules();168 disvm::runtime::builtin::initialize_builtin_modules();
144 169
145 _scheduler = std::make_unique<default_scheduler_t>(*this, default_system_thread_count, default_thread_quanta);170 _scheduler = std::make_unique<default_scheduler_t>(*this, default_system_thread_count, default_thread_quanta);
146 _module_resolvers.push_back(std::make_unique<default_resolver_t>(*this));171 _module_resolvers.push_back(std::make_unique<default_resolver_t>(*this));
@@ -157,7 +182,7 @@ vm_t::vm_t(vm_config_t config) · 10 unmodified lines
157 internal_register_system_thread(_gc->get_allocator());182 internal_register_system_thread(_gc->get_allocator());
158 183
159 // Initialize built-in modules.184 // Initialize built-in modules.
160 builtin::initialize_builtin_modules();185 disvm::runtime::builtin::initialize_builtin_modules();
161 186
162 if (config.create_scheduler == nullptr)187 if (config.create_scheduler == nullptr)
163 _scheduler = std::make_unique<default_scheduler_t>(*this, config.sys_thread_pool_size, config.thread_quanta);188 _scheduler = std::make_unique<default_scheduler_t>(*this, config.sys_thread_pool_size, config.thread_quanta);
@@ -189,7 +214,7 @@ vm_version_t vm_t::get_version() const · 25 unmodified lines
189 214
190namespace215namespace
191{216{
192 std::unique_ptr<runtime::vm_thread_t> _create_thread_safe(std::unique_ptr<runtime::vm_module_ref_t> entry_module_ref)217 std::unique_ptr<vm_thread_t> _create_thread_safe(std::unique_ptr<vm_module_ref_t> entry_module_ref)
193 {218 {
194 auto thread = std::make_unique<vm_thread_t>(*entry_module_ref, disvm::vm_t::root_vm_thread_id);219 auto thread = std::make_unique<vm_thread_t>(*entry_module_ref, disvm::vm_t::root_vm_thread_id);
195 220
@@ -201,7 +226,7 @@ namespace · 5 unmodified lines
201 }226 }
202}227}
203 228
204const runtime::vm_thread_t& vm_t::exec(const char *path)229const vm_thread_t& vm_t::exec(const char *path)
205{230{
206 assert(path != nullptr);231 assert(path != nullptr);
207 auto entry_module = load_module(path);232 auto entry_module = load_module(path);
@@ -211,7 +236,7 @@ const runtime::vm_thread_t& vm_t::exec(const char *path) · 3 unmodified lines
211 return schedule_thread(std::move(thread));236 return schedule_thread(std::move(thread));
212}237}
213 238
214const runtime::vm_thread_t& vm_t::exec(std::unique_ptr<runtime::vm_module_t> entry_module)239const vm_thread_t& vm_t::exec(std::unique_ptr<vm_module_t> entry_module)
215{240{
216 assert(entry_module != nullptr);241 assert(entry_module != nullptr);
217 242
@@ -220,11 +245,11 @@ const runtime::vm_thread_t& vm_t::exec(std::unique_ptr<runtime::vm_module_t> ent · 2 unmodified lines
220 return schedule_thread(std::move(thread));245 return schedule_thread(std::move(thread));
221}246}
222 247
223const runtime::vm_thread_t& vm_t::fork(248const vm_thread_t& vm_t::fork(
224 const uint32_t parent_tid,249 const uint32_t parent_tid,
225 runtime::vm_module_ref_t &module_ref,250 vm_module_ref_t &module_ref,
226 const runtime::vm_frame_t &initial_frame,251 const vm_frame_t &initial_frame,
227 runtime::vm_pc_t initial_pc)252 vm_pc_t initial_pc)
228{253{
229 if (initial_pc < 0 || static_cast<vm_pc_t>(module_ref.code_section.size()) <= initial_pc)254 if (initial_pc < 0 || static_cast<vm_pc_t>(module_ref.code_section.size()) <= initial_pc)
230 throw vm_user_exception{ "Invalid entry program counter" };255 throw vm_user_exception{ "Invalid entry program counter" };
@@ -235,7 +260,7 @@ const runtime::vm_thread_t& vm_t::fork( · 4 unmodified lines
235 260
236namespace261namespace
237{262{
238 std::unique_ptr<vm_module_t> resolve_module_from_path(const char *path, const std::vector<std::unique_ptr<runtime::vm_module_resolver_t>> &resolvers)263 std::unique_ptr<vm_module_t> resolve_module_from_path(const char *path, const std::vector<std::unique_ptr<vm_module_resolver_t>> &resolvers)
239 {264 {
240 assert(!resolvers.empty());265 assert(!resolvers.empty());
241 std::unique_ptr<vm_module_t> resolved_module;266 std::unique_ptr<vm_module_t> resolved_module;
@@ -244,8 +269,8 @@ namespace · 2 unmodified lines
244 const char *inferno_root_path = "/dis/";269 const char *inferno_root_path = "/dis/";
245 if (std::strncmp(path, inferno_root_path, sizeof(inferno_root_path)) == 0)270 if (std::strncmp(path, inferno_root_path, sizeof(inferno_root_path)) == 0)
246 {271 {
247 if (debug::is_component_tracing_enabled<debug::component_trace_t::module>())272 if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>())
248 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: Inferno OS path detected - >>%s<<", path);273 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "load: vm module: Inferno OS path detected - >>%s<<", path);
249 274
250 // Plus 1 for the next character. We know this will either be275 // Plus 1 for the next character. We know this will either be
251 // null or valid character since we searched for a string276 // null or valid character since we searched for a string
@@ -285,7 +310,7 @@ namespace · 33 unmodified lines
285 }310 }
286}311}
287 312
288std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path)313std::shared_ptr<vm_module_t> vm_t::load_module(const char *path)
289{314{
290 if (path == nullptr)315 if (path == nullptr)
291 throw vm_user_exception{ "Invalid module path" };316 throw vm_user_exception{ "Invalid module path" };
@@ -311,8 +336,8 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 19 unmodified lines
311 336
312 iter->module = module;337 iter->module = module;
313 338
314 if (debug::is_component_tracing_enabled<debug::component_trace_t::module>())339 if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>())
315 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "reload: vm module: >>%s<<", path);340 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "reload: vm module: >>%s<<", path);
316 }341 }
317 342
318 return module;343 return module;
@@ -323,7 +348,7 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 4 unmodified lines
323 348
324 if (path[0] == BUILTIN_MODULE_PREFIX_CHAR)349 if (path[0] == BUILTIN_MODULE_PREFIX_CHAR)
325 {350 {
326 new_module = std::move(builtin::get_builtin_module(path));351 new_module = std::move(disvm::runtime::builtin::get_builtin_module(path));
327 }352 }
328 else353 else
329 {354 {
@@ -349,8 +374,8 @@ std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) · 19 unmodified lines
349 _tool_dispatch->on_module_vm_load(*new_module_iter);374 _tool_dispatch->on_module_vm_load(*new_module_iter);
350 }375 }
351 376
352 if (debug::is_component_tracing_enabled<debug::component_trace_t::module>())377 if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>())
353 debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<", path);378 disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "load: vm module: >>%s<<", path);
354 379
355 return new_module;380 return new_module;
356}381}
@@ -368,12 +393,12 @@ void vm_t::enum_loaded_modules(loaded_vm_module_callback_t callback) const · 11 unmodified lines
368 }393 }
369}394}
370 395
371runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const396vm_scheduler_control_t &vm_t::get_scheduler_control() const
372{397{
373 return _scheduler->get_controller();398 return _scheduler->get_controller();
374}399}
375 400
376runtime::vm_garbage_collector_t &vm_t::get_garbage_collector() const401vm_garbage_collector_t &vm_t::get_garbage_collector() const
377{402{
378 return *_gc;403 return *_gc;
379}404}
@@ -385,7 +410,7 @@ void vm_t::spin_sleep_till_idle(std::chrono::milliseconds sleep_interval) const · 5 unmodified lines
385 while (!_scheduler->is_idle());410 while (!_scheduler->is_idle());
386}411}
387 412
388std::size_t vm_t::load_tool(std::shared_ptr<runtime::vm_tool_t> tool)413std::size_t vm_t::load_tool(std::shared_ptr<vm_tool_t> tool)
389{414{
390 std::lock_guard<std::mutex> lock{ _tool_dispatch_lock };415 std::lock_guard<std::mutex> lock{ _tool_dispatch_lock };
391 416
@@ -420,7 +445,7 @@ void vm_t::unload_tool(std::size_t tool_id) · 28 unmodified lines
420 }445 }
421}446}
422 447
423const runtime::vm_thread_t &vm_t::schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread)448const vm_thread_t &vm_t::schedule_thread(std::unique_ptr<vm_thread_t> thread)
424{449{
425 assert(thread != nullptr);450 assert(thread != nullptr);
426 451
src/vm/vm_exception_handler.cpp+10−6
@@ -10,10 +10,14 @@ · 9 unmodified lines
10#include <exceptions.h>10#include <exceptions.h>
11#include <debug.h>11#include <debug.h>
12 12
13using namespace disvm;13using disvm::debug::component_trace_t;
14using namespace disvm::runtime;14using disvm::debug::log_level_t;
15 15
16std::tuple<const handler_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_exception_handler(16using disvm::runtime::vm_pc_t;
17using disvm::runtime::vm_frame_t;
18using disvm::runtime::handler_entry_t;
19
20std::tuple<const handler_entry_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_exception_handler(
17 const vm_stack_t &stack,21 const vm_stack_t &stack,
18 const vm_module_ref_t &faulting_module,22 const vm_module_ref_t &faulting_module,
19 const vm_pc_t faulting_pc,23 const vm_pc_t faulting_pc,
@@ -26,7 +30,7 @@ std::tuple<const handler_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_except · 6 unmodified lines
26 30
27 while (current_frame != nullptr)31 while (current_frame != nullptr)
28 {32 {
29 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "begin: handler: %d", unwind_depth);33 disvm::debug::log_msg(component_trace_t::exception, log_level_t::debug, "begin: handler: %d", unwind_depth);
30 34
31 auto &handler_section = current_module->module->handler_section;35 auto &handler_section = current_module->module->handler_section;
32 36
@@ -42,12 +46,12 @@ std::tuple<const handler_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_except · 9 unmodified lines
42 auto exception_name = exception.name.get();46 auto exception_name = exception.name.get();
43 if (exception_id.compare_to(exception_name) == 0)47 if (exception_id.compare_to(exception_name) == 0)
44 {48 {
45 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "end: handler: match: %d", unwind_depth);49 disvm::debug::log_msg(component_trace_t::exception, log_level_t::debug, "end: handler: match: %d", unwind_depth);
46 return std::make_tuple(&handler, current_frame, exception.pc);50 return std::make_tuple(&handler, current_frame, exception.pc);
47 }51 }
48 else if (exception_name == nullptr && exception.pc != runtime_constants::invalid_program_counter)52 else if (exception_name == nullptr && exception.pc != runtime_constants::invalid_program_counter)
49 {53 {
50 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "end: handler: fallback: %d", unwind_depth);54 disvm::debug::log_msg(component_trace_t::exception, log_level_t::debug, "end: handler: fallback: %d", unwind_depth);
51 return std::make_tuple(&handler, current_frame, exception.pc);55 return std::make_tuple(&handler, current_frame, exception.pc);
52 }56 }
53 }57 }
src/vm/vm_memory.cpp+43−22
@@ -17,12 +17,35 @@ · 16 unmodified lines
17#include <debug.h>17#include <debug.h>
18#include <exceptions.h>18#include <exceptions.h>
19 19
20using namespace disvm;20using disvm::vm_t;
21using namespace disvm::runtime;21
22using disvm::debug::component_trace_t;
23using disvm::debug::log_level_t;
24
25using disvm::runtime::type_descriptor_t;
26using disvm::runtime::intrinsic_type_desc;
27using disvm::runtime::byte_t;
28using disvm::runtime::short_word_t;
29using disvm::runtime::word_t;
30using disvm::runtime::short_real_t;
31using disvm::runtime::real_t;
32using disvm::runtime::big_t;
33using disvm::runtime::pointer_t;
34using disvm::runtime::vm_thread_t;
35using disvm::runtime::vm_alloc_t;
36using disvm::runtime::vm_array_t;
37using disvm::runtime::vm_list_t;
38using disvm::runtime::vm_string_t;
39using disvm::runtime::vm_channel_t;
40using disvm::runtime::vm_module_t;
41using disvm::runtime::vm_module_ref_t;
42using disvm::runtime::vm_stack_t;
43using disvm::runtime::vm_system_exception;
44using disvm::runtime::vm_alloc_instance_finalizer_t;
22 45
23// Defined in vm.cpp46// Defined in vm.cpp
24extern thread_local vm_memory_alloc_t vm_memory_alloc;47extern thread_local disvm::runtime::vm_memory_alloc_t vm_memory_alloc;
25extern thread_local vm_memory_free_t vm_memory_free;48extern thread_local disvm::runtime::vm_memory_free_t vm_memory_free;
26 49
27void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes)50void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes)
28{51{
@@ -30,8 +53,8 @@ void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) · 1 unmodified line
30 if (memory == nullptr)53 if (memory == nullptr)
31 throw vm_system_exception{ "Out of memory" };54 throw vm_system_exception{ "Out of memory" };
32 55
33 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())56 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
34 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: %#" PRIxPTR " %d", memory, amount_in_bytes);57 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "alloc: %#" PRIxPTR " %d", memory, amount_in_bytes);
35 58
36 return memory;59 return memory;
37}60}
@@ -40,8 +63,8 @@ void disvm::runtime::free_memory(void *memory) · 2 unmodified lines
40{63{
41 vm_memory_free(memory);64 vm_memory_free(memory);
42 65
43 if (memory != nullptr && debug::is_component_tracing_enabled<debug::component_trace_t::memory>())66 if (memory != nullptr && debug::is_component_tracing_enabled<component_trace_t::memory>())
44 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory);67 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "free: %#" PRIxPTR, memory);
45}68}
46 69
47void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data)70void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data)
@@ -109,9 +132,8 @@ void disvm::runtime::enum_pointer_fields(const type_descriptor_t &type_desc, voi · 61 unmodified lines
109{132{
110 assert(data != nullptr && callback != nullptr);133 assert(data != nullptr && callback != nullptr);
111 134
112 auto offset_accum = std::size_t{ 0 };
113 auto memory = reinterpret_cast<word_t *>(data);135 auto memory = reinterpret_cast<word_t *>(data);
114 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += (8 * sizeof(pointer_t)))136 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8)
115 {137 {
116 const auto words8 = type_desc.pointer_map[i];138 const auto words8 = type_desc.pointer_map[i];
117 assert(sizeof(words8) == 1);139 assert(sizeof(words8) == 1);
@@ -136,9 +158,8 @@ void disvm::runtime::enum_pointer_fields(const type_descriptor_t &type_desc, voi · 18 unmodified lines
136{158{
137 assert(data != nullptr && callback != nullptr);159 assert(data != nullptr && callback != nullptr);
138 160
139 auto offset_accum = std::size_t{ 0 };
140 auto memory = reinterpret_cast<word_t *>(data);161 auto memory = reinterpret_cast<word_t *>(data);
141 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8, offset_accum += (8 * sizeof(pointer_t)))162 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8)
142 {163 {
143 const auto words8 = type_desc.pointer_map[i];164 const auto words8 = type_desc.pointer_map[i];
144 assert(sizeof(words8) == 1);165 assert(sizeof(words8) == 1);
@@ -232,8 +253,8 @@ vm_alloc_t *vm_alloc_t::allocate(std::shared_ptr<const type_descriptor_t> td) · 87 unmodified lines
232 auto mem = alloc_memory(sizeof(vm_alloc_t) + td->size_in_bytes);253 auto mem = alloc_memory(sizeof(vm_alloc_t) + td->size_in_bytes);
233 auto alloc = ::new(mem)vm_alloc_t{ td };254 auto alloc = ::new(mem)vm_alloc_t{ td };
234 255
235 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())256 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
236 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm alloc: %d", td->size_in_bytes);257 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm alloc: %d", td->size_in_bytes);
237 258
238 return alloc;259 return alloc;
239}260}
@@ -248,7 +269,7 @@ vm_alloc_t *vm_alloc_t::copy(const vm_alloc_t &other) · 8 unmodified lines
248 // Ref count all dynamic allocations269 // Ref count all dynamic allocations
249 inc_ref_count_in_memory(*alloc_copy->alloc_type, alloc_copy->get_allocation());270 inc_ref_count_in_memory(*alloc_copy->alloc_type, alloc_copy->get_allocation());
250 271
251 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR, &other, alloc_copy);272 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR, &other, alloc_copy);
252 return alloc_copy;273 return alloc_copy;
253}274}
254 275
@@ -272,7 +293,7 @@ vm_alloc_t::~vm_alloc_t() · 17 unmodified lines
272{293{
273#ifndef NDEBUG294#ifndef NDEBUG
274 if (_ref_count != 0)295 if (_ref_count != 0)
275 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::warning,296 disvm::debug::log_msg(component_trace_t::memory, log_level_t::warning,
276 "vm alloc being destroy with non-zero reference count. "297 "vm alloc being destroy with non-zero reference count. "
277 "This could be okay if this is happening due to frame unwinding from an exception");298 "This could be okay if this is happening due to frame unwinding from an exception");
278#endif299#endif
@@ -284,8 +305,8 @@ vm_alloc_t::~vm_alloc_t() · 5 unmodified lines
284 // Free pointer types305 // Free pointer types
285 destroy_memory(*alloc_type, get_allocation());306 destroy_memory(*alloc_type, get_allocation());
286 307
287 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())308 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
288 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc");309 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm alloc");
289}310}
290 311
291std::size_t vm_alloc_t::add_ref()312std::size_t vm_alloc_t::add_ref()
@@ -477,8 +498,8 @@ std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( · 185 unmodified lines
477 free_memory(const_cast<byte_t *>(td->pointer_map));498 free_memory(const_cast<byte_t *>(td->pointer_map));
478 debug::assign_debug_pointer(const_cast<byte_t **>(&td->pointer_map));499 debug::assign_debug_pointer(const_cast<byte_t **>(&td->pointer_map));
479 500
480 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())501 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
481 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: type descriptor");502 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: type descriptor");
482 503
483 free_memory(td);504 free_memory(td);
484 }505 }
@@ -513,8 +534,8 @@ type_descriptor_t::type_descriptor_t( · 28 unmodified lines
513#endif534#endif
514{535{
515 (void)debug_name;536 (void)debug_name;
516 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())537 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
517 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: type descriptor");538 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: type descriptor");
518}539}
519 540
520bool type_descriptor_t::is_equal(const type_descriptor_t *other) const541bool type_descriptor_t::is_equal(const type_descriptor_t *other) const