Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into 1.8.7
Browse files Browse the repository at this point in the history
Conflicts:
	vm/builtin/encoding.cpp
	vm/include/capi/ruby/ruby.h
  • Loading branch information
brixen committed May 11, 2015
2 parents 216805b + 52c2849 commit f10b62f
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ env:

os:
- linux
- osx
# - osx

osx_image: xcode61
3 changes: 2 additions & 1 deletion vm/builtin/dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace rubinius {
Dir* d = state->new_object<Dir>(G(dir));
d->os_ = 0;

state->memory()->needs_finalization(d, (FinalizerFunction)&Dir::finalize);
state->memory()->needs_finalization(d, (FinalizerFunction)&Dir::finalize,
FinalizeObject::eUnmanaged);

return d;
}
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/ffi_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace rubinius {
if(autorelease) {
if(!set_finalizer) {
state->memory()->needs_finalization(this,
(FinalizerFunction)&Pointer::finalize);
(FinalizerFunction)&Pointer::finalize, FinalizeObject::eUnmanaged);
set_finalizer = true;
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions vm/builtin/fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace rubinius {

fib->data_ = state->vm()->new_fiber_data(true);

state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize);
state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize,
FinalizeObject::eUnmanaged);

state->vm()->current_fiber.set(fib);
state->vm()->root_fiber.set(fib);
Expand Down Expand Up @@ -110,7 +111,8 @@ namespace rubinius {

fib->data_ = 0;

state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize);
state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize,
FinalizeObject::eUnmanaged);

return fib;
#else
Expand Down
6 changes: 4 additions & 2 deletions vm/builtin/fsevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace rubinius {
if((fsevent->kq_ = kqueue()) < 0) {
logger::error("%s: unable to create kqueue", strerror(errno));
} else {
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize);
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize,
FinalizeObject::eUnmanaged);
}

return fsevent;
Expand Down Expand Up @@ -79,7 +80,8 @@ namespace rubinius {
if((fsevent->in_ = inotify_init()) < 0) {
logger::error("%s: unable to create inotify", strerror(errno));
} else {
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize);
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize,
FinalizeObject::eUnmanaged);
}

return fsevent;
Expand Down
7 changes: 4 additions & 3 deletions vm/builtin/native_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,10 @@ namespace rubinius {

// Detect the stack size and set it up in the VM object
size_t stack_size;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_getstacksize (&attr, &stack_size);
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_getstacksize (&attrs, &stack_size);
pthread_attr_destroy(&attrs);
vm->set_root_stack(reinterpret_cast<uintptr_t>(&calculate_stack), stack_size);

// Setup nativemethod handles into thread local
Expand Down
5 changes: 4 additions & 1 deletion vm/builtin/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ namespace rubinius {

thr->function_ = function;

state->memory()->needs_finalization(thr, (FinalizerFunction)&Thread::finalize);
state->memory()->needs_finalization(thr, (FinalizerFunction)&Thread::finalize,
FinalizeObject::eUnmanaged);

state->vm()->metrics().system_metrics.vm_threads++;
state->vm()->metrics().system_metrics.vm_threads_total++;
Expand Down Expand Up @@ -360,6 +361,8 @@ namespace rubinius {
Exception::thread_error(state, err);
}

pthread_attr_destroy(&attrs);

return cNil;
}

Expand Down
6 changes: 3 additions & 3 deletions vm/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace rubinius {
}

Request::Request(STATE, Console* console, Response* response)
: InternalThread(state, "rbx.console.request")
: InternalThread(state, "rbx.console.request", InternalThread::eSmall)
, console_(console)
, response_(response)
, enabled_(false)
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace rubinius {
}

Response::Response(STATE, Console* console)
: InternalThread(state, "rbx.console.response")
: InternalThread(state, "rbx.console.response", InternalThread::eSmall)
, console_(console)
, inbox_(state)
, outbox_(state)
Expand Down Expand Up @@ -328,7 +328,7 @@ namespace rubinius {
}

Listener::Listener(STATE, Console* console)
: InternalThread(state, "rbx.console.listener")
: InternalThread(state, "rbx.console.listener", InternalThread::eSmall)
, console_(console)
, fsevent_(state)
, fd_(-1)
Expand Down
74 changes: 40 additions & 34 deletions vm/gc/finalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,41 +182,44 @@ namespace rubinius {
}
case eNative:
if(process_item_->finalizer) {

NativeMethodEnvironment* env = state->vm()->native_method_environment;
NativeMethodFrame nmf(env, 0, 0);
ExceptionPoint ep(env);
CallFrame* call_frame = ALLOCA_CALLFRAME(0);

call_frame->previous = 0;
call_frame->constant_scope_ = 0;
call_frame->dispatch_data = (void*)&nmf;
call_frame->compiled_code = 0;
call_frame->flags = CallFrame::cNativeMethod;
call_frame->optional_jit_data = 0;
call_frame->top_scope_ = 0;
call_frame->scope = 0;
call_frame->arguments = 0;

env->set_current_call_frame(0);
env->set_current_native_frame(&nmf);

// Register the CallFrame, because we might GC below this.
state->set_call_frame(call_frame);

nmf.setup(Qnil, Qnil, Qnil, Qnil);

PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
// TODO: log this?
} else {
if(process_item_->kind == FinalizeObject::eUnmanaged) {
(*process_item_->finalizer)(state, process_item_->object);
}
} else {
NativeMethodEnvironment* env = state->vm()->native_method_environment;
NativeMethodFrame nmf(env, 0, 0);
ExceptionPoint ep(env);
CallFrame* call_frame = ALLOCA_CALLFRAME(0);

call_frame->previous = 0;
call_frame->constant_scope_ = 0;
call_frame->dispatch_data = (void*)&nmf;
call_frame->compiled_code = 0;
call_frame->flags = CallFrame::cNativeMethod;
call_frame->optional_jit_data = 0;
call_frame->top_scope_ = 0;
call_frame->scope = 0;
call_frame->arguments = 0;

env->set_current_call_frame(0);
env->set_current_native_frame(&nmf);

// Register the CallFrame, because we might GC below this.
state->set_call_frame(call_frame);

nmf.setup(Qnil, Qnil, Qnil, Qnil);

PLACE_EXCEPTION_POINT(ep);

if(unlikely(ep.jumped_to())) {
// TODO: log this?
} else {
(*process_item_->finalizer)(state, process_item_->object);
}

state->set_call_frame(0);
env->set_current_call_frame(0);
env->set_current_native_frame(0);
state->set_call_frame(0);
env->set_current_call_frame(0);
env->set_current_native_frame(0);
}
}
process_item_->status = FinalizeObject::eNativeFinalized;
break;
Expand Down Expand Up @@ -302,13 +305,16 @@ namespace rubinius {
}
}

void FinalizerThread::record(Object* obj, FinalizerFunction func) {
void FinalizerThread::record(Object* obj, FinalizerFunction func,
FinalizeObject::FinalizeKind kind)
{
utilities::thread::Mutex::LockGuard lg(live_guard_);

if(finishing_) return;

FinalizeObject fi;
fi.object = obj;
fi.kind = kind;
fi.status = FinalizeObject::eLive;
fi.finalizer = func;

Expand Down
8 changes: 7 additions & 1 deletion vm/gc/finalize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace rubinius {

struct FinalizeObject {
public:
enum FinalizeKind {
eManaged,
eUnmanaged
};

enum FinalizationStatus {
eLive,
eQueued,
Expand All @@ -36,6 +41,7 @@ namespace rubinius {
{}

Object* object;
FinalizeKind kind;
FinalizationStatus status;
FinalizerFunction finalizer;
Object* ruby_finalizer;
Expand Down Expand Up @@ -102,7 +108,7 @@ namespace rubinius {
void next_process_item();
void finish(STATE, GCToken gct);

void record(Object* obj, FinalizerFunction func);
void record(Object* obj, FinalizerFunction func, FinalizeObject::FinalizeKind kind);
void set_ruby_finalizer(Object* obj, Object* finalizer);

void queue_objects();
Expand Down
9 changes: 5 additions & 4 deletions vm/internal_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
namespace rubinius {
using namespace utilities;

#define AUXILIARY_THREAD_STACK_SIZE 0x100000

InternalThread::InternalThread(STATE, std::string name)
InternalThread::InternalThread(STATE, std::string name, StackSize stack_size)
: vm_(state->shared().new_vm())
, name_(name)
, thread_running_(false)
, stack_size_(stack_size)
, metrics_(vm_->metrics())
, thread_exit_(false)
{
Expand Down Expand Up @@ -72,13 +71,15 @@ namespace rubinius {
void InternalThread::start_thread(STATE) {
pthread_attr_t attrs;
pthread_attr_init(&attrs);
pthread_attr_setstacksize(&attrs, AUXILIARY_THREAD_STACK_SIZE);
pthread_attr_setstacksize(&attrs, stack_size_);

if(int error = pthread_create(&vm_->os_thread(), &attrs,
InternalThread::run, (void*)this)) {
logger::fatal("%s: %s: create thread failed", strerror(error), name_.c_str());
::abort();
}

pthread_attr_destroy(&attrs);
}

void InternalThread::wakeup(STATE) {
Expand Down
9 changes: 8 additions & 1 deletion vm/internal_threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace rubinius {
VM* vm_;
std::string name_;
bool thread_running_;
uint32_t stack_size_;

metrics::MetricsData& metrics_;

Expand All @@ -26,7 +27,13 @@ namespace rubinius {

public:

InternalThread(STATE, std::string name);
enum StackSize {
eSmall = 0x1000,
eLarge = 0x10000,
eXLarge = 0x100000,
};

InternalThread(STATE, std::string name, StackSize stack_size=eLarge);
virtual ~InternalThread() { };

// OS thread trampoline
Expand Down
2 changes: 1 addition & 1 deletion vm/llvm/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace rubinius {
static const bool debug_search = false;

LLVMState::LLVMState(STATE)
: InternalThread(state, "rbx.jit")
: InternalThread(state, "rbx.jit", InternalThread::eXLarge)
, config_(state->shared().config)
, compile_list_(state)
, symbols_(state->shared().symbols)
Expand Down
36 changes: 18 additions & 18 deletions vm/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,13 @@ namespace rubinius {
}

Metrics::Metrics(STATE)
: InternalThread(state, "rbx.metrics")
: InternalThread(state, "rbx.metrics", InternalThread::eSmall)
, enabled_(true)
, values_(state)
, interval_(state->shared().config.system_metrics_interval)
, timer_(NULL)
, emitter_(NULL)
{
metrics_lock_.init();
map_metrics();

if(!state->shared().config.system_metrics_target.value.compare("statsd")) {
Expand Down Expand Up @@ -419,6 +418,7 @@ namespace rubinius {

timer_ = new timer::Timer;

metrics_lock_.init();
metrics_collection_.init();
metrics_history_.init();
}
Expand Down Expand Up @@ -459,31 +459,31 @@ namespace rubinius {

if(thread_exit_) break;

{
utilities::thread::Mutex::LockGuard guard(metrics_lock_);
metrics_collection_.init();
ThreadList* threads = state->shared().threads();

metrics_collection_.init();
ThreadList* threads = state->shared().threads();

for(ThreadList::iterator i = threads->begin();
i != threads->end();
++i) {
if(VM* vm = (*i)->as_vm()) {
metrics_collection_.add(vm->metrics());
}
for(ThreadList::iterator i = threads->begin();
i != threads->end();
++i) {
if(VM* vm = (*i)->as_vm()) {
metrics_collection_.add(vm->metrics());
}
}

#ifdef ENABLE_LLVM
if(LLVMState* llvm_state = state->shared().llvm_state) {
metrics_collection_.add(llvm_state->metrics());
}
if(LLVMState* llvm_state = state->shared().llvm_state) {
metrics_collection_.add(llvm_state->metrics());
}
#endif

metrics_collection_.add(metrics_history_);
{
utilities::thread::Mutex::LockGuard guard(metrics_lock_);

update_ruby_values(state);
metrics_collection_.add(metrics_history_);
}

update_ruby_values(state);

if(emitter_) emitter_->send_metrics();
}

Expand Down
Loading

0 comments on commit f10b62f

Please sign in to comment.