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
brixen committed Jun 6, 2016
2 parents b579c01 + dadcfa7 commit 08c6a86
Showing 9 changed files with 103 additions and 155 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
language: cpp
cache:
ccache: true
directories:
- $HOME/vendor/bundle
- $HOME/.rvm/archives/
sudo: required
dist: trusty
compiler:
- clang
os:
- linux
- osx
ruby: 2.2.0
before_install:
- rvm install 2.2.0 && rvm use 2.2.0
- echo $LANG
- echo $LC_ALL
- if [ $TRAVIS_OS_NAME == linux ]; then ./scripts/llvm.sh; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install llvm; fi
- if [ $TRAVIS_OS_NAME == linux ]; then ccache -s; export CC="ccache clang -Qunused-arguments -fcolor-diagnostics"; export CXX="ccache clang++ -Qunused-arguments -fcolor-diagnostics"; ./scripts/llvm.sh; fi
- if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install llvm ccache; ccache -s; export CC="ccache clang -Qunused-arguments -fcolor-diagnostics"; export CXX="ccache clang++ -Qunused-arguments -fcolor-diagnostics"; export PATH="/usr/local/opt/ccache/libexec:$PATH"; fi
- gem update --system
- gem --version
before_script:
- travis_retry bundle
- travis_retry bundle -j 2
- if [ $TRAVIS_OS_NAME == linux ]; then travis_retry ./configure --llvm-config=llvm-config-3.6; fi
- if [ $TRAVIS_OS_NAME == osx ]; then travis_retry ./configure; fi
script: rake ci
after_success:
- if [ $TRAVIS_OS_NAME == linux ]; then ./scripts/build_support.sh archive_core; fi
- if [ $TRAVIS_BRANCH == $TRAVIS_TAG ]; then ./scripts/deploy.sh release github website triggers; fi
- ccache -s
branches:
only:
- master
@@ -41,6 +47,7 @@ notifications:
on_start: always
env:
global:
- CCACHE_CPP2=yes
- LANG="en_US.UTF-8"
- secure: olbok/GN6rOYvPnHBYWGz7giCoCdLFpT/7WSBHukYO3E0uNeqAUOOgW2BFOwCVWdSEJ/iTvJXZQ4qVZHX+6jRfvILZeGv+D2P93VdD8UFQRoTOfFC7esAo525s9fuKm9ehUGWZxlzGOBHHckky1jn6pEf8mlXAVM5e76dlH0fck=
- secure: aqG9eB/PrzQ7XJQN6YX/00sNVvwSB77saxXQzguL2WFjAXB74h6168Hzq+awHtNX/vfOb6ta7fpWLHrA0D+gmZnvTR29VlP6nd0vs1tkdX1/jWbiBHjamRffp+NWVdKbJKYn5iLOGXcuUMOzY/opLKOdvxKZfkxGMxR2tTNLZUE=
12 changes: 6 additions & 6 deletions machine/builtin/data.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "memory.hpp"
#include "object_utils.hpp"
#include "logger.hpp"
#include "memory.hpp"
#include "on_stack.hpp"


#include "builtin/data.hpp"
#include "builtin/class.hpp"

@@ -108,18 +110,17 @@ namespace rubinius {
capi::Handle* handle = data->handle(state);

if(!handle->valid_p()) {
std::cerr << "Data::finalize: object has invalid handle!" << std::endl;
logger::fatal("finalizer: Data object has invalid handle");
return;
}

if(handle->object() != data) {
std::cerr << "Data::finalize: handle does not reference object!" << std::endl;
logger::fatal("finalizer: Data object handle does not reference the object");
return;
}

if(data->freed_p()) {
// TODO: Fix the issue of finalizer ordering.
// std::cerr << "Data::finalize called for already freed object" << std::endl;
logger::fatal("finalizer: Data finalize called for already freed object");
return;
}
data->set_freed();
@@ -155,8 +156,7 @@ namespace rubinius {
}

if(data->freed_p()) {
// TODO: Fix the issue of finalizer ordering.
// std::cerr << "Data::Info::mark called for already freed object" << std::endl;
logger::fatal("finalizer: Data mark called for already freed object");
return;
}

7 changes: 6 additions & 1 deletion machine/builtin/fiber.cpp
Original file line number Diff line number Diff line change
@@ -288,7 +288,12 @@ namespace rubinius {

void Fiber::finalize(STATE, Fiber* fib) {
#ifdef RBX_FIBER_ENABLED
if(!fib->data()) return;
if(!fib->data()) {
logger::fatal("finalizer: Fiber finalize called on instance with NULL data");
return;
}

logger::fatal("finalizer: Fiber finalize");
fib->data()->orphan(state);

delete fib->data();
5 changes: 3 additions & 2 deletions machine/builtin/system.cpp
Original file line number Diff line number Diff line change
@@ -396,10 +396,10 @@ namespace rubinius {

int pid = ::fork();

logger::reset_lock();
state->vm()->thread_nexus()->unlock();

if(pid == 0) {
logger::reset_lock();
state->vm()->after_fork_child(state);
} else if(pid > 0) {
state->shared().machine_threads()->after_fork_exec_parent(state);
@@ -840,7 +840,6 @@ namespace rubinius {

int pid = ::fork();

logger::reset_lock();
state->vm()->thread_nexus()->unlock();

if(pid > 0) {
@@ -858,6 +857,8 @@ namespace rubinius {
}
} else if(pid == 0) {
// We're in the child...
logger::reset_lock();

state->vm()->after_fork_child(state);

state->vm()->thread->init_lock();
9 changes: 3 additions & 6 deletions machine/environment.cpp
Original file line number Diff line number Diff line change
@@ -186,18 +186,15 @@ namespace rubinius {
}

if(!config.system_log.value.compare("syslog")) {
logger::open(fork_exec_lock_,
logger::eSyslog, RBX_PROGRAM_NAME, level);
logger::open(logger::eSyslog, RBX_PROGRAM_NAME, level);
} else if(!config.system_log.value.compare("console")) {
logger::open(fork_exec_lock_,
logger::eConsoleLogger, RBX_PROGRAM_NAME, level);
logger::open(logger::eConsoleLogger, RBX_PROGRAM_NAME, level);
} else {
expand_config_value(config.system_log.value, "$TMPDIR", config.system_tmp);
expand_config_value(config.system_log.value, "$PROGRAM_NAME", RBX_PROGRAM_NAME);
expand_config_value(config.system_log.value, "$USER", shared->username.c_str());

logger::open(fork_exec_lock_,
logger::eFileLogger,
logger::open(logger::eFileLogger,
config.system_log.value.c_str(), level,
config.system_log_limit.value,
config.system_log_archives.value,
2 changes: 1 addition & 1 deletion machine/fiber_data.cpp
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ namespace rubinius {
}

void FiberData::copy_to_heap(STATE) {
assert(status_ != eDead);
if(status_ == eDead) return;
assert(stack_);

heap_size_ = (uintptr_t)stack_->top_address() - (uintptr_t)stack_bottom();
133 changes: 36 additions & 97 deletions machine/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "util/file.hpp"
#include "util/thread.hpp"

#include "logger.hpp"
#include "vm.hpp"
#include "state.hpp"
#include "spinlock.hpp"
#include "thread_phase.hpp"

#include <stdarg.h>
@@ -25,22 +24,21 @@ namespace rubinius {
namespace logger {
static Logger* logger_ = 0;
static logger_level loglevel_ = eWarn;
static locks::spinlock_mutex logger_lock_;

void open(utilities::thread::SpinLock& lock, logger_type type,
const char* identifier, logger_level level, ...)
{
void open(logger_type type, const char* identifier, logger_level level, ...) {
va_list varargs;

switch(type) {
case eSyslog:
logger_ = new Syslog(lock, identifier);
logger_ = new Syslog(identifier);
break;
case eConsoleLogger:
logger_ = new ConsoleLogger(lock, identifier);
logger_ = new ConsoleLogger(identifier);
break;
case eFileLogger:
va_start(varargs, level);
logger_ = new FileLogger(lock, identifier, varargs);
logger_ = new FileLogger(identifier, varargs);
va_end(varargs);
break;
}
@@ -57,7 +55,7 @@ namespace rubinius {
}

void reset_lock() {
if(logger_) logger_->reset_lock();
logger_lock_.unlock();
}

#define LOGGER_MSG_SIZE 1024
@@ -83,104 +81,50 @@ namespace rubinius {
}

void write(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
write(&state, message, varargs);
va_end(varargs);
}

void fatal(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
fatal(&state, message, varargs);
va_end(varargs);
}

void error(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
error(&state, message, varargs);
va_end(varargs);
}

void warn(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
warn(&state, message, varargs);
va_end(varargs);
}

void info(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
info(&state, message, varargs);
va_end(varargs);
}

void debug(const char* message, ...) {
State state(VM::current());
va_list varargs;

va_start(varargs, message);
debug(&state, message, varargs);
va_end(varargs);
}

void write(STATE, const char* message, ...) {
va_list args;
va_start(args, message);
write(state, message, args);
write(message, args);
va_end(args);
}

void fatal(STATE, const char* message, ...) {
void fatal(const char* message, ...) {
va_list args;
va_start(args, message);
fatal(state, message, args);
fatal(message, args);
va_end(args);
}

void error(STATE, const char* message, ...) {
void error(const char* message, ...) {
va_list args;
va_start(args, message);
error(state, message, args);
error(message, args);
va_end(args);
}

void warn(STATE, const char* message, ...) {
void warn(const char* message, ...) {
va_list args;
va_start(args, message);
warn(state, message, args);
warn(message, args);
va_end(args);
}

void info(STATE, const char* message, ...) {
void info(const char* message, ...) {
va_list args;
va_start(args, message);
info(state, message, args);
info(message, args);
va_end(args);
}

void debug(STATE, const char* message, ...) {
void debug(const char* message, ...) {
va_list args;
va_start(args, message);
debug(state, message, args);
debug(message, args);
va_end(args);
}

void write(STATE, const char* message, va_list args) {
void write(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

char buf[LOGGER_MSG_SIZE];

@@ -190,9 +134,9 @@ namespace rubinius {
}
}

void fatal(STATE, const char* message, va_list args) {
void fatal(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

if(loglevel_ < eFatal) return;

@@ -204,9 +148,9 @@ namespace rubinius {
}
}

void error(STATE, const char* message, va_list args) {
void error(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

if(loglevel_ < eError) return;

@@ -218,9 +162,9 @@ namespace rubinius {
}
}

void warn(STATE, const char* message, va_list args) {
void warn(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

if(loglevel_ < eWarn) return;

@@ -232,9 +176,9 @@ namespace rubinius {
}
}

void info(STATE, const char* message, va_list args) {
void info(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

if(loglevel_ < eInfo) return;

@@ -246,9 +190,9 @@ namespace rubinius {
}
}

void debug(STATE, const char* message, va_list args) {
void debug(const char* message, va_list args) {
if(logger_) {
SpinLockWaiting guard(state, logger_->lock());
std::lock_guard<locks::spinlock_mutex> guard(logger_lock_);

if(loglevel_ < eDebug) return;

@@ -260,10 +204,6 @@ namespace rubinius {
}
}

void Logger::reset_lock() {
lock_.init();
}

char* Logger::timestamp() {
time_t clock;

@@ -273,8 +213,8 @@ namespace rubinius {
return formatted_time_;
}

Syslog::Syslog(utilities::thread::SpinLock& lock, const char* identifier)
: Logger(lock)
Syslog::Syslog(const char* identifier)
: Logger()
{
openlog(identifier, LOG_CONS | LOG_PID, LOG_LOCAL7);

@@ -336,8 +276,8 @@ namespace rubinius {
syslog(LOG_DEBUG, "%s", message);
}

ConsoleLogger::ConsoleLogger(utilities::thread::SpinLock& lock, const char* identifier)
: Logger(lock)
ConsoleLogger::ConsoleLogger(const char* identifier)
: Logger()
, identifier_(identifier)
{
set_label();
@@ -390,9 +330,8 @@ namespace rubinius {
#define LOGGER_FROM_FLAGS (O_RDONLY | O_CLOEXEC)
#define LOGGER_TO_FLAGS (O_CREAT | O_TRUNC | O_APPEND | O_WRONLY | O_CLOEXEC)

FileLogger::FileLogger(utilities::thread::SpinLock& lock,
const char* path, va_list varargs)
: Logger(lock)
FileLogger::FileLogger(const char* path, va_list varargs)
: Logger()
, path_(path)
{
set_label();
48 changes: 10 additions & 38 deletions machine/logger.hpp
Original file line number Diff line number Diff line change
@@ -7,12 +7,6 @@
#include <stdarg.h>

namespace rubinius {
namespace utilities {
namespace thread {
class SpinLock;
}
}

namespace logger {
enum logger_type {
eSyslog,
@@ -29,52 +23,35 @@ namespace rubinius {
};


void open(utilities::thread::SpinLock& lock, logger_type type,
const char* identifier, logger_level level=eWarn, ...);
void open(logger_type type, const char* identifier, logger_level level=eWarn, ...);
void close();

/* The API without passing STATE as the first argument must retrieve the
* current thread's VM* from a thread local variable.
*/
void write(const char* message, ...);
void fatal(const char* message, ...);
void error(const char* message, ...);
void warn(const char* message, ...);
void info(const char* message, ...);
void debug(const char* message, ...);

void write(STATE, const char* message, ...);
void fatal(STATE, const char* message, ...);
void error(STATE, const char* message, ...);
void warn(STATE, const char* message, ...);
void info(STATE, const char* message, ...);
void debug(STATE, const char* message, ...);

void write(STATE, const char* message, va_list args);
void fatal(STATE, const char* message, va_list args);
void error(STATE, const char* message, va_list args);
void warn(STATE, const char* message, va_list args);
void info(STATE, const char* message, va_list args);
void debug(STATE, const char* message, va_list args);
void write(const char* message, va_list args);
void fatal(const char* message, va_list args);
void error(const char* message, va_list args);
void warn(const char* message, va_list args);
void info(const char* message, va_list args);
void debug(const char* message, va_list args);

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

void reset_lock();

class Logger {
utilities::thread::SpinLock& lock_;

#define LOGGER_TIME_SIZE 16

char formatted_time_[LOGGER_TIME_SIZE];

public:

Logger(utilities::thread::SpinLock& lock)
: lock_(lock)
{ }

virtual ~Logger() { }

virtual void write(const char* message, int size) = 0;
@@ -86,18 +63,13 @@ namespace rubinius {

virtual void set_label() = 0;

void reset_lock();
char* timestamp();

utilities::thread::SpinLock& lock() {
return lock_;
}
};

class Syslog : public Logger {
public:

Syslog(utilities::thread::SpinLock& lock, const char* identifier);
Syslog(const char* identifier);
~Syslog();

void write(const char* message, int size);
@@ -118,7 +90,7 @@ namespace rubinius {

public:

ConsoleLogger(utilities::thread::SpinLock& lock, const char* identifier);
ConsoleLogger(const char* identifier);

void write(const char* message, int size);
void fatal(const char* message, int size);
@@ -145,7 +117,7 @@ namespace rubinius {

public:

FileLogger(utilities::thread::SpinLock& lock, const char* path, va_list varargs);
FileLogger(const char* path, va_list varargs);
~FileLogger();

void write(const char* message, int size);
27 changes: 27 additions & 0 deletions machine/spinlock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <atomic>

namespace rubinius {
namespace locks {
// Adapted from: Anthony Williams. “C++ Concurrency In Action.”

class spinlock_mutex {
std::atomic_flag flag;
public:
spinlock_mutex()
: flag()
{
flag.clear();
}

void lock() {
while(flag.test_and_set(std::memory_order_seq_cst)) {
; // spin
}
}

void unlock() {
flag.clear(std::memory_order_seq_cst);
}
};
}
}

0 comments on commit 08c6a86

Please sign in to comment.