v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ic-inl.h
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_IC_INL_H_
29 #define V8_IC_INL_H_
30 
31 #include "ic.h"
32 
33 #include "compiler.h"
34 #include "debug.h"
35 #include "macro-assembler.h"
36 
37 namespace v8 {
38 namespace internal {
39 
40 
42  // Get the address of the call.
44 
45 #ifdef ENABLE_DEBUGGER_SUPPORT
46  Debug* debug = isolate()->debug();
47  // First check if any break points are active if not just return the address
48  // of the call.
49  if (!debug->has_break_points()) return result;
50 
51  // At least one break point is active perform additional test to ensure that
52  // break point locations are updated correctly.
53  if (debug->IsDebugBreak(Assembler::target_address_at(result,
54  raw_constant_pool()))) {
55  // If the call site is a call to debug break then return the address in
56  // the original code instead of the address in the running code. This will
57  // cause the original code to be updated and keeps the breakpoint active in
58  // the running code.
59  Code* code = GetCode();
60  Code* original_code = GetOriginalCode();
61  intptr_t delta =
62  original_code->instruction_start() - code->instruction_start();
63  // Return the address in the original code. This is the place where
64  // the call which has been overwritten by the DebugBreakXXX resides
65  // and the place where the inline cache system should look.
66  return result + delta;
67  } else {
68  // No break point here just return the address of the call.
69  return result;
70  }
71 #else
72  return result;
73 #endif
74 }
75 
76 
77 ConstantPoolArray* IC::constant_pool() const {
78  if (!FLAG_enable_ool_constant_pool) {
79  return NULL;
80  } else {
81  Handle<ConstantPoolArray> result = raw_constant_pool_;
82 #ifdef ENABLE_DEBUGGER_SUPPORT
83  Debug* debug = isolate()->debug();
84  // First check if any break points are active if not just return the
85  // original constant pool.
86  if (!debug->has_break_points()) return *result;
87 
88  // At least one break point is active perform additional test to ensure that
89  // break point locations are updated correctly.
91  if (debug->IsDebugBreak(
92  Assembler::target_address_at(target, raw_constant_pool()))) {
93  // If the call site is a call to debug break then we want to return the
94  // constant pool for the original code instead of the breakpointed code.
95  return GetOriginalCode()->constant_pool();
96  }
97 #endif
98  return *result;
99  }
100 }
101 
102 
103 ConstantPoolArray* IC::raw_constant_pool() const {
104  if (FLAG_enable_ool_constant_pool) {
105  return *raw_constant_pool_;
106  } else {
107  return NULL;
108  }
109 }
110 
111 
113  ConstantPoolArray* constant_pool) {
114  // Get the target address of the IC.
115  Address target = Assembler::target_address_at(address, constant_pool);
116  // Convert target address to the code object. Code::GetCodeFromTargetAddress
117  // is safe for use during GC where the map might be marked.
118  Code* result = Code::GetCodeFromTargetAddress(target);
119  ASSERT(result->is_inline_cache_stub());
120  return result;
121 }
122 
123 
125  Code* target,
126  ConstantPoolArray* constant_pool) {
127  ASSERT(target->is_inline_cache_stub() || target->is_compare_ic_stub());
128  Heap* heap = target->GetHeap();
129  Code* old_target = GetTargetAtAddress(address, constant_pool);
130 #ifdef DEBUG
131  // STORE_IC and KEYED_STORE_IC use Code::extra_ic_state() to mark
132  // ICs as strict mode. The strict-ness of the IC must be preserved.
133  if (old_target->kind() == Code::STORE_IC ||
134  old_target->kind() == Code::KEYED_STORE_IC) {
137  }
138 #endif
140  address, constant_pool, target->instruction_start());
141  if (heap->gc_state() == Heap::MARK_COMPACT) {
142  heap->mark_compact_collector()->RecordCodeTargetPatch(address, target);
143  } else {
144  heap->incremental_marking()->RecordCodeTargetPatch(address, target);
145  }
146  PostPatching(address, target, old_target);
147 }
148 
149 
151  if (object->IsJSObject()) return OWN_MAP;
152 
153  // If the object is a value, we use the prototype map for the cache.
154  ASSERT(object->IsString() || object->IsSymbol() ||
155  object->IsNumber() || object->IsBoolean());
156  return PROTOTYPE_MAP;
157 }
158 
159 
161  Object* object,
162  InlineCacheHolderFlag holder) {
163  if (object->IsSmi()) holder = PROTOTYPE_MAP;
164  Object* map_owner = holder == OWN_MAP
165  ? object : object->GetPrototype(isolate);
166  return HeapObject::cast(map_owner);
167 }
168 
169 
171  if (type->Is(HeapType::Boolean()) ||
172  type->Is(HeapType::Number()) ||
173  type->Is(HeapType::String()) ||
174  type->Is(HeapType::Symbol())) {
175  return PROTOTYPE_MAP;
176  }
177  return OWN_MAP;
178 }
179 
180 
182  HeapType* type,
183  Isolate* isolate) {
184  if (flag == PROTOTYPE_MAP) {
185  Context* context = isolate->context()->native_context();
186  JSFunction* constructor;
187  if (type->Is(HeapType::Boolean())) {
188  constructor = context->boolean_function();
189  } else if (type->Is(HeapType::Number())) {
190  constructor = context->number_function();
191  } else if (type->Is(HeapType::String())) {
192  constructor = context->string_function();
193  } else {
194  ASSERT(type->Is(HeapType::Symbol()));
195  constructor = context->symbol_function();
196  }
197  return handle(JSObject::cast(constructor->instance_prototype())->map());
198  }
199  return TypeToMap(type, isolate);
200 }
201 
202 
203 } } // namespace v8::internal
204 
205 #endif // V8_IC_INL_H_
byte * Address
Definition: globals.h:186
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
Definition: flags.cc:269
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf map
Definition: flags.cc:350
static HeapObject * GetCodeCacheHolder(Isolate *isolate, Object *object, InlineCacheHolderFlag holder)
Definition: ic-inl.h:160
static HeapObject * cast(Object *obj)
static Address target_address_at(Address pc, ConstantPoolArray *constant_pool)
Address address() const
Definition: ic-inl.h:41
#define ASSERT(condition)
Definition: checks.h:329
Isolate * isolate() const
Definition: ic.h:157
kInstanceClassNameOffset flag
Definition: objects-inl.h:5115
static void PostPatching(Address address, Code *target, Code *old_target)
Definition: ic.cc:398
Address pc() const
Definition: ic.h:156
Context * native_context()
Definition: contexts.cc:67
byte * instruction_start()
Definition: objects-inl.h:5857
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static Code * GetCodeFromTargetAddress(Address address)
Definition: objects-inl.h:4662
bool is_inline_cache_stub()
Definition: objects-inl.h:4568
Definition: v8.h:123
static void SetTargetAtAddress(Address address, Code *target, ConstantPoolArray *constant_pool)
Definition: ic-inl.h:124
static Code * GetTargetAtAddress(Address address, ConstantPoolArray *constant_pool)
Definition: ic-inl.h:112
static StrictMode GetStrictMode(ExtraICState state)
Definition: ic.h:485
Context * context()
Definition: isolate.h:557
bool Is(TypeImpl *that)
Definition: types.h:246
bool is_compare_ic_stub()
Definition: objects.h:5307
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:103
static InlineCacheHolderFlag GetCodeCacheForObject(Object *object)
Definition: ic-inl.h:150
static Address target_address_from_return_address(Address pc)
IN DWORD64 OUT PDWORD64 OUT PIMAGEHLP_SYMBOL64 Symbol
static void set_target_address_at(Address pc, ConstantPoolArray *constant_pool, Address target)
Handle< Code > target() const
Definition: ic.h:153
ExtraICState extra_ic_state()
Definition: objects-inl.h:4320
static JSObject * cast(Object *obj)
static InlineCacheHolderFlag GetCodeCacheFlag(HeapType *type)
Definition: ic-inl.h:170
static Handle< Map > TypeToMap(HeapType *type, Isolate *isolate)
Definition: ic.cc:683