OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ExternalReference ref = ExternalReference( | 470 ExternalReference ref = ExternalReference( |
471 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); | 471 IC_Utility(IC::kLoadPropertyWithInterceptorForLoad)); |
472 __ TailCallExternalReference(ref, 5, 1); | 472 __ TailCallExternalReference(ref, 5, 1); |
473 } | 473 } |
474 | 474 |
475 private: | 475 private: |
476 Register name_; | 476 Register name_; |
477 }; | 477 }; |
478 | 478 |
479 | 479 |
480 // Holds information about possible function call optimizations. | |
481 class CallOptimization BASE_EMBEDDED { | |
482 public: | |
483 explicit CallOptimization(LookupResult* lookup) { | |
484 if (!lookup->IsProperty() || !lookup->IsCacheable() || | |
485 lookup->type() != CONSTANT_FUNCTION) { | |
486 Initialize(NULL); | |
487 } else { | |
488 // We only optimize constant function calls. | |
489 Initialize(lookup->GetConstantFunction()); | |
490 } | |
491 } | |
492 | |
493 explicit CallOptimization(JSFunction* function) { | |
494 Initialize(function); | |
495 } | |
496 | |
497 bool is_constant_call() const { | |
498 return constant_function_ != NULL; | |
499 } | |
500 | |
501 JSFunction* constant_function() const { | |
502 ASSERT(constant_function_ != NULL); | |
503 return constant_function_; | |
504 } | |
505 | |
506 bool is_simple_api_call() const { | |
507 return is_simple_api_call_; | |
508 } | |
509 | |
510 FunctionTemplateInfo* expected_receiver_type() const { | |
511 ASSERT(is_simple_api_call_); | |
512 return expected_receiver_type_; | |
513 } | |
514 | |
515 CallHandlerInfo* api_call_info() const { | |
516 ASSERT(is_simple_api_call_); | |
517 return api_call_info_; | |
518 } | |
519 | |
520 // Returns the depth of the object having the expected type in the | |
521 // prototype chain between the two arguments. | |
522 int GetPrototypeDepthOfExpectedType(JSObject* object, | |
523 JSObject* holder) const { | |
524 ASSERT(is_simple_api_call_); | |
525 if (expected_receiver_type_ == NULL) return 0; | |
526 int depth = 0; | |
527 while (object != holder) { | |
528 if (object->IsInstanceOf(expected_receiver_type_)) return depth; | |
529 object = JSObject::cast(object->GetPrototype()); | |
530 ++depth; | |
531 } | |
532 if (holder->IsInstanceOf(expected_receiver_type_)) return depth; | |
533 return kInvalidProtoDepth; | |
534 } | |
535 | |
536 private: | |
537 void Initialize(JSFunction* function) { | |
538 constant_function_ = NULL; | |
539 is_simple_api_call_ = false; | |
540 expected_receiver_type_ = NULL; | |
541 api_call_info_ = NULL; | |
542 | |
543 if (function == NULL || !function->is_compiled()) return; | |
544 | |
545 constant_function_ = function; | |
546 AnalyzePossibleApiFunction(function); | |
547 } | |
548 | |
549 // Determines whether the given function can be called using the | |
550 // fast api call builtin. | |
551 void AnalyzePossibleApiFunction(JSFunction* function) { | |
552 SharedFunctionInfo* sfi = function->shared(); | |
553 if (!sfi->IsApiFunction()) return; | |
554 FunctionTemplateInfo* info = sfi->get_api_func_data(); | |
555 | |
556 // Require a C++ callback. | |
557 if (info->call_code()->IsUndefined()) return; | |
558 api_call_info_ = CallHandlerInfo::cast(info->call_code()); | |
559 | |
560 // Accept signatures that either have no restrictions at all or | |
561 // only have restrictions on the receiver. | |
562 if (!info->signature()->IsUndefined()) { | |
563 SignatureInfo* signature = SignatureInfo::cast(info->signature()); | |
564 if (!signature->args()->IsUndefined()) return; | |
565 if (!signature->receiver()->IsUndefined()) { | |
566 expected_receiver_type_ = | |
567 FunctionTemplateInfo::cast(signature->receiver()); | |
568 } | |
569 } | |
570 | |
571 is_simple_api_call_ = true; | |
572 } | |
573 | |
574 JSFunction* constant_function_; | |
575 bool is_simple_api_call_; | |
576 FunctionTemplateInfo* expected_receiver_type_; | |
577 CallHandlerInfo* api_call_info_; | |
578 }; | |
579 | |
580 | |
581 // Reserves space for the extra arguments to FastHandleApiCall in the | 480 // Reserves space for the extra arguments to FastHandleApiCall in the |
582 // caller's frame. | 481 // caller's frame. |
583 // | 482 // |
584 // These arguments are set by CheckPrototypes and GenerateFastApiCall. | 483 // These arguments are set by CheckPrototypes and GenerateFastApiCall. |
585 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { | 484 static void ReserveSpaceForFastApiCall(MacroAssembler* masm, Register scratch) { |
586 // ----------- S t a t e ------------- | 485 // ----------- S t a t e ------------- |
587 // -- esp[0] : return address | 486 // -- esp[0] : return address |
588 // -- esp[4] : last argument in the internal frame of the caller | 487 // -- esp[4] : last argument in the internal frame of the caller |
589 // ----------------------------------- | 488 // ----------------------------------- |
590 __ pop(scratch); | 489 __ pop(scratch); |
(...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2481 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); | 2380 __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
2482 | 2381 |
2483 // Return the generated code. | 2382 // Return the generated code. |
2484 return GetCode(); | 2383 return GetCode(); |
2485 } | 2384 } |
2486 | 2385 |
2487 | 2386 |
2488 #undef __ | 2387 #undef __ |
2489 | 2388 |
2490 } } // namespace v8::internal | 2389 } } // namespace v8::internal |
OLD | NEW |