History

Various perf and style fixes

arr committed 9 years ago

Commit 08c36e01 parent b1b22c24 files · +29 −23Browse files

Unified · Split

4 files
  1. src/include/utils.h +4 −4
  2. src/include/vm_memory.h +1 −1
  3. src/vm/execution_table.cpp +17 −13
  4. src/vm/list.cpp +7 −5
src/include/utils.h+4−4
@@ -76,12 +76,12 @@ namespace disvm · 75 unmodified lines
76 76
77// Adopted from 'winnt.h' in the Windows SDK77// Adopted from 'winnt.h' in the Windows SDK
78#define DEFINE_ENUM_FLAG_OPERATORS(TYPE) \78#define DEFINE_ENUM_FLAG_OPERATORS(TYPE) \
79inline TYPE operator | (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) | static_cast<std::underlying_type_t<TYPE>>(b)); } \79constexpr TYPE operator | (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) | static_cast<std::underlying_type_t<TYPE>>(b)); } \
80inline TYPE &operator |= (TYPE &a, TYPE b) { a = a | b; return a; } \80inline TYPE &operator |= (TYPE &a, TYPE b) { a = a | b; return a; } \
81inline TYPE operator & (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) & static_cast<std::underlying_type_t<TYPE>>(b)); } \81constexpr TYPE operator & (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) & static_cast<std::underlying_type_t<TYPE>>(b)); } \
82inline TYPE &operator &= (TYPE &a, TYPE b) { a = a & b; return a; } \82inline TYPE &operator &= (TYPE &a, TYPE b) { a = a & b; return a; } \
83inline TYPE operator ^ (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) ^ static_cast<std::underlying_type_t<TYPE>>(b)); } \83constexpr TYPE operator ^ (TYPE a, TYPE b) { return static_cast<TYPE>(static_cast<std::underlying_type_t<TYPE>>(a) ^ static_cast<std::underlying_type_t<TYPE>>(b)); } \
84inline TYPE &operator ^= (TYPE &a, TYPE b) { a = a ^ b; return a; } \84inline TYPE &operator ^= (TYPE &a, TYPE b) { a = a ^ b; return a; } \
85inline TYPE operator ~ (TYPE a) { return static_cast<TYPE>(~static_cast<std::underlying_type_t<TYPE>>(a)); }85constexpr TYPE operator ~ (TYPE a) { return static_cast<TYPE>(~static_cast<std::underlying_type_t<TYPE>>(a)); }
86 86
87#endif // _DISVM_SRC_INCLUDE_UTILS_H_87#endif // _DISVM_SRC_INCLUDE_UTILS_H_
src/include/vm_memory.h+1−1
@@ -57,7 +57,7 @@ namespace disvm · 56 unmodified lines
57 template<typename CB>57 template<typename CB>
58 void enum_pointer_fields(const type_descriptor_t &type_desc, void *data, CB callback)58 void enum_pointer_fields(const type_descriptor_t &type_desc, void *data, CB callback)
59 {59 {
60 assert(data != nullptr && callback != nullptr);60 assert(data != nullptr);
61 61
62 auto memory = reinterpret_cast<word_t *>(data);62 auto memory = reinterpret_cast<word_t *>(data);
63 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8)63 for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8)
src/vm/execution_table.cpp+17−13
@@ -537,7 +537,7 @@ namespace · 536 unmodified lines
537 auto type_id = vt_ref<word_t>(r.mid);537 auto type_id = vt_ref<word_t>(r.mid);
538 const auto &types = r.module_ref->type_section;538 const auto &types = r.module_ref->type_section;
539 assert(0 <= type_id && type_id < static_cast<word_t>(types.size()));539 assert(0 <= type_id && type_id < static_cast<word_t>(types.size()));
540 auto type = types[type_id];540 const auto &type = types[type_id];
541 541
542 disvm::runtime::inc_ref_count_in_memory(*type, r.src);542 disvm::runtime::inc_ref_count_in_memory(*type, r.src);
543 destroy_memory(*type, r.dest);543 destroy_memory(*type, r.dest);
@@ -971,14 +971,15 @@ namespace · 427 unmodified lines
971 auto tail_maybe = at_val<vm_list_t>(r.dest);971 auto tail_maybe = at_val<vm_list_t>(r.dest);
972 972
973 // Create a new list973 // Create a new list
974 auto new_list = new vm_list_t{ type, tail_maybe };974 const auto type_size_in_bytes = type->size_in_bytes;
975 auto new_list = new vm_list_t{ std::move(type), tail_maybe };
975 if (tail_maybe != nullptr)976 if (tail_maybe != nullptr)
976 tail_maybe->release();977 tail_maybe->release();
977 978
978 auto destination = new_list->value();979 auto destination = new_list->value();
979 std::memmove(destination, r.src, type->size_in_bytes);980 std::memmove(destination, r.src, type_size_in_bytes);
980 981
981 if (type->map_in_bytes > 0)982 if (type_size_in_bytes > 0)
982 vm.get_garbage_collector().track_allocation(new_list);983 vm.get_garbage_collector().track_allocation(new_list);
983 984
984 // Return the list985 // Return the list
@@ -1329,9 +1330,10 @@ namespace · 344 unmodified lines
1329 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));1330 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
1330 1331
1331 auto type_desc = types[type_id];1332 auto type_desc = types[type_id];
1332 auto new_alloc = vm_alloc_t::allocate(type_desc);1333 const auto track_object = type_desc->map_in_bytes > 0;
1334 auto new_alloc = vm_alloc_t::allocate(std::move(type_desc));
1333 1335
1334 if (type_desc->map_in_bytes > 0)1336 if (track_object)
1335 vm.get_garbage_collector().track_allocation(new_alloc);1337 vm.get_garbage_collector().track_allocation(new_alloc);
1336 1338
1337 pt_ref(r.dest) = new_alloc->get_allocation();1339 pt_ref(r.dest) = new_alloc->get_allocation();
@@ -1363,9 +1365,10 @@ namespace · 25 unmodified lines
1363 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));1365 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
1364 1366
1365 auto type_desc = types[type_id];1367 auto type_desc = types[type_id];
1366 auto new_alloc = vm_alloc_t::allocate(type_desc);1368 const auto track_object = type_desc->map_in_bytes > 0;
1369 auto new_alloc = vm_alloc_t::allocate(std::move(type_desc));
1367 1370
1368 if (type_desc->map_in_bytes > 0)1371 if (track_object)
1369 vm.get_garbage_collector().track_allocation(new_alloc);1372 vm.get_garbage_collector().track_allocation(new_alloc);
1370 1373
1371 pt_ref(r.dest) = new_alloc->get_allocation();1374 pt_ref(r.dest) = new_alloc->get_allocation();
@@ -1385,9 +1388,10 @@ namespace · 13 unmodified lines
1385 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));1388 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
1386 1389
1387 const auto array_size = vt_ref<word_t>(r.src);1390 const auto array_size = vt_ref<word_t>(r.src);
1388 auto new_array = new vm_array_t(type_desc, array_size);1391 const auto track_object = type_desc->map_in_bytes > 0;
1392 auto new_array = new vm_array_t(std::move(type_desc), array_size);
1389 1393
1390 if (type_desc->map_in_bytes > 0)1394 if (track_object)
1391 vm.get_garbage_collector().track_allocation(new_array);1395 vm.get_garbage_collector().track_allocation(new_array);
1392 1396
1393 pt_ref(r.dest) = new_array->get_allocation();1397 pt_ref(r.dest) = new_array->get_allocation();
@@ -1437,7 +1441,7 @@ namespace · 43 unmodified lines
1437 1441
1438 const auto frame_type_id = vt_ref<word_t>(r.src);1442 const auto frame_type_id = vt_ref<word_t>(r.src);
1439 assert(0 <= frame_type_id && frame_type_id < static_cast<word_t>(types.size()));1443 assert(0 <= frame_type_id && frame_type_id < static_cast<word_t>(types.size()));
1440 const auto frame_type = types[frame_type_id];1444 auto frame_type = types[frame_type_id];
1441 1445
1442 pt_ref(r.dest) = r.stack.alloc_frame(std::move(frame_type))->base();1446 pt_ref(r.dest) = r.stack.alloc_frame(std::move(frame_type))->base();
1443 }1447 }
@@ -1456,9 +1460,9 @@ namespace · 12 unmodified lines
1456 1460
1457 const auto frame_type_id = function_ref.frame_type;1461 const auto frame_type_id = function_ref.frame_type;
1458 assert(0 <= frame_type_id && frame_type_id < static_cast<word_t>(types.size()));1462 assert(0 <= frame_type_id && frame_type_id < static_cast<word_t>(types.size()));
1459 const auto frame_type = types[frame_type_id];1463 auto frame_type = types[frame_type_id];
1460 1464
1461 pt_ref(r.dest) = r.stack.alloc_frame(frame_type)->base();1465 pt_ref(r.dest) = r.stack.alloc_frame(std::move(frame_type))->base();
1462 }1466 }
1463 1467
1464 EXEC_DECL(ret)1468 EXEC_DECL(ret)
src/vm/list.cpp+7−5
@@ -45,10 +45,6 @@ vm_list_t::vm_list_t(std::shared_ptr<const type_descriptor_t> td, vm_list_t *tai · 44 unmodified lines
45 45
46vm_list_t::~vm_list_t()46vm_list_t::~vm_list_t()
47{47{
48 // Remove tail
49 dec_ref_count_and_free(_tail);
50 debug::assign_debug_pointer(&_tail);
51
52 // Destroy and free the list element, if default element size was surpassed.48 // Destroy and free the list element, if default element size was surpassed.
53 if (_is_alloc)49 if (_is_alloc)
54 {50 {
@@ -61,7 +57,13 @@ vm_list_t::~vm_list_t() · 6 unmodified lines
61 }57 }
62 58
63 debug::assign_debug_pointer(&_mem.alloc);59 debug::assign_debug_pointer(&_mem.alloc);
64 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm list");60
61 // Remove tail
62 dec_ref_count_and_free(_tail);
63 debug::assign_debug_pointer(&_tail);
64
65 if (disvm::debug::is_component_tracing_enabled<component_trace_t::memory>())
66 disvm::debug::log_msg(component_trace_t::memory, log_level_t::debug, "destroy: vm list");
65}67}
66 68
67std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const69std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const