From ad19ab4c6fdf3ea74ac0ff3688d040a852f30760 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 26 Sep 2011 15:06:26 -0700 Subject: [PATCH] rt: Make the logic that moves environments between tasks update the GC alloc chain correctly --- src/rt/rust_builtin.cpp | 4 ++-- src/rt/rust_cc.cpp | 18 ++++++++++++------ src/rt/rust_task.cpp | 31 +++++++++++++++++++++++++++++++ src/rt/rust_task.h | 5 +++++ 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 3d89aa918ceb..7226171e9f15 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -456,8 +456,8 @@ migrate_alloc(rust_task *task, void *alloc, rust_task_id tid) { if(!alloc) return; rust_task *target = task->kernel->get_task_by_id(tid); if(target) { - task->local_region.release_alloc(alloc); - target->local_region.claim_alloc(alloc); + const type_desc *tydesc = task->release_alloc(alloc); + target->claim_alloc(alloc, tydesc); target->deref(); } else { diff --git a/src/rt/rust_cc.cpp b/src/rt/rust_cc.cpp index 9d6c4992b178..c53ec1aa51c2 100644 --- a/src/rt/rust_cc.cpp +++ b/src/rt/rust_cc.cpp @@ -178,16 +178,22 @@ irc::compute_ircs(rust_task *task, irc_map &ircs) { shape::arena arena; shape::type_param *params = shape::type_param::from_tydesc_and_data(tydesc, p, arena); + +#if 0 + shape::print print(task, true, tydesc->shape, params, + tydesc->shape_tables); + print.walk(); + + shape::log log(task, true, tydesc->shape, params, + tydesc->shape_tables, p + sizeof(uintptr_t), + std::cerr); + log.walk(); +#endif + irc irc(task, true, tydesc->shape, params, tydesc->shape_tables, p + sizeof(uintptr_t), ircs); irc.walk(); -#if 0 - shape::log log(task, true, tydesc->shape, params, - tydesc->shape_tables, p, std::cerr); - log.walk(); -#endif - ++begin; } } diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index ca85411e9d5e..f2c866263cf0 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -152,6 +152,8 @@ void task_start_wrapper(spawn_args *a) failed = true; } + cc::do_cc(task); + rust_closure_env* env = (rust_closure_env*)a->a3; if(env) { // free the environment. @@ -551,6 +553,35 @@ rust_chan *rust_task::get_chan_by_handle(chan_handle *handle) { return NULL; } +// Temporary routine to allow boxes on one task's shared heap to be reparented +// to another. +const type_desc * +rust_task::release_alloc(void *alloc) { + lock.lock(); + + assert(local_allocs.find(alloc) != local_allocs.end()); + const type_desc *tydesc = local_allocs[alloc]; + local_allocs.erase(alloc); + + local_region.release_alloc(alloc); + + lock.unlock(); + return tydesc; +} + +// Temporary routine to allow boxes from one task's shared heap to be +// reparented to this one. +void +rust_task::claim_alloc(void *alloc, const type_desc *tydesc) { + lock.lock(); + + assert(local_allocs.find(alloc) == local_allocs.end()); + local_allocs[alloc] = tydesc; + local_region.claim_alloc(alloc); + + lock.unlock(); +} + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 76b828af58f4..f364d2a67f7f 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -204,6 +204,11 @@ rust_task : public kernel_owned, rust_cond intptr_t get_ref_count() const { return ref_count; } rust_chan *get_chan_by_handle(chan_handle *handle); + + // FIXME: These functions only exist to get the tasking system off the + // ground. We should never be migrating shared boxes between tasks. + const type_desc *release_alloc(void *alloc); + void claim_alloc(void *alloc, const type_desc *tydesc); }; //