History

Address various performance issues discovered while profiling debugger Fix logical errors in bit shifting bytecodes Add assert for bit shifting issues that may arise on other compilers Fix bug in vm_array assert

arr committed 10 years ago

Commit d8c9a331 parent 42194725 files · +39 −25Browse files

Unified · Split

5 files
  1. src/include/runtime.h +4 −4
  2. src/vm/array.cpp +7 −7
  3. src/vm/execution_table.cpp +23 −9
  4. src/vm/module_reader.cpp +1 −1
  5. src/vm/stack.cpp +4 −4
src/include/runtime.h+4−4
@@ -107,7 +107,7 @@ namespace disvm · 106 unmodified lines
107 {107 {
108 auto alloc_inst = vm_alloc_t::from_allocation(allocation);108 auto alloc_inst = vm_alloc_t::from_allocation(allocation);
109 assert(alloc_inst == nullptr || alloc_inst->alloc_type == intrinsic_type_desc::type<T>());109 assert(alloc_inst == nullptr || alloc_inst->alloc_type == intrinsic_type_desc::type<T>());
110 return dynamic_cast<T *>(alloc_inst);110 return static_cast<T *>(alloc_inst);
111 }111 }
112 112
113 protected:113 protected:
@@ -199,9 +199,9 @@ namespace disvm · 85 unmodified lines
199 static std::shared_ptr<const type_descriptor_t> type_desc();199 static std::shared_ptr<const type_descriptor_t> type_desc();
200 200
201 public:201 public:
202 vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count);202 vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length);
203 vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&);203 vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&);
204 vm_array_t(vm_array_t *original, word_t begin_index, word_t count);204 vm_array_t(vm_array_t *original, word_t begin_index, word_t length);
205 vm_array_t(const vm_string_t *s);205 vm_array_t(const vm_string_t *s);
206 ~vm_array_t();206 ~vm_array_t();
207 207
src/vm/array.cpp+7−7
@@ -17,11 +17,11 @@ std::shared_ptr<const type_descriptor_t> vm_array_t::type_desc() · 16 unmodified lines
17 return intrinsic_type_desc::type<vm_array_t>();17 return intrinsic_type_desc::type<vm_array_t>();
18}18}
19 19
20vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count)20vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length)
21 : vm_alloc_t(vm_array_t::type_desc())21 : vm_alloc_t(vm_array_t::type_desc())
22 , _arr{ nullptr }22 , _arr{ nullptr }
23 , _element_type{ td }23 , _element_type{ td }
24 , _length{ count }24 , _length{ length }
25 , _original{ nullptr }25 , _original{ nullptr }
26{26{
27 assert(_element_type != nullptr);27 assert(_element_type != nullptr);
@@ -43,11 +43,11 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 15 unmodified lines
43 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d\n", array_len);43 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d\n", array_len);
44}44}
45 45
46vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&)46vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&)
47 : vm_alloc_t(vm_array_t::type_desc())47 : vm_alloc_t(vm_array_t::type_desc())
48 , _arr{ nullptr }48 , _arr{ nullptr }
49 , _element_type{ td }49 , _element_type{ td }
50 , _length{ count }50 , _length{ length }
51 , _original{ nullptr }51 , _original{ nullptr }
52{52{
53 assert(_element_type != nullptr);53 assert(_element_type != nullptr);
@@ -56,16 +56,16 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 2 unmodified lines
56 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm array: %d\n", _length);56 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm array: %d\n", _length);
57}57}
58 58
59vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t count)59vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length)
60 : vm_alloc_t(vm_array_t::type_desc())60 : vm_alloc_t(vm_array_t::type_desc())
61 , _arr{ nullptr }61 , _arr{ nullptr }
62 , _element_type{ original->get_element_type() }62 , _element_type{ original->get_element_type() }
63 , _length{ count }63 , _length{ length }
64 , _original{ original }64 , _original{ original }
65{65{
66 assert(_original != nullptr);66 assert(_original != nullptr);
67 assert(0 <= begin_index && begin_index < _original->get_length());67 assert(0 <= begin_index && begin_index < _original->get_length());
68 assert(_length >= 0 && (count - begin_index) < _original->get_length());68 assert(_length >= 0 && (_length + begin_index) <= _original->get_length());
69 69
70 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())70 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
71 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d\n", begin_index, _length);71 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d\n", begin_index, _length);
src/vm/execution_table.cpp+23−9
@@ -66,8 +66,22 @@ namespace · 65 unmodified lines
66 EXEC_DECL(shlw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) << vt_ref<word_t>(r.src); }66 EXEC_DECL(shlw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) << vt_ref<word_t>(r.src); }
67 EXEC_DECL(shll) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) << vt_ref<big_t>(r.src); }67 EXEC_DECL(shll) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) << vt_ref<big_t>(r.src); }
68 EXEC_DECL(shrb) { vt_ref<byte_t>(r.dest) = vt_ref<byte_t>(r.mid) >> vt_ref<byte_t>(r.src); }68 EXEC_DECL(shrb) { vt_ref<byte_t>(r.dest) = vt_ref<byte_t>(r.mid) >> vt_ref<byte_t>(r.src); }
69 EXEC_DECL(shrw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src); }69 EXEC_DECL(shrw)
70 EXEC_DECL(shrl) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src); }70 {
71 vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src);
72 // Right shifting a negative number is implementation dependent in C++.
73 // Assert the current compiler defaults to arithmetic shifting, not logical.
74 assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0));
75 }
76
77 EXEC_DECL(shrl)
78 {
79 vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src);
80 // Right shifting a negative number is implementation dependent in C++.
81 // Assert the current compiler defaults to arithmetic shifting, not logical.
82 assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0));
83 }
84
71 EXEC_DECL(lsrw) { vt_ref<word_t>(r.dest) = vt_ref<uword_t>(r.mid) >> vt_ref<word_t>(r.src); }85 EXEC_DECL(lsrw) { vt_ref<word_t>(r.dest) = vt_ref<uword_t>(r.mid) >> vt_ref<word_t>(r.src); }
72 EXEC_DECL(lsrl) { vt_ref<big_t>(r.dest) = vt_ref<ubig_t>(r.mid) >> vt_ref<big_t>(r.src); }86 EXEC_DECL(lsrl) { vt_ref<big_t>(r.dest) = vt_ref<ubig_t>(r.mid) >> vt_ref<big_t>(r.src); }
73 87
@@ -75,14 +89,14 @@ namespace · 1 unmodified line
75 // Conversion operations89 // Conversion operations
76 //90 //
77 91
78 EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<byte_t>(r.src); }92 EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = vt_ref<byte_t>(r.src); }
79 EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<word_t>(r.src); }93 EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = vt_ref<word_t>(r.src); }
80 EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<word_t>(r.src); }94 EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = vt_ref<word_t>(r.src); }
81 EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<big_t>(r.src); }95 EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = static_cast<word_t>(vt_ref<big_t>(r.src)); }
82 EXEC_DECL(cvtrf) { vt_ref<short_real_t>(r.dest) = static_cast<short_real_t>(vt_ref<real_t>(r.src)); }96 EXEC_DECL(cvtrf) { vt_ref<short_real_t>(r.dest) = static_cast<short_real_t>(vt_ref<real_t>(r.src)); }
83 EXEC_DECL(cvtfr) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<short_real_t>(r.src)); }97 EXEC_DECL(cvtfr) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<short_real_t>(r.src)); }
84 EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<word_t>(r.src); }98 EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = vt_ref<word_t>(r.src); }
85 EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<short_word_t>(r.src); }99 EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = vt_ref<short_word_t>(r.src); }
86 EXEC_DECL(cvtlf) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<big_t>(r.src)); }100 EXEC_DECL(cvtlf) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<big_t>(r.src)); }
87 EXEC_DECL(cvtfl)101 EXEC_DECL(cvtfl)
88 {102 {
@@ -1626,7 +1640,7 @@ namespace · 1537 unmodified lines
1626 if (e->alloc_type == vm_string_t::type_desc())1640 if (e->alloc_type == vm_string_t::type_desc())
1627 {1641 {
1628 // String1642 // String
1629 exception_id = dynamic_cast<vm_string_t *>(e);1643 exception_id = static_cast<vm_string_t *>(e);
1630 1644
1631 if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>())1645 if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>())
1632 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<\n", exception_id->str());1646 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<\n", exception_id->str());
src/vm/module_reader.cpp+1−1
@@ -481,7 +481,7 @@ namespace · 480 unmodified lines
481 if (arr_maybe->alloc_type != vm_array_t::type_desc())481 if (arr_maybe->alloc_type != vm_array_t::type_desc())
482 throw module_reader_exception{ "Data index not an array type" };482 throw module_reader_exception{ "Data index not an array type" };
483 483
484 auto arr = dynamic_cast<vm_array_t *>(arr_maybe);484 auto arr = static_cast<vm_array_t *>(arr_maybe);
485 485
486 auto array_index = word_t{};486 auto array_index = word_t{};
487 std::tie(success, array_index) = read_next_word(reader);487 std::tie(success, array_index) = read_next_word(reader);
src/vm/stack.cpp+4−4
@@ -203,7 +203,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 202 unmodified lines
203 assert(frame_type != nullptr);203 assert(frame_type != nullptr);
204 assert(sizeof(vm_frame_base_alloc_t) < frame_type->size_in_bytes && "Requested frame size less than VM frame base size");204 assert(sizeof(vm_frame_base_alloc_t) < frame_type->size_in_bytes && "Requested frame size less than VM frame base size");
205 205
206 auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());206 auto layout = static_cast<vm_stack_layout *>(_mem.get());
207 207
208 auto page_top_frame = layout->top_page->page_top_frame;208 auto page_top_frame = layout->top_page->page_top_frame;
209 const auto new_frame_size = sizeof(vm_frame_t) + frame_type->size_in_bytes;209 const auto new_frame_size = sizeof(vm_frame_t) + frame_type->size_in_bytes;
@@ -236,7 +236,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 26 unmodified lines
236 236
237vm_frame_t *vm_stack_t::push_frame()237vm_frame_t *vm_stack_t::push_frame()
238{238{
239 auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());239 auto layout = static_cast<vm_stack_layout *>(_mem.get());
240 240
241 auto current_top_frame = layout->top_frame;241 auto current_top_frame = layout->top_frame;
242 auto new_top_frame = layout->top_page->page_top_frame;242 auto new_top_frame = layout->top_page->page_top_frame;
@@ -252,7 +252,7 @@ vm_frame_t *vm_stack_t::push_frame() · 9 unmodified lines
252 252
253vm_frame_t *vm_stack_t::pop_frame()253vm_frame_t *vm_stack_t::pop_frame()
254{254{
255 auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());255 auto layout = static_cast<vm_stack_layout *>(_mem.get());
256 256
257 auto current_frame = layout->top_frame;257 auto current_frame = layout->top_frame;
258 if (current_frame == nullptr)258 if (current_frame == nullptr)
@@ -292,6 +292,6 @@ vm_frame_t *vm_stack_t::pop_frame() · 33 unmodified lines
292 292
293vm_frame_t *vm_stack_t::peek_frame() const293vm_frame_t *vm_stack_t::peek_frame() const
294{294{
295 auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());295 auto layout = static_cast<vm_stack_layout *>(_mem.get());
296 return layout->top_frame;296 return layout->top_frame;
297}297}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t