Changeset 209597 in webkit for trunk/Source/JavaScriptCore/jit/Repatch.cpp
- Timestamp:
- Dec 8, 2016, 10:52:51 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/jit/Repatch.cpp
r209433 r209597 45 45 #include "JITInlines.h" 46 46 #include "JSCInlines.h" 47 #include "JSWebAssembly.h" 47 48 #include "LinkBuffer.h" 48 49 #include "PolymorphicAccess.h" … … 557 558 } 558 559 560 static bool isWebAssemblyToJSCallee(VM& vm, JSCell* callee) 561 { 562 #if ENABLE(WEBASSEMBLY) 563 // The WebAssembly -> JS stub sets it caller frame's callee to a singleton which lives on the VM. 564 return callee == vm.webAssemblyToJSCallee.get(); 565 #else 566 UNUSED_PARAM(vm); 567 UNUSED_PARAM(callee); 568 return false; 569 #endif // ENABLE(WEBASSEMBLY) 570 } 571 572 static JSCell* webAssemblyOwner(VM& vm) 573 { 574 #if ENABLE(WEBASSEMBLY) 575 // Each WebAssembly.Instance shares the stubs from their WebAssembly.Module, which are therefore the appropriate owner. 576 return vm.topJSWebAssemblyInstance->module(); 577 #else 578 UNUSED_PARAM(vm); 579 RELEASE_ASSERT_NOT_REACHED(); 580 return nullptr; 581 #endif // ENABLE(WEBASSEMBLY) 582 } 583 559 584 void linkFor( 560 585 ExecState* exec, CallLinkInfo& callLinkInfo, CodeBlock* calleeCodeBlock, … … 562 587 { 563 588 ASSERT(!callLinkInfo.stub()); 564 565 CodeBlock* callerCodeBlock = exec->callerFrame()->codeBlock(); 566 567 VM* vm = callerCodeBlock->vm(); 568 589 590 CallFrame* callerFrame = exec->callerFrame(); 591 VM& vm = callerFrame->vm(); 592 CodeBlock* callerCodeBlock = callerFrame->codeBlock(); 593 594 // WebAssembly -> JS stubs don't have a valid CodeBlock. 595 JSCell* owner = isWebAssemblyToJSCallee(vm, callerFrame->callee()) ? webAssemblyOwner(vm) : callerCodeBlock; 596 ASSERT(owner); 597 569 598 ASSERT(!callLinkInfo.isLinked()); 570 callLinkInfo.setCallee( exec->callerFrame()->vm(), callerCodeBlock, callee);571 callLinkInfo.setLastSeenCallee( exec->callerFrame()->vm(), callerCodeBlock, callee);599 callLinkInfo.setCallee(vm, owner, callee); 600 callLinkInfo.setLastSeenCallee(vm, owner, callee); 572 601 if (shouldDumpDisassemblyFor(callerCodeBlock)) 573 602 dataLog("Linking call in ", *callerCodeBlock, " at ", callLinkInfo.codeOrigin(), " to ", pointerDump(calleeCodeBlock), ", entrypoint at ", codePtr, "\n"); 574 603 MacroAssembler::repatchNearCall(callLinkInfo.hotPathOther(), CodeLocationLabel(codePtr)); 575 604 576 605 if (calleeCodeBlock) 577 calleeCodeBlock->linkIncomingCall( exec->callerFrame(), &callLinkInfo);578 606 calleeCodeBlock->linkIncomingCall(callerFrame, &callLinkInfo); 607 579 608 if (callLinkInfo.specializationKind() == CodeForCall && callLinkInfo.allowStubs()) { 580 linkSlowFor( vm, callLinkInfo, linkPolymorphicCallThunkGenerator);609 linkSlowFor(&vm, callLinkInfo, linkPolymorphicCallThunkGenerator); 581 610 return; 582 611 } 583 612 584 linkSlowFor( vm, callLinkInfo);613 linkSlowFor(&vm, callLinkInfo); 585 614 } 586 615 … … 646 675 } 647 676 648 void linkVirtualFor( 649 ExecState* exec, CallLinkInfo& callLinkInfo) 650 { 651 CodeBlock* callerCodeBlock = exec->callerFrame()->codeBlock();652 VM* vm = callerCodeBlock->vm();677 void linkVirtualFor(ExecState* exec, CallLinkInfo& callLinkInfo) 678 { 679 CallFrame* callerFrame = exec->callerFrame(); 680 VM& vm = callerFrame->vm(); 681 CodeBlock* callerCodeBlock = callerFrame->codeBlock(); 653 682 654 683 if (shouldDumpDisassemblyFor(callerCodeBlock)) 655 dataLog("Linking virtual call at ", *callerCodeBlock, " ", exec->callerFrame()->codeOrigin(), "\n");656 657 MacroAssemblerCodeRef virtualThunk = virtualThunkFor( vm, callLinkInfo);658 revertCall( vm, callLinkInfo, virtualThunk);659 callLinkInfo.setSlowStub(createJITStubRoutine(virtualThunk, *vm, nullptr, true));684 dataLog("Linking virtual call at ", *callerCodeBlock, " ", callerFrame->codeOrigin(), "\n"); 685 686 MacroAssemblerCodeRef virtualThunk = virtualThunkFor(&vm, callLinkInfo); 687 revertCall(&vm, callLinkInfo, virtualThunk); 688 callLinkInfo.setSlowStub(createJITStubRoutine(virtualThunk, vm, nullptr, true)); 660 689 } 661 690 … … 678 707 return; 679 708 } 680 681 CodeBlock* callerCodeBlock = exec->callerFrame()->codeBlock(); 682 VM* vm = callerCodeBlock->vm(); 683 709 710 CallFrame* callerFrame = exec->callerFrame(); 711 VM& vm = callerFrame->vm(); 712 CodeBlock* callerCodeBlock = callerFrame->codeBlock(); 713 bool isWebAssembly = isWebAssemblyToJSCallee(vm, callerFrame->callee()); 714 715 // WebAssembly -> JS stubs don't have a valid CodeBlock. 716 JSCell* owner = isWebAssembly ? webAssemblyOwner(vm) : callerCodeBlock; 717 ASSERT(owner); 718 684 719 CallVariantList list; 685 720 if (PolymorphicCallStubRoutine* stub = callLinkInfo.stub()) … … 710 745 for (CallVariant variant : list) { 711 746 CodeBlock* codeBlock; 712 if ( variant.executable()->isHostFunction())747 if (isWebAssembly || variant.executable()->isHostFunction()) 713 748 codeBlock = nullptr; 714 749 else { … … 728 763 // If we are over the limit, just use a normal virtual call. 729 764 unsigned maxPolymorphicCallVariantListSize; 730 if (callerCodeBlock->jitType() == JITCode::topTierJIT()) 765 if (isWebAssembly) 766 maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForWebAssemblyToJS(); 767 else if (callerCodeBlock->jitType() == JITCode::topTierJIT()) 731 768 maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForTopTier(); 732 769 else 733 770 maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSize(); 771 734 772 if (list.size() > maxPolymorphicCallVariantListSize) { 735 773 linkVirtualFor(exec, callLinkInfo); … … 739 777 GPRReg calleeGPR = static_cast<GPRReg>(callLinkInfo.calleeGPR()); 740 778 741 CCallHelpers stubJit( vm, callerCodeBlock);779 CCallHelpers stubJit(&vm, callerCodeBlock); 742 780 743 781 CCallHelpers::JumpList slowPath; … … 788 826 std::unique_ptr<uint32_t[]> fastCounts; 789 827 790 if ( callerCodeBlock->jitType() != JITCode::topTierJIT())828 if (!isWebAssembly && callerCodeBlock->jitType() != JITCode::topTierJIT()) 791 829 fastCounts = std::make_unique<uint32_t[]>(callCases.size()); 792 830 … … 885 923 AssemblyHelpers::Jump slow = stubJit.jump(); 886 924 887 LinkBuffer patchBuffer( *vm, stubJit, callerCodeBlock, JITCompilationCanFail);925 LinkBuffer patchBuffer(vm, stubJit, owner, JITCompilationCanFail); 888 926 if (patchBuffer.didFailToAllocate()) { 889 927 linkVirtualFor(exec, callLinkInfo); … … 899 937 callToCodePtr.call, FunctionPtr(isTailCall ? callToCodePtr.codePtr.dataLocation() : callToCodePtr.codePtr.executableAddress())); 900 938 } 901 if ( JITCode::isOptimizingJIT(callerCodeBlock->jitType()))939 if (isWebAssembly || JITCode::isOptimizingJIT(callerCodeBlock->jitType())) 902 940 patchBuffer.link(done, callLinkInfo.callReturnLocation().labelAtOffset(0)); 903 941 else 904 942 patchBuffer.link(done, callLinkInfo.hotPathOther().labelAtOffset(0)); 905 patchBuffer.link(slow, CodeLocationLabel(vm ->getCTIStub(linkPolymorphicCallThunkGenerator).code()));943 patchBuffer.link(slow, CodeLocationLabel(vm.getCTIStub(linkPolymorphicCallThunkGenerator).code())); 906 944 907 945 auto stubRoutine = adoptRef(*new PolymorphicCallStubRoutine( … … 909 947 callerCodeBlock, patchBuffer, 910 948 ("Polymorphic call stub for %s, return point %p, targets %s", 911 toCString(*callerCodeBlock).data(), callLinkInfo.callReturnLocation().labelAtOffset(0).executableAddress(),949 isWebAssembly ? "WebAssembly" : toCString(*callerCodeBlock).data(), callLinkInfo.callReturnLocation().labelAtOffset(0).executableAddress(), 912 950 toCString(listDump(callCases)).data())), 913 *vm, callerCodeBlock, exec->callerFrame(), callLinkInfo, callCases,951 vm, owner, exec->callerFrame(), callLinkInfo, callCases, 914 952 WTFMove(fastCounts))); 915 953 … … 920 958 // reachable on 32-bits since a non-cell callee will always 921 959 // trigger the slow path 922 linkSlowFor( vm, callLinkInfo);960 linkSlowFor(&vm, callLinkInfo); 923 961 924 962 // If there had been a previous stub routine, that one will die as soon as the GC runs and sees
Note:
See TracChangeset
for help on using the changeset viewer.