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:
	Gemfile.lock
	kernel/common/hash_hamt.rb
  • Loading branch information
brixen committed Jan 28, 2015
2 parents 034f958 + e641668 commit 34e71c6
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 164 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
@@ -1,7 +1,9 @@
language: cpp

compiler:
- gcc
- clang

before_install:
- echo $LANG
- echo $LC_ALL
Expand All @@ -10,15 +12,23 @@ before_install:
- rvm use $RVM --install --binary --fuzzy
- gem update --system
- gem --version

before_script:
- travis_retry bundle
- if [ $TRAVIS_OS_NAME == linux ]; then travis_retry ./configure --llvm-config llvm-config-3.4; fi
- if [ $TRAVIS_OS_NAME == osx ]; then travis_retry ./configure --llvm-config /usr/local/opt/llvm/bin/llvm-config; fi

script: rake

after_success:
- if [ $TRAVIS_BRANCH == $TRAVIS_TAG ]; then rake deploy; fi

branches:
only:
- master
- 1.8.7
- /^v\d+\./

notifications:
email: false
irc:
Expand All @@ -32,9 +42,12 @@ notifications:
on_success: change
on_failure: always
on_start: false

env:
- RVM=2.0.0 LANG="en_US.UTF-8"

os:
- linux
- osx

osx_image: xcode61
27 changes: 25 additions & 2 deletions configure
Expand Up @@ -597,8 +597,12 @@ Unsupported language version requested: #{version}. Options are #{@supported_ver
if which
config = File.join(which, "llvm-config")
elsif @darwin
out = `brew list llvm | grep '/llvm-config$'`
config = out.chomp if $?.success?
if macports?
config = macports_llvm_config
else
out = `brew list llvm | grep '/llvm-config$'`
config = out.chomp if $?.success?
end
end
end

Expand Down Expand Up @@ -1987,6 +1991,25 @@ Available commands are:
message.index("\n") != nil
end
end

# Returns true if MacPorts is installed in its default location.
def macports?
File.exists? '/opt/local/bin/port'
end

# Query MacPorts for the path to the latest installed version of
# llvm-config that is within the range of supported LLVM versions.
def macports_llvm_config
supported_versions = (3.0 .. 3.5)
installed_ports = `port installed | egrep -o 'llvm-[^ ]+'`.split
latest_usable_port = installed_ports.sort.select do |fname|
version = fname.match(/-\K.*/)[0].to_f
supported_versions.include? version
end.last
avail_binaries = `port contents #{latest_usable_port} |
fgrep llvm-config`.split
avail_binaries.reject { |fname| fname.include? 'libexec' }.last
end
end

STDOUT.sync = true
Expand Down
4 changes: 4 additions & 0 deletions rakelib/deploy.rake
@@ -0,0 +1,4 @@
desc "Deploy a Rubinius release"
task :deploy do
puts "Deploying #{ENV["TRAVIS_TAG"]}..."
end
105 changes: 64 additions & 41 deletions vm/builtin/thread.cpp
Expand Up @@ -17,6 +17,7 @@
#include "ontology.hpp"
#include "on_stack.hpp"
#include "metrics.hpp"
#include "util/logger.hpp"

/* HACK: returns a value that should identify a native thread
* for debugging threading issues. The winpthreads library
Expand Down Expand Up @@ -47,7 +48,7 @@ namespace rubinius {
}

Thread* Thread::create(STATE, VM* target, Object* self, Run runner,
bool system_thread)
bool internal_thread)
{
Thread* thr = state->vm()->new_object_mature<Thread>(G(thread));

Expand Down Expand Up @@ -75,7 +76,7 @@ namespace rubinius {
thr->klass(state, as<Class>(self));
thr->runner_ = runner;
thr->init_lock_.init();
thr->system_thread_ = system_thread;
thr->internal_thread_ = internal_thread;

target->thread.set(thr);

Expand Down Expand Up @@ -217,13 +218,22 @@ namespace rubinius {
return cFalse;
}

int Thread::start_new_thread(STATE, const pthread_attr_t &attrs) {
int Thread::start_thread(STATE, const pthread_attr_t &attrs) {
Thread* self = this;
OnStack<1> os(state, self);

self->init_lock_.lock();
int error = pthread_create(&self->vm_->os_thread(), &attrs, in_new_thread, (void*)self->vm_);
if(error) {

void* (*thread_function)(void *);

if(internal_thread_) {
thread_function = internal_thread;
} else {
thread_function = ruby_thread;
}

if(int error = pthread_create(&self->vm_->os_thread(),
&attrs, thread_function, (void*)self->vm_)) {
return error;
}

Expand All @@ -240,34 +250,17 @@ namespace rubinius {
return 0;
}

void* Thread::in_new_thread(void* ptr) {
VM* vm = reinterpret_cast<VM*>(ptr);

State state_obj(vm), *state = &state_obj;

int calculate_stack = 0;
NativeMethod::init_thread(state);

std::string thread_name;

{
std::ostringstream tn;
tn << "rbx.ruby." << vm->thread_id();
VM::set_current(vm, tn.str());
thread_name = tn.str();
}

RUBINIUS_THREAD_START(const_cast<RBX_DTRACE_CHAR_P>(thread_name.c_str()),
vm->thread_id(), 0);

void Thread::execute_thread(STATE, VM* vm) {
if(cDebugThreading) {
std::cerr << "[THREAD " << vm->thread_id()
<< " (" << (unsigned int)thread_debug_self() << ") started thread]\n";
utilities::logger::debug("Thread: start thread: id: %d, pthread: %d",
vm->thread_id(), (unsigned int)thread_debug_self());
}

GCTokenImpl gct;
int calculate_stack = 0;
vm->set_root_stack(reinterpret_cast<uintptr_t>(&calculate_stack), THREAD_STACK_SIZE);

GCTokenImpl gct;
NativeMethod::init_thread(state);

// Lock the thread object and unlock it at __run__ in the ruby land.
vm->thread->alive(state, cTrue);
Expand Down Expand Up @@ -300,25 +293,57 @@ namespace rubinius {
(*i)->unlock_for_terminate(state, gct, 0);
}

vm->thread->init_lock_.lock();
vm->thread->stopped();

NativeMethod::cleanup_thread(state);

vm->thread->stopped();
vm->thread->init_lock_.unlock();
if(cDebugThreading) {
utilities::logger::debug("Thread: exit thread: id: %d", vm->thread_id());
}
}

void* Thread::internal_thread(void* ptr) {
VM* vm = reinterpret_cast<VM*>(ptr);

vm->shared.clear_critical(state);
SharedState& shared = vm->shared;
State state_obj(vm), *state = &state_obj;

execute_thread(state, vm);

shared.gc_independent();

return 0;
}

void* Thread::ruby_thread(void* ptr) {
VM* vm = reinterpret_cast<VM*>(ptr);

SharedState& shared = vm->shared;
State state_obj(vm), *state = &state_obj;

std::string thread_name;

{
std::ostringstream tn;
tn << "rbx.ruby." << vm->thread_id();
VM::set_current(vm, tn.str());
thread_name = tn.str();
}

RUBINIUS_THREAD_START(const_cast<RBX_DTRACE_CHAR_P>(thread_name.c_str()),
vm->thread_id(), 0);

execute_thread(state, vm);

vm->thread->vm_ = NULL;
VM::discard(state, vm);

if(cDebugThreading) {
std::cerr << "[LOCK thread " << vm->thread_id() << " exited]\n";
}
shared.clear_critical(state);
shared.gc_independent();

RUBINIUS_THREAD_STOP(const_cast<RBX_DTRACE_CHAR_P>(thread_name.c_str()),
vm->thread_id(), 0);
shared.gc_independent();

return 0;
}

Expand All @@ -334,13 +359,12 @@ namespace rubinius {
pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);
pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);

int error = start_new_thread(state, attrs);

if(error) {
if(int error = start_thread(state, attrs)) {
char buf[RBX_STRERROR_BUFSIZE];
char* err = RBX_STRERROR(error, buf, RBX_STRERROR_BUFSIZE);
Exception::thread_error(state, err);
}

return cNil;
}

Expand All @@ -349,7 +373,7 @@ namespace rubinius {
pthread_attr_init(&attrs);
pthread_attr_setstacksize(&attrs, THREAD_STACK_SIZE);

return start_new_thread(state, attrs);
return start_thread(state, attrs);
}

Object* Thread::pass(STATE, CallFrame* calling_environment) {
Expand Down Expand Up @@ -461,7 +485,6 @@ namespace rubinius {

void Thread::stopped() {
alive_ = cFalse;
vm_ = NULL;
}

void Thread::init_lock() {
Expand Down
18 changes: 9 additions & 9 deletions vm/builtin/thread.hpp
Expand Up @@ -51,10 +51,8 @@ namespace rubinius {

utilities::thread::SpinLock init_lock_;

/// Whether this is an internal VM thread that should
/// not be exposed in Ruby land but does need to be a
/// managed thread.
bool system_thread_;
/// An internal thread, for example, the GC finalizer thread.
bool internal_thread_;

/// The VM state for this thread and this thread alone
VM* vm_;
Expand Down Expand Up @@ -98,8 +96,8 @@ namespace rubinius {
return vm_;
}

bool system_thread() const {
return system_thread_;
bool internal_thread() const {
return internal_thread_;
}

public:
Expand Down Expand Up @@ -291,10 +289,12 @@ namespace rubinius {
* @see Thread::allocate().
*/
static Thread* create(STATE, VM* target, Object* self, Run runner,
bool system_thread = false);
bool internal_thread = false);

int start_new_thread(STATE, const pthread_attr_t &attrs);
static void* in_new_thread(void*);
int start_thread(STATE, const pthread_attr_t &attrs);
static void execute_thread(STATE, VM* vm);
static void* internal_thread(void*);
static void* ruby_thread(void*);

public: /* TypeInfo */

Expand Down
2 changes: 2 additions & 0 deletions vm/console.cpp
Expand Up @@ -223,6 +223,7 @@ namespace rubinius {
pthread_join(os, &return_value);
}

VM::discard(state, request_vm_);
request_vm_ = NULL;
}

Expand All @@ -238,6 +239,7 @@ namespace rubinius {
pthread_join(os, &return_value);
}

VM::discard(state, response_vm_);
response_vm_ = NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/environment.cpp
Expand Up @@ -171,6 +171,7 @@ namespace rubinius {

void Environment::start_finalizer(STATE) {
finalizer_handler_ = new FinalizerHandler(state);
finalizer_handler_->start_thread(state);
}

void Environment::start_logging(STATE) {
Expand Down Expand Up @@ -809,7 +810,6 @@ namespace rubinius {
runtime.c_str(), runtime.size()));

load_kernel(runtime);
shared->finalizer_handler()->start_thread(state);

run_file(runtime + "/loader.rbc");

Expand Down

0 comments on commit 34e71c6

Please sign in to comment.