Showing the changes to src/vm/vm_memory.cpp (1 of 16 files). Show all
Unified · Split
| @@ -110,7 +110,7 @@ void *disvm::runtime::alloc_memory(std::size_t amount_in_bytes) · 109 unmodified lines | ||
| 110 | 110 | throw vm_system_exception{ "Out of memory" }; |
| 111 | 111 | |
| 112 | 112 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 113 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: %#" PRIxPTR " %d\n", memory, amount_in_bytes); | |
| 113 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: %#" PRIxPTR " %d", memory, amount_in_bytes); | |
| 114 | 114 | |
| 115 | 115 | return memory; |
| 116 | 116 | } |
| @@ -124,7 +124,7 @@ void *disvm::runtime::calloc_memory(std::size_t amount_in_bytes) · 7 unmodified lines | ||
| 124 | 124 | throw vm_system_exception{ "Out of memory" }; |
| 125 | 125 | |
| 126 | 126 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 127 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: zeroed: %#" PRIxPTR " %d\n", memory, amount_in_bytes); | |
| 127 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "alloc: zeroed: %#" PRIxPTR " %d", memory, amount_in_bytes); | |
| 128 | 128 | |
| 129 | 129 | return memory; |
| 130 | 130 | } |
| @@ -135,7 +135,7 @@ void disvm::runtime::free_memory(void *memory) · 4 unmodified lines | ||
| 135 | 135 | return; |
| 136 | 136 | |
| 137 | 137 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 138 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR "\n", memory); | |
| 138 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "free: %#" PRIxPTR, memory); | |
| 139 | 139 | |
| 140 | 140 | std::free(memory); |
| 141 | 141 | } |
| @@ -233,7 +233,7 @@ vm_alloc_t *vm_alloc_t::allocate(std::shared_ptr<const type_descriptor_t> td) · 91 unmodified lines | ||
| 233 | 233 | // Initialize pointer types |
| 234 | 234 | init_memory(*td, alloc->get_allocation()); |
| 235 | 235 | |
| 236 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm alloc: %d\n", td->size_in_bytes); | |
| 236 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm alloc: %d", td->size_in_bytes); | |
| 237 | 237 | return alloc; |
| 238 | 238 | } |
| 239 | 239 | |
| @@ -247,7 +247,7 @@ vm_alloc_t *vm_alloc_t::allocate(std::shared_ptr<const type_descriptor_t> td, co · 7 unmodified lines | ||
| 247 | 247 | auto mem = calloc_memory(sizeof(vm_alloc_t) + td->size_in_bytes); |
| 248 | 248 | auto alloc = ::new(mem)vm_alloc_t{ td }; |
| 249 | 249 | |
| 250 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm alloc: %d\n", td->size_in_bytes); | |
| 250 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm alloc: %d", td->size_in_bytes); | |
| 251 | 251 | return alloc; |
| 252 | 252 | } |
| 253 | 253 | |
| @@ -261,7 +261,7 @@ vm_alloc_t *vm_alloc_t::copy(const vm_alloc_t &other) · 7 unmodified lines | ||
| 261 | 261 | // Ref count all dynamic allocations |
| 262 | 262 | inc_ref_count_in_memory(*alloc_copy->alloc_type, alloc_copy->get_allocation()); |
| 263 | 263 | |
| 264 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR "\n", &other, alloc_copy); | |
| 264 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "copy: vm alloc: %#" PRIxPTR " %#" PRIxPTR, &other, alloc_copy); | |
| 265 | 265 | return alloc_copy; |
| 266 | 266 | } |
| 267 | 267 | |
| @@ -291,7 +291,7 @@ vm_alloc_t::~vm_alloc_t() · 23 unmodified lines | ||
| 291 | 291 | |
| 292 | 292 | // Free pointer types |
| 293 | 293 | destroy_memory(*alloc_type, get_allocation()); |
| 294 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc\n"); | |
| 294 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: vm alloc"); | |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | std::size_t vm_alloc_t::add_ref() |
| @@ -326,24 +326,28 @@ namespace · 28 unmodified lines | ||
| 326 | 326 | { |
| 327 | 327 | namespace hidden_type_desc |
| 328 | 328 | { |
| 329 | − const type_descriptor_t byte{ sizeof(byte_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 330 | − const type_descriptor_t short_word{ sizeof(short_word_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 331 | − const type_descriptor_t word{ sizeof(word_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 332 | − const type_descriptor_t short_real{ sizeof(short_real_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 333 | − const type_descriptor_t real{ sizeof(real_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 334 | − const type_descriptor_t big{ sizeof(big_t), 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 329 | +#define TYPE_DESC(N,S,MS,M,F) const type_descriptor_t N{ S, MS, M, F, #N } | |
| 330 | + | |
| 331 | + TYPE_DESC(byte, sizeof(byte_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 332 | + TYPE_DESC(short_word, sizeof(short_word_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 333 | + TYPE_DESC(word, sizeof(word_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 334 | + TYPE_DESC(short_real, sizeof(short_real_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 335 | + TYPE_DESC(real, sizeof(real_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 336 | + TYPE_DESC(big, sizeof(big_t), 0, nullptr, type_descriptor_t::no_finalizer); | |
| 335 | 337 | |
| 336 | 338 | const byte_t pointer_map[] = { 0x80 }; |
| 337 | − const type_descriptor_t pointer{ sizeof(pointer_t), (sizeof(pointer_map) / sizeof(pointer_map[0])), pointer_map, type_descriptor_t::no_finalizer }; | |
| 339 | + TYPE_DESC(pointer, sizeof(pointer_t), (sizeof(pointer_map) / sizeof(pointer_map[0])), pointer_map, type_descriptor_t::no_finalizer); | |
| 340 | + | |
| 341 | + TYPE_DESC(vm_array, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 342 | + TYPE_DESC(vm_list, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 343 | + TYPE_DESC(vm_channel, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 344 | + TYPE_DESC(vm_string, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 338 | 345 | |
| 339 | − const type_descriptor_t vm_array{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 340 | − const type_descriptor_t vm_list{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 341 | − const type_descriptor_t vm_channel{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 342 | − const type_descriptor_t vm_string{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 346 | + TYPE_DESC(vm_module_ref, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 347 | + TYPE_DESC(vm_stack, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 348 | + TYPE_DESC(vm_thread, 0, 0, nullptr, type_descriptor_t::no_finalizer); | |
| 343 | 349 | |
| 344 | − const type_descriptor_t vm_module_ref{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 345 | − const type_descriptor_t vm_stack{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 346 | − const type_descriptor_t vm_thread{ 0, 0, nullptr, type_descriptor_t::no_finalizer }; | |
| 350 | +#undef TYPE_DESC | |
| 347 | 351 | |
| 348 | 352 | struct |
| 349 | 353 | { |
| @@ -480,7 +484,7 @@ std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( · 130 unmodified lines | ||
| 480 | 484 | debug::assign_debug_pointer(const_cast<byte_t **>(&td->pointer_map)); |
| 481 | 485 | |
| 482 | 486 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 483 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: type descriptor\n"); | |
| 487 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "destroy: type descriptor"); | |
| 484 | 488 | |
| 485 | 489 | free_memory(td); |
| 486 | 490 | } |
| @@ -496,7 +500,7 @@ std::shared_ptr<const type_descriptor_t> type_descriptor_t::create( · 9 unmodified lines | ||
| 496 | 500 | pointer_map_local[i] = pointer_map[i]; |
| 497 | 501 | } |
| 498 | 502 | |
| 499 | − auto new_type = ::new(new_type_memory) type_descriptor_t{ size_in_bytes, pointer_map_length, pointer_map_local, finalizer }; | |
| 503 | + auto new_type = ::new(new_type_memory) type_descriptor_t{ size_in_bytes, pointer_map_length, pointer_map_local, finalizer, "#" }; | |
| 500 | 504 | return std::shared_ptr<type_descriptor_t>{ new_type, deleter }; |
| 501 | 505 | } |
| 502 | 506 | |
| @@ -504,12 +508,17 @@ type_descriptor_t::type_descriptor_t( · 1 unmodified line | ||
| 504 | 508 | word_t size_in_bytes, |
| 505 | 509 | word_t map_in_bytes, |
| 506 | 510 | const byte_t * pointer_map, |
| 507 | − vm_alloc_instance_finalizer_t finalizer) | |
| 511 | + vm_alloc_instance_finalizer_t finalizer, | |
| 512 | + const char *debug_name) | |
| 508 | 513 | : size_in_bytes{ size_in_bytes } |
| 509 | 514 | , map_in_bytes{ map_in_bytes } |
| 510 | 515 | , pointer_map{ pointer_map } |
| 511 | 516 | , finalizer{ finalizer } |
| 517 | +#ifndef NDEBUG | |
| 518 | + , debug_type_name{ debug_name } | |
| 519 | +#endif | |
| 512 | 520 | { |
| 521 | + (void)debug_name; | |
| 513 | 522 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 514 | − debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: type descriptor\n"); | |
| 523 | + debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: type descriptor"); | |
| 515 | 524 | } |