From 9a6f87985ca92d0c7051c7e39bf4e7357a2318db Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 28 Jun 2016 19:33:43 -0700 Subject: 3070 Extract out the implementation of 'allocate' so other instructions (ahem, deep-copy) can use it. --- 034address.cc | 23 ++++++++++++++--------- 037abandon.cc | 13 ++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/034address.cc b/034address.cc index d78a0bb0..be8a8100 100644 --- a/034address.cc +++ b/034address.cc @@ -275,33 +275,38 @@ case ALLOCATE: { trace(9999, "mem") << "array size is " << ingredients.at(1).at(0) << end(); size = /*space for length*/1 + size*ingredients.at(1).at(0); } + int result = allocate(size); + if (SIZE(current_instruction().ingredients) > 1) { + // initialize array length + trace(9999, "mem") << "storing " << ingredients.at(1).at(0) << " in location " << result+/*skip refcount*/1 << end(); + put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); + } + products.resize(1); + products.at(0).push_back(result); + break; +} +:(code) +int allocate(int size) { // include space for refcount size++; trace(9999, "mem") << "allocating size " << size << end(); //? Total_alloc += size; //? Num_alloc++; + // Allocate Special-cases // compute the region of memory to return // really crappy at the moment ensure_space(size); const int result = Current_routine->alloc; trace(9999, "mem") << "new alloc: " << result << end(); - // save result - products.resize(1); - products.at(0).push_back(result); // initialize allocated space for (int address = result; address < result+size; ++address) { trace(9999, "mem") << "storing 0 in location " << address << end(); put(Memory, address, 0); } - if (SIZE(current_instruction().ingredients) > 1) { - // initialize array length - trace(9999, "mem") << "storing " << ingredients.at(1).at(0) << " in location " << result+/*skip refcount*/1 << end(); - put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); - } Current_routine->alloc += size; // no support yet for reclaiming memory between routines assert(Current_routine->alloc <= Current_routine->alloc_max); - break; + return result; } //: statistics for debugging diff --git a/037abandon.cc b/037abandon.cc index ea26020a..d3fc84b8 100644 --- a/037abandon.cc +++ b/037abandon.cc @@ -67,25 +67,20 @@ void abandon(int address, const type_tree* payload_type, int payload_size) { put(Current_routine->free_list, payload_size, address); } -:(before "ensure_space(size)" following "case ALLOCATE") +:(after "Allocate Special-cases") if (get_or_insert(Current_routine->free_list, size)) { trace(9999, "abandon") << "picking up space from free-list of size " << size << end(); int result = get_or_insert(Current_routine->free_list, size); trace(9999, "mem") << "new alloc from free list: " << result << end(); put(Current_routine->free_list, size, get_or_insert(Memory, result)); - for (int curr = result+1; curr < result+size; ++curr) { + put(Memory, result, 0); + for (int curr = result; curr < result+size; ++curr) { if (get_or_insert(Memory, curr) != 0) { raise << maybe(current_recipe_name()) << "memory in free list was not zeroed out: " << curr << '/' << result << "; somebody wrote to us after free!!!\n" << end(); break; // always fatal } } - if (SIZE(current_instruction().ingredients) > 1) - put(Memory, result+/*skip refcount*/1, ingredients.at(1).at(0)); - else - put(Memory, result, 0); - products.resize(1); - products.at(0).push_back(result); - break; + return result; } :(scenario new_differing_size_no_reclaim) -- cgit 1.4.1-2-gfad0