V8 Project
ic-inl.h
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 #ifndef V8_IC_INL_H_
6 #define V8_IC_INL_H_
7 
8 #include "src/ic/ic.h"
9 
10 #include "src/compiler.h"
11 #include "src/debug.h"
12 #include "src/macro-assembler.h"
13 #include "src/prototype.h"
14 
15 namespace v8 {
16 namespace internal {
17 
18 
20  // Get the address of the call.
22 
23  Debug* debug = isolate()->debug();
24  // First check if any break points are active if not just return the address
25  // of the call.
26  if (!debug->has_break_points()) return result;
27 
28  // At least one break point is active perform additional test to ensure that
29  // break point locations are updated correctly.
30  if (debug->IsDebugBreak(
32  // If the call site is a call to debug break then return the address in
33  // the original code instead of the address in the running code. This will
34  // cause the original code to be updated and keeps the breakpoint active in
35  // the running code.
36  Code* code = GetCode();
37  Code* original_code = GetOriginalCode();
38  intptr_t delta =
39  original_code->instruction_start() - code->instruction_start();
40  // Return the address in the original code. This is the place where
41  // the call which has been overwritten by the DebugBreakXXX resides
42  // and the place where the inline cache system should look.
43  return result + delta;
44  } else {
45  // No break point here just return the address of the call.
46  return result;
47  }
48 }
49 
50 
52  if (!FLAG_enable_ool_constant_pool) {
53  return NULL;
54  } else {
56  Debug* debug = isolate()->debug();
57  // First check if any break points are active if not just return the
58  // original constant pool.
59  if (!debug->has_break_points()) return *result;
60 
61  // At least one break point is active perform additional test to ensure that
62  // break point locations are updated correctly.
64  if (debug->IsDebugBreak(
66  // If the call site is a call to debug break then we want to return the
67  // constant pool for the original code instead of the breakpointed code.
68  return GetOriginalCode()->constant_pool();
69  }
70  return *result;
71  }
72 }
73 
74 
76  if (FLAG_enable_ool_constant_pool) {
77  return *raw_constant_pool_;
78  } else {
79  return NULL;
80  }
81 }
82 
83 
85  ConstantPoolArray* constant_pool) {
86  // Get the target address of the IC.
88  // Convert target address to the code object. Code::GetCodeFromTargetAddress
89  // is safe for use during GC where the map might be marked.
91  DCHECK(result->is_inline_cache_stub());
92  return result;
93 }
94 
95 
96 void IC::SetTargetAtAddress(Address address, Code* target,
97  ConstantPoolArray* constant_pool) {
98  DCHECK(target->is_inline_cache_stub() || target->is_compare_ic_stub());
99  Heap* heap = target->GetHeap();
101 #ifdef DEBUG
102  // STORE_IC and KEYED_STORE_IC use Code::extra_ic_state() to mark
103  // ICs as strict mode. The strict-ness of the IC must be preserved.
104  if (old_target->kind() == Code::STORE_IC ||
105  old_target->kind() == Code::KEYED_STORE_IC) {
107  StoreIC::GetStrictMode(target->extra_ic_state()));
108  }
109 #endif
111  target->instruction_start());
112  if (heap->gc_state() == Heap::MARK_COMPACT) {
114  } else {
116  }
117  PostPatching(address, target, old_target);
118 }
119 
120 
121 void IC::set_target(Code* code) {
122 #ifdef VERIFY_HEAP
123  code->VerifyEmbeddedObjectsDependency();
124 #endif
126  target_set_ = true;
127 }
128 
129 
131  // The contextual mode must be preserved across IC patching.
132  DCHECK(LoadICState::GetContextualMode(code->extra_ic_state()) ==
133  LoadICState::GetContextualMode(target()->extra_ic_state()));
134 
135  IC::set_target(code);
136 }
137 
138 
140  // Strict mode must be preserved across IC patching.
143  IC::set_target(code);
144 }
145 
146 
148  // Strict mode must be preserved across IC patching.
150  IC::set_target(code);
151 }
152 
153 
156 }
157 
159 
160 
161 template <class TypeClass>
162 JSFunction* IC::GetRootConstructor(TypeClass* type, Context* native_context) {
163  if (type->Is(TypeClass::Boolean())) {
164  return native_context->boolean_function();
165  } else if (type->Is(TypeClass::Number())) {
166  return native_context->number_function();
167  } else if (type->Is(TypeClass::String())) {
168  return native_context->string_function();
169  } else if (type->Is(TypeClass::Symbol())) {
170  return native_context->symbol_function();
171  } else {
172  return NULL;
173  }
174 }
175 
176 
177 Handle<Map> IC::GetHandlerCacheHolder(HeapType* type, bool receiver_is_holder,
178  Isolate* isolate, CacheHolderFlag* flag) {
179  Handle<Map> receiver_map = TypeToMap(type, isolate);
180  if (receiver_is_holder) {
182  return receiver_map;
183  }
184  Context* native_context = *isolate->native_context();
185  JSFunction* builtin_ctor = GetRootConstructor(type, native_context);
186  if (builtin_ctor != NULL) {
188  return handle(HeapObject::cast(builtin_ctor->instance_prototype())->map());
189  }
190  *flag = receiver_map->is_dictionary_map()
193  // Callers must ensure that the prototype is non-null.
194  return handle(JSObject::cast(receiver_map->prototype())->map());
195 }
196 
197 
200  Context* native_context = *isolate->native_context();
201  JSFunction* builtin_ctor = GetRootConstructor(type, native_context);
202  if (builtin_ctor != NULL) {
204  return handle(builtin_ctor->initial_map());
205  }
207  return TypeToMap(type, isolate);
208 }
209 
210 
212  Handle<Smi> slot) const {
214  Object* feedback = vector->get(slot->value());
215 
216  if (feedback == *TypeFeedbackVector::MegamorphicSentinel(isolate())) {
217  state = GENERIC;
218  } else if (feedback->IsAllocationSite() || feedback->IsJSFunction()) {
219  state = MONOMORPHIC;
220  } else {
222  }
223 
224  return state;
225 }
226 }
227 } // namespace v8::internal
228 
229 #endif // V8_IC_INL_H_
static Address target_address_at(Address pc, ConstantPoolArray *constant_pool)
static void set_target_address_at(Address pc, ConstantPoolArray *constant_pool, Address target, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
static Address target_address_from_return_address(Address pc)
IC::State FeedbackToState(Handle< TypeFeedbackVector > vector, Handle< Smi > slot) const
Definition: ic-inl.h:211
ConstantPoolArray * constant_pool()
Definition: objects-inl.h:4942
static Code * GetCodeFromTargetAddress(Address address)
Definition: objects-inl.h:5018
ExtraICState extra_ic_state()
Definition: objects-inl.h:4647
bool is_inline_cache_stub()
Definition: objects-inl.h:4921
byte * instruction_start()
Definition: objects-inl.h:6176
bool has_break_points() const
Definition: debug.h:467
static bool IsDebugBreak(Address addr)
Definition: debug.cc:1541
HeapState gc_state()
Definition: heap.h:955
IncrementalMarking * incremental_marking()
Definition: heap.h:1205
MarkCompactCollector * mark_compact_collector()
Definition: heap.h:1197
static void PostPatching(Address address, Code *target, Code *old_target)
Definition: ic.cc:422
Code * GetOriginalCode() const
Definition: ic.cc:209
static void SetTargetAtAddress(Address address, Code *target, ConstantPoolArray *constant_pool)
Definition: ic-inl.h:96
static Handle< Map > TypeToMap(HeapType *type, Isolate *isolate)
Definition: ic.cc:719
void UpdateTarget()
Definition: ic-inl.h:158
static Code * GetTargetAtAddress(Address address, ConstantPoolArray *constant_pool)
Definition: ic-inl.h:84
State state() const
Definition: ic.h:66
Handle< Code > target_
Definition: ic.h:262
ConstantPoolArray * constant_pool() const
Definition: ic-inl.h:51
Handle< ConstantPoolArray > raw_constant_pool_
Definition: ic.h:259
Isolate * isolate() const
Definition: ic.h:136
Code * raw_target() const
Definition: ic-inl.h:154
static JSFunction * GetRootConstructor(TypeClass *type, Context *native_context)
Definition: ic-inl.h:162
Isolate * isolate_
Definition: ic.h:255
bool target_set_
Definition: ic.h:263
ExtraICState extra_ic_state() const
Definition: ic.h:200
Address address() const
Definition: ic-inl.h:19
Handle< Code > target() const
Definition: ic.h:132
void set_target(Code *code)
Definition: ic-inl.h:121
ConstantPoolArray * raw_constant_pool() const
Definition: ic-inl.h:75
static Handle< Map > GetHandlerCacheHolder(HeapType *type, bool receiver_is_holder, Isolate *isolate, CacheHolderFlag *flag)
Definition: ic-inl.h:177
Address pc() const
Definition: ic.h:135
static Handle< Map > GetICCacheHolder(HeapType *type, Isolate *isolate, CacheHolderFlag *flag)
Definition: ic-inl.h:198
Code * GetCode() const
Definition: ic.cc:201
void RecordCodeTargetPatch(Code *host, Address pc, HeapObject *value)
Handle< Context > native_context()
Definition: isolate.cc:1339
void set_target(Code *code)
Definition: ic-inl.h:147
void set_target(Code *code)
Definition: ic-inl.h:130
void RecordCodeTargetPatch(Address pc, Code *target)
void set_target(Code *code)
Definition: ic-inl.h:139
static StrictMode GetStrictMode(ExtraICState state)
Definition: ic.h:453
StrictMode strict_mode() const
Definition: ic.h:465
static Handle< Object > UninitializedSentinel(Isolate *isolate)
static Handle< Object > MegamorphicSentinel(Isolate *isolate)
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 CHECK(condition)
Definition: logging.h:36
#define DCHECK(condition)
Definition: logging.h:205
IN DWORD64 OUT PDWORD64 OUT PIMAGEHLP_SYMBOL64 Symbol
@ kCacheOnPrototype
Definition: globals.h:485
@ kCacheOnReceiver
Definition: globals.h:488
@ kCacheOnPrototypeReceiverIsPrimitive
Definition: globals.h:487
@ kCacheOnPrototypeReceiverIsDictionary
Definition: globals.h:486
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
byte * Address
Definition: globals.h:101
kFeedbackVectorOffset flag
Definition: objects-inl.h:5418
@ UNINITIALIZED
Definition: globals.h:446
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20