diff --git a/mk/rt.mk b/mk/rt.mk index c460e716e71..5e5fd8dc986 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -27,6 +27,7 @@ RUNTIME_CS := rt/sync/timer.cpp \ rt/rust_obstack.cpp \ rt/rust_gc.cpp \ rt/rust_abi.cpp \ + rt/rust_cc.cpp \ rt/memory_region.cpp \ rt/test/rust_test_harness.cpp \ rt/test/rust_test_runtime.cpp \ diff --git a/src/rt/rust_cc.cpp b/src/rt/rust_cc.cpp new file mode 100644 index 00000000000..8129f60fc7c --- /dev/null +++ b/src/rt/rust_cc.cpp @@ -0,0 +1,57 @@ +// Rust cycle collector. Temporary, but will probably stick around for some +// time until LLVM's GC infrastructure is more mature. + +#include +#include +#include +#include +#include "rust_gc.h" +#include "rust_internal.h" +#include "rust_shape.h" +#include "rust_task.h" + +#undef DPRINT +#define DPRINT(fmt,...) fprintf(stderr, fmt, ##__VA_ARGS__) + +namespace cc { + +void +do_cc(rust_task *task) { + std::map::iterator begin(task->local_allocs.begin()); + std::map::iterator end(task->local_allocs.end()); + while (begin != end) { + void *p = begin->first; + type_desc *tydesc = begin->second; + + DPRINT("marking allocation: %p, tydesc=%p\n", p, tydesc); + + // Prevents warnings for now + (void)p; + (void)tydesc; +#if 0 + shape::arena arena; + shape::type_param *params = + shape::type_param::from_tydesc(tydesc, arena); + mark mark(task, true, tydesc->shape, params, tydesc->shape_tables, p); + mark.walk(); +#endif + + ++begin; + } +} + +void +maybe_cc(rust_task *task) { + // FIXME: We ought to lock this. + static int zeal = -1; + if (zeal == -1) { + char *ev = getenv("RUST_CC_ZEAL"); + zeal = ev && ev[0] != '\0' && ev[0] != '0'; + } + + if (zeal) + do_cc(task); +} + +} // end namespace cc + diff --git a/src/rt/rust_cc.h b/src/rt/rust_cc.h new file mode 100644 index 00000000000..991e69d5c31 --- /dev/null +++ b/src/rt/rust_cc.h @@ -0,0 +1,17 @@ +// Rust cycle collector. Temporary, but will probably stick around for some +// time until LLVM's GC infrastructure is more mature. + +#ifndef RUST_CC_H +#define RUST_CC_H + +struct rust_task; + +namespace cc { + +void do_cc(rust_task *task); +void maybe_cc(rust_task *task); + +} // end namespace cc + +#endif + diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 5fabb5cd1ab..863e22052e7 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -1,3 +1,4 @@ +#include "rust_cc.h" #include "rust_gc.h" #include "rust_internal.h" #include "rust_unwind.h" @@ -61,6 +62,7 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) { nbytes, td); gc::maybe_gc(task); + cc::maybe_cc(task); // TODO: Maybe use dladdr here to find a more useful name for the // type_desc.