Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 154 lines (118 sloc) 3.106 kb
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
1 #ifndef RBX_STATE_HPP
2 #define RBX_STATE_HPP
3
4 namespace rubinius {
5 class VM;
6 class ManagedThread;
7 class ThreadState;
8bf4930 @evanphx API cleanup, state->vm()->om => state->memory()
evanphx authored
8 class SharedState;
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
9
10 class State {
11 VM* vm_;
8bf4930 @evanphx API cleanup, state->vm()->om => state->memory()
evanphx authored
12 SharedState& shared_;
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
13
14 public:
15 State(VM* vm)
16 : vm_(vm)
8bf4930 @evanphx API cleanup, state->vm()->om => state->memory()
evanphx authored
17 , shared_(vm->shared)
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
18 {}
19
20 VM* vm() {
21 return vm_;
22 }
23
24 ManagedThread* thread() {
25 return (ManagedThread*)vm_;
26 }
27
778944b @evanphx State based API cleanup
evanphx authored
28 Object* raise_exception(Exception* exc) {
29 vm_->thread_state()->raise_exception(exc);
30 return 0;
31 }
32
8d2093a @dbussink Update current state object with proper VM when forking
dbussink authored
33 void set_vm(VM* vm) {
34 vm_ = vm;
35 }
36
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
37 void set_call_frame(CallFrame* cf) {
38 vm_->set_call_frame(cf);
39 }
40
41 Globals& globals() {
1956797 @evanphx API cleanup: Simplify GC interrupt checking
evanphx authored
42 return shared_.globals;
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
43 }
44
45 Symbol* symbol(const char* str) {
46 return vm_->symbol(str);
47 }
48
49 Symbol* symbol(std::string str) {
50 return vm_->symbol(str);
51 }
52
53 Symbol* symbol(String* str) {
54 return vm_->symbol(str);
55 }
56
1d69526 @dbussink Use MurmurHash 3 for String hashing
dbussink authored
57 uint32_t hash_seed() {
58 return shared_.hash_seed;
59 }
60
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
61 template <class T>
62 T* new_object(Class *cls) {
63 return reinterpret_cast<T*>(vm_->new_object_typed(cls, sizeof(T), T::type));
64 }
964a1a2 @wilson Remove shared SystemStackError object, now allocated on demand.
wilson authored
65
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
66 ThreadState* thread_state() {
67 return vm_->thread_state();
68 }
69
8bf4930 @evanphx API cleanup, state->vm()->om => state->memory()
evanphx authored
70 ObjectMemory* memory() {
71 return shared_.memory();
72 }
73
2a3dcf3 @evanphx API cleanup: state->vm()->shared => state->shared()
evanphx authored
74 SharedState& shared() {
75 return shared_;
76 }
77
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
78 bool detect_stack_condition(void* end) {
79 return vm_->detect_stack_condition(end);
80 }
81
82 bool check_async(CallFrame* call_frame) {
83 if(vm_->check_local_interrupts) {
84 return process_async(call_frame);
85 }
86 return true;
87 }
88
89 void raise_stack_error(CallFrame* call_frame);
90
91 bool check_stack(CallFrame* call_frame, void* end) {
92 // @TODO assumes stack growth direction
93 if(unlikely(reinterpret_cast<uintptr_t>(end) < vm_->stack_limit_)) {
94 raise_stack_error(call_frame);
95 return false;
96 }
97
98 return true;
99 }
100
101 bool process_async(CallFrame* call_frame);
102 void check_exception(CallFrame* call_frame);
103 bool check_interrupts(GCToken gct, CallFrame* call_frame, void* end);
104
105 gc::Slab& local_slab() {
106 return vm_->local_slab();
107 }
108
0b78034 @evanphx Fix stop_the_world deadlock bug
evanphx authored
109 bool stop_the_world() WARN_UNUSED {
110 return shared_.stop_the_world(vm_);
111 };
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
112
113 void restart_world() {
1956797 @evanphx API cleanup: Simplify GC interrupt checking
evanphx authored
114 shared_.restart_world(vm_);
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
115 }
116
a921375 @dbussink Propagate GCToken for gc_independent
dbussink authored
117 void gc_independent(GCToken gct) {
1956797 @evanphx API cleanup: Simplify GC interrupt checking
evanphx authored
118 shared_.gc_independent(vm_);
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
119 }
120
121 void gc_dependent() {
1956797 @evanphx API cleanup: Simplify GC interrupt checking
evanphx authored
122 shared_.gc_dependent(vm_);
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
123 }
124
8a07fe9 @evanphx API cleanup: move checkpointing to one method
evanphx authored
125 void checkpoint(GCToken gct, CallFrame* call_frame) {
126 vm_->set_call_frame(call_frame);
127 gc_checkpoint(gct, call_frame);
1956797 @evanphx API cleanup: Simplify GC interrupt checking
evanphx authored
128 shared_.checkpoint(vm_);
129 }
130
131 void gc_checkpoint(GCToken gct, CallFrame* frame) {
132 if(unlikely(shared_.check_gc_p())) {
133 vm_->collect_maybe(gct, frame);
134 }
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
135 }
136
a921375 @dbussink Propagate GCToken for gc_independent
dbussink authored
137 void lock(GCToken gct) {
138 gc_independent(gct);
7ed39b0 @evanphx Fix a thread not seeing a wakeup request. Fixes #1446
evanphx authored
139 vm_->lock(vm_);
5306076 @dbussink Go independent before locking to prevent deadlocking
dbussink authored
140 gc_dependent();
7ed39b0 @evanphx Fix a thread not seeing a wakeup request. Fixes #1446
evanphx authored
141 }
142
143 void unlock() {
144 vm_->unlock(vm_);
145 }
146
1f9ddd1 @ryoqun Fix timing issue of Thread#kill and sleep
ryoqun authored
147 Object* park(GCToken gct, CallFrame* call_frame);
3aa87d1 @evanphx Better way to sleep via thread parking
evanphx authored
148
1f9ddd1 @ryoqun Fix timing issue of Thread#kill and sleep
ryoqun authored
149 Object* park_timed(GCToken gct, CallFrame* call_frame, struct timespec* ts);
35a49f3 @evanphx Introduce State class as STATE
evanphx authored
150 };
151 }
152
153 #endif
Something went wrong with that request. Please try again.