Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit da8651b

Browse files
authored
Merge pull request #25439 from dotnet-maestro-bot/merge/master-to-release/3.0
[automated] Merge branch 'master' => 'release/3.0'
2 parents 7ec87b0 + 2f531ea commit da8651b

File tree

910 files changed

+20106
-106487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

910 files changed

+20106
-106487
lines changed

CMakeLists.txt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# Verify minimum required version
2-
cmake_minimum_required(VERSION 2.8.12)
2+
cmake_minimum_required(VERSION 3.5.1)
33

4-
if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
5-
cmake_policy(SET CMP0042 NEW)
6-
endif()
7-
8-
if (NOT WIN32)
9-
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -std=c++11" CACHE STRING "Flags used by the compiler during all build types.")
10-
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -std=c11" CACHE STRING "Flags used by the compiler during all build types.")
11-
endif()
4+
cmake_policy(SET CMP0042 NEW)
125

136
# Set the project name
147
project(CoreCLR)
@@ -165,7 +158,6 @@ if(CLR_CMAKE_PLATFORM_UNIX AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
165158
endif()
166159

167160
if(CLR_CMAKE_PLATFORM_UNIX)
168-
add_subdirectory(src/ToolBox/SOS/lldbplugin)
169161
add_subdirectory(src/pal)
170162
add_subdirectory(src/coreclr/hosts)
171163
add_subdirectory(src/ildasm/unixcoreclrloader)

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
</PropertyGroup>
1515
<PropertyGroup>
1616
<!-- Enables Strict mode for Roslyn compiler -->
17-
<Features>strict</Features>
17+
<Features>strict;nullablePublicOnly</Features>
1818
</PropertyGroup>
1919
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# Profiler Attach on CoreCLR
3+
4+
Starting with .Net Core 3 preview6 there is a new profiler attach mechanism for CoreCLR. The desktop .Net Framework has had profiler attach since v4, but we have not had profiler attach on .Net Core. The desktop implementation was very Windows-centric and we did not have a good way to offer a cross platform profiler attach mechanism. The recent diagnostics port work means there is now a cross platform communication channel for external processes to communicate with a running CoreCLR process, and this allowed us to finally offer profiler attach for CoreCLR.
5+
6+
## How do you attach a profiler to a running CoreCLR process?
7+
8+
***Disclaimer: the code in the dotnet/diagnostics repo referred to below is in prelease and is under active development. You should expect things to change before the official release.***
9+
10+
Attaching a profiler to a running CoreCLR process involves sending a message from an external process (the trigger process) on the diagnostics port telling the runtime which profiler to attach. We have a premade managed implementation over at the [Diagnostics repo](https://github.com/dotnet/diagnostics). The attach method is `DiagnosticHelpers.AttachProfiler` in the `Microsoft.Diagnostics.Tools.RuntimeClient` library, which will be shipped on NuGet once it is released. It takes five arguments:
11+
12+
1) `int processId` - (Required) The process ID to attach to.
13+
2) `uint attachTimeout` - (Required) A timeout that informs the runtime how long to wait while attempting to attach. This does not impact the timeout of trying to send the attach message.
14+
3) `Guid profilerGuid` - (Required) The profiler's GUID to use when initializing.
15+
4) `string profilerPath` - (Required) The path to the profiler on disk.
16+
5) `byte[] additionalData` - (Optional) A data blob that will be passed to `ICorProfilerCallback3::InitializeForAttach` as `pvClientData`.
17+
18+
This method returns a status HR following the usual convention, 0 (S_OK) means a profiler was successfully attached and any other value is an error indicating what went wrong.
19+
20+
## What if you can't run managed code in your trigger process?
21+
22+
If you are unable to run managed code as part of your trigger process, it is still possible to request a profiler attach. The spec for the diagnostics port is located [here](https://github.com/dotnet/diagnostics/blob/master/documentation/design-docs/ipc-protocol.md).
23+
24+
You will have to do the following (according to the above spec):
25+
1) Open the appropriate channel - domain socket on Linux and a named pipe on Windows
26+
2) Construct the payload with the appropriate command (Profiler) and command ID (AttachProfiler), plus all of the arguments listed above
27+
3) Send the payload over the channel
28+
4) Parse the response

Documentation/Profiling/Profiler Breaking Changes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
Over time we will need to modify the Profiler APIs, this document will serve as a record of any breaking changes.
44

55
1. Code Versioning introduced changes documented [here](../design-docs/code-versioning-profiler-breaking-changes.md)
6-
2. The work to allow adding new types and methods after module load means ICorProfilerInfo7::ApplyMetadata will now potentially trigger a GC, and will not be callable in situations where a GC can not happen (for example ICorProfilerCallback::RootReferences).
6+
2. The work to allow adding new types and methods after module load means ICorProfilerInfo7::ApplyMetadata will now potentially trigger a GC, and will not be callable in situations where a GC can not happen (for example ICorProfilerCallback::RootReferences).
7+
3. As part of the work to allow ReJIT on attach ReJITted methods will no longer be inlined (ever). Since the inlining is blocked there won't be a `ICorProfilerCallback::JITInlining` callback.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# ReJIT on Attach
2+
3+
A longstanding feature request we've had from profiler authors is the ability to ReJIT a method after attach. There are non-trivial technical reasons this was never an option in desktop .Net, but CoreCLR has had some changes that made it more feasible to attain. As of .Net Core 3 preview5 profiler authors now have the ability to ReJIT methods after attach.
4+
5+
## The new API
6+
7+
To enable ReJIT on attach there is a new API `ICorProfilerInfo10::RequestReJITWithInliners`. Here is the signature:
8+
9+
```
10+
HRESULT RequestReJITWithInliners(
11+
[in] DWORD dwRejitFlags,
12+
[in] ULONG cFunctions,
13+
[in, size_is(cFunctions)] ModuleID moduleIds[],
14+
[in, size_is(cFunctions)] mdMethodDef methodIds[]);
15+
```
16+
17+
Conceptually this works the same as `ICorProfilerInfo4::RequestReJIT` except it will automatically ReJIT any methods that have inlined the target method(s) in the past. The arguments are the same except for the additon of `dwRejitFlags` as the first parameter. The valid values for this argument come from this enum:
18+
19+
```
20+
typedef enum
21+
{
22+
// ReJITted methods will be prevented from being inlined
23+
COR_PRF_REJIT_BLOCK_INLINING = 0x1,
24+
25+
// This flag controls whether the runtime will call GetReJITParameters
26+
// on methods that are ReJITted because they inline a method that was requested
27+
// for ReJIT
28+
COR_PRF_REJIT_INLINING_CALLBACKS = 0x2
29+
} COR_PRF_REJIT_FLAGS;
30+
```
31+
32+
Any callers of this API must set `COR_PRF_REJIT_BLOCK_INLINING`. Although it is possible that in the future this restriction will be lifted, the current implementation blocks ReJITted methods from being inlined (ever).
33+
34+
The other value `COR_PRF_REJIT_INLINING_CALLBACKS` controls whether you get a `ICorProfilerCallback4::GetReJITParameters` callback for any methods that are ReJITted as inliners of the requested method. The default is to not receive callbacks for these methods. You will always receive a `GetReJITParameters` callback for any methods that are explictly requested.
35+
36+
37+
## Inner workings/Limitations
38+
39+
With this API you are no longer required to monitor JIT callbacks to manually block inlining from occurring. To acheive that the runtime now globally blocks a ReJITted method from being inlined (even if it was ReJITted with `ICorProfilerInfo4::RequestReJIT` and not the new API). Once a method is reverted with `ICorProfilerInfo4::RequestRevert` inlining will occur again for any future jittings.
40+
41+
It is important to mention here how `RequestRevert` works. When you revert a ReJITted method, the original native code is activated. This means there are potential pitfalls for calling `RequestRevert`. Consider an app where method A inlines method B and the profiler wants to ReJIT both A and B. Once A and B are both ReJITted, the application will behave as expected. However, if later on the profiler decides to revert method A but intends to leave method B ReJITted, it might be surprising to find that once the original native code for A is activated this includes the inlined non-ReJIT IL for method B. Effectively any calls to B through A will be calling the original, unmodified IL.
42+
43+
To revert a method without having to reason about the inline sequence, we suggest calling RequestReJIT again on the method but providing the original IL in GetReJITParameters.
44+
45+
The limitation of collectible and dynamic methods has not been lifted. It is not currently possible to ReJIT these types of methods, although we would like to lift that restriction in the future. Even if you never intend to call RequestReJIT directly on a collectible or dynamic method, this may still affect you when doing ReJIT on attach if the method you would like to ReJIT has been inlined in a collectible or dynamic method. I.e. if you would like to ReJIT method A which has been inlined in collectible method B, there is currently no way to make method B call the updated method A.
46+
47+
## Metadata Changes on Attach
48+
49+
Usually profiler authors do not want to trivially change the IL for ReJITted methods, but rather inject new types/methods and call those new types/methods. Previously our guidance has been to do any metadata rewriting during the `ICorProfilerCallback::ModuleLoadFinished` callback. This advice presents a challenge if the profiler is not attached during module load and still wants to modify metadata.
50+
51+
To work around this a set of metadata changes is now legal to make at any point as long as you call `ICorProfilerInfo7::ApplyMetadata` afterwards:
52+
* `DefineUserString`
53+
* `DefineTypeRefByName`
54+
* `DefineMemberRef`
55+
* `DefineTypeDef`
56+
* `DefineMethod` - methods on new types, or non-virtual methods on existing types
57+
* `DefineNestedType` - only on new types
58+
* `DefineCustomAttribute`
59+
* `DefinePinvokeMap`
60+
* `DefineModuleRef`
61+
* `DefineField` - only on new types
62+
* `DefineEvent`
63+
* `DefineMethodImpl` - only on new types
64+
* `DefineMethodSpec`
65+
66+
67+
There are still some metadata changes that are definitely illegal and will almost certainly never become legal due to restrictions/assumptions existing in the runtime:
68+
* Adding a virtual method to an existing type
69+
* Adding a field to an existing type
70+
71+
Anything not listed as either legal or illegal is untested and should not be assumed to work.

Documentation/Profiling/davbr-blog-archive/Attach.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*This blog post originally appeared on David Broman's blog on 11/4/2009*
22

3+
***[Update 5/30/19]: The archived content below refers to an Attach mechanism that only worked on desktop, not on .Net Core. Please see [Profiler Attach on CoreCLR](../Profiler Attach on Coreclr.md) for profiler attach on CoreCLR***
4+
35

46
Profiler attach is a feature that allows you to attach a profiler to an already running process. The usefulness of this is fairly obvious to anyone who's ever attached a debugger to a running-process: It's helpful when diagnosing hard-to-reproduce problems, and particularly useful when encountering issues in production.
57

Documentation/Profiling/davbr-blog-archive/Attach2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*This blog post originally appeared on David Broman's blog on 1/18/2010*
22

3+
***[Update 5/30/19]: The archived content below refers to an Attach mechanism that only worked on desktop, not on .Net Core. Please see [Profiler Attach on CoreCLR](../Profiler Attach on Coreclr.md) for profiler attach on CoreCLR***
34

45
In a previous [post](Attach.md), I outlined to all you profiler writers how to modify your profiler so it can attach to running processes, and what sorts of limitations your profiler will have when it attaches. In this post, I answer the question, “My profiler is attached. What should it do next?”
56

0 commit comments

Comments
 (0)