Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into codedb-ffi-io
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jun 10, 2016
2 parents e200552 + 08547ed commit cb6f950
Show file tree
Hide file tree
Showing 25 changed files with 473 additions and 304 deletions.
31 changes: 31 additions & 0 deletions library/rubinius/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,33 @@

f.vm_variable "stack_size", 512 * 1024,
"The size in bytes of the Fiber's stack"

f.section "log" do |l|
l.vm_variable "lifetime", true,
"Log events during the Fiber's lifetime"

l.vm_variable "finalizer", false,
"Log finalizer execution"

l.vm_variable "filter", "^core/.*$",
"Filter paths matching pattern when logging events"
end
end

m.section "thread" do |t|
t.vm_variable "stack_size", 4 * 1024 * 1024,
"The size in bytes of the Thread's stack"

t.section "log" do |l|
l.vm_variable "lifetime", true,
"Log events during the Thread's lifetime"

l.vm_variable "finalizer", false,
"Log finalizer execution"

l.vm_variable "filter", "^core/.*$",
"Filter paths matching pattern when logging events"
end
end

m.vm_variable "stack_cushion", 4096,
Expand Down Expand Up @@ -116,6 +138,15 @@

l.vm_variable "level", "warn",
"Logging level: fatal, error, warn, info, debug"

l.vm_variable "config", true,
"Log configuration options"

l.vm_variable "lifetime", true,
"Log events during the process lifetime"

l.vm_variable "filter", "^core/.*$",
"Filter paths matching pattern when logging events"
end

s.section "metrics" do |m|
Expand Down
2 changes: 1 addition & 1 deletion machine/builtin/call_site.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace rubinius {

if(new_size == 0) {
call_site->depth(0);
delete[] call_site->caches();
free(call_site->caches());
call_site->caches(NULL);

call_site->execute(CallSite::default_execute);
Expand Down
44 changes: 22 additions & 22 deletions machine/builtin/call_site.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "global_cache.hpp"
#include "lookup_data.hpp"
#include "object_utils.hpp"
#include "spinlock.hpp"
#include "vm.hpp"

#include "builtin/integer.hpp"
Expand Down Expand Up @@ -42,6 +43,8 @@ namespace rubinius {

attr_field(caches, InlineCaches*);

locks::spinlock_mutex cache_mutex_;

public:
static int max_caches;
static Executor default_execute;
Expand Down Expand Up @@ -169,6 +172,7 @@ namespace rubinius {
obj->execute(default_execute);
obj->cache_miss(default_execute);
obj->caches(NULL);
obj->cache_mutex_.unlock();
}

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

if(cache_mutex_.try_lock()) return;

ClassData class_data = klass->class_data();

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

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

cache_mutex_.unlock();
return;
}
}
Expand All @@ -315,10 +321,10 @@ namespace rubinius {

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

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

cache_mutex_.unlock();
return;
}
}
Expand All @@ -332,6 +338,8 @@ namespace rubinius {
inline_caches = InlineCaches::allocate(1);
execute(invoke_cached);
} else {
cache_mutex_.unlock();
return;
inline_caches = InlineCaches::allocate(CallSite::max_caches);
state->vm()->metrics().machine.call_site_polymorphic++;
}
Expand All @@ -345,24 +353,14 @@ namespace rubinius {
inline_caches->cache[i] = caches()->cache[i - 1];
}

/* We CAS here because under concurrency, we don't know who may have
* beat us here and whether those caches are in use. We know that our
* caches are not in use, so if we fail to CAS, we simply discard our
* work and eventually the executable will cache again if it is used.
*/
InlineCaches* previous_caches = caches();
InlineCaches** updated_caches = &_caches_;
if(atomic::compare_and_swap(reinterpret_cast<void**>(updated_caches),
previous_caches, inline_caches))
{
if(previous_caches) delete previous_caches;
} else {
delete inline_caches;
}
caches(inline_caches);

cache_mutex_.unlock();
return;
}

cache_mutex_.unlock();

// 4. Check if we should stop trying to cache.
if(invokes() > CallSite::max_caches) {
state->vm()->metrics().machine.call_site_full++;
Expand All @@ -377,6 +375,8 @@ namespace rubinius {
Object* cache_miss(STATE, Arguments& args) {
Object* value = _cache_miss_(state, this, args);

if(cache_mutex_.try_lock()) return value;

// Check if all caching should be disabled.
if(invokes() > CallSite::max_caches) {
if(depth() == CallSite::max_caches) {
Expand All @@ -394,18 +394,16 @@ namespace rubinius {
execute(CallSite::dispatch);
cache_miss(CallSite::dispatch);

delete caches();
free(caches());
caches(NULL);

atomic::memory_barrier();

state->vm()->metrics().machine.inline_cache_disabled++;

return value;
}
}
}

cache_mutex_.unlock();

return value;
}

Expand Down Expand Up @@ -505,7 +503,9 @@ namespace rubinius {

// Rubinius.primitive :call_site_reset
CallSite* reset(STATE) {
if(caches()) delete caches();
std::lock_guard<locks::spinlock_mutex> guard(cache_mutex_);

if(caches()) free(caches());

invokes(0);
execute(default_execute);
Expand Down
39 changes: 24 additions & 15 deletions machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ namespace rubinius {
fib->dead(cTrue);
fib->set_call_frame(state, 0);

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

Fiber* dest = fib->prev();

Expand Down Expand Up @@ -130,20 +132,24 @@ namespace rubinius {
fib->stack_size(state, size);
}

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

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

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

fib->source(state, String::create(state, source.str().c_str()));
} else {
logger::write("fiber: new: %s, %d",
fib->thread_name()->c_str(state), fib->fiber_id()->to_native());
logger::write("fiber: new: %s, %d, %s",
fib->thread_name()->c_str(state),
fib->fiber_id()->to_native(), source.str().c_str());

fib->source(state, String::create(state, source.str().c_str()));
} else {
logger::write("fiber: new: %s, %d",
fib->thread_name()->c_str(state), fib->fiber_id()->to_native());
}
}

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

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

if(!fib->data()) return;
fib->data()->orphan(state);
Expand Down
Loading

0 comments on commit cb6f950

Please sign in to comment.