Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 533 lines (420 sloc) 13.594 kb
d769c94 Initial work on new C++ VM
Evan Phoenix authored
1 #include "vm.hpp"
2 #include "objectmemory.hpp"
9eb4748 Flesh out Task considerable more
Evan Phoenix authored
3 #include "global_cache.hpp"
baf87dc GC performance tweeks
Evan Phoenix authored
4 #include "gc/gc.hpp"
3a0e9a4 Eero Saynatkari Renamed vm/object.hpp to vm/object_utils.hpp. File/#include shuffling.
rue authored
5
6 #include "vm/object_utils.hpp"
7
6ac48bd Fixed a LOT of dependencies by stripping objects.hpp and prelude.hpp as ...
Ryan Davis authored
8 #include "builtin/class.hpp"
9 #include "builtin/fixnum.hpp"
10 #include "builtin/list.hpp"
255a070 Brian Shirai Re-enabled instrumenting profiler.
brixen authored
11 #include "builtin/lookuptable.hpp"
6ac48bd Fixed a LOT of dependencies by stripping objects.hpp and prelude.hpp as ...
Ryan Davis authored
12 #include "builtin/symbol.hpp"
13 #include "builtin/thread.hpp"
14 #include "builtin/tuple.hpp"
15 #include "builtin/string.hpp"
58f050c Brian Shirai Ensure probe variables are initialized.
brixen authored
16 #include "builtin/taskprobe.hpp"
5d3b39f Populate a StackError with a backtrace
Evan Phoenix authored
17 #include "builtin/system.hpp"
a227ba1 Add experimental Fiber support
Evan Phoenix authored
18 #include "builtin/fiber.hpp"
6035068 Rewire debugger infrastructure, add new simple debugger.
Evan Phoenix authored
19 #include "builtin/location.hpp"
d769c94 Initial work on new C++ VM
Evan Phoenix authored
20
255a070 Brian Shirai Re-enabled instrumenting profiler.
brixen authored
21 #include "instruments/profiler.hpp"
22
b09a24c Wire the JIT in via MachineMethod
Evan Phoenix authored
23 #include "config_parser.hpp"
6c31ab6 Add cli switch to enable jit
Evan Phoenix authored
24 #include "config.h"
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
25
26 #include "native_thread.hpp"
3d7bc75 Fix reraising off non-Exception raise values
Evan Phoenix authored
27 #include "call_frame.hpp"
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
28 #include "signal.hpp"
bf09647 Add ability to turn on GIL debugging at runtime
Evan Phoenix authored
29 #include "configuration.hpp"
33892db Add step to the debugger; begin unification of interrupt checking
Evan Phoenix authored
30 #include "helpers.hpp"
8dc150e Implement ConfigParser, wire in into RUBY_CONFIG.
Evan Phoenix authored
31
a227ba1 Add experimental Fiber support
Evan Phoenix authored
32 #include "util/thread.hpp"
33
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
34 #include <iostream>
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
35 #include <iomanip>
f9ec582 Add preemptive thread scheduling
Evan Phoenix authored
36 #include <signal.h>
3d3c195 Dirkjan Bussink Small build fixes for FreeBSD
dbussink authored
37 #include <sys/resource.h>
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
38
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
39 // Reset macros since we're inside state
40 #undef G
41 #undef GO
d6416f8 Remove Globals& from VM
Evan Phoenix authored
42 #define G(whatever) globals().whatever.get()
43 #define GO(whatever) globals().whatever
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
44
d769c94 Initial work on new C++ VM
Evan Phoenix authored
45 namespace rubinius {
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
46
bf09647 Add ability to turn on GIL debugging at runtime
Evan Phoenix authored
47 bool GlobalLock::debug_locking = false;
149a517 Handle very large values from getrlimit properly
Evan Phoenix authored
48 unsigned long VM::cStackDepthMax = 655300;
49
50 // getrlimit can report there is 4G of stack (ie, unlimited).
51 // Even when there is unlimited stack, we clamp the max to
52 // this value (currently 128M)
53 static rlim_t cMaxStack = (1024 * 1024 * 128);
38100a0 Add simple recursion protection
Evan Phoenix authored
54
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
55 VM::VM(SharedState& shared)
d087929 Revamp agent API, add a number of variables
Evan Phoenix authored
56 : ManagedThread(shared, ManagedThread::eRuby)
945145d Big memory usage cleanup
Evan Phoenix authored
57 , saved_call_frame_(0)
4318087 Improve how the stack depth is checked
Evan Phoenix authored
58 , stack_start_(0)
51cb55a Brian Shirai Fixed profiler.
brixen authored
59 , profiler_(0)
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
60 , run_signals_(false)
7fc5dcb Use VM::check_interrupts, make sure thread_step_ is initialized
Evan Phoenix authored
61 , thread_step_(false)
1df37d9 Improve write barrier performance
Evan Phoenix authored
62
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
63 , shared(shared)
0d55903 Brian Shirai Initialize waiter_ in VM constructor.
brixen authored
64 , waiter_(NULL)
e4c92f8 Rework how signals are delivered. Fixes #356
Evan Phoenix authored
65 , interrupt_with_signal_(false)
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
66 , om(shared.om)
67 , interrupts(shared.interrupts)
07fc27b Hook up signal delivery
Evan Phoenix authored
68 , check_local_interrupts(false)
12aeac9 Fix return-in-ensure, a stack problem, and more
Evan Phoenix authored
69 , thread_state_(this)
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
70 , thread(this, (Thread*)Qnil)
a227ba1 Add experimental Fiber support
Evan Phoenix authored
71 , current_fiber(this, (Fiber*)Qnil)
77d214c Jake Douglas Implement Fiber#transfer and other fiber cleanup
jakedouglas authored
72 , root_fiber(this, (Fiber*)Qnil)
a5aa8c4 Initialize probe correctly so threads work
Evan Phoenix authored
73 {
d6416f8 Remove Globals& from VM
Evan Phoenix authored
74 probe.set(Qnil, &globals().roots);
4318087 Improve how the stack depth is checked
Evan Phoenix authored
75 set_stack_size(cStackDepthMax);
ad006cb Fix ugly signal bug related to pipe fds.
Evan Phoenix authored
76 os_thread_ = pthread_self(); // initial value
1df37d9 Improve write barrier performance
Evan Phoenix authored
77
78 if(shared.om) {
79 young_start_ = shared.om->young_start();
80 young_end_ = shared.om->yound_end();
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
81 shared.om->refill_slab(local_slab_);
1df37d9 Improve write barrier performance
Evan Phoenix authored
82 }
a5aa8c4 Initialize probe correctly so threads work
Evan Phoenix authored
83 }
84
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
85 void VM::discard(VM* vm) {
86 vm->saved_call_frame_ = 0;
87 if(vm->profiler_) {
88 vm->shared.remove_profiler(vm, vm->profiler_);
255a070 Brian Shirai Re-enabled instrumenting profiler.
brixen authored
89 }
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
90
91 vm->shared.remove_vm(vm);
92 delete vm;
17b1959 Add deletion of unused VMs
Evan Phoenix authored
93 }
94
37dc489 Add real Configuration infrastructure
Evan Phoenix authored
95 void VM::initialize() {
1615ead Refactoring of ObjectMemory's object creation
Evan Phoenix authored
96 VM::register_state(this);
97
37dc489 Add real Configuration infrastructure
Evan Phoenix authored
98 om = new ObjectMemory(this, shared.config);
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
99 shared.om = om;
100
1df37d9 Improve write barrier performance
Evan Phoenix authored
101 young_start_ = shared.om->young_start();
102 young_end_ = shared.om->yound_end();
103
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
104 om->refill_slab(local_slab_);
105
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
106 shared.set_initialized();
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
107
108 // This seems like we should do this in VM(), ie, for every VM and
109 // therefore every Thread object in the process. But in fact, because
110 // we're using the GIL atm, we only do it once. When the GIL goes
111 // away, this needs to be moved to VM().
112
113 shared.gc_dependent();
6c31ab6 Add cli switch to enable jit
Evan Phoenix authored
114 }
115
116 void VM::boot() {
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
117 TypeInfo::auto_learn_fields(this);
5be79de Implement simple context cache
Evan Phoenix authored
118
d769c94 Initial work on new C++ VM
Evan Phoenix authored
119 bootstrap_ontology();
da8639a Added libev integration. 60% coverage.
Evan Phoenix authored
120
31ad5c2 Introduces the dynamic interpreter
Evan Phoenix authored
121 VMMethod::init(this);
122
9205eab Lazily start the timer thread. Fixes #199.
Evan Phoenix authored
123 // Setup the main Thread, which is a reflect of the pthread_self()
124 // when the VM boots.
49d27d7 Move LLVM's lazy code generation into the execute pipeline
Evan Phoenix authored
125 boot_threads();
f9ec582 Add preemptive thread scheduling
Evan Phoenix authored
126
bf09647 Add ability to turn on GIL debugging at runtime
Evan Phoenix authored
127 GlobalLock::debug_locking = shared.config.gil_debug;
d769c94 Initial work on new C++ VM
Evan Phoenix authored
128 }
129
2ad580f Cleanup some jit config options
Evan Phoenix authored
130 void VM::initialize_config() {
131 #ifdef USE_DYNAMIC_INTERPRETER
132 if(shared.config.dynamic_interpreter_enabled) {
133 G(rubinius)->set_const(this, "INTERPRETER", symbol("dynamic"));
134 } else {
135 G(rubinius)->set_const(this, "INTERPRETER", symbol("static"));
136 }
137 #else
138 G(rubinius)->set_const(this, "INTERPRETER", symbol("static"));
139 #endif
140
141 #ifdef ENABLE_LLVM
142 if(!shared.config.jit_disabled) {
143 Array* ary = Array::create(this, 3);
144 ary->append(this, symbol("usage"));
145 if(shared.config.jit_inline_generic) {
146 ary->append(this, symbol("inline_generic"));
147 }
148
149 if(shared.config.jit_inline_blocks) {
150 ary->append(this, symbol("inline_blocks"));
151 }
152 G(rubinius)->set_const(this, "JIT", ary);
153 } else {
154 G(rubinius)->set_const(this, "JIT", Qfalse);
155 }
156 #else
157 G(rubinius)->set_const(this, "JIT", Qnil);
158 #endif
159 }
160
bc4b80f Remove STATE argument from debug functions
Evan Phoenix authored
161 // HACK so not thread safe or anything!
162 static VM* __state = NULL;
163
164 VM* VM::current_state() {
165 return __state;
166 }
167
168 void VM::register_state(VM *vm) {
169 __state = vm;
170 }
171
a227ba1 Add experimental Fiber support
Evan Phoenix authored
172 thread::ThreadData<VM*> _current_vm;
173
174 VM* VM::current() {
175 return _current_vm.get();
176 }
177
178 void VM::set_current(VM* vm) {
ad006cb Fix ugly signal bug related to pipe fds.
Evan Phoenix authored
179 vm->os_thread_ = pthread_self();
a227ba1 Add experimental Fiber support
Evan Phoenix authored
180 _current_vm.set(vm);
181 }
182
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
183 void VM::boot_threads() {
d6416f8 Remove Globals& from VM
Evan Phoenix authored
184 thread.set(Thread::create(this, this, pthread_self()), &globals().roots);
2cc2e45 Eero Saynatkari Update/fix Thread handling in VM. Possibly over-cautious again.
rue authored
185 thread->sleep(this, Qfalse);
a227ba1 Add experimental Fiber support
Evan Phoenix authored
186
187 VM::set_current(this);
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
188 }
189
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
190 Object* VM::new_object_typed(Class* cls, size_t size, object_type type) {
191 Object* obj = reinterpret_cast<Object*>(local_slab().allocate(size));
192
193 if(unlikely(!obj)) {
194 if(shared.om->refill_slab(local_slab())) {
195 obj = reinterpret_cast<Object*>(local_slab().allocate(size));
196 }
197
198 // If refill_slab fails, obj will still be NULL.
199
200 if(!obj) {
201 return om->new_object_typed(cls, size, type);
202 }
203 }
204
205 obj->init_header(cls, YoungObjectZone, type);
206 obj->clear_fields(size);
207
208 return obj;
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
209 }
210
2fd060c Fix spurious wakeup of Condition
Evan Phoenix authored
211 Object* VM::new_object_typed_mature(Class* cls, size_t bytes, object_type type) {
212 return om->new_object_typed_mature(cls, bytes, type);
213 }
214
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
215 Object* VM::new_object_from_type(Class* cls, TypeInfo* ti) {
7cdde43 Allocate cleanup phase 1
Evan Phoenix authored
216 return new_object_typed(cls, ti->instance_size, ti->type);
15fc505 More builtin objects, and a README file
Evan Phoenix authored
217 }
218
e8107bb Remove all traces of ::fields
Evan Phoenix authored
219 Class* VM::new_basic_class(Class* sup) {
ea2b516 Allocate Class/Module/IncludedModule as enduring objects
Evan Phoenix authored
220 Class *cls = om->new_object_enduring<Class>(G(klass));
b70d0be Add ivar detection and automatic packed ivars
Evan Phoenix authored
221 cls->init(shared.inc_class_count());
3cee96d Add ability to inline ivar accessors
Evan Phoenix authored
222
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
223 if(sup->nil_p()) {
387bc2d Brian Shirai Converted to attr_accessor for C++ member variable access.
brixen authored
224 cls->instance_type(this, Fixnum::from(ObjectType));
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
225 cls->set_type_info(find_type(ObjectType));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
226 } else {
387bc2d Brian Shirai Converted to attr_accessor for C++ member variable access.
brixen authored
227 cls->instance_type(this, sup->instance_type()); // HACK test that this is always true
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
228 cls->set_type_info(sup->type_info());
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
229 }
387bc2d Brian Shirai Converted to attr_accessor for C++ member variable access.
brixen authored
230 cls->superclass(this, sup);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
231
232 return cls;
233 }
234
235 Class* VM::new_class(const char* name) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
236 return new_class(name, G(object), G(object));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
237 }
238
239 Class* VM::new_class(const char* name, Class* super_class) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
240 return new_class(name, super_class, G(object));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
241 }
242
e8107bb Remove all traces of ::fields
Evan Phoenix authored
243 Class* VM::new_class(const char* name, Class* sup, Module* under) {
244 Class* cls = new_basic_class(sup);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
245 cls->setup(this, name, under);
246
247 // HACK test that we've got the MOP setup properly
248 MetaClass::attach(this, cls, sup->metaclass(this));
249 return cls;
250 }
251
252 Class* VM::new_class_under(const char* name, Module* under) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
253 return new_class(name, G(object), under);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
254 }
255
256 Module* VM::new_module(const char* name, Module* under) {
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
257 Module *mod = new_object<Module>(G(module));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
258 mod->setup(this, name, under);
259 return mod;
260 }
261
262
1fdd151 Eero Saynatkari Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
263 Symbol* VM::symbol(const char* str) {
9b196bb Refactor code out of rubinius::VM
Evan Phoenix authored
264 return shared.symbols.lookup(this, str);
304caf3 Bunch more work.
Evan Phoenix authored
265 }
266
1fdd151 Eero Saynatkari Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
267 Symbol* VM::symbol(String* str) {
9b196bb Refactor code out of rubinius::VM
Evan Phoenix authored
268 return shared.symbols.lookup(this, str);
195ef1b Brian Shirai Isolated access to SymbolTable behind VM methods.
brixen authored
269 }
270
1fdd151 Eero Saynatkari Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
271 void type_assert(STATE, Object* obj, object_type type, const char* reason) {
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
272 if((obj->reference_p() && obj->type_id() != type)
a1704be Brian Shirai Rework exceptions in the VM.
brixen authored
273 || (type == FixnumType && !obj->fixnum_p())) {
274 Exception::type_error(state, type, obj, reason);
fceff3d NativeFunction, Selector, SendSite
Evan Phoenix authored
275 }
304caf3 Bunch more work.
Evan Phoenix authored
276 }
4c08cc4 Add object cleanup post collect and on shutdown
Evan Phoenix authored
277
5d3b39f Populate a StackError with a backtrace
Evan Phoenix authored
278 void VM::raise_stack_error(CallFrame* call_frame) {
6035068 Rewire debugger infrastructure, add new simple debugger.
Evan Phoenix authored
279 G(stack_error)->locations(this, Location::from_call_stack(this, call_frame));
38100a0 Add simple recursion protection
Evan Phoenix authored
280 thread_state()->raise_exception(G(stack_error));
281 }
282
283 void VM::init_stack_size() {
284 struct rlimit rlim;
149a517 Handle very large values from getrlimit properly
Evan Phoenix authored
285 if(getrlimit(RLIMIT_STACK, &rlim) == 0) {
286 rlim_t space = rlim.rlim_cur/5;
287
288 if(space > 1024*1024) space = 1024*1024;
289 rlim_t adjusted = (rlim.rlim_cur - space);
38100a0 Add simple recursion protection
Evan Phoenix authored
290
149a517 Handle very large values from getrlimit properly
Evan Phoenix authored
291 if(adjusted > cMaxStack) {
292 cStackDepthMax = cMaxStack;
293 } else {
294 cStackDepthMax = adjusted;
295 }
38100a0 Add simple recursion protection
Evan Phoenix authored
296 }
297 }
298
388b751 Wire up primitives to be resolved and executed.
Evan Phoenix authored
299 TypeInfo* VM::find_type(int type) {
300 return om->type_info[type];
301 }
302
f1fa512 Eric Hodel Oh yeah, C++ isn't ruby.
drbrain authored
303 Thread *VM::current_thread() {
d6416f8 Remove Globals& from VM
Evan Phoenix authored
304 return globals().current_thread.get();
da8639a Added libev integration. 60% coverage.
Evan Phoenix authored
305 }
f10f155 Pass in valgrind to find some GC bugs
Evan Phoenix authored
306
3dc347c Fix memory thrash and interrupt checks
Evan Phoenix authored
307 void VM::run_gc_soon() {
308 om->collect_young_now = true;
309 om->collect_mature_now = true;
d390938 Cleanup interrupt checking, improve JIT debugging output
Evan Phoenix authored
310 interrupts.set_perform_gc();
3dc347c Fix memory thrash and interrupt checks
Evan Phoenix authored
311 }
312
f0e8625 Remove task from execution logic, add code to run GC
Evan Phoenix authored
313 void VM::collect(CallFrame* call_frame) {
e04d3da Performance fix for seeing all top CallFrames
Evan Phoenix authored
314 this->set_call_frame(call_frame);
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
315
4477824 Add ObjectSpace.find_object, implement other OS methods
Evan Phoenix authored
316 // Don't go any further unless we're allowed to GC.
317 if(!om->can_gc()) return;
318
0c8eb66 Healthy living through better thread management
Evan Phoenix authored
319 // Stops all other threads, so we're only here by ourselves.
320 StopTheWorld guard(this);
321
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
322 GCData gc_data(this);
323
324 om->collect_young(gc_data);
325 om->collect_mature(gc_data);
a9c471d Add GC finalization support, fix IO close-on-cleanup bug
Evan Phoenix authored
326
270db0c Fix ruby finalizers finally
Evan Phoenix authored
327 om->run_finalizers(this, call_frame);
f10f155 Pass in valgrind to find some GC bugs
Evan Phoenix authored
328 }
52c078b Fleshing out Instruction tests, more type safety
Evan Phoenix authored
329
f0e8625 Remove task from execution logic, add code to run GC
Evan Phoenix authored
330 void VM::collect_maybe(CallFrame* call_frame) {
e04d3da Performance fix for seeing all top CallFrames
Evan Phoenix authored
331 this->set_call_frame(call_frame);
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
332
4477824 Add ObjectSpace.find_object, implement other OS methods
Evan Phoenix authored
333 // Don't go any further unless we're allowed to GC.
334 if(!om->can_gc()) return;
335
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
336 // Stops all other threads, so we're only here by ourselves.
337 StopTheWorld guard(this);
338
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
339 GCData gc_data(this);
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
340
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
341 uint64_t start_time = 0;
342
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
343 if(om->collect_young_now) {
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
344 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
345 start_time = get_current_time();
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
346 }
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
347
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
348 YoungCollectStats stats;
5599aa0 Brian Shirai Added pseudo profiler methods for GC runs.
brixen authored
349
350 #ifdef RBX_PROFILER
351 if(unlikely(shared.profiling())) {
352 profiler::MethodEntry method(this, profiler::kYoungGC);
353 om->collect_young(gc_data, &stats);
354 } else {
355 om->collect_young(gc_data, &stats);
356 }
357 #else
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
358 om->collect_young(gc_data, &stats);
5599aa0 Brian Shirai Added pseudo profiler methods for GC runs.
brixen authored
359 #endif
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
360
361 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
362 uint64_t fin_time = get_current_time();
363 int diff = (fin_time - start_time) / 1000000;
364
365 fprintf(stderr, "[GC %0.1f%% %d/%d %d %2dms]\n",
366 stats.percentage_used,
367 stats.promoted_objects,
368 stats.excess_objects,
369 stats.lifetime,
370 diff);
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
371 }
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
372 }
373
374 if(om->collect_mature_now) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
375 int before_kb = 0;
376
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
377 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
378 start_time = get_current_time();
379 before_kb = om->mature_bytes_allocated() / 1024;
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
380 }
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
381
5599aa0 Brian Shirai Added pseudo profiler methods for GC runs.
brixen authored
382 #ifdef RBX_PROFILER
383 if(unlikely(shared.profiling())) {
384 profiler::MethodEntry method(this, profiler::kMatureGC);
385 om->collect_mature(gc_data);
386 } else {
387 om->collect_mature(gc_data);
388 }
389 #else
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
390 om->collect_mature(gc_data);
5599aa0 Brian Shirai Added pseudo profiler methods for GC runs.
brixen authored
391 #endif
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
392
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
393 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
394 uint64_t fin_time = get_current_time();
395 int diff = (fin_time - start_time) / 1000000;
396 int kb = om->mature_bytes_allocated() / 1024;
397 fprintf(stderr, "[Full GC %dkB => %dkB %2dms]\n",
398 before_kb,
399 kb,
400 diff);
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
401 }
402
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
403 }
a9c471d Add GC finalization support, fix IO close-on-cleanup bug
Evan Phoenix authored
404
4737d1a Count finalizer time toward the mature GC
Evan Phoenix authored
405 // Count the finalizers toward running the mature gc. Not great,
406 // but better than not seeing the time at all.
407 #ifdef RBX_PROFILER
408 if(unlikely(shared.profiling())) {
409 profiler::MethodEntry method(this, profiler::kMatureGC);
270db0c Fix ruby finalizers finally
Evan Phoenix authored
410 om->run_finalizers(this, call_frame);
4737d1a Count finalizer time toward the mature GC
Evan Phoenix authored
411 } else {
270db0c Fix ruby finalizers finally
Evan Phoenix authored
412 om->run_finalizers(this, call_frame);
4737d1a Count finalizer time toward the mature GC
Evan Phoenix authored
413 }
414 #else
270db0c Fix ruby finalizers finally
Evan Phoenix authored
415 om->run_finalizers(this, call_frame);
4737d1a Count finalizer time toward the mature GC
Evan Phoenix authored
416 #endif
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
417 }
418
1fdd151 Eero Saynatkari Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
419 void VM::set_const(const char* name, Object* val) {
d6416f8 Remove Globals& from VM
Evan Phoenix authored
420 globals().object->set_const(this, (char*)name, val);
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
421 }
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
422
1fdd151 Eero Saynatkari Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
423 void VM::set_const(Module* mod, const char* name, Object* val) {
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
424 mod->set_const(this, (char*)name, val);
425 }
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
426
427 void VM::print_backtrace() {
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
428 abort();
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
429 }
430
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
431 void VM::install_waiter(Waiter& waiter) {
432 waiter_ = &waiter;
433 }
434
e4c92f8 Rework how signals are delivered. Fixes #356
Evan Phoenix authored
435 void VM::interrupt_with_signal() {
436 interrupt_with_signal_ = true;
437 }
438
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
439 bool VM::wakeup() {
ad006cb Fix ugly signal bug related to pipe fds.
Evan Phoenix authored
440 if(interrupt_with_signal_) {
441 pthread_kill(os_thread_, SIGVTALRM);
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
442 return true;
ad006cb Fix ugly signal bug related to pipe fds.
Evan Phoenix authored
443 } else {
444 // Use a local here because waiter_ can get reset to NULL by another thread
445 // We can't use a mutex here because this is called from inside a
446 // signal handler.
447 if(Waiter* w = waiter_) {
448 w->run();
449 return true;
450 }
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
451
ad006cb Fix ugly signal bug related to pipe fds.
Evan Phoenix authored
452 return false;
453 }
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
454 }
455
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
456 void VM::clear_waiter() {
e4c92f8 Rework how signals are delivered. Fixes #356
Evan Phoenix authored
457 interrupt_with_signal_ = false;
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
458 waiter_ = NULL;
459 }
460
07fc27b Hook up signal delivery
Evan Phoenix authored
461 bool VM::process_async(CallFrame* call_frame) {
462 check_local_interrupts = false;
463
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
464 if(run_signals_) {
465 shared.signal_handler()->deliver_signals(call_frame);
c17afc3 Fix up Thread
Evan Phoenix authored
466 }
467
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
468 if(thread_state_.raise_reason() != cNone) return false;
469
07fc27b Hook up signal delivery
Evan Phoenix authored
470 return true;
471 }
c17afc3 Fix up Thread
Evan Phoenix authored
472
473 void VM::register_raise(Exception* exc) {
474 thread_state_.raise_exception(exc);
475 check_local_interrupts = true;
702e649 Dirkjan Bussink Potential fix for spurious CI hangs
dbussink authored
476 get_attention();
c17afc3 Fix up Thread
Evan Phoenix authored
477 }
478
3d7bc75 Fix reraising off non-Exception raise values
Evan Phoenix authored
479 void VM::check_exception(CallFrame* call_frame) {
480 if(thread_state()->raise_reason() == cNone) {
481 std::cout << "Exception propogating, but none registered!\n";
482 call_frame->print_backtrace(this);
483 rubinius::abort();
484 }
485 }
486
33892db Add step to the debugger; begin unification of interrupt checking
Evan Phoenix authored
487 bool VM::check_interrupts(CallFrame* call_frame, void* end) {
488 // First, we might be here because someone reset the stack_limit_ so that
489 // we'd fall into here to check interrupts even if the stack is fine,
490 //
491 // So fix up the stack_limit_ if thats the case first.
492
493 // If this is true, stack_limit_ was just changed to get our attention, reset
494 // it now.
495 if(stack_limit_ == stack_start_) {
496 reset_stack_limit();
497 } else {
498 if(!check_stack(call_frame, end)) return false;
499 }
500
501 if(unlikely(check_local_interrupts)) {
502 if(!process_async(call_frame)) return false;
503 }
504
505 // If the current thread is trying to step, debugger wise, then assist!
506 if(thread_step()) {
507 clear_thread_step();
508 if(!Helpers::yield_debugger(this, call_frame, Qnil)) return false;
509 }
510
511 return true;
512 }
513
d815cbb Brian Shirai Fixed responsibilities for creating, registering, removing, deleting pro...
brixen authored
514 profiler::Profiler* VM::profiler() {
515 if(unlikely(!profiler_)) {
516 profiler_ = new profiler::Profiler(this);
517 shared.add_profiler(this, profiler_);
518 }
519
520 return profiler_;
521 }
522
523 void VM::remove_profiler() {
524 profiler_ = 0;
255a070 Brian Shirai Re-enabled instrumenting profiler.
brixen authored
525 }
a227ba1 Add experimental Fiber support
Evan Phoenix authored
526
527 void VM::set_current_fiber(Fiber* fib) {
528 set_stack_start(fib->stack());
529 set_stack_size(fib->stack_size());
530 current_fiber.set(fib);
531 }
d769c94 Initial work on new C++ VM
Evan Phoenix authored
532 };
Something went wrong with that request. Please try again.