Remove using statements and minor GC improvement
Unified · Split
| @@ -7,8 +7,6 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <ostream> |
| 8 | 8 | #include <vm_asm.h> |
| 9 | 9 | |
| 10 | −using namespace disvm::runtime; | |
| 11 | − | |
| 12 | 10 | std::ostream& disvm::runtime::operator<<(std::ostream &ss, const inst_data_generic_t &m) |
| 13 | 11 | { |
| 14 | 12 | switch (m.mode) |
| @@ -13,8 +13,15 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <utils.h> |
| 14 | 14 | #include <buffered_reader.h> |
| 15 | 15 | |
| 16 | −using namespace disvm; | |
| 17 | −using namespace disvm::symbol; | |
| 16 | +using disvm::runtime::vm_pc_t; | |
| 17 | + | |
| 18 | +using disvm::symbol::advance_pc_t; | |
| 19 | +using disvm::symbol::function_data_t; | |
| 20 | +using disvm::symbol::function_name_format_t; | |
| 21 | +using disvm::symbol::source_ref_t; | |
| 22 | +using disvm::symbol::symbol_data_t; | |
| 23 | +using disvm::symbol::symbol_pc_iter_t; | |
| 24 | +using disvm::symbol::type_class_t; | |
| 18 | 25 | |
| 19 | 26 | namespace |
| 20 | 27 | { |
| @@ -67,8 +74,8 @@ namespace · 46 unmodified lines | ||
| 67 | 74 | |
| 68 | 75 | struct func_item_t |
| 69 | 76 | { |
| 70 | − runtime::vm_pc_t entry_pc; | |
| 71 | − runtime::vm_pc_t limit_pc; | |
| 77 | + vm_pc_t entry_pc; | |
| 78 | + vm_pc_t limit_pc; | |
| 72 | 79 | std::string name; |
| 73 | 80 | id_table_t args; |
| 74 | 81 | id_table_t locals; |
| @@ -195,7 +202,7 @@ namespace · 120 unmodified lines | ||
| 195 | 202 | |
| 196 | 203 | // header: <magic> '\n' module '\n' |
| 197 | 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 | 207 | header_t header; |
| 201 | 208 | auto v = r.get_as_string_until('\n'); |
| @@ -213,7 +220,7 @@ namespace · 11 unmodified lines | ||
| 213 | 220 | |
| 214 | 221 | // file-table: <count> '\n' file* |
| 215 | 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 | 225 | auto count_str = r.get_as_string_until('\n'); |
| 219 | 226 | |
| @@ -236,7 +243,7 @@ namespace · 16 unmodified lines | ||
| 236 | 243 | // char: <int> |
| 237 | 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 | 247 | if (src_parts.size() != 2) |
| 241 | 248 | throw std::runtime_error{ "Invalid source item" }; |
| 242 | 249 | |
| @@ -289,7 +296,7 @@ namespace · 46 unmodified lines | ||
| 289 | 296 | // pc-table: <count> '\n' pc-item* |
| 290 | 297 | // pc-item: src ' ' stmt '\n' |
| 291 | 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 | 301 | auto count_str = r.get_as_string_until('\n'); |
| 295 | 302 | |
| @@ -303,7 +310,7 @@ namespace · 7 unmodified lines | ||
| 303 | 310 | { |
| 304 | 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 | 314 | if (pc_item_parts.size() != 2) |
| 308 | 315 | throw std::runtime_error{ "Invalid PC item" }; |
| 309 | 316 | |
| @@ -323,13 +330,13 @@ namespace · 13 unmodified lines | ||
| 323 | 330 | } |
| 324 | 331 | |
| 325 | 332 | // 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 | 335 | // id-table: <count> '\n' id-item* |
| 329 | 336 | // id-item: id-offset ':' id-name ':' src ' ' type '\n' |
| 330 | 337 | // id-offset: <int> |
| 331 | 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 | 341 | auto count_str = r.get_as_string_until('\n'); |
| 335 | 342 | int32_t count = std::stoi(count_str); |
| @@ -376,7 +383,7 @@ namespace · 40 unmodified lines | ||
| 376 | 383 | // tag-item: tag-name ':' src ' ' size '\n' id-table |
| 377 | 384 | // | tag-name ':' src '\n' |
| 378 | 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 | 388 | assert(parts.size() == 2 || parts.size() == 3); |
| 382 | 389 | name_source_size_t item; |
| @@ -411,7 +418,7 @@ namespace · 28 unmodified lines | ||
| 411 | 418 | // 'f' # Real |
| 412 | 419 | // 's' # String |
| 413 | 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 | 423 | bool success; |
| 417 | 424 | uint8_t tc_byte; |
| @@ -452,7 +459,7 @@ namespace · 34 unmodified lines | ||
| 452 | 459 | case type_class_t::adt_pick: |
| 453 | 460 | { |
| 454 | 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 | 463 | if (adt_parts.size() != 3) |
| 457 | 464 | throw std::runtime_error{ "Invalid adt item" }; |
| 458 | 465 | |
| @@ -468,7 +475,7 @@ namespace · 9 unmodified lines | ||
| 468 | 475 | for (auto i = 0; i < count; ++i) |
| 469 | 476 | { |
| 470 | 477 | tmp = r.get_as_string_until('\n'); |
| 471 | − auto tag_parts = util::split(tmp, " :"); | |
| 478 | + auto tag_parts = disvm::util::split(tmp, " :"); | |
| 472 | 479 | if (tag_parts.size() != 2 && tag_parts.size() != 3) |
| 473 | 480 | throw std::runtime_error{ "Invalid tag item" }; |
| 474 | 481 | |
| @@ -530,7 +537,7 @@ namespace · 55 unmodified lines | ||
| 530 | 537 | } |
| 531 | 538 | |
| 532 | 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 | 542 | auto count_str = r.get_as_string_until('\n'); |
| 536 | 543 | |
| @@ -550,7 +557,7 @@ namespace · 13 unmodified lines | ||
| 550 | 557 | // args: id-table |
| 551 | 558 | // locals: id-table |
| 552 | 559 | // 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 | 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 | 591 | // 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 | 594 | return read_id_table(r, tt, fc); |
| 588 | 595 | } |
| @@ -662,11 +669,11 @@ namespace · 73 unmodified lines | ||
| 662 | 669 | { |
| 663 | 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 | 673 | if (inc_name) |
| 667 | 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 | 677 | if (inc_arguments) |
| 671 | 678 | { |
| 672 | 679 | ss << '('; |
| @@ -685,7 +692,7 @@ namespace · 12 unmodified lines | ||
| 685 | 692 | } |
| 686 | 693 | |
| 687 | 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 | 696 | && f.return_type.type_class != type_class_t::none) |
| 690 | 697 | { |
| 691 | 698 | if (inc_name || inc_arguments) |
| @@ -714,9 +721,9 @@ namespace · 22 unmodified lines | ||
| 714 | 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) override | |
| 724 | + 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 | 727 | switch (adv) |
| 721 | 728 | { |
| 722 | 729 | case advance_pc_t::next_debug_statement: |
| @@ -738,7 +745,7 @@ namespace · 15 unmodified lines | ||
| 738 | 745 | } |
| 739 | 746 | |
| 740 | 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 | 749 | return false; |
| 743 | 750 | ++new_pc; |
| 744 | 751 | break; |
| @@ -791,7 +798,7 @@ namespace · 46 unmodified lines | ||
| 791 | 798 | } |
| 792 | 799 | |
| 793 | 800 | private: |
| 794 | − runtime::vm_pc_t _current_pc; | |
| 801 | + vm_pc_t _current_pc; | |
| 795 | 802 | std::shared_ptr<const sbl_file_t> _file; |
| 796 | 803 | }; |
| 797 | 804 | |
| @@ -9,7 +9,11 @@ · 8 unmodified lines | ||
| 9 | 9 | #include "rfc1321/global.h" |
| 10 | 10 | #include "rfc1321/md5.h" |
| 11 | 11 | |
| 12 | −using namespace disvm::assembly::sigkind; | |
| 12 | +using disvm::assembly::sigkind::sig_stream_t; | |
| 13 | +using disvm::assembly::sigkind::Tadt_pick_tag; | |
| 14 | +using disvm::assembly::sigkind::Tfixed; | |
| 15 | +using disvm::assembly::sigkind::Tm; | |
| 16 | +using disvm::assembly::sigkind::Ttype_ref; | |
| 13 | 17 | |
| 14 | 18 | namespace |
| 15 | 19 | { |
| @@ -18,8 +18,36 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <exceptions.h> |
| 19 | 19 | #include "exec.h" |
| 20 | 20 | |
| 21 | −using namespace disvm; | |
| 22 | −using namespace disvm::runtime; | |
| 21 | +using disvm::vm_t; | |
| 22 | +using disvm::loaded_vm_module_t; | |
| 23 | +using disvm::opcode_t; | |
| 24 | + | |
| 25 | +using disvm::runtime::type_descriptor_t; | |
| 26 | +using disvm::runtime::intrinsic_type_desc; | |
| 27 | +using disvm::runtime::word_t; | |
| 28 | +using disvm::runtime::pointer_t; | |
| 29 | +using disvm::runtime::module_id_t; | |
| 30 | +using disvm::runtime::runtime_flags_t; | |
| 31 | +using disvm::runtime::cookie_t; | |
| 32 | +using disvm::runtime::vm_pc_t; | |
| 33 | +using disvm::runtime::vm_registers_t; | |
| 34 | +using disvm::runtime::vm_module_t; | |
| 35 | +using disvm::runtime::vm_module_ref_t; | |
| 36 | +using disvm::runtime::vm_alloc_t; | |
| 37 | +using disvm::runtime::vm_string_t; | |
| 38 | +using disvm::runtime::vm_array_t; | |
| 39 | +using disvm::runtime::vm_list_t; | |
| 40 | +using disvm::runtime::vm_channel_t; | |
| 41 | +using disvm::runtime::vm_thread_state_t; | |
| 42 | +using disvm::runtime::vm_trap_flags_t; | |
| 43 | +using disvm::runtime::vm_term_request; | |
| 44 | +using disvm::runtime::vm_tool_controller_t; | |
| 45 | +using disvm::runtime::vm_event_t; | |
| 46 | +using disvm::runtime::vm_event_context_t; | |
| 47 | + | |
| 48 | +using disvm::symbol::function_name_format_t; | |
| 49 | +using disvm::symbol::advance_pc_t; | |
| 50 | +using disvm::symbol::symbol_data_t; | |
| 23 | 51 | |
| 24 | 52 | namespace |
| 25 | 53 | { |
| @@ -146,7 +174,7 @@ namespace · 120 unmodified lines | ||
| 146 | 174 | auto msg = std::stringstream{}; |
| 147 | 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 | 178 | if (!func_maybe.empty()) |
| 151 | 179 | { |
| 152 | 180 | assert(func_maybe.size() == 1); |
| @@ -507,7 +535,7 @@ namespace · 354 unmodified lines | ||
| 507 | 535 | { |
| 508 | 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 | 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 | 597 | << std::setw(16) << details.module->module_name->str() |
| 570 | 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 | 601 | if (!func_maybe.empty()) |
| 574 | 602 | { |
| 575 | 603 | assert(func_maybe.size() == 1); |
| @@ -720,7 +748,7 @@ namespace · 144 unmodified lines | ||
| 720 | 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 | 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 | 754 | auto msg = std::stringstream{}; |
| @@ -817,7 +845,7 @@ namespace · 90 unmodified lines | ||
| 817 | 845 | auto value_is_pointer = bool{ false }; |
| 818 | 846 | const auto pointer_offset1 = byte_offset1 / pointer_size; |
| 819 | 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 | 850 | value_is_pointer = true; |
| 823 | 851 | auto alloc_to_examine = vm_alloc_t::from_allocation(value_to_examine); |
| @@ -835,7 +863,7 @@ namespace · 11 unmodified lines | ||
| 835 | 863 | |
| 836 | 864 | const auto pointer_offset2 = byte_offset2 / pointer_size; |
| 837 | 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 | 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 | 1054 | if (cmd_tokens.empty()) |
| 1027 | 1055 | return; |
| 1028 | 1056 | |
| @@ -1081,9 +1109,9 @@ namespace · 52 unmodified lines | ||
| 1081 | 1109 | |
| 1082 | 1110 | std::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" | |
| 1085 | − << "Break on module load: " << std::boolalpha << 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"; | |
| 1112 | + ss << "Break on enter: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_enter) << "\n" | |
| 1113 | + << "Break on module load: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_module_load) << "\n" | |
| 1114 | + << "Break on exception: " << std::boolalpha << disvm::util::has_flag(o, debugger_options::break_on_exception) << "\n"; | |
| 1087 | 1115 | |
| 1088 | 1116 | return ss; |
| 1089 | 1117 | } |
| @@ -1096,10 +1124,10 @@ debugger::debugger(const debugger_options opt) · 6 unmodified lines | ||
| 1096 | 1124 | { } |
| 1097 | 1125 | |
| 1098 | 1126 | std::vector<std::string> debugger::resolve_to_function_source_line( |
| 1099 | − disvm::runtime::module_id_t vm_id, | |
| 1127 | + module_id_t vm_id, | |
| 1100 | 1128 | vm_pc_t begin_pc, |
| 1101 | 1129 | vm_pc_t end_pc, |
| 1102 | − symbol::function_name_format_t fmt) const | |
| 1130 | + function_name_format_t fmt) const | |
| 1103 | 1131 | { |
| 1104 | 1132 | auto iter = _vm_id_to_symbol_info.find(vm_id); |
| 1105 | 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 | 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 | 1162 | return resolved_functions_by_pc; |
| 1135 | 1163 | } |
| 1136 | 1164 | |
| 1137 | −std::vector<std::string> debugger::get_module_functions(disvm::runtime::module_id_t vm_id, const char *match) const | |
| 1165 | +std::vector<std::string> debugger::get_module_functions(module_id_t vm_id, const char *match) const | |
| 1138 | 1166 | { |
| 1139 | 1167 | std::vector<std::string> funcs; |
| 1140 | 1168 | auto iter = _vm_id_to_symbol_info.find(vm_id); |
| 1141 | 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 | 1172 | for (auto &fi : f_infos) |
| 1145 | 1173 | { |
| 1146 | 1174 | // 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 | 1191 | return funcs; |
| 1164 | 1192 | } |
| 1165 | 1193 | |
| 1166 | −bool debugger::symbols_exist(disvm::runtime::module_id_t vm_id) const | |
| 1194 | +bool debugger::symbols_exist(module_id_t vm_id) const | |
| 1167 | 1195 | { |
| 1168 | 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 | 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 | 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 | 1278 | << m->module_name->str() |
| 1251 | 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 | 1282 | ss << " (built-in)"; |
| 1255 | 1283 | |
| 1256 | 1284 | debug_print_info(ss.str()); |
| 1257 | 1285 | |
| 1258 | 1286 | // If the break on enter flag was set, it will be true |
| 1259 | 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 | 1290 | // Reset the break on enter flag and set a breakpoint |
| 1263 | 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 | 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 | 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 | 1362 | if (!sbl_file.is_open()) |
| 1335 | 1363 | return; |
| 1336 | 1364 | |
| 1337 | − std::unique_ptr<symbol::symbol_data_t> symbol_data; | |
| 1365 | + std::unique_ptr<symbol_data_t> symbol_data; | |
| 1338 | 1366 | try |
| 1339 | 1367 | { |
| 1340 | − symbol_data = symbol::read(sbl_file); | |
| 1368 | + symbol_data = disvm::symbol::read(sbl_file); | |
| 1341 | 1369 | } |
| 1342 | 1370 | catch (const std::runtime_error &e) |
| 1343 | 1371 | { |
| @@ -15,9 +15,38 @@ · 14 unmodified lines | ||
| 15 | 15 | #include <vm_version.h> |
| 16 | 16 | #include "exec.h" |
| 17 | 17 | |
| 18 | −using namespace disvm; | |
| 19 | −using namespace disvm::runtime; | |
| 20 | −using namespace disvm::assembly::sigkind; | |
| 18 | +using disvm::vm_t; | |
| 19 | +using disvm::vm_config_t; | |
| 20 | +using disvm::opcode_t; | |
| 21 | + | |
| 22 | +using disvm::assembly::sigkind::sig_stream_t; | |
| 23 | +using disvm::assembly::sigkind::Tfunction; | |
| 24 | +using disvm::assembly::sigkind::Tlist; | |
| 25 | +using disvm::assembly::sigkind::Tstring; | |
| 26 | +using disvm::assembly::sigkind::Tnone; | |
| 27 | + | |
| 28 | +using disvm::debug::component_trace_t; | |
| 29 | +using disvm::debug::log_level_t; | |
| 30 | + | |
| 31 | +using disvm::runtime::type_descriptor_t; | |
| 32 | +using disvm::runtime::intrinsic_type_desc; | |
| 33 | +using disvm::runtime::byte_t; | |
| 34 | +using disvm::runtime::word_t; | |
| 35 | +using disvm::runtime::pointer_t; | |
| 36 | +using disvm::runtime::runtime_flags_t; | |
| 37 | +using disvm::runtime::vm_module_t; | |
| 38 | +using disvm::runtime::vm_alloc_t; | |
| 39 | +using disvm::runtime::vm_string_t; | |
| 40 | +using disvm::runtime::vm_list_t; | |
| 41 | +using disvm::runtime::vm_frame_base_alloc_t; | |
| 42 | +using disvm::runtime::vm_frame_constants; | |
| 43 | +using disvm::runtime::vm_exec_op_t; | |
| 44 | +using disvm::runtime::address_mode_t; | |
| 45 | +using disvm::runtime::address_mode_middle_t; | |
| 46 | +using disvm::runtime::import_function_t; | |
| 47 | +using disvm::runtime::import_vm_module_t; | |
| 48 | +using disvm::runtime::vm_user_exception; | |
| 49 | +using disvm::runtime::vm_system_exception; | |
| 21 | 50 | |
| 22 | 51 | namespace |
| 23 | 52 | { |
| @@ -62,7 +91,7 @@ namespace · 38 unmodified lines | ||
| 62 | 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 | 97 | if (command_module_path == nullptr) |
| @@ -107,7 +136,7 @@ namespace · 38 unmodified lines | ||
| 107 | 136 | { vm_exec_op_t |
| 108 | 137 | { |
| 109 | 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 | 140 | { address_mode_t::offset_indirect_mp, 0, 0 }, // command module path |
| 112 | 141 | { address_mode_middle_t::small_immediate, 0 }, // import table index |
| 113 | 142 | { address_mode_t::offset_indirect_fp, 20, 0 } // module reference |
| @@ -116,7 +145,7 @@ namespace · 2 unmodified lines | ||
| 116 | 145 | { vm_exec_op_t |
| 117 | 146 | { |
| 118 | 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 | 149 | { address_mode_t::offset_indirect_fp, 20, 0 }, // module reference |
| 121 | 150 | { address_mode_middle_t::small_immediate, 0 }, // function index into module |
| 122 | 151 | { address_mode_t::offset_indirect_fp, 24, 0 } // module call frame |
| @@ -125,7 +154,7 @@ namespace · 2 unmodified lines | ||
| 125 | 154 | { vm_exec_op_t |
| 126 | 155 | { |
| 127 | 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 | 158 | { address_mode_t::offset_indirect_mp, 4, 0 }, // Argument list |
| 130 | 159 | { address_mode_middle_t::none }, |
| 131 | 160 | { 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 | 163 | { vm_exec_op_t |
| 135 | 164 | { |
| 136 | 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 | 167 | { address_mode_t::offset_indirect_fp, 24, 0 }, // module call frame |
| 139 | 168 | { address_mode_middle_t::small_immediate, 0 }, // function index into module |
| 140 | 169 | { address_mode_t::offset_indirect_fp, 20, 0 } // module reference |
| @@ -143,7 +172,7 @@ namespace · 2 unmodified lines | ||
| 143 | 172 | { vm_exec_op_t |
| 144 | 173 | { |
| 145 | 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 | 176 | { address_mode_t::none }, |
| 148 | 177 | { address_mode_middle_t::none }, |
| 149 | 178 | { address_mode_t::none } |
| @@ -248,16 +277,16 @@ void print_help() · 98 unmodified lines | ||
| 248 | 277 | " h - Print help (alternative: '?')\n"; |
| 249 | 278 | } |
| 250 | 279 | |
| 251 | −void log_callback(const debug::component_trace_t origin, const debug::log_level_t level, const char *msg_fmt, std::va_list args) | |
| 280 | +void log_callback(const component_trace_t origin, const log_level_t level, const char *msg_fmt, std::va_list args) | |
| 252 | 281 | { |
| 253 | 282 | std::stringstream ss; |
| 254 | 283 | |
| 255 | 284 | switch (level) |
| 256 | 285 | { |
| 257 | − case debug::log_level_t::warning: | |
| 286 | + case log_level_t::warning: | |
| 258 | 287 | ss << "w: "; |
| 259 | 288 | break; |
| 260 | − case debug::log_level_t::debug: | |
| 289 | + case log_level_t::debug: | |
| 261 | 290 | ss << "d: "; |
| 262 | 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 | 353 | case 'l': |
| 325 | 354 | // Set the callback |
| 326 | − debug::set_logging_callback(log_callback); | |
| 355 | + disvm::debug::set_logging_callback(log_callback); | |
| 327 | 356 | for (auto i = std::size_t{ 2 }; i < arg_len; ++i) |
| 328 | 357 | { |
| 329 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 375 | break; |
| 347 | 376 | } |
| 348 | 377 | } |
| @@ -519,30 +519,30 @@ namespace disvm · 518 unmodified lines | ||
| 519 | 519 | }; |
| 520 | 520 | |
| 521 | 521 | // Exception entry for handler |
| 522 | − struct exception_t | |
| 522 | + struct exception_entry_t | |
| 523 | 523 | { |
| 524 | − exception_t() = default; | |
| 525 | − exception_t(exception_t &&); | |
| 524 | + exception_entry_t() = default; | |
| 525 | + exception_entry_t(exception_entry_t &&); | |
| 526 | 526 | |
| 527 | − exception_t(const exception_t &) = delete; | |
| 528 | − exception_t &operator=(const exception_t &) = delete; | |
| 527 | + exception_entry_t(const exception_entry_t &) = delete; | |
| 528 | + exception_entry_t &operator=(const exception_entry_t &) = delete; | |
| 529 | 529 | |
| 530 | − ~exception_t(); | |
| 530 | + ~exception_entry_t(); | |
| 531 | 531 | |
| 532 | 532 | vm_pc_t pc; |
| 533 | 533 | std::unique_ptr<vm_string_t> name; |
| 534 | 534 | }; |
| 535 | 535 | |
| 536 | 536 | // Exception handler |
| 537 | − struct handler_t | |
| 537 | + struct handler_entry_t | |
| 538 | 538 | { |
| 539 | − handler_t() = default; | |
| 540 | − handler_t(handler_t &&); | |
| 539 | + handler_entry_t() = default; | |
| 540 | + handler_entry_t(handler_entry_t &&); | |
| 541 | 541 | |
| 542 | − handler_t(const handler_t &) = delete; | |
| 543 | − handler_t &operator=(const handler_t &) = delete; | |
| 542 | + handler_entry_t(const handler_entry_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 | 547 | // Byte offset in the handling frame the exception should be placed. |
| 548 | 548 | word_t exception_offset; |
| @@ -554,14 +554,14 @@ namespace disvm · 5 unmodified lines | ||
| 554 | 554 | word_t exception_type_count; |
| 555 | 555 | |
| 556 | 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 | 560 | using code_section_t = std::vector<vm_instruction_t>; |
| 561 | 561 | using type_section_map_t = std::vector<std::shared_ptr<const type_descriptor_t>>; |
| 562 | 562 | using export_section_t = std::unordered_multimap<word_t, const export_function_t>; |
| 563 | 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 | 566 | using module_id_t = std::size_t; |
| 567 | 567 | |
| @@ -696,7 +696,7 @@ namespace disvm · 128 unmodified lines | ||
| 696 | 696 | |
| 697 | 697 | // Walk the supplied stack and faulting module find the handler, handling stack frame, and program counter for the supplied exception ID. |
| 698 | 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 | 700 | const vm_stack_t &stack, |
| 701 | 701 | const vm_module_ref_t &faulting_module, |
| 702 | 702 | const vm_pc_t faulting_pc, |
| @@ -9,8 +9,16 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <debug.h> |
| 10 | 10 | #include <exceptions.h> |
| 11 | 11 | |
| 12 | −using namespace disvm; | |
| 13 | −using namespace disvm::runtime; | |
| 12 | +using disvm::debug::component_trace_t; | |
| 13 | +using disvm::debug::log_level_t; | |
| 14 | + | |
| 15 | +using disvm::runtime::intrinsic_type_desc; | |
| 16 | +using disvm::runtime::pointer_t; | |
| 17 | +using disvm::runtime::type_descriptor_t; | |
| 18 | +using disvm::runtime::vm_alloc_t; | |
| 19 | +using disvm::runtime::vm_array_t; | |
| 20 | +using disvm::runtime::vm_string_t; | |
| 21 | +using disvm::runtime::word_t; | |
| 14 | 22 | |
| 15 | 23 | std::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 | 35 | assert(_element_type != nullptr); |
| 28 | 36 | assert(_length >= 0); |
| 29 | 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 | 40 | // [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 | 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>()) | |
| 45 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length); | |
| 52 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | 55 | // Set the data to reference the original array |
| 48 | 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 | 85 | std::memcpy(_arr, str, _length); |
| 78 | 86 | } |
| 79 | 87 | |
| 80 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 88 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 89 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm array: vm string: %d", _length); | |
| 82 | 90 | } |
| 83 | 91 | |
| 84 | 92 | vm_array_t::~vm_array_t() |
| @@ -92,7 +100,7 @@ vm_array_t::~vm_array_t() · 7 unmodified lines | ||
| 92 | 100 | dec_ref_count_and_free(_original); |
| 93 | 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 | 105 | else |
| 98 | 106 | { |
| @@ -100,19 +108,19 @@ vm_array_t::~vm_array_t() · 1 unmodified line | ||
| 100 | 108 | auto arr_local = _arr; |
| 101 | 109 | const auto array_len = _length; |
| 102 | 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 | 112 | for (word_t i = 0; i < array_len; ++i) |
| 105 | 113 | { |
| 106 | 114 | destroy_memory(element_type, arr_local); |
| 107 | 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 | 119 | // Free array memory |
| 112 | 120 | free_memory(_arr); |
| 113 | 121 | |
| 114 | 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 | } |
| @@ -14,8 +14,8 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <debug.h> |
| 15 | 15 | #include <exceptions.h> |
| 16 | 16 | |
| 17 | −using namespace disvm::runtime; | |
| 18 | −using namespace disvm::runtime::builtin; | |
| 17 | +using disvm::runtime::type_descriptor_t; | |
| 18 | +using disvm::runtime::vm_module_t; | |
| 19 | 19 | |
| 20 | 20 | namespace |
| 21 | 21 | { |
| @@ -9,8 +9,17 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <debug.h> |
| 10 | 10 | #include <exceptions.h> |
| 11 | 11 | |
| 12 | −using namespace disvm; | |
| 13 | −using namespace disvm::runtime; | |
| 12 | +using disvm::debug::component_trace_t; | |
| 13 | +using disvm::debug::log_level_t; | |
| 14 | + | |
| 15 | +using disvm::runtime::intrinsic_type_desc; | |
| 16 | +using disvm::runtime::type_descriptor_t; | |
| 17 | +using disvm::runtime::vm_alloc_t; | |
| 18 | +using disvm::runtime::vm_array_t; | |
| 19 | +using disvm::runtime::vm_channel_t; | |
| 20 | +using disvm::runtime::vm_channel_request_t; | |
| 21 | +using disvm::runtime::vm_request_mutex_t; | |
| 22 | +using disvm::runtime::word_t; | |
| 14 | 23 | |
| 15 | 24 | vm_request_mutex_t::vm_request_mutex_t() |
| 16 | 25 | : pending_request{ false } |
| @@ -44,13 +53,13 @@ vm_channel_t::vm_channel_t( · 27 unmodified lines | ||
| 44 | 53 | if (buffer_len > 0) |
| 45 | 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 | |
| 50 | 59 | vm_channel_t::~vm_channel_t() |
| 51 | 60 | { |
| 52 | 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 | |
| 56 | 65 | std::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 | 96 | return true; |
| 88 | 97 | } |
| 89 | 98 | |
| 90 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 99 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 100 | + disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: send: queue: %d", send_request.thread_id); | |
| 92 | 101 | |
| 93 | 102 | _data_senders.emplace_back(std::move(send_request)); |
| 94 | 103 | return false; |
| @@ -121,8 +130,8 @@ bool vm_channel_t::send_data(vm_channel_request_t &send_request) · 26 unmodified lines | ||
| 121 | 130 | pending_req_lock.unlock(); |
| 122 | 131 | data_lock.unlock(); |
| 123 | 132 | |
| 124 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 133 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 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 | 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 | 167 | return true; |
| 159 | 168 | } |
| 160 | 169 | |
| 161 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 170 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 171 | + disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: receive: queue: %d", receive_request.thread_id); | |
| 163 | 172 | |
| 164 | 173 | _data_receivers.emplace_back(std::move(receive_request)); |
| 165 | 174 | return false; |
| @@ -200,8 +209,8 @@ bool vm_channel_t::receive_data(vm_channel_request_t &receive_request) · 34 unmodified lines | ||
| 200 | 209 | // Transfer data since there wasn't anything in the buffer |
| 201 | 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>()) | |
| 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); | |
| 212 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 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 | 216 | // 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 | 243 | _data_senders.erase(sender_iter); |
| 235 | 244 | } |
| 236 | 245 | |
| 237 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::channel>()) | |
| 238 | − debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "channel: cancel: request: %d", thread_id); | |
| 246 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 247 | + disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: cancel: request: %d", thread_id); | |
| 239 | 248 | } |
| 240 | 249 | |
| 241 | 250 | word_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 | 275 | _data_transfer(dest, send_request.data, _data_type.get()); |
| 267 | 276 | send_request.request_mutex.get().pending_request = false; |
| 268 | 277 | |
| 269 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 278 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 279 | + disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: send: buffer: %d", send_request.thread_id); | |
| 271 | 280 | |
| 272 | 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 | 303 | receive_request.request_mutex.get().pending_request = false; |
| 295 | 304 | |
| 296 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 305 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::channel>()) | |
| 306 | + disvm::debug::log_msg(component_trace_t::channel, log_level_t::debug, "channel: receive: buffer: %d", receive_request.thread_id); | |
| 298 | 307 | |
| 299 | 308 | return true; |
| 300 | 309 | } |
| @@ -1286,8 +1286,8 @@ namespace · 1285 unmodified lines | ||
| 1286 | 1286 | { |
| 1287 | 1287 | r.request_mutex.pending_request = false; |
| 1288 | 1288 | |
| 1289 | − if (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"); | |
| 1289 | + if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::channel>()) | |
| 1290 | + disvm::debug::log_msg(debug::component_trace_t::channel, debug::log_level_t::debug, "alt: request: non-blocking"); | |
| 1291 | 1291 | |
| 1292 | 1292 | // Cancel request in all channels. |
| 1293 | 1293 | for (auto i = word_t{ 0 }; i < channel_count; ++i) |
| @@ -1482,8 +1482,8 @@ namespace · 188 unmodified lines | ||
| 1482 | 1482 | if (new_frame == nullptr) |
| 1483 | 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>()) | |
| 1486 | − debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "exit: function"); | |
| 1485 | + if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::stack>()) | |
| 1486 | + disvm::debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "exit: function"); | |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | EXEC_DECL(call) |
| @@ -1500,7 +1500,7 @@ namespace · 10 unmodified lines | ||
| 1500 | 1500 | |
| 1501 | 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 | 1506 | EXEC_DECL(mcall) |
| @@ -1529,9 +1529,9 @@ namespace · 22 unmodified lines | ||
| 1529 | 1529 | top_frame->prev_pc() = r.next_pc; |
| 1530 | 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 | 1535 | debug::component_trace_t::stack, |
| 1536 | 1536 | debug::log_level_t::debug, |
| 1537 | 1537 | "enter: function: inter-module: %d >>%s<< %d %s", |
| @@ -1660,8 +1660,8 @@ namespace · 122 unmodified lines | ||
| 1660 | 1660 | // String |
| 1661 | 1661 | exception_id = static_cast<vm_string_t *>(e); |
| 1662 | 1662 | |
| 1663 | − if (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()); | |
| 1663 | + if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::exception>()) | |
| 1664 | + disvm::debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<", exception_id->str()); | |
| 1665 | 1665 | } |
| 1666 | 1666 | else |
| 1667 | 1667 | { |
| @@ -1673,8 +1673,8 @@ namespace · 5 unmodified lines | ||
| 1673 | 1673 | exception_id = at_val<vm_string_t>(content); |
| 1674 | 1674 | assert(exception_id != nullptr); |
| 1675 | 1675 | |
| 1676 | − if (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()); | |
| 1676 | + if (disvm::debug::is_component_tracing_enabled<debug::component_trace_t::exception>()) | |
| 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 | 1680 | // Check if the tool dispatcher has been supplied |
| @@ -1682,7 +1682,7 @@ namespace · 1 unmodified line | ||
| 1682 | 1682 | if (tool_dispatch != nullptr) |
| 1683 | 1683 | tool_dispatch->on_exception_raised(r, *exception_id, *e); |
| 1684 | 1684 | |
| 1685 | − const handler_t *handler; | |
| 1685 | + const handler_entry_t *handler; | |
| 1686 | 1686 | vm_frame_t *target_frame; |
| 1687 | 1687 | vm_pc_t handler_pc; |
| 1688 | 1688 | |
| @@ -1783,7 +1783,7 @@ namespace · 94 unmodified lines | ||
| 1783 | 1783 | } |
| 1784 | 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 | 1787 | return; |
| 1788 | 1788 | } |
| 1789 | 1789 | } |
| @@ -12,8 +12,22 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <exceptions.h> |
| 13 | 13 | #include "garbage_collector.h" |
| 14 | 14 | |
| 15 | −using namespace disvm; | |
| 16 | −using namespace disvm::runtime; | |
| 15 | +using disvm::vm_t; | |
| 16 | + | |
| 17 | +using disvm::debug::component_trace_t; | |
| 18 | +using disvm::debug::log_level_t; | |
| 19 | + | |
| 20 | +using disvm::runtime::default_garbage_collector_t; | |
| 21 | +using disvm::runtime::intrinsic_type_desc; | |
| 22 | +using disvm::runtime::pointer_t; | |
| 23 | +using disvm::runtime::type_descriptor_t; | |
| 24 | +using disvm::runtime::vm_alloc_t; | |
| 25 | +using disvm::runtime::vm_alloc_callback_t; | |
| 26 | +using disvm::runtime::vm_garbage_collector_t; | |
| 27 | +using disvm::runtime::vm_memory_allocator_t; | |
| 28 | +using disvm::runtime::vm_string_t; | |
| 29 | +using disvm::runtime::vm_thread_t; | |
| 30 | +using disvm::runtime::vm_tool_controller_t; | |
| 17 | 31 | |
| 18 | 32 | // Empty destructors for vm garbage collector 'interfaces' |
| 19 | 33 | vm_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 | 61 | return std::make_unique<no_op_gc>(); |
| 48 | 62 | } |
| 49 | 63 | |
| 50 | −default_garbage_collector_t::default_garbage_collector_t(vm_t &vm) | |
| 51 | − : _collection_epoch{ 0 } | |
| 52 | − , _vm{ vm } | |
| 53 | −{ | |
| 54 | −} | |
| 55 | − | |
| 56 | −default_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 | − | |
| 63 | 64 | namespace |
| 64 | 65 | { |
| 65 | 66 | enum class gc_colour_t |
| @@ -91,6 +92,42 @@ namespace · 25 unmodified lines | ||
| 91 | 92 | { |
| 92 | 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 | + | |
| 116 | +default_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 | + | |
| 123 | +default_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 | |
| 96 | 133 | vm_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 | 140 | assert(alloc != nullptr); |
| 104 | 141 | |
| 105 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::garbage_collector>()) | |
| 106 | − debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: track: %#" PRIxPTR, alloc); | |
| 142 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::garbage_collector>()) | |
| 143 | + disvm::debug::log_msg(component_trace_t::garbage_collector, log_level_t::debug, "gc: track: %#" PRIxPTR, alloc); | |
| 107 | 144 | |
| 108 | 145 | alloc->add_ref(); |
| 109 | 146 | set_gc_colour(alloc, get_current_colour(_collection_epoch)); |
| 110 | 147 | |
| 111 | 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 | |
| 115 | 152 | void 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 | |
| 125 | 162 | namespace |
| 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 | 164 | void mark_pointers(pointer_t p, void *cxt) |
| 140 | 165 | { |
| 141 | 166 | auto a = vm_alloc_t::from_allocation(p); |
| 142 | 167 | |
| 143 | 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 | 171 | // Don't examine vm strings or allocations with the current colour |
| 147 | 172 | if (c->curr_colour != get_gc_colour(a) && a->alloc_type.get() != c->string_type) |
| 148 | 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 | 178 | // Get roots from threads |
| 160 | 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>(); | |
| 183 | − if (log_enabled) | |
| 184 | − debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: roots found: %" PRIuPTR, mark_cxt.size()); | |
| 201 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::garbage_collector>()) | |
| 202 | + disvm::debug::log_msg(component_trace_t::garbage_collector, log_level_t::debug, "gc: roots found: %" PRIuPTR, mark_cxt.size()); | |
| 185 | 203 | |
| 186 | 204 | // Traverse the graph |
| 187 | 205 | while (!mark_cxt.empty()) |
| 188 | 206 | { |
| 189 | − auto curr = mark_cxt.top(); | |
| 190 | − mark_cxt.pop(); | |
| 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); | |
| 207 | + auto curr = mark_cxt.pop(); | |
| 208 | + set_gc_colour(curr, mark_cxt.curr_colour); | |
| 194 | 209 | |
| 195 | 210 | if (curr->alloc_type->map_in_bytes > 0) |
| 196 | 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); | |
| 205 | − | |
| 206 | − const auto starting_size = allocs_local.size(); | |
| 207 | − for (auto a : allocs_local) | |
| 217 | + // Remove sweeper colour allocations. | |
| 218 | + tracking_allocs.remove_if([sweeper_colour](vm_alloc_t *a) | |
| 208 | 219 | { |
| 209 | 220 | const auto colour = get_gc_colour(a); |
| 210 | − if (colour == sweeper_colour) | |
| 221 | + const auto remove = (colour == sweeper_colour); | |
| 222 | + if (remove) | |
| 211 | 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>()) | |
| 217 | − debug::log_msg(debug::component_trace_t::garbage_collector, debug::log_level_t::debug, "gc: sweep: %u", starting_size - tracking_allocs.size()); | |
| 225 | + return remove; | |
| 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 | 237 | return false; |
| 229 | 238 | |
| 230 | 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 | 241 | if (log_enabled) |
| 233 | 242 | { |
| 234 | 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); | |
| 239 | − mark(threads, curr_colour); | |
| 247 | + auto mark_cxt = static_cast<mark_cxt_t *>(_mark_cxt); | |
| 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 | 255 | const auto sweeper_colour = get_sweeper_colour(_collection_epoch); |
| 242 | 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 | 258 | if (log_enabled) |
| 245 | 259 | { |
| 246 | 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 | 264 | ++_collection_epoch; |
| @@ -9,7 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | #include <cstdint> |
| 11 | 11 | #include <mutex> |
| 12 | −#include <deque> | |
| 12 | +#include <forward_list> | |
| 13 | 13 | #include <vector> |
| 14 | 14 | #include <disvm.h> |
| 15 | 15 | |
| @@ -37,9 +37,10 @@ namespace disvm · 21 unmodified lines | ||
| 37 | 37 | private: |
| 38 | 38 | vm_t &_vm; |
| 39 | 39 | |
| 40 | + void *_mark_cxt; | |
| 40 | 41 | std::size_t _collection_epoch; |
| 41 | 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 | } |
| @@ -9,8 +9,15 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <vm_memory.h> |
| 10 | 10 | #include <debug.h> |
| 11 | 11 | |
| 12 | −using namespace disvm; | |
| 13 | −using namespace disvm::runtime; | |
| 12 | +using disvm::debug::component_trace_t; | |
| 13 | +using disvm::debug::log_level_t; | |
| 14 | + | |
| 15 | +using disvm::runtime::intrinsic_type_desc; | |
| 16 | +using disvm::runtime::pointer_t; | |
| 17 | +using disvm::runtime::type_descriptor_t; | |
| 18 | +using disvm::runtime::vm_alloc_t; | |
| 19 | +using disvm::runtime::vm_list_t; | |
| 20 | +using disvm::runtime::word_t; | |
| 14 | 21 | |
| 15 | 22 | std::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 | 39 | if (_is_alloc) |
| 33 | 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>()) | |
| 36 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm list"); | |
| 42 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 43 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm list"); | |
| 37 | 44 | } |
| 38 | 45 | |
| 39 | 46 | vm_list_t::~vm_list_t() |
| @@ -54,7 +61,7 @@ vm_list_t::~vm_list_t() · 14 unmodified lines | ||
| 54 | 61 | } |
| 55 | 62 | |
| 56 | 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 | |
| 60 | 67 | std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const |
| @@ -7,8 +7,19 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <debug.h> |
| 8 | 8 | #include "Mathmod.h" |
| 9 | 9 | |
| 10 | −using namespace disvm; | |
| 11 | −using namespace disvm::runtime; | |
| 10 | +using disvm::vm_t; | |
| 11 | + | |
| 12 | +using disvm::debug::component_trace_t; | |
| 13 | +using disvm::debug::log_level_t; | |
| 14 | + | |
| 15 | +using disvm::runtime::dereference_nil; | |
| 16 | +using disvm::runtime::intrinsic_type_desc; | |
| 17 | +using disvm::runtime::real_t; | |
| 18 | +using disvm::runtime::vm_alloc_t; | |
| 19 | +using disvm::runtime::vm_array_t; | |
| 20 | +using disvm::runtime::vm_user_exception; | |
| 21 | +using disvm::runtime::vm_system_exception; | |
| 22 | +using disvm::runtime::word_t; | |
| 12 | 23 | |
| 13 | 24 | namespace |
| 14 | 25 | { |
| @@ -90,7 +101,7 @@ namespace · 75 unmodified lines | ||
| 90 | 101 | void |
| 91 | 102 | Mathmodinit(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 | |
| 96 | 107 | void |
| @@ -99,7 +110,7 @@ Math_FPcontrol(vm_registers_t &r, vm_t &vm) · 2 unmodified lines | ||
| 99 | 110 | auto &fp = r.stack.peek_frame()->base<F_Math_FPcontrol>(); |
| 100 | 111 | |
| 101 | 112 | // [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 | 115 | *fp.ret = fp.mask; |
| 105 | 116 | } |
| @@ -11,8 +11,15 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <disvm.h> |
| 12 | 12 | #include <builtin_module.h> |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::vm_t; | |
| 15 | + | |
| 16 | +using disvm::runtime::byte_t; | |
| 17 | +using disvm::runtime::word_t; | |
| 18 | +using disvm::runtime::big_t; | |
| 19 | +using disvm::runtime::real_t; | |
| 20 | +using disvm::runtime::pointer_t; | |
| 21 | +using disvm::runtime::vm_registers_t; | |
| 22 | +using disvm::runtime::vm_frame_base_alloc_t; | |
| 16 | 23 | |
| 17 | 24 | void Math_FPcontrol(vm_registers_t &r, vm_t &vm); |
| 18 | 25 | struct F_Math_FPcontrol : public vm_frame_base_alloc_t |
| @@ -18,9 +18,33 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <module_reader.h> |
| 19 | 19 | #include "buffered_reader.h" |
| 20 | 20 | |
| 21 | −using namespace disvm; | |
| 22 | −using namespace disvm::runtime; | |
| 23 | −using namespace disvm::format; | |
| 21 | +using disvm::opcode_t; | |
| 22 | + | |
| 23 | +using disvm::format::operand_t; | |
| 24 | + | |
| 25 | +using disvm::runtime::addr_code_t; | |
| 26 | +using disvm::runtime::address_mode_t; | |
| 27 | +using disvm::runtime::address_mode_middle_t; | |
| 28 | +using disvm::runtime::big_t; | |
| 29 | +using disvm::runtime::byte_t; | |
| 30 | +using disvm::runtime::word_t; | |
| 31 | +using disvm::runtime::real_t; | |
| 32 | +using disvm::runtime::pointer_t; | |
| 33 | +using disvm::runtime::runtime_flags_t; | |
| 34 | +using disvm::runtime::type_descriptor_t; | |
| 35 | +using disvm::runtime::vm_module_t; | |
| 36 | +using disvm::runtime::vm_alloc_t; | |
| 37 | +using disvm::runtime::vm_array_t; | |
| 38 | +using disvm::runtime::vm_string_t; | |
| 39 | +using disvm::runtime::vm_pc_t; | |
| 40 | +using disvm::runtime::import_function_t; | |
| 41 | +using disvm::runtime::export_function_t; | |
| 42 | +using disvm::runtime::import_vm_module_t; | |
| 43 | +using disvm::runtime::handler_entry_t; | |
| 44 | +using disvm::runtime::exception_entry_t; | |
| 45 | +using disvm::runtime::vm_instruction_t; | |
| 46 | +using disvm::runtime::vm_module_exception; | |
| 47 | +using disvm::runtime::module_reader_exception; | |
| 24 | 48 | |
| 25 | 49 | namespace |
| 26 | 50 | { |
| @@ -49,7 +73,7 @@ namespace · 22 unmodified lines | ||
| 49 | 73 | }; |
| 50 | 74 | |
| 51 | 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 | 78 | operand_t result; |
| 55 | 79 | |
| @@ -111,7 +135,7 @@ namespace · 55 unmodified lines | ||
| 111 | 135 | } |
| 112 | 136 | |
| 113 | 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 | 140 | auto result = word_t{}; |
| 117 | 141 | |
| @@ -141,7 +165,7 @@ namespace · 23 unmodified lines | ||
| 141 | 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 | 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 | 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 | 219 | auto success = bool{}; |
| 196 | 220 | auto &header = modobj.header; |
| @@ -200,7 +224,7 @@ namespace · 3 unmodified lines | ||
| 200 | 224 | throw module_reader_exception{ "Failed to read magic number" }; |
| 201 | 225 | |
| 202 | 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 | 229 | std::tie(success, header.Signature.length) = read_next_operand(reader); |
| 206 | 230 | if (!success) throw module_reader_exception{ "Failed to read signature length" }; |
| @@ -209,7 +233,7 @@ namespace · 2 unmodified lines | ||
| 209 | 233 | const auto bytesRead = reader.get_next_bytes(header.Signature.length, header.Signature.signature.get()); |
| 210 | 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 | 238 | header.Signature.length = word_t{ 0 }; |
| 215 | 239 | } |
| @@ -248,7 +272,7 @@ namespace · 32 unmodified lines | ||
| 248 | 272 | } |
| 249 | 273 | |
| 250 | 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 | 277 | auto success = bool{}; |
| 254 | 278 | const auto instruction_count = modobj.header.code_size; |
| @@ -320,7 +344,7 @@ namespace · 65 unmodified lines | ||
| 320 | 344 | } |
| 321 | 345 | |
| 322 | 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 | 349 | auto success = bool{}; |
| 326 | 350 | const auto type_count = modobj.header.type_size; |
| @@ -356,7 +380,7 @@ namespace · 29 unmodified lines | ||
| 356 | 380 | } |
| 357 | 381 | |
| 358 | 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 | 385 | if (modobj.header.data_size != 0) |
| 362 | 386 | { |
| @@ -496,7 +520,7 @@ namespace · 133 unmodified lines | ||
| 496 | 520 | } |
| 497 | 521 | |
| 498 | 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 | 525 | auto string_buffer = std::vector<uint8_t>{}; |
| 502 | 526 | if (!reader.get_bytes_until(0, string_buffer)) |
| @@ -507,7 +531,7 @@ namespace · 4 unmodified lines | ||
| 507 | 531 | } |
| 508 | 532 | |
| 509 | 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 | 536 | auto success = bool{}; |
| 513 | 537 | const auto export_count = modobj.header.export_size; |
| @@ -543,7 +567,7 @@ namespace · 29 unmodified lines | ||
| 543 | 567 | // See import section in Dis VM specification (http://www.vitanuova.com/inferno/man/6/dis.html) |
| 544 | 568 | // [SPEC] The specification does not seem to match what is observed in an actual module. |
| 545 | 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 | 572 | auto success = bool{}; |
| 549 | 573 | auto module_import_count = operand_t{}; |
| @@ -592,7 +616,7 @@ namespace · 42 unmodified lines | ||
| 592 | 616 | } |
| 593 | 617 | |
| 594 | 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 | 621 | auto success = bool{}; |
| 598 | 622 | auto handler_count = operand_t{}; |
| @@ -604,7 +628,7 @@ namespace · 5 unmodified lines | ||
| 604 | 628 | for (auto c = operand_t{ 0 }; c < handler_count; ++c) |
| 605 | 629 | { |
| 606 | 630 | // Read in single handler |
| 607 | − handler_t handler{}; | |
| 631 | + handler_entry_t handler{}; | |
| 608 | 632 | |
| 609 | 633 | std::tie(success, handler.exception_offset) = read_next_operand(reader); |
| 610 | 634 | if (!success) throw module_reader_exception{ "Failed to read exception offset" }; |
| @@ -643,7 +667,7 @@ namespace · 32 unmodified lines | ||
| 643 | 667 | for (auto k = operand_t{ 0 }; k < total_count; ++k) |
| 644 | 668 | { |
| 645 | 669 | // Read in single exception |
| 646 | − exception_t except{}; | |
| 670 | + exception_entry_t except{}; | |
| 647 | 671 | |
| 648 | 672 | auto string_buffer = std::vector<uint8_t>{}; |
| 649 | 673 | if (!reader.get_bytes_until(0, string_buffer)) |
| @@ -658,7 +682,7 @@ namespace · 8 unmodified lines | ||
| 658 | 682 | } |
| 659 | 683 | |
| 660 | 684 | // Read in wildcard exception |
| 661 | − exception_t wildcard_exception{}; | |
| 685 | + exception_entry_t wildcard_exception{}; | |
| 662 | 686 | std::tie(success, wildcard_exception.pc) = read_next_operand(reader); |
| 663 | 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 | |
| 708 | −exception_t::exception_t(exception_t &&other) | |
| 732 | +exception_entry_t::exception_entry_t(exception_entry_t &&other) | |
| 709 | 733 | : pc{ other.pc } |
| 710 | 734 | , name{ std::move(other.name) } |
| 711 | 735 | { |
| 712 | 736 | } |
| 713 | 737 | |
| 714 | −exception_t::~exception_t() | |
| 738 | +exception_entry_t::~exception_entry_t() | |
| 715 | 739 | { |
| 716 | 740 | if (name != nullptr) |
| 717 | 741 | name->release(); |
| 718 | 742 | } |
| 719 | 743 | |
| 720 | −handler_t::handler_t(handler_t &&other) | |
| 744 | +handler_entry_t::handler_entry_t(handler_entry_t &&other) | |
| 721 | 745 | : exception_offset{ other.exception_offset } |
| 722 | 746 | , begin_pc{ other.begin_pc } |
| 723 | 747 | , end_pc{ other.end_pc } |
| @@ -736,15 +760,15 @@ vm_module_t::~vm_module_t() · 12 unmodified lines | ||
| 736 | 760 | original_mp->release(); |
| 737 | 761 | } |
| 738 | 762 | |
| 739 | −std::unique_ptr<runtime::vm_module_t> disvm::read_module(std::istream &data) | |
| 763 | +std::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 | 767 | auto modobj = std::make_unique<vm_module_t>(); |
| 744 | 768 | |
| 745 | 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 | 772 | throw module_reader_exception{ "Obsolete module" }; |
| 749 | 773 | |
| 750 | 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 | 777 | read_module_name(reader, *modobj); |
| 754 | 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 | 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 | 784 | read_handler_section(reader, *modobj); |
| 761 | 785 | |
| 762 | 786 | // [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 | 789 | return modobj; |
| 766 | 790 | } |
| @@ -10,8 +10,22 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <utils.h> |
| 11 | 11 | #include <debug.h> |
| 12 | 12 | |
| 13 | −using namespace disvm; | |
| 14 | −using namespace disvm::runtime; | |
| 13 | +using disvm::debug::component_trace_t; | |
| 14 | +using disvm::debug::log_level_t; | |
| 15 | + | |
| 16 | +using disvm::runtime::type_descriptor_t; | |
| 17 | +using disvm::runtime::intrinsic_type_desc; | |
| 18 | +using disvm::runtime::byte_t; | |
| 19 | +using disvm::runtime::word_t; | |
| 20 | +using disvm::runtime::vm_array_t; | |
| 21 | +using disvm::runtime::vm_string_t; | |
| 22 | +using disvm::runtime::vm_module_t; | |
| 23 | +using disvm::runtime::vm_module_ref_t; | |
| 24 | +using disvm::runtime::export_section_t; | |
| 25 | +using disvm::runtime::import_vm_module_t; | |
| 26 | +using disvm::runtime::vm_module_function_ref_t; | |
| 27 | +using disvm::runtime::vm_system_exception; | |
| 28 | +using disvm::runtime::vm_user_exception; | |
| 15 | 29 | |
| 16 | 30 | namespace |
| 17 | 31 | { |
| @@ -47,11 +61,11 @@ namespace · 29 unmodified lines | ||
| 47 | 61 | ref.entry_pc = export_entry.pc; |
| 48 | 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( | |
| 53 | − debug::component_trace_t::module, | |
| 54 | − debug::log_level_t::debug, | |
| 66 | + disvm::debug::log_msg( | |
| 67 | + component_trace_t::module, | |
| 68 | + log_level_t::debug, | |
| 55 | 69 | "export: %d %#08x >>%s<<", |
| 56 | 70 | index, |
| 57 | 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 | 93 | if (module->original_mp != nullptr) |
| 80 | 94 | mp_base = vm_alloc_t::copy(*module->original_mp); |
| 81 | 95 | |
| 82 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 83 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm module ref"); | |
| 96 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 97 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm module ref"); | |
| 84 | 98 | } |
| 85 | 99 | |
| 86 | 100 | vm_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 | 111 | if (module->original_mp != nullptr) |
| 98 | 112 | mp_base = vm_alloc_t::copy(*module->original_mp); |
| 99 | 113 | |
| 100 | − if (debug::is_component_tracing_enabled<debug::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()); | |
| 114 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | |
| 104 | 118 | vm_module_ref_t::~vm_module_ref_t() |
| @@ -108,8 +122,8 @@ vm_module_ref_t::~vm_module_ref_t() · 3 unmodified lines | ||
| 108 | 122 | if (_function_refs != nullptr) |
| 109 | 123 | _function_refs->release(); |
| 110 | 124 | |
| 111 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 112 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm module ref"); | |
| 125 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 126 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm module ref"); | |
| 113 | 127 | } |
| 114 | 128 | |
| 115 | 129 | bool vm_module_ref_t::is_builtin_module() const |
| @@ -12,7 +12,12 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <exceptions.h> |
| 13 | 13 | #include "module_resolver.h" |
| 14 | 14 | |
| 15 | −using namespace disvm::runtime; | |
| 15 | +using disvm::debug::component_trace_t; | |
| 16 | +using disvm::debug::log_level_t; | |
| 17 | + | |
| 18 | +using disvm::runtime::default_resolver_t; | |
| 19 | +using disvm::runtime::vm_module_t; | |
| 20 | +using disvm::runtime::vm_module_resolver_t; | |
| 16 | 21 | |
| 17 | 22 | // Empty destructor for vm module resolver 'interface' |
| 18 | 23 | vm_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 | 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 | 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 | 46 | auto module_file = std::ifstream{ path, std::ifstream::binary }; |
| 42 | 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 | 52 | p.append(path); |
| 48 | 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 | 56 | module_file = std::ifstream{ p, std::ifstream::binary }; |
| 52 | 57 | if (module_file.is_open()) |
| 53 | 58 | { |
| 54 | 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 | 62 | break; |
| 58 | 63 | } |
| @@ -11,8 +11,17 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <exceptions.h> |
| 12 | 12 | #include "scheduler.h" |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::vm_t; | |
| 15 | + | |
| 16 | +using disvm::debug::component_trace_t; | |
| 17 | +using disvm::debug::log_level_t; | |
| 18 | + | |
| 19 | +using disvm::runtime::vm_thread_t; | |
| 20 | +using disvm::runtime::vm_scheduler_t; | |
| 21 | +using disvm::runtime::vm_scheduler_control_t; | |
| 22 | +using disvm::runtime::vm_tool_dispatch_t; | |
| 23 | +using disvm::runtime::vm_thread_state_t; | |
| 24 | +using disvm::runtime::default_scheduler_t; | |
| 16 | 25 | |
| 17 | 26 | // Empty destructors for vm scheduler 'interfaces' |
| 18 | 27 | vm_scheduler_t::~vm_scheduler_t() |
| @@ -25,7 +34,7 @@ vm_scheduler_control_t::~vm_scheduler_control_t() · 6 unmodified lines | ||
| 25 | 34 | |
| 26 | 35 | void 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 | 39 | register_system_thread(instance._vm); |
| 31 | 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 | 46 | current_thread = instance.next_thread(std::move(current_thread)); |
| 38 | 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 | 50 | break; |
| 42 | 51 | } |
| 43 | 52 | |
| 44 | − if (debug::is_component_tracing_enabled<debug::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()); | |
| 53 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 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 | 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 | 125 | for (auto &w : _worker_pool) |
| 117 | 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 | |
| 122 | 131 | bool default_scheduler_t::is_idle() const |
| @@ -130,14 +139,14 @@ vm_scheduler_control_t &default_scheduler_t::get_controller() const · 7 unmodified lines | ||
| 130 | 139 | return const_cast<default_scheduler_t&>(*this); |
| 131 | 140 | } |
| 132 | 141 | |
| 133 | −const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread) | |
| 142 | +const vm_thread_t& default_scheduler_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) | |
| 134 | 143 | { |
| 135 | 144 | assert(thread != nullptr); |
| 136 | 145 | if (thread->get_registers().current_thread_state != vm_thread_state_t::ready) |
| 137 | 146 | throw vm_system_exception{ "Scheduled thread in invalid state" }; |
| 138 | 147 | |
| 139 | − if (debug::is_component_tracing_enabled<debug::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()); | |
| 148 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 149 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: scheduled: %d", thread->get_thread_id()); | |
| 141 | 150 | |
| 142 | 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 | 261 | _blocked_vm_thread_ids.erase(blocked_iter); |
| 253 | 262 | |
| 254 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 255 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: enqueue blocked: %d", thread_id); | |
| 263 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 264 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: enqueue blocked: %d", thread_id); | |
| 256 | 265 | |
| 257 | 266 | const bool runnable_thread = enqueue_thread_unsafe(thread_container.get(), vm_thread_state_t::ready); |
| 258 | 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 | 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 | 348 | assert(false && "VM thread deadlock detected"); |
| 340 | 349 | } |
| 341 | 350 | |
| 342 | 351 | if (_terminating) |
| 343 | 352 | return{}; |
| 344 | 353 | |
| 345 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 346 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: worker: waiting"); | |
| 354 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 355 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: worker: waiting"); | |
| 347 | 356 | |
| 348 | 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 | |
| 383 | −bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instance, runtime::vm_thread_state_t current_state) | |
| 392 | +bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instance, vm_thread_state_t current_state) | |
| 384 | 393 | { |
| 385 | 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 | 402 | _runnable_vm_thread_ids.push_back(thread_id); |
| 394 | 403 | |
| 395 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 396 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: enqueue: %d", thread_id); | |
| 404 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 405 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: enqueue: %d", thread_id); | |
| 397 | 406 | |
| 398 | 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 | 414 | _blocked_vm_thread_ids.insert(thread_id); |
| 406 | 415 | |
| 407 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 408 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: blocked: %d", thread_id); | |
| 416 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 417 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: blocked: %d", thread_id); | |
| 409 | 418 | |
| 410 | 419 | break; |
| 411 | 420 | } |
| @@ -413,8 +422,8 @@ bool default_scheduler_t::enqueue_thread_unsafe(thread_instance_t *thread_instan · 1 unmodified line | ||
| 413 | 422 | case vm_thread_state_t::empty_stack: |
| 414 | 423 | case vm_thread_state_t::exiting: |
| 415 | 424 | { |
| 416 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 417 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: exiting: %d", thread_id); | |
| 425 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 426 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: exiting: %d", thread_id); | |
| 418 | 427 | |
| 419 | 428 | // Remove the thread |
| 420 | 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 | 436 | case vm_thread_state_t::broken: |
| 428 | 437 | { |
| 429 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::scheduler>()) | |
| 430 | − debug::log_msg(debug::component_trace_t::scheduler, debug::log_level_t::debug, "scheduler: broken: %d", thread_id); | |
| 438 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::scheduler>()) | |
| 439 | + disvm::debug::log_msg(component_trace_t::scheduler, log_level_t::debug, "scheduler: broken: %d", thread_id); | |
| 431 | 440 | |
| 432 | 441 | auto err_msg = thread_instance->vm_thread->get_error_message(); |
| 433 | 442 | assert(err_msg != nullptr); |
| @@ -11,8 +11,16 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <debug.h> |
| 12 | 12 | #include <exceptions.h> |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::debug::component_trace_t; | |
| 15 | +using disvm::debug::log_level_t; | |
| 16 | + | |
| 17 | +using disvm::runtime::type_descriptor_t; | |
| 18 | +using disvm::runtime::pointer_t; | |
| 19 | +using disvm::runtime::vm_pc_t; | |
| 20 | +using disvm::runtime::vm_module_ref_t; | |
| 21 | +using disvm::runtime::vm_frame_t; | |
| 22 | +using disvm::runtime::vm_stack_t; | |
| 23 | +using disvm::runtime::vm_alloc_t; | |
| 16 | 24 | |
| 17 | 25 | namespace |
| 18 | 26 | { |
| @@ -54,7 +62,7 @@ namespace · 35 unmodified lines | ||
| 54 | 62 | ~vm_stack_layout() |
| 55 | 63 | { |
| 56 | 64 | assert(top_page != nullptr); |
| 57 | − free_memory(top_page); | |
| 65 | + disvm::runtime::free_memory(top_page); | |
| 58 | 66 | } |
| 59 | 67 | |
| 60 | 68 | const std::size_t stack_page_size; |
| @@ -66,7 +74,7 @@ namespace · 5 unmodified lines | ||
| 66 | 74 | void *new_page() |
| 67 | 75 | { |
| 68 | 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 | 79 | // Initialize the stack allocation. |
| 72 | 80 | top_page->prev_page = current_stack_page; |
| @@ -75,8 +83,8 @@ namespace · 2 unmodified lines | ||
| 75 | 83 | top_page->page_top_frame = nullptr; |
| 76 | 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>()) | |
| 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); | |
| 86 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | 89 | return top_page->stack_data(); |
| 82 | 90 | } |
| @@ -87,10 +95,10 @@ namespace · 4 unmodified lines | ||
| 87 | 95 | auto current_stack_page = top_page->prev_page; |
| 88 | 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>()) | |
| 93 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: vm stack alloc"); | |
| 100 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 101 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "free: vm stack alloc"); | |
| 94 | 102 | |
| 95 | 103 | // Set the top page |
| 96 | 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 | 118 | prev_frame() = nullptr; |
| 111 | 119 | prev_module_ref() = nullptr; |
| 112 | 120 | |
| 113 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 121 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | |
| 117 | 125 | vm_frame_t::~vm_frame_t() |
| @@ -120,8 +128,8 @@ vm_frame_t::~vm_frame_t() · 2 unmodified lines | ||
| 120 | 128 | |
| 121 | 129 | destroy_memory(*frame_type, base()); |
| 122 | 130 | |
| 123 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 124 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm frame: %#" PRIxPTR, this); | |
| 131 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 132 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm frame: %#" PRIxPTR, this); | |
| 125 | 133 | } |
| 126 | 134 | |
| 127 | 135 | void 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 | 189 | : _mem{ std::make_unique<vm_stack_layout>(stack_extent) } |
| 182 | 190 | { |
| 183 | 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 | |
| 187 | 195 | vm_stack_t::~vm_stack_t() |
| @@ -195,7 +203,7 @@ vm_stack_t::~vm_stack_t() · 7 unmodified lines | ||
| 195 | 203 | _mem->release(); |
| 196 | 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 | |
| 201 | 209 | vm_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 | 253 | layout->top_frame = new_top_frame; |
| 246 | 254 | |
| 247 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 255 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::stack>()) | |
| 256 | + log_msg(component_trace_t::stack, log_level_t::debug, "update: push vm frame: %#" PRIxPTR, new_top_frame); | |
| 249 | 257 | |
| 250 | 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>()) | |
| 288 | − debug::log_msg(debug::component_trace_t::stack, debug::log_level_t::debug, "update: pop vm frame: %#" PRIxPTR, current_frame); | |
| 295 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::stack>()) | |
| 296 | + log_msg(component_trace_t::stack, log_level_t::debug, "update: pop vm frame: %#" PRIxPTR, current_frame); | |
| 289 | 297 | |
| 290 | 298 | return current_frame; |
| 291 | 299 | } |
| @@ -11,8 +11,13 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <debug.h> |
| 12 | 12 | #include <exceptions.h> |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::debug::component_trace_t; | |
| 15 | +using disvm::debug::log_level_t; | |
| 16 | + | |
| 17 | +using disvm::runtime::intrinsic_type_desc; | |
| 18 | +using disvm::runtime::type_descriptor_t; | |
| 19 | +using disvm::runtime::vm_string_t; | |
| 20 | +using disvm::runtime::word_t; | |
| 16 | 21 | |
| 17 | 22 | std::shared_ptr<const type_descriptor_t> vm_string_t::type_desc() |
| 18 | 23 | { |
| @@ -47,8 +52,8 @@ namespace · 28 unmodified lines | ||
| 47 | 52 | { |
| 48 | 53 | for (auto i = word_t{ 0 }; i < len; ++i) |
| 49 | 54 | { |
| 50 | − const auto sc1 = static_cast<runtime::rune_t>(s1[i]); | |
| 51 | − const auto sc2 = static_cast<runtime::rune_t>(s2[i]); | |
| 55 | + const auto sc1 = static_cast<disvm::runtime::rune_t>(s1[i]); | |
| 56 | + const auto sc2 = static_cast<disvm::runtime::rune_t>(s2[i]); | |
| 52 | 57 | |
| 53 | 58 | if (sc1 != sc2) |
| 54 | 59 | return (sc1 < sc2) ? (-1) : 1; |
| @@ -128,10 +133,10 @@ namespace · 73 unmodified lines | ||
| 128 | 133 | } |
| 129 | 134 | |
| 130 | 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 | 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 | 142 | void combine( |
| @@ -146,14 +151,14 @@ namespace · 8 unmodified lines | ||
| 146 | 151 | { |
| 147 | 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 | 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 | 157 | else |
| 153 | 158 | copy_characters_to(dest_rune, 0, source1, source1_length); |
| 154 | 159 | |
| 155 | 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 | 162 | else |
| 158 | 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 | 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>()) | |
| 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); | |
| 243 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | |
| 242 | 247 | vm_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 | 302 | const auto length_in_bytes = _length * _character_size; |
| 298 | 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>()) | |
| 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); | |
| 305 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 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 | |
| 304 | 309 | vm_string_t::~vm_string_t() |
| @@ -314,8 +319,8 @@ vm_string_t::~vm_string_t() · 9 unmodified lines | ||
| 314 | 319 | debug::assign_debug_pointer(&source); |
| 315 | 320 | debug::assign_debug_pointer(&_encoded_str); |
| 316 | 321 | |
| 317 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 318 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm string"); | |
| 322 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 323 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm string"); | |
| 319 | 324 | } |
| 320 | 325 | |
| 321 | 326 | vm_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 | 394 | return _length; |
| 390 | 395 | } |
| 391 | 396 | |
| 392 | −runtime::rune_t vm_string_t::get_rune(word_t index) const | |
| 397 | +disvm::runtime::rune_t vm_string_t::get_rune(word_t index) const | |
| 393 | 398 | { |
| 394 | 399 | if (index < 0 || _length <= index) |
| 395 | 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 | 407 | // Check if multi-byte or ASCII |
| 403 | 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 | 410 | 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 | |
| 409 | −void vm_string_t::set_rune(word_t index, rune_t value) | |
| 414 | +void vm_string_t::set_rune(word_t index, disvm::runtime::rune_t value) | |
| 410 | 415 | { |
| 411 | 416 | // This function does not adhere to the immutable string contract. |
| 412 | 417 | // Therefore, it is unsafe to call this function if there is more |
| @@ -18,8 +18,23 @@ · 17 unmodified lines | ||
| 18 | 18 | #include "Sysmod.h" |
| 19 | 19 | #include "sys_utils.h" |
| 20 | 20 | |
| 21 | −using namespace disvm; | |
| 22 | −using namespace disvm::runtime; | |
| 21 | +using disvm::vm_t; | |
| 22 | + | |
| 23 | +using disvm::debug::component_trace_t; | |
| 24 | +using disvm::debug::log_level_t; | |
| 25 | + | |
| 26 | +using disvm::runtime::dereference_nil; | |
| 27 | +using disvm::runtime::intrinsic_type_desc; | |
| 28 | +using disvm::runtime::out_of_range_memory; | |
| 29 | +using disvm::runtime::type_descriptor_t; | |
| 30 | +using disvm::runtime::vm_alloc_t; | |
| 31 | +using disvm::runtime::vm_array_t; | |
| 32 | +using disvm::runtime::vm_list_t; | |
| 33 | +using disvm::runtime::vm_string_t; | |
| 34 | +using disvm::runtime::vm_syscall_exception; | |
| 35 | +using disvm::runtime::vm_system_exception; | |
| 36 | +using disvm::runtime::vm_user_exception; | |
| 37 | +using disvm::runtime::word_t; | |
| 23 | 38 | |
| 24 | 39 | namespace |
| 25 | 40 | { |
| @@ -85,16 +100,16 @@ namespace · 59 unmodified lines | ||
| 85 | 100 | { |
| 86 | 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( | |
| 91 | − debug::component_trace_t::builtin, | |
| 92 | − debug::log_level_t::debug, | |
| 105 | + disvm::debug::log_msg( | |
| 106 | + component_trace_t::builtin, | |
| 107 | + log_level_t::debug, | |
| 93 | 108 | "sys: fd: finalize: %d", |
| 94 | 109 | fd->fd); |
| 95 | 110 | } |
| 96 | 111 | |
| 97 | − sys::drop_fd_record(fd->fd); | |
| 112 | + disvm::runtime::sys::drop_fd_record(fd->fd); | |
| 98 | 113 | fd->~vm_fd_t(); |
| 99 | 114 | } |
| 100 | 115 | |
| @@ -102,7 +117,7 @@ namespace · 1 unmodified line | ||
| 102 | 117 | { |
| 103 | 118 | assert(s != nullptr); |
| 104 | 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 | 121 | auto vm_fd = ::new(alloc->get_allocation())vm_fd_t{ fd, std::move(s), fd_mode, fd_path }; |
| 107 | 122 | |
| 108 | 123 | return std::make_tuple(vm_fd->fd, alloc); |
| @@ -143,8 +158,8 @@ namespace · 34 unmodified lines | ||
| 143 | 158 | |
| 144 | 159 | ~vm_fd_t() |
| 145 | 160 | { |
| 146 | − debug::assign_debug_pointer(&_istream); | |
| 147 | − debug::assign_debug_pointer(&_ostream); | |
| 161 | + disvm::debug::assign_debug_pointer(&_istream); | |
| 162 | + disvm::debug::assign_debug_pointer(&_ostream); | |
| 148 | 163 | if (_stream != nullptr) |
| 149 | 164 | _stream.reset(); |
| 150 | 165 | |
| @@ -153,7 +168,7 @@ namespace · 2 unmodified lines | ||
| 153 | 168 | std::remove(_fd_path->str()); |
| 154 | 169 | |
| 155 | 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 | 174 | word_t get_original_mode() const |
| @@ -217,7 +232,7 @@ namespace · 57 unmodified lines | ||
| 217 | 232 | disvm::runtime::pointer_t base) |
| 218 | 233 | { |
| 219 | 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 | 236 | if (written >= 0) |
| 222 | 237 | { |
| 223 | 238 | fd.write(vm, written, static_buffer.data()); |
| @@ -225,7 +240,7 @@ namespace · 1 unmodified line | ||
| 225 | 240 | else |
| 226 | 241 | { |
| 227 | 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 | 244 | fd.write(vm, written, dynamic_buffer.data()); |
| 230 | 245 | } |
| 231 | 246 | |
| @@ -270,7 +285,7 @@ namespace · 38 unmodified lines | ||
| 270 | 285 | void |
| 271 | 286 | Sysmodinit(void) |
| 272 | 287 | { |
| 273 | − builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab); | |
| 288 | + disvm::runtime::builtin::register_module_exports(Sys_PATH, Sysmodlen, Sysmodtab); | |
| 274 | 289 | T_Qid = type_descriptor_t::create(sizeof(Sys_Qid), sizeof(Sys_Qid_map), Sys_Qid_map); |
| 275 | 290 | T_Dir = type_descriptor_t::create(sizeof(Sys_Dir), sizeof(Sys_Dir_map), Sys_Dir_map); |
| 276 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 354 | fp.ret->t1 = 0; |
| 340 | 355 | fp.ret->t2 = 0; |
| 341 | 356 | |
| 342 | − auto state = utf8::decode_state_t::accept; | |
| 343 | − auto result = runtime::rune_t{}; | |
| 357 | + auto state = disvm::runtime::utf8::decode_state_t::accept; | |
| 358 | + auto result = disvm::runtime::rune_t{}; | |
| 344 | 359 | const auto buffer_len = buffer->get_length(); |
| 345 | 360 | for (auto i = n; i < buffer_len; ++i) |
| 346 | 361 | { |
| 347 | 362 | auto b = buffer->at<byte_t>(i); |
| 348 | − state = utf8::decode_step(state, result, b); | |
| 349 | − if (state == utf8::decode_state_t::accept) | |
| 363 | + state = disvm::runtime::utf8::decode_step(state, result, b); | |
| 364 | + if (state == disvm::runtime::utf8::decode_state_t::accept) | |
| 350 | 365 | { |
| 351 | 366 | fp.ret->t0 = result; |
| 352 | 367 | fp.ret->t1 = (i - n) + 1; // Number of bytes consumed |
| 353 | 368 | fp.ret->t2 = 1; |
| 354 | 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 | 373 | fp.ret->t1 = 1; |
| 359 | 374 | return; |
| @@ -373,13 +388,13 @@ Sys_char2byte(vm_registers_t &r, vm_t &vm) · 13 unmodified lines | ||
| 373 | 388 | if (buffer == nullptr || n >= buffer->get_length()) |
| 374 | 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 | 393 | static_assert(Sys_UTFmax == sizeof(rune), "UTF max should be same size as rune"); |
| 379 | 394 | uint8_t buffer_local[Sys_UTFmax]; |
| 380 | 395 | auto begin = buffer_local; |
| 381 | 396 | |
| 382 | − auto end = utf8::encode(rune, begin); | |
| 397 | + auto end = disvm::runtime::utf8::encode(rune, begin); | |
| 383 | 398 | const auto count = static_cast<word_t>(end - begin); |
| 384 | 399 | |
| 385 | 400 | const auto final_index = n + count; |
| @@ -414,12 +429,12 @@ Sys_create(vm_registers_t &r, vm_t &vm) · 28 unmodified lines | ||
| 414 | 429 | auto path = vm_alloc_t::from_allocation<vm_string_t>(fp.s); |
| 415 | 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 | 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 | 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 | 439 | // Return null if file stream is not open. |
| 425 | 440 | if (file_stream == nullptr) |
| @@ -432,11 +447,11 @@ Sys_create(vm_registers_t &r, vm_t &vm) · 6 unmodified lines | ||
| 432 | 447 | auto fd = word_t{}; |
| 433 | 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( | |
| 438 | − debug::component_trace_t::builtin, | |
| 439 | − debug::log_level_t::debug, | |
| 452 | + disvm::debug::log_msg( | |
| 453 | + component_trace_t::builtin, | |
| 454 | + log_level_t::debug, | |
| 440 | 455 | "sys: create: %d >>%s<< %#x %#x", |
| 441 | 456 | fd, |
| 442 | 457 | path->str(), |
| @@ -497,7 +512,7 @@ Sys_fildes(vm_registers_t &r, vm_t &vm) · 54 unmodified lines | ||
| 497 | 512 | dec_ref_count_and_free(vm_alloc_t::from_allocation(*fp.ret)); |
| 498 | 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 | 516 | if (fd != nullptr) |
| 502 | 517 | { |
| 503 | 518 | fd->add_ref(); |
| @@ -588,7 +603,7 @@ Sys_open(vm_registers_t &r, vm_t &vm) · 84 unmodified lines | ||
| 588 | 603 | const auto open_mode = convert_to_openmode(fp.mode); |
| 589 | 604 | |
| 590 | 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 | 608 | // Return null if file stream is not open. |
| 594 | 609 | if (file_stream == nullptr) |
| @@ -601,11 +616,11 @@ Sys_open(vm_registers_t &r, vm_t &vm) · 6 unmodified lines | ||
| 601 | 616 | auto fd = word_t{}; |
| 602 | 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( | |
| 607 | − debug::component_trace_t::builtin, | |
| 608 | − debug::log_level_t::debug, | |
| 621 | + disvm::debug::log_msg( | |
| 622 | + component_trace_t::builtin, | |
| 623 | + log_level_t::debug, | |
| 609 | 624 | "sys: open: %d >>%s<< %#x", |
| 610 | 625 | fd, |
| 611 | 626 | path->str(), |
| @@ -746,7 +761,7 @@ Sys_sprint(vm_registers_t &r, vm_t &vm) · 134 unmodified lines | ||
| 746 | 761 | vm_string_t *new_string; |
| 747 | 762 | auto static_buffer = std::array<char, 128>{}; |
| 748 | 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 | 765 | if (written >= 0) |
| 751 | 766 | { |
| 752 | 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 | 769 | else |
| 755 | 770 | { |
| 756 | 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 | 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 | |
| 778 | 793 | namespace |
| 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 | 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 | 852 | if (delim == nullptr || delim->get_length() == 0) |
| 838 | 853 | { |
| 839 | 854 | // 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 | 856 | s->add_ref(); |
| 842 | 857 | |
| 843 | 858 | fp.ret->t0 = 1; |
| @@ -881,7 +896,7 @@ Sys_tokenize(vm_registers_t &r, vm_t &vm) · 37 unmodified lines | ||
| 881 | 896 | curr_node = new vm_list_t{ intrinsic_type_desc::type<pointer_t>() }; |
| 882 | 897 | |
| 883 | 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 | 901 | // Previous node is initially null |
| 887 | 902 | if (prev_node != nullptr) |
| @@ -921,7 +936,7 @@ Sys_utfbytes(vm_registers_t &r, vm_t &vm) · 33 unmodified lines | ||
| 921 | 936 | |
| 922 | 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 | 940 | *fp.ret = static_cast<word_t>(len.byte_count); |
| 926 | 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 | 951 | if (s != nullptr) |
| 937 | 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 | 955 | *fp.ret = 0; |
| 941 | 956 | } |
| 942 | 957 | |
| @@ -11,8 +11,15 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <disvm.h> |
| 12 | 12 | #include <builtin_module.h> |
| 13 | 13 | |
| 14 | −using namespace disvm; | |
| 15 | −using namespace disvm::runtime; | |
| 14 | +using disvm::vm_t; | |
| 15 | + | |
| 16 | +using disvm::runtime::byte_t; | |
| 17 | +using disvm::runtime::word_t; | |
| 18 | +using disvm::runtime::big_t; | |
| 19 | +using disvm::runtime::real_t; | |
| 20 | +using disvm::runtime::pointer_t; | |
| 21 | +using disvm::runtime::vm_registers_t; | |
| 22 | +using disvm::runtime::vm_frame_base_alloc_t; | |
| 16 | 23 | |
| 17 | 24 | struct Sys_Qid |
| 18 | 25 | { |
| @@ -11,7 +11,8 @@ · 10 unmodified lines | ||
| 11 | 11 | #include <vm_memory.h> |
| 12 | 12 | #include "sys_utils.h" |
| 13 | 13 | |
| 14 | −using namespace disvm::runtime; | |
| 14 | +using disvm::runtime::vm_alloc_t; | |
| 15 | +using disvm::runtime::word_t; | |
| 15 | 16 | |
| 16 | 17 | namespace |
| 17 | 18 | { |
| @@ -10,8 +10,6 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <utils.h> |
| 11 | 11 | #include "sys_utils.h" |
| 12 | 12 | |
| 13 | −using namespace disvm::runtime; | |
| 14 | − | |
| 15 | 13 | namespace |
| 16 | 14 | { |
| 17 | 15 | std::mutex _create_file_stream_mutex; |
| @@ -9,8 +9,10 @@ · 8 unmodified lines | ||
| 9 | 9 | #include <utf8.h> |
| 10 | 10 | #include "sys_utils.h" |
| 11 | 11 | |
| 12 | −using namespace disvm::runtime; | |
| 13 | −using namespace disvm::runtime::utf8; | |
| 12 | +using disvm::runtime::byte_t; | |
| 13 | +using disvm::runtime::pointer_t; | |
| 14 | +using disvm::runtime::vm_array_t; | |
| 15 | +using disvm::runtime::word_t; | |
| 14 | 16 | |
| 15 | 17 | namespace |
| 16 | 18 | { |
| @@ -16,8 +16,28 @@ · 15 unmodified lines | ||
| 16 | 16 | #include "execution_table.h" |
| 17 | 17 | #include "tool_dispatch.h" |
| 18 | 18 | |
| 19 | −using namespace disvm; | |
| 20 | −using namespace disvm::runtime; | |
| 19 | +using disvm::vm_t; | |
| 20 | +using disvm::opcode_t; | |
| 21 | + | |
| 22 | +using disvm::debug::component_trace_t; | |
| 23 | +using disvm::debug::log_level_t; | |
| 24 | + | |
| 25 | +using disvm::runtime::type_descriptor_t; | |
| 26 | +using disvm::runtime::word_t; | |
| 27 | +using disvm::runtime::pointer_t; | |
| 28 | +using disvm::runtime::vm_pc_t; | |
| 29 | +using disvm::runtime::vm_exec_op_t; | |
| 30 | +using disvm::runtime::vm_thread_t; | |
| 31 | +using disvm::runtime::vm_frame_t; | |
| 32 | +using disvm::runtime::vm_module_t; | |
| 33 | +using disvm::runtime::vm_module_ref_t; | |
| 34 | +using disvm::runtime::vm_registers_t; | |
| 35 | +using disvm::runtime::address_mode_t; | |
| 36 | +using disvm::runtime::address_mode_middle_t; | |
| 37 | +using disvm::runtime::vm_trap_flags_t; | |
| 38 | +using disvm::runtime::vm_thread_state_t; | |
| 39 | +using disvm::runtime::vm_tool_dispatch_t; | |
| 40 | +using disvm::runtime::vm_system_exception; | |
| 21 | 41 | |
| 22 | 42 | namespace |
| 23 | 43 | { |
| @@ -30,11 +50,11 @@ namespace · 6 unmodified lines | ||
| 30 | 50 | |
| 31 | 51 | #ifndef NDEBUG |
| 32 | 52 | // 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( | |
| 36 | − debug::component_trace_t::addressing, | |
| 37 | − debug::log_level_t::debug, | |
| 55 | + disvm::debug::log_msg( | |
| 56 | + component_trace_t::addressing, | |
| 57 | + log_level_t::debug, | |
| 38 | 58 | "decode: registers: %d (%#" PRIxPTR " %#" PRIxPTR " %#" PRIxPTR ")", |
| 39 | 59 | inst.opcode, |
| 40 | 60 | reg.src, |
| @@ -130,7 +150,7 @@ vm_thread_t::vm_thread_t( · 89 unmodified lines | ||
| 130 | 150 | // Pushing the initial frame sets the FP register |
| 131 | 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 | |
| 136 | 156 | vm_thread_t::vm_thread_t( |
| @@ -159,14 +179,14 @@ vm_thread_t::vm_thread_t( · 22 unmodified lines | ||
| 159 | 179 | // Copy over the frame into this thread - pass arguments to the thread |
| 160 | 180 | current_frame->copy_frame_contents(initial_frame); |
| 161 | 181 | |
| 162 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 182 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::thread>()) | |
| 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 | |
| 166 | 186 | vm_thread_t::~vm_thread_t() |
| 167 | 187 | { |
| 168 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 188 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::thread>()) | |
| 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 | 191 | free_memory(_error_message); |
| 172 | 192 | debug::assign_debug_pointer(&_error_message); |
| @@ -187,7 +207,7 @@ namespace · 14 unmodified lines | ||
| 187 | 207 | static void after_exec(vm_registers_t &r, vm_t &) |
| 188 | 208 | { |
| 189 | 209 | 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 | 211 | return; |
| 192 | 212 | |
| 193 | 213 | auto tool_dispatch = r.tool_dispatch.load(); |
| @@ -217,13 +237,12 @@ namespace · 23 unmodified lines | ||
| 217 | 237 | assert(!r.module_ref->is_builtin_module() && "Interpreter thread is unable to execute native instructions"); |
| 218 | 238 | const auto &inst = code_section[r.pc].op; |
| 219 | 239 | const auto opcode = static_cast<std::size_t>(inst.opcode); |
| 220 | − if (static_cast<std::size_t>(opcode_t::last_opcode) < opcode) | |
| 221 | − throw vm_system_exception{ "Unknown op-code" }; | |
| 240 | + assert(opcode <= static_cast<std::size_t>(opcode_t::last_opcode)); | |
| 222 | 241 | |
| 223 | 242 | // Instruction is valid, decode and update registers for operation |
| 224 | 243 | decode_address(inst, r); |
| 225 | 244 | r.next_pc = (r.pc + 1); |
| 226 | − vm_exec_table[opcode](r, vm); | |
| 245 | + disvm::runtime::vm_exec_table[opcode](r, vm); | |
| 227 | 246 | r.pc = r.next_pc; |
| 228 | 247 | |
| 229 | 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 | 301 | // 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( | |
| 286 | − debug::component_trace_t::thread, | |
| 287 | − debug::log_level_t::debug, | |
| 304 | + disvm::debug::log_msg( | |
| 305 | + component_trace_t::thread, | |
| 306 | + log_level_t::debug, | |
| 288 | 307 | "status: vm thread: execute: %d %d %d %d", |
| 289 | 308 | _thread_id, |
| 290 | 309 | (quanta - _registers.current_thread_quanta), |
| @@ -14,8 +14,27 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <utils.h> |
| 15 | 15 | #include "tool_dispatch.h" |
| 16 | 16 | |
| 17 | −using namespace disvm; | |
| 18 | −using namespace disvm::runtime; | |
| 17 | +using disvm::vm_t; | |
| 18 | +using disvm::opcode_t; | |
| 19 | +using disvm::loaded_vm_module_t; | |
| 20 | + | |
| 21 | +using disvm::debug::component_trace_t; | |
| 22 | +using disvm::debug::log_level_t; | |
| 23 | + | |
| 24 | +using disvm::runtime::cookie_t; | |
| 25 | +using disvm::runtime::vm_pc_t; | |
| 26 | +using disvm::runtime::vm_module_t; | |
| 27 | +using disvm::runtime::vm_thread_t; | |
| 28 | +using disvm::runtime::vm_registers_t; | |
| 29 | +using disvm::runtime::vm_alloc_t; | |
| 30 | +using disvm::runtime::vm_string_t; | |
| 31 | +using disvm::runtime::vm_tool_t; | |
| 32 | +using disvm::runtime::vm_tool_dispatch_t; | |
| 33 | +using disvm::runtime::vm_trap_flags_t; | |
| 34 | +using disvm::runtime::vm_event_t; | |
| 35 | +using disvm::runtime::vm_event_context_t; | |
| 36 | +using disvm::runtime::vm_event_callback_t; | |
| 37 | +using disvm::runtime::breakpoint_details_t; | |
| 19 | 38 | |
| 20 | 39 | // Empty destructor for vm tool 'interface' |
| 21 | 40 | vm_tool_t::~vm_tool_t() |
| @@ -38,7 +57,7 @@ vm_tool_dispatch_t::~vm_tool_dispatch_t() · 16 unmodified lines | ||
| 38 | 57 | t.second->on_unload(); |
| 39 | 58 | } |
| 40 | 59 | |
| 41 | −std::size_t vm_tool_dispatch_t::load_tool(std::shared_ptr<runtime::vm_tool_t> tool) | |
| 60 | +std::size_t vm_tool_dispatch_t::load_tool(std::shared_ptr<vm_tool_t> tool) | |
| 42 | 61 | { |
| 43 | 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 | 78 | catch (...) |
| 60 | 79 | { |
| 61 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>()) | |
| 62 | − debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::warning, "load: tool: failure"); | |
| 80 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 81 | + disvm::debug::log_msg(component_trace_t::tool, log_level_t::warning, "load: tool: failure"); | |
| 63 | 82 | |
| 64 | 83 | // The ID is tainted and will not be re-used |
| 65 | 84 | _tools.erase(current_id); |
| 66 | 85 | throw; |
| 67 | 86 | } |
| 68 | 87 | |
| 69 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>()) | |
| 70 | − debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "load: tool: %d", current_id); | |
| 88 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 89 | + disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "load: tool: %d", current_id); | |
| 71 | 90 | |
| 72 | 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 | 102 | auto tool = iter->second; |
| 84 | 103 | _tools.erase(iter); |
| 85 | 104 | |
| 86 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::tool>()) | |
| 87 | − debug::log_msg(debug::component_trace_t::tool, debug::log_level_t::debug, "unload: tool: %d", tool_id); | |
| 105 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 106 | + disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "unload: tool: %d", tool_id); | |
| 88 | 107 | |
| 89 | 108 | assert(tool != nullptr); |
| 90 | 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 | 241 | // Store the cookie with the associate event |
| 223 | 242 | _events.cookie_to_event[cookie_id] = evt; |
| 224 | 243 | |
| 225 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 244 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 245 | + disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "subscribe: event: %d %d", evt, cookie_id); | |
| 227 | 246 | |
| 228 | 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 | 261 | event_callbacks.erase(cookie_id); |
| 243 | 262 | _events.cookie_to_event.erase(iter); |
| 244 | 263 | |
| 245 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 264 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 265 | + disvm::debug::log_msg(component_trace_t::tool, log_level_t::debug, "unsubscribe: event: %d %d", evt, cookie_id); | |
| 247 | 266 | } |
| 248 | 267 | |
| 249 | 268 | cookie_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 | 299 | // Replace the current opcode with breakpoint |
| 281 | 300 | code_section[pc].op.opcode = opcode_t::brkpt; |
| 282 | 301 | |
| 283 | − if (debug::is_component_tracing_enabled<debug::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()); | |
| 302 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 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 | 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 | 343 | assert(code_section[target_pc].op.opcode == opcode_t::brkpt); |
| 325 | 344 | code_section[target_pc].op.opcode = original_opcode; |
| 326 | 345 | |
| 327 | − if (debug::is_component_tracing_enabled<debug::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()); | |
| 346 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::tool>()) | |
| 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 | 349 | // Clean-up the PC mapping to opcode |
| 331 | 350 | pc_map.erase(iter_pc); |
| @@ -12,7 +12,8 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <utf8.h> |
| 13 | 13 | #include <exceptions.h> |
| 14 | 14 | |
| 15 | −using namespace disvm::runtime; | |
| 15 | +using disvm::runtime::utf8::decode_state_t; | |
| 16 | +using disvm::runtime::utf8::utf8_length_t; | |
| 16 | 17 | |
| 17 | 18 | namespace |
| 18 | 19 | { |
| @@ -40,21 +41,21 @@ namespace · 21 unmodified lines | ||
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. |
| 43 | −utf8::decode_state_t disvm::runtime::utf8::decode_step(utf8::decode_state_t &state, rune_t &codepoint, uint8_t byte) | |
| 44 | +decode_state_t disvm::runtime::utf8::decode_step(decode_state_t &state, rune_t &codepoint, uint8_t byte) | |
| 44 | 45 | { |
| 45 | 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 | 49 | (byte & 0x3fu) | (codepoint << 6) : |
| 49 | 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 | 53 | return state; |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | // Adopted from 'countCodePoints(uint8_t* s, size_t* count)' |
| 56 | 57 | // See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. |
| 57 | −utf8::utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std::size_t max_len) | |
| 58 | +utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, const std::size_t max_len) | |
| 58 | 59 | { |
| 59 | 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 | 66 | auto single_character = rune_t{}; |
| 66 | 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 | 70 | auto last = str; |
| 70 | 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 | 75 | last = curr; |
| 75 | 76 | points++; |
| @@ -84,7 +85,7 @@ utf8::utf8_length_t disvm::runtime::utf8::count_codepoints(const uint8_t *str, c · 8 unmodified lines | ||
| 84 | 85 | std::size_t disvm::runtime::utf8::decode(const uint8_t *str, rune_t &codepoint) |
| 85 | 86 | { |
| 86 | 87 | assert(str != nullptr); |
| 87 | − auto state = utf8::decode_state_t::accept; | |
| 88 | + auto state = decode_state_t::accept; | |
| 88 | 89 | |
| 89 | 90 | codepoint = 0; |
| 90 | 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 | 94 | while (0 != (c = *curr)) |
| 94 | 95 | { |
| 95 | 96 | curr++; |
| 96 | − state = utf8::decode_step(state, codepoint, c); | |
| 97 | − if (state == utf8::decode_state_t::accept) | |
| 97 | + state = decode_step(state, codepoint, c); | |
| 98 | + if (state == decode_state_t::accept) | |
| 98 | 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 | ||
| 108 | 109 | uint8_t *disvm::runtime::utf8::encode(const rune_t rune, uint8_t *str) |
| 109 | 110 | { |
| 110 | 111 | assert(str != nullptr); |
| 111 | − if (rune <= utf8::constants::max_codepoint_ascii) | |
| 112 | + if (rune <= constants::max_codepoint_ascii) | |
| 112 | 113 | { |
| 113 | 114 | // Layout: 0xxxxxxx |
| 114 | 115 | str[0] = static_cast<uint8_t>(rune); |
| 115 | 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 | 120 | // Layout: 110xxxxx 10xxxxxx |
| 120 | 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 | 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 | 127 | // Layout: 1110xxxx 10xxxxxx 10xxxxxx |
| 127 | 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[2] = static_cast<uint8_t>(0x80 + (rune & utf8::constants::multi_byte_value_mask)); | |
| 129 | + str[1] = static_cast<uint8_t>(0x80 + ((rune >> 6) & constants::multi_byte_value_mask)); | |
| 130 | + str[2] = static_cast<uint8_t>(0x80 + (rune & constants::multi_byte_value_mask)); | |
| 130 | 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 | 135 | // Layout: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
| 135 | 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[2] = static_cast<uint8_t>(0x80 + ((rune >> 6) & utf8::constants::multi_byte_value_mask)); | |
| 138 | − str[3] = static_cast<uint8_t>(0x80 + (rune & utf8::constants::multi_byte_value_mask)); | |
| 137 | + str[1] = static_cast<uint8_t>(0x80 + ((rune >> 12) & constants::multi_byte_value_mask)); | |
| 138 | + str[2] = static_cast<uint8_t>(0x80 + ((rune >> 6) & constants::multi_byte_value_mask)); | |
| 139 | + str[3] = static_cast<uint8_t>(0x80 + (rune & constants::multi_byte_value_mask)); | |
| 139 | 140 | return (str + 4); |
| 140 | 141 | } |
| 141 | 142 | |
| @@ -19,8 +19,33 @@ · 18 unmodified lines | ||
| 19 | 19 | #include "tool_dispatch.h" |
| 20 | 20 | #include "module_resolver.h" |
| 21 | 21 | |
| 22 | −using namespace disvm; | |
| 23 | −using namespace disvm::runtime; | |
| 22 | +using disvm::vm_t; | |
| 23 | +using disvm::vm_config_t; | |
| 24 | +using disvm::vm_version_t; | |
| 25 | +using disvm::loaded_vm_module_callback_t; | |
| 26 | + | |
| 27 | +using disvm::debug::component_trace_t; | |
| 28 | +using disvm::debug::log_level_t; | |
| 29 | + | |
| 30 | +using disvm::runtime::vm_pc_t; | |
| 31 | +using disvm::runtime::vm_thread_t; | |
| 32 | +using disvm::runtime::vm_memory_allocator_t; | |
| 33 | +using disvm::runtime::vm_string_t; | |
| 34 | +using disvm::runtime::vm_frame_t; | |
| 35 | +using disvm::runtime::vm_module_t; | |
| 36 | +using disvm::runtime::vm_module_ref_t; | |
| 37 | +using disvm::runtime::vm_module_resolver_t; | |
| 38 | +using disvm::runtime::vm_garbage_collector_t; | |
| 39 | +using disvm::runtime::vm_scheduler_t; | |
| 40 | +using disvm::runtime::vm_scheduler_control_t; | |
| 41 | +using disvm::runtime::vm_tool_t; | |
| 42 | +using disvm::runtime::vm_tool_dispatch_t; | |
| 43 | +using disvm::runtime::vm_user_exception; | |
| 44 | +using disvm::runtime::vm_module_exception; | |
| 45 | +using disvm::runtime::vm_system_exception; | |
| 46 | +using disvm::runtime::default_garbage_collector_t; | |
| 47 | +using disvm::runtime::default_scheduler_t; | |
| 48 | +using disvm::runtime::default_resolver_t; | |
| 24 | 49 | |
| 25 | 50 | namespace |
| 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 | 96 | // Consumed in vm_memory.cpp |
| 72 | −thread_local vm_memory_alloc_t vm_memory_alloc; | |
| 73 | −thread_local vm_memory_free_t vm_memory_free; | |
| 97 | +thread_local disvm::runtime::vm_memory_alloc_t vm_memory_alloc; | |
| 98 | +thread_local disvm::runtime::vm_memory_free_t vm_memory_free; | |
| 74 | 99 | |
| 75 | 100 | namespace |
| 76 | 101 | { |
| @@ -140,7 +165,7 @@ vm_t::vm_t() · 63 unmodified lines | ||
| 140 | 165 | internal_register_system_thread(_gc->get_allocator()); |
| 141 | 166 | |
| 142 | 167 | // Initialize built-in modules. |
| 143 | − builtin::initialize_builtin_modules(); | |
| 168 | + disvm::runtime::builtin::initialize_builtin_modules(); | |
| 144 | 169 | |
| 145 | 170 | _scheduler = std::make_unique<default_scheduler_t>(*this, default_system_thread_count, default_thread_quanta); |
| 146 | 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 | 182 | internal_register_system_thread(_gc->get_allocator()); |
| 158 | 183 | |
| 159 | 184 | // Initialize built-in modules. |
| 160 | − builtin::initialize_builtin_modules(); | |
| 185 | + disvm::runtime::builtin::initialize_builtin_modules(); | |
| 161 | 186 | |
| 162 | 187 | if (config.create_scheduler == nullptr) |
| 163 | 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 | |
| 190 | 215 | namespace |
| 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 | 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 | |
| 204 | −const runtime::vm_thread_t& vm_t::exec(const char *path) | |
| 229 | +const vm_thread_t& vm_t::exec(const char *path) | |
| 205 | 230 | { |
| 206 | 231 | assert(path != nullptr); |
| 207 | 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 | 236 | return schedule_thread(std::move(thread)); |
| 212 | 237 | } |
| 213 | 238 | |
| 214 | −const runtime::vm_thread_t& vm_t::exec(std::unique_ptr<runtime::vm_module_t> entry_module) | |
| 239 | +const vm_thread_t& vm_t::exec(std::unique_ptr<vm_module_t> entry_module) | |
| 215 | 240 | { |
| 216 | 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 | 245 | return schedule_thread(std::move(thread)); |
| 221 | 246 | } |
| 222 | 247 | |
| 223 | −const runtime::vm_thread_t& vm_t::fork( | |
| 248 | +const vm_thread_t& vm_t::fork( | |
| 224 | 249 | const uint32_t parent_tid, |
| 225 | − runtime::vm_module_ref_t &module_ref, | |
| 226 | − const runtime::vm_frame_t &initial_frame, | |
| 227 | − runtime::vm_pc_t initial_pc) | |
| 250 | + vm_module_ref_t &module_ref, | |
| 251 | + const vm_frame_t &initial_frame, | |
| 252 | + vm_pc_t initial_pc) | |
| 228 | 253 | { |
| 229 | 254 | if (initial_pc < 0 || static_cast<vm_pc_t>(module_ref.code_section.size()) <= initial_pc) |
| 230 | 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 | |
| 236 | 261 | namespace |
| 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 | 265 | assert(!resolvers.empty()); |
| 241 | 266 | std::unique_ptr<vm_module_t> resolved_module; |
| @@ -244,8 +269,8 @@ namespace · 2 unmodified lines | ||
| 244 | 269 | const char *inferno_root_path = "/dis/"; |
| 245 | 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>()) | |
| 248 | − debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: Inferno OS path detected - >>%s<<", path); | |
| 272 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>()) | |
| 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 | 275 | // Plus 1 for the next character. We know this will either be |
| 251 | 276 | // null or valid character since we searched for a string |
| @@ -285,7 +310,7 @@ namespace · 33 unmodified lines | ||
| 285 | 310 | } |
| 286 | 311 | } |
| 287 | 312 | |
| 288 | −std::shared_ptr<runtime::vm_module_t> vm_t::load_module(const char *path) | |
| 313 | +std::shared_ptr<vm_module_t> vm_t::load_module(const char *path) | |
| 289 | 314 | { |
| 290 | 315 | if (path == nullptr) |
| 291 | 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 | 337 | iter->module = module; |
| 313 | 338 | |
| 314 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::module>()) | |
| 315 | − debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "reload: vm module: >>%s<<", path); | |
| 339 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>()) | |
| 340 | + disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "reload: vm module: >>%s<<", path); | |
| 316 | 341 | } |
| 317 | 342 | |
| 318 | 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 | 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 | 353 | 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 | 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>()) | |
| 353 | − debug::log_msg(debug::component_trace_t::module, debug::log_level_t::debug, "load: vm module: >>%s<<", path); | |
| 377 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::module>()) | |
| 378 | + disvm::debug::log_msg(component_trace_t::module, log_level_t::debug, "load: vm module: >>%s<<", path); | |
| 354 | 379 | |
| 355 | 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 | |
| 371 | −runtime::vm_scheduler_control_t &vm_t::get_scheduler_control() const | |
| 396 | +vm_scheduler_control_t &vm_t::get_scheduler_control() const | |
| 372 | 397 | { |
| 373 | 398 | return _scheduler->get_controller(); |
| 374 | 399 | } |
| 375 | 400 | |
| 376 | −runtime::vm_garbage_collector_t &vm_t::get_garbage_collector() const | |
| 401 | +vm_garbage_collector_t &vm_t::get_garbage_collector() const | |
| 377 | 402 | { |
| 378 | 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 | 410 | while (!_scheduler->is_idle()); |
| 386 | 411 | } |
| 387 | 412 | |
| 388 | −std::size_t vm_t::load_tool(std::shared_ptr<runtime::vm_tool_t> tool) | |
| 413 | +std::size_t vm_t::load_tool(std::shared_ptr<vm_tool_t> tool) | |
| 389 | 414 | { |
| 390 | 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 | |
| 423 | −const runtime::vm_thread_t &vm_t::schedule_thread(std::unique_ptr<runtime::vm_thread_t> thread) | |
| 448 | +const vm_thread_t &vm_t::schedule_thread(std::unique_ptr<vm_thread_t> thread) | |
| 424 | 449 | { |
| 425 | 450 | assert(thread != nullptr); |
| 426 | 451 | |
| @@ -10,10 +10,14 @@ · 9 unmodified lines | ||
| 10 | 10 | #include <exceptions.h> |
| 11 | 11 | #include <debug.h> |
| 12 | 12 | |
| 13 | −using namespace disvm; | |
| 14 | −using namespace disvm::runtime; | |
| 13 | +using disvm::debug::component_trace_t; | |
| 14 | +using disvm::debug::log_level_t; | |
| 15 | 15 | |
| 16 | −std::tuple<const handler_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_exception_handler( | |
| 16 | +using disvm::runtime::vm_pc_t; | |
| 17 | +using disvm::runtime::vm_frame_t; | |
| 18 | +using disvm::runtime::handler_entry_t; | |
| 19 | + | |
| 20 | +std::tuple<const handler_entry_t *, vm_frame_t *, vm_pc_t> disvm::runtime::find_exception_handler( | |
| 17 | 21 | const vm_stack_t &stack, |
| 18 | 22 | const vm_module_ref_t &faulting_module, |
| 19 | 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 | 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 | 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 | 46 | auto exception_name = exception.name.get(); |
| 43 | 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 | 50 | return std::make_tuple(&handler, current_frame, exception.pc); |
| 47 | 51 | } |
| 48 | 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 | 55 | return std::make_tuple(&handler, current_frame, exception.pc); |
| 52 | 56 | } |
| 53 | 57 | } |
| @@ -17,12 +17,35 @@ · 16 unmodified lines | ||
| 17 | 17 | #include <debug.h> |
| 18 | 18 | #include <exceptions.h> |
| 19 | 19 | |
| 20 | −using namespace disvm; | |
| 21 | −using namespace disvm::runtime; | |
| 20 | +using disvm::vm_t; | |
| 21 | + | |
| 22 | +using disvm::debug::component_trace_t; | |
| 23 | +using disvm::debug::log_level_t; | |
| 24 | + | |
| 25 | +using disvm::runtime::type_descriptor_t; | |
| 26 | +using disvm::runtime::intrinsic_type_desc; | |
| 27 | +using disvm::runtime::byte_t; | |
| 28 | +using disvm::runtime::short_word_t; | |
| 29 | +using disvm::runtime::word_t; | |
| 30 | +using disvm::runtime::short_real_t; | |
| 31 | +using disvm::runtime::real_t; | |
| 32 | +using disvm::runtime::big_t; | |
| 33 | +using disvm::runtime::pointer_t; | |
| 34 | +using disvm::runtime::vm_thread_t; | |
| 35 | +using disvm::runtime::vm_alloc_t; | |
| 36 | +using disvm::runtime::vm_array_t; | |
| 37 | +using disvm::runtime::vm_list_t; | |
| 38 | +using disvm::runtime::vm_string_t; | |
| 39 | +using disvm::runtime::vm_channel_t; | |
| 40 | +using disvm::runtime::vm_module_t; | |
| 41 | +using disvm::runtime::vm_module_ref_t; | |
| 42 | +using disvm::runtime::vm_stack_t; | |
| 43 | +using disvm::runtime::vm_system_exception; | |
| 44 | +using disvm::runtime::vm_alloc_instance_finalizer_t; | |
| 22 | 45 | |
| 23 | 46 | // Defined in vm.cpp |
| 24 | −extern thread_local vm_memory_alloc_t vm_memory_alloc; | |
| 25 | −extern thread_local vm_memory_free_t vm_memory_free; | |
| 47 | +extern thread_local disvm::runtime::vm_memory_alloc_t vm_memory_alloc; | |
| 48 | +extern thread_local disvm::runtime::vm_memory_free_t vm_memory_free; | |
| 26 | 49 | |
| 27 | 50 | void *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 | 53 | if (memory == nullptr) |
| 31 | 54 | throw vm_system_exception{ "Out of memory" }; |
| 32 | 55 | |
| 33 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 56 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 57 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "alloc: %#" PRIxPTR " %d", memory, amount_in_bytes); | |
| 35 | 58 | |
| 36 | 59 | return memory; |
| 37 | 60 | } |
| @@ -40,8 +63,8 @@ void disvm::runtime::free_memory(void *memory) · 2 unmodified lines | ||
| 40 | 63 | { |
| 41 | 64 | vm_memory_free(memory); |
| 42 | 65 | |
| 43 | − if (memory != nullptr && debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 44 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory); | |
| 66 | + if (memory != nullptr && debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 67 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "free: %#" PRIxPTR, memory); | |
| 45 | 68 | } |
| 46 | 69 | |
| 47 | 70 | void 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 | 133 | assert(data != nullptr && callback != nullptr); |
| 111 | 134 | |
| 112 | − auto offset_accum = std::size_t{ 0 }; | |
| 113 | 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 | 138 | const auto words8 = type_desc.pointer_map[i]; |
| 117 | 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 | 159 | assert(data != nullptr && callback != nullptr); |
| 138 | 160 | |
| 139 | − auto offset_accum = std::size_t{ 0 }; | |
| 140 | 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 | 164 | const auto words8 = type_desc.pointer_map[i]; |
| 144 | 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 | 253 | auto mem = alloc_memory(sizeof(vm_alloc_t) + td->size_in_bytes); |
| 233 | 254 | auto alloc = ::new(mem)vm_alloc_t{ td }; |
| 234 | 255 | |
| 235 | − if (debug::is_component_tracing_enabled<debug::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); | |
| 256 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 257 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: vm alloc: %d", td->size_in_bytes); | |
| 237 | 258 | |
| 238 | 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 | 269 | // Ref count all dynamic allocations |
| 249 | 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 | 273 | return alloc_copy; |
| 253 | 274 | } |
| 254 | 275 | |
| @@ -272,7 +293,7 @@ vm_alloc_t::~vm_alloc_t() · 17 unmodified lines | ||
| 272 | 293 | { |
| 273 | 294 | #ifndef NDEBUG |
| 274 | 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 | 297 | "vm alloc being destroy with non-zero reference count. " |
| 277 | 298 | "This could be okay if this is happening due to frame unwinding from an exception"); |
| 278 | 299 | #endif |
| @@ -284,8 +305,8 @@ vm_alloc_t::~vm_alloc_t() · 5 unmodified lines | ||
| 284 | 305 | // Free pointer types |
| 285 | 306 | destroy_memory(*alloc_type, get_allocation()); |
| 286 | 307 | |
| 287 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 288 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc"); | |
| 308 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 309 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm alloc"); | |
| 289 | 310 | } |
| 290 | 311 | |
| 291 | 312 | std::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 | 498 | free_memory(const_cast<byte_t *>(td->pointer_map)); |
| 478 | 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>()) | |
| 481 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: type descriptor"); | |
| 501 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 502 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: type descriptor"); | |
| 482 | 503 | |
| 483 | 504 | free_memory(td); |
| 484 | 505 | } |
| @@ -513,8 +534,8 @@ type_descriptor_t::type_descriptor_t( · 28 unmodified lines | ||
| 513 | 534 | #endif |
| 514 | 535 | { |
| 515 | 536 | (void)debug_name; |
| 516 | − if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) | |
| 517 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: type descriptor"); | |
| 537 | + if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>()) | |
| 538 | + disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "init: type descriptor"); | |
| 518 | 539 | } |
| 519 | 540 | |
| 520 | 541 | bool type_descriptor_t::is_equal(const type_descriptor_t *other) const |