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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 3545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3556 __ movp(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 3556 __ movp(rax, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
3557 | 3557 |
3558 __ bind(&exit); | 3558 __ bind(&exit); |
3559 __ AssertSmi(rax); | 3559 __ AssertSmi(rax); |
3560 context()->Plug(rax); | 3560 context()->Plug(rax); |
3561 } | 3561 } |
3562 | 3562 |
3563 | 3563 |
3564 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { | 3564 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
3565 ZoneList<Expression*>* args = expr->arguments(); | 3565 ZoneList<Expression*>* args = expr->arguments(); |
3566 DCHECK_EQ(1, args->length()); | 3566 DCHECK(args->length() == 1); |
3567 Label done, null, function, function_constructor; | 3567 Label done, null, function, non_function_constructor; |
3568 | 3568 |
3569 VisitForAccumulatorValue(args->at(0)); | 3569 VisitForAccumulatorValue(args->at(0)); |
3570 | 3570 |
3571 // If the object is a smi, we return null. | 3571 // If the object is a smi, we return null. |
3572 __ JumpIfSmi(rax, &null, Label::kNear); | 3572 __ JumpIfSmi(rax, &null); |
3573 | 3573 |
3574 // If the object is not a receiver, we return null. | 3574 // Check that the object is a JS object but take special care of JS |
3575 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); | 3575 // functions to make sure they have 'Function' as their class. |
3576 __ CmpObjectType(rax, FIRST_JS_RECEIVER_TYPE, rax); | 3576 // Assume that there are only two callable types, and one of them is at |
3577 __ j(below, &null, Label::kNear); | 3577 // either end of the type range for JS object types. Saves extra comparisons. |
| 3578 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 3579 __ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax); |
| 3580 // Map is now in rax. |
| 3581 __ j(below, &null); |
| 3582 STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3583 FIRST_SPEC_OBJECT_TYPE + 1); |
| 3584 __ j(equal, &function); |
3578 | 3585 |
3579 // According to ES5 section 15 Standard Built-in ECMAScript Objects, the | 3586 __ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE); |
3580 // [[Class]] of builtin objects is "Function" if a [[Call]] internal | 3587 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
3581 // method is present. | 3588 LAST_SPEC_OBJECT_TYPE - 1); |
3582 __ testb(FieldOperand(rax, Map::kBitFieldOffset), | 3589 __ j(equal, &function); |
3583 Immediate(1 << Map::kIsCallable)); | 3590 // Assume that there is no larger type. |
3584 __ j(not_zero, &function, Label::kNear); | 3591 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
3585 | 3592 |
3586 // Check if the constructor in the map is a JS function. | 3593 // Check if the constructor in the map is a JS function. |
3587 __ GetMapConstructor(rax, rax, rbx); | 3594 __ GetMapConstructor(rax, rax, rbx); |
3588 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE); | 3595 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE); |
3589 __ j(equal, &function_constructor, Label::kNear); | 3596 __ j(not_equal, &non_function_constructor); |
| 3597 |
| 3598 // rax now contains the constructor function. Grab the |
| 3599 // instance class name from there. |
| 3600 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); |
| 3601 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3602 __ jmp(&done); |
| 3603 |
| 3604 // Functions have class 'Function'. |
| 3605 __ bind(&function); |
| 3606 __ Move(rax, isolate()->factory()->Function_string()); |
| 3607 __ jmp(&done); |
3590 | 3608 |
3591 // Objects with a non-function constructor have class 'Object'. | 3609 // Objects with a non-function constructor have class 'Object'. |
3592 __ LoadRoot(rax, Heap::kObject_stringRootIndex); | 3610 __ bind(&non_function_constructor); |
3593 __ jmp(&done, Label::kNear); | 3611 __ Move(rax, isolate()->factory()->Object_string()); |
| 3612 __ jmp(&done); |
3594 | 3613 |
3595 // Non-JS objects have class null. | 3614 // Non-JS objects have class null. |
3596 __ bind(&null); | 3615 __ bind(&null); |
3597 __ LoadRoot(rax, Heap::kNullValueRootIndex); | 3616 __ LoadRoot(rax, Heap::kNullValueRootIndex); |
3598 __ jmp(&done, Label::kNear); | |
3599 | |
3600 // Functions have class 'Function'. | |
3601 __ bind(&function); | |
3602 __ LoadRoot(rax, Heap::kFunction_stringRootIndex); | |
3603 __ jmp(&done, Label::kNear); | |
3604 | |
3605 __ bind(&function_constructor); | |
3606 // rax now contains the constructor function. Grab the | |
3607 // instance class name from there. | |
3608 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); | |
3609 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); | |
3610 | 3617 |
3611 // All done. | 3618 // All done. |
3612 __ bind(&done); | 3619 __ bind(&done); |
3613 | 3620 |
3614 context()->Plug(rax); | 3621 context()->Plug(rax); |
3615 } | 3622 } |
3616 | 3623 |
3617 | 3624 |
3618 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { | 3625 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
3619 ZoneList<Expression*>* args = expr->arguments(); | 3626 ZoneList<Expression*>* args = expr->arguments(); |
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5235 Assembler::target_address_at(call_target_address, | 5242 Assembler::target_address_at(call_target_address, |
5236 unoptimized_code)); | 5243 unoptimized_code)); |
5237 return OSR_AFTER_STACK_CHECK; | 5244 return OSR_AFTER_STACK_CHECK; |
5238 } | 5245 } |
5239 | 5246 |
5240 | 5247 |
5241 } // namespace internal | 5248 } // namespace internal |
5242 } // namespace v8 | 5249 } // namespace v8 |
5243 | 5250 |
5244 #endif // V8_TARGET_ARCH_X64 | 5251 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |