| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_IC_INL_H_ | 5 #ifndef V8_IC_INL_H_ |
| 6 #define V8_IC_INL_H_ | 6 #define V8_IC_INL_H_ |
| 7 | 7 |
| 8 #include "src/ic.h" | 8 #include "src/ic.h" |
| 9 | 9 |
| 10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 address, constant_pool, target->instruction_start()); | 112 address, constant_pool, target->instruction_start()); |
| 113 if (heap->gc_state() == Heap::MARK_COMPACT) { | 113 if (heap->gc_state() == Heap::MARK_COMPACT) { |
| 114 heap->mark_compact_collector()->RecordCodeTargetPatch(address, target); | 114 heap->mark_compact_collector()->RecordCodeTargetPatch(address, target); |
| 115 } else { | 115 } else { |
| 116 heap->incremental_marking()->RecordCodeTargetPatch(address, target); | 116 heap->incremental_marking()->RecordCodeTargetPatch(address, target); |
| 117 } | 117 } |
| 118 PostPatching(address, target, old_target); | 118 PostPatching(address, target, old_target); |
| 119 } | 119 } |
| 120 | 120 |
| 121 | 121 |
| 122 InlineCacheHolderFlag IC::GetCodeCacheForObject(Object* object) { | 122 template <class TypeClass> |
| 123 if (object->IsJSObject()) return OWN_MAP; | 123 JSFunction* IC::GetBuiltinConstructor(TypeClass* type, |
| 124 | 124 Context* native_context) { |
| 125 // If the object is a value, we use the prototype map for the cache. | 125 if (type->Is(TypeClass::Boolean())) { |
| 126 ASSERT(object->IsString() || object->IsSymbol() || | 126 return native_context->boolean_function(); |
| 127 object->IsNumber() || object->IsBoolean()); | 127 } else if (type->Is(TypeClass::Number())) { |
| 128 return PROTOTYPE_MAP; | 128 return native_context->number_function(); |
| 129 } else if (type->Is(TypeClass::String())) { |
| 130 return native_context->string_function(); |
| 131 } else if (type->Is(TypeClass::Symbol())) { |
| 132 return native_context->symbol_function(); |
| 133 } else { |
| 134 return NULL; |
| 135 } |
| 129 } | 136 } |
| 130 | 137 |
| 131 | 138 |
| 132 HeapObject* IC::GetCodeCacheHolder(Isolate* isolate, | 139 Handle<Map> IC::GetHandlerCacheHolder(HeapType* type, bool receiver_is_holder, |
| 133 Object* object, | 140 Isolate* isolate, CacheHolderFlag* flag) { |
| 134 InlineCacheHolderFlag holder) { | 141 Handle<Map> receiver_map = TypeToMap(type, isolate); |
| 135 if (object->IsSmi()) holder = PROTOTYPE_MAP; | 142 if (receiver_is_holder) { |
| 136 PrototypeIterator iter(isolate, object, | 143 *flag = kCacheOnReceiver; |
| 137 holder == OWN_MAP | 144 return receiver_map; |
| 138 ? PrototypeIterator::START_AT_RECEIVER | 145 } |
| 139 : PrototypeIterator::START_AT_PROTOTYPE); | 146 Context* native_context = *isolate->native_context(); |
| 140 return HeapObject::cast(iter.GetCurrent()); | 147 JSFunction* builtin_ctor = GetBuiltinConstructor(type, native_context); |
| 148 if (builtin_ctor != NULL) { |
| 149 *flag = kCacheOnPrototypeReceiverIsPrimitive; |
| 150 return handle(HeapObject::cast(builtin_ctor->instance_prototype())->map()); |
| 151 } |
| 152 *flag = receiver_map->is_dictionary_map() |
| 153 ? kCacheOnPrototypeReceiverIsDictionary |
| 154 : kCacheOnPrototype; |
| 155 // Callers must ensure that the prototype is non-null. |
| 156 return handle(JSObject::cast(receiver_map->prototype())->map()); |
| 141 } | 157 } |
| 142 | 158 |
| 143 | 159 |
| 144 InlineCacheHolderFlag IC::GetCodeCacheFlag(HeapType* type) { | 160 Handle<Map> IC::GetICCacheHolder(HeapType* type, Isolate* isolate, |
| 145 if (type->Is(HeapType::Boolean()) || | 161 CacheHolderFlag* flag) { |
| 146 type->Is(HeapType::Number()) || | 162 Context* native_context = *isolate->native_context(); |
| 147 type->Is(HeapType::String()) || | 163 JSFunction* builtin_ctor = GetBuiltinConstructor(type, native_context); |
| 148 type->Is(HeapType::Symbol())) { | 164 if (builtin_ctor != NULL) { |
| 149 return PROTOTYPE_MAP; | 165 *flag = kCacheOnPrototype; |
| 166 return handle(builtin_ctor->initial_map()); |
| 150 } | 167 } |
| 151 return OWN_MAP; | 168 *flag = kCacheOnReceiver; |
| 152 } | |
| 153 | |
| 154 | |
| 155 Handle<Map> IC::GetCodeCacheHolder(InlineCacheHolderFlag flag, | |
| 156 HeapType* type, | |
| 157 Isolate* isolate) { | |
| 158 if (flag == PROTOTYPE_MAP) { | |
| 159 Context* context = *isolate->native_context(); | |
| 160 JSFunction* constructor; | |
| 161 if (type->Is(HeapType::Boolean())) { | |
| 162 constructor = context->boolean_function(); | |
| 163 } else if (type->Is(HeapType::Number())) { | |
| 164 constructor = context->number_function(); | |
| 165 } else if (type->Is(HeapType::String())) { | |
| 166 constructor = context->string_function(); | |
| 167 } else { | |
| 168 ASSERT(type->Is(HeapType::Symbol())); | |
| 169 constructor = context->symbol_function(); | |
| 170 } | |
| 171 return handle(JSObject::cast(constructor->instance_prototype())->map()); | |
| 172 } | |
| 173 return TypeToMap(type, isolate); | 169 return TypeToMap(type, isolate); |
| 174 } | 170 } |
| 175 | 171 |
| 176 | |
| 177 } } // namespace v8::internal | 172 } } // namespace v8::internal |
| 178 | 173 |
| 179 #endif // V8_IC_INL_H_ | 174 #endif // V8_IC_INL_H_ |
| OLD | NEW |