about summary refs log tree commit diff stats
path: root/085scenario_console.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2018-01-03 00:31:10 -0800
committerKartik K. Agaram <vc@akkartik.com>2018-01-03 00:44:09 -0800
commitacce384bcc88d5b300b913c14b9872081a182155 (patch)
treea21c33d342c44382b08e37a212a2e79416baca45 /085scenario_console.cc
parentc8eb6c1a64d76dc9a1005571c4eb71ddc6d8f2a9 (diff)
downloadmu-acce384bcc88d5b300b913c14b9872081a182155.tar.gz
4179 - experiment: rip out memory reclamation
I have a plan for a way to avoid use-after-free errors without all the
overheads of maintaining refcounts. Has the nice side-effect of
requiring manual memory management. The Mu way is to leak memory by
default and build tools to help decide when and where to expend effort
plugging memory leaks. Arguably programs should be distributed with
summaries of their resource use characteristics.

Eliminating refcount maintenance reduces time to run tests by 30% for
`mu edit`:

              this commit                 parent
  mu test:         3.9s                        4.5s
  mu test edit:  2:38                        3:48

Open questions:
  - making reclamation easier; some sort of support for destructors
  - reclaiming local scopes (which are allocated on the heap)
    - should we support automatically reclaiming allocations inside them?
Diffstat (limited to '085scenario_console.cc')
-rw-r--r--085scenario_console.cc16
1 files changed, 6 insertions, 10 deletions
diff --git a/085scenario_console.cc b/085scenario_console.cc
index cb69bdb0..2c3ab4bc 100644
--- a/085scenario_console.cc
+++ b/085scenario_console.cc
@@ -58,11 +58,11 @@ case ASSUME_CONSOLE: {
   slurp_body(in, r);
   int num_events = count_events(r);
   // initialize the events like in new-fake-console
-  int size = /*space for refcount and length*/2 + num_events*size_of_event();
+  int size = /*length*/1 + num_events*size_of_event();
   int event_data_address = allocate(size);
   // store length
-  put(Memory, event_data_address+/*skip refcount*/1, num_events);
-  int curr_address = event_data_address + /*skip refcount and length*/2;
+  put(Memory, event_data_address, num_events);
+  int curr_address = event_data_address + /*skip length*/1;
   for (int i = 0;  i < SIZE(r.steps);  ++i) {
     const instruction& inst = r.steps.at(i);
     if (inst.name == "left-click") {
@@ -118,12 +118,8 @@ case ASSUME_CONSOLE: {
   int console_address = allocate(size_of_console());
   trace("mem") << "storing console in " << console_address << end();
   put(Memory, CONSOLE, console_address);
-  trace("mem") << "storing console data in " << console_address+/*skip refcount*/1+/*offset of 'data' in container 'events'*/1 << end();
-  put(Memory, console_address+/*skip refcount*/1+/*offset of 'data' in container 'events'*/1, event_data_address);
-  // increment refcount for event data
-  put(Memory, event_data_address, 1);
-  // increment refcount for console
-  put(Memory, console_address, 1);
+  trace("mem") << "storing console data in " << console_address+/*offset of 'data' in container 'events'*/1 << end();
+  put(Memory, console_address+/*offset of 'data' in container 'events'*/1, event_data_address);
   break;
 }
 
@@ -309,7 +305,7 @@ int size_of_console() {
   if (result) return result;
   assert(get(Type_ordinal, "console"));
   type_tree* type = new type_tree("console");
-  result = size_of(type)+/*refcount*/1;
+  result = size_of(type);
   delete type;
   return result;
 }