From acce384bcc88d5b300b913c14b9872081a182155 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 3 Jan 2018 00:31:10 -0800 Subject: 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? --- 038new_text.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to '038new_text.cc') diff --git a/038new_text.cc b/038new_text.cc index ea73dac6..4b666f1c 100644 --- a/038new_text.cc +++ b/038new_text.cc @@ -41,9 +41,7 @@ int new_mu_text(const string& contents) { //? Total_alloc += string_length+1; //? ++Num_alloc; int result = allocate(string_length+/*array length*/1); - trace("mem") << "storing string refcount 0 in location " << result << end(); - put(Memory, result, 0); - int curr_address = result+/*skip refcount*/1; + int curr_address = result; trace("mem") << "storing string length " << string_length << " in location " << curr_address << end(); put(Memory, curr_address, string_length); ++curr_address; // skip length @@ -118,13 +116,13 @@ if (!canonize_type(x)) return false; //: Allocate more to routine when initializing a literal string :(scenario new_string_overflow) -% Initial_memory_per_routine = 3; +% Initial_memory_per_routine = 2; def main [ 1:address:num/raw <- new number:type - 2:text/raw <- new [a] # not enough room in initial page, if you take the refcount and array length into account + 2:text/raw <- new [a] # not enough room in initial page, if you take the array length into account ] -+new: routine allocated memory from 1000 to 1003 -+new: routine allocated memory from 1003 to 1006 ++new: routine allocated memory from 1000 to 1002 ++new: routine allocated memory from 1002 to 1004 //: helpers :(code) @@ -142,7 +140,6 @@ int unicode_length(const string& s) { string read_mu_text(int address) { if (address == 0) return ""; - ++address; // skip refcount int length = get_or_insert(Memory, address); if (length == 0) return ""; return read_mu_characters(address+1, length); -- cgit 1.4.1-2-gfad0