Skip to content

Commit 37d287d

Browse files
committed
---
yaml --- r: 4857 b: refs/heads/master c: 8fa8667 h: refs/heads/master i: 4855: 250153d v: v3
1 parent b0199fd commit 37d287d

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a3f4a1b6adf9d5e8664f0dbccc62d425d1bab7b1
2+
refs/heads/master: 8fa86672ab21a3ef437bbf3af17972091fb9e146

trunk/src/rt/rust_gc.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Rust garbage collection.
22

33
#include <algorithm>
4+
#include <iostream>
45
#include <utility>
56
#include <vector>
67
#include <stdint.h>
78

89
#include "rust_gc.h"
910
#include "rust_internal.h"
11+
#include "rust_shape.h"
1012

1113
#ifdef __WIN32__
1214
#include <windows.h>
@@ -24,13 +26,10 @@ struct frame {
2426
uint8_t *bp; // The frame pointer.
2527
void (*ra)(); // The return address.
2628

27-
frame(void *in_bp) : bp((uint8_t *)in_bp) {}
28-
29-
inline void read_ra() {
30-
ra = *(void (**)())(bp + sizeof(void *));
31-
}
29+
frame(void *in_bp, void (*in_ra)()) : bp((uint8_t *)in_bp), ra(in_ra) {}
3230

3331
inline void next() {
32+
ra = *(void (**)())(bp + sizeof(void *));
3433
bp = *(uint8_t **)bp;
3534
}
3635
};
@@ -106,11 +105,15 @@ class safe_point_map {
106105

107106
class gc {
108107
private:
108+
rust_task *task;
109+
109110
void mark(std::vector<root> &roots);
110111
void sweep();
111112

112113
public:
113-
void run(rust_task *task);
114+
gc(rust_task *in_task) : task(in_task) {}
115+
116+
void run();
114117
std::vector<frame> backtrace();
115118
};
116119

@@ -127,6 +130,14 @@ gc::mark(std::vector<root> &roots) {
127130
std::vector<root>::iterator ri = roots.begin(), rend = roots.end();
128131
while (ri < rend) {
129132
DPRINT("root: %p\n", ri->data);
133+
134+
shape::arena arena;
135+
shape::type_param *params = shape::type_param::make(ri->tydesc,
136+
arena);
137+
shape::log log(task, ri->tydesc->shape, params,
138+
ri->tydesc->shape_tables, ri->data, std::cerr);
139+
log.walk(true);
140+
130141
++ri;
131142
}
132143
// TODO
@@ -140,17 +151,21 @@ gc::sweep() {
140151
std::vector<frame>
141152
gc::backtrace() {
142153
std::vector<frame> frames;
143-
frame f(__builtin_frame_address(0));
154+
155+
// Ideally we would use the current value of EIP here, but there's no
156+
// portable way to get that and there are never any GC roots in our C++
157+
// frames anyhow.
158+
frame f(__builtin_frame_address(0), (void (*)())NULL);
159+
144160
while (f.ra != END_OF_STACK_RA) {
145-
f.read_ra();
146161
frames.push_back(f);
147162
f.next();
148163
}
149164
return frames;
150165
}
151166

152167
void
153-
gc::run(rust_task *task) {
168+
gc::run() {
154169
safe_point_map map;
155170

156171
// Find roots.
@@ -187,8 +202,8 @@ maybe_gc(rust_task *task) {
187202
}
188203

189204
if (zeal) {
190-
gc gc;
191-
gc.run(task);
205+
gc gc(task);
206+
gc.run();
192207
}
193208
}
194209

0 commit comments

Comments
 (0)