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/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 3172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3183 } | 3183 } |
3184 | 3184 |
3185 | 3185 |
3186 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { | 3186 void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
3187 ZoneList<Expression*>* args = expr->arguments(); | 3187 ZoneList<Expression*>* args = expr->arguments(); |
3188 DCHECK(args->length() == 1); | 3188 DCHECK(args->length() == 1); |
3189 Label done, null, function, non_function_constructor; | 3189 Label done, null, function, non_function_constructor; |
3190 | 3190 |
3191 VisitForAccumulatorValue(args->at(0)); | 3191 VisitForAccumulatorValue(args->at(0)); |
3192 | 3192 |
3193 // If the object is a smi, we return null. | 3193 // If the object is not a JSReceiver, we return null. |
3194 __ JumpIfSmi(rax, &null); | 3194 __ JumpIfSmi(rax, &null, Label::kNear); |
| 3195 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
| 3196 __ CmpObjectType(rax, FIRST_JS_RECEIVER_TYPE, rax); |
| 3197 __ j(below, &null, Label::kNear); |
3195 | 3198 |
3196 // Check that the object is a JS object but take special care of JS | 3199 // Return 'Function' for JSFunction objects. |
3197 // functions to make sure they have 'Function' as their class. | 3200 __ CmpInstanceType(rax, JS_FUNCTION_TYPE); |
3198 // Assume that there are only two callable types, and one of them is at | 3201 __ j(equal, &function, Label::kNear); |
3199 // either end of the type range for JS object types. Saves extra comparisons. | |
3200 STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); | |
3201 __ CmpObjectType(rax, FIRST_JS_RECEIVER_TYPE, rax); | |
3202 // Map is now in rax. | |
3203 __ j(below, &null); | |
3204 | |
3205 __ CmpInstanceType(rax, LAST_JS_RECEIVER_TYPE); | |
3206 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == | |
3207 LAST_JS_RECEIVER_TYPE - 1); | |
3208 __ j(equal, &function); | |
3209 // Assume that there is no larger type. | |
3210 STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); | |
3211 | 3202 |
3212 // Check if the constructor in the map is a JS function. | 3203 // Check if the constructor in the map is a JS function. |
3213 __ GetMapConstructor(rax, rax, rbx); | 3204 __ GetMapConstructor(rax, rax, rbx); |
3214 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE); | 3205 __ CmpInstanceType(rbx, JS_FUNCTION_TYPE); |
3215 __ j(not_equal, &non_function_constructor); | 3206 __ j(not_equal, &non_function_constructor, Label::kNear); |
3216 | 3207 |
3217 // rax now contains the constructor function. Grab the | 3208 // rax now contains the constructor function. Grab the |
3218 // instance class name from there. | 3209 // instance class name from there. |
3219 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); | 3210 __ movp(rax, FieldOperand(rax, JSFunction::kSharedFunctionInfoOffset)); |
3220 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); | 3211 __ movp(rax, FieldOperand(rax, SharedFunctionInfo::kInstanceClassNameOffset)); |
3221 __ jmp(&done); | 3212 __ jmp(&done, Label::kNear); |
3222 | |
3223 // Functions have class 'Function'. | |
3224 __ bind(&function); | |
3225 __ Move(rax, isolate()->factory()->Function_string()); | |
3226 __ jmp(&done); | |
3227 | |
3228 // Objects with a non-function constructor have class 'Object'. | |
3229 __ bind(&non_function_constructor); | |
3230 __ Move(rax, isolate()->factory()->Object_string()); | |
3231 __ jmp(&done); | |
3232 | 3213 |
3233 // Non-JS objects have class null. | 3214 // Non-JS objects have class null. |
3234 __ bind(&null); | 3215 __ bind(&null); |
3235 __ LoadRoot(rax, Heap::kNullValueRootIndex); | 3216 __ LoadRoot(rax, Heap::kNullValueRootIndex); |
| 3217 __ jmp(&done, Label::kNear); |
| 3218 |
| 3219 // Functions have class 'Function'. |
| 3220 __ bind(&function); |
| 3221 __ LoadRoot(rax, Heap::kFunction_stringRootIndex); |
| 3222 __ jmp(&done, Label::kNear); |
| 3223 |
| 3224 // Objects with a non-function constructor have class 'Object'. |
| 3225 __ bind(&non_function_constructor); |
| 3226 __ LoadRoot(rax, Heap::kObject_stringRootIndex); |
3236 | 3227 |
3237 // All done. | 3228 // All done. |
3238 __ bind(&done); | 3229 __ bind(&done); |
3239 | 3230 |
3240 context()->Plug(rax); | 3231 context()->Plug(rax); |
3241 } | 3232 } |
3242 | 3233 |
3243 | 3234 |
3244 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { | 3235 void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
3245 ZoneList<Expression*>* args = expr->arguments(); | 3236 ZoneList<Expression*>* args = expr->arguments(); |
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4781 Assembler::target_address_at(call_target_address, | 4772 Assembler::target_address_at(call_target_address, |
4782 unoptimized_code)); | 4773 unoptimized_code)); |
4783 return OSR_AFTER_STACK_CHECK; | 4774 return OSR_AFTER_STACK_CHECK; |
4784 } | 4775 } |
4785 | 4776 |
4786 | 4777 |
4787 } // namespace internal | 4778 } // namespace internal |
4788 } // namespace v8 | 4779 } // namespace v8 |
4789 | 4780 |
4790 #endif // V8_TARGET_ARCH_X64 | 4781 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |