diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2019-04-09 02:59:08 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2019-04-09 02:59:08 +0100 |
commit | 5c331f54c23dd5db6ee4cd92bf67460935aaec5f (patch) | |
tree | 71a0f73e77b7b2afadaf066162225c634abae585 /mixlib/mix_vm.h | |
parent | 5e854d5060e4874d27049cda500535bb7eabe6d9 (diff) | |
download | mdk-5c331f54c23dd5db6ee4cd92bf67460935aaec5f.tar.gz mdk-5c331f54c23dd5db6ee4cd92bf67460935aaec5f.tar.bz2 |
Change vm->address_list from GSList to GQueue
The current emulator uses an unbounded linked list for tracking the
memory locations our program has traveled through. On a 64 bit system,
this requires 16 bytes of data for every instruction a MIX program
performs. For small programs that are light on computation cycles,
this does not cause a noticeable issue.
For programs that execute hundreds of millions of instructions, this
causes the memory footprint of the virtual machine to explode. I have
attached an example MIXAL program that will cause the VM to grow to
over 3 GB of memory usage when run.
To run the sample, compile coin-opt.mixal (attached), run it in mixvm,
and enter 499 at the prompt. Or use the following steps.
This patch changes all the appropriate references to GQueue references
and also caps the backtrace at 1000, which can be changed in the
mixlib/mix_vm.h header. I feel like 1000 is a reasonable limit for the
vast majority of debugging needs. Most people are looking back at the
most recent 100 instructions or so.
You can get the original behavior (unlimited tracing) back by setting
the MIX_MAXTRACE to -1, albeit with a slightly higher memory cost (24
bytes per instruction). Or you can turn it off entirely by setting it
to 0.
Using a queue doesn't change the logic of the program in any
significant way, and it allows programs to run for an extended period
of time without consuming all the memory on the machine and slowing
down to a crawl.
-Kevin Brunelle
Diffstat (limited to 'mixlib/mix_vm.h')
-rw-r--r-- | mixlib/mix_vm.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mixlib/mix_vm.h b/mixlib/mix_vm.h index 0f4e690..4b07164 100644 --- a/mixlib/mix_vm.h +++ b/mixlib/mix_vm.h @@ -34,6 +34,9 @@ /* Comparison flag */ typedef enum { mix_LESS, mix_EQ, mix_GREAT } mix_cmpflag_t; +/* Maximum number of addresses for backtraces: -1 = unlimited, 0 = off */ +enum { MIX_MAX_TRACE_AMOUNT = 500 }; + /* Number of memory cells in the virtual machine */ enum { MIX_VM_CELL_NO = 4000 }; @@ -247,9 +250,16 @@ extern mix_time_t mix_vm_get_uptime (const mix_vm_t *vm); /* Get the list of addresses for executed instructions */ -extern const GSList * +extern GQueue * mix_vm_get_backtrace (const mix_vm_t *vm); +/* Get the maximum number of instructions we will trace */ +gint +mix_vm_get_max_trace (const mix_vm_t *vm); + +/* Set the maximum number of instructions we will trace */ +void +mix_vm_set_max_trace (mix_vm_t *vm, gint val); #endif /* MIX_VM_H */ |