V8 Project
v8::internal::StubCache Class Reference

#include <stub-cache.h>

+ Collaboration diagram for v8::internal::StubCache:

Classes

struct  Entry
 

Public Types

enum  Table { kPrimary , kSecondary }
 

Public Member Functions

void Initialize ()
 
CodeSet (Name *name, Map *map, Code *code)
 
CodeGet (Name *name, Map *map, Code::Flags flags)
 
void Clear ()
 
void CollectMatchingMaps (SmallMapList *types, Handle< Name > name, Code::Flags flags, Handle< Context > native_context, Zone *zone)
 
void GenerateProbe (MacroAssembler *masm, Code::Flags flags, bool leave_frame, Register receiver, Register name, Register scratch, Register extra, Register extra2=no_reg, Register extra3=no_reg)
 
SCTableReference key_reference (StubCache::Table table)
 
SCTableReference map_reference (StubCache::Table table)
 
SCTableReference value_reference (StubCache::Table table)
 
StubCache::Entryfirst_entry (StubCache::Table table)
 
Isolateisolate ()
 

Static Public Attributes

static const int kCacheIndexShift = Name::kHashShift
 

Private Member Functions

 StubCache (Isolate *isolate)
 
 DISALLOW_COPY_AND_ASSIGN (StubCache)
 

Static Private Member Functions

static int PrimaryOffset (Name *name, Code::Flags flags, Map *map)
 
static int SecondaryOffset (Name *name, Code::Flags flags, int seed)
 
static Entryentry (Entry *table, int offset)
 

Private Attributes

Entry primary_ [kPrimaryTableSize]
 
Entry secondary_ [kSecondaryTableSize]
 
Isolateisolate_
 

Static Private Attributes

static const int kPrimaryTableBits = 11
 
static const int kPrimaryTableSize = (1 << kPrimaryTableBits)
 
static const int kSecondaryTableBits = 9
 
static const int kSecondaryTableSize = (1 << kSecondaryTableBits)
 

Friends

class Isolate
 
class SCTableReference
 

Detailed Description

Definition at line 33 of file stub-cache.h.

Member Enumeration Documentation

◆ Table

Enumerator
kPrimary 
kSecondary 

Definition at line 60 of file stub-cache.h.

Constructor & Destructor Documentation

◆ StubCache()

v8::internal::StubCache::StubCache ( Isolate isolate)
explicitprivate

Definition at line 15 of file stub-cache.cc.

15 : isolate_(isolate) {}

Member Function Documentation

◆ Clear()

void v8::internal::StubCache::Clear ( )

Definition at line 93 of file stub-cache.cc.

93  {
94  Code* empty = isolate_->builtins()->builtin(Builtins::kIllegal);
95  for (int i = 0; i < kPrimaryTableSize; i++) {
96  primary_[i].key = isolate()->heap()->empty_string();
97  primary_[i].map = NULL;
98  primary_[i].value = empty;
99  }
100  for (int j = 0; j < kSecondaryTableSize; j++) {
101  secondary_[j].key = isolate()->heap()->empty_string();
102  secondary_[j].map = NULL;
103  secondary_[j].value = empty;
104  }
105 }
Code * builtin(Name name)
Definition: builtins.h:254
Builtins * builtins()
Definition: isolate.h:947
Entry secondary_[kSecondaryTableSize]
Definition: stub-cache.h:160
static const int kSecondaryTableSize
Definition: stub-cache.h:156
static const int kPrimaryTableSize
Definition: stub-cache.h:154
Entry primary_[kPrimaryTableSize]
Definition: stub-cache.h:159
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

References v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), v8::internal::Isolate::heap(), isolate(), isolate_, v8::internal::StubCache::Entry::key, kPrimaryTableSize, kSecondaryTableSize, v8::internal::StubCache::Entry::map, NULL, primary_, secondary_, and v8::internal::StubCache::Entry::value.

Referenced by v8::internal::MarkCompactCollector::Finish(), and Initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CollectMatchingMaps()

void v8::internal::StubCache::CollectMatchingMaps ( SmallMapList *  types,
Handle< Name name,
Code::Flags  flags,
Handle< Context native_context,
Zone zone 
)

Definition at line 108 of file stub-cache.cc.

111  {
112  for (int i = 0; i < kPrimaryTableSize; i++) {
113  if (primary_[i].key == *name) {
114  Map* map = primary_[i].map;
115  // Map can be NULL, if the stub is constant function call
116  // with a primitive receiver.
117  if (map == NULL) continue;
118 
119  int offset = PrimaryOffset(*name, flags, map);
120  if (entry(primary_, offset) == &primary_[i] &&
121  !TypeFeedbackOracle::CanRetainOtherContext(map, *native_context)) {
122  types->AddMapIfMissing(Handle<Map>(map), zone);
123  }
124  }
125  }
126 
127  for (int i = 0; i < kSecondaryTableSize; i++) {
128  if (secondary_[i].key == *name) {
129  Map* map = secondary_[i].map;
130  // Map can be NULL, if the stub is constant function call
131  // with a primitive receiver.
132  if (map == NULL) continue;
133 
134  // Lookup in primary table and skip duplicates.
135  int primary_offset = PrimaryOffset(*name, flags, map);
136 
137  // Lookup in secondary table and add matches.
138  int offset = SecondaryOffset(*name, flags, primary_offset);
139  if (entry(secondary_, offset) == &secondary_[i] &&
140  !TypeFeedbackOracle::CanRetainOtherContext(map, *native_context)) {
141  types->AddMapIfMissing(Handle<Map>(map), zone);
142  }
143  }
144  }
145 }
static Entry * entry(Entry *table, int offset)
Definition: stub-cache.h:147
static int PrimaryOffset(Name *name, Code::Flags flags, Map *map)
Definition: stub-cache.h:108
static int SecondaryOffset(Name *name, Code::Flags flags, int seed)
Definition: stub-cache.h:130
static bool CanRetainOtherContext(Map *map, Context *native_context)
Definition: type-info.cc:326
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf map
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name

References v8::internal::TypeFeedbackOracle::CanRetainOtherContext(), entry(), v8::internal::anonymous_namespace{flags.cc}::flags, kPrimaryTableSize, kSecondaryTableSize, map, v8::internal::StubCache::Entry::map, name, NULL, primary_, PrimaryOffset(), secondary_, and SecondaryOffset().

Referenced by v8::internal::TypeFeedbackOracle::CollectReceiverTypes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::StubCache::DISALLOW_COPY_AND_ASSIGN ( StubCache  )
private

◆ entry()

static Entry* v8::internal::StubCache::entry ( Entry table,
int  offset 
)
inlinestaticprivate

Definition at line 147 of file stub-cache.h.

147  {
148  const int multiplier = sizeof(*table) >> Name::kHashShift;
149  return reinterpret_cast<Entry*>(reinterpret_cast<Address>(table) +
150  offset * multiplier);
151  }
static const int kHashShift
Definition: objects.h:8499
byte * Address
Definition: globals.h:101

References v8::internal::Name::kHashShift.

Referenced by CollectMatchingMaps(), Get(), and Set().

+ Here is the caller graph for this function:

◆ first_entry()

StubCache::Entry* v8::internal::StubCache::first_entry ( StubCache::Table  table)
inline

Definition at line 77 of file stub-cache.h.

77  {
78  switch (table) {
80  return StubCache::primary_;
82  return StubCache::secondary_;
83  }
84  UNREACHABLE();
85  return NULL;
86  }
#define UNREACHABLE()
Definition: logging.h:30

References kPrimary, kSecondary, NULL, primary_, secondary_, and UNREACHABLE.

Referenced by key_reference(), map_reference(), and value_reference().

+ Here is the caller graph for this function:

◆ GenerateProbe()

void v8::internal::StubCache::GenerateProbe ( MacroAssembler masm,
Code::Flags  flags,
bool  leave_frame,
Register  receiver,
Register  name,
Register  scratch,
Register  extra,
Register  extra2 = no_reg,
Register  extra3 = no_reg 
)

◆ Get()

Code * v8::internal::StubCache::Get ( Name name,
Map map,
Code::Flags  flags 
)

Definition at line 77 of file stub-cache.cc.

77  {
79  int primary_offset = PrimaryOffset(name, flags, map);
80  Entry* primary = entry(primary_, primary_offset);
81  if (primary->key == name && primary->map == map) {
82  return primary->value;
83  }
84  int secondary_offset = SecondaryOffset(name, flags, primary_offset);
85  Entry* secondary = entry(secondary_, secondary_offset);
86  if (secondary->key == name && secondary->map == map) {
87  return secondary->value;
88  }
89  return NULL;
90 }
static Code::Flags CommonStubCacheChecks(Name *name, Map *map, Code::Flags flags)
Definition: stub-cache.cc:25

References v8::internal::CommonStubCacheChecks(), entry(), v8::internal::anonymous_namespace{flags.cc}::flags, v8::internal::StubCache::Entry::key, map, v8::internal::StubCache::Entry::map, name, NULL, primary_, PrimaryOffset(), secondary_, SecondaryOffset(), and v8::internal::StubCache::Entry::value.

Referenced by v8::internal::IC::ComputeHandler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Initialize()

void v8::internal::StubCache::Initialize ( )

Definition at line 18 of file stub-cache.cc.

18  {
21  Clear();
22 }
#define DCHECK(condition)
Definition: logging.h:205
bool IsPowerOfTwo32(uint32_t value)
Definition: bits.h:77

References Clear(), DCHECK, v8::base::bits::IsPowerOfTwo32(), kPrimaryTableSize, and kSecondaryTableSize.

Referenced by v8::internal::Isolate::Init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isolate()

Isolate* v8::internal::StubCache::isolate ( )
inline

Definition at line 88 of file stub-cache.h.

88 { return isolate_; }

References isolate_.

Referenced by Clear(), and Set().

+ Here is the caller graph for this function:

◆ key_reference()

SCTableReference v8::internal::StubCache::key_reference ( StubCache::Table  table)
inline

Definition at line 62 of file stub-cache.h.

62  {
63  return SCTableReference(
64  reinterpret_cast<Address>(&first_entry(table)->key));
65  }
StubCache::Entry * first_entry(StubCache::Table table)
Definition: stub-cache.h:77
friend class SCTableReference
Definition: stub-cache.h:164

References first_entry(), and SCTableReference.

+ Here is the call graph for this function:

◆ map_reference()

SCTableReference v8::internal::StubCache::map_reference ( StubCache::Table  table)
inline

Definition at line 67 of file stub-cache.h.

67  {
68  return SCTableReference(
69  reinterpret_cast<Address>(&first_entry(table)->map));
70  }

References first_entry(), map, and SCTableReference.

+ Here is the call graph for this function:

◆ PrimaryOffset()

static int v8::internal::StubCache::PrimaryOffset ( Name name,
Code::Flags  flags,
Map map 
)
inlinestaticprivate

Definition at line 108 of file stub-cache.h.

108  {
110  // Compute the hash of the name (use entire hash field).
111  DCHECK(name->HasHashCode());
112  uint32_t field = name->hash_field();
113  // Using only the low bits in 64-bit mode is unlikely to increase the
114  // risk of collision even if the heap is spread over an area larger than
115  // 4Gb (and not at all if it isn't).
116  uint32_t map_low32bits =
117  static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map));
118  // We always set the in_loop bit to zero when generating the lookup code
119  // so do it here too so the hash codes match.
120  uint32_t iflags =
121  (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
122  // Base the offset on a simple combination of name, flags, and map.
123  uint32_t key = (map_low32bits + field) ^ iflags;
124  return key & ((kPrimaryTableSize - 1) << kCacheIndexShift);
125  }
static const int kFlagsNotUsedInLookup
Definition: objects.h:5448
static const int kCacheIndexShift
Definition: stub-cache.h:93
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))

References DCHECK, v8::internal::anonymous_namespace{flags.cc}::flags, kCacheIndexShift, v8::internal::Code::kFlagsNotUsedInLookup, v8::internal::Name::kHashShift, kPrimaryTableSize, map, name, and v8::internal::STATIC_ASSERT().

Referenced by CollectMatchingMaps(), Get(), and Set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SecondaryOffset()

static int v8::internal::StubCache::SecondaryOffset ( Name name,
Code::Flags  flags,
int  seed 
)
inlinestaticprivate

Definition at line 130 of file stub-cache.h.

130  {
131  // Use the seed from the primary cache in the secondary cache.
132  uint32_t name_low32bits =
133  static_cast<uint32_t>(reinterpret_cast<uintptr_t>(name));
134  // We always set the in_loop bit to zero when generating the lookup code
135  // so do it here too so the hash codes match.
136  uint32_t iflags =
137  (static_cast<uint32_t>(flags) & ~Code::kFlagsNotUsedInLookup);
138  uint32_t key = (seed - name_low32bits) + iflags;
139  return key & ((kSecondaryTableSize - 1) << kCacheIndexShift);
140  }

References v8::internal::anonymous_namespace{flags.cc}::flags, kCacheIndexShift, v8::internal::Code::kFlagsNotUsedInLookup, kSecondaryTableSize, and name.

Referenced by CollectMatchingMaps(), Get(), and Set().

+ Here is the caller graph for this function:

◆ Set()

Code * v8::internal::StubCache::Set ( Name name,
Map map,
Code code 
)

Definition at line 48 of file stub-cache.cc.

48  {
49  Code::Flags flags = CommonStubCacheChecks(name, map, code->flags());
50 
51  // Compute the primary entry.
52  int primary_offset = PrimaryOffset(name, flags, map);
53  Entry* primary = entry(primary_, primary_offset);
54  Code* old_code = primary->value;
55 
56  // If the primary entry has useful data in it, we retire it to the
57  // secondary cache before overwriting it.
58  if (old_code != isolate_->builtins()->builtin(Builtins::kIllegal)) {
59  Map* old_map = primary->map;
60  Code::Flags old_flags =
61  Code::RemoveTypeAndHolderFromFlags(old_code->flags());
62  int seed = PrimaryOffset(primary->key, old_flags, old_map);
63  int secondary_offset = SecondaryOffset(primary->key, old_flags, seed);
64  Entry* secondary = entry(secondary_, secondary_offset);
65  *secondary = *primary;
66  }
67 
68  // Update primary cache.
69  primary->key = name;
70  primary->value = code;
71  primary->map = map;
72  isolate()->counters()->megamorphic_stub_cache_updates()->Increment();
73  return code;
74 }
static Flags RemoveTypeAndHolderFromFlags(Flags flags)
Definition: objects-inl.h:5012
uint32_t Flags
Definition: objects.h:4929
Counters * counters()
Definition: isolate.h:857

References v8::internal::Builtins::builtin(), v8::internal::Isolate::builtins(), v8::internal::CommonStubCacheChecks(), v8::internal::Isolate::counters(), entry(), v8::internal::Code::flags(), v8::internal::anonymous_namespace{flags.cc}::flags, isolate(), isolate_, v8::internal::StubCache::Entry::key, map, v8::internal::StubCache::Entry::map, name, primary_, PrimaryOffset(), v8::internal::Code::RemoveTypeAndHolderFromFlags(), secondary_, SecondaryOffset(), and v8::internal::StubCache::Entry::value.

Referenced by v8::internal::IC::UpdateMegamorphicCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ value_reference()

SCTableReference v8::internal::StubCache::value_reference ( StubCache::Table  table)
inline

Definition at line 72 of file stub-cache.h.

72  {
73  return SCTableReference(
74  reinterpret_cast<Address>(&first_entry(table)->value));
75  }

References first_entry(), and SCTableReference.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ Isolate

friend class Isolate
friend

Definition at line 163 of file stub-cache.h.

◆ SCTableReference

friend class SCTableReference
friend

Definition at line 164 of file stub-cache.h.

Referenced by key_reference(), map_reference(), and value_reference().

Member Data Documentation

◆ isolate_

Isolate* v8::internal::StubCache::isolate_
private

Definition at line 161 of file stub-cache.h.

Referenced by Clear(), isolate(), and Set().

◆ kCacheIndexShift

const int v8::internal::StubCache::kCacheIndexShift = Name::kHashShift
static

Definition at line 93 of file stub-cache.h.

Referenced by PrimaryOffset(), and SecondaryOffset().

◆ kPrimaryTableBits

const int v8::internal::StubCache::kPrimaryTableBits = 11
staticprivate

Definition at line 153 of file stub-cache.h.

◆ kPrimaryTableSize

const int v8::internal::StubCache::kPrimaryTableSize = (1 << kPrimaryTableBits)
staticprivate

Definition at line 154 of file stub-cache.h.

Referenced by Clear(), CollectMatchingMaps(), Initialize(), and PrimaryOffset().

◆ kSecondaryTableBits

const int v8::internal::StubCache::kSecondaryTableBits = 9
staticprivate

Definition at line 155 of file stub-cache.h.

◆ kSecondaryTableSize

const int v8::internal::StubCache::kSecondaryTableSize = (1 << kSecondaryTableBits)
staticprivate

Definition at line 156 of file stub-cache.h.

Referenced by Clear(), CollectMatchingMaps(), Initialize(), and SecondaryOffset().

◆ primary_

Entry v8::internal::StubCache::primary_[kPrimaryTableSize]
private

Definition at line 159 of file stub-cache.h.

Referenced by Clear(), CollectMatchingMaps(), first_entry(), Get(), and Set().

◆ secondary_

Entry v8::internal::StubCache::secondary_[kSecondaryTableSize]
private

Definition at line 160 of file stub-cache.h.

Referenced by Clear(), CollectMatchingMaps(), first_entry(), Get(), and Set().


The documentation for this class was generated from the following files: