Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9e28da4ab417
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 85cd7c9c26ec
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on Mar 20, 2016

  1. Fixed updating PID for logger.

    brixen committed Mar 20, 2016
    Copy the full SHA
    e5573c3 View commit details
  2. Fixed setting Thread management state.

    Before returning from Thread.new (or any similar methods), we ensure that
    all the state for tracking Thread instances and any related state are
    completely initialized. This prevents a case where the process calls fork()
    immediately after creating a Thread and the Thread's state is only partially
    initialized before the fork() call completes.
    brixen committed Mar 20, 2016
    Copy the full SHA
    4000cca View commit details
  3. Copy the full SHA
    85cd7c9 View commit details
Showing with 48 additions and 45 deletions.
  1. +4 −3 machine/builtin/thread.cpp
  2. +1 −0 machine/internal_threads.cpp
  3. +3 −16 machine/thread_nexus.cpp
  4. +0 −2 machine/thread_nexus.hpp
  5. +26 −10 machine/util/logger.cpp
  6. +11 −1 machine/util/logger.hpp
  7. +3 −4 machine/vm.cpp
  8. +0 −9 machine/vm.hpp
7 changes: 4 additions & 3 deletions machine/builtin/thread.cpp
Original file line number Diff line number Diff line change
@@ -81,8 +81,9 @@ namespace rubinius {
}

Thread* Thread::create(STATE, Object* self, ThreadFunction function) {
return Thread::create(state, self,
state->shared().thread_nexus()->new_vm_solo(&state->shared()), function);
VM* vm = state->shared().thread_nexus()->new_vm(&state->shared());

return Thread::create(state, self, vm, function);
}

Thread* Thread::create(STATE, Object* self, VM* vm, ThreadFunction function) {
@@ -347,7 +348,6 @@ namespace rubinius {
State state_obj(vm), *state = &state_obj;

vm->set_current_thread();
state->shared().thread_nexus()->add_vm(vm);

RUBINIUS_THREAD_START(
const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 0);
@@ -388,6 +388,7 @@ namespace rubinius {

utilities::logger::write("exit thread: %s", vm->name().c_str());

vm->set_call_frame(0);
vm->become_unmanaged();

if(vm->main_thread_p() || (!value && vm->thread_state()->raise_reason() == cExit)) {
1 change: 1 addition & 0 deletions machine/internal_threads.cpp
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ namespace rubinius {
RUBINIUS_THREAD_STOP(
const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

vm->set_call_frame(0);
vm->become_unmanaged();

vm->set_zombie(state);
19 changes: 3 additions & 16 deletions machine/thread_nexus.cpp
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ namespace rubinius {
return (vm->thread_phase() & cYielding) == cYielding;
}

VM* ThreadNexus::new_vm_solo(SharedState* shared, const char* name) {
VM* ThreadNexus::new_vm(SharedState* shared, const char* name) {
utilities::thread::SpinLock::LockGuard guard(threads_lock_);

uint32_t max_id = thread_ids_;
@@ -42,26 +42,13 @@ namespace rubinius {
rubinius::bug("exceeded maximum number of threads");
}

return new VM(id, *shared, name);
}

VM* ThreadNexus::new_vm(SharedState* shared, const char* name) {
VM* vm = new_vm_solo(shared, name);
VM* vm = new VM(id, *shared, name);

add_vm(vm);
threads_.push_back(vm);

return vm;
}

void ThreadNexus::add_vm(VM* vm) {
utilities::thread::SpinLock::LockGuard guard(threads_lock_);

if(vm->tracked_p()) return;

vm->set_tracked();
threads_.push_back(vm);
}

void ThreadNexus::delete_vm(VM* vm) {
utilities::thread::SpinLock::LockGuard guard(threads_lock_);

2 changes: 0 additions & 2 deletions machine/thread_nexus.hpp
Original file line number Diff line number Diff line change
@@ -94,8 +94,6 @@ namespace rubinius {
void detect_halt_deadlock(uint64_t nanoseconds, VM* vm);

VM* new_vm(SharedState* shared, const char* name = NULL);
VM* new_vm_solo(SharedState* shared, const char* name = NULL);
void add_vm(VM* vm);
void delete_vm(VM* vm);

void after_fork_child(STATE);
36 changes: 26 additions & 10 deletions machine/util/logger.cpp
Original file line number Diff line number Diff line change
@@ -48,6 +48,9 @@ namespace rubinius {
delete logger_;
}

void set_label() {
if(logger_) logger_->set_label();
}
#define LOGGER_MSG_SIZE 1024

static int append_newline(char* message) {
@@ -213,6 +216,10 @@ namespace rubinius {
closelog();
}

void Syslog::set_label() {
if(logger_) logger_->set_label();
}

// Syslog doesn't give us the ability to write a message to the log
// independent of a priority. Bummer.
void Syslog::write(const char* message, int size) {
@@ -242,15 +249,20 @@ namespace rubinius {

ConsoleLogger::ConsoleLogger(const char* identifier)
: Logger()
, identifier_(identifier)
{
std::ostringstream str;
str << identifier << "[" << getpid() << "]";
set_label();
}

identifier_ = std::string(str.str());
void ConsoleLogger::set_label() {
std::ostringstream label;
label << identifier_ << "[" << getpid() << "]";

label_ = std::string(label.str());
}

void ConsoleLogger::write_log(const char* level, const char* message, int size) {
fprintf(stderr, "%s %s %s %s", timestamp(), identifier_.c_str(), level, message);
fprintf(stderr, "%s %s %s %s", timestamp(), label_.c_str(), level, message);
}

#define LOGGER_LEVEL_FATAL "<Fatal>"
@@ -260,7 +272,7 @@ namespace rubinius {
#define LOGGER_LEVEL_DEBUG "<Debug>"

void ConsoleLogger::write(const char* message, int size) {
fprintf(stderr, "%s %s %s", timestamp(), identifier_.c_str(), message);
fprintf(stderr, "%s %s %s", timestamp(), label_.c_str(), message);
}

void ConsoleLogger::fatal(const char* message, int size) {
@@ -293,10 +305,7 @@ namespace rubinius {
: Logger()
, path_(path)
{
std::ostringstream label;
label << " [" << getpid() << "] ";

identifier_ = label.str();
set_label();

limit_ = va_arg(varargs, long);
archives_ = va_arg(varargs, long);
@@ -314,6 +323,13 @@ namespace rubinius {
cleanup();
}

void FileLogger::set_label() {
std::ostringstream label;
label << " [" << getpid() << "] ";

label_ = label.str();
}

void FileLogger::cleanup() {
::close(logger_fd_);
logger_fd_ = -1;
@@ -388,7 +404,7 @@ namespace rubinius {

const char* time = timestamp();
write_status_ = ::write(logger_fd_, time, strlen(time));
write_status_ = ::write(logger_fd_, identifier_.c_str(), identifier_.size());
write_status_ = ::write(logger_fd_, label_.c_str(), label_.size());
if(level) {
write_status_ = ::write(logger_fd_, level, strlen(level));
write_status_ = ::write(logger_fd_, " ", 1);
12 changes: 11 additions & 1 deletion machine/util/logger.hpp
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ namespace rubinius {
void info(const char* message, ...);
void debug(const char* message, ...);

void set_label();
void set_loglevel(logger_level level);

class Logger {
@@ -51,6 +52,8 @@ namespace rubinius {
virtual void info(const char* message, int size) = 0;
virtual void debug(const char* message, int size) = 0;

virtual void set_label() = 0;

char* timestamp();
};

@@ -66,10 +69,13 @@ namespace rubinius {
void warn(const char* message, int size);
void info(const char* message, int size);
void debug(const char* message, int size);

void set_label();
};

class ConsoleLogger : public Logger {
std::string identifier_;
std::string label_;

void write_log(const char* level, const char* message, int size);

@@ -83,11 +89,13 @@ namespace rubinius {
void warn(const char* message, int size);
void info(const char* message, int size);
void debug(const char* message, int size);

void set_label();
};

class FileLogger : public Logger {
std::string path_;
std::string identifier_;
std::string label_;
int logger_fd_;
long limit_;
long archives_;
@@ -109,6 +117,8 @@ namespace rubinius {
void warn(const char* message, int size);
void info(const char* message, int size);
void debug(const char* message, int size);

void set_label();
};
}
}
7 changes: 3 additions & 4 deletions machine/vm.cpp
Original file line number Diff line number Diff line change
@@ -82,8 +82,7 @@ namespace rubinius {
, constant_missing_reason_(vFound)
, zombie_(false)
, main_thread_(false)
, tracked_(false)
, thread_phase_(ThreadNexus::cManaged)
, thread_phase_(ThreadNexus::cUnmanaged)
, shared(shared)
, waiting_channel_(this, nil<Channel>())
, interrupted_exception_(this, nil<Exception>())
@@ -111,8 +110,6 @@ namespace rubinius {
}

void VM::discard(STATE, VM* vm) {
vm->call_frame_ = 0;

state->vm()->metrics().system.threads_destroyed++;

delete vm;
@@ -288,6 +285,8 @@ namespace rubinius {
}

void VM::after_fork_child(STATE) {
utilities::logger::set_label();

thread_nexus_->after_fork_child(state);

interrupt_lock_.init();
9 changes: 0 additions & 9 deletions machine/vm.hpp
Original file line number Diff line number Diff line change
@@ -115,7 +115,6 @@ namespace rubinius {
bool tooling_;
bool allocation_tracking_;
bool main_thread_;
bool tracked_;

ThreadNexus::Phase thread_phase_;

@@ -159,14 +158,6 @@ namespace rubinius {
return thread_phase_;
}

void set_tracked(bool tracked = true) {
tracked_ = tracked;
}

bool tracked_p() {
return tracked_;
}

ThreadNexus* thread_nexus() {
return thread_nexus_;
}