History

Move some basic offset functions to header files for inlining ease Replace enum_pointer_field functions with custom implementations - GC now has custom implementation - other implementations use template<> version Fix misuse of shared_ptr<type_descriptor_t> in various built-in types Observed 5 - 8 % improvement in GC for compiler scenario.

arr committed 9 years ago

Commit cd2748b1 parent 3dd1c8210 files · +115 −160Browse files

Showing the changes to src/include/runtime.h (1 of 10 files). Show all

Unified · Split

src/include/runtime.h+15−3
@@ -98,7 +98,14 @@ namespace disvm · 97 unmodified lines
9898
9999 static vm_alloc_t *allocate(std::shared_ptr<const type_descriptor_t> td);
100100 static vm_alloc_t *copy(const vm_alloc_t &other);
101− static vm_alloc_t *from_allocation(pointer_t allocation);
101+
102+ static vm_alloc_t *from_allocation(pointer_t allocation)
103+ {
104+ if (allocation == nullptr)
105+ return nullptr;
106+
107+ return reinterpret_cast<vm_alloc_t *>(reinterpret_cast<uint8_t *>(allocation) - sizeof(vm_alloc_t));
108+ }
102109
103110 template <typename T>
104111 static T *from_allocation(pointer_t allocation)
@@ -125,7 +132,12 @@ namespace disvm · 20 unmodified lines
125132 pointer_t gc_reserved;
126133
127134 public:
128− pointer_t get_allocation() const;
135+ pointer_t get_allocation() const
136+ {
137+ // Remove const on the this pointer so the offset can be computed.
138+ auto non_const_this = const_cast<vm_alloc_t *>(this);
139+ return reinterpret_cast<pointer_t>(reinterpret_cast<uint8_t *>(non_const_this) + sizeof(vm_alloc_t));
140+ }
129141
130142 template <typename T>
131143 T *get_allocation() const
@@ -638,7 +650,7 @@ namespace disvm · 506 unmodified lines
638650 class vm_frame_t final
639651 {
640652 public:
641− vm_frame_t(std::shared_ptr<const type_descriptor_t> &frame_type);
653+ vm_frame_t(std::shared_ptr<const type_descriptor_t> frame_type);
642654 ~vm_frame_t();
643655
644656 std::shared_ptr<const type_descriptor_t> frame_type;