1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_IC_IC_STATS_H_ 6 #define V8_IC_IC_STATS_H_ 7 8 #include <memory> 9 #include <string> 10 #include <unordered_map> 11 #include <vector> 12 13 #include "include/v8-internal.h" // For Address. 14 #include "src/base/atomicops.h" 15 #include "src/base/lazy-instance.h" 16 17 namespace v8 { 18 19 namespace tracing { 20 class TracedValue; 21 } // namespace tracing 22 23 namespace internal { 24 25 class JSFunction; 26 class Script; 27 28 struct ICInfo { 29 ICInfo(); 30 void Reset(); 31 void AppendToTracedValue(v8::tracing::TracedValue* value) const; 32 std::string type; 33 const char* function_name; 34 int script_offset; 35 const char* script_name; 36 int line_num; 37 int column_num; 38 bool is_constructor; 39 bool is_optimized; 40 std::string state; 41 // Address of the map. 42 void* map; 43 // Whether map is a dictionary map. 44 bool is_dictionary_map; 45 // Number of own descriptors. 46 unsigned number_of_own_descriptors; 47 std::string instance_type; 48 }; 49 50 class ICStats { 51 public: 52 const int MAX_IC_INFO = 4096; 53 54 ICStats(); 55 void Dump(); 56 void Begin(); 57 void End(); 58 void Reset(); Current()59 V8_INLINE ICInfo& Current() { 60 DCHECK(pos_ >= 0 && pos_ < MAX_IC_INFO); 61 return ic_infos_[pos_]; 62 } 63 const char* GetOrCacheScriptName(Script script); 64 const char* GetOrCacheFunctionName(JSFunction function); instance()65 V8_INLINE static ICStats* instance() { return instance_.Pointer(); } 66 67 private: 68 static base::LazyInstance<ICStats>::type instance_; 69 base::Atomic32 enabled_; 70 std::vector<ICInfo> ic_infos_; 71 // Keys are Script pointers; uses raw Address to keep includes light. 72 std::unordered_map<Address, std::unique_ptr<char[]>> script_name_map_; 73 // Keys are JSFunction pointers; uses raw Address to keep includes light. 74 std::unordered_map<Address, std::unique_ptr<char[]>> function_name_map_; 75 int pos_; 76 }; 77 78 } // namespace internal 79 } // namespace v8 80 81 #endif // V8_IC_IC_STATS_H_ 82