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 2297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 } else { | 2308 } else { |
2309 __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 2309 __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
2310 __ lw(result, FieldMemOperand(result, instr->hydrogen()->offset())); | 2310 __ lw(result, FieldMemOperand(result, instr->hydrogen()->offset())); |
2311 } | 2311 } |
2312 } | 2312 } |
2313 | 2313 |
2314 | 2314 |
2315 void LCodeGen::EmitLoadFieldOrConstantFunction(Register result, | 2315 void LCodeGen::EmitLoadFieldOrConstantFunction(Register result, |
2316 Register object, | 2316 Register object, |
2317 Handle<Map> type, | 2317 Handle<Map> type, |
2318 Handle<String> name) { | 2318 Handle<String> name, |
| 2319 LEnvironment* env) { |
2319 LookupResult lookup(isolate()); | 2320 LookupResult lookup(isolate()); |
2320 type->LookupInDescriptors(NULL, *name, &lookup); | 2321 type->LookupInDescriptors(NULL, *name, &lookup); |
2321 ASSERT(lookup.IsFound() && | 2322 ASSERT(lookup.IsFound() || lookup.IsCacheable()); |
2322 (lookup.type() == FIELD || lookup.type() == CONSTANT_FUNCTION)); | 2323 if (lookup.IsFound() && lookup.type() == FIELD) { |
2323 if (lookup.type() == FIELD) { | |
2324 int index = lookup.GetLocalFieldIndexFromMap(*type); | 2324 int index = lookup.GetLocalFieldIndexFromMap(*type); |
2325 int offset = index * kPointerSize; | 2325 int offset = index * kPointerSize; |
2326 if (index < 0) { | 2326 if (index < 0) { |
2327 // Negative property indices are in-object properties, indexed | 2327 // Negative property indices are in-object properties, indexed |
2328 // from the end of the fixed part of the object. | 2328 // from the end of the fixed part of the object. |
2329 __ lw(result, FieldMemOperand(object, offset + type->instance_size())); | 2329 __ lw(result, FieldMemOperand(object, offset + type->instance_size())); |
2330 } else { | 2330 } else { |
2331 // Non-negative property indices are in the properties array. | 2331 // Non-negative property indices are in the properties array. |
2332 __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); | 2332 __ lw(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
2333 __ lw(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize)); | 2333 __ lw(result, FieldMemOperand(result, offset + FixedArray::kHeaderSize)); |
2334 } | 2334 } |
2335 } else { | 2335 } else if (lookup.IsFound() && lookup.type() == CONSTANT_FUNCTION) { |
2336 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type)); | 2336 Handle<JSFunction> function(lookup.GetConstantFunctionFromMap(*type)); |
2337 __ LoadHeapObject(result, function); | 2337 __ LoadHeapObject(result, function); |
| 2338 } else { |
| 2339 // Negative lookup. |
| 2340 // Check prototypes. |
| 2341 HeapObject* current = HeapObject::cast((*type)->prototype()); |
| 2342 Heap* heap = type->GetHeap(); |
| 2343 while (current != heap->null_value()) { |
| 2344 Handle<HeapObject> link(current); |
| 2345 __ LoadHeapObject(result, link); |
| 2346 __ lw(result, FieldMemOperand(result, HeapObject::kMapOffset)); |
| 2347 DeoptimizeIf(ne, env, |
| 2348 result, Operand(Handle<Map>(JSObject::cast(current)->map()))); |
| 2349 current = HeapObject::cast(current->map()->prototype()); |
| 2350 } |
| 2351 __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
2338 } | 2352 } |
2339 } | 2353 } |
2340 | 2354 |
2341 | 2355 |
2342 void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { | 2356 void LCodeGen::DoLoadNamedFieldPolymorphic(LLoadNamedFieldPolymorphic* instr) { |
2343 Register object = ToRegister(instr->object()); | 2357 Register object = ToRegister(instr->object()); |
2344 Register result = ToRegister(instr->result()); | 2358 Register result = ToRegister(instr->result()); |
2345 Register scratch = scratch0(); | 2359 Register object_map = scratch0(); |
2346 | 2360 |
2347 int map_count = instr->hydrogen()->types()->length(); | 2361 int map_count = instr->hydrogen()->types()->length(); |
2348 bool need_generic = instr->hydrogen()->need_generic(); | 2362 bool need_generic = instr->hydrogen()->need_generic(); |
2349 | 2363 |
2350 if (map_count == 0 && !need_generic) { | 2364 if (map_count == 0 && !need_generic) { |
2351 DeoptimizeIf(al, instr->environment()); | 2365 DeoptimizeIf(al, instr->environment()); |
2352 return; | 2366 return; |
2353 } | 2367 } |
2354 Handle<String> name = instr->hydrogen()->name(); | 2368 Handle<String> name = instr->hydrogen()->name(); |
2355 Label done; | 2369 Label done; |
2356 __ lw(scratch, FieldMemOperand(object, HeapObject::kMapOffset)); | 2370 __ lw(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
2357 for (int i = 0; i < map_count; ++i) { | 2371 for (int i = 0; i < map_count; ++i) { |
2358 bool last = (i == map_count - 1); | 2372 bool last = (i == map_count - 1); |
2359 Handle<Map> map = instr->hydrogen()->types()->at(i); | 2373 Handle<Map> map = instr->hydrogen()->types()->at(i); |
| 2374 Label check_passed; |
| 2375 __ CompareMapAndBranch( |
| 2376 object_map, map, &check_passed, |
| 2377 eq, &check_passed, ALLOW_ELEMENT_TRANSITION_MAPS); |
2360 if (last && !need_generic) { | 2378 if (last && !need_generic) { |
2361 DeoptimizeIf(ne, instr->environment(), scratch, Operand(map)); | 2379 DeoptimizeIf(al, instr->environment()); |
2362 EmitLoadFieldOrConstantFunction(result, object, map, name); | 2380 __ bind(&check_passed); |
| 2381 EmitLoadFieldOrConstantFunction( |
| 2382 result, object, map, name, instr->environment()); |
2363 } else { | 2383 } else { |
2364 Label next; | 2384 Label next; |
2365 __ Branch(&next, ne, scratch, Operand(map)); | 2385 __ Branch(&next); |
2366 EmitLoadFieldOrConstantFunction(result, object, map, name); | 2386 __ bind(&check_passed); |
| 2387 EmitLoadFieldOrConstantFunction( |
| 2388 result, object, map, name, instr->environment()); |
2367 __ Branch(&done); | 2389 __ Branch(&done); |
2368 __ bind(&next); | 2390 __ bind(&next); |
2369 } | 2391 } |
2370 } | 2392 } |
2371 if (need_generic) { | 2393 if (need_generic) { |
2372 __ li(a2, Operand(name)); | 2394 __ li(a2, Operand(name)); |
2373 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 2395 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
2374 CallCode(ic, RelocInfo::CODE_TARGET, instr); | 2396 CallCode(ic, RelocInfo::CODE_TARGET, instr); |
2375 } | 2397 } |
2376 __ bind(&done); | 2398 __ bind(&done); |
(...skipping 2799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5176 __ Subu(scratch, result, scratch); | 5198 __ Subu(scratch, result, scratch); |
5177 __ lw(result, FieldMemOperand(scratch, | 5199 __ lw(result, FieldMemOperand(scratch, |
5178 FixedArray::kHeaderSize - kPointerSize)); | 5200 FixedArray::kHeaderSize - kPointerSize)); |
5179 __ bind(&done); | 5201 __ bind(&done); |
5180 } | 5202 } |
5181 | 5203 |
5182 | 5204 |
5183 #undef __ | 5205 #undef __ |
5184 | 5206 |
5185 } } // namespace v8::internal | 5207 } } // namespace v8::internal |
OLD | NEW |