V8 Project
perf-jit.cc
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "src/perf-jit.h"
29 
30 #if V8_OS_LINUX
31 #include <fcntl.h>
32 #include <unistd.h>
34 #endif // V8_OS_LINUX
35 
36 namespace v8 {
37 namespace internal {
38 
39 #if V8_OS_LINUX
40 
41 const char PerfJitLogger::kFilenameFormatString[] = "perfjit-%d.dump";
42 
43 // Extra padding for the PID in the filename
44 const int PerfJitLogger::kFilenameBufferPadding = 16;
45 
46 
47 PerfJitLogger::PerfJitLogger() : perf_output_handle_(NULL), code_index_(0) {
48  if (!base::TimeTicks::KernelTimestampAvailable()) {
49  FATAL("Cannot profile with perf JIT - kernel timestamps not available.");
50  }
51 
52  // Open the perf JIT dump file.
53  int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
54  ScopedVector<char> perf_dump_name(bufferSize);
55  int size = SNPrintF(perf_dump_name, kFilenameFormatString,
56  base::OS::GetCurrentProcessId());
57  CHECK_NE(size, -1);
58  perf_output_handle_ =
59  base::OS::FOpen(perf_dump_name.start(), base::OS::LogFileOpenMode);
60  CHECK_NE(perf_output_handle_, NULL);
61  setvbuf(perf_output_handle_, NULL, _IOFBF, kLogBufferSize);
62 
63  LogWriteHeader();
64 }
65 
66 
67 PerfJitLogger::~PerfJitLogger() {
68  fclose(perf_output_handle_);
69  perf_output_handle_ = NULL;
70 }
71 
72 
73 uint64_t PerfJitLogger::GetTimestamp() {
74  return static_cast<int64_t>(
75  base::TimeTicks::KernelTimestampNow().ToInternalValue());
76 }
77 
78 
79 void PerfJitLogger::LogRecordedBuffer(Code* code, SharedFunctionInfo*,
80  const char* name, int length) {
81  DCHECK(code->instruction_start() == code->address() + Code::kHeaderSize);
82  DCHECK(perf_output_handle_ != NULL);
83 
84  const char* code_name = name;
85  uint8_t* code_pointer = reinterpret_cast<uint8_t*>(code->instruction_start());
86  uint32_t code_size = code->is_crankshafted() ? code->safepoint_table_offset()
87  : code->instruction_size();
88 
89  static const char string_terminator[] = "\0";
90 
91  jr_code_load code_load;
92  code_load.p.id = JIT_CODE_LOAD;
93  code_load.p.total_size = sizeof(code_load) + length + 1 + code_size;
94  code_load.p.timestamp = GetTimestamp();
95  code_load.pid = static_cast<uint32_t>(base::OS::GetCurrentProcessId());
96  code_load.tid = static_cast<uint32_t>(base::OS::GetCurrentThreadId());
97  code_load.vma = 0x0; // Our addresses are absolute.
98  code_load.code_addr = reinterpret_cast<uint64_t>(code_pointer);
99  code_load.code_size = code_size;
100  code_load.code_index = code_index_;
101 
102  code_index_++;
103 
104  LogWriteBytes(reinterpret_cast<const char*>(&code_load), sizeof(code_load));
105  LogWriteBytes(code_name, length);
106  LogWriteBytes(string_terminator, 1);
107  LogWriteBytes(reinterpret_cast<const char*>(code_pointer), code_size);
108 }
109 
110 
111 void PerfJitLogger::CodeMoveEvent(Address from, Address to) {
112  // Code relocation not supported.
113  UNREACHABLE();
114 }
115 
116 
117 void PerfJitLogger::CodeDeleteEvent(Address from) {
118  // V8 does not send notification on code unload
119 }
120 
121 
122 void PerfJitLogger::SnapshotPositionEvent(Address addr, int pos) {}
123 
124 
125 void PerfJitLogger::LogWriteBytes(const char* bytes, int size) {
126  size_t rv = fwrite(bytes, 1, size, perf_output_handle_);
127  DCHECK(static_cast<size_t>(size) == rv);
128  USE(rv);
129 }
130 
131 
132 void PerfJitLogger::LogWriteHeader() {
133  DCHECK(perf_output_handle_ != NULL);
134  jitheader header;
135  header.magic = JITHEADER_MAGIC;
136  header.version = JITHEADER_VERSION;
137  header.total_size = sizeof(jitheader);
138  header.pad1 = 0xdeadbeef;
139  header.elf_mach = GetElfMach();
140  header.pid = base::OS::GetCurrentProcessId();
141  header.timestamp =
142  static_cast<uint64_t>(base::OS::TimeCurrentMillis() * 1000.0);
143  LogWriteBytes(reinterpret_cast<const char*>(&header), sizeof(header));
144 }
145 
146 #endif // V8_OS_LINUX
147 }
148 } // namespace v8::internal
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define JITHEADER_VERSION
Definition: jitdump.h:14
@ JIT_CODE_LOAD
Definition: jitdump.h:27
#define JITHEADER_MAGIC
Definition: jitdump.h:9
#define UNREACHABLE()
Definition: logging.h:30
#define CHECK_NE(unexpected, value)
Definition: logging.h:173
#define FATAL(msg)
Definition: logging.h:26
#define DCHECK(condition)
Definition: logging.h:205
void USE(T)
Definition: macros.h:322
int SNPrintF(Vector< char > str, const char *format,...)
Definition: utils.cc:105
byte * Address
Definition: globals.h:101
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
static FILE * FOpen(const char *path, const char *mode)
Definition: d8.cc:1056
uint64_t timestamp
Definition: jitdump.h:23
uint32_t magic
Definition: jitdump.h:17
uint32_t pid
Definition: jitdump.h:22
uint32_t total_size
Definition: jitdump.h:19
uint32_t version
Definition: jitdump.h:18
uint32_t pad1
Definition: jitdump.h:21
uint32_t elf_mach
Definition: jitdump.h:20
uint64_t code_addr
Definition: jitdump.h:47
uint64_t code_index
Definition: jitdump.h:49
struct jr_prefix p
Definition: jitdump.h:42
uint32_t tid
Definition: jitdump.h:45
uint32_t pid
Definition: jitdump.h:44
uint64_t vma
Definition: jitdump.h:46
uint64_t code_size
Definition: jitdump.h:48
uint32_t total_size
Definition: jitdump.h:37
uint64_t timestamp
Definition: jitdump.h:38
uint32_t id
Definition: jitdump.h:36