xref: /third_party/node/deps/v8/src/ic/ic-stats.h (revision 1cb0ef41)
11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#ifndef V8_IC_IC_STATS_H_
61cb0ef41Sopenharmony_ci#define V8_IC_IC_STATS_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include <memory>
91cb0ef41Sopenharmony_ci#include <string>
101cb0ef41Sopenharmony_ci#include <unordered_map>
111cb0ef41Sopenharmony_ci#include <vector>
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci#include "include/v8-internal.h"  // For Address.
141cb0ef41Sopenharmony_ci#include "src/base/atomicops.h"
151cb0ef41Sopenharmony_ci#include "src/base/lazy-instance.h"
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cinamespace v8 {
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cinamespace tracing {
201cb0ef41Sopenharmony_ciclass TracedValue;
211cb0ef41Sopenharmony_ci}  // namespace tracing
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_cinamespace internal {
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ciclass JSFunction;
261cb0ef41Sopenharmony_ciclass Script;
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_cistruct ICInfo {
291cb0ef41Sopenharmony_ci  ICInfo();
301cb0ef41Sopenharmony_ci  void Reset();
311cb0ef41Sopenharmony_ci  void AppendToTracedValue(v8::tracing::TracedValue* value) const;
321cb0ef41Sopenharmony_ci  std::string type;
331cb0ef41Sopenharmony_ci  const char* function_name;
341cb0ef41Sopenharmony_ci  int script_offset;
351cb0ef41Sopenharmony_ci  const char* script_name;
361cb0ef41Sopenharmony_ci  int line_num;
371cb0ef41Sopenharmony_ci  int column_num;
381cb0ef41Sopenharmony_ci  bool is_constructor;
391cb0ef41Sopenharmony_ci  bool is_optimized;
401cb0ef41Sopenharmony_ci  std::string state;
411cb0ef41Sopenharmony_ci  // Address of the map.
421cb0ef41Sopenharmony_ci  void* map;
431cb0ef41Sopenharmony_ci  // Whether map is a dictionary map.
441cb0ef41Sopenharmony_ci  bool is_dictionary_map;
451cb0ef41Sopenharmony_ci  // Number of own descriptors.
461cb0ef41Sopenharmony_ci  unsigned number_of_own_descriptors;
471cb0ef41Sopenharmony_ci  std::string instance_type;
481cb0ef41Sopenharmony_ci};
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ciclass ICStats {
511cb0ef41Sopenharmony_ci public:
521cb0ef41Sopenharmony_ci  const int MAX_IC_INFO = 4096;
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_ci  ICStats();
551cb0ef41Sopenharmony_ci  void Dump();
561cb0ef41Sopenharmony_ci  void Begin();
571cb0ef41Sopenharmony_ci  void End();
581cb0ef41Sopenharmony_ci  void Reset();
591cb0ef41Sopenharmony_ci  V8_INLINE ICInfo& Current() {
601cb0ef41Sopenharmony_ci    DCHECK(pos_ >= 0 && pos_ < MAX_IC_INFO);
611cb0ef41Sopenharmony_ci    return ic_infos_[pos_];
621cb0ef41Sopenharmony_ci  }
631cb0ef41Sopenharmony_ci  const char* GetOrCacheScriptName(Script script);
641cb0ef41Sopenharmony_ci  const char* GetOrCacheFunctionName(JSFunction function);
651cb0ef41Sopenharmony_ci  V8_INLINE static ICStats* instance() { return instance_.Pointer(); }
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci private:
681cb0ef41Sopenharmony_ci  static base::LazyInstance<ICStats>::type instance_;
691cb0ef41Sopenharmony_ci  base::Atomic32 enabled_;
701cb0ef41Sopenharmony_ci  std::vector<ICInfo> ic_infos_;
711cb0ef41Sopenharmony_ci  // Keys are Script pointers; uses raw Address to keep includes light.
721cb0ef41Sopenharmony_ci  std::unordered_map<Address, std::unique_ptr<char[]>> script_name_map_;
731cb0ef41Sopenharmony_ci  // Keys are JSFunction pointers; uses raw Address to keep includes light.
741cb0ef41Sopenharmony_ci  std::unordered_map<Address, std::unique_ptr<char[]>> function_name_map_;
751cb0ef41Sopenharmony_ci  int pos_;
761cb0ef41Sopenharmony_ci};
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci}  // namespace internal
791cb0ef41Sopenharmony_ci}  // namespace v8
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci#endif  // V8_IC_IC_STATS_H_
82