rt: Stub code for the cycle collector

This commit is contained in:
Patrick Walton 2011-09-20 16:47:59 -07:00
parent c61691110a
commit e26b1883dd
4 changed files with 77 additions and 0 deletions

View file

@ -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 \

57
src/rt/rust_cc.cpp Normal file
View file

@ -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 <cstdio>
#include <cstdlib>
#include <map>
#include <vector>
#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<void *,type_desc *>::iterator begin(task->local_allocs.begin());
std::map<void *,type_desc *>::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

17
src/rt/rust_cc.h Normal file
View file

@ -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

View file

@ -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.