1ea91cc579ade536e3a08498a8157921dd4f533d1ager@chromium.org// Copyright 2011 the V8 project authors. All rights reserved.
23484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// Use of this source code is governed by a BSD-style license that can be
33484964a86451e86dcf04be9bd8c0d76ee04f081rossberg@chromium.org// found in the LICENSE file.
443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen#include <stdarg.h>
643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
7196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/v8.h"
8196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org
9b4ef18e93b120b995e067ba72707b62a448eeed6machenbach@chromium.org#include "src/bailout-reason.h"
105de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org#include "src/base/platform/platform.h"
11196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/bootstrapper.h"
12196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/code-stubs.h"
13196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/cpu-profiler.h"
14196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/deoptimizer.h"
15196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/global-handles.h"
16196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/log.h"
17196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/log-utils.h"
18196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/macro-assembler.h"
19d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org#include "src/perf-jit.h"
20196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/runtime-profiler.h"
21196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/serialize.h"
22196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/string-stream.h"
23196eb601290dc49c3754da728dc58700dff2de1bmachenbach@chromium.org#include "src/vm-state-inl.h"
2443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
2571affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace v8 {
2671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.orgnamespace internal {
2743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
2810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
29ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#define DECLARE_EVENT(ignore1, name) name,
30ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgstatic const char* const kLogEventsNames[Logger::NUMBER_OF_LOG_EVENTS] = {
31ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LOG_EVENTS_AND_TAGS_LIST(DECLARE_EVENT)
32ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org};
33ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#undef DECLARE_EVENT
34ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
35ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
36d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org#define CALL_LISTENERS(Call)                    \
37d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgfor (int i = 0; i < listeners_.length(); ++i) { \
38d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  listeners_[i]->Call;                          \
39d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org}
40d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
41c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org#define PROFILER_LOG(Call)                                \
42c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  do {                                                    \
43c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org    CpuProfiler* cpu_profiler = isolate_->cpu_profiler(); \
44c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org    if (cpu_profiler->is_profiling()) {                   \
45c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org      cpu_profiler->Call;                                 \
46c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org    }                                                     \
47c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  } while (false);
48c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org
49ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org// ComputeMarker must only be used when SharedFunctionInfo is known.
50ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgstatic const char* ComputeMarker(Code* code) {
51ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  switch (code->kind()) {
52ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    case Code::FUNCTION: return code->optimizable() ? "~" : "";
53ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    case Code::OPTIMIZED_FUNCTION: return "*";
54ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    default: return "";
55ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
56ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
57ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
58ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
59d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgclass CodeEventLogger::NameBuffer {
60ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org public:
61d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  NameBuffer() { Reset(); }
627ca89addc38b7479d2d7526d2043283ab7480ffcdanno@chromium.org
63d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void Reset() {
64d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    utf8_pos_ = 0;
65d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
66ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
67d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void Init(Logger::LogEventsAndTags tag) {
68d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    Reset();
69d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    AppendBytes(kLogEventsNames[tag]);
70d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    AppendByte(':');
71d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
72d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
73d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendName(Name* name) {
74d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (name->IsString()) {
75d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      AppendString(String::cast(name));
76d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    } else {
77d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      Symbol* symbol = Symbol::cast(name);
78d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      AppendBytes("symbol(");
79d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      if (!symbol->name()->IsUndefined()) {
80d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        AppendBytes("\"");
81d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        AppendString(String::cast(symbol->name()));
82d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        AppendBytes("\" ");
83ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      }
84d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      AppendBytes("hash ");
85d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      AppendHex(symbol->Hash());
86d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      AppendByte(')');
87ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    }
88d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
89ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
90d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendString(String* str) {
91d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (str == NULL) return;
92d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    int uc16_length = Min(str->length(), kUtf16BufferSize);
93d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    String::WriteToFlat(str, utf16_buffer, 0, uc16_length);
94d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    int previous = unibrow::Utf16::kNoPreviousCharacter;
95d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    for (int i = 0; i < uc16_length && utf8_pos_ < kUtf8BufferSize; ++i) {
96d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      uc16 c = utf16_buffer[i];
97d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      if (c <= unibrow::Utf8::kMaxOneByteChar) {
98d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        utf8_buffer_[utf8_pos_++] = static_cast<char>(c);
99d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      } else {
100d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        int char_length = unibrow::Utf8::Length(c, previous);
101d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        if (utf8_pos_ + char_length > kUtf8BufferSize) break;
102d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        unibrow::Utf8::Encode(utf8_buffer_ + utf8_pos_, c, previous);
103d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org        utf8_pos_ += char_length;
104c22f2d813ad21e25e8df5d4a371fd63f582e4262danno@chromium.org      }
105d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      previous = c;
106c22f2d813ad21e25e8df5d4a371fd63f582e4262danno@chromium.org    }
107d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
108ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
109d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendBytes(const char* bytes, int size) {
110d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    size = Min(size, kUtf8BufferSize - utf8_pos_);
111d06b9264b1c886fc80a100e9915cf8ae07fdb4e5machenbach@chromium.org    MemCopy(utf8_buffer_ + utf8_pos_, bytes, size);
112d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    utf8_pos_ += size;
113d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
114ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
115d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendBytes(const char* bytes) {
116d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    AppendBytes(bytes, StrLength(bytes));
117d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
118ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
119d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendByte(char c) {
120d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (utf8_pos_ >= kUtf8BufferSize) return;
121d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    utf8_buffer_[utf8_pos_++] = c;
122d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
123ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
124d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendInt(int n) {
125d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    Vector<char> buffer(utf8_buffer_ + utf8_pos_,
126d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                        kUtf8BufferSize - utf8_pos_);
12770ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org    int size = SNPrintF(buffer, "%d", n);
128d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
129d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      utf8_pos_ += size;
130ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    }
131d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
132ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
133d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  void AppendHex(uint32_t n) {
134d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    Vector<char> buffer(utf8_buffer_ + utf8_pos_,
135d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                        kUtf8BufferSize - utf8_pos_);
13670ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org    int size = SNPrintF(buffer, "%x", n);
137d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (size > 0 && utf8_pos_ + size <= kUtf8BufferSize) {
138d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      utf8_pos_ += size;
139c22f2d813ad21e25e8df5d4a371fd63f582e4262danno@chromium.org    }
140d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  }
141ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
142d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  const char* get() { return utf8_buffer_; }
143d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  int size() const { return utf8_pos_; }
144ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
145c22f2d813ad21e25e8df5d4a371fd63f582e4262danno@chromium.org private:
146d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  static const int kUtf8BufferSize = 512;
147d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  static const int kUtf16BufferSize = 128;
1487ca89addc38b7479d2d7526d2043283ab7480ffcdanno@chromium.org
149d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  int utf8_pos_;
150d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  char utf8_buffer_[kUtf8BufferSize];
151d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  uc16 utf16_buffer[kUtf16BufferSize];
152c22f2d813ad21e25e8df5d4a371fd63f582e4262danno@chromium.org};
1537ca89addc38b7479d2d7526d2043283ab7480ffcdanno@chromium.org
1547ca89addc38b7479d2d7526d2043283ab7480ffcdanno@chromium.org
155d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgCodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { }
156d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
157d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgCodeEventLogger::~CodeEventLogger() { delete name_buffer_; }
158d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
159d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
160ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
161ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      Code* code,
162ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      const char* comment) {
163d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(tag);
164d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendBytes(comment);
165d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
166ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
167ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
168ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
169ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
170ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      Code* code,
171ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      Name* name) {
172d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(tag);
173d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendName(name);
174d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
175ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
176ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
177ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
178ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
179d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      Code* code,
180d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      SharedFunctionInfo* shared,
181d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      CompilationInfo* info,
182d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      Name* name) {
183d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(tag);
184d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendBytes(ComputeMarker(code));
185d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendName(name);
186d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
187ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
188ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
189ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
190ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
191d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      Code* code,
192d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      SharedFunctionInfo* shared,
193d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                      CompilationInfo* info,
194dd6d9eedcac6e3b5adfb7702649ac32def9c3585mvstanton@chromium.org                                      Name* source, int line, int column) {
195d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(tag);
196d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendBytes(ComputeMarker(code));
197d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendString(shared->DebugName());
198d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendByte(' ');
199ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (source->IsString()) {
200d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    name_buffer_->AppendString(String::cast(source));
201ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  } else {
202d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    name_buffer_->AppendBytes("symbol(hash ");
203d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    name_buffer_->AppendHex(Name::cast(source)->Hash());
204d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    name_buffer_->AppendByte(')');
205ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
206d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendByte(':');
207d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendInt(line);
208d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, shared, name_buffer_->get(), name_buffer_->size());
209ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
210ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
211ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
212ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::CodeCreateEvent(Logger::LogEventsAndTags tag,
213ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      Code* code,
214ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                      int args_count) {
215d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(tag);
216d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendInt(args_count);
217d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
218ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
219ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
220ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
221ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid CodeEventLogger::RegExpCodeCreateEvent(Code* code, String* source) {
222d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->Init(Logger::REG_EXP_TAG);
223d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  name_buffer_->AppendString(source);
224d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogRecordedBuffer(code, NULL, name_buffer_->get(), name_buffer_->size());
225ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
226ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
227ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
228f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org// Linux perf tool logging support
229f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgclass PerfBasicLogger : public CodeEventLogger {
230f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org public:
231f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  PerfBasicLogger();
232f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  virtual ~PerfBasicLogger();
233f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
234f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  virtual void CodeMoveEvent(Address from, Address to) { }
235fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
236f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  virtual void CodeDeleteEvent(Address from) { }
237f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
238f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org private:
239f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  virtual void LogRecordedBuffer(Code* code,
240f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                 SharedFunctionInfo* shared,
241f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                 const char* name,
242f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                 int length);
243f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
244f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  // Extension added to V8 log file name to get the low-level log name.
245f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  static const char kFilenameFormatString[];
246f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  static const int kFilenameBufferPadding;
247f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
248f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  // File buffer size of the low-level log. We don't use the default to
249f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  // minimize the associated overhead.
250f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  static const int kLogBufferSize = 2 * MB;
251f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
252f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  FILE* perf_output_handle_;
253f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org};
254f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
255f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgconst char PerfBasicLogger::kFilenameFormatString[] = "/tmp/perf-%d.map";
256f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org// Extra space for the PID in the filename
257f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgconst int PerfBasicLogger::kFilenameBufferPadding = 16;
258f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
259f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgPerfBasicLogger::PerfBasicLogger()
260f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    : perf_output_handle_(NULL) {
261f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  // Open the perf JIT dump file.
262f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
263f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  ScopedVector<char> perf_dump_name(bufferSize);
26470ec1a2160dd946b9578d04d97d631a6d4ab4f8cbmeurer@chromium.org  int size = SNPrintF(
265f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org      perf_dump_name,
266f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org      kFilenameFormatString,
2675de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org      base::OS::GetCurrentProcessId());
268f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  CHECK_NE(size, -1);
2695de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  perf_output_handle_ =
2705de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org      base::OS::FOpen(perf_dump_name.start(), base::OS::LogFileOpenMode);
271f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  CHECK_NE(perf_output_handle_, NULL);
272f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize);
273f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org}
274f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
275f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
276f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgPerfBasicLogger::~PerfBasicLogger() {
277f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  fclose(perf_output_handle_);
278f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  perf_output_handle_ = NULL;
279f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org}
280f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
281f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
282f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgvoid PerfBasicLogger::LogRecordedBuffer(Code* code,
283f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                       SharedFunctionInfo*,
284f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                       const char* name,
285f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org                                       int length) {
286e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize);
287f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
2885de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::OS::FPrint(perf_output_handle_, "%llx %x %.*s\n",
2895de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org                   reinterpret_cast<uint64_t>(code->instruction_start()),
2905de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org                   code->instruction_size(), length, name);
291f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org}
292f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
293f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
29410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org// Low-level logging support.
295d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org#define LL_LOG(Call) if (ll_logger_) ll_logger_->Call;
296d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
297ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgclass LowLevelLogger : public CodeEventLogger {
29810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org public:
29910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  explicit LowLevelLogger(const char* file_name);
300ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  virtual ~LowLevelLogger();
30110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
302d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void CodeMoveEvent(Address from, Address to);
303fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
304d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void CodeDeleteEvent(Address from);
305d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void SnapshotPositionEvent(Address addr, int pos);
306d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void CodeMovingGCEvent();
30710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
30810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org private:
309ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  virtual void LogRecordedBuffer(Code* code,
310ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                 SharedFunctionInfo* shared,
311d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                 const char* name,
312d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                 int length);
31310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
314ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Low-level profiling event structures.
31510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  struct CodeCreateStruct {
31610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    static const char kTag = 'C';
31710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
31810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    int32_t name_size;
31910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    Address code_address;
32010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    int32_t code_size;
32110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  };
32210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
32310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
32410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  struct CodeMoveStruct {
32510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    static const char kTag = 'M';
32610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
32710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    Address from_address;
32810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    Address to_address;
32910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  };
33010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
33110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
33210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  struct CodeDeleteStruct {
33310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    static const char kTag = 'D';
33410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
33510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    Address address;
33610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  };
33710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
33810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
33910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  struct SnapshotPositionStruct {
34010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    static const char kTag = 'P';
34110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
34210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    Address address;
34310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    int32_t position;
34410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  };
34510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
34610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
34710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  static const char kCodeMovingGCTag = 'G';
34810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
34910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
35010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  // Extension added to V8 log file name to get the low-level log name.
35110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  static const char kLogExt[];
35210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
35310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  // File buffer size of the low-level log. We don't use the default to
35410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  // minimize the associated overhead.
35510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  static const int kLogBufferSize = 2 * MB;
35610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
35710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  void LogCodeInfo();
35810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  void LogWriteBytes(const char* bytes, int size);
35910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
36010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  template <typename T>
36110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  void LogWriteStruct(const T& s) {
36210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    char tag = T::kTag;
36310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    LogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag));
36410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    LogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s));
36510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  }
36610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
36710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  FILE* ll_output_handle_;
36810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org};
36910480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
37010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.orgconst char LowLevelLogger::kLogExt[] = ".ll";
37110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
372ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgLowLevelLogger::LowLevelLogger(const char* name)
373ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    : ll_output_handle_(NULL) {
374ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Open the low-level log file.
375ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  size_t len = strlen(name);
376ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLogExt)));
377d06b9264b1c886fc80a100e9915cf8ae07fdb4e5machenbach@chromium.org  MemCopy(ll_name.start(), name, len);
378d06b9264b1c886fc80a100e9915cf8ae07fdb4e5machenbach@chromium.org  MemCopy(ll_name.start() + len, kLogExt, sizeof(kLogExt));
3795de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  ll_output_handle_ =
3805de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org      base::OS::FOpen(ll_name.start(), base::OS::LogFileOpenMode);
381ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  setvbuf(ll_output_handle_, NULL, _IOFBF, kLogBufferSize);
382ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
383ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogCodeInfo();
384ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
385ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
386ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
387ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgLowLevelLogger::~LowLevelLogger() {
388ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  fclose(ll_output_handle_);
389ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  ll_output_handle_ = NULL;
390ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
391ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
392ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
393ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::LogCodeInfo() {
394ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#if V8_TARGET_ARCH_IA32
395ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char arch[] = "ia32";
39608e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_64_BIT
397ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char arch[] = "x64";
39808e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org#elif V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
39908e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org  const char arch[] = "x32";
400ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#elif V8_TARGET_ARCH_ARM
401ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char arch[] = "arm";
402ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#elif V8_TARGET_ARCH_MIPS
403ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char arch[] = "mips";
404864abd7677f434b5aef191e3388e71cd4dd1e6c8machenbach@chromium.org#elif V8_TARGET_ARCH_X87
405864abd7677f434b5aef191e3388e71cd4dd1e6c8machenbach@chromium.org  const char arch[] = "x87";
40608e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org#elif V8_TARGET_ARCH_ARM64
40708e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org  const char arch[] = "arm64";
408ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#else
409ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char arch[] = "unknown";
410ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org#endif
411ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteBytes(arch, sizeof(arch));
412ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
413ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
414ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
415ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::LogRecordedBuffer(Code* code,
416ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                       SharedFunctionInfo*,
417d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                       const char* name,
418d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                       int length) {
419ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  CodeCreateStruct event;
420d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  event.name_size = length;
421ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_address = code->instruction_start();
422e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(event.code_address == code->address() + Code::kHeaderSize);
423ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_size = code->instruction_size();
424ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteStruct(event);
425d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  LogWriteBytes(name, length);
426ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteBytes(
427ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      reinterpret_cast<const char*>(code->instruction_start()),
428ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      code->instruction_size());
429ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
430ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
431ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
432ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::CodeMoveEvent(Address from, Address to) {
433ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  CodeMoveStruct event;
434ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.from_address = from + Code::kHeaderSize;
435ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.to_address = to + Code::kHeaderSize;
436ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteStruct(event);
437ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
438ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
439ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
440ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::CodeDeleteEvent(Address from) {
441ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  CodeDeleteStruct event;
442ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.address = from + Code::kHeaderSize;
443ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteStruct(event);
444ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
445ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
446ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
447ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::SnapshotPositionEvent(Address addr, int pos) {
448ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  SnapshotPositionStruct event;
449ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.address = addr + Code::kHeaderSize;
450ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.position = pos;
451ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteStruct(event);
452ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
453ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
454ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
455ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::LogWriteBytes(const char* bytes, int size) {
456ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  size_t rv = fwrite(bytes, 1, size, ll_output_handle_);
457e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(static_cast<size_t>(size) == rv);
458ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  USE(rv);
459ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
460ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
461ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
462ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid LowLevelLogger::CodeMovingGCEvent() {
463ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const char tag = kCodeMovingGCTag;
464ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
465ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  LogWriteBytes(&tag, sizeof(tag));
466ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
467ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
468ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
469d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org#define JIT_LOG(Call) if (jit_logger_) jit_logger_->Call;
470ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
471ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
472ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgclass JitLogger : public CodeEventLogger {
473ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org public:
474ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  explicit JitLogger(JitCodeEventHandler code_event_handler);
475ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
476d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void CodeMoveEvent(Address from, Address to);
477fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  virtual void CodeDisableOptEvent(Code* code, SharedFunctionInfo* shared) { }
478d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void CodeDeleteEvent(Address from);
479d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  virtual void AddCodeLinePosInfoEvent(
480ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      void* jit_handler_data,
481ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      int pc_offset,
482ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      int position,
483ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      JitCodeEvent::PositionType position_type);
484d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
485ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  void* StartCodePosInfoEvent();
486ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  void EndCodePosInfoEvent(Code* code, void* jit_handler_data);
487ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
488ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org private:
489ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  virtual void LogRecordedBuffer(Code* code,
490ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                 SharedFunctionInfo* shared,
491d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                 const char* name,
492d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                 int length);
493ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
494ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEventHandler code_event_handler_;
495ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org};
496ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
497ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
498ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgJitLogger::JitLogger(JitCodeEventHandler code_event_handler)
499ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    : code_event_handler_(code_event_handler) {
500ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
501ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
502ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
503ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid JitLogger::LogRecordedBuffer(Code* code,
504ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  SharedFunctionInfo* shared,
505d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                  const char* name,
506d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org                                  int length) {
507ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
508ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  memset(&event, 0, sizeof(event));
509ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_ADDED;
510ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_start = code->instruction_start();
511ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_len = code->instruction_size();
512d6472083da14af6fde0101cc78f95ababd7cc077machenbach@chromium.org  Handle<SharedFunctionInfo> shared_function_handle;
513ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (shared && shared->script()->IsScript()) {
514d6472083da14af6fde0101cc78f95ababd7cc077machenbach@chromium.org    shared_function_handle = Handle<SharedFunctionInfo>(shared);
515ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
516d6472083da14af6fde0101cc78f95ababd7cc077machenbach@chromium.org  event.script = ToApiHandle<v8::UnboundScript>(shared_function_handle);
517d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  event.name.str = name;
518d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  event.name.len = length;
519ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
520ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
521ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
522ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
523c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.orgvoid JitLogger::CodeMoveEvent(Address from, Address to) {
524ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Code* from_code = Code::cast(HeapObject::FromAddress(from));
525ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
526ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
527ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_MOVED;
528ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_start = from_code->instruction_start();
529ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_len = from_code->instruction_size();
530ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
531ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Calculate the header size.
532ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  const size_t header_size =
533ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      from_code->instruction_start() - reinterpret_cast<byte*>(from_code);
534ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
535ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  // Calculate the new start address of the instructions.
536ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.new_code_start =
537ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      reinterpret_cast<byte*>(HeapObject::FromAddress(to)) + header_size;
538ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
539ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
540ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
541ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
542ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
543ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid JitLogger::CodeDeleteEvent(Address from) {
544ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Code* from_code = Code::cast(HeapObject::FromAddress(from));
545ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
546ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
547ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_REMOVED;
548ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_start = from_code->instruction_start();
549ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_len = from_code->instruction_size();
550ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
551ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
552ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
553ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
554ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid JitLogger::AddCodeLinePosInfoEvent(
555ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    void* jit_handler_data,
556ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    int pc_offset,
557ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    int position,
558ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    JitCodeEvent::PositionType position_type) {
559ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
560ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  memset(&event, 0, sizeof(event));
561ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_ADD_LINE_POS_INFO;
562ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.user_data = jit_handler_data;
563ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.line_info.offset = pc_offset;
564ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.line_info.pos = position;
565ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.line_info.position_type = position_type;
566ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
567ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
568ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
569ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
570ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
571ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid* JitLogger::StartCodePosInfoEvent() {
572ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
573ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  memset(&event, 0, sizeof(event));
574ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_START_LINE_INFO_RECORDING;
575ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
576ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
577ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  return event.user_data;
578ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
579ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
580ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
581ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid JitLogger::EndCodePosInfoEvent(Code* code, void* jit_handler_data) {
582ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JitCodeEvent event;
583ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  memset(&event, 0, sizeof(event));
584ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING;
585ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.code_start = code->instruction_start();
586ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  event.user_data = jit_handler_data;
587ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
588ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  code_event_handler_(&event);
589ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
590ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
591ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
59243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// The Profiler samples pc and sp values for the main thread.
59343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// Each sample is appended to a circular buffer.
59443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// An independent thread removes data and writes it to the log.
59543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// This design minimizes the time spent in the sampler.
59643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
5975de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.orgclass Profiler: public base::Thread {
59843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen public:
599ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  explicit Profiler(Isolate* isolate);
60043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  void Engage();
60143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  void Disengage();
60243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
60343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Inserts collected profiling data into buffer.
60443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  void Insert(TickSample* sample) {
605245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org    if (paused_)
606245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org      return;
607245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
60843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    if (Succ(head_) == tail_) {
60943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      overflow_ = true;
61043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    } else {
61143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      buffer_[head_] = *sample;
61243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      head_ = Succ(head_);
613e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org      buffer_semaphore_.Signal();  // Tell we have an element.
61443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    }
61543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
61643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
6171e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  virtual void Run();
6181e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org
6191e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  // Pause and Resume TickSample data collection.
6201e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  void pause() { paused_ = true; }
6211e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  void resume() { paused_ = false; }
6221e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org
6231e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org private:
62443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Waits for a signal and removes profiling data.
62543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  bool Remove(TickSample* sample) {
626e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org    buffer_semaphore_.Wait();  // Wait for an element.
62743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    *sample = buffer_[tail_];
62843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    bool result = overflow_;
62943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    tail_ = Succ(tail_);
63043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    overflow_ = false;
63143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    return result;
63243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
63343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
63443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Returns the next index in the cyclic buffer.
63543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  int Succ(int index) { return (index + 1) % kBufferSize; }
63643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
6376d786c9805481bd13ecb29c3155540f2f32950e1svenpanne@chromium.org  Isolate* isolate_;
63843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Cyclic buffer for communicating profiling samples
63943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // between the signal handler and the worker thread.
64043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  static const int kBufferSize = 128;
64143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  TickSample buffer_[kBufferSize];  // Buffer storage.
64243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  int head_;  // Index to the buffer head.
64343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  int tail_;  // Index to the buffer tail.
64443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  bool overflow_;  // Tell whether a buffer overflow has occurred.
6451e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  // Sempahore used for buffer synchronization.
6465de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::Semaphore buffer_semaphore_;
64743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
6483811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org  // Tells whether profiler is engaged, that is, processing thread is stated.
6493811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org  bool engaged_;
6503811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org
65143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Tells whether worker thread should continue running.
65243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  bool running_;
653245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
654245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org  // Tells whether we are currently recording tick samples.
655ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  bool paused_;
65643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen};
65743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
65843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
65943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
66043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// Ticker used to provide ticks to the profiler and the sliding state
66143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// window.
66243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
6639a4089a092cad9ff23b6416b92cd5d818dc101d1mads.s.ager@gmail.comclass Ticker: public Sampler {
66443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen public:
66574f333bce721daf6b1f9d7d3d3faa623f77658d7vegorov@chromium.org  Ticker(Isolate* isolate, int interval):
666ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      Sampler(isolate, interval),
667a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      profiler_(NULL) {}
66843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
66943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  ~Ticker() { if (IsActive()) Stop(); }
67043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
6714a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org  virtual void Tick(TickSample* sample) {
67243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    if (profiler_) profiler_->Insert(sample);
67343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
67443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
67543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  void SetProfiler(Profiler* profiler) {
676e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org    DCHECK(profiler_ == NULL);
67743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    profiler_ = profiler;
678a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    IncreaseProfilingDepth();
679dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    if (!IsActive()) Start();
68043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
68143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
68243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  void ClearProfiler() {
68343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    profiler_ = NULL;
6845323a9c29497eb5a52821d396990c6d75a37baf7jkummerow@chromium.org    if (IsActive()) Stop();
685dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    DecreaseProfilingDepth();
68643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
68743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
68843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen private:
68943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  Profiler* profiler_;
69043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen};
69143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
69243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
69343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
69443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// Profiler implementation.
69543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen//
696ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgProfiler::Profiler(Isolate* isolate)
6975e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org    : base::Thread(Options("v8:Profiler")),
6986d786c9805481bd13ecb29c3155540f2f32950e1svenpanne@chromium.org      isolate_(isolate),
6995d00b60c201d860c74821f553fdc34f4e057b411lrn@chromium.org      head_(0),
7003811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org      tail_(0),
7013811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org      overflow_(false),
702e900018c7a2a695fde788911564da37535c7e736mstarzinger@chromium.org      buffer_semaphore_(0),
7033811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org      engaged_(false),
704ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      running_(false),
7055e57059e20217fd540b60c237d326414afe2171emachenbach@chromium.org      paused_(false) {}
70643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
70743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
70843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Profiler::Engage() {
7093811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org  if (engaged_) return;
7103811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org  engaged_ = true;
7113811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org
7125de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  std::vector<base::OS::SharedLibraryAddress> addresses =
7135de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org      base::OS::GetSharedLibraryAddresses();
7141845eb0120c7a870d7388de091246a7d1b48a4f8machenbach@chromium.org  for (size_t i = 0; i < addresses.size(); ++i) {
7151845eb0120c7a870d7388de091246a7d1b48a4f8machenbach@chromium.org    LOG(isolate_, SharedLibraryEvent(
7161845eb0120c7a870d7388de091246a7d1b48a4f8machenbach@chromium.org        addresses[i].library_path, addresses[i].start, addresses[i].end));
7171845eb0120c7a870d7388de091246a7d1b48a4f8machenbach@chromium.org  }
71843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
71943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Start thread processing the profiler buffer.
72043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  running_ = true;
72143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  Start();
72243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
72343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Register to get ticks.
724e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  Logger* logger = isolate_->logger();
725e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  logger->ticker_->SetProfiler(this);
72643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
727e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  logger->ProfilerBeginEvent();
72843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
72943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
73043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
73143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Profiler::Disengage() {
7323811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org  if (!engaged_) return;
7333811b436bf328d2ace6fe79ce99aeda71f9f06d3ager@chromium.org
73443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Stop receiving ticks.
735e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  isolate_->logger()->ticker_->ClearProfiler();
73643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
73743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Terminate the worker thread by setting running_ to false,
73843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // inserting a fake element in the queue and then wait for
73943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // the thread to terminate.
74043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  running_ = false;
74143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  TickSample sample;
74271affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  // Reset 'paused_' flag, otherwise semaphore may not be signalled.
74371affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  resume();
74443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  Insert(&sample);
74543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  Join();
74643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
747c5d4971574b7a205fa0e788d8121dc79485e5e67hpayer@chromium.org  LOG(isolate_, UncheckedStringEvent("profiler", "end"));
74843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
74943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
75043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
75143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Profiler::Run() {
75243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  TickSample sample;
753ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  bool overflow = Remove(&sample);
754ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  while (running_) {
755ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    LOG(isolate_, TickEvent(&sample, overflow));
756ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    overflow = Remove(&sample);
757750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
758ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org}
759750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org
7608e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org
761ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org//
762ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org// Logger class implementation.
763ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org//
7648e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org
765c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.orgLogger::Logger(Isolate* isolate)
766c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  : isolate_(isolate),
767c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org    ticker_(NULL),
768ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    profiler_(NULL),
769ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    log_events_(NULL),
770dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    is_logging_(false),
771ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org    log_(new Log(this)),
772f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_basic_logger_(NULL),
773f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_jit_logger_(NULL),
77410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    ll_logger_(NULL),
775ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    jit_logger_(NULL),
776d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    listeners_(5),
777dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    is_initialized_(false) {
778ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org}
779ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
7808e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org
781ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgLogger::~Logger() {
782ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  delete log_;
783ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org}
784eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org
7858e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org
786d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgvoid Logger::addCodeEventListener(CodeEventListener* listener) {
787e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(!hasCodeEventListener(listener));
788d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  listeners_.Add(listener);
789d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org}
790d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
791d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
792d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgvoid Logger::removeCodeEventListener(CodeEventListener* listener) {
793e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(hasCodeEventListener(listener));
794d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  listeners_.RemoveElement(listener);
795d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org}
796d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
797d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
798d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgbool Logger::hasCodeEventListener(CodeEventListener* listener) {
799d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  return listeners_.Contains(listener);
800d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org}
801d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
802d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
803755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.orgvoid Logger::ProfilerBeginEvent() {
804ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled()) return;
805ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
8069bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs);
807755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org  msg.WriteToLogFile();
808755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org}
809755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org
810381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org
81143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::StringEvent(const char* name, const char* value) {
8126f10e41fef1524c70846d970268de222e41c594cager@chromium.org  if (FLAG_log) UncheckedStringEvent(name, value);
8136f10e41fef1524c70846d970268de222e41c594cager@chromium.org}
8146f10e41fef1524c70846d970268de222e41c594cager@chromium.org
8156f10e41fef1524c70846d970268de222e41c594cager@chromium.org
8166f10e41fef1524c70846d970268de222e41c594cager@chromium.orgvoid Logger::UncheckedStringEvent(const char* name, const char* value) {
817ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled()) return;
818ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
8199bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("%s,\"%s\"", name, value);
820381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
82143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
82243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
82343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
82443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::IntEvent(const char* name, int value) {
825ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org  if (FLAG_log) UncheckedIntEvent(name, value);
826ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org}
827ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org
828ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org
829f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.orgvoid Logger::IntPtrTEvent(const char* name, intptr_t value) {
830f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org  if (FLAG_log) UncheckedIntPtrTEvent(name, value);
831f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org}
832f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org
833f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org
834ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.orgvoid Logger::UncheckedIntEvent(const char* name, int value) {
835ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled()) return;
836ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
8379bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("%s,%d", name, value);
838381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
83943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
84043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
84143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
842f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.orgvoid Logger::UncheckedIntPtrTEvent(const char* name, intptr_t value) {
843ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled()) return;
844ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
8459bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("%s,%" V8_PTR_PREFIX "d", name, value);
846f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org  msg.WriteToLogFile();
847f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org}
848f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org
849f05f2913e034b9332e55c02c9395e701725c02c1kmillikin@chromium.org
85043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::HandleEvent(const char* name, Object** location) {
851ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_handles) return;
852ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
8539bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("%s,0x%" V8PRIxPTR, name, location);
854381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
85543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
85643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
85743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
85843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// ApiEvent is private so all the calls come from the Logger class.  It is the
8599085a016223a6b72bf580d5781c93ec7b9e54422ager@chromium.org// caller's responsibility to ensure that log is enabled and that
86043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen// FLAG_log_api is true.
86143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiEvent(const char* format, ...) {
862e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(log_->IsEnabled() && FLAG_log_api);
863ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
86443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  va_list ap;
86543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  va_start(ap, format);
866eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org  msg.AppendVA(format, ap);
867381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  va_end(ap);
868381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
86943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
87043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
87143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
87243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiNamedSecurityCheck(Object* key) {
873ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
87443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  if (key->IsString()) {
87583e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org    SmartArrayPointer<char> str =
87643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen        String::cast(key)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
8779bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org    ApiEvent("api,check-security,\"%s\"", str.get());
878750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else if (key->IsSymbol()) {
879f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    Symbol* symbol = Symbol::cast(key);
880f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    if (symbol->name()->IsUndefined()) {
8819bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org      ApiEvent("api,check-security,symbol(hash %x)", Symbol::cast(key)->Hash());
882f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    } else {
883f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString(
884f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org          DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
8859bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org      ApiEvent("api,check-security,symbol(\"%s\" hash %x)", str.get(),
886f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org               Symbol::cast(key)->Hash());
887f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    }
88843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  } else if (key->IsUndefined()) {
8899bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org    ApiEvent("api,check-security,undefined");
89043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  } else {
8919bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org    ApiEvent("api,check-security,['no-name']");
89243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
89343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
89443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
89543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
8961845eb0120c7a870d7388de091246a7d1b48a4f8machenbach@chromium.orgvoid Logger::SharedLibraryEvent(const std::string& library_path,
8975aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org                                uintptr_t start,
8985aa501ca9fb4dfb30f4191aac135202fe8d80e4aager@chromium.org                                uintptr_t end) {
899ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_prof) return;
900ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
9019bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR,
9029bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org             library_path.c_str(), start, end);
903381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
90443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
90543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
906b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
907c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.orgvoid Logger::CodeDeoptEvent(Code* code) {
908c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org  if (!log_->IsEnabled()) return;
909e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(FLAG_log_internal_timer_events);
910ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
911dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
9129bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("code-deopt,%ld,%d", since_epoch, code->CodeSize());
913c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org  msg.WriteToLogFile();
914c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org}
915c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org
916c1789eecd43bf9c5497636592bf14fa754d04c89machenbach@chromium.org
91770d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.orgvoid Logger::CurrentTimeEvent() {
91870d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org  if (!log_->IsEnabled()) return;
919e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(FLAG_log_internal_timer_events);
92070d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org  Log::MessageBuilder msg(log_);
92170d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org  int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
9229bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("current-time,%ld", since_epoch);
92370d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org  msg.WriteToLogFile();
92470d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org}
92570d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org
92670d11c79c7833b9ab1ee185625fcf707b9480a40machenbach@chromium.org
9274c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.orgvoid Logger::TimerEvent(Logger::StartEnd se, const char* name) {
9281f34ad3eadf9b0e6b8ed415817d276f54dd6d06bdanno@chromium.org  if (!log_->IsEnabled()) return;
929e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(FLAG_log_internal_timer_events);
930ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
931dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  int since_epoch = static_cast<int>(timer_.Elapsed().InMicroseconds());
9329bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  const char* format = (se == START) ? "timer-event-start,\"%s\",%ld"
9339bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org                                     : "timer-event-end,\"%s\",%ld";
934068ea0a6ea115c058d1d9798029bd7fa1eaaa955mstarzinger@chromium.org  msg.Append(format, name, since_epoch);
9358e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org  msg.WriteToLogFile();
9368e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org}
9378e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
9388e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
939ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.orgvoid Logger::EnterExternal(Isolate* isolate) {
9404c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org  LOG(isolate, TimerEvent(START, TimerEventExternal::name()));
941e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(isolate->current_vm_state() == JS);
942ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.org  isolate->set_current_vm_state(EXTERNAL);
94383130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org}
94483130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org
94583130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org
946ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.orgvoid Logger::LeaveExternal(Isolate* isolate) {
9474c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org  LOG(isolate, TimerEvent(END, TimerEventExternal::name()));
948e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(isolate->current_vm_state() == EXTERNAL);
949ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.org  isolate->set_current_vm_state(JS);
95083130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org}
95183130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org
95283130cfc204d3ffed6832a7ef149b19328a58b33svenpanne@chromium.org
9534c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.orgvoid Logger::DefaultTimerEventsLogger(const char* name, int se) {
954ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org  Isolate* isolate = Isolate::Current();
955ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org  LOG(isolate, TimerEvent(static_cast<StartEnd>(se), name));
956ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org}
957ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org
958ca2f2040e0e1a10df95bec18e69499f85f4c1316machenbach@chromium.org
9594c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.orgtemplate <class TimerEvent>
9604c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.orgvoid TimerEventScope<TimerEvent>::LogTimerEvent(Logger::StartEnd se) {
9614c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org  if (TimerEvent::expose_to_api() ||
9624c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org      isolate_->event_logger() == Logger::DefaultTimerEventsLogger) {
9634c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org    isolate_->event_logger()(TimerEvent::name(), se);
9644c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org  }
9651f34ad3eadf9b0e6b8ed415817d276f54dd6d06bdanno@chromium.org}
9661f34ad3eadf9b0e6b8ed415817d276f54dd6d06bdanno@chromium.org
9671f34ad3eadf9b0e6b8ed415817d276f54dd6d06bdanno@chromium.org
9684c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org// Instantiate template methods.
9694c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org#define V(TimerName, expose)                                           \
9704c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org  template void TimerEventScope<TimerEvent##TimerName>::LogTimerEvent( \
9714c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org      Logger::StartEnd se);
9724c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.orgTIMER_EVENTS_LIST(V)
9734c3ce7c3fd2802da8f91c6516a9c9aea3cd93f1emachenbach@chromium.org#undef V
9748e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
9758e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
976236ad9617a7359a463144a6ebeb5431a70f769cfager@chromium.orgvoid Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
977b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  // Prints "/" + re.source + "/" +
978b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  //      (re.global?"g":"") + (re.ignorecase?"i":"") + (re.multiline?"m":"")
979ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
980b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
9819fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org  Handle<Object> source = Object::GetProperty(
9829fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org      isolate_, regexp, "source").ToHandleChecked();
983b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  if (!source->IsString()) {
984381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append("no source");
985b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org    return;
986b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  }
987b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
9889fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.org  switch (regexp->TypeTag()) {
98941044eb0969b0d7d5c041a077519a36efa6aff27kasperl@chromium.org    case JSRegExp::ATOM:
990381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org      msg.Append('a');
99141044eb0969b0d7d5c041a077519a36efa6aff27kasperl@chromium.org      break;
99241044eb0969b0d7d5c041a077519a36efa6aff27kasperl@chromium.org    default:
99341044eb0969b0d7d5c041a077519a36efa6aff27kasperl@chromium.org      break;
99441044eb0969b0d7d5c041a077519a36efa6aff27kasperl@chromium.org  }
995381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append('/');
996381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.AppendDetailed(*Handle<String>::cast(source), false);
997381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append('/');
998b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
999b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  // global flag
10009fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org  Handle<Object> global = Object::GetProperty(
10019fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org      isolate_, regexp, "global").ToHandleChecked();
1002b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  if (global->IsTrue()) {
1003381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append('g');
1004b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  }
1005b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  // ignorecase flag
10069fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org  Handle<Object> ignorecase = Object::GetProperty(
10079fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org      isolate_, regexp, "ignoreCase").ToHandleChecked();
1008b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  if (ignorecase->IsTrue()) {
1009381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append('i');
1010b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  }
1011b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  // multiline flag
10129fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org  Handle<Object> multiline = Object::GetProperty(
10139fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org      isolate_, regexp, "multiline").ToHandleChecked();
1014b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  if (multiline->IsTrue()) {
1015381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append('m');
1016b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  }
1017381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org
1018381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
1019b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org}
1020b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
1021b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
10229fe21c6d4c657d15af27c8751257d3e2bf113e45kasperl@chromium.orgvoid Logger::RegExpCompileEvent(Handle<JSRegExp> regexp, bool in_cache) {
1023ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_regexp) return;
1024ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
1025381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append("regexp-compile,");
1026b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org  LogRegExpSource(regexp);
10279bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append(in_cache ? ",hit" : ",miss");
1028381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
1029b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org}
1030b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
1031b912362e2b2e704d09faac4290e027fd744bf587kasperl@chromium.org
103243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiIndexedSecurityCheck(uint32_t index) {
1033ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
10349bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  ApiEvent("api,check-security,%u", index);
103543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
103643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
103743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
103843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiNamedPropertyAccess(const char* tag,
103943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen                                    JSObject* holder,
104043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen                                    Object* name) {
1041e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(name->IsName());
1042ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
104343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  String* class_name_obj = holder->class_name();
104483e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  SmartArrayPointer<char> class_name =
104543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1046750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (name->IsString()) {
1047750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    SmartArrayPointer<char> property_name =
1048750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org        String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
10499bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org    ApiEvent("api,%s,\"%s\",\"%s\"", tag, class_name.get(),
1050afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org             property_name.get());
1051750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1052f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    Symbol* symbol = Symbol::cast(name);
1053f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    uint32_t hash = symbol->Hash();
1054f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    if (symbol->name()->IsUndefined()) {
10559bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org      ApiEvent("api,%s,\"%s\",symbol(hash %x)", tag, class_name.get(), hash);
1056f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    } else {
1057f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString(
1058f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org          DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
10599bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org      ApiEvent("api,%s,\"%s\",symbol(\"%s\" hash %x)", tag, class_name.get(),
10609bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org               str.get(), hash);
1061f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    }
1062750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
106343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
106443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
106543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiIndexedPropertyAccess(const char* tag,
106643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen                                      JSObject* holder,
106743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen                                      uint32_t index) {
1068ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
106943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  String* class_name_obj = holder->class_name();
107083e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  SmartArrayPointer<char> class_name =
107143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
10729bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  ApiEvent("api,%s,\"%s\",%u", tag, class_name.get(), index);
107343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
107443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1075e0e1b0d3e70c933d36ed381d511e9fda39f2a751mstarzinger@chromium.org
107643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiObjectAccess(const char* tag, JSObject* object) {
1077ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
107843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  String* class_name_obj = object->class_name();
107983e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  SmartArrayPointer<char> class_name =
108043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen      class_name_obj->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
10819bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  ApiEvent("api,%s,\"%s\"", tag, class_name.get());
108243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
108343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
108443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
108543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ApiEntryCall(const char* name) {
1086ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_api) return;
10879bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  ApiEvent("api,%s", name);
108843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
108943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
109043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
109143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::NewEvent(const char* name, void* object, size_t size) {
1092ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log) return;
1093ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
10949bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("new,%s,0x%" V8PRIxPTR ",%u", name, object,
1095381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org             static_cast<unsigned int>(size));
1096381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
109743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
109843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
109943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
110043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::DeleteEvent(const char* name, void* object) {
1101ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log) return;
1102ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
11039bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("delete,%s,0x%" V8PRIxPTR, name, object);
1104381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
110543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
110643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
110743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1108ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgvoid Logger::NewEventStatic(const char* name, void* object, size_t size) {
1109e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  Isolate::Current()->logger()->NewEvent(name, object, size);
1110ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org}
1111ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1112ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1113ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgvoid Logger::DeleteEventStatic(const char* name, void* object) {
1114e27d617298263725e8a48c2aa14029759b952623mstarzinger@chromium.org  Isolate::Current()->logger()->DeleteEvent(name, object);
1115ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org}
1116ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1117ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1118750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgvoid Logger::CallbackEventInternal(const char* prefix, Name* name,
1119ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org                                   Address entry_point) {
1120c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1121ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
11221510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg.Append("%s,%s,-2,",
11235f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org             kLogEventsNames[CODE_CREATION_EVENT],
11245f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org             kLogEventsNames[CALLBACK_TAG]);
112501beca7f8d9f549e04ec575a0bca96d859ab55a5ager@chromium.org  msg.AppendAddress(entry_point);
1126750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (name->IsString()) {
1127750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    SmartArrayPointer<char> str =
1128750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org        String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1129afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org    msg.Append(",1,\"%s%s\"", prefix, str.get());
1130750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1131f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    Symbol* symbol = Symbol::cast(name);
1132f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    if (symbol->name()->IsUndefined()) {
1133f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      msg.Append(",1,symbol(hash %x)", prefix, symbol->Hash());
1134f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    } else {
1135f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      SmartArrayPointer<char> str = String::cast(symbol->name())->ToCString(
1136f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org          DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1137afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org      msg.Append(",1,symbol(\"%s\" hash %x)", prefix, str.get(),
1138afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org                 symbol->Hash());
1139f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    }
1140750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
114101beca7f8d9f549e04ec575a0bca96d859ab55a5ager@chromium.org  msg.WriteToLogFile();
1142ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org}
1143ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1144ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1145750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgvoid Logger::CallbackEvent(Name* name, Address entry_point) {
1146c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CallbackEvent(name, entry_point));
1147750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  CallbackEventInternal("", name, entry_point);
1148ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org}
1149ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1150ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1151750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgvoid Logger::GetterCallbackEvent(Name* name, Address entry_point) {
1152c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(GetterCallbackEvent(name, entry_point));
1153750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  CallbackEventInternal("get ", name, entry_point);
1154ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org}
1155ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1156ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1157750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgvoid Logger::SetterCallbackEvent(Name* name, Address entry_point) {
1158c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(SetterCallbackEvent(name, entry_point));
1159750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  CallbackEventInternal("set ", name, entry_point);
116001beca7f8d9f549e04ec575a0bca96d859ab55a5ager@chromium.org}
116101beca7f8d9f549e04ec575a0bca96d859ab55a5ager@chromium.org
116201beca7f8d9f549e04ec575a0bca96d859ab55a5ager@chromium.org
1163ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgstatic void AppendCodeCreateHeader(Log::MessageBuilder* msg,
1164ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                   Logger::LogEventsAndTags tag,
1165ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                   Code* code) {
1166e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org  DCHECK(msg);
11671510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg->Append("%s,%s,%d,",
1168ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org              kLogEventsNames[Logger::CODE_CREATION_EVENT],
11691510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org              kLogEventsNames[tag],
11701510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org              code->kind());
11711510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg->AppendAddress(code->address());
11721510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg->Append(",%d,", code->ExecutableSize());
11731510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org}
11741510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
11751510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
11761510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.orgvoid Logger::CodeCreateEvent(LogEventsAndTags tag,
11771510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                             Code* code,
11781510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org                             const char* comment) {
1179c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeCreateEvent(tag, code, comment));
1180ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1181c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1182d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeCreateEvent(tag, code, comment));
11831510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
11841510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1185ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
11861510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, tag, code);
11871510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg.AppendDoubleQuotedString(comment);
1188381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
118943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
119043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
119143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
11923a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.orgvoid Logger::CodeCreateEvent(LogEventsAndTags tag,
11933a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                             Code* code,
1194750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org                             Name* name) {
1195c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeCreateEvent(tag, code, name));
1196ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1197c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1198d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeCreateEvent(tag, code, name));
11991510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
12001510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1201ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
12021510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, tag, code);
1203750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (name->IsString()) {
1204750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.Append('"');
1205750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.AppendDetailed(String::cast(name), false);
1206750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.Append('"');
1207750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1208ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    msg.AppendSymbolName(Symbol::cast(name));
1209750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
12108e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org  msg.WriteToLogFile();
12113a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org}
12123a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org
12133a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org
12143a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.orgvoid Logger::CodeCreateEvent(LogEventsAndTags tag,
12153a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                             Code* code,
12163a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                             SharedFunctionInfo* shared,
12174e308cf00936c6e7bead43e5141a04e37b49b9b5jkummerow@chromium.org                             CompilationInfo* info,
1218750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org                             Name* name) {
1219c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, name));
1220ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1221c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1222d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, name));
12231510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
12241510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1225a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org  if (code == isolate_->builtins()->builtin(Builtins::kCompileLazy)) return;
1226ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1227ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
12281510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, tag, code);
1229750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (name->IsString()) {
1230750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    SmartArrayPointer<char> str =
1231750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org        String::cast(name)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1232afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org    msg.Append("\"%s\"", str.get());
1233750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1234ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    msg.AppendSymbolName(Symbol::cast(name));
1235750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
1236750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  msg.Append(',');
12373a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org  msg.AppendAddress(shared->address());
12383a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org  msg.Append(",%s", ComputeMarker(code));
1239381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
124043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
124143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
124243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
12433a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org// Although, it is possible to extract source and line from
12443a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org// the SharedFunctionInfo object, we left it to caller
12453a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org// to leave logging functions free from heap allocations.
1246eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.orgvoid Logger::CodeCreateEvent(LogEventsAndTags tag,
12473a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                             Code* code,
12483a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org                             SharedFunctionInfo* shared,
12494e308cf00936c6e7bead43e5141a04e37b49b9b5jkummerow@chromium.org                             CompilationInfo* info,
12501e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org                             Name* source, int line, int column) {
1251dd6d9eedcac6e3b5adfb7702649ac32def9c3585mvstanton@chromium.org  PROFILER_LOG(CodeCreateEvent(tag, code, shared, info, source, line, column));
1252ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1253c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1254dd6d9eedcac6e3b5adfb7702649ac32def9c3585mvstanton@chromium.org  CALL_LISTENERS(CodeCreateEvent(tag, code, shared, info, source, line,
1255dd6d9eedcac6e3b5adfb7702649ac32def9c3585mvstanton@chromium.org                                 column));
12561510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
12571510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1258ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
12591510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, tag, code);
126083e168294456ca2f02db421a635f7d5f5d023966kmillikin@chromium.org  SmartArrayPointer<char> name =
12613a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org      shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1262afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org  msg.Append("\"%s ", name.get());
1263750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (source->IsString()) {
1264750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    SmartArrayPointer<char> sourcestr =
1265750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org       String::cast(source)->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1266afbdadc5f06365a7889e7c1c1fdb7dbf596cce68machenbach@chromium.org    msg.Append("%s", sourcestr.get());
1267750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1268ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    msg.AppendSymbolName(Symbol::cast(source));
1269750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
12701e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org  msg.Append(":%d:%d\",", line, column);
12713a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org  msg.AppendAddress(shared->address());
12723a5fd78f0ca6c2827bb05f69a373d152a9ce6ff3fschneider@chromium.org  msg.Append(",%s", ComputeMarker(code));
1273381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
1274245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org}
1275245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
1276245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
1277ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.orgvoid Logger::CodeCreateEvent(LogEventsAndTags tag,
1278ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                             Code* code,
1279ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                             int args_count) {
1280c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeCreateEvent(tag, code, args_count));
1281ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1282c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1283d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeCreateEvent(tag, code, args_count));
12841510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
12851510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1286ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
12871510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, tag, code);
12881510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg.Append("\"args_count: %d\"", args_count);
1289381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
129043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
129143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
129243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1293fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.orgvoid Logger::CodeDisableOptEvent(Code* code,
1294fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org                                 SharedFunctionInfo* shared) {
1295fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  PROFILER_LOG(CodeDisableOptEvent(code, shared));
1296fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1297fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  if (!is_logging_code_events()) return;
1298fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  CALL_LISTENERS(CodeDisableOptEvent(code, shared));
1299fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1300fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1301fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  Log::MessageBuilder msg(log_);
1302fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  msg.Append("%s,", kLogEventsNames[CODE_DISABLE_OPT_EVENT]);
1303fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  SmartArrayPointer<char> name =
1304fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org      shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
1305fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  msg.Append("\"%s\",", name.get());
13069bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("\"%s\"", GetBailoutReason(shared->DisableOptimizationReason()));
1307fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org  msg.WriteToLogFile();
1308fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org}
1309fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
1310fb547e07aef43e02715c5d6c1530e84bb3cbba02machenbach@chromium.org
13114a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.orgvoid Logger::CodeMovingGCEvent() {
1312c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeMovingGCEvent());
1313c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org
1314c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
13158e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_ll_prof) return;
1316d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeMovingGCEvent());
13175de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  base::OS::SignalCodeMovingGC();
13184a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org}
13194a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org
13204a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org
132171daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.orgvoid Logger::RegExpCodeCreateEvent(Code* code, String* source) {
1322c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(RegExpCodeCreateEvent(code, source));
1323ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1324c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1325d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(RegExpCodeCreateEvent(code, source));
13261510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org
13271510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1328ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
13291510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  AppendCodeCreateHeader(&msg, REG_EXP_TAG, code);
13301510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg.Append('"');
133171daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.org  msg.AppendDetailed(source, false);
13321510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org  msg.Append('"');
133371daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.org  msg.WriteToLogFile();
133471daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.org}
133571daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.org
133671daaf639544be2a6638e3566f78e0b14f05cd7bager@chromium.org
133743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::CodeMoveEvent(Address from, Address to) {
1338c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeMoveEvent(from, to));
1339c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org
1340c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1341d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeMoveEvent(from, to));
1342b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  MoveEventInternal(CODE_MOVE_EVENT, from, to);
1343b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org}
1344b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1345b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1346b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.orgvoid Logger::CodeDeleteEvent(Address from) {
1347c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(CodeDeleteEvent(from));
1348c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org
1349c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1350d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  CALL_LISTENERS(CodeDeleteEvent(from));
1351ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1352c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1353ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
1354ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  msg.Append("%s,", kLogEventsNames[CODE_DELETE_EVENT]);
1355ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  msg.AppendAddress(from);
1356ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  msg.WriteToLogFile();
1357b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org}
1358b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1359ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1360c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.orgvoid Logger::CodeLinePosInfoAddPositionEvent(void* jit_handler_data,
1361c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                                     int pc_offset,
1362c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                                     int position) {
1363ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data,
1364ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  pc_offset,
1365ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  position,
1366ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  JitCodeEvent::POSITION));
1367c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org}
1368c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org
1369ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1370c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.orgvoid Logger::CodeLinePosInfoAddStatementPositionEvent(void* jit_handler_data,
1371c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                                                      int pc_offset,
1372c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                                                      int position) {
1373ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JIT_LOG(AddCodeLinePosInfoEvent(jit_handler_data,
1374ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  pc_offset,
1375ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  position,
1376ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org                                  JitCodeEvent::STATEMENT_POSITION));
1377c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org}
1378c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org
1379e0e1b0d3e70c933d36ed381d511e9fda39f2a751mstarzinger@chromium.org
1380c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.orgvoid Logger::CodeStartLinePosInfoRecordEvent(PositionsRecorder* pos_recorder) {
1381ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (jit_logger_ != NULL) {
1382ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      pos_recorder->AttachJITHandlerData(jit_logger_->StartCodePosInfoEvent());
1383c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  }
1384c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org}
1385c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org
1386ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1387c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.orgvoid Logger::CodeEndLinePosInfoRecordEvent(Code* code,
1388c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                                           void* jit_handler_data) {
1389ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  JIT_LOG(EndCodePosInfoEvent(code, jit_handler_data));
1390c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org}
1391b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1392e0e1b0d3e70c933d36ed381d511e9fda39f2a751mstarzinger@chromium.org
1393d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.orgvoid Logger::CodeNameEvent(Address addr, int pos, const char* code_name) {
1394d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  if (code_name == NULL) return;  // Not a code object.
1395d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  Log::MessageBuilder msg(log_);
1396d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  msg.Append("%s,%d,", kLogEventsNames[SNAPSHOT_CODE_NAME_EVENT], pos);
1397d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  msg.AppendDoubleQuotedString(code_name);
1398d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org  msg.WriteToLogFile();
1399d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org}
1400d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
1401d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org
1402b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.orgvoid Logger::SnapshotPositionEvent(Address addr, int pos) {
14038e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org  if (!log_->IsEnabled()) return;
140410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  LL_LOG(SnapshotPositionEvent(addr, pos));
14058e8294a88dc7d58f579aee0ba08c19fc8a616e2dsgjesse@chromium.org  if (!FLAG_log_snapshot_positions) return;
1406ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14075f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org  msg.Append("%s,", kLogEventsNames[SNAPSHOT_POSITION_EVENT]);
1408b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  msg.AppendAddress(addr);
1409b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  msg.Append(",%d", pos);
1410b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  msg.WriteToLogFile();
1411b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org}
1412b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1413b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1414b08986cb66c3f6687247cb6da186c1e73057e399whesse@chromium.orgvoid Logger::SharedFunctionInfoMoveEvent(Address from, Address to) {
1415c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  PROFILER_LOG(SharedFunctionInfoMoveEvent(from, to));
1416c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org
1417c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!is_logging_code_events()) return;
1418b08986cb66c3f6687247cb6da186c1e73057e399whesse@chromium.org  MoveEventInternal(SHARED_FUNC_MOVE_EVENT, from, to);
1419b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org}
1420b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1421b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org
1422b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.orgvoid Logger::MoveEventInternal(LogEventsAndTags event,
1423b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org                               Address from,
1424b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org                               Address to) {
1425c73d55b355913690124f3ee70c344035431cdd3ayangguo@chromium.org  if (!FLAG_log_code || !log_->IsEnabled()) return;
1426ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14275f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org  msg.Append("%s,", kLogEventsNames[event]);
1428eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org  msg.AppendAddress(from);
1429eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org  msg.Append(',');
14305f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org  msg.AppendAddress(to);
1431381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
143243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
143343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
143443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
143543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::ResourceEvent(const char* name, const char* tag) {
1436ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log) return;
1437ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
1438381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append("%s,%s,", name, tag);
143943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
144043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  uint32_t sec, usec;
14415de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  if (base::OS::GetUserTime(&sec, &usec) != -1) {
1442381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append("%d,%d,", sec, usec);
144343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
14445de0074a922429f5e0ec2cf140c2d2989bf88140yangguo@chromium.org  msg.Append("%.0f", base::OS::TimeCurrentMillis());
1445381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
144643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
144743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
144843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1449750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.orgvoid Logger::SuspectReadEvent(Name* name, Object* obj) {
1450ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_suspect) return;
1451ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14528bb60585bafbf81564e6b30fcf18c82615a76f95ager@chromium.org  String* class_name = obj->IsJSObject()
14538bb60585bafbf81564e6b30fcf18c82615a76f95ager@chromium.org                       ? JSObject::cast(obj)->class_name()
1454c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org                       : isolate_->heap()->empty_string();
1455381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append("suspect-read,");
1456381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append(class_name);
1457381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.Append(',');
1458750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  if (name->IsString()) {
1459750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.Append('"');
1460750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.Append(String::cast(name));
1461750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    msg.Append('"');
1462750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  } else {
1463ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    msg.AppendSymbolName(Symbol::cast(name));
1464750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org  }
1465381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
146643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
146743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
146843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
146943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::HeapSampleBeginEvent(const char* space, const char* kind) {
1470ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_gc) return;
1471ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
1472e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org  // Using non-relative system time in order to be able to synchronize with
1473e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org  // external memory profiling events (e.g. DOM memory size).
14749bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("heap-sample-begin,\"%s\",\"%s\",%.0f", space, kind,
14759bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org             base::OS::TimeCurrentMillis());
1476e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org  msg.WriteToLogFile();
1477e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org}
1478e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org
1479e959c18cf7193e2f021245584a3c8f1f32f82c92kasperl@chromium.org
148043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::HeapSampleEndEvent(const char* space, const char* kind) {
1481ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_gc) return;
1482ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14839bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("heap-sample-end,\"%s\",\"%s\"", space, kind);
1484381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
148543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
148643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
148743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
148843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::HeapSampleItemEvent(const char* type, int number, int bytes) {
1489ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log_gc) return;
1490ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14919bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("heap-sample-item,%s,%d,%d", type, number, bytes);
1492381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
149343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
149443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
149543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1496769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.comvoid Logger::DebugTag(const char* call_site_tag) {
1497ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log) return;
1498ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
14999bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("debug-tag,%s", call_site_tag);
1500381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
1501769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com}
1502769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com
1503769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com
1504769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.comvoid Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) {
1505ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_log) return;
1506769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com  StringBuilder s(parameter.length() + 1);
1507769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com  for (int i = 0; i < parameter.length(); ++i) {
1508769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com    s.AddCharacter(static_cast<char>(parameter[i]));
1509769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com  }
1510769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com  char* parameter_string = s.Finalize();
1511ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
15129bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org  msg.Append("debug-queue-event,%s,%15.3f,%s", event_type,
15139bf7aff6cc5ed8807b7b2abc11b6cf77b928ded1machenbach@chromium.org             base::OS::TimeCurrentMillis(), parameter_string);
1514769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com  DeleteArray(parameter_string);
1515381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
1516769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com}
1517769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com
1518769cc962a043dd8d92cc010dd2c50bc26f652c94mads.s.ager@gmail.com
151943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansenvoid Logger::TickEvent(TickSample* sample, bool overflow) {
1520ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled() || !FLAG_prof) return;
1521ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  Log::MessageBuilder msg(log_);
15225f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org  msg.Append("%s,", kLogEventsNames[TICK_EVENT]);
15235f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org  msg.AppendAddress(sample->pc);
1524dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  msg.Append(",%ld", static_cast<int>(timer_.Elapsed().InMicroseconds()));
152577ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org  if (sample->has_external_callback) {
152677ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org    msg.Append(",1,");
152777ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org    msg.AppendAddress(sample->external_callback);
152877ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org  } else {
152977ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org    msg.Append(",0,");
153077ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org    msg.AppendAddress(sample->tos);
153177ca49ac05d25684c89442029c22f5b2bce94395ulan@chromium.org  }
1532eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org  msg.Append(",%d", static_cast<int>(sample->state));
1533381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  if (overflow) {
1534381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org    msg.Append(",overflow");
1535381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  }
153608e7569a10f8edbb47b8fe70a6e160a4e0c9cd30machenbach@chromium.org  for (unsigned i = 0; i < sample->frames_count; ++i) {
1537eadaf2282ee421d7a63a21d71369b029105341ccager@chromium.org    msg.Append(',');
15385f0c45f2cacb31d36a8f80c31f17bda7751a3644ager@chromium.org    msg.AppendAddress(sample->stack[i]);
1539381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  }
1540381abbb58260f2fc7d346d0e2f83d0f132a4c14bager@chromium.org  msg.WriteToLogFile();
154143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
1542245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
1543245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org
1544dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.orgvoid Logger::StopProfiler() {
1545ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (!log_->IsEnabled()) return;
15464f693d6b99ffdbc05e5e211e08ed5039e13279d2ricow@chromium.org  if (profiler_ != NULL) {
1547dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    profiler_->pause();
1548dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    is_logging_ = false;
1549755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org  }
1550245aa859d34fd516161c48ef4c69d38d9b889284iposva@chromium.org}
15519085a016223a6b72bf580d5781c93ec7b9e54422ager@chromium.org
15529085a016223a6b72bf580d5781c93ec7b9e54422ager@chromium.org
1553755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org// This function can be called when Log's mutex is acquired,
1554755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org// either from main or Profiler's thread.
1555ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgvoid Logger::LogFailure() {
1556dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  StopProfiler();
1557755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org}
1558755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org
1559755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org
1560a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.orgclass EnumerateOptimizedFunctionsVisitor: public OptimizedFunctionVisitor {
1561a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org public:
1562a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  EnumerateOptimizedFunctionsVisitor(Handle<SharedFunctionInfo>* sfis,
1563a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org                                     Handle<Code>* code_objects,
1564a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org                                     int* count)
1565a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      : sfis_(sfis), code_objects_(code_objects), count_(count) { }
1566a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1567a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  virtual void EnterContext(Context* context) {}
1568a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  virtual void LeaveContext(Context* context) {}
1569a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1570a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  virtual void VisitFunction(JSFunction* function) {
15717b26015ac58e54e88f4214e248f772ad4f055477whesse@chromium.org    SharedFunctionInfo* sfi = SharedFunctionInfo::cast(function->shared());
15727b26015ac58e54e88f4214e248f772ad4f055477whesse@chromium.org    Object* maybe_script = sfi->script();
15737b26015ac58e54e88f4214e248f772ad4f055477whesse@chromium.org    if (maybe_script->IsScript()
15747b26015ac58e54e88f4214e248f772ad4f055477whesse@chromium.org        && !Script::cast(maybe_script)->HasValidSource()) return;
1575a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    if (sfis_ != NULL) {
15767b26015ac58e54e88f4214e248f772ad4f055477whesse@chromium.org      sfis_[*count_] = Handle<SharedFunctionInfo>(sfi);
1577a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    }
1578a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    if (code_objects_ != NULL) {
1579e3c177a423baa3c30225c4e422b6f6c76d38b951machenbach@chromium.org      DCHECK(function->code()->kind() == Code::OPTIMIZED_FUNCTION);
1580a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      code_objects_[*count_] = Handle<Code>(function->code());
1581a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    }
1582a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org    *count_ = *count_ + 1;
1583a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  }
1584a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1585a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org private:
1586a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  Handle<SharedFunctionInfo>* sfis_;
1587a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  Handle<Code>* code_objects_;
1588a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  int* count_;
1589a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org};
1590a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1591a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
15927c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.orgstatic int EnumerateCompiledFunctions(Heap* heap,
15937c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org                                      Handle<SharedFunctionInfo>* sfis,
1594a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org                                      Handle<Code>* code_objects) {
15957c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  HeapIterator iterator(heap);
159679e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  DisallowHeapAllocation no_gc;
159771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  int compiled_funcs_count = 0;
1598a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1599a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  // Iterate the heap to find shared function info objects and record
1600a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  // the unoptimized code for them.
1601b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
1602152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org    if (!obj->IsSharedFunctionInfo()) continue;
1603152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org    SharedFunctionInfo* sfi = SharedFunctionInfo::cast(obj);
1604152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org    if (sfi->is_compiled()
1605152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org        && (!sfi->script()->IsScript()
1606152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org            || Script::cast(sfi->script())->HasValidSource())) {
1607a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      if (sfis != NULL) {
1608152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org        sfis[compiled_funcs_count] = Handle<SharedFunctionInfo>(sfi);
1609a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      }
1610a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      if (code_objects != NULL) {
1611a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org        code_objects[compiled_funcs_count] = Handle<Code>(sfi->code());
1612a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org      }
1613152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org      ++compiled_funcs_count;
161471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org    }
1615152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org  }
1616a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1617a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  // Iterate all optimized functions in all contexts.
1618a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  EnumerateOptimizedFunctionsVisitor visitor(sfis,
1619a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org                                             code_objects,
1620a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org                                             &compiled_funcs_count);
1621876cca833d7212e476250d102cad185cdcfa9dfesvenpanne@chromium.org  Deoptimizer::VisitAllOptimizedFunctions(heap->isolate(), &visitor);
1622a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org
1623152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org  return compiled_funcs_count;
1624152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.org}
162571affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org
162671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org
1627c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.orgvoid Logger::LogCodeObject(Object* object) {
162879e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  Code* code_object = Code::cast(object);
162979e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  LogEventsAndTags tag = Logger::STUB_TAG;
163079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  const char* description = "Unknown code from the snapshot";
163179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  switch (code_object->kind()) {
163279e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::FUNCTION:
163379e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::OPTIMIZED_FUNCTION:
163479e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      return;  // We log this later using LogCompiledFunctions.
1635ce9c514a4e015930324b2b45326a478a69535388machenbach@chromium.org    case Code::BINARY_OP_IC:
163679e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::COMPARE_IC:  // fall through
163779e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::COMPARE_NIL_IC:   // fall through
163879e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::TO_BOOLEAN_IC:  // fall through
163979e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::STUB:
164079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description =
164179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org          CodeStub::MajorName(CodeStub::GetMajorKey(code_object), true);
164279e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      if (description == NULL)
164379e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org        description = "A stub from the snapshot";
164479e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::STUB_TAG;
164579e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
16461510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    case Code::REGEXP:
16471510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org      description = "Regular expression code";
16481510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org      tag = Logger::REG_EXP_TAG;
16491510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org      break;
165079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::BUILTIN:
165179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description = "A builtin from the snapshot";
165279e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::BUILTIN_TAG;
165379e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
165432aa03c4b5fe6e129df7529ecdaaeefce3ecee29jkummerow@chromium.org    case Code::HANDLER:
165532aa03c4b5fe6e129df7529ecdaaeefce3ecee29jkummerow@chromium.org      description = "An IC handler from the snapshot";
165632aa03c4b5fe6e129df7529ecdaaeefce3ecee29jkummerow@chromium.org      tag = Logger::HANDLER_TAG;
165732aa03c4b5fe6e129df7529ecdaaeefce3ecee29jkummerow@chromium.org      break;
165879e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::KEYED_LOAD_IC:
165979e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description = "A keyed load IC from the snapshot";
166079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::KEYED_LOAD_IC_TAG;
166179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
166279e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::LOAD_IC:
166379e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description = "A load IC from the snapshot";
166479e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::LOAD_IC_TAG;
166579e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
1666a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org    case Code::CALL_IC:
1667a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org      description = "A call IC from the snapshot";
1668a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org      tag = Logger::CALL_IC_TAG;
1669a86d416fb652b1936026eee315eccd4f17ca1002machenbach@chromium.org      break;
167079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::STORE_IC:
167179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description = "A store IC from the snapshot";
167279e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::STORE_IC_TAG;
167379e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
167479e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org    case Code::KEYED_STORE_IC:
167579e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      description = "A keyed store IC from the snapshot";
167679e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      tag = Logger::KEYED_STORE_IC_TAG;
167779e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org      break;
16781510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org    case Code::NUMBER_OF_KINDS:
16791510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org      break;
1680c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org  }
168179e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  PROFILE(isolate_, CodeCreateEvent(tag, code_object, description));
1682c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org}
1683c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org
1684c4c927273ae2b690c4a015b4640a2a469c9a1a69ager@chromium.org
16855c838251403b0be9a882540f1922577abba4c872ager@chromium.orgvoid Logger::LogCodeObjects() {
1686c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  Heap* heap = isolate_->heap();
16877c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  heap->CollectAllGarbage(Heap::kMakeHeapIterableMask,
1688994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org                          "Logger::LogCodeObjects");
16897c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  HeapIterator iterator(heap);
169079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  DisallowHeapAllocation no_gc;
16915c838251403b0be9a882540f1922577abba4c872ager@chromium.org  for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
16925c838251403b0be9a882540f1922577abba4c872ager@chromium.org    if (obj->IsCode()) LogCodeObject(obj);
16935c838251403b0be9a882540f1922577abba4c872ager@chromium.org  }
16945c838251403b0be9a882540f1922577abba4c872ager@chromium.org}
16955c838251403b0be9a882540f1922577abba4c872ager@chromium.org
16965c838251403b0be9a882540f1922577abba4c872ager@chromium.org
169734e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.orgvoid Logger::LogExistingFunction(Handle<SharedFunctionInfo> shared,
169834e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                                 Handle<Code> code) {
169934e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org  Handle<String> func_name(shared->DebugName());
170034e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org  if (shared->script()->IsScript()) {
170134e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    Handle<Script> script(Script::cast(shared->script()));
17029fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org    int line_num = Script::GetLineNumber(script, shared->start_position()) + 1;
17031e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org    int column_num =
17049fa619507474a4c1c21c6935b3209070bc13a218machenbach@chromium.org        Script::GetColumnNumber(script, shared->start_position()) + 1;
170534e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    if (script->name()->IsString()) {
1706f95d4b920abb640ab0986d138ad559a7d3b91d04danno@chromium.org      Handle<String> script_name(String::cast(script->name()));
1707f95d4b920abb640ab0986d138ad559a7d3b91d04danno@chromium.org      if (line_num > 0) {
1708f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org        PROFILE(isolate_,
170934e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                CodeCreateEvent(
171034e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                    Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
17114e308cf00936c6e7bead43e5141a04e37b49b9b5jkummerow@chromium.org                    *code, *shared, NULL,
17121e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org                    *script_name, line_num, column_num));
171334e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org      } else {
171434e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org        // Can't distinguish eval and script here, so always use Script.
1715f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org        PROFILE(isolate_,
171634e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                CodeCreateEvent(
171734e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                    Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
17184e308cf00936c6e7bead43e5141a04e37b49b9b5jkummerow@chromium.org                    *code, *shared, NULL, *script_name));
171934e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org      }
172034e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    } else {
1721f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      PROFILE(isolate_,
172234e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org              CodeCreateEvent(
172334e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org                  Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
1724e0e1b0d3e70c933d36ed381d511e9fda39f2a751mstarzinger@chromium.org                  *code, *shared, NULL,
17251e8da746019f818a22dfdc6f691dbc0447048cadjkummerow@chromium.org                  isolate_->heap()->empty_string(), line_num, column_num));
172634e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    }
172734e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org  } else if (shared->IsApiFunction()) {
172834e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    // API function.
172934e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    FunctionTemplateInfo* fun_data = shared->get_api_func_data();
173034e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    Object* raw_call_data = fun_data->call_code();
173134e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    if (!raw_call_data->IsUndefined()) {
173234e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org      CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
173334e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org      Object* callback_obj = call_data->callback();
173434e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org      Address entry_point = v8::ToCData<Address>(callback_obj);
1735f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      PROFILE(isolate_, CallbackEvent(*func_name, entry_point));
173634e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    }
173734e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org  } else {
1738f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org    PROFILE(isolate_,
173934e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org            CodeCreateEvent(
17404e308cf00936c6e7bead43e5141a04e37b49b9b5jkummerow@chromium.org                Logger::LAZY_COMPILE_TAG, *code, *shared, NULL, *func_name));
174134e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org  }
174234e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org}
174334e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org
174434e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org
1745152a0b013d7d17f4fe9d04cdce58ec3d6fab2aa5sgjesse@chromium.orgvoid Logger::LogCompiledFunctions() {
1746c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  Heap* heap = isolate_->heap();
17477c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  heap->CollectAllGarbage(Heap::kMakeHeapIterableMask,
1748994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org                          "Logger::LogCompiledFunctions");
1749c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  HandleScope scope(isolate_);
17507c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  const int compiled_funcs_count = EnumerateCompiledFunctions(heap, NULL, NULL);
1751720dc0bc17114e33b9b2177fcb6726bda9cabd62sgjesse@chromium.org  ScopedVector< Handle<SharedFunctionInfo> > sfis(compiled_funcs_count);
1752a55512615f5adc085d23bc8589d155c4b579fb7bkasperl@chromium.org  ScopedVector< Handle<Code> > code_objects(compiled_funcs_count);
17537c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  EnumerateCompiledFunctions(heap, sfis.start(), code_objects.start());
175471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org
175571affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  // During iteration, there can be heap allocation due to
175671affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  // GetScriptLineNumber call.
175771affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  for (int i = 0; i < compiled_funcs_count; ++i) {
1758a2c0c1516848536a514b3178d2c040b7df0ceb5bmachenbach@chromium.org    if (code_objects[i].is_identical_to(isolate_->builtins()->CompileLazy()))
1759ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org      continue;
176034e60787ea1e76f3ee49e859f71f036170c21f0elrn@chromium.org    LogExistingFunction(sfis[i], code_objects[i]);
176171affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  }
176271affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org}
176371affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org
1764ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
1765ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.orgvoid Logger::LogAccessorCallbacks() {
1766c03a1924dcc113678c0ebe58aa7d3c855a657719yangguo@chromium.org  Heap* heap = isolate_->heap();
17677c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  heap->CollectAllGarbage(Heap::kMakeHeapIterableMask,
1768994edf6a113fb3651536b60073df05a72a95f77erossberg@chromium.org                          "Logger::LogAccessorCallbacks");
17697c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org  HeapIterator iterator(heap);
177079e7902fa5f94747b5383dd40f3002dd8b62303arossberg@chromium.org  DisallowHeapAllocation no_gc;
1771b302e56e5b70c4504faa2adf4ec3efb64a9d3e38sgjesse@chromium.org  for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) {
17727c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org    if (!obj->IsExecutableAccessorInfo()) continue;
17737c3372bc426136cb79479c1b59d1770f5528882ahpayer@chromium.org    ExecutableAccessorInfo* ai = ExecutableAccessorInfo::cast(obj);
1774750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    if (!ai->name()->IsName()) continue;
1775ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    Address getter_entry = v8::ToCData<Address>(ai->getter());
1776750145ab1b720c97adf2b548cc8fbd28c8b8e06dulan@chromium.org    Name* name = Name::cast(ai->name());
1777ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    if (getter_entry != 0) {
1778f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      PROFILE(isolate_, GetterCallbackEvent(name, getter_entry));
1779ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    }
1780ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    Address setter_entry = v8::ToCData<Address>(ai->setter());
1781ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    if (setter_entry != 0) {
1782f705b5034dc5bc422ac1019b591469a7d0534772mstarzinger@chromium.org      PROFILE(isolate_, SetterCallbackEvent(name, setter_entry));
1783ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org    }
1784ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org  }
1785ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org}
1786ac6aa175ab59d65cfb7a88dbb621e1d7f1a80b8fsgjesse@chromium.org
178743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1788d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.orgstatic void AddIsolateIdIfNeeded(OStream& os,  // NOLINT
1789d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org                                 Isolate* isolate) {
1790d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  if (FLAG_logfile_per_isolate) os << "isolate-" << isolate << "-";
179110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org}
179210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
179310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
1794d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.orgstatic void PrepareLogFileName(OStream& os,  // NOLINT
1795d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org                               Isolate* isolate, const char* file_name) {
1796d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  AddIsolateIdIfNeeded(os, isolate);
17973c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org  for (const char* p = file_name; *p; p++) {
17983c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org    if (*p == '%') {
17993c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org      p++;
18003c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org      switch (*p) {
18013c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org        case '\0':
18023c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          // If there's a % at the end of the string we back up
18033c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          // one character so we can escape the loop properly.
18043c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          p--;
18053c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          break;
18063c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org        case 'p':
1807d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org          os << base::OS::GetCurrentProcessId();
18083c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          break;
1809d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org        case 't':
18103c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          // %t expands to the current time in milliseconds.
1811d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org          os << static_cast<int64_t>(base::OS::TimeCurrentMillis());
18123c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          break;
18133c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org        case '%':
18143c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          // %% expands (contracts really) to %.
1815d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org          os << '%';
18163c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          break;
18173c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org        default:
18183c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          // All other %'s expand to themselves.
1819d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org          os << '%' << *p;
18203c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org          break;
182110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org      }
18223c3c8d733702cb2b41471efa5eead1faf5b5711bmachenbach@chromium.org    } else {
1823d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org      os << *p;
182410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    }
182510480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  }
182610480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org}
182710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
182810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
1829ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.orgbool Logger::SetUp(Isolate* isolate) {
1830ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  // Tests and EnsureInitialize() can call this twice in a row. It's harmless.
1831ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  if (is_initialized_) return true;
1832ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  is_initialized_ = true;
183343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
18344a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org  // --ll-prof implies --log-code and --log-snapshot-positions.
18354a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org  if (FLAG_ll_prof) {
18364a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org    FLAG_log_snapshot_positions = true;
18374a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org  }
18384a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org
1839d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  OStringStream log_file_name;
1840d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  PrepareLogFileName(log_file_name, isolate, FLAG_logfile);
1841d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org  log_->Initialize(log_file_name.c_str());
184243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1843f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
1844f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  if (FLAG_perf_basic_prof) {
1845f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_basic_logger_ = new PerfBasicLogger();
1846f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    addCodeEventListener(perf_basic_logger_);
1847f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  }
1848f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
1849f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  if (FLAG_perf_jit_prof) {
1850f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_jit_logger_ = new PerfJitLogger();
1851f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    addCodeEventListener(perf_jit_logger_);
1852f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  }
1853f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
185410480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  if (FLAG_ll_prof) {
1855d0bddc653152f270a27fe32d5d7b0f5c0fa3b00cmachenbach@chromium.org    ll_logger_ = new LowLevelLogger(log_file_name.c_str());
1856d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    addCodeEventListener(ll_logger_);
185710480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  }
18584a5224e84636d192e82f288bfab0d308bdae5c37whesse@chromium.org
18596d786c9805481bd13ecb29c3155540f2f32950e1svenpanne@chromium.org  ticker_ = new Ticker(isolate, kSamplingIntervalMs);
18606d786c9805481bd13ecb29c3155540f2f32950e1svenpanne@chromium.org
1861ca29dd85fa02449d17188f5a6ff9a7cdf2ad9680danno@chromium.org  if (Log::InitLogAtStart()) {
1862dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    is_logging_ = true;
1863ce5e87bd905d592a8bd612b3dedf7a994177c13aager@chromium.org  }
18643e87580939cb78c5802369f723680d4a16cc2902ager@chromium.org
186543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  if (FLAG_prof) {
18667979bbb1df2eaff193e85d44c8da1ffa1525b7fcfschneider@chromium.org    profiler_ = new Profiler(isolate);
1867dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    is_logging_ = true;
1868dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org    profiler_->Engage();
186943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
187043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1871dc94e19484d1700cb0ec22365444223e49a3ac1ejkummerow@chromium.org  if (FLAG_log_internal_timer_events || FLAG_prof) timer_.Start();
18728e8d8825f97138de12985f8e0d3163074dff5258ulan@chromium.org
187343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  return true;
187443d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
187543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
187643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1877355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.orgvoid Logger::SetCodeEventHandler(uint32_t options,
1878355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org                                 JitCodeEventHandler event_handler) {
1879ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (jit_logger_) {
1880d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      removeCodeEventListener(jit_logger_);
1881ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      delete jit_logger_;
1882ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org      jit_logger_ = NULL;
1883ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
1884355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org
1885ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (event_handler) {
1886ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    jit_logger_ = new JitLogger(event_handler);
1887d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    addCodeEventListener(jit_logger_);
1888d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    if (options & kJitCodeEventEnumExisting) {
1889d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      HandleScope scope(isolate_);
1890d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      LogCodeObjects();
1891d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org      LogCompiledFunctions();
1892d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    }
1893355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org  }
1894355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org}
1895355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org
1896355cfd19c23ac613f2738a40e356ea48297f7d5eyangguo@chromium.org
1897ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.orgSampler* Logger::sampler() {
1898ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  return ticker_;
1899ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org}
1900ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1901ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org
1902030d38ee536bc25856546e75fdac60d1a0c42bddwhesse@chromium.orgFILE* Logger::TearDown() {
1903030d38ee536bc25856546e75fdac60d1a0c42bddwhesse@chromium.org  if (!is_initialized_) return NULL;
1904ea88ce93dcb41a9200ec8747ae7642a5db1f4ce7sgjesse@chromium.org  is_initialized_ = false;
1905755c5b1cc880bc54405d2652f934a941e8fcda4asgjesse@chromium.org
190643d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  // Stop the profiler before closing the file.
190743d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  if (profiler_ != NULL) {
190843d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    profiler_->Disengage();
190943d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    delete profiler_;
191043d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen    profiler_ = NULL;
191143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  }
191243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
191343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen  delete ticker_;
191471affb54842da76b24f0bb3184e9f0960523f89dkasperl@chromium.org  ticker_ = NULL;
191543d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
1916f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  if (perf_basic_logger_) {
1917f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    removeCodeEventListener(perf_basic_logger_);
1918f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    delete perf_basic_logger_;
1919f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_basic_logger_ = NULL;
1920f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  }
1921f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
1922f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  if (perf_jit_logger_) {
1923f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    removeCodeEventListener(perf_jit_logger_);
1924f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    delete perf_jit_logger_;
1925f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org    perf_jit_logger_ = NULL;
1926f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org  }
1927f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org
192810480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  if (ll_logger_) {
1929d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    removeCodeEventListener(ll_logger_);
193010480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    delete ll_logger_;
193110480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org    ll_logger_ = NULL;
193210480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org  }
193310480471c0db59c51c15e57d2a3489551d61b273jkummerow@chromium.org
1934ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  if (jit_logger_) {
1935d3c42109e5b85232d19beab8deeb24bdcbbf07f9danno@chromium.org    removeCodeEventListener(jit_logger_);
1936ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    delete jit_logger_;
1937ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org    jit_logger_ = NULL;
1938ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org  }
1939ba72ec861b69b67139c93fc6dd56f4a73c9b3135jkummerow@chromium.org
1940030d38ee536bc25856546e75fdac60d1a0c42bddwhesse@chromium.org  return log_->Close();
194143d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen}
194243d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen
194343d26ecc3563a46f62a0224030667c8f8f3f6cebchristian.plesner.hansen} }  // namespace v8::internal
1944