Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Side by Side Diff: src/ia32/code-stubs-ia32.cc

Issue 8932004: Implement target cache for constructor calls. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Vyacheslav Egorov. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 4555 matching lines...) Expand 10 before | Expand all | Expand 10 after
4566 __ cmp(scratch, kSymbolTag | kStringTag); 4566 __ cmp(scratch, kSymbolTag | kStringTag);
4567 __ j(not_equal, label); 4567 __ j(not_equal, label);
4568 } 4568 }
4569 4569
4570 4570
4571 void StackCheckStub::Generate(MacroAssembler* masm) { 4571 void StackCheckStub::Generate(MacroAssembler* masm) {
4572 __ TailCallRuntime(Runtime::kStackGuard, 0, 1); 4572 __ TailCallRuntime(Runtime::kStackGuard, 0, 1);
4573 } 4573 }
4574 4574
4575 4575
4576 void CallFunctionStub::FinishCode(Handle<Code> code) { 4576 static void GenerateRecordCallTarget(MacroAssembler* masm) {
4577 code->set_has_function_cache(RecordCallTarget()); 4577 // Cache the called function in a global property cell. Cache states
4578 } 4578 // are uninitialized, monomorphic (indicated by a JSFunction), and
4579 // megamorphic.
4580 // ebx : cache cell for call target
4581 // edi : the function to call
4582 Isolate* isolate = masm->isolate();
4583 Label initialize, done;
4579 4584
4585 // Load the cache state into ecx.
4586 __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset));
4580 4587
4581 void CallFunctionStub::Clear(Heap* heap, Address address) { 4588 // A monomorphic cache hit or an already megamorphic state: invoke the
4582 ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte); 4589 // function without changing the state.
4583 // 1 ~ size of the test eax opcode. 4590 __ cmp(ecx, edi);
4584 Object* cell = Memory::Object_at(address + kPointerSize + 1); 4591 __ j(equal, &done, Label::kNear);
4585 // Low-level because clearing happens during GC. 4592 __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate)));
4586 reinterpret_cast<JSGlobalPropertyCell*>(cell)->set_value( 4593 __ j(equal, &done, Label::kNear);
4587 RawUninitializedSentinel(heap));
4588 }
4589 4594
4595 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
4596 // megamorphic.
4597 __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate)));
4598 __ j(equal, &initialize, Label::kNear);
4599 // MegamorphicSentinel is an immortal immovable object (undefined) so no
4600 // write-barrier is needed.
4601 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset),
4602 Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate)));
4603 __ jmp(&done, Label::kNear);
4590 4604
4591 Object* CallFunctionStub::GetCachedValue(Address address) { 4605 // An uninitialized cache is patched with the function.
4592 ASSERT(Memory::uint8_at(address + kPointerSize) == Assembler::kTestEaxByte); 4606 __ bind(&initialize);
4593 // 1 ~ size of the test eax opcode. 4607 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi);
4594 Object* cell = Memory::Object_at(address + kPointerSize + 1); 4608 // No need for a write barrier here - cells are rescanned.
4595 return JSGlobalPropertyCell::cast(cell)->value(); 4609
4610 __ bind(&done);
4596 } 4611 }
4597 4612
4598 4613
4599 void CallFunctionStub::Generate(MacroAssembler* masm) { 4614 void CallFunctionStub::Generate(MacroAssembler* masm) {
4615 // ebx : cache cell for call target
4600 // edi : the function to call 4616 // edi : the function to call
4601 Isolate* isolate = masm->isolate(); 4617 Isolate* isolate = masm->isolate();
4602 Label slow, non_function; 4618 Label slow, non_function;
4603 4619
4604 // The receiver might implicitly be the global object. This is 4620 // The receiver might implicitly be the global object. This is
4605 // indicated by passing the hole as the receiver to the call 4621 // indicated by passing the hole as the receiver to the call
4606 // function stub. 4622 // function stub.
4607 if (ReceiverMightBeImplicit()) { 4623 if (ReceiverMightBeImplicit()) {
4608 Label receiver_ok; 4624 Label receiver_ok;
4609 // Get the receiver from the stack. 4625 // Get the receiver from the stack.
4610 // +1 ~ return address 4626 // +1 ~ return address
4611 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); 4627 __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize));
4612 // Call as function is indicated with the hole. 4628 // Call as function is indicated with the hole.
4613 __ cmp(eax, isolate->factory()->the_hole_value()); 4629 __ cmp(eax, isolate->factory()->the_hole_value());
4614 __ j(not_equal, &receiver_ok, Label::kNear); 4630 __ j(not_equal, &receiver_ok, Label::kNear);
4615 // Patch the receiver on the stack with the global receiver object. 4631 // Patch the receiver on the stack with the global receiver object.
4616 __ mov(ebx, GlobalObjectOperand()); 4632 __ mov(ecx, GlobalObjectOperand());
4617 __ mov(ebx, FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); 4633 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset));
4618 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ebx); 4634 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx);
4619 __ bind(&receiver_ok); 4635 __ bind(&receiver_ok);
4620 } 4636 }
4621 4637
4622 // Check that the function really is a JavaScript function. 4638 // Check that the function really is a JavaScript function.
4623 __ JumpIfSmi(edi, &non_function); 4639 __ JumpIfSmi(edi, &non_function);
4624 // Goto slow case if we do not have a function. 4640 // Goto slow case if we do not have a function.
4625 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); 4641 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
4626 __ j(not_equal, &slow); 4642 __ j(not_equal, &slow);
4627 4643
4628 if (RecordCallTarget()) { 4644 if (RecordCallTarget()) {
4629 // Cache the called function in a global property cell in the 4645 GenerateRecordCallTarget(masm);
4630 // instruction stream after the call. Cache states are uninitialized,
4631 // monomorphic (indicated by a JSFunction), and megamorphic.
4632 Label initialize, call;
4633 // Load the cache cell address into ebx and the cache state into ecx.
4634 __ mov(ebx, Operand(esp, 0)); // Return address.
4635 __ mov(ebx, Operand(ebx, 1)); // 1 ~ sizeof 'test eax' opcode in bytes.
4636 __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset));
4637
4638 // A monomorphic cache hit or an already megamorphic state: invoke the
4639 // function without changing the state.
4640 __ cmp(ecx, edi);
4641 __ j(equal, &call, Label::kNear);
4642 __ cmp(ecx, Immediate(MegamorphicSentinel(isolate)));
4643 __ j(equal, &call, Label::kNear);
4644
4645 // A monomorphic miss (i.e, here the cache is not uninitialized) goes
4646 // megamorphic.
4647 __ cmp(ecx, Immediate(UninitializedSentinel(isolate)));
4648 __ j(equal, &initialize, Label::kNear);
4649 // MegamorphicSentinel is an immortal immovable object (undefined) so no
4650 // write-barrier is needed.
4651 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset),
4652 Immediate(MegamorphicSentinel(isolate)));
4653 __ jmp(&call, Label::kNear);
4654
4655 // An uninitialized cache is patched with the function.
4656 __ bind(&initialize);
4657 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi);
4658 // No need for a write barrier here - cells are rescanned.
4659
4660 __ bind(&call);
4661 } 4646 }
4662 4647
4663 // Fast-case: Just invoke the function. 4648 // Fast-case: Just invoke the function.
4664 ParameterCount actual(argc_); 4649 ParameterCount actual(argc_);
4665 4650
4666 if (ReceiverMightBeImplicit()) { 4651 if (ReceiverMightBeImplicit()) {
4667 Label call_as_function; 4652 Label call_as_function;
4668 __ cmp(eax, isolate->factory()->the_hole_value()); 4653 __ cmp(eax, isolate->factory()->the_hole_value());
4669 __ j(equal, &call_as_function); 4654 __ j(equal, &call_as_function);
4670 __ InvokeFunction(edi, 4655 __ InvokeFunction(edi,
4671 actual, 4656 actual,
4672 JUMP_FUNCTION, 4657 JUMP_FUNCTION,
4673 NullCallWrapper(), 4658 NullCallWrapper(),
4674 CALL_AS_METHOD); 4659 CALL_AS_METHOD);
4675 __ bind(&call_as_function); 4660 __ bind(&call_as_function);
4676 } 4661 }
4677 __ InvokeFunction(edi, 4662 __ InvokeFunction(edi,
4678 actual, 4663 actual,
4679 JUMP_FUNCTION, 4664 JUMP_FUNCTION,
4680 NullCallWrapper(), 4665 NullCallWrapper(),
4681 CALL_AS_FUNCTION); 4666 CALL_AS_FUNCTION);
4682 4667
4683 // Slow-case: Non-function called. 4668 // Slow-case: Non-function called.
4684 __ bind(&slow); 4669 __ bind(&slow);
4685 if (RecordCallTarget()) { 4670 if (RecordCallTarget()) {
4686 // If there is a call target cache, mark it megamorphic in the 4671 // If there is a call target cache, mark it megamorphic in the
4687 // non-function case. 4672 // non-function case. MegamorphicSentinel is an immortal immovable
4688 __ mov(ebx, Operand(esp, 0)); 4673 // object (undefined) so no write barrier is needed.
4689 __ mov(ebx, Operand(ebx, 1));
4690 // MegamorphicSentinel is an immortal immovable object (undefined) so no
4691 // write barrier is needed.
4692 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), 4674 __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset),
4693 Immediate(MegamorphicSentinel(isolate))); 4675 Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate)));
4694 } 4676 }
4695 // Check for function proxy. 4677 // Check for function proxy.
4696 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); 4678 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
4697 __ j(not_equal, &non_function); 4679 __ j(not_equal, &non_function);
4698 __ pop(ecx); 4680 __ pop(ecx);
4699 __ push(edi); // put proxy as additional argument under return address 4681 __ push(edi); // put proxy as additional argument under return address
4700 __ push(ecx); 4682 __ push(ecx);
4701 __ Set(eax, Immediate(argc_ + 1)); 4683 __ Set(eax, Immediate(argc_ + 1));
4702 __ Set(ebx, Immediate(0)); 4684 __ Set(ebx, Immediate(0));
4703 __ SetCallKind(ecx, CALL_AS_FUNCTION); 4685 __ SetCallKind(ecx, CALL_AS_FUNCTION);
4704 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); 4686 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY);
4705 { 4687 {
4706 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); 4688 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
4707 __ jmp(adaptor, RelocInfo::CODE_TARGET); 4689 __ jmp(adaptor, RelocInfo::CODE_TARGET);
4708 } 4690 }
4709 4691
4710 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead 4692 // CALL_NON_FUNCTION expects the non-function callee as receiver (instead
4711 // of the original receiver from the call site). 4693 // of the original receiver from the call site).
4712 __ bind(&non_function); 4694 __ bind(&non_function);
4713 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); 4695 __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi);
4714 __ Set(eax, Immediate(argc_)); 4696 __ Set(eax, Immediate(argc_));
4715 __ Set(ebx, Immediate(0)); 4697 __ Set(ebx, Immediate(0));
4716 __ SetCallKind(ecx, CALL_AS_METHOD); 4698 __ SetCallKind(ecx, CALL_AS_METHOD);
4717 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); 4699 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION);
4718 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); 4700 Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline();
4719 __ jmp(adaptor, RelocInfo::CODE_TARGET); 4701 __ jmp(adaptor, RelocInfo::CODE_TARGET);
4720 } 4702 }
4721 4703
4722 4704
4705 void CallConstructStub::Generate(MacroAssembler* masm) {
4706 // eax : number of arguments
4707 // ebx : cache cell for call target
4708 // edi : constructor function
4709 Label slow, non_function_call;
4710
4711 // Check that function is not a smi.
4712 __ JumpIfSmi(edi, &non_function_call);
4713 // Check that function is a JSFunction.
4714 __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx);
4715 __ j(not_equal, &slow);
4716
4717 if (RecordCallTarget()) {
4718 GenerateRecordCallTarget(masm);
4719 }
4720
4721 // Jump to the function-specific construct stub.
4722 __ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
4723 __ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kConstructStubOffset));
4724 __ lea(ebx, FieldOperand(ebx, Code::kHeaderSize));
4725 __ jmp(ebx);
4726
4727 // edi: called object
4728 // eax: number of arguments
4729 // ecx: object map
4730 Label do_call;
4731 __ bind(&slow);
4732 __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE);
4733 __ j(not_equal, &non_function_call);
4734 __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
4735 __ jmp(&do_call);
4736
4737 __ bind(&non_function_call);
4738 __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
4739 __ bind(&do_call);
4740 // Set expected number of arguments to zero (not changing eax).
4741 __ Set(ebx, Immediate(0));
4742 Handle<Code> arguments_adaptor =
4743 masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
4744 __ SetCallKind(ecx, CALL_AS_METHOD);
4745 __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET);
4746 }
4747
4748
4723 bool CEntryStub::NeedsImmovableCode() { 4749 bool CEntryStub::NeedsImmovableCode() {
4724 return false; 4750 return false;
4725 } 4751 }
4726 4752
4727 4753
4728 bool CEntryStub::IsPregenerated() { 4754 bool CEntryStub::IsPregenerated() {
4729 return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && 4755 return (!save_doubles_ || ISOLATE->fp_stubs_generated()) &&
4730 result_size_ == 1; 4756 result_size_ == 1;
4731 } 4757 }
4732 4758
(...skipping 2612 matching lines...) Expand 10 before | Expand all | Expand 10 after
7345 false); 7371 false);
7346 __ pop(edx); 7372 __ pop(edx);
7347 __ ret(0); 7373 __ ret(0);
7348 } 7374 }
7349 7375
7350 #undef __ 7376 #undef __
7351 7377
7352 } } // namespace v8::internal 7378 } } // namespace v8::internal
7353 7379
7354 #endif // V8_TARGET_ARCH_IA32 7380 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/ia32/debug-ia32.cc » ('j') | src/type-info.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698