2009-05-05 15:57:47 +00:00
|
|
|
// Copyright 2006-2009 the V8 project authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Tests of logging functions from log.h
|
|
|
|
|
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
|
|
|
|
2009-07-28 09:10:29 +00:00
|
|
|
#ifdef __linux__
|
2009-09-04 11:16:51 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <pthread.h>
|
2009-07-28 09:10:29 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2009-09-04 11:16:51 +00:00
|
|
|
#endif // __linux__
|
2009-05-05 15:57:47 +00:00
|
|
|
|
2009-07-28 09:10:29 +00:00
|
|
|
#include "v8.h"
|
2009-05-05 15:57:47 +00:00
|
|
|
#include "log.h"
|
2010-04-06 10:36:38 +00:00
|
|
|
#include "cpu-profiler.h"
|
2009-09-04 11:16:51 +00:00
|
|
|
#include "v8threads.h"
|
2009-05-05 15:57:47 +00:00
|
|
|
#include "cctest.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "vm-state-inl.h"
|
2009-05-05 15:57:47 +00:00
|
|
|
|
2009-05-20 09:04:13 +00:00
|
|
|
using v8::internal::Address;
|
2009-05-25 08:25:36 +00:00
|
|
|
using v8::internal::EmbeddedVector;
|
2009-05-05 15:57:47 +00:00
|
|
|
using v8::internal::Logger;
|
2009-11-11 09:50:06 +00:00
|
|
|
using v8::internal::StrLength;
|
2009-05-05 15:57:47 +00:00
|
|
|
|
2009-05-20 09:04:13 +00:00
|
|
|
namespace i = v8::internal;
|
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
static void SetUp() {
|
|
|
|
// Log to memory buffer.
|
2009-05-20 09:04:13 +00:00
|
|
|
i::FLAG_logfile = "*";
|
|
|
|
i::FLAG_log = true;
|
2009-05-05 15:57:47 +00:00
|
|
|
Logger::Setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDown() {
|
|
|
|
Logger::TearDown();
|
|
|
|
}
|
|
|
|
|
2009-05-08 10:06:38 +00:00
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
TEST(EmptyLog) {
|
|
|
|
SetUp();
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(100, NULL, 0));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 100));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(100, NULL, 100));
|
|
|
|
TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GetMessages) {
|
|
|
|
SetUp();
|
|
|
|
Logger::StringEvent("aaa", "bbb");
|
|
|
|
Logger::StringEvent("cccc", "dddd");
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
|
|
|
|
char log_lines[100];
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
// See Logger::StringEvent.
|
|
|
|
const char* line_1 = "aaa,\"bbb\"\n";
|
2009-11-11 09:50:06 +00:00
|
|
|
const int line_1_len = StrLength(line_1);
|
2009-05-05 15:57:47 +00:00
|
|
|
// The exact size.
|
|
|
|
CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len));
|
|
|
|
CHECK_EQ(line_1, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
// A bit more than the first line length.
|
|
|
|
CHECK_EQ(line_1_len, Logger::GetLogLines(0, log_lines, line_1_len + 3));
|
2009-05-28 07:08:09 +00:00
|
|
|
log_lines[line_1_len] = '\0';
|
2009-05-05 15:57:47 +00:00
|
|
|
CHECK_EQ(line_1, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
const char* line_2 = "cccc,\"dddd\"\n";
|
2009-11-11 09:50:06 +00:00
|
|
|
const int line_2_len = StrLength(line_2);
|
2009-05-05 15:57:47 +00:00
|
|
|
// Now start with line_2 beginning.
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(line_1_len, log_lines, 0));
|
|
|
|
CHECK_EQ(line_2_len, Logger::GetLogLines(line_1_len, log_lines, line_2_len));
|
|
|
|
CHECK_EQ(line_2, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
CHECK_EQ(line_2_len,
|
|
|
|
Logger::GetLogLines(line_1_len, log_lines, line_2_len + 3));
|
|
|
|
CHECK_EQ(line_2, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
// Now get entire buffer contents.
|
|
|
|
const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
|
2009-11-11 09:50:06 +00:00
|
|
|
const int all_lines_len = StrLength(all_lines);
|
2009-05-05 15:57:47 +00:00
|
|
|
CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len));
|
|
|
|
CHECK_EQ(all_lines, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
CHECK_EQ(all_lines_len, Logger::GetLogLines(0, log_lines, all_lines_len + 3));
|
|
|
|
CHECK_EQ(all_lines, log_lines);
|
|
|
|
memset(log_lines, 0, sizeof(log_lines));
|
|
|
|
TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 08:25:36 +00:00
|
|
|
static int GetLogLines(int start_pos, i::Vector<char>* buffer) {
|
|
|
|
return Logger::GetLogLines(start_pos, buffer->start(), buffer->length());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
TEST(BeyondWritePosition) {
|
|
|
|
SetUp();
|
|
|
|
Logger::StringEvent("aaa", "bbb");
|
|
|
|
Logger::StringEvent("cccc", "dddd");
|
|
|
|
// See Logger::StringEvent.
|
|
|
|
const char* all_lines = "aaa,\"bbb\"\ncccc,\"dddd\"\n";
|
2009-11-11 09:50:06 +00:00
|
|
|
const int all_lines_len = StrLength(all_lines);
|
2009-05-25 08:25:36 +00:00
|
|
|
EmbeddedVector<char, 100> buffer;
|
|
|
|
const int beyond_write_pos = all_lines_len;
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos, buffer.start(), 1));
|
|
|
|
CHECK_EQ(0, GetLogLines(beyond_write_pos, &buffer));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 1, buffer.start(), 1));
|
|
|
|
CHECK_EQ(0, GetLogLines(beyond_write_pos + 1, &buffer));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(beyond_write_pos + 100, buffer.start(), 1));
|
|
|
|
CHECK_EQ(0, GetLogLines(beyond_write_pos + 100, &buffer));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(10 * 1024 * 1024, buffer.start(), 1));
|
|
|
|
CHECK_EQ(0, GetLogLines(10 * 1024 * 1024, &buffer));
|
2009-05-05 15:57:47 +00:00
|
|
|
TearDown();
|
|
|
|
}
|
|
|
|
|
2009-05-08 10:06:38 +00:00
|
|
|
|
|
|
|
TEST(MemoryLoggingTurnedOff) {
|
|
|
|
// Log to stdout
|
2009-05-20 09:04:13 +00:00
|
|
|
i::FLAG_logfile = "-";
|
|
|
|
i::FLAG_log = true;
|
2009-05-08 10:06:38 +00:00
|
|
|
Logger::Setup();
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 0));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(100, NULL, 0));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(0, NULL, 100));
|
|
|
|
CHECK_EQ(0, Logger::GetLogLines(100, NULL, 100));
|
|
|
|
Logger::TearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 08:25:36 +00:00
|
|
|
static void CompileAndRunScript(const char *src) {
|
|
|
|
v8::Script::Compile(v8::String::New(src))->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class LoggerTestHelper : public AllStatic {
|
|
|
|
public:
|
|
|
|
static bool IsSamplerActive() { return Logger::IsProfilerSamplerActive(); }
|
2010-11-25 15:54:52 +00:00
|
|
|
static void ResetSamplesTaken() {
|
|
|
|
reinterpret_cast<Sampler*>(Logger::ticker_)->ResetSamplesTaken();
|
|
|
|
}
|
|
|
|
static bool has_samples_taken() {
|
|
|
|
return reinterpret_cast<Sampler*>(Logger::ticker_)->samples_taken() > 0;
|
|
|
|
}
|
2009-05-25 08:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace v8::internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
using v8::internal::LoggerTestHelper;
|
|
|
|
|
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ScopedLoggerInitializer {
|
|
|
|
public:
|
2010-03-01 10:41:34 +00:00
|
|
|
explicit ScopedLoggerInitializer(bool prof_lazy)
|
|
|
|
: saved_prof_lazy_(i::FLAG_prof_lazy),
|
2010-02-17 13:23:46 +00:00
|
|
|
saved_prof_(i::FLAG_prof),
|
|
|
|
saved_prof_auto_(i::FLAG_prof_auto),
|
2010-03-01 10:41:34 +00:00
|
|
|
trick_to_run_init_flags_(init_flags_(prof_lazy)),
|
2010-02-17 13:23:46 +00:00
|
|
|
need_to_set_up_logger_(i::V8::IsRunning()),
|
|
|
|
scope_(),
|
|
|
|
env_(v8::Context::New()) {
|
|
|
|
if (need_to_set_up_logger_) Logger::Setup();
|
|
|
|
env_->Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedLoggerInitializer() {
|
|
|
|
env_->Exit();
|
|
|
|
Logger::TearDown();
|
|
|
|
i::FLAG_prof_lazy = saved_prof_lazy_;
|
|
|
|
i::FLAG_prof = saved_prof_;
|
|
|
|
i::FLAG_prof_auto = saved_prof_auto_;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Handle<v8::Context>& env() { return env_; }
|
|
|
|
|
|
|
|
private:
|
2010-03-01 10:41:34 +00:00
|
|
|
static bool init_flags_(bool prof_lazy) {
|
2010-02-17 13:23:46 +00:00
|
|
|
i::FLAG_prof = true;
|
|
|
|
i::FLAG_prof_lazy = prof_lazy;
|
|
|
|
i::FLAG_prof_auto = false;
|
|
|
|
i::FLAG_logfile = "*";
|
|
|
|
return prof_lazy;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool saved_prof_lazy_;
|
|
|
|
const bool saved_prof_;
|
|
|
|
const bool saved_prof_auto_;
|
|
|
|
const bool trick_to_run_init_flags_;
|
|
|
|
const bool need_to_set_up_logger_;
|
|
|
|
v8::HandleScope scope_;
|
|
|
|
v8::Handle<v8::Context> env_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LogBufferMatcher {
|
|
|
|
public:
|
|
|
|
LogBufferMatcher() {
|
|
|
|
// Skip all initially logged stuff.
|
|
|
|
log_pos_ = GetLogLines(0, &buffer_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int log_pos() { return log_pos_; }
|
|
|
|
|
|
|
|
int GetNextChunk() {
|
|
|
|
int chunk_size = GetLogLines(log_pos_, &buffer_);
|
|
|
|
CHECK_GT(buffer_.length(), chunk_size);
|
|
|
|
buffer_[chunk_size] = '\0';
|
|
|
|
log_pos_ += chunk_size;
|
|
|
|
return chunk_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Find(const char* substr) {
|
|
|
|
return strstr(buffer_.start(), substr);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Find(const i::Vector<char>& substr) {
|
|
|
|
return Find(substr.start());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsInSequence(const char* s1, const char* s2) {
|
|
|
|
const char* s1_pos = Find(s1);
|
|
|
|
const char* s2_pos = Find(s2);
|
|
|
|
CHECK_NE(NULL, s1_pos);
|
|
|
|
CHECK_NE(NULL, s2_pos);
|
|
|
|
return s1_pos < s2_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrintBuffer() {
|
|
|
|
puts(buffer_.start());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EmbeddedVector<char, 102400> buffer_;
|
|
|
|
int log_pos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
static void CheckThatProfilerWorks(LogBufferMatcher* matcher) {
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(i::RuntimeProfiler::IsEnabled() ||
|
|
|
|
!LoggerTestHelper::IsSamplerActive());
|
2010-11-25 15:54:52 +00:00
|
|
|
LoggerTestHelper::ResetSamplesTaken();
|
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0);
|
2009-05-25 08:25:36 +00:00
|
|
|
CHECK(LoggerTestHelper::IsSamplerActive());
|
|
|
|
|
|
|
|
// Verify that the current map of compiled functions has been logged.
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_GT(matcher->GetNextChunk(), 0);
|
2009-05-25 08:25:36 +00:00
|
|
|
const char* code_creation = "\ncode-creation,"; // eq. to /^code-creation,/
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_NE(NULL, matcher->Find(code_creation));
|
2009-05-25 08:25:36 +00:00
|
|
|
|
|
|
|
// Force compiler to generate new code by parametrizing source.
|
|
|
|
EmbeddedVector<char, 100> script_src;
|
|
|
|
i::OS::SNPrintF(script_src,
|
Fix issue 553: function frame is skipped in profile when compare stub is called.
The problem appeared due to a fact that stubs doesn't create a stack
frame, reusing the stack frame of the caller function. When building
stack traces, the current function is retrieved from PC, and its
callees are retrieved by traversing the stack backwards. Thus, for
stubs, the stub itself was discovered via PC, and then stub's caller's
caller was retrieved from stack.
To fix this problem, a pointer to JSFunction object is now captured
from the topmost stack frame, and is saved into stack trace log
record. Then a simple heuristics is applied whether a referred
function should be added to decoded stack, or not, to avoid reporting
the same function twice (from PC and from the pointer.)
BUG=553
TEST=added to mjsunit/tools/tickprocessor
Review URL: http://codereview.chromium.org/546089
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3673 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2010-01-21 16:42:41 +00:00
|
|
|
"function f%d(x) { return %d * x; }"
|
|
|
|
"for (var i = 0; i < 10000; ++i) { f%d(i); }",
|
2010-02-17 13:23:46 +00:00
|
|
|
matcher->log_pos(), matcher->log_pos(), matcher->log_pos());
|
2009-05-29 15:33:02 +00:00
|
|
|
// Run code for 200 msecs to get some ticks.
|
|
|
|
const double end_time = i::OS::TimeCurrentMillis() + 200;
|
|
|
|
while (i::OS::TimeCurrentMillis() < end_time) {
|
2009-05-25 08:25:36 +00:00
|
|
|
CompileAndRunScript(script_src.start());
|
2009-07-28 08:34:55 +00:00
|
|
|
// Yield CPU to give Profiler thread a chance to process ticks.
|
|
|
|
i::OS::Sleep(1);
|
2009-05-25 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 0);
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(i::RuntimeProfiler::IsEnabled() ||
|
|
|
|
!LoggerTestHelper::IsSamplerActive());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
2009-05-29 15:33:02 +00:00
|
|
|
// Wait 50 msecs to allow Profiler thread to process the last
|
|
|
|
// tick sample it has got.
|
|
|
|
i::OS::Sleep(50);
|
|
|
|
|
2009-05-25 08:25:36 +00:00
|
|
|
// Now we must have compiler and tick records.
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_GT(matcher->GetNextChunk(), 0);
|
|
|
|
matcher->PrintBuffer();
|
|
|
|
CHECK_NE(NULL, matcher->Find(code_creation));
|
2009-05-25 08:25:36 +00:00
|
|
|
const char* tick = "\ntick,";
|
2010-02-17 13:23:46 +00:00
|
|
|
const bool ticks_found = matcher->Find(tick) != NULL;
|
2010-11-25 15:54:52 +00:00
|
|
|
CHECK_EQ(LoggerTestHelper::has_samples_taken(), ticks_found);
|
2009-05-25 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ProfLazyMode) {
|
2010-03-01 10:41:34 +00:00
|
|
|
ScopedLoggerInitializer initialize_logger(true);
|
2009-05-25 08:25:36 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
if (!i::V8::UseCrankshaft()) return;
|
|
|
|
|
|
|
|
// No sampling should happen prior to resuming profiler unless we
|
|
|
|
// are runtime profiling.
|
|
|
|
CHECK(i::RuntimeProfiler::IsEnabled() ||
|
|
|
|
!LoggerTestHelper::IsSamplerActive());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
LogBufferMatcher matcher;
|
2009-10-28 09:13:11 +00:00
|
|
|
// Nothing must be logged until profiling is resumed.
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_EQ(0, matcher.log_pos());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
|
|
|
CompileAndRunScript("var a = (function(x) { return x + 1; })(10);");
|
|
|
|
|
|
|
|
// Nothing must be logged while profiling is suspended.
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_EQ(0, matcher.GetNextChunk());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
CheckThatProfilerWorks(&matcher);
|
2009-05-25 08:25:36 +00:00
|
|
|
|
|
|
|
CompileAndRunScript("var a = (function(x) { return x + 1; })(10);");
|
|
|
|
|
|
|
|
// No new data beyond last retrieved position.
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_EQ(0, matcher.GetNextChunk());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
|
|
|
// Check that profiling can be resumed again.
|
2010-02-17 13:23:46 +00:00
|
|
|
CheckThatProfilerWorks(&matcher);
|
2009-05-25 08:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-26 14:51:31 +00:00
|
|
|
// BUG(913). Need to implement support for profiling multiple VM threads.
|
|
|
|
#if 0
|
2009-09-04 11:16:51 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class LoopingThread : public v8::internal::Thread {
|
|
|
|
public:
|
|
|
|
LoopingThread()
|
|
|
|
: v8::internal::Thread(),
|
|
|
|
semaphore_(v8::internal::OS::CreateSemaphore(0)),
|
|
|
|
run_(true) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~LoopingThread() { delete semaphore_; }
|
|
|
|
|
|
|
|
void Run() {
|
|
|
|
self_ = pthread_self();
|
|
|
|
RunLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendSigProf() { pthread_kill(self_, SIGPROF); }
|
|
|
|
|
|
|
|
void Stop() { run_ = false; }
|
|
|
|
|
|
|
|
bool WaitForRunning() { return semaphore_->Wait(1000000); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool IsRunning() { return run_; }
|
|
|
|
|
|
|
|
virtual void RunLoop() = 0;
|
|
|
|
|
|
|
|
void SetV8ThreadId() {
|
|
|
|
v8_thread_id_ = v8::V8::GetCurrentThreadId();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalRunning() { semaphore_->Signal(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::internal::Semaphore* semaphore_;
|
|
|
|
bool run_;
|
|
|
|
pthread_t self_;
|
|
|
|
int v8_thread_id_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LoopingJsThread : public LoopingThread {
|
|
|
|
public:
|
|
|
|
void RunLoop() {
|
2010-03-04 13:25:23 +00:00
|
|
|
v8::Locker locker;
|
|
|
|
CHECK(v8::internal::ThreadManager::HasId());
|
|
|
|
SetV8ThreadId();
|
2009-09-04 11:16:51 +00:00
|
|
|
while (IsRunning()) {
|
|
|
|
v8::HandleScope scope;
|
|
|
|
v8::Persistent<v8::Context> context = v8::Context::New();
|
2010-03-04 13:25:23 +00:00
|
|
|
CHECK(!context.IsEmpty());
|
|
|
|
{
|
|
|
|
v8::Context::Scope context_scope(context);
|
|
|
|
SignalRunning();
|
|
|
|
CompileAndRunScript(
|
|
|
|
"var j; for (var i=0; i<10000; ++i) { j = Math.sin(i); }");
|
|
|
|
}
|
2009-09-04 11:16:51 +00:00
|
|
|
context.Dispose();
|
2010-03-04 15:03:36 +00:00
|
|
|
i::OS::Sleep(1);
|
2009-09-04 11:16:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class LoopingNonJsThread : public LoopingThread {
|
|
|
|
public:
|
|
|
|
void RunLoop() {
|
|
|
|
v8::Locker locker;
|
|
|
|
v8::Unlocker unlocker;
|
|
|
|
// Now thread has V8's id, but will not run VM code.
|
|
|
|
CHECK(v8::internal::ThreadManager::HasId());
|
|
|
|
double i = 10;
|
|
|
|
SignalRunning();
|
|
|
|
while (IsRunning()) {
|
|
|
|
i = sin(i);
|
|
|
|
i::OS::Sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class TestSampler : public v8::internal::Sampler {
|
|
|
|
public:
|
|
|
|
TestSampler()
|
2010-12-07 11:31:57 +00:00
|
|
|
: Sampler(0, true, true),
|
2009-09-04 11:16:51 +00:00
|
|
|
semaphore_(v8::internal::OS::CreateSemaphore(0)),
|
|
|
|
was_sample_stack_called_(false) {
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestSampler() { delete semaphore_; }
|
|
|
|
|
|
|
|
void SampleStack(v8::internal::TickSample*) {
|
|
|
|
was_sample_stack_called_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Tick(v8::internal::TickSample*) { semaphore_->Signal(); }
|
|
|
|
|
|
|
|
bool WaitForTick() { return semaphore_->Wait(1000000); }
|
|
|
|
|
|
|
|
void Reset() { was_sample_stack_called_ = false; }
|
|
|
|
|
|
|
|
bool WasSampleStackCalled() { return was_sample_stack_called_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::internal::Semaphore* semaphore_;
|
|
|
|
bool was_sample_stack_called_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(ProfMultipleThreads) {
|
2010-12-07 11:31:57 +00:00
|
|
|
TestSampler* sampler = NULL;
|
|
|
|
{
|
|
|
|
v8::Locker locker;
|
|
|
|
sampler = new TestSampler();
|
|
|
|
sampler->Start();
|
|
|
|
CHECK(sampler->IsActive());
|
|
|
|
}
|
|
|
|
|
2009-09-04 11:16:51 +00:00
|
|
|
LoopingJsThread jsThread;
|
|
|
|
jsThread.Start();
|
|
|
|
LoopingNonJsThread nonJsThread;
|
|
|
|
nonJsThread.Start();
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(!sampler->WasSampleStackCalled());
|
2009-09-04 11:16:51 +00:00
|
|
|
jsThread.WaitForRunning();
|
|
|
|
jsThread.SendSigProf();
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(sampler->WaitForTick());
|
|
|
|
CHECK(sampler->WasSampleStackCalled());
|
|
|
|
sampler->Reset();
|
|
|
|
CHECK(!sampler->WasSampleStackCalled());
|
2009-09-04 11:16:51 +00:00
|
|
|
nonJsThread.WaitForRunning();
|
|
|
|
nonJsThread.SendSigProf();
|
2010-12-07 11:31:57 +00:00
|
|
|
CHECK(!sampler->WaitForTick());
|
|
|
|
CHECK(!sampler->WasSampleStackCalled());
|
|
|
|
sampler->Stop();
|
2009-09-04 11:16:51 +00:00
|
|
|
|
|
|
|
jsThread.Stop();
|
|
|
|
nonJsThread.Stop();
|
|
|
|
jsThread.Join();
|
|
|
|
nonJsThread.Join();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
delete sampler;
|
2009-09-04 11:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __linux__
|
|
|
|
|
|
|
|
|
2009-10-07 12:20:02 +00:00
|
|
|
// Test for issue http://crbug.com/23768 in Chromium.
|
|
|
|
// Heap can contain scripts with already disposed external sources.
|
|
|
|
// We need to verify that LogCompiledFunctions doesn't crash on them.
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SimpleExternalString : public v8::String::ExternalStringResource {
|
|
|
|
public:
|
|
|
|
explicit SimpleExternalString(const char* source)
|
2009-11-11 09:50:06 +00:00
|
|
|
: utf_source_(StrLength(source)) {
|
2009-10-07 12:20:02 +00:00
|
|
|
for (int i = 0; i < utf_source_.length(); ++i)
|
|
|
|
utf_source_[i] = source[i];
|
|
|
|
}
|
|
|
|
virtual ~SimpleExternalString() {}
|
|
|
|
virtual size_t length() const { return utf_source_.length(); }
|
|
|
|
virtual const uint16_t* data() const { return utf_source_.start(); }
|
|
|
|
private:
|
|
|
|
i::ScopedVector<uint16_t> utf_source_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(Issue23768) {
|
|
|
|
v8::HandleScope scope;
|
|
|
|
v8::Handle<v8::Context> env = v8::Context::New();
|
|
|
|
env->Enter();
|
|
|
|
|
|
|
|
SimpleExternalString source_ext_str("(function ext() {})();");
|
|
|
|
v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str);
|
|
|
|
// Script needs to have a name in order to trigger InitLineEnds execution.
|
|
|
|
v8::Handle<v8::String> origin = v8::String::New("issue-23768-test");
|
|
|
|
v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin);
|
|
|
|
CHECK(!evil_script.IsEmpty());
|
|
|
|
CHECK(!evil_script->Run().IsEmpty());
|
|
|
|
i::Handle<i::ExternalTwoByteString> i_source(
|
|
|
|
i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
|
|
|
|
// This situation can happen if source was an external string disposed
|
|
|
|
// by its owner.
|
|
|
|
i_source->set_resource(NULL);
|
|
|
|
|
|
|
|
// Must not crash.
|
|
|
|
i::Logger::LogCompiledFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-20 12:15:46 +00:00
|
|
|
static v8::Handle<v8::Value> ObjMethod1(const v8::Arguments& args) {
|
|
|
|
return v8::Handle<v8::Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LogCallbacks) {
|
2010-03-01 10:41:34 +00:00
|
|
|
ScopedLoggerInitializer initialize_logger(false);
|
2010-02-17 13:23:46 +00:00
|
|
|
LogBufferMatcher matcher;
|
2009-11-20 12:15:46 +00:00
|
|
|
|
|
|
|
v8::Persistent<v8::FunctionTemplate> obj =
|
|
|
|
v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
|
|
|
|
obj->SetClassName(v8::String::New("Obj"));
|
|
|
|
v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate();
|
|
|
|
v8::Local<v8::Signature> signature = v8::Signature::New(obj);
|
|
|
|
proto->Set(v8::String::New("method1"),
|
|
|
|
v8::FunctionTemplate::New(ObjMethod1,
|
|
|
|
v8::Handle<v8::Value>(),
|
|
|
|
signature),
|
|
|
|
static_cast<v8::PropertyAttribute>(v8::DontDelete));
|
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction());
|
2009-11-23 09:19:24 +00:00
|
|
|
CompileAndRunScript("Obj.prototype.method1.toString();");
|
|
|
|
|
|
|
|
i::Logger::LogCompiledFunctions();
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_GT(matcher.GetNextChunk(), 0);
|
2009-11-20 12:15:46 +00:00
|
|
|
|
|
|
|
const char* callback_rec = "code-creation,Callback,";
|
2010-02-17 13:23:46 +00:00
|
|
|
char* pos = const_cast<char*>(matcher.Find(callback_rec));
|
2009-11-20 12:15:46 +00:00
|
|
|
CHECK_NE(NULL, pos);
|
|
|
|
pos += strlen(callback_rec);
|
|
|
|
EmbeddedVector<char, 100> ref_data;
|
|
|
|
i::OS::SNPrintF(ref_data,
|
2009-11-23 14:43:00 +00:00
|
|
|
"0x%" V8PRIxPTR ",1,\"method1\"", ObjMethod1);
|
2009-11-23 09:19:24 +00:00
|
|
|
*(pos + strlen(ref_data.start())) = '\0';
|
2009-11-20 12:15:46 +00:00
|
|
|
CHECK_EQ(ref_data.start(), pos);
|
|
|
|
|
|
|
|
obj.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-25 16:39:18 +00:00
|
|
|
static v8::Handle<v8::Value> Prop1Getter(v8::Local<v8::String> property,
|
|
|
|
const v8::AccessorInfo& info) {
|
|
|
|
return v8::Handle<v8::Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Prop1Setter(v8::Local<v8::String> property,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::AccessorInfo& info) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Handle<v8::Value> Prop2Getter(v8::Local<v8::String> property,
|
|
|
|
const v8::AccessorInfo& info) {
|
|
|
|
return v8::Handle<v8::Value>();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LogAccessorCallbacks) {
|
2010-03-01 10:41:34 +00:00
|
|
|
ScopedLoggerInitializer initialize_logger(false);
|
2010-02-17 13:23:46 +00:00
|
|
|
LogBufferMatcher matcher;
|
2009-11-25 16:39:18 +00:00
|
|
|
|
|
|
|
v8::Persistent<v8::FunctionTemplate> obj =
|
|
|
|
v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New());
|
|
|
|
obj->SetClassName(v8::String::New("Obj"));
|
|
|
|
v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate();
|
|
|
|
inst->SetAccessor(v8::String::New("prop1"), Prop1Getter, Prop1Setter);
|
|
|
|
inst->SetAccessor(v8::String::New("prop2"), Prop2Getter);
|
|
|
|
|
|
|
|
i::Logger::LogAccessorCallbacks();
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_GT(matcher.GetNextChunk(), 0);
|
|
|
|
matcher.PrintBuffer();
|
2009-11-25 16:39:18 +00:00
|
|
|
|
|
|
|
EmbeddedVector<char, 100> prop1_getter_record;
|
|
|
|
i::OS::SNPrintF(prop1_getter_record,
|
|
|
|
"code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop1\"",
|
|
|
|
Prop1Getter);
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_NE(NULL, matcher.Find(prop1_getter_record));
|
2009-11-25 16:39:18 +00:00
|
|
|
EmbeddedVector<char, 100> prop1_setter_record;
|
|
|
|
i::OS::SNPrintF(prop1_setter_record,
|
|
|
|
"code-creation,Callback,0x%" V8PRIxPTR ",1,\"set prop1\"",
|
|
|
|
Prop1Setter);
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_NE(NULL, matcher.Find(prop1_setter_record));
|
2009-11-25 16:39:18 +00:00
|
|
|
EmbeddedVector<char, 100> prop2_getter_record;
|
|
|
|
i::OS::SNPrintF(prop2_getter_record,
|
|
|
|
"code-creation,Callback,0x%" V8PRIxPTR ",1,\"get prop2\"",
|
|
|
|
Prop2Getter);
|
2010-02-17 13:23:46 +00:00
|
|
|
CHECK_NE(NULL, matcher.Find(prop2_getter_record));
|
2009-11-25 16:39:18 +00:00
|
|
|
|
|
|
|
obj.Dispose();
|
2010-02-17 13:23:46 +00:00
|
|
|
}
|
2009-11-25 16:39:18 +00:00
|
|
|
|
2010-02-17 13:23:46 +00:00
|
|
|
|
|
|
|
TEST(LogTags) {
|
2010-03-01 10:41:34 +00:00
|
|
|
ScopedLoggerInitializer initialize_logger(false);
|
2010-02-17 13:23:46 +00:00
|
|
|
LogBufferMatcher matcher;
|
|
|
|
|
|
|
|
const char* open_tag = "open-tag,";
|
|
|
|
const char* close_tag = "close-tag,";
|
|
|
|
|
|
|
|
// Check compatibility with the old style behavior.
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 0);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 0);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
CHECK_EQ(NULL, matcher.Find(open_tag));
|
|
|
|
CHECK_EQ(NULL, matcher.Find(close_tag));
|
|
|
|
|
|
|
|
const char* open_tag1 = "open-tag,1\n";
|
|
|
|
const char* close_tag1 = "close-tag,1\n";
|
|
|
|
|
|
|
|
// Check non-nested tag case.
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
CHECK_GT(matcher.GetNextChunk(), 0);
|
|
|
|
CHECK(matcher.IsInSequence(open_tag1, close_tag1));
|
|
|
|
|
|
|
|
const char* open_tag2 = "open-tag,2\n";
|
|
|
|
const char* close_tag2 = "close-tag,2\n";
|
|
|
|
|
|
|
|
// Check nested tags case.
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
CHECK_GT(matcher.GetNextChunk(), 0);
|
|
|
|
// open_tag1 < open_tag2 < close_tag2 < close_tag1
|
|
|
|
CHECK(matcher.IsInSequence(open_tag1, open_tag2));
|
|
|
|
CHECK(matcher.IsInSequence(open_tag2, close_tag2));
|
|
|
|
CHECK(matcher.IsInSequence(close_tag2, close_tag1));
|
|
|
|
|
|
|
|
// Check overlapped tags case.
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
CHECK_GT(matcher.GetNextChunk(), 0);
|
|
|
|
// open_tag1 < open_tag2 < close_tag1 < close_tag2
|
|
|
|
CHECK(matcher.IsInSequence(open_tag1, open_tag2));
|
|
|
|
CHECK(matcher.IsInSequence(open_tag2, close_tag1));
|
|
|
|
CHECK(matcher.IsInSequence(close_tag1, close_tag2));
|
|
|
|
|
|
|
|
const char* open_tag3 = "open-tag,3\n";
|
|
|
|
const char* close_tag3 = "close-tag,3\n";
|
|
|
|
|
|
|
|
// Check pausing overflow case.
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 2);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_CPU, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 3);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 3);
|
|
|
|
CHECK_EQ(v8::PROFILER_MODULE_NONE, Logger::GetActiveProfilerModules());
|
|
|
|
// Must be no tags, because logging must be disabled.
|
|
|
|
CHECK_EQ(NULL, matcher.Find(open_tag3));
|
|
|
|
CHECK_EQ(NULL, matcher.Find(close_tag3));
|
2009-11-25 16:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-01 10:41:34 +00:00
|
|
|
TEST(IsLoggingPreserved) {
|
|
|
|
ScopedLoggerInitializer initialize_logger(false);
|
|
|
|
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::ResumeProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::PauseProfiler(v8::PROFILER_MODULE_CPU, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::ResumeProfiler(
|
|
|
|
v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::PauseProfiler(
|
|
|
|
v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::ResumeProfiler(
|
|
|
|
v8::PROFILER_MODULE_CPU |
|
|
|
|
v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
Logger::PauseProfiler(
|
|
|
|
v8::PROFILER_MODULE_CPU |
|
|
|
|
v8::PROFILER_MODULE_HEAP_STATS | v8::PROFILER_MODULE_JS_CONSTRUCTORS, 1);
|
|
|
|
CHECK(Logger::is_logging());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-20 09:04:13 +00:00
|
|
|
static inline bool IsStringEqualTo(const char* r, const char* s) {
|
|
|
|
return strncmp(r, s, strlen(r)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool Consume(const char* str, char** buf) {
|
|
|
|
if (IsStringEqualTo(str, *buf)) {
|
|
|
|
*buf += strlen(str);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A code entity is a pointer to a position of code-creation event in buffer log
|
|
|
|
// offset to a point where entity size begins, i.e.: '255,"func"\n'. This makes
|
|
|
|
// comparing code entities pretty easy.
|
|
|
|
typedef char* CodeEntityInfo;
|
|
|
|
|
2009-05-20 16:43:46 +00:00
|
|
|
class Interval {
|
|
|
|
public:
|
|
|
|
Interval()
|
2009-05-25 10:27:18 +00:00
|
|
|
: min_addr_(reinterpret_cast<Address>(-1)),
|
|
|
|
max_addr_(reinterpret_cast<Address>(0)), next_(NULL) {}
|
2009-05-20 16:43:46 +00:00
|
|
|
|
2009-05-25 10:27:18 +00:00
|
|
|
~Interval() { delete next_; }
|
2009-05-20 16:43:46 +00:00
|
|
|
|
|
|
|
size_t Length() {
|
2009-05-25 10:27:18 +00:00
|
|
|
size_t result = max_addr_ - min_addr_ + 1;
|
|
|
|
if (next_ != NULL) result += next_->Length();
|
2009-05-20 16:43:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloneFrom(Interval* src) {
|
|
|
|
while (src != NULL) {
|
2009-05-25 10:27:18 +00:00
|
|
|
RegisterAddress(src->min_addr_);
|
|
|
|
RegisterAddress(src->max_addr_);
|
|
|
|
src = src->next_;
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Contains(Address addr) {
|
2009-05-25 10:27:18 +00:00
|
|
|
if (min_addr_ <= addr && addr <= max_addr_) {
|
2009-05-20 16:43:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-25 10:27:18 +00:00
|
|
|
if (next_ != NULL) {
|
|
|
|
return next_->Contains(addr);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetIndex(Address addr) {
|
2009-05-25 10:27:18 +00:00
|
|
|
if (min_addr_ <= addr && addr <= max_addr_) {
|
|
|
|
return addr - min_addr_;
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
2009-05-25 10:27:18 +00:00
|
|
|
CHECK_NE(NULL, next_);
|
|
|
|
return (max_addr_ - min_addr_ + 1) + next_->GetIndex(addr);
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Address GetMinAddr() {
|
2009-05-25 10:27:18 +00:00
|
|
|
return next_ == NULL ? min_addr_ : i::Min(min_addr_, next_->GetMinAddr());
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Address GetMaxAddr() {
|
2009-05-25 10:27:18 +00:00
|
|
|
return next_ == NULL ? max_addr_ : i::Max(max_addr_, next_->GetMaxAddr());
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RegisterAddress(Address addr) {
|
2009-05-25 10:27:18 +00:00
|
|
|
if (min_addr_ == reinterpret_cast<Address>(-1)
|
|
|
|
|| (size_t)(addr > min_addr_ ?
|
|
|
|
addr - min_addr_ : min_addr_ - addr) < MAX_DELTA) {
|
|
|
|
if (addr < min_addr_) min_addr_ = addr;
|
|
|
|
if (addr > max_addr_) max_addr_ = addr;
|
2009-05-20 16:43:46 +00:00
|
|
|
} else {
|
2009-05-25 10:27:18 +00:00
|
|
|
if (next_ == NULL) next_ = new Interval();
|
|
|
|
next_->RegisterAddress(addr);
|
2009-05-20 16:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-25 10:27:18 +00:00
|
|
|
Address raw_min_addr() { return min_addr_; }
|
2009-05-20 16:43:46 +00:00
|
|
|
|
2009-05-25 10:27:18 +00:00
|
|
|
Address raw_max_addr() { return max_addr_; }
|
2009-05-20 16:43:46 +00:00
|
|
|
|
2009-05-25 10:27:18 +00:00
|
|
|
Interval* get_next() { return next_; }
|
2009-05-20 16:43:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const size_t MAX_DELTA = 0x100000;
|
2009-05-25 10:27:18 +00:00
|
|
|
Address min_addr_;
|
|
|
|
Address max_addr_;
|
|
|
|
Interval* next_;
|
2009-05-20 16:43:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-20 09:04:13 +00:00
|
|
|
// A structure used to return log parsing results.
|
|
|
|
class ParseLogResult {
|
|
|
|
public:
|
|
|
|
ParseLogResult()
|
2009-05-20 16:43:46 +00:00
|
|
|
: entities_map(NULL), entities(NULL),
|
2009-05-20 12:47:30 +00:00
|
|
|
max_entities(0) {}
|
2009-05-20 09:04:13 +00:00
|
|
|
|
|
|
|
~ParseLogResult() {
|
2009-05-20 16:43:46 +00:00
|
|
|
i::DeleteArray(entities_map);
|
2009-05-20 09:04:13 +00:00
|
|
|
i::DeleteArray(entities);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AllocateEntities() {
|
|
|
|
// Make sure that the test doesn't operate on a bogus log.
|
|
|
|
CHECK_GT(max_entities, 0);
|
2009-05-20 16:43:46 +00:00
|
|
|
CHECK_GT(bounds.GetMinAddr(), 0);
|
|
|
|
CHECK_GT(bounds.GetMaxAddr(), bounds.GetMinAddr());
|
2009-05-20 09:04:13 +00:00
|
|
|
|
|
|
|
entities = i::NewArray<CodeEntityInfo>(max_entities);
|
|
|
|
for (int i = 0; i < max_entities; ++i) {
|
|
|
|
entities[i] = NULL;
|
|
|
|
}
|
2009-05-20 16:43:46 +00:00
|
|
|
const size_t map_length = bounds.Length();
|
2009-11-11 09:50:06 +00:00
|
|
|
entities_map = i::NewArray<int>(static_cast<int>(map_length));
|
2009-05-20 16:43:46 +00:00
|
|
|
for (size_t i = 0; i < map_length; ++i) {
|
2009-05-20 09:04:13 +00:00
|
|
|
entities_map[i] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-20 16:43:46 +00:00
|
|
|
bool HasIndexForAddress(Address addr) {
|
|
|
|
return bounds.Contains(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t GetIndexForAddress(Address addr) {
|
|
|
|
CHECK(HasIndexForAddress(addr));
|
|
|
|
return bounds.GetIndex(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeEntityInfo GetEntity(Address addr) {
|
|
|
|
if (HasIndexForAddress(addr)) {
|
|
|
|
size_t idx = GetIndexForAddress(addr);
|
|
|
|
int item = entities_map[idx];
|
|
|
|
return item != -1 ? entities[item] : NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParseAddress(char* start) {
|
|
|
|
Address addr =
|
|
|
|
reinterpret_cast<Address>(strtoul(start, NULL, 16)); // NOLINT
|
|
|
|
bounds.RegisterAddress(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address ConsumeAddress(char** start) {
|
|
|
|
char* end_ptr;
|
|
|
|
Address addr =
|
|
|
|
reinterpret_cast<Address>(strtoul(*start, &end_ptr, 16)); // NOLINT
|
|
|
|
CHECK(HasIndexForAddress(addr));
|
|
|
|
*start = end_ptr;
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Interval bounds;
|
2009-05-25 10:27:18 +00:00
|
|
|
// Memory map of entities start addresses.
|
2009-05-20 09:04:13 +00:00
|
|
|
int* entities_map;
|
|
|
|
// An array of code entities.
|
|
|
|
CodeEntityInfo* entities;
|
|
|
|
// Maximal entities count. Actual entities count can be lower,
|
|
|
|
// empty entity slots are pointing to NULL.
|
|
|
|
int max_entities;
|
|
|
|
};
|
|
|
|
|
2009-05-20 12:47:30 +00:00
|
|
|
} // namespace
|
2009-05-20 09:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef void (*ParserBlock)(char* start, char* end, ParseLogResult* result);
|
|
|
|
|
|
|
|
static void ParserCycle(
|
|
|
|
char* start, char* end, ParseLogResult* result,
|
|
|
|
ParserBlock block_creation, ParserBlock block_delete,
|
|
|
|
ParserBlock block_move) {
|
|
|
|
|
|
|
|
const char* code_creation = "code-creation,";
|
|
|
|
const char* code_delete = "code-delete,";
|
|
|
|
const char* code_move = "code-move,";
|
|
|
|
|
|
|
|
const char* lazy_compile = "LazyCompile,";
|
|
|
|
const char* script = "Script,";
|
|
|
|
const char* function = "Function,";
|
|
|
|
|
|
|
|
while (start < end) {
|
|
|
|
if (Consume(code_creation, &start)) {
|
|
|
|
if (Consume(lazy_compile, &start)
|
|
|
|
|| Consume(script, &start)
|
|
|
|
|| Consume(function, &start)) {
|
|
|
|
block_creation(start, end, result);
|
|
|
|
}
|
|
|
|
} else if (Consume(code_delete, &start)) {
|
|
|
|
block_delete(start, end, result);
|
|
|
|
} else if (Consume(code_move, &start)) {
|
|
|
|
block_move(start, end, result);
|
|
|
|
}
|
|
|
|
while (start < end && *start != '\n') ++start;
|
|
|
|
++start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass1CodeCreation(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
result->ParseAddress(start);
|
2009-05-20 09:04:13 +00:00
|
|
|
++result->max_entities;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass1CodeDelete(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
result->ParseAddress(start);
|
2009-05-20 09:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass1CodeMove(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
result->ParseAddress(start);
|
2009-05-20 09:04:13 +00:00
|
|
|
// Skip old address.
|
|
|
|
while (start < end && *start != ',') ++start;
|
|
|
|
CHECK_GT(end, start);
|
2009-05-20 12:47:30 +00:00
|
|
|
++start; // Skip ','.
|
2009-05-20 16:43:46 +00:00
|
|
|
result->ParseAddress(start);
|
2009-05-20 09:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass2CodeCreation(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
Address addr = result->ConsumeAddress(&start);
|
2009-05-20 09:04:13 +00:00
|
|
|
CHECK_GT(end, start);
|
2009-05-20 12:47:30 +00:00
|
|
|
++start; // Skip ','.
|
2009-05-20 09:04:13 +00:00
|
|
|
|
2009-05-20 16:43:46 +00:00
|
|
|
size_t idx = result->GetIndexForAddress(addr);
|
2009-05-20 09:04:13 +00:00
|
|
|
result->entities_map[idx] = -1;
|
|
|
|
for (int i = 0; i < result->max_entities; ++i) {
|
|
|
|
// Find an empty slot and fill it.
|
|
|
|
if (result->entities[i] == NULL) {
|
|
|
|
result->entities[i] = start;
|
|
|
|
result->entities_map[idx] = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Make sure that a slot was found.
|
|
|
|
CHECK_GE(result->entities_map[idx], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass2CodeDelete(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
Address addr = result->ConsumeAddress(&start);
|
|
|
|
size_t idx = result->GetIndexForAddress(addr);
|
2009-05-20 09:04:13 +00:00
|
|
|
// There can be code deletes that are not related to JS code.
|
|
|
|
if (result->entities_map[idx] >= 0) {
|
|
|
|
result->entities[result->entities_map[idx]] = NULL;
|
|
|
|
result->entities_map[idx] = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Pass2CodeMove(char* start, char* end, ParseLogResult* result) {
|
2009-05-20 16:43:46 +00:00
|
|
|
Address from_addr = result->ConsumeAddress(&start);
|
2009-05-20 09:04:13 +00:00
|
|
|
CHECK_GT(end, start);
|
2009-05-20 12:47:30 +00:00
|
|
|
++start; // Skip ','.
|
2009-05-20 16:43:46 +00:00
|
|
|
Address to_addr = result->ConsumeAddress(&start);
|
2009-05-20 09:04:13 +00:00
|
|
|
CHECK_GT(end, start);
|
|
|
|
|
2009-05-20 16:43:46 +00:00
|
|
|
size_t from_idx = result->GetIndexForAddress(from_addr);
|
|
|
|
size_t to_idx = result->GetIndexForAddress(to_addr);
|
2009-05-20 09:04:13 +00:00
|
|
|
// There can be code moves that are not related to JS code.
|
|
|
|
if (from_idx != to_idx && result->entities_map[from_idx] >= 0) {
|
|
|
|
CHECK_EQ(-1, result->entities_map[to_idx]);
|
|
|
|
result->entities_map[to_idx] = result->entities_map[from_idx];
|
|
|
|
result->entities_map[from_idx] = -1;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ParseLog(char* start, char* end, ParseLogResult* result) {
|
|
|
|
// Pass 1: Calculate boundaries of addresses and entities count.
|
|
|
|
ParserCycle(start, end, result,
|
|
|
|
Pass1CodeCreation, Pass1CodeDelete, Pass1CodeMove);
|
|
|
|
|
|
|
|
printf("min_addr: %p, max_addr: %p, entities: %d\n",
|
2009-05-20 16:43:46 +00:00
|
|
|
result->bounds.GetMinAddr(), result->bounds.GetMaxAddr(),
|
|
|
|
result->max_entities);
|
2009-05-20 09:04:13 +00:00
|
|
|
|
|
|
|
result->AllocateEntities();
|
|
|
|
|
|
|
|
// Pass 2: Fill in code entries data.
|
|
|
|
ParserCycle(start, end, result,
|
|
|
|
Pass2CodeCreation, Pass2CodeDelete, Pass2CodeMove);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void PrintCodeEntityInfo(CodeEntityInfo entity) {
|
|
|
|
const int max_len = 50;
|
|
|
|
if (entity != NULL) {
|
|
|
|
char* eol = strchr(entity, '\n');
|
2009-11-11 09:50:06 +00:00
|
|
|
int len = static_cast<int>(eol - entity);
|
2009-05-20 09:04:13 +00:00
|
|
|
len = len <= max_len ? len : max_len;
|
|
|
|
printf("%-*.*s ", max_len, len, entity);
|
|
|
|
} else {
|
|
|
|
printf("%*s", max_len + 1, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void PrintCodeEntitiesInfo(
|
|
|
|
bool is_equal, Address addr,
|
|
|
|
CodeEntityInfo l_entity, CodeEntityInfo r_entity) {
|
|
|
|
printf("%c %p ", is_equal ? ' ' : '*', addr);
|
|
|
|
PrintCodeEntityInfo(l_entity);
|
|
|
|
PrintCodeEntityInfo(r_entity);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int StrChrLen(const char* s, char c) {
|
2009-11-11 09:50:06 +00:00
|
|
|
return static_cast<int>(strchr(s, c) - s);
|
2009-05-20 09:04:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool AreFuncSizesEqual(CodeEntityInfo ref_s, CodeEntityInfo new_s) {
|
|
|
|
int ref_len = StrChrLen(ref_s, ',');
|
|
|
|
int new_len = StrChrLen(new_s, ',');
|
|
|
|
return ref_len == new_len && strncmp(ref_s, new_s, ref_len) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool AreFuncNamesEqual(CodeEntityInfo ref_s, CodeEntityInfo new_s) {
|
|
|
|
// Skip size.
|
|
|
|
ref_s = strchr(ref_s, ',') + 1;
|
|
|
|
new_s = strchr(new_s, ',') + 1;
|
|
|
|
int ref_len = StrChrLen(ref_s, '\n');
|
|
|
|
int new_len = StrChrLen(new_s, '\n');
|
|
|
|
// If reference is anonymous (""), it's OK to have anything in new.
|
|
|
|
if (ref_len == 2) return true;
|
|
|
|
// A special case for ErrorPrototype. Haven't yet figured out why they
|
|
|
|
// are different.
|
|
|
|
const char* error_prototype = "\"ErrorPrototype";
|
|
|
|
if (IsStringEqualTo(error_prototype, ref_s)
|
|
|
|
&& IsStringEqualTo(error_prototype, new_s)) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-20 12:47:30 +00:00
|
|
|
// Built-in objects have problems too.
|
|
|
|
const char* built_ins[] = {
|
|
|
|
"\"Boolean\"", "\"Function\"", "\"Number\"",
|
|
|
|
"\"Object\"", "\"Script\"", "\"String\""
|
|
|
|
};
|
|
|
|
for (size_t i = 0; i < sizeof(built_ins) / sizeof(*built_ins); ++i) {
|
|
|
|
if (IsStringEqualTo(built_ins[i], new_s)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-05-20 09:04:13 +00:00
|
|
|
return ref_len == new_len && strncmp(ref_s, new_s, ref_len) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool AreEntitiesEqual(CodeEntityInfo ref_e, CodeEntityInfo new_e) {
|
|
|
|
if (ref_e == NULL && new_e != NULL) return true;
|
|
|
|
if (ref_e != NULL && new_e != NULL) {
|
|
|
|
return AreFuncSizesEqual(ref_e, new_e) && AreFuncNamesEqual(ref_e, new_e);
|
|
|
|
}
|
|
|
|
if (ref_e != NULL && new_e == NULL) {
|
|
|
|
// args_count entities (argument adapters) are not found by heap traversal,
|
|
|
|
// but they are not needed because they doesn't contain any code.
|
|
|
|
ref_e = strchr(ref_e, ',') + 1;
|
|
|
|
const char* args_count = "\"args_count:";
|
|
|
|
return IsStringEqualTo(args_count, ref_e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that logging of code create / move / delete events
|
|
|
|
// is equivalent to traversal of a resulting heap.
|
|
|
|
TEST(EquivalenceOfLoggingAndTraversal) {
|
2009-05-25 08:25:36 +00:00
|
|
|
// This test needs to be run on a "clean" V8 to ensure that snapshot log
|
|
|
|
// is loaded. This is always true when running using tools/test.py because
|
|
|
|
// it launches a new cctest instance for every test. To be sure that launching
|
|
|
|
// cctest manually also works, please be sure that no tests below
|
|
|
|
// are using V8.
|
|
|
|
//
|
|
|
|
// P.S. No, V8 can't be re-initialized after disposal, see include/v8.h.
|
2009-05-25 19:39:52 +00:00
|
|
|
CHECK(!i::V8::IsRunning());
|
2009-05-25 08:25:36 +00:00
|
|
|
|
2009-05-20 09:04:13 +00:00
|
|
|
i::FLAG_logfile = "*";
|
|
|
|
i::FLAG_log = true;
|
|
|
|
i::FLAG_log_code = true;
|
|
|
|
|
|
|
|
// Make sure objects move.
|
|
|
|
bool saved_always_compact = i::FLAG_always_compact;
|
|
|
|
if (!i::FLAG_never_compact) {
|
|
|
|
i::FLAG_always_compact = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::HandleScope scope;
|
2009-05-20 12:47:30 +00:00
|
|
|
v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>();
|
2009-05-25 08:25:36 +00:00
|
|
|
v8::Handle<v8::Context> env = v8::Context::New(
|
2009-05-20 12:47:30 +00:00
|
|
|
0, v8::Handle<v8::ObjectTemplate>(), global_object);
|
2009-05-20 09:04:13 +00:00
|
|
|
env->Enter();
|
|
|
|
|
|
|
|
// Compile and run a function that creates other functions.
|
2009-05-25 08:25:36 +00:00
|
|
|
CompileAndRunScript(
|
2009-05-20 12:47:30 +00:00
|
|
|
"(function f(obj) {\n"
|
|
|
|
" obj.test =\n"
|
|
|
|
" (function a(j) { return function b() { return j; } })(100);\n"
|
2009-05-25 08:25:36 +00:00
|
|
|
"})(this);");
|
2009-08-25 03:18:40 +00:00
|
|
|
i::Heap::CollectAllGarbage(false);
|
2009-05-20 09:04:13 +00:00
|
|
|
|
2009-05-25 08:25:36 +00:00
|
|
|
EmbeddedVector<char, 204800> buffer;
|
2009-05-20 09:04:13 +00:00
|
|
|
int log_size;
|
|
|
|
ParseLogResult ref_result;
|
|
|
|
|
|
|
|
// Retrieve the log.
|
|
|
|
{
|
|
|
|
// Make sure that no GCs occur prior to LogCompiledFunctions call.
|
|
|
|
i::AssertNoAllocation no_alloc;
|
|
|
|
|
2009-05-25 08:25:36 +00:00
|
|
|
log_size = GetLogLines(0, &buffer);
|
2009-05-20 09:04:13 +00:00
|
|
|
CHECK_GT(log_size, 0);
|
|
|
|
CHECK_GT(buffer.length(), log_size);
|
|
|
|
|
|
|
|
// Fill a map of compiled code objects.
|
|
|
|
ParseLog(buffer.start(), buffer.start() + log_size, &ref_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate heap to find compiled functions, will write to log.
|
|
|
|
i::Logger::LogCompiledFunctions();
|
|
|
|
char* new_log_start = buffer.start() + log_size;
|
|
|
|
const int new_log_size = Logger::GetLogLines(
|
|
|
|
log_size, new_log_start, buffer.length() - log_size);
|
|
|
|
CHECK_GT(new_log_size, 0);
|
|
|
|
CHECK_GT(buffer.length(), log_size + new_log_size);
|
|
|
|
|
|
|
|
// Fill an equivalent map of compiled code objects.
|
|
|
|
ParseLogResult new_result;
|
|
|
|
ParseLog(new_log_start, new_log_start + new_log_size, &new_result);
|
|
|
|
|
|
|
|
// Test their actual equivalence.
|
2009-05-20 16:43:46 +00:00
|
|
|
Interval combined;
|
|
|
|
combined.CloneFrom(&ref_result.bounds);
|
|
|
|
combined.CloneFrom(&new_result.bounds);
|
|
|
|
Interval* iter = &combined;
|
2009-05-20 09:04:13 +00:00
|
|
|
bool results_equal = true;
|
2009-05-20 16:43:46 +00:00
|
|
|
|
|
|
|
while (iter != NULL) {
|
|
|
|
for (Address addr = iter->raw_min_addr();
|
|
|
|
addr <= iter->raw_max_addr(); ++addr) {
|
|
|
|
CodeEntityInfo ref_entity = ref_result.GetEntity(addr);
|
|
|
|
CodeEntityInfo new_entity = new_result.GetEntity(addr);
|
|
|
|
if (ref_entity != NULL || new_entity != NULL) {
|
|
|
|
const bool equal = AreEntitiesEqual(ref_entity, new_entity);
|
|
|
|
if (!equal) results_equal = false;
|
|
|
|
PrintCodeEntitiesInfo(equal, addr, ref_entity, new_entity);
|
|
|
|
}
|
2009-05-20 09:04:13 +00:00
|
|
|
}
|
2009-05-20 16:43:46 +00:00
|
|
|
iter = iter->get_next();
|
2009-05-20 09:04:13 +00:00
|
|
|
}
|
2009-05-20 12:47:30 +00:00
|
|
|
// Make sure that all log data is written prior crash due to CHECK failure.
|
|
|
|
fflush(stdout);
|
2009-05-20 09:04:13 +00:00
|
|
|
CHECK(results_equal);
|
|
|
|
|
|
|
|
env->Exit();
|
2009-05-25 08:25:36 +00:00
|
|
|
Logger::TearDown();
|
2009-05-20 09:04:13 +00:00
|
|
|
i::FLAG_always_compact = saved_always_compact;
|
|
|
|
}
|
|
|
|
|
2009-05-05 15:57:47 +00:00
|
|
|
#endif // ENABLE_LOGGING_AND_PROFILING
|