-
Notifications
You must be signed in to change notification settings - Fork 608
/
gc.hpp
144 lines (111 loc) · 3.02 KB
/
gc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef RBX_VM_GC_HPP
#define RBX_VM_GC_HPP
#include <list>
#include "oop.hpp"
#include "builtin/object.hpp"
namespace rubinius {
class ObjectMemory;
struct CallFrame;
class VariableScope;
class GlobalCache;
class StackVariables;
class ManagedThread;
namespace capi {
class Handles;
}
typedef std::vector<Object*> ObjectArray;
class ObjectVisitor {
public:
virtual ~ObjectVisitor() { }
virtual Object* call(Object*) = 0;
};
class GCData {
Roots& roots_;
CallFrameLocationList& call_frames_;
VariableRootBuffers& variable_buffers_;
RootBuffers* root_buffers_;
capi::Handles* handles_;
capi::Handles* cached_handles_;
GlobalCache* global_cache_;
std::list<ManagedThread*>* threads_;
std::list<capi::Handle**>* global_handle_locations_;
public:
GCData(STATE);
GCData(Roots& r, CallFrameLocationList& l, VariableRootBuffers& b,
capi::Handles* handles = NULL, capi::Handles* cached_handles = NULL,
GlobalCache *cache = NULL, std::list<ManagedThread*>* ths = NULL,
std::list<capi::Handle**>* global_handle_locations = NULL,
RootBuffers* rf = NULL)
: roots_(r)
, call_frames_(l)
, variable_buffers_(b)
, root_buffers_(rf)
, handles_(handles)
, cached_handles_(cached_handles)
, global_cache_(cache)
, threads_(ths)
, global_handle_locations_(global_handle_locations)
{}
Roots& roots() {
return roots_;
}
CallFrameLocationList& call_frames() {
return call_frames_;
}
std::list<ManagedThread*>* threads() {
return threads_;
}
VariableRootBuffers& variable_buffers() {
return variable_buffers_;
}
RootBuffers* root_buffers() {
return root_buffers_;
}
capi::Handles* handles() {
return handles_;
}
capi::Handles* cached_handles() {
return cached_handles_;
}
GlobalCache* global_cache() {
return global_cache_;
}
std::list<capi::Handle**>* global_handle_locations() {
return global_handle_locations_;
}
};
class GarbageCollector {
protected:
ObjectMemory* object_memory_;
private:
ObjectArray* weak_refs_;
public:
GarbageCollector(ObjectMemory *om);
virtual ~GarbageCollector() {
if(weak_refs_) delete weak_refs_;
}
virtual Object* saw_object(Object*) = 0;
void scan_object(Object* obj);
void delete_object(Object* obj);
void walk_call_frame(CallFrame* top_call_frame);
void saw_variable_scope(CallFrame* call_frame, StackVariables* scope);
Object* mark_object(Object* obj) {
if(!obj || !obj->reference_p()) return obj;
Object* tmp = saw_object(obj);
if(tmp) return tmp;
return obj;
}
void clean_weakrefs(bool check_forwards=false);
VM* state();
void add_weak_ref(Object* obj) {
if(!weak_refs_) {
weak_refs_ = new ObjectArray;
}
weak_refs_->push_back(obj);
}
void reset_stats() {
}
friend class ObjectMark;
};
}
#endif