| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 class CpuProfile; | 43 class CpuProfile; |
| 44 class CpuProfilesCollection; | 44 class CpuProfilesCollection; |
| 45 class HashMap; | 45 class HashMap; |
| 46 class ProfileGenerator; | 46 class ProfileGenerator; |
| 47 class TokenEnumerator; | 47 class TokenEnumerator; |
| 48 | 48 |
| 49 #define CODE_EVENTS_TYPE_LIST(V) \ | 49 #define CODE_EVENTS_TYPE_LIST(V) \ |
| 50 V(CODE_CREATION, CodeCreateEventRecord) \ | 50 V(CODE_CREATION, CodeCreateEventRecord) \ |
| 51 V(CODE_MOVE, CodeMoveEventRecord) \ | 51 V(CODE_MOVE, CodeMoveEventRecord) \ |
| 52 V(CODE_DELETE, CodeDeleteEventRecord) \ | 52 V(CODE_DELETE, CodeDeleteEventRecord) \ |
| 53 V(CODE_ALIAS, CodeAliasEventRecord) | 53 V(SFI_MOVE, SFIMoveEventRecord) |
| 54 | 54 |
| 55 | 55 |
| 56 class CodeEventRecord { | 56 class CodeEventRecord { |
| 57 public: | 57 public: |
| 58 #define DECLARE_TYPE(type, ignore) type, | 58 #define DECLARE_TYPE(type, ignore) type, |
| 59 enum Type { | 59 enum Type { |
| 60 NONE = 0, | 60 NONE = 0, |
| 61 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) | 61 CODE_EVENTS_TYPE_LIST(DECLARE_TYPE) |
| 62 NUMBER_OF_TYPES | 62 NUMBER_OF_TYPES |
| 63 }; | 63 }; |
| 64 #undef DECLARE_TYPE | 64 #undef DECLARE_TYPE |
| 65 | 65 |
| 66 Type type; | 66 Type type; |
| 67 unsigned order; | 67 unsigned order; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 | 70 |
| 71 class CodeCreateEventRecord : public CodeEventRecord { | 71 class CodeCreateEventRecord : public CodeEventRecord { |
| 72 public: | 72 public: |
| 73 Address start; | 73 Address start; |
| 74 CodeEntry* entry; | 74 CodeEntry* entry; |
| 75 unsigned size; | 75 unsigned size; |
| 76 Address sfi_address; |
| 76 | 77 |
| 77 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 78 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 | 81 |
| 81 class CodeMoveEventRecord : public CodeEventRecord { | 82 class CodeMoveEventRecord : public CodeEventRecord { |
| 82 public: | 83 public: |
| 83 Address from; | 84 Address from; |
| 84 Address to; | 85 Address to; |
| 85 | 86 |
| 86 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 87 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 | 90 |
| 90 class CodeDeleteEventRecord : public CodeEventRecord { | 91 class CodeDeleteEventRecord : public CodeEventRecord { |
| 91 public: | 92 public: |
| 92 Address start; | 93 Address start; |
| 93 | 94 |
| 94 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 95 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 | 98 |
| 98 class CodeAliasEventRecord : public CodeEventRecord { | 99 class SFIMoveEventRecord : public CodeEventRecord { |
| 99 public: | 100 public: |
| 100 Address start; | 101 Address from; |
| 101 CodeEntry* entry; | 102 Address to; |
| 102 Address code_start; | |
| 103 | 103 |
| 104 INLINE(void UpdateCodeMap(CodeMap* code_map)); | 104 INLINE(void UpdateCodeMap(CodeMap* code_map)); |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 | 107 |
| 108 class TickSampleEventRecord BASE_EMBEDDED { | 108 class TickSampleEventRecord BASE_EMBEDDED { |
| 109 public: | 109 public: |
| 110 TickSampleEventRecord() | 110 TickSampleEventRecord() |
| 111 : filler(1) { | 111 : filler(1) { |
| 112 ASSERT(filler != SamplingCircularQueue::kClear); | 112 ASSERT(filler != SamplingCircularQueue::kClear); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 INLINE(static TickSampleEventRecord* init(void* value)); | 128 INLINE(static TickSampleEventRecord* init(void* value)); |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 | 131 |
| 132 // This class implements both the profile events processor thread and | 132 // This class implements both the profile events processor thread and |
| 133 // methods called by event producers: VM and stack sampler threads. | 133 // methods called by event producers: VM and stack sampler threads. |
| 134 class ProfilerEventsProcessor : public Thread { | 134 class ProfilerEventsProcessor : public Thread { |
| 135 public: | 135 public: |
| 136 explicit ProfilerEventsProcessor(Isolate* isolate, | 136 explicit ProfilerEventsProcessor(Isolate* isolate, |
| 137 ProfileGenerator* generator); | 137 ProfileGenerator* generator); |
| 138 virtual ~ProfilerEventsProcessor(); | 138 virtual ~ProfilerEventsProcessor() {} |
| 139 | 139 |
| 140 // Thread control. | 140 // Thread control. |
| 141 virtual void Run(); | 141 virtual void Run(); |
| 142 inline void Stop() { running_ = false; } | 142 inline void Stop() { running_ = false; } |
| 143 INLINE(bool running()) { return running_; } | 143 INLINE(bool running()) { return running_; } |
| 144 | 144 |
| 145 // Events adding methods. Called by VM threads. | 145 // Events adding methods. Called by VM threads. |
| 146 void CallbackCreateEvent(Logger::LogEventsAndTags tag, | 146 void CallbackCreateEvent(Logger::LogEventsAndTags tag, |
| 147 const char* prefix, String* name, | 147 const char* prefix, String* name, |
| 148 Address start); | 148 Address start); |
| 149 void CodeCreateEvent(Logger::LogEventsAndTags tag, | 149 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 150 String* name, | 150 String* name, |
| 151 String* resource_name, int line_number, | 151 String* resource_name, int line_number, |
| 152 Address start, unsigned size); | 152 Address start, unsigned size, |
| 153 Address sfi_address); |
| 153 void CodeCreateEvent(Logger::LogEventsAndTags tag, | 154 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 154 const char* name, | 155 const char* name, |
| 155 Address start, unsigned size); | 156 Address start, unsigned size); |
| 156 void CodeCreateEvent(Logger::LogEventsAndTags tag, | 157 void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 157 int args_count, | 158 int args_count, |
| 158 Address start, unsigned size); | 159 Address start, unsigned size); |
| 159 void CodeMoveEvent(Address from, Address to); | 160 void CodeMoveEvent(Address from, Address to); |
| 160 void CodeDeleteEvent(Address from); | 161 void CodeDeleteEvent(Address from); |
| 161 void FunctionCreateEvent(Address alias, Address start, int security_token_id); | 162 void SFIMoveEvent(Address from, Address to); |
| 162 void FunctionMoveEvent(Address from, Address to); | |
| 163 void FunctionDeleteEvent(Address from); | |
| 164 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, | 163 void RegExpCodeCreateEvent(Logger::LogEventsAndTags tag, |
| 165 const char* prefix, String* name, | 164 const char* prefix, String* name, |
| 166 Address start, unsigned size); | 165 Address start, unsigned size); |
| 167 // Puts current stack into tick sample events buffer. | 166 // Puts current stack into tick sample events buffer. |
| 168 void AddCurrentStack(); | 167 void AddCurrentStack(); |
| 169 bool IsKnownFunction(Address start); | |
| 170 void ProcessMovedFunctions(); | |
| 171 void RememberMovedFunction(JSFunction* function); | |
| 172 | 168 |
| 173 // Tick sample events are filled directly in the buffer of the circular | 169 // Tick sample events are filled directly in the buffer of the circular |
| 174 // queue (because the structure is of fixed width, but usually not all | 170 // queue (because the structure is of fixed width, but usually not all |
| 175 // stack frame entries are filled.) This method returns a pointer to the | 171 // stack frame entries are filled.) This method returns a pointer to the |
| 176 // next record of the buffer. | 172 // next record of the buffer. |
| 177 INLINE(TickSample* TickSampleEvent()); | 173 INLINE(TickSample* TickSampleEvent()); |
| 178 | 174 |
| 179 private: | 175 private: |
| 180 union CodeEventsContainer { | 176 union CodeEventsContainer { |
| 181 CodeEventRecord generic; | 177 CodeEventRecord generic; |
| 182 #define DECLARE_CLASS(ignore, type) type type##_; | 178 #define DECLARE_CLASS(ignore, type) type type##_; |
| 183 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) | 179 CODE_EVENTS_TYPE_LIST(DECLARE_CLASS) |
| 184 #undef DECLARE_TYPE | 180 #undef DECLARE_TYPE |
| 185 }; | 181 }; |
| 186 | 182 |
| 187 // Called from events processing thread (Run() method.) | 183 // Called from events processing thread (Run() method.) |
| 188 bool ProcessCodeEvent(unsigned* dequeue_order); | 184 bool ProcessCodeEvent(unsigned* dequeue_order); |
| 189 bool ProcessTicks(unsigned dequeue_order); | 185 bool ProcessTicks(unsigned dequeue_order); |
| 190 | 186 |
| 191 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); | 187 INLINE(static bool FilterOutCodeCreateEvent(Logger::LogEventsAndTags tag)); |
| 192 INLINE(static bool AddressesMatch(void* key1, void* key2)) { | |
| 193 return key1 == key2; | |
| 194 } | |
| 195 INLINE(static uint32_t AddressHash(Address addr)) { | |
| 196 return ComputeIntegerHash( | |
| 197 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr))); | |
| 198 } | |
| 199 | 188 |
| 200 ProfileGenerator* generator_; | 189 ProfileGenerator* generator_; |
| 201 bool running_; | 190 bool running_; |
| 202 UnboundQueue<CodeEventsContainer> events_buffer_; | 191 UnboundQueue<CodeEventsContainer> events_buffer_; |
| 203 SamplingCircularQueue ticks_buffer_; | 192 SamplingCircularQueue ticks_buffer_; |
| 204 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; | 193 UnboundQueue<TickSampleEventRecord> ticks_from_vm_buffer_; |
| 205 unsigned enqueue_order_; | 194 unsigned enqueue_order_; |
| 206 | |
| 207 // Used from the VM thread. | |
| 208 HashMap* known_functions_; | |
| 209 List<JSFunction*> moved_functions_; | |
| 210 }; | 195 }; |
| 211 | 196 |
| 212 } } // namespace v8::internal | 197 } } // namespace v8::internal |
| 213 | 198 |
| 214 | 199 |
| 215 #define PROFILE(Call) \ | 200 #define PROFILE(Call) \ |
| 216 LOG(Call); \ | 201 LOG(Call); \ |
| 217 do { \ | 202 do { \ |
| 218 if (v8::internal::CpuProfiler::is_profiling()) { \ | 203 if (v8::internal::CpuProfiler::is_profiling()) { \ |
| 219 v8::internal::CpuProfiler::Call; \ | 204 v8::internal::CpuProfiler::Call; \ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 247 static TickSample* TickSampleEvent(Isolate* isolate); | 232 static TickSample* TickSampleEvent(Isolate* isolate); |
| 248 | 233 |
| 249 // Must be called via PROFILE macro, otherwise will crash when | 234 // Must be called via PROFILE macro, otherwise will crash when |
| 250 // profiling is not enabled. | 235 // profiling is not enabled. |
| 251 static void CallbackEvent(String* name, Address entry_point); | 236 static void CallbackEvent(String* name, Address entry_point); |
| 252 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 237 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 253 Code* code, const char* comment); | 238 Code* code, const char* comment); |
| 254 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 239 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 255 Code* code, String* name); | 240 Code* code, String* name); |
| 256 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 241 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 257 Code* code, String* name, | 242 Code* code, |
| 243 SharedFunctionInfo *shared, |
| 244 String* name); |
| 245 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 246 Code* code, |
| 247 SharedFunctionInfo *shared, |
| 258 String* source, int line); | 248 String* source, int line); |
| 259 static void CodeCreateEvent(Logger::LogEventsAndTags tag, | 249 static void CodeCreateEvent(Logger::LogEventsAndTags tag, |
| 260 Code* code, int args_count); | 250 Code* code, int args_count); |
| 261 static void CodeMovingGCEvent() {} | 251 static void CodeMovingGCEvent() {} |
| 262 static void CodeMoveEvent(Address from, Address to); | 252 static void CodeMoveEvent(Address from, Address to); |
| 263 static void CodeDeleteEvent(Address from); | 253 static void CodeDeleteEvent(Address from); |
| 264 static void FunctionCreateEvent(JSFunction* function); | |
| 265 // Reports function creation in case we had missed it (e.g. | |
| 266 // if it was created from compiled code). | |
| 267 static void FunctionCreateEventFromMove(Heap* heap, JSFunction* function); | |
| 268 static void FunctionMoveEvent(Heap* heap, Address from, Address to); | |
| 269 static void FunctionDeleteEvent(Address from); | |
| 270 static void GetterCallbackEvent(String* name, Address entry_point); | 254 static void GetterCallbackEvent(String* name, Address entry_point); |
| 271 static void RegExpCodeCreateEvent(Code* code, String* source); | 255 static void RegExpCodeCreateEvent(Code* code, String* source); |
| 272 static void ProcessMovedFunctions(); | |
| 273 static void SetterCallbackEvent(String* name, Address entry_point); | 256 static void SetterCallbackEvent(String* name, Address entry_point); |
| 257 static void SFIMoveEvent(Address from, Address to); |
| 274 | 258 |
| 275 // TODO(isolates): this doesn't have to use atomics anymore. | 259 // TODO(isolates): this doesn't have to use atomics anymore. |
| 276 | 260 |
| 277 static INLINE(bool is_profiling()) { | 261 static INLINE(bool is_profiling()) { |
| 278 return is_profiling(Isolate::Current()); | 262 return is_profiling(Isolate::Current()); |
| 279 } | 263 } |
| 280 | 264 |
| 281 static INLINE(bool is_profiling(Isolate* isolate)) { | 265 static INLINE(bool is_profiling(Isolate* isolate)) { |
| 282 CpuProfiler* profiler = isolate->cpu_profiler(); | 266 CpuProfiler* profiler = isolate->cpu_profiler(); |
| 283 return profiler != NULL && NoBarrier_Load(&profiler->is_profiling_); | 267 return profiler != NULL && NoBarrier_Load(&profiler->is_profiling_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 306 #endif // ENABLE_LOGGING_AND_PROFILING | 290 #endif // ENABLE_LOGGING_AND_PROFILING |
| 307 | 291 |
| 308 private: | 292 private: |
| 309 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); | 293 DISALLOW_COPY_AND_ASSIGN(CpuProfiler); |
| 310 }; | 294 }; |
| 311 | 295 |
| 312 } } // namespace v8::internal | 296 } } // namespace v8::internal |
| 313 | 297 |
| 314 | 298 |
| 315 #endif // V8_CPU_PROFILER_H_ | 299 #endif // V8_CPU_PROFILER_H_ |
| OLD | NEW |