Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 476 lines (371 sloc) 11.905 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 "event.hpp"
4 #include "global_cache.hpp"
baf87dc GC performance tweeks
Evan Phoenix authored
5 #include "gc/gc.hpp"
3a0e9a4 @rue Renamed vm/object.hpp to vm/object_utils.hpp. File/#include shuffling.
rue authored
6
7 #include "vm/object_utils.hpp"
8
6ac48bd Fixed a LOT of dependencies by stripping objects.hpp and prelude.hpp as ...
Ryan Davis authored
9 #include "builtin/class.hpp"
10 #include "builtin/fixnum.hpp"
11 #include "builtin/list.hpp"
255a070 @brixen Re-enabled instrumenting profiler.
brixen authored
12 #include "builtin/lookuptable.hpp"
6ac48bd Fixed a LOT of dependencies by stripping objects.hpp and prelude.hpp as ...
Ryan Davis authored
13 #include "builtin/symbol.hpp"
14 #include "builtin/thread.hpp"
15 #include "builtin/tuple.hpp"
16 #include "builtin/string.hpp"
58f050c @brixen Ensure probe variables are initialized.
brixen authored
17 #include "builtin/taskprobe.hpp"
5d3b39f Populate a StackError with a backtrace
Evan Phoenix authored
18 #include "builtin/system.hpp"
a227ba1 Add experimental Fiber support
Evan Phoenix authored
19 #include "builtin/fiber.hpp"
d769c94 Initial work on new C++ VM
Evan Phoenix authored
20
255a070 @brixen 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"
8dc150e Implement ConfigParser, wire in into RUBY_CONFIG.
Evan Phoenix authored
30
a227ba1 Add experimental Fiber support
Evan Phoenix authored
31 #include "util/thread.hpp"
32
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
33 #include <iostream>
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
34 #include <iomanip>
f9ec582 Add preemptive thread scheduling
Evan Phoenix authored
35 #include <signal.h>
3d3c195 @dbussink Small build fixes for FreeBSD
dbussink authored
36 #include <sys/resource.h>
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
37
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
38 // Reset macros since we're inside state
39 #undef G
40 #undef GO
41 #define G(whatever) globals.whatever.get()
42 #define GO(whatever) globals.whatever
43
d769c94 Initial work on new C++ VM
Evan Phoenix authored
44 namespace rubinius {
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
45
bf09647 Add ability to turn on GIL debugging at runtime
Evan Phoenix authored
46 bool GlobalLock::debug_locking = false;
38100a0 Add simple recursion protection
Evan Phoenix authored
47 int VM::cStackDepthMax = 655300;
48
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
49 VM::VM(SharedState& shared)
945145d Big memory usage cleanup
Evan Phoenix authored
50 : ManagedThread(shared)
51 , saved_call_frame_(0)
4318087 Improve how the stack depth is checked
Evan Phoenix authored
52 , stack_start_(0)
17b1959 Add deletion of unused VMs
Evan Phoenix authored
53 , alive_(true)
51cb55a @brixen Fixed profiler.
brixen authored
54 , profiler_(0)
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
55 , run_signals_(false)
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
56 , shared(shared)
0d55903 @brixen Initialize waiter_ in VM constructor.
brixen authored
57 , waiter_(NULL)
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
58 , globals(shared.globals)
59 , om(shared.om)
60 , global_cache(shared.global_cache)
61 , interrupts(shared.interrupts)
62 , symbols(shared.symbols)
07fc27b Hook up signal delivery
Evan Phoenix authored
63 , check_local_interrupts(false)
12aeac9 Fix return-in-ensure, a stack problem, and more
Evan Phoenix authored
64 , thread_state_(this)
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
65 , thread(this, (Thread*)Qnil)
a227ba1 Add experimental Fiber support
Evan Phoenix authored
66 , current_fiber(this, (Fiber*)Qnil)
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
67 , current_mark(NULL)
31ad5c2 Introduces the dynamic interpreter
Evan Phoenix authored
68 , reuse_llvm(true)
a5aa8c4 Initialize probe correctly so threads work
Evan Phoenix authored
69 {
70 probe.set(Qnil, &globals.roots);
4318087 Improve how the stack depth is checked
Evan Phoenix authored
71 set_stack_size(cStackDepthMax);
a5aa8c4 Initialize probe correctly so threads work
Evan Phoenix authored
72 }
73
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
74
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
75 void VM::discard(VM* vm) {
76 vm->alive_ = false;
77 vm->saved_call_frame_ = 0;
78 if(vm->profiler_) {
79 vm->shared.remove_profiler(vm, vm->profiler_);
255a070 @brixen Re-enabled instrumenting profiler.
brixen authored
80 }
41400f4 Remove VMManager, simply SharedState/VM workflow
Evan Phoenix authored
81
82 vm->shared.remove_vm(vm);
83 delete vm;
17b1959 Add deletion of unused VMs
Evan Phoenix authored
84 }
85
37dc489 Add real Configuration infrastructure
Evan Phoenix authored
86 void VM::initialize() {
1615ead Refactoring of ObjectMemory's object creation
Evan Phoenix authored
87 VM::register_state(this);
88
37dc489 Add real Configuration infrastructure
Evan Phoenix authored
89 om = new ObjectMemory(this, shared.config);
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
90 shared.om = om;
91
92 global_cache = new GlobalCache;
93 shared.global_cache = global_cache;
6c31ab6 Add cli switch to enable jit
Evan Phoenix authored
94
86fe9a8 @rue Some notes on Thread/VM interaction.
rue authored
95 /** @todo Done by Environment::boot_vm(), and Thread::s_new()
96 * does not boot at all. Should this be removed? --rue */
97 // this->boot();
6cfae75 Add VMManager, fix exit to behave well
Evan Phoenix authored
98
99 shared.set_initialized();
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
100
101 // This seems like we should do this in VM(), ie, for every VM and
102 // therefore every Thread object in the process. But in fact, because
103 // we're using the GIL atm, we only do it once. When the GIL goes
104 // away, this needs to be moved to VM().
105
106 shared.gc_dependent();
6c31ab6 Add cli switch to enable jit
Evan Phoenix authored
107 }
108
109 void VM::boot() {
5e917ee Move TypeInfo::init under ObjectMemory
Evan Phoenix authored
110 TypeInfo::auto_learn_fields(this);
5be79de Implement simple context cache
Evan Phoenix authored
111
d769c94 Initial work on new C++ VM
Evan Phoenix authored
112 bootstrap_ontology();
da8639a Added libev integration. 60% coverage.
Evan Phoenix authored
113
3f594b6 @rue Changed all TODO:s to @todo so that doxygen picks them up.
rue authored
114 /* @todo Using a single default loop, revisit when many loops.
115 * @todo This needs to be handled through the environment.
6767c76 @dgtized disabled EVBACKEND_EPOLL as it seems to make linux unhappy -- this shoul...
dgtized authored
116 * (disabled epoll backend as it frequently caused hangs on epoll_wait)
d75d4be @rue Add forkcheck flag to event loop and init SIGCHLD handler at VM startup.
rue authored
117 */
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
118 // signal_events = new event::Loop(EVFLAG_FORKCHECK | EVBACKEND_SELECT | EVBACKEND_POLL);
119 // events = signal_events;
432b29d Get send_on_signal working and couple simple fixes.
Evan Phoenix authored
120
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
121 // signal_events->start(new event::Child::Event(this));
122
123 events = 0;
124 signal_events = 0;
d75d4be @rue Add forkcheck flag to event loop and init SIGCHLD handler at VM startup.
rue authored
125
31ad5c2 Introduces the dynamic interpreter
Evan Phoenix authored
126 VMMethod::init(this);
127
86fe9a8 @rue Some notes on Thread/VM interaction.
rue authored
128 /** @todo Should a thread be starting a VM or is it the other way around? */
49d27d7 Move LLVM's lazy code generation into the execute pipeline
Evan Phoenix authored
129 boot_threads();
f9ec582 Add preemptive thread scheduling
Evan Phoenix authored
130
131 // Force these back to false because creating the default Thread
132 // sets them to true.
133 interrupts.enable_preempt = false;
bf09647 Add ability to turn on GIL debugging at runtime
Evan Phoenix authored
134
135 GlobalLock::debug_locking = shared.config.gil_debug;
d769c94 Initial work on new C++ VM
Evan Phoenix authored
136 }
137
2ad580f Cleanup some jit config options
Evan Phoenix authored
138 void VM::initialize_config() {
139 #ifdef USE_DYNAMIC_INTERPRETER
140 if(shared.config.dynamic_interpreter_enabled) {
141 G(rubinius)->set_const(this, "INTERPRETER", symbol("dynamic"));
142 } else {
143 G(rubinius)->set_const(this, "INTERPRETER", symbol("static"));
144 }
145 #else
146 G(rubinius)->set_const(this, "INTERPRETER", symbol("static"));
147 #endif
148
149 #ifdef ENABLE_LLVM
150 if(!shared.config.jit_disabled) {
151 Array* ary = Array::create(this, 3);
152 ary->append(this, symbol("usage"));
153 if(shared.config.jit_inline_generic) {
154 ary->append(this, symbol("inline_generic"));
155 }
156
157 if(shared.config.jit_inline_blocks) {
158 ary->append(this, symbol("inline_blocks"));
159 }
160 G(rubinius)->set_const(this, "JIT", ary);
161 } else {
162 G(rubinius)->set_const(this, "JIT", Qfalse);
163 }
164 #else
165 G(rubinius)->set_const(this, "JIT", Qnil);
166 #endif
167 }
168
bc4b80f Remove STATE argument from debug functions
Evan Phoenix authored
169 // HACK so not thread safe or anything!
170 static VM* __state = NULL;
171
172 VM* VM::current_state() {
173 return __state;
174 }
175
176 void VM::register_state(VM *vm) {
177 __state = vm;
178 }
179
a227ba1 Add experimental Fiber support
Evan Phoenix authored
180 thread::ThreadData<VM*> _current_vm;
181
182 VM* VM::current() {
183 return _current_vm.get();
184 }
185
186 void VM::set_current(VM* vm) {
187 _current_vm.set(vm);
188 }
189
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
190 void VM::boot_threads() {
d0dbabb Rework how pthread_t is passed down
Evan Phoenix authored
191 thread.set(Thread::create(this, this, pthread_self()), &globals.roots);
2cc2e45 @rue Update/fix Thread handling in VM. Possibly over-cautious again.
rue authored
192 thread->sleep(this, Qfalse);
a227ba1 Add experimental Fiber support
Evan Phoenix authored
193
194 VM::set_current(this);
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
195 }
196
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
197 Object* VM::new_object_typed(Class* cls, size_t bytes, object_type type) {
198 return om->new_object_typed(cls, bytes, type);
199 }
200
2fd060c Fix spurious wakeup of Condition
Evan Phoenix authored
201 Object* VM::new_object_typed_mature(Class* cls, size_t bytes, object_type type) {
202 return om->new_object_typed_mature(cls, bytes, type);
203 }
204
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
205 Object* VM::new_object_from_type(Class* cls, TypeInfo* ti) {
206 return om->new_object_typed(cls, ti->instance_size, ti->type);
15fc505 More builtin objects, and a README file
Evan Phoenix authored
207 }
208
e8107bb Remove all traces of ::fields
Evan Phoenix authored
209 Class* VM::new_basic_class(Class* sup) {
ea2b516 Allocate Class/Module/IncludedModule as enduring objects
Evan Phoenix authored
210 Class *cls = om->new_object_enduring<Class>(G(klass));
3cee96d Add ability to inline ivar accessors
Evan Phoenix authored
211 cls->set_class_id(shared.inc_class_count());
0be116a Add prelim support for packed object layout
Evan Phoenix authored
212 cls->set_packed_size(0);
3cee96d Add ability to inline ivar accessors
Evan Phoenix authored
213
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
214 if(sup->nil_p()) {
387bc2d @brixen Converted to attr_accessor for C++ member variable access.
brixen authored
215 cls->instance_type(this, Fixnum::from(ObjectType));
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
216 cls->set_type_info(find_type(ObjectType));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
217 } else {
387bc2d @brixen Converted to attr_accessor for C++ member variable access.
brixen authored
218 cls->instance_type(this, sup->instance_type()); // HACK test that this is always true
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
219 cls->set_type_info(sup->type_info());
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
220 }
387bc2d @brixen Converted to attr_accessor for C++ member variable access.
brixen authored
221 cls->superclass(this, sup);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
222
223 return cls;
224 }
225
226 Class* VM::new_class(const char* name) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
227 return new_class(name, G(object), G(object));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
228 }
229
230 Class* VM::new_class(const char* name, Class* super_class) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
231 return new_class(name, super_class, G(object));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
232 }
233
e8107bb Remove all traces of ::fields
Evan Phoenix authored
234 Class* VM::new_class(const char* name, Class* sup, Module* under) {
235 Class* cls = new_basic_class(sup);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
236 cls->setup(this, name, under);
237
238 // HACK test that we've got the MOP setup properly
239 MetaClass::attach(this, cls, sup->metaclass(this));
240 return cls;
241 }
242
243 Class* VM::new_class_under(const char* name, Module* under) {
e8107bb Remove all traces of ::fields
Evan Phoenix authored
244 return new_class(name, G(object), under);
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
245 }
246
247 Module* VM::new_module(const char* name, Module* under) {
78632ae Remove using Type::fields infavor of sizeof(Type)
Evan Phoenix authored
248 Module *mod = new_object<Module>(G(module));
f5cf833 Reorganize ontology and class initialization
Evan Phoenix authored
249 mod->setup(this, name, under);
250 return mod;
251 }
252
253
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
254 Symbol* VM::symbol(const char* str) {
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
255 return symbols.lookup(this, str);
304caf3 Bunch more work.
Evan Phoenix authored
256 }
257
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
258 Symbol* VM::symbol(String* str) {
5f2adf4 @brixen Replaced SymbolTable with native C++ class using STL.
brixen authored
259 return symbols.lookup(this, str);
195ef1b @brixen Isolated access to SymbolTable behind VM methods.
brixen authored
260 }
261
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
262 void type_assert(STATE, Object* obj, object_type type, const char* reason) {
481c5e5 Class / TypeInfo cleanup
Evan Phoenix authored
263 if((obj->reference_p() && obj->type_id() != type)
a1704be @brixen Rework exceptions in the VM.
brixen authored
264 || (type == FixnumType && !obj->fixnum_p())) {
265 Exception::type_error(state, type, obj, reason);
fceff3d NativeFunction, Selector, SendSite
Evan Phoenix authored
266 }
304caf3 Bunch more work.
Evan Phoenix authored
267 }
4c08cc4 Add object cleanup post collect and on shutdown
Evan Phoenix authored
268
5d3b39f Populate a StackError with a backtrace
Evan Phoenix authored
269 void VM::raise_stack_error(CallFrame* call_frame) {
270 G(stack_error)->locations(this, System::vm_backtrace(this, Fixnum::from(0), call_frame));
38100a0 Add simple recursion protection
Evan Phoenix authored
271 thread_state()->raise_exception(G(stack_error));
272 }
273
274 void VM::init_stack_size() {
275 struct rlimit rlim;
276 if (getrlimit(RLIMIT_STACK, &rlim) == 0) {
277 unsigned int space = rlim.rlim_cur/5;
278
279 if (space > 1024*1024) space = 1024*1024;
280 cStackDepthMax = (rlim.rlim_cur - space);
281 }
282 }
283
388b751 Wire up primitives to be resolved and executed.
Evan Phoenix authored
284 TypeInfo* VM::find_type(int type) {
285 return om->type_info[type];
286 }
287
f1fa512 @drbrain Oh yeah, C++ isn't ruby.
drbrain authored
288 Thread *VM::current_thread() {
6f546f0 @drbrain Implement VM::current_thread().
drbrain authored
289 return globals.current_thread.get();
da8639a Added libev integration. 60% coverage.
Evan Phoenix authored
290 }
f10f155 Pass in valgrind to find some GC bugs
Evan Phoenix authored
291
3dc347c Fix memory thrash and interrupt checks
Evan Phoenix authored
292 void VM::run_gc_soon() {
293 om->collect_young_now = true;
294 om->collect_mature_now = true;
d390938 Cleanup interrupt checking, improve JIT debugging output
Evan Phoenix authored
295 interrupts.set_perform_gc();
3dc347c Fix memory thrash and interrupt checks
Evan Phoenix authored
296 }
297
f0e8625 Remove task from execution logic, add code to run GC
Evan Phoenix authored
298 void VM::collect(CallFrame* call_frame) {
e04d3da Performance fix for seeing all top CallFrames
Evan Phoenix authored
299 this->set_call_frame(call_frame);
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
300
4477824 Add ObjectSpace.find_object, implement other OS methods
Evan Phoenix authored
301 // Don't go any further unless we're allowed to GC.
302 if(!om->can_gc()) return;
303
0c8eb66 Healthy living through better thread management
Evan Phoenix authored
304 // Stops all other threads, so we're only here by ourselves.
305 StopTheWorld guard(this);
306
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
307 GCData gc_data(this);
308
309 om->collect_young(gc_data);
310 om->collect_mature(gc_data);
a9c471d Add GC finalization support, fix IO close-on-cleanup bug
Evan Phoenix authored
311
312 om->run_finalizers(this);
f10f155 Pass in valgrind to find some GC bugs
Evan Phoenix authored
313 }
52c078b Fleshing out Instruction tests, more type safety
Evan Phoenix authored
314
f0e8625 Remove task from execution logic, add code to run GC
Evan Phoenix authored
315 void VM::collect_maybe(CallFrame* call_frame) {
e04d3da Performance fix for seeing all top CallFrames
Evan Phoenix authored
316 this->set_call_frame(call_frame);
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
317
4477824 Add ObjectSpace.find_object, implement other OS methods
Evan Phoenix authored
318 // Don't go any further unless we're allowed to GC.
319 if(!om->can_gc()) return;
320
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
321 // Stops all other threads, so we're only here by ourselves.
322 StopTheWorld guard(this);
323
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
324 GCData gc_data(this);
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
325
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
326 uint64_t start_time = 0;
327
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
328 if(om->collect_young_now) {
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
329 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
330 start_time = get_current_time();
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
331 }
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
332
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
333 YoungCollectStats stats;
5599aa0 @brixen Added pseudo profiler methods for GC runs.
brixen authored
334
335 #ifdef RBX_PROFILER
336 if(unlikely(shared.profiling())) {
337 profiler::MethodEntry method(this, profiler::kYoungGC);
338 om->collect_young(gc_data, &stats);
339 } else {
340 om->collect_young(gc_data, &stats);
341 }
342 #else
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
343 om->collect_young(gc_data, &stats);
5599aa0 @brixen Added pseudo profiler methods for GC runs.
brixen authored
344 #endif
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
345
346 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
347 uint64_t fin_time = get_current_time();
348 int diff = (fin_time - start_time) / 1000000;
349
350 fprintf(stderr, "[GC %0.1f%% %d/%d %d %2dms]\n",
351 stats.percentage_used,
352 stats.promoted_objects,
353 stats.excess_objects,
354 stats.lifetime,
355 diff);
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
356 }
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
357 }
358
359 if(om->collect_mature_now) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
360 int before_kb = 0;
361
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
362 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
363 start_time = get_current_time();
364 before_kb = om->mature_bytes_allocated() / 1024;
720b6a4 Add -Xgc.show to print out when the GC runs
Evan Phoenix authored
365 }
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
366
5599aa0 @brixen Added pseudo profiler methods for GC runs.
brixen authored
367 #ifdef RBX_PROFILER
368 if(unlikely(shared.profiling())) {
369 profiler::MethodEntry method(this, profiler::kMatureGC);
370 om->collect_mature(gc_data);
371 } else {
372 om->collect_mature(gc_data);
373 }
374 #else
1431083 Add OnStack class to protect C++ variables from GC
Evan Phoenix authored
375 om->collect_mature(gc_data);
5599aa0 @brixen Added pseudo profiler methods for GC runs.
brixen authored
376 #endif
ef185e2 Refactor timing code and add GC timing
Evan Phoenix authored
377
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
378 if(shared.config.gc_show) {
4e26843 Improve young GC and add more GC stats
Evan Phoenix authored
379 uint64_t fin_time = get_current_time();
380 int diff = (fin_time - start_time) / 1000000;
381 int kb = om->mature_bytes_allocated() / 1024;
382 fprintf(stderr, "[Full GC %dkB => %dkB %2dms]\n",
383 before_kb,
384 kb,
385 diff);
651bdc0 Show GC stops as well with -Xgc.show
Evan Phoenix authored
386 }
387
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
388 }
a9c471d Add GC finalization support, fix IO close-on-cleanup bug
Evan Phoenix authored
389
390 om->run_finalizers(this);
f781b6a Move GC running into VM, remove Task::check_interrupts
Evan Phoenix authored
391 }
392
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
393 void VM::set_const(const char* name, Object* val) {
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
394 globals.object->set_const(this, (char*)name, val);
395 }
879a046 A whole slew. Enhanced type-info, debugged GC.
Evan Phoenix authored
396
1fdd151 @rue Changed all OBJECT, SYMBOL, FIXNUM, INTEGER to normal syntax.
rue authored
397 void VM::set_const(Module* mod, const char* name, Object* val) {
feb91b4 Tons of stuff (too much probably)
Evan Phoenix authored
398 mod->set_const(this, (char*)name, val);
399 }
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
400
401 void VM::print_backtrace() {
bb9618c Fix wait, Channels, and GC for multiple threads
Evan Phoenix authored
402 abort();
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
403 }
404
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
405 void VM::install_waiter(Waiter& waiter) {
406 waiter_ = &waiter;
407 }
408
409 bool VM::wakeup() {
410 if(waiter_) {
e53284c Wire background compiling thread into JIT mode
Evan Phoenix authored
411 waiter_->run();
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
412 waiter_ = NULL;
1dd0497 Hooked a bit of Threads back up
Evan Phoenix authored
413 return true;
414 }
415
416 return false;
417 }
418
b4cfdcb Fix subtend, irb runs
Evan Phoenix authored
419 void VM::clear_waiter() {
420 waiter_ = NULL;
421 }
422
07fc27b Hook up signal delivery
Evan Phoenix authored
423 void VM::send_async_signal(int sig) {
424 mailbox_.add(ASyncMessage(ASyncMessage::cSignal, sig));
425 check_local_interrupts = true;
426
427 // TODO I'm worried there might be a race calling
428 // wakeup without the lock held...
429 wakeup();
430 }
431
432 bool VM::process_async(CallFrame* call_frame) {
433 check_local_interrupts = false;
434
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
435 if(run_signals_) {
436 shared.signal_handler()->deliver_signals(call_frame);
c17afc3 Fix up Thread
Evan Phoenix authored
437 }
438
e6bb96a Fix a number of IO/Signal interaction issues
Evan Phoenix authored
439 if(thread_state_.raise_reason() != cNone) return false;
440
07fc27b Hook up signal delivery
Evan Phoenix authored
441 return true;
442 }
c17afc3 Fix up Thread
Evan Phoenix authored
443
444 void VM::register_raise(Exception* exc) {
445 thread_state_.raise_exception(exc);
446 check_local_interrupts = true;
447 }
448
3d7bc75 Fix reraising off non-Exception raise values
Evan Phoenix authored
449 void VM::check_exception(CallFrame* call_frame) {
450 if(thread_state()->raise_reason() == cNone) {
451 std::cout << "Exception propogating, but none registered!\n";
452 call_frame->print_backtrace(this);
453 rubinius::abort();
454 }
455 }
456
d815cbb @brixen Fixed responsibilities for creating, registering, removing, deleting pro...
brixen authored
457 profiler::Profiler* VM::profiler() {
458 if(unlikely(!profiler_)) {
459 profiler_ = new profiler::Profiler(this);
460 shared.add_profiler(this, profiler_);
461 }
462
463 return profiler_;
464 }
465
466 void VM::remove_profiler() {
467 profiler_ = 0;
255a070 @brixen Re-enabled instrumenting profiler.
brixen authored
468 }
a227ba1 Add experimental Fiber support
Evan Phoenix authored
469
470 void VM::set_current_fiber(Fiber* fib) {
471 set_stack_start(fib->stack());
472 set_stack_size(fib->stack_size());
473 current_fiber.set(fib);
474 }
d769c94 Initial work on new C++ VM
Evan Phoenix authored
475 };
Something went wrong with that request. Please try again.