From dcd2563a3a7662d03ab33b67c92652e6e24c5af1 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Wed, 6 Jul 2011 16:42:02 -0700 Subject: [PATCH] Removing the synchronized memory region from tasks. --- src/rt/memory.h | 36 ++++--------------------- src/rt/memory_region.h | 3 --- src/rt/rust_builtin.cpp | 11 ++++---- src/rt/rust_srv.cpp | 3 +-- src/rt/rust_srv.h | 2 +- src/rt/rust_task.cpp | 58 ++++++----------------------------------- src/rt/rust_task.h | 6 ----- 7 files changed, 21 insertions(+), 98 deletions(-) diff --git a/src/rt/memory.h b/src/rt/memory.h index d5e5a6eb1a7..edf8d27eb2d 100644 --- a/src/rt/memory.h +++ b/src/rt/memory.h @@ -11,49 +11,23 @@ inline void *operator new(size_t size, rust_kernel *kernel) { } inline void *operator new(size_t size, rust_task *task) { - return task->malloc(size, memory_region::LOCAL); + return task->malloc(size); } inline void *operator new[](size_t size, rust_task *task) { - return task->malloc(size, memory_region::LOCAL); + return task->malloc(size); } inline void *operator new(size_t size, rust_task &task) { - return task.malloc(size, memory_region::LOCAL); + return task.malloc(size); } inline void *operator new[](size_t size, rust_task &task) { - return task.malloc(size, memory_region::LOCAL); -} - -inline void *operator new(size_t size, rust_task *task, - memory_region::memory_region_type type) { - return task->malloc(size, type); -} - -inline void *operator new[](size_t size, rust_task *task, - memory_region::memory_region_type type) { - return task->malloc(size, type); -} - -inline void *operator new(size_t size, rust_task &task, - memory_region::memory_region_type type) { - return task.malloc(size, type); -} - -inline void *operator new[](size_t size, rust_task &task, - memory_region::memory_region_type type) { - return task.malloc(size, type); + return task.malloc(size); } inline void operator delete(void *mem, rust_task *task) { - task->free(mem, memory_region::LOCAL); - return; -} - -inline void operator delete(void *mem, rust_task *task, - memory_region::memory_region_type type) { - task->free(mem, type); + task->free(mem); return; } diff --git a/src/rt/memory_region.h b/src/rt/memory_region.h index 381392b6af0..a72faf76338 100644 --- a/src/rt/memory_region.h +++ b/src/rt/memory_region.h @@ -23,9 +23,6 @@ private: const bool _synchronized; lock_and_signal _lock; public: - enum memory_region_type { - LOCAL = 0x1, SYNCHRONIZED = 0x2 - }; memory_region(rust_srv *srv, bool synchronized); memory_region(memory_region *parent); void *malloc(size_t size); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 32e12e71058..f97040928a0 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -42,7 +42,7 @@ last_os_error(rust_task *task) { #endif size_t fill = strlen(buf) + 1; size_t alloc = next_power_of_two(sizeof(rust_str) + fill); - void *mem = task->malloc(alloc, memory_region::LOCAL); + void *mem = task->malloc(alloc); if (!mem) { task->fail(1); return NULL; @@ -74,7 +74,7 @@ rust_getcwd(rust_task *task) { size_t fill = strlen(cbuf) + 1; size_t alloc = next_power_of_two(sizeof(rust_str) + fill); - void *mem = task->malloc(alloc, memory_region::LOCAL); + void *mem = task->malloc(alloc); if (!mem) { task->fail(1); return NULL; @@ -201,7 +201,7 @@ vec_alloc_with_data(rust_task *task, { rust_scheduler *sched = task->sched; size_t alloc = next_power_of_two(sizeof(rust_vec) + (n_elts * elt_size)); - void *mem = task->malloc(alloc, memory_region::LOCAL); + void *mem = task->malloc(alloc); if (!mem) return NULL; return new (mem) rust_vec(sched, alloc, fill * elt_size, (uint8_t*)d); } @@ -635,8 +635,9 @@ ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems) v->payload.ptr = heap_part; } else { // On heap; resize. - heap_part = (rust_ivec_heap *)task->realloc(v->payload.ptr, - new_alloc + sizeof(size_t)); + heap_part = (rust_ivec_heap *) + task->realloc(v->payload.ptr, + new_alloc + sizeof(size_t)); v->payload.ptr = heap_part; } diff --git a/src/rt/rust_srv.cpp b/src/rt/rust_srv.cpp index 8bdfcd7a064..1587176fc8a 100644 --- a/src/rt/rust_srv.cpp +++ b/src/rt/rust_srv.cpp @@ -6,8 +6,7 @@ #include "rust_srv.h" rust_srv::rust_srv() : - local_region(this, false), - synchronized_region(this, true) { + local_region(this, false) { // Nop. } diff --git a/src/rt/rust_srv.h b/src/rt/rust_srv.h index 465b03b7ecc..beec5d70345 100644 --- a/src/rt/rust_srv.h +++ b/src/rt/rust_srv.h @@ -1,3 +1,4 @@ +// -*- c++ -*- #ifndef RUST_SRV_H #define RUST_SRV_H @@ -6,7 +7,6 @@ class rust_srv { public: memory_region local_region; - memory_region synchronized_region; virtual void log(char const *msg); virtual void fatal(char const *expression, char const *file, diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 0ca34e0985d..721f5b0ed20 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -73,7 +73,6 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state, running_on(-1), pinned_on(-1), local_region(&sched->srv->local_region), - synchronized_region(&sched->srv->synchronized_region), _on_wakeup(NULL) { LOGPTR(sched, "new task", (uintptr_t)this); @@ -326,7 +325,7 @@ rust_task::malloc(size_t sz, type_desc *td) if (td) { sz += sizeof(gc_alloc); } - void *mem = malloc(sz, memory_region::LOCAL); + void *mem = local_region.malloc(sz); if (!mem) return mem; if (td) { @@ -353,7 +352,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc) gc_alloc *gcm = (gc_alloc*)(((char *)data) - sizeof(gc_alloc)); unlink_gc(gcm); sz += sizeof(gc_alloc); - gcm = (gc_alloc*) realloc((void*)gcm, sz, memory_region::LOCAL); + gcm = (gc_alloc*) local_region.realloc((void*)gcm, sz); DLOG(sched, task, "task %s @0x%" PRIxPTR " reallocated %d GC bytes = 0x%" PRIxPTR, name, (uintptr_t)this, sz, gcm); @@ -362,7 +361,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc) link_gc(gcm); data = (void*) &(gcm->data); } else { - data = realloc(data, sz, memory_region::LOCAL); + data = local_region.realloc(data, sz); } return data; } @@ -379,9 +378,11 @@ rust_task::free(void *p, bool is_gc) DLOG(sched, mem, "task %s @0x%" PRIxPTR " freeing GC memory = 0x%" PRIxPTR, name, (uintptr_t)this, gcm); - free(gcm, memory_region::LOCAL); + DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", gcm); + local_region.free(gcm); } else { - free(p, memory_region::LOCAL); + DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", p); + local_region.free(p); } } @@ -473,52 +474,9 @@ bool rust_task::can_schedule(int id) (pinned_on == -1 || pinned_on == id); } -void * -rust_task::malloc(size_t size, memory_region::memory_region_type type) { - if (type == memory_region::LOCAL) { - return local_region.malloc(size); - } else if (type == memory_region::SYNCHRONIZED) { - return synchronized_region.malloc(size); - } - I(sched, false); - return NULL; -} - void * rust_task::calloc(size_t size) { - return calloc(size, memory_region::LOCAL); -} - -void * -rust_task::calloc(size_t size, memory_region::memory_region_type type) { - if (type == memory_region::LOCAL) { - return local_region.calloc(size); - } else if (type == memory_region::SYNCHRONIZED) { - return synchronized_region.calloc(size); - } - return NULL; -} - -void * -rust_task::realloc(void *mem, size_t size, - memory_region::memory_region_type type) { - if (type == memory_region::LOCAL) { - return local_region.realloc(mem, size); - } else if (type == memory_region::SYNCHRONIZED) { - return synchronized_region.realloc(mem, size); - } - return NULL; -} - -void -rust_task::free(void *mem, memory_region::memory_region_type type) { - DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", mem); - if (type == memory_region::LOCAL) { - local_region.free(mem); - } else if (type == memory_region::SYNCHRONIZED) { - synchronized_region.free(mem); - } - return; + return local_region.calloc(size); } void rust_task::pin() { diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 29da8d82723..e15f105222b 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -81,7 +81,6 @@ rust_task : public maybe_proxy, int pinned_on; memory_region local_region; - memory_region synchronized_region; class wakeup_callback { public: @@ -153,12 +152,7 @@ rust_task : public maybe_proxy, bool can_schedule(int worker); - void *malloc(size_t size, memory_region::memory_region_type type); void *calloc(size_t size); - void *calloc(size_t size, memory_region::memory_region_type type); - void *realloc(void *mem, size_t size, - memory_region::memory_region_type type); - void free(void *mem, memory_region::memory_region_type type); void pin(); void pin(int id);