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
7676
7777 // Adopted from 'winnt.h' in the Windows SDK
7878 #define DEFINE_ENUM_FLAG_OPERATORS(TYPE) \
79−inline 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)); } \
79+constexpr 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)); } \
8080 inline TYPE &operator |= (TYPE &a, TYPE b) { a = a | b; return a; } \
81−inline 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)); } \
81+constexpr 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)); } \
8282 inline TYPE &operator &= (TYPE &a, TYPE b) { a = a & b; return a; } \
83−inline 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)); } \
83+constexpr 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)); } \
8484 inline TYPE &operator ^= (TYPE &a, TYPE b) { a = a ^ b; return a; } \
85−inline TYPE operator ~ (TYPE a) { return static_cast<TYPE>(~static_cast<std::underlying_type_t<TYPE>>(a)); }
85+constexpr TYPE operator ~ (TYPE a) { return static_cast<TYPE>(~static_cast<std::underlying_type_t<TYPE>>(a)); }
8686
8787 #endif // _DISVM_SRC_INCLUDE_UTILS_H_
src/include/vm_memory.h+1−1
@@ -57,7 +57,7 @@ namespace disvm · 56 unmodified lines
5757 template<typename CB>
5858 void enum_pointer_fields(const type_descriptor_t &type_desc, void *data, CB callback)
5959 {
60− assert(data != nullptr && callback != nullptr);
60+ assert(data != nullptr);
6161
6262 auto memory = reinterpret_cast<word_t *>(data);
6363 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
537537 auto type_id = vt_ref<word_t>(r.mid);
538538 const auto &types = r.module_ref->type_section;
539539 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];
541541
542542 disvm::runtime::inc_ref_count_in_memory(*type, r.src);
543543 destroy_memory(*type, r.dest);
@@ -971,14 +971,15 @@ namespace · 427 unmodified lines
971971 auto tail_maybe = at_val<vm_list_t>(r.dest);
972972
973973 // 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 };
975976 if (tail_maybe != nullptr)
976977 tail_maybe->release();
977978
978979 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);
980981
981− if (type->map_in_bytes > 0)
982+ if (type_size_in_bytes > 0)
982983 vm.get_garbage_collector().track_allocation(new_list);
983984
984985 // Return the list
@@ -1329,9 +1330,10 @@ namespace · 344 unmodified lines
13291330 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13301331
13311332 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));
13331335
1334− if (type_desc->map_in_bytes > 0)
1336+ if (track_object)
13351337 vm.get_garbage_collector().track_allocation(new_alloc);
13361338
13371339 pt_ref(r.dest) = new_alloc->get_allocation();
@@ -1363,9 +1365,10 @@ namespace · 25 unmodified lines
13631365 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13641366
13651367 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));
13671370
1368− if (type_desc->map_in_bytes > 0)
1371+ if (track_object)
13691372 vm.get_garbage_collector().track_allocation(new_alloc);
13701373
13711374 pt_ref(r.dest) = new_alloc->get_allocation();
@@ -1385,9 +1388,10 @@ namespace · 13 unmodified lines
13851388 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13861389
13871390 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);
13891393
1390− if (type_desc->map_in_bytes > 0)
1394+ if (track_object)
13911395 vm.get_garbage_collector().track_allocation(new_array);
13921396
13931397 pt_ref(r.dest) = new_array->get_allocation();
@@ -1437,7 +1441,7 @@ namespace · 43 unmodified lines
14371441
14381442 const auto frame_type_id = vt_ref<word_t>(r.src);
14391443 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];
14411445
14421446 pt_ref(r.dest) = r.stack.alloc_frame(std::move(frame_type))->base();
14431447 }
@@ -1456,9 +1460,9 @@ namespace · 12 unmodified lines
14561460
14571461 const auto frame_type_id = function_ref.frame_type;
14581462 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];
14601464
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();
14621466 }
14631467
14641468 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
4545
4646 vm_list_t::~vm_list_t()
4747 {
48− // Remove tail
49− dec_ref_count_and_free(_tail);
50− debug::assign_debug_pointer(&_tail);
51−
5248 // Destroy and free the list element, if default element size was surpassed.
5349 if (_is_alloc)
5450 {
@@ -61,7 +57,13 @@ vm_list_t::~vm_list_t() · 6 unmodified lines
6157 }
6258
6359 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");
6567 }
6668
6769 std::shared_ptr<const type_descriptor_t> vm_list_t::get_element_type() const