Showing the changes to src/vm/vm_memory.cpp (1 of 5 files). Show all
Unified · Split
| @@ -140,20 +140,18 @@ void disvm::runtime::free_memory(void *memory) · 139 unmodified lines | |||
| 140 | void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data) | 140 | void disvm::runtime::init_memory(const type_descriptor_t &type_desc, void *data) |
| 141 | { | 141 | { |
| 142 | assert(data != nullptr); | 142 | assert(data != nullptr); |
| 143 | auto memory_word_len = std::size_t{ type_desc.size_in_bytes / sizeof(word_t) }; | 143 | if (type_desc.size_in_bytes == 0) |
| 144 | if (memory_word_len == 0) | ||
| 145 | return; | 144 | return; |
| 146 | 145 | ||
| 147 | debug::assign_debug_memory(data, type_desc.size_in_bytes); | 146 | debug::assign_debug_memory(data, type_desc.size_in_bytes); |
| 148 | 147 | ||
| 149 | auto memory = reinterpret_cast<word_t *>(data); | 148 | auto memory = reinterpret_cast<word_t *>(data); |
| 150 | assert((memory_word_len / sizeof(word_t)) <= static_cast<std::size_t>(type_desc.size_in_bytes)); // type desc is in bytes convert len to bytes from words. | ||
| 151 | for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8) | 149 | for (auto i = word_t{ 0 }; i < type_desc.map_in_bytes; ++i, memory += 8) |
| 152 | { | 150 | { |
| 153 | const auto words8 = type_desc.pointer_map[i]; | 151 | const auto words8 = type_desc.pointer_map[i]; |
| 154 | if (words8 != 0) | 152 | if (words8 != 0) |
| 155 | { | 153 | { |
| 156 | auto flags = std::bitset<sizeof(words8) * 8>{ words8 }; | 154 | const auto flags = std::bitset<sizeof(words8) * 8>{ words8 }; |
| 157 | 155 | ||
| 158 | // Enumerating the flags in reverse order so memory access is linear. | 156 | // Enumerating the flags in reverse order so memory access is linear. |
| 159 | if (flags[7]) memory[0] = runtime_constants::nil; | 157 | if (flags[7]) memory[0] = runtime_constants::nil; |
| @@ -414,19 +412,19 @@ static std::shared_ptr<const type_descriptor_t> intrinsic_type_desc::type<vm_thr · 254 unmodified lines | |||
| 414 | 412 | ||
| 415 | vm_alloc_instance_finalizer_t type_descriptor_t::no_finalizer = nullptr; | 413 | vm_alloc_instance_finalizer_t type_descriptor_t::no_finalizer = nullptr; |
| 416 | 414 | ||
| 417 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create(const word_t size) | 415 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create(const word_t size_in_bytes) |
| 418 | { | 416 | { |
| 419 | return type_descriptor_t::create(size, 0, nullptr); | 417 | return type_descriptor_t::create(size_in_bytes, 0, nullptr); |
| 420 | } | 418 | } |
| 421 | 419 | ||
| 422 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create(const word_t size, const std::vector<byte_t> &pointer_map) | 420 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create(const word_t size_in_bytes, const std::vector<byte_t> &pointer_map) |
| 423 | { | 421 | { |
| 424 | assert(pointer_map.size() < static_cast<std::size_t>(std::numeric_limits<word_t>::max())); | 422 | assert(pointer_map.size() < static_cast<std::size_t>(std::numeric_limits<word_t>::max())); |
| 425 | return type_descriptor_t::create(size, static_cast<word_t>(pointer_map.size()), pointer_map.data()); | 423 | return type_descriptor_t::create(size_in_bytes, static_cast<word_t>(pointer_map.size()), pointer_map.data()); |
| 426 | } | 424 | } |
| 427 | 425 | ||
| 428 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( | 426 | std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( |
| 429 | const word_t size, | 427 | const word_t size_in_bytes, |
| 430 | const word_t pointer_map_length, | 428 | const word_t pointer_map_length, |
| 431 | const byte_t *pointer_map, | 429 | const byte_t *pointer_map, |
| 432 | const vm_alloc_instance_finalizer_t finalizer) | 430 | const vm_alloc_instance_finalizer_t finalizer) |
| @@ -453,7 +451,7 @@ std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( · 20 unmodified lines | |||
| 453 | pointer_map_local[i] = pointer_map[i]; | 451 | pointer_map_local[i] = pointer_map[i]; |
| 454 | } | 452 | } |
| 455 | 453 | ||
| 456 | auto new_type = ::new(new_type_memory) type_descriptor_t{ size, pointer_map_length, pointer_map_local, finalizer }; | 454 | auto new_type = ::new(new_type_memory) type_descriptor_t{ size_in_bytes, pointer_map_length, pointer_map_local, finalizer }; |
| 457 | return std::shared_ptr<type_descriptor_t>{ new_type, deleter }; | 455 | return std::shared_ptr<type_descriptor_t>{ new_type, deleter }; |
| 458 | } | 456 | } |
| 459 | 457 | ||