Line data Source code
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 : }
22 :
23 : namespace internal {
24 :
25 : class JSFunction;
26 : class Script;
27 :
28 0 : 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 : bool is_constructor;
38 : bool is_optimized;
39 : std::string state;
40 : // Address of the map.
41 : void* map;
42 : // Whether map is a dictionary map.
43 : bool is_dictionary_map;
44 : // Number of own descriptors.
45 : unsigned number_of_own_descriptors;
46 : std::string instance_type;
47 : };
48 :
49 : class ICStats {
50 : public:
51 : const int MAX_IC_INFO = 4096;
52 :
53 : ICStats();
54 : void Dump();
55 : void Begin();
56 : void End();
57 : void Reset();
58 : V8_INLINE ICInfo& Current() {
59 : DCHECK(pos_ >= 0 && pos_ < MAX_IC_INFO);
60 0 : return ic_infos_[pos_];
61 : }
62 : const char* GetOrCacheScriptName(Script script);
63 : const char* GetOrCacheFunctionName(JSFunction function);
64 0 : V8_INLINE static ICStats* instance() { return instance_.Pointer(); }
65 :
66 : private:
67 : static base::LazyInstance<ICStats>::type instance_;
68 : base::Atomic32 enabled_;
69 : std::vector<ICInfo> ic_infos_;
70 : // Keys are Script pointers; uses raw Address to keep includes light.
71 : std::unordered_map<Address, std::unique_ptr<char[]>> script_name_map_;
72 : // Keys are JSFunction pointers; uses raw Address to keep includes light.
73 : std::unordered_map<Address, std::unique_ptr<char[]>> function_name_map_;
74 : int pos_;
75 : };
76 :
77 : } // namespace internal
78 : } // namespace v8
79 :
80 : #endif // V8_IC_IC_STATS_H_
|