Move the BSTR trailbyte tracking out of the sync block#121362
Merged
jkoritzinsky merged 10 commits intodotnet:mainfrom Nov 7, 2025
Merged
Move the BSTR trailbyte tracking out of the sync block#121362jkoritzinsky merged 10 commits intodotnet:mainfrom
jkoritzinsky merged 10 commits intodotnet:mainfrom
Conversation
This corner case becomes less used with time, and it increases the size of every syncblock even though it's only used with strings.
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
jkotas
reviewed
Nov 5, 2025
3 tasks
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request removes the legacy BSTR trail byte support from the CoreCLR, migrating it from a sync block-based implementation to a ConditionalWeakTable-based approach in managed code. This change aims to reduce memory overhead and simplify the string object implementation.
Key Changes
- Removed trail byte field and related methods from SyncBlock
- Removed trail byte methods from StringObject (HasTrailByte, GetTrailByte, SetTrailByte)
- Moved trail byte storage to managed code using ConditionalWeakTable in BSTRMarshaler
- Updated BSTR marshaling code to call managed methods instead of native interop
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/vm/syncblk.h | Removed m_BSTRTrailByte field and related methods from SyncBlock |
| src/coreclr/vm/object.h | Removed trail byte methods and NewString overload from StringObject |
| src/coreclr/vm/object.cpp | Removed trail byte method implementations and NewString overload |
| src/coreclr/vm/stubhelpers.h | Removed native trail byte function declarations |
| src/coreclr/vm/stubhelpers.cpp | Removed native trail byte function implementations |
| src/coreclr/vm/qcallentrypoints.cpp | Removed QCall entry point for SetStringTrailByte |
| src/coreclr/vm/ecalllist.h | Removed FCall entry for TryGetStringTrailByte |
| src/coreclr/vm/olevariant.cpp | Updated to call managed methods for trail byte operations and fixed GC mode contracts |
| src/coreclr/vm/metasig.h | Added method signatures for new managed trail byte methods |
| src/coreclr/vm/corelib.h | Added method definitions for SetTrailByte and TryGetTrailByte |
| src/coreclr/vm/callhelpers.h | Added INT8_TO_ARGHOLDER macro for byte argument conversion |
| src/coreclr/System.Private.CoreLib/src/System/StubHelpers.cs | Implemented ConditionalWeakTable-based trail byte storage in BSTRMarshaler |
Comments suppressed due to low confidence (1)
src/coreclr/vm/object.cpp:826
- These macros and functions (SPECIAL_STRING_VB_BYTE_ARRAY, MARKS_VB_BYTE_ARRAY, MAKE_VB_TRAIL_BYTE, GET_VB_TRAIL_BYTE) appear to be unused after the removal of trail byte functionality from StringObject and SyncBlock. Since the trail byte feature has been moved to managed code using ConditionalWeakTable, these definitions should be removed to avoid confusion and reduce technical debt.
//The special string helpers are used as flag bits for weird strings that have bytes
//after the terminating 0. The only case where we use this right now is the VB BSTR as
//byte array which is described in MakeStringAsByteArrayFromBytes.
#define SPECIAL_STRING_VB_BYTE_ARRAY 0x100
FORCEINLINE BOOL MARKS_VB_BYTE_ARRAY(WCHAR x)
{
return static_cast<BOOL>(x & SPECIAL_STRING_VB_BYTE_ARRAY);
}
FORCEINLINE WCHAR MAKE_VB_TRAIL_BYTE(BYTE x)
{
return static_cast<WCHAR>(x) | SPECIAL_STRING_VB_BYTE_ARRAY;
}
FORCEINLINE BYTE GET_VB_TRAIL_BYTE(WCHAR x)
{
return static_cast<BYTE>(x & 0xFF);
}
Member
AaronRobinsonMSFT
left a comment
There was a problem hiding this comment.
Do we have a test for this already?
jkotas
reviewed
Nov 5, 2025
Co-authored-by: Jan Kotas <[email protected]>
Member
Author
|
I don't see one, I'll go add one. |
This was referenced Nov 6, 2025
Open
jkotas
reviewed
Nov 6, 2025
jkotas
reviewed
Nov 6, 2025
Member
Author
|
/ba-g android timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This corner case becomes less used with time, and it increases the size of every syncblock even though it's only used with strings.
This should also help reduce the number of syncblks we create for legacy applications that do use this feature a lot.