aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/ic/ic-stats.h
blob: a3015d0a6a940a0540aa585deac061ec2cda81cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_IC_IC_STATS_H_
#define V8_IC_IC_STATS_H_

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "src/base/atomicops.h"
#include "src/base/lazy-instance.h"

namespace v8 {

namespace tracing {
class TracedValue;
}

namespace internal {

class JSFunction;
class Script;

struct ICInfo {
  ICInfo();
  void Reset();
  void AppendToTracedValue(v8::tracing::TracedValue* value) const;
  std::string type;
  const char* function_name;
  int script_offset;
  const char* script_name;
  int line_num;
  bool is_constructor;
  bool is_optimized;
  std::string state;
  // Address of the map.
  void* map;
  // Whether map is a dictionary map.
  bool is_dictionary_map;
  // Number of own descriptors.
  unsigned number_of_own_descriptors;
  std::string instance_type;
};

class ICStats {
 public:
  const int MAX_IC_INFO = 4096;

  ICStats();
  void Dump();
  void Begin();
  void End();
  void Reset();
  V8_INLINE ICInfo& Current() {
    DCHECK(pos_ >= 0 && pos_ < MAX_IC_INFO);
    return ic_infos_[pos_];
  }
  const char* GetOrCacheScriptName(Script* script);
  const char* GetOrCacheFunctionName(JSFunction* function);
  V8_INLINE static ICStats* instance() { return instance_.Pointer(); }

 private:
  static base::LazyInstance<ICStats>::type instance_;
  base::Atomic32 enabled_;
  std::vector<ICInfo> ic_infos_;
  std::unordered_map<Script*, std::unique_ptr<char[]>> script_name_map_;
  std::unordered_map<JSFunction*, std::unique_ptr<char[]>> function_name_map_;
  int pos_;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_IC_IC_STATS_H_