/
state.hpp
267 lines (199 loc) · 5.29 KB
/
state.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#ifndef VM_LLVM_STATE_HPP
#define VM_LLVM_STATE_HPP
#include <stdint.h>
#include <unistd.h>
#include "vm/config.h"
#include <llvm/Module.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Function.h>
#include <llvm/Module.h>
#include <llvm/Instructions.h>
#if RBX_LLVM_API_VER >= 302
#include <llvm/IRBuilder.h>
#else
#include <llvm/Support/IRBuilder.h>
#endif
#include <llvm/ExecutionEngine/JIT.h>
#include <llvm/CodeGen/MachineCodeInfo.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Pass.h>
#include <llvm/PassManager.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/LLVMContext.h>
#include "llvm/local_info.hpp"
#include "gc/managed.hpp"
#include "gc/write_barrier.hpp"
#include "auxiliary_threads.hpp"
#include "configuration.hpp"
#include "util/thread.hpp"
namespace rubinius {
typedef std::map<int, LocalInfo> LocalMap;
class SymbolTable;
class CompiledCode;
class GarbageCollector;
namespace jit {
class Builder;
class RubiniusJITMemoryManager;
}
class BackgroundCompilerThread;
class BlockEnvironment;
class Context;
enum JitDebug {
cSimple = 1,
cOptimized = 2,
cMachineCode = 4
};
class LLVMState : public AuxiliaryThread, public ManagedThread {
jit::RubiniusJITMemoryManager* memory_;
Configuration& config_;
BackgroundCompilerThread* background_thread_;
SymbolTable& symbols_;
int jitted_methods_;
int queued_methods_;
int accessors_inlined_;
int uncommons_taken_;
SharedState& shared_;
bool include_profiling_;
int code_bytes_;
std::ostream* log_;
gc::WriteBarrier write_barrier_;
int fixnum_class_id_;
int integer_class_id_;
int numeric_class_id_;
int symbol_class_id_;
int string_class_id_;
int regexp_class_id_;
int encoding_class_id_;
int module_class_id_;
int class_class_id_;
int nil_class_id_;
int true_class_id_;
int false_class_id_;
bool type_optz_;
utilities::thread::SpinLock method_update_lock_;
utilities::thread::Mutex wait_mutex;
utilities::thread::Condition wait_cond;
public:
uint64_t time_spent;
static LLVMState* get(STATE);
static LLVMState* get_if_set(STATE);
static LLVMState* get_if_set(VM*);
static void start(STATE);
static void on_fork(STATE);
static void pause(STATE);
static void unpause(STATE);
LLVMState(STATE);
virtual ~LLVMState();
void add_internal_functions();
int jit_dump_code() {
return config_.jit_dump_code;
}
bool debug_p();
Configuration& config() {
return config_;
}
bool include_profiling() {
return include_profiling_;
}
jit::RubiniusJITMemoryManager* memory() { return memory_; }
int jitted_methods() {
return jitted_methods_;
}
int queued_methods() {
return queued_methods_;
}
int add_jitted_method() {
return ++jitted_methods_;
}
int code_bytes() {
return code_bytes_;
}
void add_code_bytes(int bytes) {
code_bytes_ += bytes;
}
void add_accessor_inlined() {
accessors_inlined_++;
}
int accessors_inlined() {
return accessors_inlined_;
}
void add_uncommons_taken() {
uncommons_taken_++;
}
int uncommons_taken() {
return uncommons_taken_;
}
SharedState& shared() { return shared_; }
std::ostream& log() {
return *log_;
}
gc::WriteBarrier* write_barrier() {
return &write_barrier_;
}
int fixnum_class_id() {
return fixnum_class_id_;
}
int integer_class_id() {
return integer_class_id_;
}
int numeric_class_id() {
return numeric_class_id_;
}
int symbol_class_id() {
return symbol_class_id_;
}
int string_class_id() {
return string_class_id_;
}
int regexp_class_id() {
return regexp_class_id_;
}
int encoding_class_id() {
return encoding_class_id_;
}
int module_class_id() {
return module_class_id_;
}
int class_class_id() {
return class_class_id_;
}
int nil_class_id() {
return nil_class_id_;
}
int true_class_id() {
return true_class_id_;
}
int false_class_id() {
return false_class_id_;
}
bool type_optz() {
return type_optz_;
}
void start_method_update() {
method_update_lock_.lock();
}
void end_method_update() {
method_update_lock_.unlock();
}
void gc_dependent();
void gc_independent();
void compile_soon(STATE, GCToken gct, CompiledCode* code, CallFrame* call_frame,
Object* extra, bool is_block=false);
void remove(void* func);
CallFrame* find_candidate(STATE, CompiledCode* start, CallFrame* call_frame);
void compile_callframe(STATE, GCToken gct, CompiledCode* start, CallFrame* call_frame,
int primitive = -1);
Symbol* symbol(const std::string& sym);
std::string symbol_debug_str(const Symbol* sym);
std::string enclosure_name(CompiledCode* code);
void shutdown(STATE);
void before_exec(STATE);
void after_exec(STATE);
void before_fork(STATE);
void after_fork_parent(STATE);
void after_fork_child(STATE);
void gc_scan(GarbageCollector* gc);
static void show_machine_code(void* impl, size_t bytes);
};
}
#endif