Changeset 249310 in webkit


Ignore:
Timestamp:
Aug 29, 2019 8:28:20 PM (5 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] Repatch should construct CallCases and CasesValue at the same time
https://bugs.webkit.org/show_bug.cgi?id=201325

Reviewed by Saam Barati.

JSTests:

  • stress/repatch-switch.js: Added.

(main.f2.f0):
(main.f2.f3):
(main.f2.f1):
(main.f2):
(main):

Source/JavaScriptCore:

In linkPolymorphicCall, we should create callCases and casesValue at the same time to assert callCases.size() == casesValue.size().
If the call variant is isClosureCall and InternalFunction, we skip adding it to casesValue. So we should not add this variant to callCases too.

  • jit/Repatch.cpp:

(JSC::linkPolymorphicCall):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r249306 r249310  
     12019-08-29  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Repatch should construct CallCases and CasesValue at the same time
     4        https://bugs.webkit.org/show_bug.cgi?id=201325
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/repatch-switch.js: Added.
     9        (main.f2.f0):
     10        (main.f2.f3):
     11        (main.f2.f1):
     12        (main.f2):
     13        (main):
     14
    1152019-08-29  Yusuke Suzuki  <ysuzuki@apple.com>
    216
  • trunk/Source/JavaScriptCore/ChangeLog

    r249306 r249310  
     12019-08-29  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] Repatch should construct CallCases and CasesValue at the same time
     4        https://bugs.webkit.org/show_bug.cgi?id=201325
     5
     6        Reviewed by Saam Barati.
     7
     8        In linkPolymorphicCall, we should create callCases and casesValue at the same time to assert `callCases.size() == casesValue.size()`.
     9        If the call variant is isClosureCall and InternalFunction, we skip adding it to casesValue. So we should not add this variant to callCases too.
     10
     11        * jit/Repatch.cpp:
     12        (JSC::linkPolymorphicCall):
     13
    1142019-08-29  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/Source/JavaScriptCore/jit/Repatch.cpp

    r249175 r249310  
    10081008   
    10091009    Vector<PolymorphicCallCase> callCases;
     1010    Vector<int64_t> caseValues;
    10101011   
    10111012    // Figure out what our cases are.
     
    10221023            }
    10231024        }
    1024        
    1025         callCases.append(PolymorphicCallCase(variant, codeBlock));
    1026     }
    1027    
    1028     // If we are over the limit, just use a normal virtual call.
    1029     unsigned maxPolymorphicCallVariantListSize;
    1030     if (isWebAssembly)
    1031         maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForWebAssemblyToJS();
    1032     else if (callerCodeBlock->jitType() == JITCode::topTierJIT())
    1033         maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForTopTier();
    1034     else
    1035         maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSize();
    1036 
    1037     if (list.size() > maxPolymorphicCallVariantListSize) {
    1038         linkVirtualFor(exec, callLinkInfo);
    1039         return;
    1040     }
    1041 
    1042     Vector<int64_t> caseValues(callCases.size());
    1043     Vector<CallToCodePtr> calls(callCases.size());
    1044     UniqueArray<uint32_t> fastCounts;
    1045    
    1046     if (!isWebAssembly && callerCodeBlock->jitType() != JITCode::topTierJIT())
    1047         fastCounts = makeUniqueArray<uint32_t>(callCases.size());
    1048    
    1049     for (size_t i = 0; i < callCases.size(); ++i) {
    1050         if (fastCounts)
    1051             fastCounts[i] = 0;
    1052        
    1053         CallVariant variant = callCases[i].variant();
     1025
    10541026        int64_t newCaseValue = 0;
    10551027        if (isClosureCall) {
     
    10651037                newCaseValue = bitwise_cast<intptr_t>(variant.internalFunction());
    10661038        }
    1067        
     1039
    10681040        if (!ASSERT_DISABLED) {
    1069             for (size_t j = 0; j < i; ++j) {
    1070                 if (caseValues[j] != newCaseValue)
    1071                     continue;
    1072 
     1041            if (caseValues.contains(newCaseValue)) {
    10731042                dataLog("ERROR: Attempt to add duplicate case value.\n");
    10741043                dataLog("Existing case values: ");
    10751044                CommaPrinter comma;
    1076                 for (size_t k = 0; k < i; ++k)
    1077                     dataLog(comma, caseValues[k]);
     1045                for (auto& value : caseValues)
     1046                    dataLog(comma, value);
    10781047                dataLog("\n");
    10791048                dataLog("Attempting to add: ", newCaseValue, "\n");
     
    10821051            }
    10831052        }
    1084        
    1085         caseValues[i] = newCaseValue;
     1053
     1054        callCases.append(PolymorphicCallCase(variant, codeBlock));
     1055        caseValues.append(newCaseValue);
     1056    }
     1057    ASSERT(callCases.size() == caseValues.size());
     1058
     1059    // If we are over the limit, just use a normal virtual call.
     1060    unsigned maxPolymorphicCallVariantListSize;
     1061    if (isWebAssembly)
     1062        maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForWebAssemblyToJS();
     1063    else if (callerCodeBlock->jitType() == JITCode::topTierJIT())
     1064        maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSizeForTopTier();
     1065    else
     1066        maxPolymorphicCallVariantListSize = Options::maxPolymorphicCallVariantListSize();
     1067
     1068    // We use list.size() instead of callCases.size() because we respect CallVariant size for now.
     1069    if (list.size() > maxPolymorphicCallVariantListSize) {
     1070        linkVirtualFor(exec, callLinkInfo);
     1071        return;
     1072    }
     1073
     1074    Vector<CallToCodePtr> calls(callCases.size());
     1075    UniqueArray<uint32_t> fastCounts;
     1076
     1077    if (!isWebAssembly && callerCodeBlock->jitType() != JITCode::topTierJIT()) {
     1078        fastCounts = makeUniqueArray<uint32_t>(callCases.size());
     1079        memset(fastCounts.get(), 0, callCases.size() * sizeof(uint32_t));
    10861080    }
    10871081   
Note: See TracChangeset for help on using the changeset viewer.