| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3083 Register result = ToRegister(instr->result()); | 3083 Register result = ToRegister(instr->result()); |
| 3084 if (access.IsInobject()) { | 3084 if (access.IsInobject()) { |
| 3085 __ mov(result, FieldOperand(object, offset)); | 3085 __ mov(result, FieldOperand(object, offset)); |
| 3086 } else { | 3086 } else { |
| 3087 __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); | 3087 __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); |
| 3088 __ mov(result, FieldOperand(result, offset)); | 3088 __ mov(result, FieldOperand(result, offset)); |
| 3089 } | 3089 } |
| 3090 } | 3090 } |
| 3091 | 3091 |
| 3092 | 3092 |
| 3093 void LCodeGen::EmitLoadFieldOrConstant(Register result, | |
| 3094 Register object, | |
| 3095 Handle<Map> type, | |
| 3096 Handle<String> name, | |
| 3097 LEnvironment* env) { | |
| 3098 LookupResult lookup(isolate()); | |
| 3099 type->LookupDescriptor(NULL, *name, &lookup); | |
| 3100 ASSERT(lookup.IsFound() || lookup.IsCacheable()); | |
| 3101 if (lookup.IsField()) { | |
| 3102 int index = lookup.GetLocalFieldIndexFromMap(*type); | |
| 3103 int offset = index * kPointerSize; | |
| 3104 if (index < 0) { | |
| 3105 // Negative property indices are in-object properties, indexed | |
| 3106 // from the end of the fixed part of the object. | |
| 3107 __ mov(result, FieldOperand(object, offset + type->instance_size())); | |
| 3108 } else { | |
| 3109 // Non-negative property indices are in the properties array. | |
| 3110 __ mov(result, FieldOperand(object, JSObject::kPropertiesOffset)); | |
| 3111 __ mov(result, FieldOperand(result, offset + FixedArray::kHeaderSize)); | |
| 3112 } | |
| 3113 } else if (lookup.IsConstant()) { | |
| 3114 Handle<Object> constant(lookup.GetConstantFromMap(*type), isolate()); | |
| 3115 __ LoadObject(result, constant); | |
| 3116 } else { | |
| 3117 // Negative lookup. | |
| 3118 // Check prototypes. | |
| 3119 Handle<HeapObject> current(HeapObject::cast((*type)->prototype())); | |
| 3120 Heap* heap = type->GetHeap(); | |
| 3121 while (*current != heap->null_value()) { | |
| 3122 __ LoadHeapObject(result, current); | |
| 3123 __ cmp(FieldOperand(result, HeapObject::kMapOffset), | |
| 3124 Handle<Map>(current->map())); | |
| 3125 DeoptimizeIf(not_equal, env); | |
| 3126 current = | |
| 3127 Handle<HeapObject>(HeapObject::cast(current->map()->prototype())); | |
| 3128 } | |
| 3129 __ mov(result, factory()->undefined_value()); | |
| 3130 } | |
| 3131 } | |
| 3132 | |
| 3133 | |
| 3134 void LCodeGen::EmitPushTaggedOperand(LOperand* operand) { | 3093 void LCodeGen::EmitPushTaggedOperand(LOperand* operand) { |
| 3135 ASSERT(!operand->IsDoubleRegister()); | 3094 ASSERT(!operand->IsDoubleRegister()); |
| 3136 if (operand->IsConstantOperand()) { | 3095 if (operand->IsConstantOperand()) { |
| 3137 Handle<Object> object = ToHandle(LConstantOperand::cast(operand)); | 3096 Handle<Object> object = ToHandle(LConstantOperand::cast(operand)); |
| 3138 AllowDeferredHandleDereference smi_check; | 3097 AllowDeferredHandleDereference smi_check; |
| 3139 if (object->IsSmi()) { | 3098 if (object->IsSmi()) { |
| 3140 __ Push(Handle<Smi>::cast(object)); | 3099 __ Push(Handle<Smi>::cast(object)); |
| 3141 } else { | 3100 } else { |
| 3142 __ PushHeapObject(Handle<HeapObject>::cast(object)); | 3101 __ PushHeapObject(Handle<HeapObject>::cast(object)); |
| 3143 } | 3102 } |
| 3144 } else if (operand->IsRegister()) { | 3103 } else if (operand->IsRegister()) { |
| 3145 __ push(ToRegister(operand)); | 3104 __ push(ToRegister(operand)); |
| 3146 } else { | 3105 } else { |
| 3147 __ push(ToOperand(operand)); | 3106 __ push(ToOperand(operand)); |
| 3148 } | 3107 } |
| 3149 } | 3108 } |
| 3150 | 3109 |
| 3151 | 3110 |
| 3152 // Check for cases where EmitLoadFieldOrConstantFunction needs to walk the | |
| 3153 // prototype chain, which causes unbounded code generation. | |
| 3154 static bool CompactEmit(SmallMapList* list, | |
| 3155 Handle<String> name, | |
| 3156 int i, | |
| 3157 Isolate* isolate) { | |
| 3158 Handle<Map> map = list->at(i); | |
| 3159 LookupResult lookup(isolate); | |
| 3160 map->LookupDescriptor(NULL, *name, &lookup); | |
| 3161 return lookup.IsField() || lookup.IsConstant(); | |
| 3162 } | |
| 3163 | |
| 3164 | |
| 3165 void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { | |
| 3166 Register object = ToRegister(instr->object()); | |
| 3167 Register result = ToRegister(instr->result()); | |
| 3168 | |
| 3169 int map_count = instr->hydrogen()->types()->length(); | |
| 3170 bool need_generic = instr->hydrogen()->need_generic(); | |
| 3171 | |
| 3172 if (map_count == 0 && !need_generic) { | |
| 3173 DeoptimizeIf(no_condition, instr->environment()); | |
| 3174 return; | |
| 3175 } | |
| 3176 Handle<String> name = instr->hydrogen()->name(); | |
| 3177 Label done; | |
| 3178 bool all_are_compact = true; | |
| 3179 for (int i = 0; i < map_count; ++i) { | |
| 3180 if (!CompactEmit(instr->hydrogen()->types(), name, i, isolate())) { | |
| 3181 all_are_compact = false; | |
| 3182 break; | |
| 3183 } | |
| 3184 } | |
| 3185 for (int i = 0; i < map_count; ++i) { | |
| 3186 bool last = (i == map_count - 1); | |
| 3187 Handle<Map> map = instr->hydrogen()->types()->at(i); | |
| 3188 Label check_passed; | |
| 3189 __ CompareMap(object, map, &check_passed); | |
| 3190 if (last && !need_generic) { | |
| 3191 DeoptimizeIf(not_equal, instr->environment()); | |
| 3192 __ bind(&check_passed); | |
| 3193 EmitLoadFieldOrConstant(result, object, map, name, instr->environment()); | |
| 3194 } else { | |
| 3195 Label next; | |
| 3196 bool compact = all_are_compact ? true : | |
| 3197 CompactEmit(instr->hydrogen()->types(), name, i, isolate()); | |
| 3198 __ j(not_equal, &next, compact ? Label::kNear : Label::kFar); | |
| 3199 __ bind(&check_passed); | |
| 3200 EmitLoadFieldOrConstant(result, object, map, name, instr->environment()); | |
| 3201 __ jmp(&done, all_are_compact ? Label::kNear : Label::kFar); | |
| 3202 __ bind(&next); | |
| 3203 } | |
| 3204 } | |
| 3205 if (need_generic) { | |
| 3206 __ mov(ecx, name); | |
| 3207 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | |
| 3208 CallCode(ic, RelocInfo::CODE_TARGET, instr); | |
| 3209 } | |
| 3210 __ bind(&done); | |
| 3211 } | |
| 3212 | |
| 3213 | |
| 3214 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { | 3111 void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 3215 ASSERT(ToRegister(instr->context()).is(esi)); | 3112 ASSERT(ToRegister(instr->context()).is(esi)); |
| 3216 ASSERT(ToRegister(instr->object()).is(edx)); | 3113 ASSERT(ToRegister(instr->object()).is(edx)); |
| 3217 ASSERT(ToRegister(instr->result()).is(eax)); | 3114 ASSERT(ToRegister(instr->result()).is(eax)); |
| 3218 | 3115 |
| 3219 __ mov(ecx, instr->name()); | 3116 __ mov(ecx, instr->name()); |
| 3220 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 3117 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
| 3221 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 3118 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3222 } | 3119 } |
| 3223 | 3120 |
| (...skipping 3308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6532 FixedArray::kHeaderSize - kPointerSize)); | 6429 FixedArray::kHeaderSize - kPointerSize)); |
| 6533 __ bind(&done); | 6430 __ bind(&done); |
| 6534 } | 6431 } |
| 6535 | 6432 |
| 6536 | 6433 |
| 6537 #undef __ | 6434 #undef __ |
| 6538 | 6435 |
| 6539 } } // namespace v8::internal | 6436 } } // namespace v8::internal |
| 6540 | 6437 |
| 6541 #endif // V8_TARGET_ARCH_IA32 | 6438 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |