V8 Project
stub-cache.cc
Go to the documentation of this file.
1 // Copyright 2012 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 #include "src/v8.h"
6 
7 #include "src/base/bits.h"
8 #include "src/ic/stub-cache.h"
9 #include "src/type-info.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 
15 StubCache::StubCache(Isolate* isolate) : isolate_(isolate) {}
16 
17 
21  Clear();
22 }
23 
24 
28 
29  // Validate that the name does not move on scavenge, and that we
30  // can use identity checks instead of structural equality checks.
31  DCHECK(!name->GetHeap()->InNewSpace(name));
32  DCHECK(name->IsUniqueName());
33 
34  // The state bits are not important to the hash function because the stub
35  // cache only contains handlers. Make sure that the bits are the least
36  // significant so they will be the ones masked out.
39 
40  // Make sure that the code type and cache holder are not included in the hash.
43 
44  return flags;
45 }
46 
47 
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 =
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 }
75 
76 
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 }
91 
92 
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 }
106 
107 
110  Handle<Context> native_context,
111  Zone* zone) {
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 }
146 }
147 } // namespace v8::internal
static const U kMask
Definition: utils.h:203
Code * builtin(Name name)
Definition: builtins.h:254
static StubType ExtractTypeFromFlags(Flags flags)
Definition: objects-inl.h:4996
static Flags RemoveTypeAndHolderFromFlags(Flags flags)
Definition: objects-inl.h:5012
static Kind ExtractKindFromFlags(Flags flags)
Definition: objects-inl.h:4981
static CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags)
Definition: objects-inl.h:5001
Builtins * builtins()
Definition: isolate.h:947
Counters * counters()
Definition: isolate.h:857
static Entry * entry(Entry *table, int offset)
Definition: stub-cache.h:147
Entry secondary_[kSecondaryTableSize]
Definition: stub-cache.h:160
StubCache(Isolate *isolate)
Definition: stub-cache.cc:15
Code * Get(Name *name, Map *map, Code::Flags flags)
Definition: stub-cache.cc:77
static int PrimaryOffset(Name *name, Code::Flags flags, Map *map)
Definition: stub-cache.h:108
static const int kSecondaryTableSize
Definition: stub-cache.h:156
static const int kPrimaryTableSize
Definition: stub-cache.h:154
static int SecondaryOffset(Name *name, Code::Flags flags, int seed)
Definition: stub-cache.h:130
Entry primary_[kPrimaryTableSize]
Definition: stub-cache.h:159
Code * Set(Name *name, Map *map, Code *code)
Definition: stub-cache.cc:48
void CollectMatchingMaps(SmallMapList *types, Handle< Name > name, Code::Flags flags, Handle< Context > native_context, Zone *zone)
Definition: stub-cache.cc:108
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
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
#define DCHECK(condition)
Definition: logging.h:205
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
bool IsPowerOfTwo32(uint32_t value)
Definition: bits.h:77
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
static Code::Flags CommonStubCacheChecks(Name *name, Map *map, Code::Flags flags)
Definition: stub-cache.cc:25
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20