Commit 6c6a998e authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

* Fix build errors on FreeBSD 8.2

* Fix Crankshaft on FreeBSD.
* Partially fix profiling on FreeBSD.
* Remove bash-isms from tick processor script.
Review URL: http://codereview.chromium.org/6673045

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7200 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ac1eb2d9
...@@ -174,6 +174,7 @@ LIBRARY_FLAGS = { ...@@ -174,6 +174,7 @@ LIBRARY_FLAGS = {
'CPPPATH' : ['/usr/local/include'], 'CPPPATH' : ['/usr/local/include'],
'LIBPATH' : ['/usr/local/lib'], 'LIBPATH' : ['/usr/local/lib'],
'CCFLAGS': ['-ansi'], 'CCFLAGS': ['-ansi'],
'LIBS': ['execinfo']
}, },
'os:openbsd': { 'os:openbsd': {
'CPPPATH' : ['/usr/local/include'], 'CPPPATH' : ['/usr/local/include'],
......
...@@ -375,8 +375,10 @@ static Handle<Value> GetStdout(int child_fd, ...@@ -375,8 +375,10 @@ static Handle<Value> GetStdout(int child_fd,
// a parent process hangs on waiting while a child process is already a zombie. // a parent process hangs on waiting while a child process is already a zombie.
// See http://code.google.com/p/v8/issues/detail?id=401. // See http://code.google.com/p/v8/issues/detail?id=401.
#if defined(WNOWAIT) && !defined(ANDROID) && !defined(__APPLE__) #if defined(WNOWAIT) && !defined(ANDROID) && !defined(__APPLE__)
#if !defined(__FreeBSD__)
#define HAS_WAITID 1 #define HAS_WAITID 1
#endif #endif
#endif
// Get exit status of child. // Get exit status of child.
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <sys/stat.h> // open #include <sys/stat.h> // open
#include <sys/fcntl.h> // open #include <sys/fcntl.h> // open
#include <unistd.h> // getpagesize #include <unistd.h> // getpagesize
// If you don't have execinfo.h then you need devel/libexecinfo from ports.
#include <execinfo.h> // backtrace, backtrace_symbols #include <execinfo.h> // backtrace, backtrace_symbols
#include <strings.h> // index #include <strings.h> // index
#include <errno.h> #include <errno.h>
...@@ -526,6 +527,16 @@ class FreeBSDMutex : public Mutex { ...@@ -526,6 +527,16 @@ class FreeBSDMutex : public Mutex {
return result; return result;
} }
virtual bool TryLock() {
int result = pthread_mutex_trylock(&mutex_);
// Return false if the lock is busy and locking failed.
if (result == EBUSY) {
return false;
}
ASSERT(result == 0); // Verify no other errors.
return true;
}
private: private:
pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms. pthread_mutex_t mutex_; // Pthread mutex for POSIX platforms.
}; };
...@@ -595,52 +606,116 @@ Semaphore* OS::CreateSemaphore(int count) { ...@@ -595,52 +606,116 @@ Semaphore* OS::CreateSemaphore(int count) {
#ifdef ENABLE_LOGGING_AND_PROFILING #ifdef ENABLE_LOGGING_AND_PROFILING
static Sampler* active_sampler_ = NULL; static Sampler* active_sampler_ = NULL;
static pthread_t vm_tid_ = NULL;
static pthread_t GetThreadID() {
pthread_t thread_id = pthread_self();
return thread_id;
}
class Sampler::PlatformData : public Malloced {
public:
enum SleepInterval {
FULL_INTERVAL,
HALF_INTERVAL
};
explicit PlatformData(Sampler* sampler)
: sampler_(sampler),
signal_handler_installed_(false),
signal_sender_launched_(false) {
}
void SignalSender() {
while (sampler_->IsActive()) {
if (rate_limiter_.SuspendIfNecessary()) continue;
if (sampler_->IsProfiling() && RuntimeProfiler::IsEnabled()) {
Sleep(FULL_INTERVAL);
RuntimeProfiler::NotifyTick();
} else {
if (RuntimeProfiler::IsEnabled()) RuntimeProfiler::NotifyTick();
Sleep(FULL_INTERVAL);
}
}
}
void Sleep(SleepInterval full_or_half) {
// Convert ms to us and subtract 100 us to compensate delays
// occuring during signal delivery.
useconds_t interval = sampler_->interval_ * 1000 - 100;
if (full_or_half == HALF_INTERVAL) interval /= 2;
int result = usleep(interval);
#ifdef DEBUG
if (result != 0 && errno != EINTR) {
fprintf(stderr,
"SignalSender usleep error; interval = %u, errno = %d\n",
interval,
errno);
ASSERT(result == 0 || errno == EINTR);
}
#endif
USE(result);
}
Sampler* sampler_;
bool signal_handler_installed_;
struct sigaction old_signal_handler_;
struct itimerval old_timer_value_;
bool signal_sender_launched_;
pthread_t signal_sender_thread_;
RuntimeProfilerRateLimiter rate_limiter_;
};
static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) {
USE(info); USE(info);
if (signal != SIGPROF) return; if (signal != SIGPROF) return;
if (active_sampler_ == NULL) return; if (active_sampler_ == NULL) return;
if (!active_sampler_->IsActive()) {
// Restore old signal handler
Sampler::PlatformData* data = active_sampler_->data();
if (data->signal_handler_installed_) {
sigaction(SIGPROF, &data->old_signal_handler_, 0);
data->signal_handler_installed_ = false;
}
return;
}
TickSample sample; if (vm_tid_ != GetThreadID()) return;
// We always sample the VM state. TickSample sample_obj;
sample.state = VMState::current_state(); TickSample* sample = CpuProfiler::TickSampleEvent();
if (sample == NULL) sample = &sample_obj;
// If profiling, we extract the current pc and sp. // Extracting the sample from the context is extremely machine dependent.
if (active_sampler_->IsProfiling()) { ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
// Extracting the sample from the context is extremely machine dependent. mcontext_t& mcontext = ucontext->uc_mcontext;
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
mcontext_t& mcontext = ucontext->uc_mcontext;
#if V8_HOST_ARCH_IA32 #if V8_HOST_ARCH_IA32
sample.pc = reinterpret_cast<Address>(mcontext.mc_eip); sample->pc = reinterpret_cast<Address>(mcontext.mc_eip);
sample.sp = reinterpret_cast<Address>(mcontext.mc_esp); sample->sp = reinterpret_cast<Address>(mcontext.mc_esp);
sample.fp = reinterpret_cast<Address>(mcontext.mc_ebp); sample->fp = reinterpret_cast<Address>(mcontext.mc_ebp);
#elif V8_HOST_ARCH_X64 #elif V8_HOST_ARCH_X64
sample.pc = reinterpret_cast<Address>(mcontext.mc_rip); sample->pc = reinterpret_cast<Address>(mcontext.mc_rip);
sample.sp = reinterpret_cast<Address>(mcontext.mc_rsp); sample->sp = reinterpret_cast<Address>(mcontext.mc_rsp);
sample.fp = reinterpret_cast<Address>(mcontext.mc_rbp); sample->fp = reinterpret_cast<Address>(mcontext.mc_rbp);
#elif V8_HOST_ARCH_ARM #elif V8_HOST_ARCH_ARM
sample.pc = reinterpret_cast<Address>(mcontext.mc_r15); sample->pc = reinterpret_cast<Address>(mcontext.mc_r15);
sample.sp = reinterpret_cast<Address>(mcontext.mc_r13); sample->sp = reinterpret_cast<Address>(mcontext.mc_r13);
sample.fp = reinterpret_cast<Address>(mcontext.mc_r11); sample->fp = reinterpret_cast<Address>(mcontext.mc_r11);
#endif #endif
active_sampler_->SampleStack(&sample); active_sampler_->SampleStack(sample);
} active_sampler_->Tick(sample);
active_sampler_->Tick(&sample);
} }
class Sampler::PlatformData : public Malloced { static void* SenderEntry(void* arg) {
public: Sampler::PlatformData* data =
PlatformData() { reinterpret_cast<Sampler::PlatformData*>(arg);
signal_handler_installed_ = false; data->SignalSender();
} return 0;
}
bool signal_handler_installed_;
struct sigaction old_signal_handler_;
struct itimerval old_timer_value_;
};
Sampler::Sampler(int interval) Sampler::Sampler(int interval)
...@@ -648,7 +723,7 @@ Sampler::Sampler(int interval) ...@@ -648,7 +723,7 @@ Sampler::Sampler(int interval)
profiling_(false), profiling_(false),
active_(false), active_(false),
samples_taken_(0) { samples_taken_(0) {
data_ = new PlatformData(); data_ = new PlatformData(this);
} }
...@@ -660,7 +735,8 @@ Sampler::~Sampler() { ...@@ -660,7 +735,8 @@ Sampler::~Sampler() {
void Sampler::Start() { void Sampler::Start() {
// There can only be one active sampler at the time on POSIX // There can only be one active sampler at the time on POSIX
// platforms. // platforms.
if (active_sampler_ != NULL) return; ASSERT(!IsActive());
vm_tid_ = GetThreadID();
// Request profiling signals. // Request profiling signals.
struct sigaction sa; struct sigaction sa;
...@@ -680,21 +756,29 @@ void Sampler::Start() { ...@@ -680,21 +756,29 @@ void Sampler::Start() {
// Set this sampler as the active sampler. // Set this sampler as the active sampler.
active_sampler_ = this; active_sampler_ = this;
active_ = true; SetActive(true);
// There's no way to send a signal to a thread on FreeBSD, but we can
// start a thread that uses the stack guard to interrupt the JS thread.
if (pthread_create(
&data_->signal_sender_thread_, NULL, SenderEntry, data_) == 0) {
data_->signal_sender_launched_ = true;
}
} }
void Sampler::Stop() { void Sampler::Stop() {
// Restore old signal handler
if (data_->signal_handler_installed_) {
setitimer(ITIMER_PROF, &data_->old_timer_value_, NULL);
sigaction(SIGPROF, &data_->old_signal_handler_, 0);
data_->signal_handler_installed_ = false;
}
// This sampler is no longer the active sampler. // This sampler is no longer the active sampler.
active_sampler_ = NULL; active_sampler_ = NULL;
active_ = false; SetActive(false);
// Wait for signal sender termination (it will exit after setting
// active_ to false).
if (data_->signal_sender_launched_) {
Top::WakeUpRuntimeProfilerThreadBeforeShutdown();
pthread_join(data_->signal_sender_thread_, NULL);
data_->signal_sender_launched_ = false;
}
} }
#endif // ENABLE_LOGGING_AND_PROFILING #endif // ENABLE_LOGGING_AND_PROFILING
......
...@@ -613,6 +613,7 @@ class Sampler { ...@@ -613,6 +613,7 @@ class Sampler {
void ResetSamplesTaken() { samples_taken_ = 0; } void ResetSamplesTaken() { samples_taken_ = 0; }
class PlatformData; class PlatformData;
PlatformData* data() { return data_; }
protected: protected:
virtual void DoSampleStack(TickSample* sample) = 0; virtual void DoSampleStack(TickSample* sample) = 0;
......
#!/bin/sh
# A wrapper script to call 'linux-tick-processor'.
# Known issues on FreeBSD:
# No ticks from C++ code.
# You must have d8 built and in your path before calling this.
tools_path=`cd $(dirname "$0");pwd`
$tools_path/linux-tick-processor "$@"
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
tools_path=`cd $(dirname "$0");pwd` tools_path=`cd $(dirname "$0");pwd`
if [ ! "$D8_PATH" ]; then if [ ! "$D8_PATH" ]; then
d8_public=`which d8` d8_public=`which d8`
if [ $d8_public ]; then D8_PATH=$(dirname "$d8_public"); fi if [ -x $d8_public ]; then D8_PATH=$(dirname "$d8_public"); fi
fi fi
[ "$D8_PATH" ] || D8_PATH=$tools_path/.. [ "$D8_PATH" ] || D8_PATH=$tools_path/..
d8_exec=$D8_PATH/d8 d8_exec=$D8_PATH/d8
if [ "$1" == "--no-build" ]; then if [ "$1" = "--no-build" ]; then
shift shift
else else
# compile d8 if it doesn't exist, assuming this script # compile d8 if it doesn't exist, assuming this script
...@@ -16,15 +16,17 @@ else ...@@ -16,15 +16,17 @@ else
[ -x $d8_exec ] || scons -j4 -C $D8_PATH -Y $tools_path/.. d8 [ -x $d8_exec ] || scons -j4 -C $D8_PATH -Y $tools_path/.. d8
fi fi
# find the name of the log file to process, it must not start with a dash. # find the name of the log file to process, it must not start with a dash.
log_file="v8.log" log_file="v8.log"
for arg in "$@" for arg in "$@"
do do
if [[ "${arg}" != -* ]]; then if ! expr "X${arg}" : "^X-" > /dev/null; then
log_file=${arg} log_file=${arg}
fi fi
done done
# nm spits out 'no symbols found' messages to stderr. # nm spits out 'no symbols found' messages to stderr.
cat $log_file | $d8_exec $tools_path/splaytree.js $tools_path/codemap.js \ cat $log_file | $d8_exec $tools_path/splaytree.js $tools_path/codemap.js \
$tools_path/csvparser.js $tools_path/consarray.js \ $tools_path/csvparser.js $tools_path/consarray.js \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment