Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f10b62f

Browse files
committedMay 11, 2015
Merge remote-tracking branch 'origin' into 1.8.7
Conflicts: vm/builtin/encoding.cpp vm/include/capi/ruby/ruby.h
2 parents 216805b + 52c2849 commit f10b62f

18 files changed

+139
-94
lines changed
 

Diff for: ‎.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ env:
4848

4949
os:
5050
- linux
51-
- osx
51+
# - osx
5252

5353
osx_image: xcode61

Diff for: ‎vm/builtin/dir.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace rubinius {
1818
Dir* d = state->new_object<Dir>(G(dir));
1919
d->os_ = 0;
2020

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

2324
return d;
2425
}

Diff for: ‎vm/builtin/ffi_pointer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace rubinius {
116116
if(autorelease) {
117117
if(!set_finalizer) {
118118
state->memory()->needs_finalization(this,
119-
(FinalizerFunction)&Pointer::finalize);
119+
(FinalizerFunction)&Pointer::finalize, FinalizeObject::eUnmanaged);
120120
set_finalizer = true;
121121
}
122122
} else {

Diff for: ‎vm/builtin/fiber.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ namespace rubinius {
3737

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

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

4243
state->vm()->current_fiber.set(fib);
4344
state->vm()->root_fiber.set(fib);
@@ -110,7 +111,8 @@ namespace rubinius {
110111

111112
fib->data_ = 0;
112113

113-
state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize);
114+
state->memory()->needs_finalization(fib, (FinalizerFunction)&Fiber::finalize,
115+
FinalizeObject::eUnmanaged);
114116

115117
return fib;
116118
#else

Diff for: ‎vm/builtin/fsevent.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace rubinius {
3232
if((fsevent->kq_ = kqueue()) < 0) {
3333
logger::error("%s: unable to create kqueue", strerror(errno));
3434
} else {
35-
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize);
35+
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize,
36+
FinalizeObject::eUnmanaged);
3637
}
3738

3839
return fsevent;
@@ -79,7 +80,8 @@ namespace rubinius {
7980
if((fsevent->in_ = inotify_init()) < 0) {
8081
logger::error("%s: unable to create inotify", strerror(errno));
8182
} else {
82-
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize);
83+
state->memory()->needs_finalization(fsevent, (FinalizerFunction)&FSEvent::finalize,
84+
FinalizeObject::eUnmanaged);
8385
}
8486

8587
return fsevent;

Diff for: ‎vm/builtin/native_function.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,10 @@ namespace rubinius {
342342

343343
// Detect the stack size and set it up in the VM object
344344
size_t stack_size;
345-
pthread_attr_t attr;
346-
pthread_attr_init(&attr);
347-
pthread_attr_getstacksize (&attr, &stack_size);
345+
pthread_attr_t attrs;
346+
pthread_attr_init(&attrs);
347+
pthread_attr_getstacksize (&attrs, &stack_size);
348+
pthread_attr_destroy(&attrs);
348349
vm->set_root_stack(reinterpret_cast<uintptr_t>(&calculate_stack), stack_size);
349350

350351
// Setup nativemethod handles into thread local

Diff for: ‎vm/builtin/thread.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ namespace rubinius {
8888

8989
thr->function_ = function;
9090

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

9394
state->vm()->metrics().system_metrics.vm_threads++;
9495
state->vm()->metrics().system_metrics.vm_threads_total++;
@@ -360,6 +361,8 @@ namespace rubinius {
360361
Exception::thread_error(state, err);
361362
}
362363

364+
pthread_attr_destroy(&attrs);
365+
363366
return cNil;
364367
}
365368

Diff for: ‎vm/console.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace rubinius {
5757
}
5858

5959
Request::Request(STATE, Console* console, Response* response)
60-
: InternalThread(state, "rbx.console.request")
60+
: InternalThread(state, "rbx.console.request", InternalThread::eSmall)
6161
, console_(console)
6262
, response_(response)
6363
, enabled_(false)
@@ -166,7 +166,7 @@ namespace rubinius {
166166
}
167167

168168
Response::Response(STATE, Console* console)
169-
: InternalThread(state, "rbx.console.response")
169+
: InternalThread(state, "rbx.console.response", InternalThread::eSmall)
170170
, console_(console)
171171
, inbox_(state)
172172
, outbox_(state)
@@ -328,7 +328,7 @@ namespace rubinius {
328328
}
329329

330330
Listener::Listener(STATE, Console* console)
331-
: InternalThread(state, "rbx.console.listener")
331+
: InternalThread(state, "rbx.console.listener", InternalThread::eSmall)
332332
, console_(console)
333333
, fsevent_(state)
334334
, fd_(-1)

Diff for: ‎vm/gc/finalize.cpp

+40-34
Original file line numberDiff line numberDiff line change
@@ -182,41 +182,44 @@ namespace rubinius {
182182
}
183183
case eNative:
184184
if(process_item_->finalizer) {
185-
186-
NativeMethodEnvironment* env = state->vm()->native_method_environment;
187-
NativeMethodFrame nmf(env, 0, 0);
188-
ExceptionPoint ep(env);
189-
CallFrame* call_frame = ALLOCA_CALLFRAME(0);
190-
191-
call_frame->previous = 0;
192-
call_frame->constant_scope_ = 0;
193-
call_frame->dispatch_data = (void*)&nmf;
194-
call_frame->compiled_code = 0;
195-
call_frame->flags = CallFrame::cNativeMethod;
196-
call_frame->optional_jit_data = 0;
197-
call_frame->top_scope_ = 0;
198-
call_frame->scope = 0;
199-
call_frame->arguments = 0;
200-
201-
env->set_current_call_frame(0);
202-
env->set_current_native_frame(&nmf);
203-
204-
// Register the CallFrame, because we might GC below this.
205-
state->set_call_frame(call_frame);
206-
207-
nmf.setup(Qnil, Qnil, Qnil, Qnil);
208-
209-
PLACE_EXCEPTION_POINT(ep);
210-
211-
if(unlikely(ep.jumped_to())) {
212-
// TODO: log this?
213-
} else {
185+
if(process_item_->kind == FinalizeObject::eUnmanaged) {
214186
(*process_item_->finalizer)(state, process_item_->object);
215-
}
187+
} else {
188+
NativeMethodEnvironment* env = state->vm()->native_method_environment;
189+
NativeMethodFrame nmf(env, 0, 0);
190+
ExceptionPoint ep(env);
191+
CallFrame* call_frame = ALLOCA_CALLFRAME(0);
192+
193+
call_frame->previous = 0;
194+
call_frame->constant_scope_ = 0;
195+
call_frame->dispatch_data = (void*)&nmf;
196+
call_frame->compiled_code = 0;
197+
call_frame->flags = CallFrame::cNativeMethod;
198+
call_frame->optional_jit_data = 0;
199+
call_frame->top_scope_ = 0;
200+
call_frame->scope = 0;
201+
call_frame->arguments = 0;
202+
203+
env->set_current_call_frame(0);
204+
env->set_current_native_frame(&nmf);
205+
206+
// Register the CallFrame, because we might GC below this.
207+
state->set_call_frame(call_frame);
208+
209+
nmf.setup(Qnil, Qnil, Qnil, Qnil);
210+
211+
PLACE_EXCEPTION_POINT(ep);
212+
213+
if(unlikely(ep.jumped_to())) {
214+
// TODO: log this?
215+
} else {
216+
(*process_item_->finalizer)(state, process_item_->object);
217+
}
216218

217-
state->set_call_frame(0);
218-
env->set_current_call_frame(0);
219-
env->set_current_native_frame(0);
219+
state->set_call_frame(0);
220+
env->set_current_call_frame(0);
221+
env->set_current_native_frame(0);
222+
}
220223
}
221224
process_item_->status = FinalizeObject::eNativeFinalized;
222225
break;
@@ -302,13 +305,16 @@ namespace rubinius {
302305
}
303306
}
304307

305-
void FinalizerThread::record(Object* obj, FinalizerFunction func) {
308+
void FinalizerThread::record(Object* obj, FinalizerFunction func,
309+
FinalizeObject::FinalizeKind kind)
310+
{
306311
utilities::thread::Mutex::LockGuard lg(live_guard_);
307312

308313
if(finishing_) return;
309314

310315
FinalizeObject fi;
311316
fi.object = obj;
317+
fi.kind = kind;
312318
fi.status = FinalizeObject::eLive;
313319
fi.finalizer = func;
314320

Diff for: ‎vm/gc/finalize.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ namespace rubinius {
1919

2020
struct FinalizeObject {
2121
public:
22+
enum FinalizeKind {
23+
eManaged,
24+
eUnmanaged
25+
};
26+
2227
enum FinalizationStatus {
2328
eLive,
2429
eQueued,
@@ -36,6 +41,7 @@ namespace rubinius {
3641
{}
3742

3843
Object* object;
44+
FinalizeKind kind;
3945
FinalizationStatus status;
4046
FinalizerFunction finalizer;
4147
Object* ruby_finalizer;
@@ -102,7 +108,7 @@ namespace rubinius {
102108
void next_process_item();
103109
void finish(STATE, GCToken gct);
104110

105-
void record(Object* obj, FinalizerFunction func);
111+
void record(Object* obj, FinalizerFunction func, FinalizeObject::FinalizeKind kind);
106112
void set_ruby_finalizer(Object* obj, Object* finalizer);
107113

108114
void queue_objects();

Diff for: ‎vm/internal_threads.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
namespace rubinius {
1212
using namespace utilities;
1313

14-
#define AUXILIARY_THREAD_STACK_SIZE 0x100000
15-
16-
InternalThread::InternalThread(STATE, std::string name)
14+
InternalThread::InternalThread(STATE, std::string name, StackSize stack_size)
1715
: vm_(state->shared().new_vm())
1816
, name_(name)
1917
, thread_running_(false)
18+
, stack_size_(stack_size)
2019
, metrics_(vm_->metrics())
2120
, thread_exit_(false)
2221
{
@@ -72,13 +71,15 @@ namespace rubinius {
7271
void InternalThread::start_thread(STATE) {
7372
pthread_attr_t attrs;
7473
pthread_attr_init(&attrs);
75-
pthread_attr_setstacksize(&attrs, AUXILIARY_THREAD_STACK_SIZE);
74+
pthread_attr_setstacksize(&attrs, stack_size_);
7675

7776
if(int error = pthread_create(&vm_->os_thread(), &attrs,
7877
InternalThread::run, (void*)this)) {
7978
logger::fatal("%s: %s: create thread failed", strerror(error), name_.c_str());
8079
::abort();
8180
}
81+
82+
pthread_attr_destroy(&attrs);
8283
}
8384

8485
void InternalThread::wakeup(STATE) {

Diff for: ‎vm/internal_threads.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace rubinius {
1717
VM* vm_;
1818
std::string name_;
1919
bool thread_running_;
20+
uint32_t stack_size_;
2021

2122
metrics::MetricsData& metrics_;
2223

@@ -26,7 +27,13 @@ namespace rubinius {
2627

2728
public:
2829

29-
InternalThread(STATE, std::string name);
30+
enum StackSize {
31+
eSmall = 0x1000,
32+
eLarge = 0x10000,
33+
eXLarge = 0x100000,
34+
};
35+
36+
InternalThread(STATE, std::string name, StackSize stack_size=eLarge);
3037
virtual ~InternalThread() { };
3138

3239
// OS thread trampoline

Diff for: ‎vm/llvm/state.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace rubinius {
8989
static const bool debug_search = false;
9090

9191
LLVMState::LLVMState(STATE)
92-
: InternalThread(state, "rbx.jit")
92+
: InternalThread(state, "rbx.jit", InternalThread::eXLarge)
9393
, config_(state->shared().config)
9494
, compile_list_(state)
9595
, symbols_(state->shared().symbols)

Diff for: ‎vm/metrics.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,13 @@ namespace rubinius {
190190
}
191191

192192
Metrics::Metrics(STATE)
193-
: InternalThread(state, "rbx.metrics")
193+
: InternalThread(state, "rbx.metrics", InternalThread::eSmall)
194194
, enabled_(true)
195195
, values_(state)
196196
, interval_(state->shared().config.system_metrics_interval)
197197
, timer_(NULL)
198198
, emitter_(NULL)
199199
{
200-
metrics_lock_.init();
201200
map_metrics();
202201

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

420419
timer_ = new timer::Timer;
421420

421+
metrics_lock_.init();
422422
metrics_collection_.init();
423423
metrics_history_.init();
424424
}
@@ -459,31 +459,31 @@ namespace rubinius {
459459

460460
if(thread_exit_) break;
461461

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

465-
metrics_collection_.init();
466-
ThreadList* threads = state->shared().threads();
467-
468-
for(ThreadList::iterator i = threads->begin();
469-
i != threads->end();
470-
++i) {
471-
if(VM* vm = (*i)->as_vm()) {
472-
metrics_collection_.add(vm->metrics());
473-
}
465+
for(ThreadList::iterator i = threads->begin();
466+
i != threads->end();
467+
++i) {
468+
if(VM* vm = (*i)->as_vm()) {
469+
metrics_collection_.add(vm->metrics());
474470
}
471+
}
475472

476473
#ifdef ENABLE_LLVM
477-
if(LLVMState* llvm_state = state->shared().llvm_state) {
478-
metrics_collection_.add(llvm_state->metrics());
479-
}
474+
if(LLVMState* llvm_state = state->shared().llvm_state) {
475+
metrics_collection_.add(llvm_state->metrics());
476+
}
480477
#endif
481478

482-
metrics_collection_.add(metrics_history_);
479+
{
480+
utilities::thread::Mutex::LockGuard guard(metrics_lock_);
483481

484-
update_ruby_values(state);
482+
metrics_collection_.add(metrics_history_);
485483
}
486484

485+
update_ruby_values(state);
486+
487487
if(emitter_) emitter_->send_metrics();
488488
}
489489

Diff for: ‎vm/object_memory.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1012,9 +1012,11 @@ namespace rubinius {
10121012
code_manager_.add_resource(cr, &collect_mature_now);
10131013
}
10141014

1015-
void ObjectMemory::needs_finalization(Object* obj, FinalizerFunction func) {
1015+
void ObjectMemory::needs_finalization(Object* obj, FinalizerFunction func,
1016+
FinalizeObject::FinalizeKind kind)
1017+
{
10161018
if(FinalizerThread* fh = shared_.finalizer_handler()) {
1017-
fh->record(obj, func);
1019+
fh->record(obj, func, kind);
10181020
}
10191021
}
10201022

Diff for: ‎vm/object_memory.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ namespace rubinius {
320320

321321
void collect_maybe(STATE, GCToken gct, CallFrame* call_frame);
322322

323-
void needs_finalization(Object* obj, FinalizerFunction func);
323+
void needs_finalization(Object* obj, FinalizerFunction func,
324+
FinalizeObject::FinalizeKind kind = FinalizeObject::eManaged);
324325
void set_ruby_finalizer(Object* obj, Object* finalizer);
325326

326327
size_t& loe_usage();

Diff for: ‎vm/signal.cpp

+26-17
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace rubinius {
5454
static struct utsname machine_info;
5555

5656
SignalThread::SignalThread(STATE, Configuration& config)
57-
: InternalThread(state, "rbx.signal")
57+
: InternalThread(state, "rbx.signal", InternalThread::eSmall)
5858
, shared_(state->shared())
5959
, target_(state->vm())
6060
, queued_signals_(0)
@@ -93,28 +93,37 @@ namespace rubinius {
9393
}
9494

9595
void SignalThread::print_machine_info(PrintFunction function) {
96-
function("sysname: %s", machine_info.sysname);
97-
function("nodename: %s", machine_info.nodename);
98-
function("release: %s", machine_info.release);
99-
function("version: %s", machine_info.version);
100-
function("machine: %s", machine_info.machine);
96+
function("node info: %s %s", machine_info.nodename, machine_info.version);
10197
}
10298

10399

100+
#define RBX_PROCESS_INFO_LEN 256
101+
104102
void SignalThread::print_process_info(PrintFunction function) {
105-
function("user: %s", signal_thread_->shared().username.c_str());
106-
function("pid: %s", signal_thread_->shared().pid.c_str());
107-
function("program name: %s", RBX_PROGRAM_NAME);
108-
function("version: %s", RBX_VERSION);
109-
function("ruby version: %s", RBX_RUBY_VERSION);
110-
function("release date: %s", RBX_RELEASE_DATE);
111-
function("build revision: %s", RBX_BUILD_REV);
103+
const char* llvm_version;
104+
const char* jit_status;
105+
112106
#if ENABLE_LLVM
113-
function("llvm version: %s", RBX_LLVM_VERSION);
107+
llvm_version = RBX_LLVM_VERSION;
108+
#else
109+
llvm_version = "LLVM Disabled";
114110
#endif
115-
function("jit status: %s",
116-
CBOOL(signal_thread_->shared().env()->state->globals().jit.get()->enabled())
117-
? "enabled" : "disabled");
111+
112+
if(CBOOL(signal_thread_->shared().env()->state->globals().jit.get()->enabled())) {
113+
jit_status = "JIT";
114+
} else {
115+
jit_status = "JIT disabled";
116+
}
117+
118+
char process_info[RBX_PROCESS_INFO_LEN];
119+
120+
snprintf(process_info, RBX_PROCESS_INFO_LEN, "%s %s %s %s %s %s %.8s %s %s",
121+
signal_thread_->shared().username.c_str(),
122+
RBX_PROGRAM_NAME, signal_thread_->shared().pid.c_str(),
123+
RBX_VERSION, RBX_RUBY_VERSION, RBX_RELEASE_DATE, RBX_BUILD_REV,
124+
llvm_version, jit_status);
125+
126+
function("process info: %s", process_info);
118127
}
119128

120129
void SignalThread::run(STATE) {

Diff for: ‎vm/util/thread.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ namespace thread {
134134
}
135135
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_JOINABLE);
136136

137-
return pthread_create(&native_, &attrs, trampoline, (void*)this);
137+
int status = pthread_create(&native_, &attrs, trampoline, (void*)this);
138+
139+
pthread_attr_destroy(&attrs);
140+
141+
return status;
138142
}
139143

140144
virtual void perform() { }

0 commit comments

Comments
 (0)
Please sign in to comment.