about summary refs log tree commit diff stats
path: root/073scheduler.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 /073scheduler.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 '073scheduler.cc')
-rw-r--r--073scheduler.cc69
1 files changed, 0 insertions, 69 deletions
diff --git a/073scheduler.cc b/073scheduler.cc
index a8af8853..51b3584f 100644
--- a/073scheduler.cc
+++ b/073scheduler.cc
@@ -130,7 +130,6 @@ void run_main(int argc, char* argv[]) {
     vector<double> arg;
     arg.push_back(new_mu_text(argv[i]));
     assert(get(Memory, arg.back()) == 0);
-    put(Memory, arg.back(), 1);  // update refcount
     current_call().ingredient_atoms.push_back(arg);
   }
   run(main_routine);
@@ -253,74 +252,6 @@ def f2 n:&:num [
 :(before "End is_indirect_call_with_ingredients Special-cases")
 if (r == START_RUNNING) return true;
 
-//: refcounting management when starting up new routines
-
-:(scenario start_running_immediately_updates_refcounts_of_ingredients)
-% Scheduling_interval = 1;
-def main [
-  local-scope
-  create-new-routine
-  # padding to make sure we run new-routine before returning
-  dummy:num <- copy 0
-  dummy:num <- copy 0
-]
-def create-new-routine [
-  local-scope
-  n:&:num <- new number:type
-  *n <- copy 34
-  start-running new-routine, n
-  # refcount of n decremented
-]
-def new-routine n:&:num [
-  local-scope
-  load-ingredients
-  1:num/raw <- copy *n
-]
-# check that n was successfully passed into new-routine before being reclaimed
-+mem: storing 34 in location 1
-
-//: ensure this works with indirect calls using 'call' as well
-:(scenario start_running_immediately_updates_refcounts_of_ingredients_of_indirect_calls)
-% Scheduling_interval = 1;
-def main [
-  local-scope
-  n:&:num <- new number:type
-  *n <- copy 34
-  call f1, n
-  1:num/raw <- copy *n
-]
-def f1 n:&:num [
-  local-scope
-  load-ingredients
-]
-# check that n was successfully passed into new-routine before being reclaimed
-+mem: storing 34 in location 1
-
-:(scenario next_ingredient_never_leaks_refcounts)
-def create-space n:&:num -> default-space:space [
-  default-space <- new location:type, 2
-  load-ingredients
-]
-def use-space [
-  local-scope
-  0:space/names:create-space <- next-ingredient
-  n:&:num/space:1 <- next-ingredient  # should decrement refcount
-  *n/space:1 <- copy 34
-  n2:num <- add *n/space:1, 1
-  return n2
-]
-def main [
-  local-scope
-  n:&:num <- copy 12000/unsafe  # pretend allocation with a known address
-  *n <- copy 23
-  space:space/names:create-space <- create-space n
-  n2:&:num <- copy 13000/unsafe
-  n3:num <- use-space space, n2
-]
-+run: {n: ("address" "number"), "space": "1"} <- next-ingredient
-+mem: decrementing refcount of 12000: 2 -> 1
-+run: {n: ("address" "number"), "space": "1", "lookup": ()} <- copy {34: "literal"}
-
 //: back to testing 'start-running'
 
 :(scenario start_running_returns_routine_id)