Skip to content

Commit cb6f950

Browse files
committedJun 10, 2016
Merge remote-tracking branch 'origin' into codedb-ffi-io
2 parents e200552 + 08547ed commit cb6f950

25 files changed

+473
-304
lines changed
 

Diff for: ‎library/rubinius/configuration.rb

+31
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,33 @@
6565

6666
f.vm_variable "stack_size", 512 * 1024,
6767
"The size in bytes of the Fiber's stack"
68+
69+
f.section "log" do |l|
70+
l.vm_variable "lifetime", true,
71+
"Log events during the Fiber's lifetime"
72+
73+
l.vm_variable "finalizer", false,
74+
"Log finalizer execution"
75+
76+
l.vm_variable "filter", "^core/.*$",
77+
"Filter paths matching pattern when logging events"
78+
end
6879
end
6980

7081
m.section "thread" do |t|
7182
t.vm_variable "stack_size", 4 * 1024 * 1024,
7283
"The size in bytes of the Thread's stack"
84+
85+
t.section "log" do |l|
86+
l.vm_variable "lifetime", true,
87+
"Log events during the Thread's lifetime"
88+
89+
l.vm_variable "finalizer", false,
90+
"Log finalizer execution"
91+
92+
l.vm_variable "filter", "^core/.*$",
93+
"Filter paths matching pattern when logging events"
94+
end
7395
end
7496

7597
m.vm_variable "stack_cushion", 4096,
@@ -116,6 +138,15 @@
116138

117139
l.vm_variable "level", "warn",
118140
"Logging level: fatal, error, warn, info, debug"
141+
142+
l.vm_variable "config", true,
143+
"Log configuration options"
144+
145+
l.vm_variable "lifetime", true,
146+
"Log events during the process lifetime"
147+
148+
l.vm_variable "filter", "^core/.*$",
149+
"Filter paths matching pattern when logging events"
119150
end
120151

121152
s.section "metrics" do |m|

Diff for: ‎machine/builtin/call_site.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace rubinius {
5454

5555
if(new_size == 0) {
5656
call_site->depth(0);
57-
delete[] call_site->caches();
57+
free(call_site->caches());
5858
call_site->caches(NULL);
5959

6060
call_site->execute(CallSite::default_execute);

Diff for: ‎machine/builtin/call_site.hpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "global_cache.hpp"
88
#include "lookup_data.hpp"
99
#include "object_utils.hpp"
10+
#include "spinlock.hpp"
1011
#include "vm.hpp"
1112

1213
#include "builtin/integer.hpp"
@@ -42,6 +43,8 @@ namespace rubinius {
4243

4344
attr_field(caches, InlineCaches*);
4445

46+
locks::spinlock_mutex cache_mutex_;
47+
4548
public:
4649
static int max_caches;
4750
static Executor default_execute;
@@ -169,6 +172,7 @@ namespace rubinius {
169172
obj->execute(default_execute);
170173
obj->cache_miss(default_execute);
171174
obj->caches(NULL);
175+
obj->cache_mutex_.unlock();
172176
}
173177

174178
void finalize(STATE) {
@@ -292,6 +296,8 @@ namespace rubinius {
292296
// 0. Ignore method_missing for now
293297
if(dispatch.name == G(sym_method_missing)) return;
294298

299+
if(cache_mutex_.try_lock()) return;
300+
295301
ClassData class_data = klass->class_data();
296302

297303
// 1. Attempt to update a cache.
@@ -301,10 +307,10 @@ namespace rubinius {
301307
// We know that nothing matched the cache, so we only need this test
302308
if(cache->receiver_data().class_id() == class_data.class_id()) {
303309
cache->update(dispatch, class_data);
304-
atomic::memory_barrier();
305310

306311
state->vm()->metrics().machine.inline_cache_updated++;
307312

313+
cache_mutex_.unlock();
308314
return;
309315
}
310316
}
@@ -315,10 +321,10 @@ namespace rubinius {
315321

316322
if(cache->inefficient_p()) {
317323
cache->update(klass, dispatch);
318-
atomic::memory_barrier();
319324

320325
state->vm()->metrics().machine.inline_cache_replaced++;
321326

327+
cache_mutex_.unlock();
322328
return;
323329
}
324330
}
@@ -332,6 +338,8 @@ namespace rubinius {
332338
inline_caches = InlineCaches::allocate(1);
333339
execute(invoke_cached);
334340
} else {
341+
cache_mutex_.unlock();
342+
return;
335343
inline_caches = InlineCaches::allocate(CallSite::max_caches);
336344
state->vm()->metrics().machine.call_site_polymorphic++;
337345
}
@@ -345,24 +353,14 @@ namespace rubinius {
345353
inline_caches->cache[i] = caches()->cache[i - 1];
346354
}
347355

348-
/* We CAS here because under concurrency, we don't know who may have
349-
* beat us here and whether those caches are in use. We know that our
350-
* caches are not in use, so if we fail to CAS, we simply discard our
351-
* work and eventually the executable will cache again if it is used.
352-
*/
353-
InlineCaches* previous_caches = caches();
354-
InlineCaches** updated_caches = &_caches_;
355-
if(atomic::compare_and_swap(reinterpret_cast<void**>(updated_caches),
356-
previous_caches, inline_caches))
357-
{
358-
if(previous_caches) delete previous_caches;
359-
} else {
360-
delete inline_caches;
361-
}
356+
caches(inline_caches);
362357

358+
cache_mutex_.unlock();
363359
return;
364360
}
365361

362+
cache_mutex_.unlock();
363+
366364
// 4. Check if we should stop trying to cache.
367365
if(invokes() > CallSite::max_caches) {
368366
state->vm()->metrics().machine.call_site_full++;
@@ -377,6 +375,8 @@ namespace rubinius {
377375
Object* cache_miss(STATE, Arguments& args) {
378376
Object* value = _cache_miss_(state, this, args);
379377

378+
if(cache_mutex_.try_lock()) return value;
379+
380380
// Check if all caching should be disabled.
381381
if(invokes() > CallSite::max_caches) {
382382
if(depth() == CallSite::max_caches) {
@@ -394,18 +394,16 @@ namespace rubinius {
394394
execute(CallSite::dispatch);
395395
cache_miss(CallSite::dispatch);
396396

397-
delete caches();
397+
free(caches());
398398
caches(NULL);
399399

400-
atomic::memory_barrier();
401-
402400
state->vm()->metrics().machine.inline_cache_disabled++;
403-
404-
return value;
405401
}
406402
}
407403
}
408404

405+
cache_mutex_.unlock();
406+
409407
return value;
410408
}
411409

@@ -505,7 +503,9 @@ namespace rubinius {
505503

506504
// Rubinius.primitive :call_site_reset
507505
CallSite* reset(STATE) {
508-
if(caches()) delete caches();
506+
std::lock_guard<locks::spinlock_mutex> guard(cache_mutex_);
507+
508+
if(caches()) free(caches());
509509

510510
invokes(0);
511511
execute(default_execute);

Diff for: ‎machine/builtin/fiber.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ namespace rubinius {
8282
fib->dead(cTrue);
8383
fib->set_call_frame(state, 0);
8484

85-
logger::write("fiber: exit: %s, %d, %fs",
86-
fib->thread_name()->c_str(state),
87-
fib->fiber_id()->to_native(), fib->run_time());
85+
if(state->shared().config.machine_fiber_log_lifetime.value) {
86+
logger::write("fiber: exit: %s, %d, %fs",
87+
fib->thread_name()->c_str(state),
88+
fib->fiber_id()->to_native(), fib->run_time());
89+
}
8890

8991
Fiber* dest = fib->prev();
9092

@@ -130,20 +132,24 @@ namespace rubinius {
130132
fib->stack_size(state, size);
131133
}
132134

133-
if(CallFrame* call_frame = state->vm()->get_noncore_frame(state)) {
134-
std::ostringstream source;
135+
if(state->shared().config.machine_fiber_log_lifetime.value) {
136+
std::string& filter = state->shared().config.machine_fiber_log_filter.value;
135137

136-
source << call_frame->file(state)->cpp_str(state).c_str()
137-
<< ":" << call_frame->line(state);
138+
if(CallFrame* call_frame = state->vm()->get_filtered_frame(state, filter)) {
139+
std::ostringstream source;
138140

139-
logger::write("fiber: new: %s, %d, %s",
140-
fib->thread_name()->c_str(state),
141-
fib->fiber_id()->to_native(), source.str().c_str());
141+
source << call_frame->file(state)->cpp_str(state).c_str()
142+
<< ":" << call_frame->line(state);
142143

143-
fib->source(state, String::create(state, source.str().c_str()));
144-
} else {
145-
logger::write("fiber: new: %s, %d",
146-
fib->thread_name()->c_str(state), fib->fiber_id()->to_native());
144+
logger::write("fiber: new: %s, %d, %s",
145+
fib->thread_name()->c_str(state),
146+
fib->fiber_id()->to_native(), source.str().c_str());
147+
148+
fib->source(state, String::create(state, source.str().c_str()));
149+
} else {
150+
logger::write("fiber: new: %s, %d",
151+
fib->thread_name()->c_str(state), fib->fiber_id()->to_native());
152+
}
147153
}
148154

149155
state->vm()->metrics().system.fibers_created++;
@@ -318,7 +324,10 @@ namespace rubinius {
318324

319325
void Fiber::finalize(STATE, Fiber* fib) {
320326
#ifdef RBX_FIBER_ENABLED
321-
logger::write("finalizer: fiber: %ld", (intptr_t)fib);
327+
if(state->shared().config.machine_fiber_log_finalizer.value) {
328+
logger::write("fiber: finalizer: %s, %d",
329+
fib->thread_name()->c_str(state), fib->fiber_id()->to_native());
330+
}
322331

323332
if(!fib->data()) return;
324333
fib->data()->orphan(state);

0 commit comments

Comments
 (0)
Please sign in to comment.