Skip to content

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Dec 10, 2025

Fixes: #121760

To make the insertion of methods more robust we:

  • double the capacity of the MT builder up to the absolute limit required by the implementation of MethodDesc.
  • check if we still fit in the budget when adding methods.

Note: it may result in some programs that used to run to start throwing TypeLoadException.

These would be extreme cases though. The capacity for simple methods is implementation-specific. In CoreCLR a type cannot contain more than 65524 methods due to internal limitations.
(More complex cases involving inheritance/virtual methods may have additional limits.)

With runtime async, methods that return Task/ValueTask may consume 2 methods instead of 1 from this 65524 budget.
In a worst case where all methods return Task, the limit becomes 32762 methods in a single type, which still seems a very high limit for reasonably real programs that are not generated testcases.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 10, 2025
@VSadov VSadov added area-VM-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 10, 2025
@VSadov VSadov added this to the 11.0.0 milestone Dec 10, 2025
@dotnet-policy-service
Copy link
Contributor

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

VSadov and others added 8 commits December 10, 2025 15:21
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Per @VSadov's feedback, replaced runtime type generation with actual
source-defined classes containing 40k and 32k+ methods.

Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
@VSadov VSadov marked this pull request as ready for review December 11, 2025 00:42
@VSadov VSadov requested review from Copilot and jkotas December 11, 2025 00:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes a TODO comment in methodtablebuilder.cpp and makes the insertion of async method variants more robust by implementing proper capacity management and bounds checking. The changes enable RuntimeAsync by default and add comprehensive tests to verify the new method capacity limits.

  • Implements robust capacity doubling for async methods (up to MAX_SLOT_INDEX - 1 = 65524)
  • Adds runtime bounds checking before method insertion to prevent array overflow
  • Enables RuntimeAsync by default for CoreCLR and enables corresponding tests

Reviewed changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/coreclr/vm/methodtablebuilder.cpp Replaces conditional capacity doubling with robust upfront capacity calculation clamped to MAX_SLOT_INDEX - 1, and adds bounds check before method insertion to throw TypeLoadException when limit is exceeded
src/coreclr/utilcode/allocmemtracker.cpp Increases consistency check threshold from 10,000 to 60,000 blocks to accommodate larger classes with up to 65,524 methods
src/coreclr/inc/clrconfigvalues.h Enables RuntimeAsync feature by default (changes default value from 0 to 1)
src/tests/async/Directory.Build.targets Removes the DisableProjectBuild condition to enable async tests for CoreCLR (non-nativeaot) builds
src/tests/async/capacity/capacity.csproj Defines new test project structure including test file and three generated test class files
src/tests/async/capacity/capacity.cs Adds three test scenarios: 40,000 int-returning methods (should succeed), 32,750 Task-returning methods (should succeed), and 32,763 Task-returning methods (should fail with TypeLoadException)

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

LGTM otherwise. Thanks!

@VSadov
Copy link
Member Author

VSadov commented Dec 12, 2025

/ba-g failures in LibraryImportGenerator are all #122447

@VSadov VSadov enabled auto-merge (squash) December 12, 2025 02:34
@VSadov VSadov merged commit 68cccae into dotnet:main Dec 12, 2025
97 of 104 checks passed
@VSadov VSadov deleted the TODOmt branch December 12, 2025 02:34
@VSadov
Copy link
Member Author

VSadov commented Dec 12, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RuntimeAsync] TODO in methodtablebuildr.cpp

2 participants