') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Enable FEATURE_ARRAYSTUB_AS_IL on all platforms by huoyaoyuan · Pull Request #103533 · dotnet/runtime · GitHub
Skip to content

Enable FEATURE_ARRAYSTUB_AS_IL on all platforms - #103533

Merged
jkotas merged 6 commits into
dotnet:mainfrom
huoyaoyuan:array-stub-x86
Jun 16, 2024
Merged

Enable FEATURE_ARRAYSTUB_AS_IL on all platforms#103533
jkotas merged 6 commits into
dotnet:mainfrom
huoyaoyuan:array-stub-x86

Conversation

@huoyaoyuan

Copy link
Copy Markdown
Member

Since the initial publish commit of coreclr, FEATURE_ARRAYSTUB_AS_IL was not enabled for win-x86. Now it's 10 years later and our JIT compiler is able to produce better code than hand written assemblies. It's also much easier to maintain the logic in IL.

A little portion of dead code accessing ESP+offset is not removed in stublinkerx86.

@ghostghost added the area-VM-coreclr label Jun 16, 2024
@huoyaoyuan
huoyaoyuan marked this pull request as ready for review June 16, 2024 07:34
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Jun 16, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@huoyaoyuan

Copy link
Copy Markdown
MemberAuthor

Benchmarks:

publicclassBase{}publicclassDerived:Base{}publicstructGCStruct{publicobjecta,b,c,d,e,f,g,h;}privateBase[,]baseArray=newBase[10,1];privateBase[,]covariantArray=newDerived[10,1];privateDerived[,]derivedArray=newDerived[10,1];privateint[,]intArray=newint[10,1];privateGuid[,]guidArray=newGuid[10,1];privateGCStruct[,]gcStructArray=newGCStruct[10,1];privatedouble[,]doubleArray=newdouble[10,1];privateDerivedderivedObj=newDerived();privateGuidguid=Guid.NewGuid();privateGCStructgcStruct=newGCStruct{a=newobject(),g=newobject(),};privatevoidGenericSet<T>(T[,]array,Tvalue){for(inti=0;i<10;i++){array[i,0]=value;}}[Benchmark]publicvoidReferenceTypeBase()=>GenericSet(baseArray,derivedObj);[Benchmark]publicvoidReferenceTypeExactMatch()=>GenericSet(derivedArray,derivedObj);[Benchmark]publicvoidReferenceTypeCovariant()=>GenericSet(covariantArray,derivedObj);[Benchmark]publicvoidPrimitiveInt()=>GenericSet(intArray,42);[Benchmark]publicvoidNonGCStruct()=>GenericSet(guidArray,guid);[Benchmark]publicvoidGCStruct()=>GenericSet(gcStructArray,gcStruct);[Benchmark]publicvoidFPUType()=>GenericSet(doubleArray,123.456);
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3737/23H2/2023Update/SunValley3)
13th Gen Intel Core i9-13900K, 1 CPU, 32 logical and 24 physical cores
.NET SDK 9.0.100-preview.4.24267.66
[Host] : .NET 8.0.5 (8.0.524.21615), X86 RyuJIT AVX2
Job-PHSMMU : .NET 9.0.0 (42.42.42.42424), X86 RyuJIT AVX2
Job-LOQTGY : .NET 9.0.0 (42.42.42.42424), X86 RyuJIT AVX2
OutlierMode=DontRemove Affinity=00000000000000001111111111111111 MemoryRandomization=True
MethodJobToolchainMeanErrorStdDevRatioRatioSD
ReferenceTypeBaseJob-PHSMMU\x86-baseline\corerun.exe39.986 ns0.2994 ns0.2800 ns1.000.00
ReferenceTypeBaseJob-LOQTGY\x86-pr\corerun.exe31.664 ns0.2694 ns0.2520 ns0.790.00
ReferenceTypeExactMatchJob-PHSMMU\x86-baseline\corerun.exe24.066 ns0.0779 ns0.0729 ns1.000.00
ReferenceTypeExactMatchJob-LOQTGY\x86-pr\corerun.exe24.819 ns0.5049 ns0.5185 ns1.030.02
ReferenceTypeCovariantJob-PHSMMU\x86-baseline\corerun.exe23.918 ns0.1255 ns0.1174 ns1.000.00
ReferenceTypeCovariantJob-LOQTGY\x86-pr\corerun.exe24.498 ns0.4961 ns0.4872 ns1.020.02
PrimitiveIntJob-PHSMMU\x86-baseline\corerun.exe4.219 ns0.0412 ns0.0385 ns1.000.00
PrimitiveIntJob-LOQTGY\x86-pr\corerun.exe4.127 ns0.0582 ns0.0544 ns0.980.02
NonGCStructJob-PHSMMU\x86-baseline\corerun.exe82.065 ns0.9609 ns0.8989 ns1.000.00
NonGCStructJob-LOQTGY\x86-pr\corerun.exe10.953 ns0.1486 ns0.1390 ns0.130.00
GCStructJob-PHSMMU\x86-baseline\corerun.exe103.016 ns0.7472 ns0.6989 ns1.000.00
GCStructJob-LOQTGY\x86-pr\corerun.exe60.069 ns1.1729 ns1.0971 ns0.580.01
FPUTypeJob-PHSMMU\x86-baseline\corerun.exe5.275 ns0.0429 ns0.0402 ns1.000.00
FPUTypeJob-LOQTGY\x86-pr\corerun.exe5.140 ns0.1218 ns0.1140 ns0.970.02

JIT generates much better code for large structs.

@huoyaoyuan

Copy link
Copy Markdown
MemberAuthor

Test failure at ILStubCache::CreateNewMethodDesc. Looks related.

@huoyaoyuan

Copy link
Copy Markdown
MemberAuthor

The test failure seems to unveil another bug:

In ILStubCache::CreateNewMethodDesc, the stub type is detected for each stub. For StubVirtualStaticMethodDispatch, it's detection is not in else if, but another block separated from the if-else if tree:

pMD->SetILStubType(DynamicMethodDesc::StubCLRToNativeInterop);
}
}
if (SF_IsVirtualStaticMethodDispatchStub(dwStubFlags))
{
pMD->SetILStubType(DynamicMethodDesc::StubVirtualStaticMethodDispatch);
}

Thus for SVM dispatch stubs, the stub type is set as the fallback StubCLRToNativeInterop, then StubVirtualStaticMethodDispatch.
However in DynamicMethodDesc::SetILStubType, the stub type bits are |'d, without clearing existing flag:

voidSetILStubType(ILStubType type)
{
_ASSERTE(HasFlags(FlagIsILStub));
m_dwExtendedFlags |= type;
}

So the stub type will actually be set as StubCLRToNativeInterop|StubVirtualStaticMethodDispatch. The value of StubCLRToNativeInterop is 0x01, and for all other configurations and previously Windows x86, the value of StubVirtualStaticMethodDispatch is odd, so the |'d result is still StubVirtualStaticMethodDispatch.
By enabling StubArrayOp, this PR changes the value on Windows x86 from 0x09 to 0x0a, then the result of StubCLRToNativeInterop|StubVirtualStaticMethodDispatch becomes 0x0b, which is out of range.

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you

@jkotas
jkotas merged commit 2d9373a into dotnet:mainJun 16, 2024
@huoyaoyuan
huoyaoyuan deleted the array-stub-x86 branch June 17, 2024 01:58
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Jul 17, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-VM-coreclrcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@huoyaoyuan@jkotas