Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Merge nmirror to master - #1337

Merged
jkotas merged 17 commits into
dotnet:masterfrom
jkotas:nmirror-merge
May 28, 2016
Merged

jkotas merged 17 commits into
dotnet:masterfrom
jkotas:nmirror-merge

Conversation

@jkotas

@jkotas jkotas commented May 28, 2016

Copy link
Copy Markdown
Member

No description provided.

RyanByi and others added 17 commits May 24, 2016 15:13
After un-marshaling the object reset the stream to the beginning. This addresses an issue causing the Threading\FirstParty\FTMThreadingTests to fail. What I suspect is happening although I can't verify this in the debugger is that when we create the stream we don't zero it out so it may contain contents of a previous stream that has already been released.  So if we don't reset the stream after we have un-marshaled the object and call CoReleaseMarshalData from the finalizer the stream may be positioned at another object and CoReleaseMarshalData may be releasing that object instead of the actual one that was written to the beginning of the stream.

Updating QueryInterface to call AddRef on the instance.

Updating Read and Write to use Buffer.MemoryCopy which should be faster.

Updating CopyTo to check the return value of Read and Write.

[tfs-changeset: 1607790]
… from another thread, the exception serialization logic missed the exception object and therefore is inaccessible in the final crash dump.

[tfs-changeset: 1608493]
[tfs-changeset: 1608951]
We have like 2 managed copies of EEType readers and there is a need to read EETypes from CoreLib and CoreRT compiler tests now (as a perf optimization/maintentance improvement). Time to consolidate everything into one thing instead of creating a new thing.

EEType.cs in the type loader is in the best position to become the ultimate EEType reader, so I'm cleaning it up a little (making it use the shared enums we use in the compiler and Runtime.Base).

***Next steps after this***
1. Mechanically remove the "m_" field prefixes
2. Put all the setters under #if TYPE_LOADER_IMPLEMENTATION
3. Move the file out next to EEType.Constants.cs (mirrors it to Github)
4. Profit
5. Make Runtime.Base use the common EEType.cs and delete the inferior EEType.cs
6. Make System.Private.CoreLib use the common EEType.cs and delete RuntimeImports for all of the trivial EEType sniffing
7. Delete RuntimeExports from Runtime.Base that provide EEType sniffing
8. Write unit tests for EEType emission in the CoreRT compiler and use EEType.cs to validate the structures look as expected

[tfs-changeset: 1608978]
CR: JKotas, DavidWr

The generic ConditionalWeakTable class uses the non-generic DependentHandle struct to store GC handles for keys and values.  Runtime type casts from objects back to TKey and TValue types are relatively expensive as they involve extracting the corresponding EETypePtr from the generic dictionary and calling the runtime casting routine.  The main change here is skipping certainly safe type casts in ConditionalWeakTable code by using RuntimeHelpers.UncheckedCast intrinsic.  One alternative approach would be making the DependentHandle struct generic; however, that would emit extra EETypes into SharedLibrary.dll.

Details:
*  Move LockHolder.cs file from TypeLoader to Common and add it to System.Private.CoreLib assembly.
*  Monitor.cs:  Move ConditionalWeakTable and delegate initialization to the class constructor so that we do not need to check whether they have been initialized on each GetLock or GetCondition call.
*  ClassConstructorRunner.cs:
    -  Use the LockHolder pattern to avoid potential reentrancy issues with Monitor..cctor after the change in Monitor.cs.
    -  Use raw EETypePtr equality when checking for the Lock type in the GetLock method to improve its performance.  This check is temporary and will be removed after we fix Framework code to directly use Lock.Acquire/Release methods instead of the lock statement on Lock objects.
*  ConditionalWeakTable.cs:  Use the LockHolder pattern for update operations.  Replace certainly safe type casts with RuntimeHelpers.UncheckedCast intrinsic calls.

With these changes I am observing ~28% throughput improvement for locking on normal types, and ~21% throughput improvement for locking on the special System.Threading.Lock type for x86ret build with SharedLibrary.dll.  These numbers should be taken with a grain of salt as they depend on inlining decisions and binary code layout.

[tfs-changeset: 1608989]
We have like 2 managed copies of EEType readers and there is a need to read EETypes from CoreLib and CoreRT compiler tests now (as a perf optimization/maintentance improvement). Time to consolidate everything into one thing instead of creating a new thing.

EEType.cs in the type loader is in the best position to become the ultimate EEType reader, so I'm cleaning it up a little (making it use the shared enums we use in the compiler and Runtime.Base).

***Next steps after this***
1. Mechanically remove the "m_" field prefixes
2. Put all the setters under #if TYPE_LOADER_IMPLEMENTATION
3. Move the file out next to EEType.Constants.cs (mirrors it to Github)
4. Profit
5. Make Runtime.Base use the common EEType.cs and delete the inferior EEType.cs
6. Make System.Private.CoreLib use the common EEType.cs and delete RuntimeImports for all of the trivial EEType sniffing
7. Delete RuntimeExports from Runtime.Base that provide EEType sniffing
8. Write unit tests for EEType emission in the CoreRT compiler and use EEType.cs to validate the structures look as expected

[tfs-changeset: 1608978]
Conflicts:
	src/System.Private.CoreLib/src/System/Threading/Monitor.cs
@jkotas
jkotas merged commit 6f8a31c into dotnet:master May 28, 2016
@jkotas
jkotas deleted the nmirror-merge branch May 31, 2016 14:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants