V8 Project
stub-cache-arm64.cc
Go to the documentation of this file.
1 // Copyright 2013 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 #if V8_TARGET_ARCH_ARM64
8 
9 #include "src/codegen.h"
10 #include "src/ic/stub-cache.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 
16 #define __ ACCESS_MASM(masm)
17 
18 
19 // Probe primary or secondary table.
20 // If the entry is found in the cache, the generated code jump to the first
21 // instruction of the stub in the cache.
22 // If there is a miss the code fall trough.
23 //
24 // 'receiver', 'name' and 'offset' registers are preserved on miss.
25 static void ProbeTable(Isolate* isolate, MacroAssembler* masm,
26  Code::Flags flags, bool leave_frame,
27  StubCache::Table table, Register receiver, Register name,
28  Register offset, Register scratch, Register scratch2,
29  Register scratch3) {
30  // Some code below relies on the fact that the Entry struct contains
31  // 3 pointers (name, code, map).
32  STATIC_ASSERT(sizeof(StubCache::Entry) == (3 * kPointerSize));
33 
34  ExternalReference key_offset(isolate->stub_cache()->key_reference(table));
35  ExternalReference value_offset(isolate->stub_cache()->value_reference(table));
36  ExternalReference map_offset(isolate->stub_cache()->map_reference(table));
37 
38  uintptr_t key_off_addr = reinterpret_cast<uintptr_t>(key_offset.address());
39  uintptr_t value_off_addr =
40  reinterpret_cast<uintptr_t>(value_offset.address());
41  uintptr_t map_off_addr = reinterpret_cast<uintptr_t>(map_offset.address());
42 
43  Label miss;
44 
45  DCHECK(!AreAliased(name, offset, scratch, scratch2, scratch3));
46 
47  // Multiply by 3 because there are 3 fields per entry.
48  __ Add(scratch3, offset, Operand(offset, LSL, 1));
49 
50  // Calculate the base address of the entry.
51  __ Mov(scratch, key_offset);
52  __ Add(scratch, scratch, Operand(scratch3, LSL, kPointerSizeLog2));
53 
54  // Check that the key in the entry matches the name.
55  __ Ldr(scratch2, MemOperand(scratch));
56  __ Cmp(name, scratch2);
57  __ B(ne, &miss);
58 
59  // Check the map matches.
60  __ Ldr(scratch2, MemOperand(scratch, map_off_addr - key_off_addr));
61  __ Ldr(scratch3, FieldMemOperand(receiver, HeapObject::kMapOffset));
62  __ Cmp(scratch2, scratch3);
63  __ B(ne, &miss);
64 
65  // Get the code entry from the cache.
66  __ Ldr(scratch, MemOperand(scratch, value_off_addr - key_off_addr));
67 
68  // Check that the flags match what we're looking for.
69  __ Ldr(scratch2.W(), FieldMemOperand(scratch, Code::kFlagsOffset));
70  __ Bic(scratch2.W(), scratch2.W(), Code::kFlagsNotUsedInLookup);
71  __ Cmp(scratch2.W(), flags);
72  __ B(ne, &miss);
73 
74 #ifdef DEBUG
75  if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) {
76  __ B(&miss);
77  } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) {
78  __ B(&miss);
79  }
80 #endif
81 
82  if (leave_frame) __ LeaveFrame(StackFrame::INTERNAL);
83 
84  // Jump to the first instruction in the code stub.
85  __ Add(scratch, scratch, Code::kHeaderSize - kHeapObjectTag);
86  __ Br(scratch);
87 
88  // Miss: fall through.
89  __ Bind(&miss);
90 }
91 
92 
93 void StubCache::GenerateProbe(MacroAssembler* masm, Code::Flags flags,
94  bool leave_frame, Register receiver,
95  Register name, Register scratch, Register extra,
96  Register extra2, Register extra3) {
97  Isolate* isolate = masm->isolate();
98  Label miss;
99 
100  // Make sure the flags does not name a specific type.
102 
103  // Make sure that there are no register conflicts.
104  DCHECK(!AreAliased(receiver, name, scratch, extra, extra2, extra3));
105 
106  // Make sure extra and extra2 registers are valid.
107  DCHECK(!extra.is(no_reg));
108  DCHECK(!extra2.is(no_reg));
109  DCHECK(!extra3.is(no_reg));
110 
111  Counters* counters = masm->isolate()->counters();
112  __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1, extra2,
113  extra3);
114 
115  // Check that the receiver isn't a smi.
116  __ JumpIfSmi(receiver, &miss);
117 
118  // Compute the hash for primary table.
120  __ Ldr(extra, FieldMemOperand(receiver, HeapObject::kMapOffset));
121  __ Add(scratch, scratch, extra);
122  __ Eor(scratch, scratch, flags);
123  // We shift out the last two bits because they are not part of the hash.
124  __ Ubfx(scratch, scratch, kCacheIndexShift,
126 
127  // Probe the primary table.
128  ProbeTable(isolate, masm, flags, leave_frame, kPrimary, receiver, name,
129  scratch, extra, extra2, extra3);
130 
131  // Primary miss: Compute hash for secondary table.
132  __ Sub(scratch, scratch, Operand(name, LSR, kCacheIndexShift));
133  __ Add(scratch, scratch, flags >> kCacheIndexShift);
134  __ And(scratch, scratch, kSecondaryTableSize - 1);
135 
136  // Probe the secondary table.
137  ProbeTable(isolate, masm, flags, leave_frame, kSecondary, receiver, name,
138  scratch, extra, extra2, extra3);
139 
140  // Cache miss: Fall-through and let caller handle the miss by
141  // entering the runtime system.
142  __ Bind(&miss);
143  __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1, extra2,
144  extra3);
145 }
146 }
147 } // namespace v8::internal
148 
149 #endif // V8_TARGET_ARCH_ARM64
static const int kFlagsOffset
Definition: objects.h:5361
static StubType ExtractTypeFromFlags(Flags flags)
Definition: objects-inl.h:4996
static const int kFlagsNotUsedInLookup
Definition: objects.h:5448
static const int kHeaderSize
Definition: objects.h:5373
uint32_t Flags
Definition: objects.h:4929
static const int kMapOffset
Definition: objects.h:1427
static const int kHashFieldOffset
Definition: objects.h:8486
static const int kCacheIndexShift
Definition: stub-cache.h:93
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)
static const int kSecondaryTableSize
Definition: stub-cache.h:156
static const int kPrimaryTableSize
Definition: stub-cache.h:154
friend class Isolate
Definition: stub-cache.h:163
#define __
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
#define DCHECK(condition)
Definition: logging.h:205
const int kPointerSize
Definition: globals.h:129
bool AreAliased(const CPURegister &reg1, const CPURegister &reg2, const CPURegister &reg3=NoReg, const CPURegister &reg4=NoReg, const CPURegister &reg5=NoReg, const CPURegister &reg6=NoReg, const CPURegister &reg7=NoReg, const CPURegister &reg8=NoReg)
const int kPointerSizeLog2
Definition: globals.h:147
MemOperand FieldMemOperand(Register object, int offset)
const int kHeapObjectTag
Definition: v8.h:5737
const Register no_reg
STATIC_ASSERT(sizeof(CPURegister)==sizeof(Register))
int CountTrailingZeros(uint64_t value, int width)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20