// Copyright 2011 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided
-// with the distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived
-// from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include <stdarg.h>
-#include "v8.h"
-
-#include "bootstrapper.h"
-#include "code-stubs.h"
-#include "cpu-profiler.h"
-#include "deoptimizer.h"
-#include "global-handles.h"
-#include "log.h"
-#include "log-utils.h"
-#include "macro-assembler.h"
-#include "platform.h"
-#include "runtime-profiler.h"
-#include "serialize.h"
-#include "string-stream.h"
-#include "vm-state-inl.h"
-
-// XDK support
-#include "third_party/xdk/xdk-v8.h"
+#include "src/v8.h"
+
+#include "src/base/platform/platform.h"
+#include "src/bootstrapper.h"
+#include "src/code-stubs.h"
+#include "src/cpu-profiler.h"
+#include "src/deoptimizer.h"
+#include "src/global-handles.h"
+#include "src/log.h"
+#include "src/log-utils.h"
+#include "src/macro-assembler.h"
+#include "src/perf-jit.h"
+#include "src/runtime-profiler.h"
+#include "src/serialize.h"
+#include "src/string-stream.h"
+#include "src/vm-state-inl.h"
namespace v8 {
namespace internal {
void AppendBytes(const char* bytes, int size) {
size = Min(size, kUtf8BufferSize - utf8_pos_);
- OS::MemCopy(utf8_buffer_ + utf8_pos_, bytes, size);
+ MemCopy(utf8_buffer_ + utf8_pos_, bytes, size);
utf8_pos_ += size;
}
void AppendInt(int n) {
Vector<char> buffer(utf8_buffer_ + utf8_pos_,
kUtf8BufferSize - utf8_pos_);
- int size = OS::SNPrintF(buffer, "%d", n);
+ int size = SNPrintF(buffer, "%d", n);
if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
utf8_pos_ += size;
}
void AppendHex(uint32_t n) {
Vector<char> buffer(utf8_buffer_ + utf8_pos_,
kUtf8BufferSize - utf8_pos_);
- int size = OS::SNPrintF(buffer, "%x", n);
- if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
- utf8_pos_ += size;
- }
- }
-
- // XDK needs this function temporarily. It will be removed later.
- void AppendAddress(Address address) {
- Vector<char> buffer(utf8_buffer_ + utf8_pos_, kUtf8BufferSize - utf8_pos_);
- int size = OS::SNPrintF(buffer, "0x%x", address);
+ int size = SNPrintF(buffer, "%x", n);
if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
utf8_pos_ += size;
}
virtual ~PerfBasicLogger();
virtual void CodeMoveEvent(Address from, Address to) { }
+ virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
virtual void CodeDeleteEvent(Address from) { }
private:
// Open the perf JIT dump file.
int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
ScopedVector<char> perf_dump_name(bufferSize);
- int size = OS::SNPrintF(
+ int size = SNPrintF(
perf_dump_name,
kFilenameFormatString,
- OS::GetCurrentProcessId());
+ base::OS::GetCurrentProcessId());
CHECK_NE(size, -1);
- perf_output_handle_ = OS::FOpen(perf_dump_name.start(), OS::LogFileOpenMode);
+ perf_output_handle_ =
+ base::OS::FOpen(perf_dump_name.start(), base::OS::LogFileOpenMode);
CHECK_NE(perf_output_handle_, NULL);
setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize);
}
SharedFunctionInfo*,
const char* name,
int length) {
- ASSERT(code->instruction_start() == code->address() + Code::kHeaderSize);
+ DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize);
- OS::FPrint(perf_output_handle_, "%llx %x %.*s\n",
- reinterpret_cast<uint64_t>(code->instruction_start()),
- code->instruction_size(),
- length, name);
-}
-
-
-// Linux perf tool logging support
-class PerfJitLogger : public CodeEventLogger {
- public:
- PerfJitLogger();
- virtual ~PerfJitLogger();
-
- virtual void CodeMoveEvent(Address from, Address to) { }
- virtual void CodeDeleteEvent(Address from) { }
-
- private:
- virtual void LogRecordedBuffer(Code* code,
- SharedFunctionInfo* shared,
- const char* name,
- int length);
-
- // Extension added to V8 log file name to get the low-level log name.
- static const char kFilenameFormatString[];
- static const int kFilenameBufferPadding;
-
- // File buffer size of the low-level log. We don't use the default to
- // minimize the associated overhead.
- static const int kLogBufferSize = 2 * MB;
-
- void LogWriteBytes(const char* bytes, int size);
- void LogWriteHeader();
-
- static const uint32_t kJitHeaderMagic = 0x4F74496A;
- static const uint32_t kJitHeaderVersion = 0x2;
- static const uint32_t kElfMachIA32 = 3;
- static const uint32_t kElfMachX64 = 62;
- static const uint32_t kElfMachARM = 40;
- static const uint32_t kElfMachMIPS = 10;
-
- struct jitheader {
- uint32_t magic;
- uint32_t version;
- uint32_t total_size;
- uint32_t elf_mach;
- uint32_t pad1;
- uint32_t pid;
- uint64_t timestamp;
- };
-
- enum jit_record_type {
- JIT_CODE_LOAD = 0
- // JIT_CODE_UNLOAD = 1,
- // JIT_CODE_CLOSE = 2,
- // JIT_CODE_DEBUG_INFO = 3,
- // JIT_CODE_PAGE_MAP = 4,
- // JIT_CODE_MAX = 5
- };
-
- struct jr_code_load {
- uint32_t id;
- uint32_t total_size;
- uint64_t timestamp;
- uint64_t vma;
- uint64_t code_addr;
- uint32_t code_size;
- uint32_t align;
- };
-
- uint32_t GetElfMach() {
-#if V8_TARGET_ARCH_IA32
- return kElfMachIA32;
-#elif V8_TARGET_ARCH_X64
- return kElfMachX64;
-#elif V8_TARGET_ARCH_ARM
- return kElfMachARM;
-#elif V8_TARGET_ARCH_MIPS
- return kElfMachMIPS;
-#else
- UNIMPLEMENTED();
- return 0;
-#endif
- }
-
- FILE* perf_output_handle_;
-};
-
-const char PerfJitLogger::kFilenameFormatString[] = "/tmp/jit-%d.dump";
-
-// Extra padding for the PID in the filename
-const int PerfJitLogger::kFilenameBufferPadding = 16;
-
-PerfJitLogger::PerfJitLogger()
- : perf_output_handle_(NULL) {
- // Open the perf JIT dump file.
- int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
- ScopedVector<char> perf_dump_name(bufferSize);
- int size = OS::SNPrintF(
- perf_dump_name,
- kFilenameFormatString,
- OS::GetCurrentProcessId());
- CHECK_NE(size, -1);
- perf_output_handle_ = OS::FOpen(perf_dump_name.start(), OS::LogFileOpenMode);
- CHECK_NE(perf_output_handle_, NULL);
- setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize);
-
- LogWriteHeader();
-}
-
-
-PerfJitLogger::~PerfJitLogger() {
- fclose(perf_output_handle_);
- perf_output_handle_ = NULL;
-}
-
-
-void PerfJitLogger::LogRecordedBuffer(Code* code,
- SharedFunctionInfo*,
- const char* name,
- int length) {
- ASSERT(code->instruction_start() == code->address() + Code::kHeaderSize);
- ASSERT(perf_output_handle_ != NULL);
-
- const char* code_name = name;
- uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start());
- uint32_t code_size = code->instruction_size();
-
- static const char string_terminator[] = "\0";
-
- jr_code_load code_load;
- code_load.id = JIT_CODE_LOAD;
- code_load.total_size = sizeof(code_load) + length + 1 + code_size;
- code_load.timestamp =
- static_cast<uint64_t>(OS::TimeCurrentMillis() * 1000.0);
- code_load.vma = 0x0; // Our addresses are absolute.
- code_load.code_addr = reinterpret_cast<uint64_t>(code->instruction_start());
- code_load.code_size = code_size;
- code_load.align = 0;
-
- LogWriteBytes(reinterpret_cast<const char*>(&code_load), sizeof(code_load));
- LogWriteBytes(code_name, length);
- LogWriteBytes(string_terminator, 1);
- LogWriteBytes(reinterpret_cast<const char*>(code_pointer), code_size);
-}
-
-
-void PerfJitLogger::LogWriteBytes(const char* bytes, int size) {
- size_t rv = fwrite(bytes, 1, size, perf_output_handle_);
- ASSERT(static_cast<size_t>(size) == rv);
- USE(rv);
-}
-
-
-void PerfJitLogger::LogWriteHeader() {
- ASSERT(perf_output_handle_ != NULL);
- jitheader header;
- header.magic = kJitHeaderMagic;
- header.version = kJitHeaderVersion;
- header.total_size = sizeof(jitheader);
- header.pad1 = 0xdeadbeef;
- header.elf_mach = GetElfMach();
- header.pid = OS::GetCurrentProcessId();
- header.timestamp = static_cast<uint64_t>(OS::TimeCurrentMillis() * 1000.0);
- LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header));
+ base::OS::FPrint(perf_output_handle_, "%llx %x %.*s\n",
+ reinterpret_cast<uint64_t>(code->instruction_start()),
+ code->instruction_size(), length, name);
}
virtual ~LowLevelLogger();
virtual void CodeMoveEvent(Address from, Address to);
+ virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
virtual void CodeDeleteEvent(Address from);
virtual void SnapshotPositionEvent(Address addr, int pos);
virtual void CodeMovingGCEvent();
// Open the low-level log file.
size_t len = strlen(name);
ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLogExt)));
- OS::MemCopy(ll_name.start(), name, len);
- OS::MemCopy(ll_name.start() + len, kLogExt, sizeof(kLogExt));
- ll_output_handle_ = OS::FOpen(ll_name.start(), OS::LogFileOpenMode);
+ MemCopy(ll_name.start(), name, len);
+ MemCopy(ll_name.start() + len, kLogExt, sizeof(kLogExt));
+ ll_output_handle_ =
+ base::OS::FOpen(ll_name.start(), base::OS::LogFileOpenMode);
setvbuf(ll_output_handle_, NULL, _IOFBF, kLogBufferSize);
LogCodeInfo();
void LowLevelLogger::LogCodeInfo() {
#if V8_TARGET_ARCH_IA32
const char arch[] = "ia32";
-#elif V8_TARGET_ARCH_X64
+#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT
const char arch[] = "x64";
+#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
+ const char arch[] = "x32";
#elif V8_TARGET_ARCH_ARM
const char arch[] = "arm";
#elif V8_TARGET_ARCH_MIPS
const char arch[] = "mips";
+#elif V8_TARGET_ARCH_X87
+ const char arch[] = "x87";
+#elif V8_TARGET_ARCH_ARM64
+ const char arch[] = "arm64";
#else
const char arch[] = "unknown";
#endif
CodeCreateStruct event;
event.name_size = length;
event.code_address = code->instruction_start();
- ASSERT(event.code_address == code->address() + Code::kHeaderSize);
+ DCHECK(event.code_address == code->address() + Code::kHeaderSize);
event.code_size = code->instruction_size();
LogWriteStruct(event);
LogWriteBytes(name, length);
void LowLevelLogger::LogWriteBytes(const char* bytes, int size) {
size_t rv = fwrite(bytes, 1, size, ll_output_handle_);
- ASSERT(static_cast<size_t>(size) == rv);
+ DCHECK(static_cast<size_t>(size) == rv);
USE(rv);
}
explicit JitLogger(JitCodeEventHandler code_event_handler);
virtual void CodeMoveEvent(Address from, Address to);
+ virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
virtual void CodeDeleteEvent(Address from);
virtual void AddCodeLinePosInfoEvent(
void* jit_handler_data,
void* StartCodePosInfoEvent();
void EndCodePosInfoEvent(Code* code, void* jit_handler_data);
-
- // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- // XDK needs all this stuff below to generate the strings like
- // "code-creation:..." in the same format as Logger generates.
- // This string is sent to XDK by code_event_handler and then used for
- // postprocessing. All these CodeCreateEvent(...) functions and helpers
- // will be removed before commit.
- void AppendCodeCreateHeader(NameBuffer* msg,
- Logger::LogEventsAndTags tag,
- Code* code) {
- CHECK(msg);
- msg->AppendBytes(kLogEventsNames[Logger::CODE_CREATION_EVENT]);
- msg->AppendByte(',');
- msg->AppendBytes(kLogEventsNames[tag]);
- msg->AppendByte(',');
- msg->AppendInt(code->kind());
- msg->AppendByte(',');
- msg->AppendAddress(code->instruction_start());
- msg->AppendByte(',');
- msg->AppendInt(code->instruction_size());
- msg->AppendByte(',');
- }
-
-
- void AppendDetailed(NameBuffer* msg, String* str, bool show_impl_info) {
- CHECK(msg);
- if (str == NULL) return;
- DisallowHeapAllocation no_gc; // Ensure string stay valid.
- int len = str->length();
- if (len > 0x1000)
- len = 0x1000;
- if (show_impl_info) {
- msg->AppendByte(str->IsOneByteRepresentation() ? 'a' : '2');
- if (StringShape(str).IsExternal())
- msg->AppendByte('e');
- if (StringShape(str).IsInternalized())
- msg->AppendByte('#');
- msg->AppendByte(':');
- msg->AppendInt(str->length());
- msg->AppendByte(':');
- }
- for (int i = 0; i < len; i++) {
- uc32 c = str->Get(i);
- if (c > 0xff) {
- msg->AppendBytes("\\u");
- msg->AppendHex(c);
- } else if (c < 32 || c > 126) {
- msg->AppendBytes("\\x");
- msg->AppendHex(c);
- } else if (c == ',') {
- msg->AppendBytes("\\,");
- } else if (c == '\\') {
- msg->AppendBytes("\\\\");
- } else if (c == '\"') {
- msg->AppendBytes("\"\"");
- } else {
- msg->AppendByte(c);
- }
- }
- }
-
-
- void AppendDoubleQuotedString(NameBuffer* msg, const char* string) {
- CHECK(msg);
- msg->AppendByte('"');
- for (const char* p = string; *p != '\0'; p++) {
- if (*p == '"') {
- msg->AppendByte('\\');
- }
- msg->AppendByte(*p);
- }
- msg->AppendByte('"');
- }
-
-
- void AppendSymbolName(NameBuffer* msg, Symbol* symbol) {
- CHECK(msg);
- ASSERT(symbol);
- msg->AppendBytes("symbol(");
- if (!symbol->name()->IsUndefined()) {
- msg->AppendByte('"');
- AppendDetailed(msg, String::cast(symbol->name()), false);
- msg->AppendBytes("\" ");
- }
- msg->AppendBytes("hash ");
- msg->AppendHex(symbol->Hash());
- msg->AppendByte(')');
- }
-
-
- virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code, const char* comment) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::CodeCreateEvent(tag, code, comment);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, tag, code);
- AppendDoubleQuotedString(name_buffer_, comment);
- LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
- }
-
-
- virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code, Name* name) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::CodeCreateEvent(tag, code, name);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, tag, code);
- if (name->IsString()) {
- name_buffer_->AppendByte('"');
- AppendDetailed(name_buffer_, String::cast(name), false);
- name_buffer_->AppendByte('"');
- } else {
- AppendSymbolName(name_buffer_, Symbol::cast(name));
- }
- LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
- }
-
-
- virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code,
- SharedFunctionInfo* shared,
- CompilationInfo* info,
- Name* name) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::CodeCreateEvent(tag, code, shared, info, name);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, tag, code);
- if (name->IsString()) {
- SmartArrayPointer<char> str =
- String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- name_buffer_->AppendByte('"');
- name_buffer_->AppendBytes(str.get());
- name_buffer_->AppendByte('"');
- } else {
- AppendSymbolName(name_buffer_, Symbol::cast(name));
- }
- name_buffer_->AppendByte(',');
- name_buffer_->AppendAddress(shared->address());
- name_buffer_->AppendByte(',');
- name_buffer_->AppendBytes(ComputeMarker(code));
- LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
- }
-
- virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code,
- SharedFunctionInfo* shared,
- CompilationInfo* info,
- Name* source,
- int line, int column) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::CodeCreateEvent(tag, code, shared,
- info, source, line, column);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, tag, code);
- SmartArrayPointer<char> name =
- shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- name_buffer_->AppendByte('"');
- name_buffer_->AppendBytes(name.get());
- name_buffer_->AppendByte(' ');
- if (source->IsString()) {
- SmartArrayPointer<char> sourcestr =
- String::cast(source)->ToCString(DISALLOW_NULLS,
- ROBUST_STRING_TRAVERSAL);
- name_buffer_->AppendBytes(sourcestr.get());
- } else {
- AppendSymbolName(name_buffer_, Symbol::cast(source));
- }
- name_buffer_->AppendByte(':');
- name_buffer_->AppendInt(line);
- name_buffer_->AppendByte(':');
- name_buffer_->AppendInt(column);
- name_buffer_->AppendBytes("\",");
- name_buffer_->AppendAddress(shared->address());
- name_buffer_->AppendByte(',');
- name_buffer_->AppendBytes(ComputeMarker(code));
- LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
- }
-
-
- virtual void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code,
- int args_count) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::CodeCreateEvent(tag, code, args_count);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, tag, code);
- name_buffer_->AppendBytes("\"args_count: ");
- name_buffer_->AppendInt(args_count);
- name_buffer_->AppendByte('"');
- }
-
-
- virtual void RegExpCodeCreateEvent(Code* code, String* source) {
- if (!xdk::XDKIsAgentAlive()) {
- CodeEventLogger::RegExpCodeCreateEvent(code, source);
- return;
- }
-
- name_buffer_->Reset();
- AppendCodeCreateHeader(name_buffer_, Logger::REG_EXP_TAG, code);
- name_buffer_->AppendByte('"');
- AppendDetailed(name_buffer_, source, false);
- name_buffer_->AppendByte('"');
- }
-
private:
virtual void LogRecordedBuffer(Code* code,
SharedFunctionInfo* shared,
event.type = JitCodeEvent::CODE_ADDED;
event.code_start = code->instruction_start();
event.code_len = code->instruction_size();
- Handle<Script> script_handle;
+ Handle<SharedFunctionInfo> shared_function_handle;
if (shared && shared->script()->IsScript()) {
- script_handle = Handle<Script>(Script::cast(shared->script()));
+ shared_function_handle = Handle<SharedFunctionInfo>(shared);
}
- event.script = ToApiHandle<v8::Script>(script_handle);
+ event.script = ToApiHandle<v8::UnboundScript>(shared_function_handle);
event.name.str = name;
event.name.len = length;
code_event_handler_(&event);
// An independent thread removes data and writes it to the log.
// This design minimizes the time spent in the sampler.
//
-class Profiler: public Thread {
+class Profiler: public base::Thread {
public:
explicit Profiler(Isolate* isolate);
void Engage();
int tail_; // Index to the buffer tail.
bool overflow_; // Tell whether a buffer overflow has occurred.
// Sempahore used for buffer synchronization.
- Semaphore buffer_semaphore_;
+ base::Semaphore buffer_semaphore_;
// Tells whether profiler is engaged, that is, processing thread is stated.
bool engaged_;
}
void SetProfiler(Profiler* profiler) {
- ASSERT(profiler_ == NULL);
+ DCHECK(profiler_ == NULL);
profiler_ = profiler;
IncreaseProfilingDepth();
if (!IsActive()) Start();
// Profiler implementation.
//
Profiler::Profiler(Isolate* isolate)
- : Thread("v8:Profiler"),
+ : base::Thread(Options("v8:Profiler")),
isolate_(isolate),
head_(0),
tail_(0),
buffer_semaphore_(0),
engaged_(false),
running_(false),
- paused_(false) {
-}
+ paused_(false) {}
void Profiler::Engage() {
if (engaged_) return;
engaged_ = true;
- OS::LogSharedLibraryAddresses(isolate_);
+ std::vector<base::OS::SharedLibraryAddress> addresses =
+ base::OS::GetSharedLibraryAddresses();
+ for (size_t i = 0; i < addresses.size(); ++i) {
+ LOG(isolate_, SharedLibraryEvent(
+ addresses[i].library_path, addresses[i].start, addresses[i].end));
+ }
// Start thread processing the profiler buffer.
running_ = true;
void Logger::addCodeEventListener(CodeEventListener* listener) {
- ASSERT(!hasCodeEventListener(listener));
+ DCHECK(!hasCodeEventListener(listener));
listeners_.Add(listener);
}
void Logger::removeCodeEventListener(CodeEventListener* listener) {
- ASSERT(hasCodeEventListener(listener));
+ DCHECK(hasCodeEventListener(listener));
listeners_.RemoveElement(listener);
}
void Logger::ProfilerBeginEvent() {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
- msg.Append("profiler,\"begin\",%d\n", kSamplingIntervalMs);
+ msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs);
msg.WriteToLogFile();
}
void Logger::UncheckedStringEvent(const char* name, const char* value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
- msg.Append("%s,\"%s\"\n", name, value);
+ msg.Append("%s,\"%s\"", name, value);
msg.WriteToLogFile();
}
void Logger::UncheckedIntEvent(const char* name, int value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
- msg.Append("%s,%d\n", name, value);
+ msg.Append("%s,%d", name, value);
msg.WriteToLogFile();
}
void Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
- msg.Append("%s,%" V8_PTR_PREFIX "d\n", name, value);
+ msg.Append("%s,%" V8_PTR_PREFIX "d", name, value);
msg.WriteToLogFile();
}
void Logger::HandleEvent(const char* name, Object** location) {
if (!log_->IsEnabled() || !FLAG_log_handles) return;
Log::MessageBuilder msg(log_);
- msg.Append("%s,0x%" V8PRIxPTR "\n", name, location);
+ msg.Append("%s,0x%" V8PRIxPTR, name, location);
msg.WriteToLogFile();
}
// caller's responsibility to ensure that log is enabled and that
// FLAG_log_api is true.
void Logger::ApiEvent(const char* format, ...) {
- ASSERT(log_->IsEnabled() && FLAG_log_api);
+ DCHECK(log_->IsEnabled() && FLAG_log_api);
Log::MessageBuilder msg(log_);
va_list ap;
va_start(ap, format);
if (key->IsString()) {
SmartArrayPointer<char> str =
String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,check-security,\"%s\"\n", str.get());
+ ApiEvent("api,check-security,\"%s\"", str.get());
} else if (key->IsSymbol()) {
Symbol* symbol = Symbol::cast(key);
if (symbol->name()->IsUndefined()) {
- ApiEvent("api,check-security,symbol(hash %x)\n",
- Symbol::cast(key)->Hash());
+ ApiEvent("api,check-security,symbol(hash %x)", Symbol::cast(key)->Hash());
} else {
SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString(
DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,check-security,symbol(\"%s\" hash %x)\n",
- str.get(),
+ ApiEvent("api,check-security,symbol(\"%s\" hash %x)", str.get(),
Symbol::cast(key)->Hash());
}
} else if (key->IsUndefined()) {
- ApiEvent("api,check-security,undefined\n");
+ ApiEvent("api,check-security,undefined");
} else {
- ApiEvent("api,check-security,['no-name']\n");
+ ApiEvent("api,check-security,['no-name']");
}
}
-void Logger::SharedLibraryEvent(const char* library_path,
+void Logger::SharedLibraryEvent(const std::string& library_path,
uintptr_t start,
uintptr_t end) {
if (!log_->IsEnabled() || !FLAG_prof) return;
Log::MessageBuilder msg(log_);
- msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
- library_path,
- start,
- end);
+ msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR,
+ library_path.c_str(), start, end);
msg.WriteToLogFile();
}
-void Logger::SharedLibraryEvent(const wchar_t* library_path,
- uintptr_t start,
- uintptr_t end) {
- if (!log_->IsEnabled() || !FLAG_prof) return;
+void Logger::CodeDeoptEvent(Code* code) {
+ if (!log_->IsEnabled()) return;
+ DCHECK(FLAG_log_internal_timer_events);
Log::MessageBuilder msg(log_);
- msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n",
- library_path,
- start,
- end);
+ int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
+ msg.Append("code-deopt,%ld,%d", since_epoch, code->CodeSize());
msg.WriteToLogFile();
}
-void Logger::CodeDeoptEvent(Code* code) {
+void Logger::CurrentTimeEvent() {
if (!log_->IsEnabled()) return;
- ASSERT(FLAG_log_internal_timer_events);
+ DCHECK(FLAG_log_internal_timer_events);
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
- msg.Append("code-deopt,%ld,%d\n", since_epoch, code->CodeSize());
+ msg.Append("current-time,%ld", since_epoch);
msg.WriteToLogFile();
}
-void Logger::TimerEvent(StartEnd se, const char* name) {
+void Logger::TimerEvent(Logger::StartEnd se, const char* name) {
if (!log_->IsEnabled()) return;
- ASSERT(FLAG_log_internal_timer_events);
+ DCHECK(FLAG_log_internal_timer_events);
Log::MessageBuilder msg(log_);
int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
- const char* format = (se == START) ? "timer-event-start,\"%s\",%ld\n"
- : "timer-event-end,\"%s\",%ld\n";
+ const char* format = (se == START) ? "timer-event-start,\"%s\",%ld"
+ : "timer-event-end,\"%s\",%ld";
msg.Append(format, name, since_epoch);
msg.WriteToLogFile();
}
void Logger::EnterExternal(Isolate* isolate) {
- LOG(isolate, TimerEvent(START, TimerEventScope::v8_external));
- ASSERT(isolate->current_vm_state() == JS);
+ LOG(isolate, TimerEvent(START, TimerEventExternal::name()));
+ DCHECK(isolate->current_vm_state() == JS);
isolate->set_current_vm_state(EXTERNAL);
}
void Logger::LeaveExternal(Isolate* isolate) {
- LOG(isolate, TimerEvent(END, TimerEventScope::v8_external));
- ASSERT(isolate->current_vm_state() == EXTERNAL);
+ LOG(isolate, TimerEvent(END, TimerEventExternal::name()));
+ DCHECK(isolate->current_vm_state() == EXTERNAL);
isolate->set_current_vm_state(JS);
}
-void Logger::TimerEventScope::LogTimerEvent(StartEnd se) {
- LOG(isolate_, TimerEvent(se, name_));
+void Logger::DefaultTimerEventsLogger(const char* name, int se) {
+ Isolate* isolate = Isolate::Current();
+ LOG(isolate, TimerEvent(static_cast<StartEnd>(se), name));
}
-const char* Logger::TimerEventScope::v8_recompile_synchronous =
- "V8.RecompileSynchronous";
-const char* Logger::TimerEventScope::v8_recompile_concurrent =
- "V8.RecompileConcurrent";
-const char* Logger::TimerEventScope::v8_compile_full_code =
- "V8.CompileFullCode";
-const char* Logger::TimerEventScope::v8_execute = "V8.Execute";
-const char* Logger::TimerEventScope::v8_external = "V8.External";
+template <class TimerEvent>
+void TimerEventScope<TimerEvent>::LogTimerEvent(Logger::StartEnd se) {
+ if (TimerEvent::expose_to_api() ||
+ isolate_->event_logger() == Logger::DefaultTimerEventsLogger) {
+ isolate_->event_logger()(TimerEvent::name(), se);
+ }
+}
+
+
+// Instantiate template methods.
+#define V(TimerName, expose) \
+ template void TimerEventScope<TimerEvent##TimerName>::LogTimerEvent( \
+ Logger::StartEnd se);
+TIMER_EVENTS_LIST(V)
+#undef V
void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
// (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
Log::MessageBuilder msg(log_);
- Handle<Object> source = GetProperty(regexp, "source");
+ Handle<Object> source = Object::GetProperty(
+ isolate_, regexp, "source").ToHandleChecked();
if (!source->IsString()) {
msg.Append("no source");
return;
msg.Append('/');
// global flag
- Handle<Object> global = GetProperty(regexp, "global");
+ Handle<Object> global = Object::GetProperty(
+ isolate_, regexp, "global").ToHandleChecked();
if (global->IsTrue()) {
msg.Append('g');
}
// ignorecase flag
- Handle<Object> ignorecase = GetProperty(regexp, "ignoreCase");
+ Handle<Object> ignorecase = Object::GetProperty(
+ isolate_, regexp, "ignoreCase").ToHandleChecked();
if (ignorecase->IsTrue()) {
msg.Append('i');
}
// multiline flag
- Handle<Object> multiline = GetProperty(regexp, "multiline");
+ Handle<Object> multiline = Object::GetProperty(
+ isolate_, regexp, "multiline").ToHandleChecked();
if (multiline->IsTrue()) {
msg.Append('m');
}
Log::MessageBuilder msg(log_);
msg.Append("regexp-compile,");
LogRegExpSource(regexp);
- msg.Append(in_cache ? ",hit\n" : ",miss\n");
- msg.WriteToLogFile();
-}
-
-
-void Logger::LogRuntime(Vector<const char> format,
- JSArray* args) {
- if (!log_->IsEnabled() || !FLAG_log_runtime) return;
- HandleScope scope(isolate_);
- Log::MessageBuilder msg(log_);
- for (int i = 0; i < format.length(); i++) {
- char c = format[i];
- if (c == '%' && i <= format.length() - 2) {
- i++;
- ASSERT('0' <= format[i] && format[i] <= '9');
- MaybeObject* maybe = args->GetElement(isolate_, format[i] - '0');
- Object* obj;
- if (!maybe->ToObject(&obj)) {
- msg.Append("<exception>");
- continue;
- }
- i++;
- switch (format[i]) {
- case 's':
- msg.AppendDetailed(String::cast(obj), false);
- break;
- case 'S':
- msg.AppendDetailed(String::cast(obj), true);
- break;
- case 'r':
- Logger::LogRegExpSource(Handle<JSRegExp>(JSRegExp::cast(obj)));
- break;
- case 'x':
- msg.Append("0x%x", Smi::cast(obj)->value());
- break;
- case 'i':
- msg.Append("%i", Smi::cast(obj)->value());
- break;
- default:
- UNREACHABLE();
- }
- } else {
- msg.Append(c);
- }
- }
- msg.Append('\n');
+ msg.Append(in_cache ? ",hit" : ",miss");
msg.WriteToLogFile();
}
void Logger::ApiIndexedSecurityCheck(uint32_t index) {
if (!log_->IsEnabled() || !FLAG_log_api) return;
- ApiEvent("api,check-security,%u\n", index);
+ ApiEvent("api,check-security,%u", index);
}
void Logger::ApiNamedPropertyAccess(const char* tag,
JSObject* holder,
Object* name) {
- ASSERT(name->IsName());
+ DCHECK(name->IsName());
if (!log_->IsEnabled() || !FLAG_log_api) return;
String* class_name_obj = holder->class_name();
SmartArrayPointer<char> class_name =
if (name->IsString()) {
SmartArrayPointer<char> property_name =
String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,%s,\"%s\",\"%s\"\n", tag, class_name.get(),
+ ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(),
property_name.get());
} else {
Symbol* symbol = Symbol::cast(name);
uint32_t hash = symbol->Hash();
if (symbol->name()->IsUndefined()) {
- ApiEvent("api,%s,\"%s\",symbol(hash %x)\n", tag, class_name.get(), hash);
+ ApiEvent("api,%s,\"%s\",symbol(hash %x)", tag, class_name.get(), hash);
} else {
SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString(
DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)\n",
- tag, class_name.get(), str.get(), hash);
+ ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)", tag, class_name.get(),
+ str.get(), hash);
}
}
}
String* class_name_obj = holder->class_name();
SmartArrayPointer<char> class_name =
class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,%s,\"%s\",%u\n", tag, class_name.get(), index);
+ ApiEvent("api,%s,\"%s\",%u", tag, class_name.get(), index);
}
String* class_name_obj = object->class_name();
SmartArrayPointer<char> class_name =
class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
- ApiEvent("api,%s,\"%s\"\n", tag, class_name.get());
+ ApiEvent("api,%s,\"%s\"", tag, class_name.get());
}
void Logger::ApiEntryCall(const char* name) {
if (!log_->IsEnabled() || !FLAG_log_api) return;
- ApiEvent("api,%s\n", name);
+ ApiEvent("api,%s", name);
}
void Logger::NewEvent(const char* name, void* object, size_t size) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
- msg.Append("new,%s,0x%" V8PRIxPTR ",%u\n", name, object,
+ msg.Append("new,%s,0x%" V8PRIxPTR ",%u", name, object,
static_cast<unsigned int>(size));
msg.WriteToLogFile();
}
void Logger::DeleteEvent(const char* name, void* object) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
- msg.Append("delete,%s,0x%" V8PRIxPTR "\n", name, object);
+ msg.Append("delete,%s,0x%" V8PRIxPTR, name, object);
msg.WriteToLogFile();
}
symbol->Hash());
}
}
- msg.Append('\n');
msg.WriteToLogFile();
}
static void AppendCodeCreateHeader(Log::MessageBuilder* msg,
Logger::LogEventsAndTags tag,
Code* code) {
- ASSERT(msg);
+ DCHECK(msg);
msg->Append("%s,%s,%d,",
kLogEventsNames[Logger::CODE_CREATION_EVENT],
kLogEventsNames[tag],
code->kind());
- if (xdk::XDKIsAgentAlive()) {
- msg->AppendAddress(code->instruction_start());
- msg->Append(",%d,", code->instruction_size());
- } else {
- msg->AppendAddress(code->address());
- msg->Append(",%d,", code->ExecutableSize());
- }
+ msg->AppendAddress(code->address());
+ msg->Append(",%d,", code->ExecutableSize());
}
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(&msg, tag, code);
msg.AppendDoubleQuotedString(comment);
- msg.Append('\n');
msg.WriteToLogFile();
}
} else {
msg.AppendSymbolName(Symbol::cast(name));
}
- msg.Append('\n');
msg.WriteToLogFile();
}
msg.Append(',');
msg.AppendAddress(shared->address());
msg.Append(",%s", ComputeMarker(code));
- msg.Append('\n');
msg.WriteToLogFile();
}
msg.Append(":%d:%d\",", line, column);
msg.AppendAddress(shared->address());
msg.Append(",%s", ComputeMarker(code));
- msg.Append('\n');
msg.WriteToLogFile();
}
Log::MessageBuilder msg(log_);
AppendCodeCreateHeader(&msg, tag, code);
msg.Append("\"args_count: %d\"", args_count);
- msg.Append('\n');
+ msg.WriteToLogFile();
+}
+
+
+void Logger::CodeDisableOptEvent(Code* code,
+ SharedFunctionInfo* shared) {
+ PROFILER_LOG(CodeDisableOptEvent(code, shared));
+
+ if (!is_logging_code_events()) return;
+ CALL_LISTENERS(CodeDisableOptEvent(code, shared));
+
+ if (!FLAG_log_code || !log_->IsEnabled()) return;
+ Log::MessageBuilder msg(log_);
+ msg.Append("%s,", kLogEventsNames[CODE_DISABLE_OPT_EVENT]);
+ SmartArrayPointer<char> name =
+ shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
+ msg.Append("\"%s\",", name.get());
+ msg.Append("\"%s\"", GetBailoutReason(shared->DisableOptimizationReason()));
msg.WriteToLogFile();
}
if (!is_logging_code_events()) return;
if (!log_->IsEnabled() || !FLAG_ll_prof) return;
CALL_LISTENERS(CodeMovingGCEvent());
- OS::SignalCodeMovingGC();
+ base::OS::SignalCodeMovingGC();
}
msg.Append('"');
msg.AppendDetailed(source, false);
msg.Append('"');
- msg.Append('\n');
msg.WriteToLogFile();
}
Log::MessageBuilder msg(log_);
msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]);
msg.AppendAddress(from);
- msg.Append('\n');
msg.WriteToLogFile();
}
Log::MessageBuilder msg(log_);
msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos);
msg.AppendDoubleQuotedString(code_name);
- msg.Append("\n");
msg.WriteToLogFile();
}
msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]);
msg.AppendAddress(addr);
msg.Append(",%d", pos);
- msg.Append('\n');
msg.WriteToLogFile();
}
Address from,
Address to) {
if (!FLAG_log_code || !log_->IsEnabled()) return;
-
- Code* from_code = NULL;
- Address to_code = NULL;
- if (xdk::XDKIsAgentAlive()) {
- from_code = Code::cast(HeapObject::FromAddress(from));
- const size_t header_size =
- from_code->instruction_start() - reinterpret_cast<byte*>(from_code);
- to_code =
- reinterpret_cast<byte*>(HeapObject::FromAddress(to)) + header_size;
- }
-
Log::MessageBuilder msg(log_);
msg.Append("%s,", kLogEventsNames[event]);
- if (xdk::XDKIsAgentAlive()) {
- msg.AppendAddress(from_code->instruction_start());
- } else {
- msg.AppendAddress(from);
- }
+ msg.AppendAddress(from);
msg.Append(',');
- if (xdk::XDKIsAgentAlive()) {
- msg.AppendAddress(to_code);
- } else {
- msg.AppendAddress(to);
- }
- msg.Append('\n');
+ msg.AppendAddress(to);
msg.WriteToLogFile();
}
msg.Append("%s,%s,", name, tag);
uint32_t sec, usec;
- if (OS::GetUserTime(&sec, &usec) != -1) {
+ if (base::OS::GetUserTime(&sec, &usec) != -1) {
msg.Append("%d,%d,", sec, usec);
}
- msg.Append("%.0f", OS::TimeCurrentMillis());
-
- msg.Append('\n');
+ msg.Append("%.0f", base::OS::TimeCurrentMillis());
msg.WriteToLogFile();
}
} else {
msg.AppendSymbolName(Symbol::cast(name));
}
- msg.Append('\n');
msg.WriteToLogFile();
}
Log::MessageBuilder msg(log_);
// Using non-relative system time in order to be able to synchronize with
// external memory profiling events (e.g. DOM memory size).
- msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f\n",
- space, kind, OS::TimeCurrentMillis());
+ msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f", space, kind,
+ base::OS::TimeCurrentMillis());
msg.WriteToLogFile();
}
void Logger::HeapSampleEndEvent(const char* space, const char* kind) {
if (!log_->IsEnabled() || !FLAG_log_gc) return;
Log::MessageBuilder msg(log_);
- msg.Append("heap-sample-end,\"%s\",\"%s\"\n", space, kind);
+ msg.Append("heap-sample-end,\"%s\",\"%s\"", space, kind);
msg.WriteToLogFile();
}
void Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
if (!log_->IsEnabled() || !FLAG_log_gc) return;
Log::MessageBuilder msg(log_);
- msg.Append("heap-sample-item,%s,%d,%d\n", type, number, bytes);
+ msg.Append("heap-sample-item,%s,%d,%d", type, number, bytes);
msg.WriteToLogFile();
}
void Logger::DebugTag(const char* call_site_tag) {
if (!log_->IsEnabled() || !FLAG_log) return;
Log::MessageBuilder msg(log_);
- msg.Append("debug-tag,%s\n", call_site_tag);
+ msg.Append("debug-tag,%s", call_site_tag);
msg.WriteToLogFile();
}
}
char* parameter_string = s.Finalize();
Log::MessageBuilder msg(log_);
- msg.Append("debug-queue-event,%s,%15.3f,%s\n",
- event_type,
- OS::TimeCurrentMillis(),
- parameter_string);
+ msg.Append("debug-queue-event,%s,%15.3f,%s", event_type,
+ base::OS::TimeCurrentMillis(), parameter_string);
DeleteArray(parameter_string);
msg.WriteToLogFile();
}
if (overflow) {
msg.Append(",overflow");
}
- for (int i = 0; i < sample->frames_count; ++i) {
+ for (unsigned i = 0; i < sample->frames_count; ++i) {
msg.Append(',');
msg.AppendAddress(sample->stack[i]);
}
- msg.Append('\n');
msg.WriteToLogFile();
}
-void Logger::XDKResumeProfiler() {
- if (!log_->IsEnabled()) return;
- if (profiler_ != NULL) {
- profiler_->resume();
- is_logging_ = true;
- }
-}
-
-
void Logger::StopProfiler() {
if (!log_->IsEnabled()) return;
if (profiler_ != NULL) {
sfis_[*count_] = Handle<SharedFunctionInfo>(sfi);
}
if (code_objects_ != NULL) {
- ASSERT(function->code()->kind() == Code::OPTIMIZED_FUNCTION);
+ DCHECK(function->code()->kind() == Code::OPTIMIZED_FUNCTION);
code_objects_[*count_] = Handle<Code>(function->code());
}
*count_ = *count_ + 1;
description = "A load IC from the snapshot";
tag = Logger::LOAD_IC_TAG;
break;
+ case Code::CALL_IC:
+ description = "A call IC from the snapshot";
+ tag = Logger::CALL_IC_TAG;
+ break;
case Code::STORE_IC:
description = "A store IC from the snapshot";
tag = Logger::STORE_IC_TAG;
void Logger::LogCodeObjects() {
- // Starting from Chromium v34 this function is also called from
- // V8::Initialize. This causes reading the heap to collect already
- // compiled methods. For XDK that must be done because XDK profiler
- // consumes CODE_ADDED events and mantains a map of compiled methods.
- if (xdk::XDKIsAgentAlive()) return;
-
Heap* heap = isolate_->heap();
heap->CollectAllGarbage(Heap::kMakeHeapIterableMask,
"Logger::LogCodeObjects");
Handle<String> func_name(shared->DebugName());
if (shared->script()->IsScript()) {
Handle<Script> script(Script::cast(shared->script()));
- int line_num = GetScriptLineNumber(script, shared->start_position()) + 1;
+ int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
int column_num =
- GetScriptColumnNumber(script, shared->start_position()) + 1;
+ Script::GetColumnNumber(script, shared->start_position()) + 1;
if (script->name()->IsString()) {
Handle<String> script_name(String::cast(script->name()));
if (line_num > 0) {
void Logger::LogCompiledFunctions() {
- // Starting from Chromium v34 this function is also called from
- // V8::Initialize. This causes reading the heap to collect already
- // compiled methods. For XDK that must be done because XDK profiler
- // consumes CODE_ADDED events and mantains a map of compiled methods.
- if (xdk::XDKIsAgentAlive()) return;
-
Heap* heap = isolate_->heap();
heap->CollectAllGarbage(Heap::kMakeHeapIterableMask,
"Logger::LogCompiledFunctions");
}
-static void AddIsolateIdIfNeeded(Isolate* isolate, StringStream* stream) {
- if (isolate->IsDefaultIsolate() || !FLAG_logfile_per_isolate) return;
- stream->Add("isolate-%p-", isolate);
-}
-
-
-static SmartArrayPointer<const char> PrepareLogFileName(
- Isolate* isolate, const char* file_name) {
- if (strchr(file_name, '%') != NULL || !isolate->IsDefaultIsolate()) {
- // If there's a '%' in the log file name we have to expand
- // placeholders.
- HeapStringAllocator allocator;
- StringStream stream(&allocator);
- AddIsolateIdIfNeeded(isolate, &stream);
- for (const char* p = file_name; *p; p++) {
- if (*p == '%') {
- p++;
- switch (*p) {
- case '\0':
- // If there's a % at the end of the string we back up
- // one character so we can escape the loop properly.
- p--;
- break;
- case 'p':
- stream.Add("%d", OS::GetCurrentProcessId());
- break;
- case 't': {
- // %t expands to the current time in milliseconds.
- double time = OS::TimeCurrentMillis();
- stream.Add("%.0f", FmtElm(time));
- break;
- }
- case '%':
- // %% expands (contracts really) to %.
- stream.Put('%');
- break;
- default:
- // All other %'s expand to themselves.
- stream.Put('%');
- stream.Put(*p);
- break;
- }
- } else {
- stream.Put(*p);
+static void AddIsolateIdIfNeeded(OStream& os, // NOLINT
+ Isolate* isolate) {
+ if (FLAG_logfile_per_isolate) os << "isolate-" << isolate << "-";
+}
+
+
+static void PrepareLogFileName(OStream& os, // NOLINT
+ Isolate* isolate, const char* file_name) {
+ AddIsolateIdIfNeeded(os, isolate);
+ for (const char* p = file_name; *p; p++) {
+ if (*p == '%') {
+ p++;
+ switch (*p) {
+ case '\0':
+ // If there's a % at the end of the string we back up
+ // one character so we can escape the loop properly.
+ p--;
+ break;
+ case 'p':
+ os << base::OS::GetCurrentProcessId();
+ break;
+ case 't':
+ // %t expands to the current time in milliseconds.
+ os << static_cast<int64_t>(base::OS::TimeCurrentMillis());
+ break;
+ case '%':
+ // %% expands (contracts really) to %.
+ os << '%';
+ break;
+ default:
+ // All other %'s expand to themselves.
+ os << '%' << *p;
+ break;
}
+ } else {
+ os << *p;
}
- return SmartArrayPointer<const char>(stream.ToCString());
}
- int length = StrLength(file_name);
- char* str = NewArray<char>(length + 1);
- OS::MemCopy(str, file_name, length);
- str[length] = '\0';
- return SmartArrayPointer<const char>(str);
}
FLAG_log_snapshot_positions = true;
}
- SmartArrayPointer<const char> log_file_name =
- PrepareLogFileName(isolate, FLAG_logfile);
- log_->Initialize(log_file_name.get());
+ OStringStream log_file_name;
+ PrepareLogFileName(log_file_name, isolate, FLAG_logfile);
+ log_->Initialize(log_file_name.c_str());
if (FLAG_perf_basic_prof) {
}
if (FLAG_ll_prof) {
- ll_logger_ = new LowLevelLogger(log_file_name.get());
+ ll_logger_ = new LowLevelLogger(log_file_name.c_str());
addCodeEventListener(ll_logger_);
}
is_logging_ = true;
}
- xdk::XDKInitializeForV8(isolate);
-
if (FLAG_prof) {
profiler_ = new Profiler(isolate);
is_logging_ = true;
profiler_->Engage();
-
- if (xdk::XDKIsAgentAlive()) {
- // A way to to start profiler in pause mode was removed.
- // To pause collection of the CPU ticks we need to emulate pause.
- // This will be removed later once XDK agent will have own sampler.
- profiler_->pause();
- }
}
if (FLAG_log_internal_timer_events || FLAG_prof) timer_.Start();