mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Get rid of rust_crate_cache in the runtime
We are no longer generating dynamic tydescs or dicts. Issue #1982
This commit is contained in:
parent
bc21a5ddbe
commit
146b61189a
1
mk/rt.mk
1
mk/rt.mk
@ -40,7 +40,6 @@ RUNTIME_CS_$(1) := \
|
||||
rt/rust.cpp \
|
||||
rt/rust_builtin.cpp \
|
||||
rt/rust_run_program.cpp \
|
||||
rt/rust_crate_cache.cpp \
|
||||
rt/rust_env.cpp \
|
||||
rt/rust_task_thread.cpp \
|
||||
rt/rust_scheduler.cpp \
|
||||
|
@ -1,103 +0,0 @@
|
||||
|
||||
#include "rust_internal.h"
|
||||
#include <algorithm>
|
||||
|
||||
type_desc *
|
||||
rust_crate_cache::get_type_desc(size_t size,
|
||||
size_t align,
|
||||
size_t n_descs,
|
||||
type_desc const **descs,
|
||||
uintptr_t n_obj_params)
|
||||
{
|
||||
I(thread, n_descs > 1);
|
||||
type_desc *td = NULL;
|
||||
size_t keysz = n_descs * sizeof(type_desc*);
|
||||
HASH_FIND(hh, this->type_descs, descs, keysz, td);
|
||||
if (td) {
|
||||
DLOG(thread, cache, "rust_crate_cache::get_type_desc hit");
|
||||
|
||||
// FIXME: This is a gross hack.
|
||||
td->n_obj_params = std::max(td->n_obj_params, n_obj_params);
|
||||
|
||||
return td;
|
||||
}
|
||||
DLOG(thread, cache, "rust_crate_cache::get_type_desc miss");
|
||||
td = (type_desc*) thread->kernel->malloc(sizeof(type_desc) + keysz,
|
||||
"crate cache typedesc");
|
||||
if (!td)
|
||||
return NULL;
|
||||
// By convention, desc 0 is the root descriptor.
|
||||
// but we ignore the size and alignment of it and use the
|
||||
// passed-in, computed values.
|
||||
memcpy(td, descs[0], sizeof(type_desc));
|
||||
td->first_param = &td->descs[1];
|
||||
td->size = size;
|
||||
td->align = align;
|
||||
for (size_t i = 0; i < n_descs; ++i) {
|
||||
DLOG(thread, cache,
|
||||
"rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR,
|
||||
i, descs[i]);
|
||||
td->descs[i] = descs[i];
|
||||
}
|
||||
td->n_obj_params = n_obj_params;
|
||||
td->n_params = n_descs - 1;
|
||||
HASH_ADD(hh, this->type_descs, descs, keysz, td);
|
||||
return td;
|
||||
}
|
||||
|
||||
void**
|
||||
rust_crate_cache::get_dict(size_t n_fields, void** dict) {
|
||||
rust_hashable_dict *found = NULL;
|
||||
size_t dictsz = sizeof(void*) * n_fields;
|
||||
HASH_FIND(hh, this->dicts, dict, dictsz, found);
|
||||
if (found) return &(found->fields[0]);
|
||||
found = (rust_hashable_dict*)
|
||||
thread->kernel->malloc(sizeof(UT_hash_handle) + dictsz,
|
||||
"crate cache dict");
|
||||
if (!found) return NULL;
|
||||
void** retptr = &(found->fields[0]);
|
||||
memcpy(retptr, dict, dictsz);
|
||||
HASH_ADD_KEYPTR(hh, this->dicts, retptr, dictsz, found);
|
||||
return retptr;
|
||||
}
|
||||
|
||||
rust_crate_cache::rust_crate_cache(rust_task_thread *thread)
|
||||
: type_descs(NULL),
|
||||
dicts(NULL),
|
||||
thread(thread),
|
||||
idx(0)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
rust_crate_cache::flush() {
|
||||
DLOG(thread, cache, "rust_crate_cache::flush()");
|
||||
|
||||
while (type_descs) {
|
||||
type_desc *d = type_descs;
|
||||
HASH_DEL(type_descs, d);
|
||||
DLOG(thread, mem, "rust_crate_cache::flush() tydesc %" PRIxPTR, d);
|
||||
thread->kernel->free(d);
|
||||
}
|
||||
while (dicts) {
|
||||
rust_hashable_dict *d = dicts;
|
||||
HASH_DEL(dicts, d);
|
||||
thread->kernel->free(d);
|
||||
}
|
||||
}
|
||||
|
||||
rust_crate_cache::~rust_crate_cache()
|
||||
{
|
||||
flush();
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
// fill-column: 78;
|
||||
// indent-tabs-mode: nil
|
||||
// c-basic-offset: 4
|
||||
// buffer-file-coding-system: utf-8-unix
|
||||
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
||||
// End:
|
||||
//
|
@ -55,7 +55,6 @@ struct rust_task;
|
||||
class rust_log;
|
||||
class rust_port;
|
||||
class rust_kernel;
|
||||
class rust_crate_cache;
|
||||
|
||||
struct stk_seg;
|
||||
struct type_desc;
|
||||
|
@ -71,7 +71,6 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
|
||||
runtime_sp(0),
|
||||
sched(thread->sched),
|
||||
thread(thread),
|
||||
cache(NULL),
|
||||
kernel(thread->kernel),
|
||||
name(name),
|
||||
list_index(-1),
|
||||
@ -445,16 +444,6 @@ rust_task::die() {
|
||||
transition(&thread->running_tasks, &thread->dead_tasks, NULL, "none");
|
||||
}
|
||||
|
||||
rust_crate_cache *
|
||||
rust_task::get_crate_cache()
|
||||
{
|
||||
if (!cache) {
|
||||
DLOG(thread, task, "fetching cache for current crate");
|
||||
cache = thread->get_cache();
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
void
|
||||
rust_task::backtrace() {
|
||||
if (!log_rt_backtrace) return;
|
||||
|
@ -57,7 +57,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||
uintptr_t runtime_sp; // Runtime sp while task running.
|
||||
rust_scheduler *sched;
|
||||
rust_task_thread *thread;
|
||||
rust_crate_cache *cache;
|
||||
|
||||
// Fields known only to the runtime.
|
||||
rust_kernel *kernel;
|
||||
@ -185,7 +184,6 @@ public:
|
||||
void unsupervise();
|
||||
|
||||
frame_glue_fns *get_frame_glue_fns(uintptr_t fp);
|
||||
rust_crate_cache * get_crate_cache();
|
||||
|
||||
void *calloc(size_t size, const char *tag);
|
||||
|
||||
|
@ -24,7 +24,6 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
|
||||
int id) :
|
||||
rust_thread(SCHED_STACK_SIZE),
|
||||
_log(srv, this),
|
||||
cache(this),
|
||||
id(id),
|
||||
should_exit(false),
|
||||
cached_c_stack(NULL),
|
||||
@ -295,11 +294,6 @@ rust_task_thread::start_main_loop() {
|
||||
}
|
||||
}
|
||||
|
||||
rust_crate_cache *
|
||||
rust_task_thread::get_cache() {
|
||||
return &cache;
|
||||
}
|
||||
|
||||
rust_task *
|
||||
rust_task_thread::create_task(rust_task *spawner, const char *name,
|
||||
size_t init_stack_sz) {
|
||||
|
@ -11,37 +11,6 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
struct rust_task_thread;
|
||||
|
||||
struct rust_hashable_dict {
|
||||
UT_hash_handle hh;
|
||||
void* fields[0];
|
||||
};
|
||||
|
||||
class rust_crate_cache {
|
||||
public:
|
||||
type_desc *get_type_desc(size_t size,
|
||||
size_t align,
|
||||
size_t n_descs,
|
||||
type_desc const **descs,
|
||||
uintptr_t n_obj_params);
|
||||
void** get_dict(size_t n_fields, void** dict);
|
||||
|
||||
private:
|
||||
|
||||
type_desc *type_descs;
|
||||
rust_hashable_dict *dicts;
|
||||
|
||||
public:
|
||||
|
||||
rust_task_thread *thread;
|
||||
size_t idx;
|
||||
|
||||
rust_crate_cache(rust_task_thread *thread);
|
||||
~rust_crate_cache();
|
||||
void flush();
|
||||
};
|
||||
|
||||
struct rust_task_thread : public kernel_owned<rust_task_thread>,
|
||||
rust_thread
|
||||
{
|
||||
@ -52,7 +21,6 @@ private:
|
||||
// Fields known only by the runtime:
|
||||
rust_log _log;
|
||||
|
||||
rust_crate_cache cache;
|
||||
const int id;
|
||||
|
||||
#ifndef __WIN32__
|
||||
@ -108,7 +76,6 @@ public:
|
||||
rust_log & get_log();
|
||||
void fail();
|
||||
|
||||
rust_crate_cache *get_cache();
|
||||
size_t number_of_live_tasks();
|
||||
|
||||
void reap_dead_tasks();
|
||||
|
@ -361,73 +361,6 @@ upcall_free_shared_type_desc(type_desc *td) {
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Called to intern a task-local type descriptor into the hashtable
|
||||
* associated with each scheduler.
|
||||
*/
|
||||
|
||||
struct s_get_type_desc_args {
|
||||
type_desc *retval;
|
||||
size_t size;
|
||||
size_t align;
|
||||
size_t n_descs;
|
||||
type_desc const **descs;
|
||||
uintptr_t n_obj_params;
|
||||
};
|
||||
|
||||
extern "C" CDECL void
|
||||
upcall_s_get_type_desc(s_get_type_desc_args *args) {
|
||||
rust_task *task = rust_task_thread::get_task();
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
|
||||
LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR
|
||||
", align=%" PRIdPTR ", %" PRIdPTR " descs", args->size, args->align,
|
||||
args->n_descs);
|
||||
rust_crate_cache *cache = task->get_crate_cache();
|
||||
type_desc *td = cache->get_type_desc(args->size, args->align, args->n_descs,
|
||||
args->descs, args->n_obj_params);
|
||||
LOG(task, cache, "returning tydesc 0x%" PRIxPTR, td);
|
||||
args->retval = td;
|
||||
}
|
||||
|
||||
extern "C" CDECL type_desc *
|
||||
upcall_get_type_desc(void *curr_crate, // ignored, legacy compat.
|
||||
size_t size,
|
||||
size_t align,
|
||||
size_t n_descs,
|
||||
type_desc const **descs,
|
||||
uintptr_t n_obj_params) {
|
||||
s_get_type_desc_args args = {0,size,align,n_descs,descs,n_obj_params};
|
||||
UPCALL_SWITCH_STACK(&args, upcall_s_get_type_desc);
|
||||
return args.retval;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Called to get a heap-allocated dict. These are interned and kept
|
||||
* around indefinitely
|
||||
*/
|
||||
|
||||
struct s_intern_dict_args {
|
||||
size_t n_fields;
|
||||
void** dict;
|
||||
void** res;
|
||||
};
|
||||
|
||||
extern "C" CDECL void
|
||||
upcall_s_intern_dict(s_intern_dict_args *args) {
|
||||
rust_task *task = rust_task_thread::get_task();
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
rust_crate_cache *cache = task->get_crate_cache();
|
||||
args->res = cache->get_dict(args->n_fields, args->dict);
|
||||
}
|
||||
|
||||
extern "C" CDECL void**
|
||||
upcall_intern_dict(size_t n_fields, void** dict) {
|
||||
s_intern_dict_args args = {n_fields, dict, 0 };
|
||||
UPCALL_SWITCH_STACK(&args, upcall_s_intern_dict);
|
||||
return args.res;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
struct s_vec_grow_args {
|
||||
|
@ -65,8 +65,6 @@ upcall_free
|
||||
upcall_validate_box
|
||||
upcall_create_shared_type_desc
|
||||
upcall_free_shared_type_desc
|
||||
upcall_get_type_desc
|
||||
upcall_intern_dict
|
||||
upcall_log_type
|
||||
upcall_malloc
|
||||
upcall_rust_personality
|
||||
|
@ -18,7 +18,6 @@ type upcalls =
|
||||
mark: ValueRef,
|
||||
create_shared_type_desc: ValueRef,
|
||||
free_shared_type_desc: ValueRef,
|
||||
get_type_desc: ValueRef,
|
||||
vec_grow: ValueRef,
|
||||
vec_push: ValueRef,
|
||||
cmp_type: ValueRef,
|
||||
@ -71,12 +70,6 @@ fn declare_upcalls(targ_cfg: @session::config,
|
||||
T_ptr(tydesc_type)),
|
||||
free_shared_type_desc:
|
||||
dv("free_shared_type_desc", [T_ptr(tydesc_type)]),
|
||||
get_type_desc:
|
||||
d("get_type_desc",
|
||||
[T_ptr(T_nil()), size_t,
|
||||
size_t, size_t,
|
||||
T_ptr(T_ptr(tydesc_type)), int_t],
|
||||
T_ptr(tydesc_type)),
|
||||
vec_grow:
|
||||
dv("vec_grow", [T_ptr(T_ptr(opaque_vec_t)), int_t]),
|
||||
vec_push:
|
||||
|
Loading…
Reference in New Issue
Block a user