2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . Diagnostics . CodeAnalysis ;
5
- using System . IO ;
6
5
using System . Linq ;
7
6
using System . Management ;
8
7
using System . Reflection ;
9
8
using System . Runtime . InteropServices ;
10
9
using System . Text . RegularExpressions ;
11
10
using BenchmarkDotNet . Detectors ;
12
- using BenchmarkDotNet . Detectors . Cpu ;
13
11
using BenchmarkDotNet . Environments ;
14
12
using BenchmarkDotNet . Extensions ;
15
13
using BenchmarkDotNet . Helpers ;
16
- using JetBrains . Annotations ;
17
- using Microsoft . Win32 ;
18
- using Perfolizer . Helpers ;
19
14
using static System . Runtime . InteropServices . RuntimeInformation ;
20
- using RuntimeEnvironment = Microsoft . DotNet . PlatformAbstractions . RuntimeEnvironment ;
21
15
22
16
namespace BenchmarkDotNet . Portability
23
17
{
@@ -48,26 +42,15 @@ internal static class RuntimeInformation
48
42
FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) ;
49
43
#endif
50
44
51
- public static readonly bool IsNetNative = FrameworkDescription . StartsWith ( ".NET Native" , StringComparison . OrdinalIgnoreCase ) ;
52
-
53
- public static readonly bool IsNetCore =
54
- ( ( Environment . Version . Major >= 5 ) || FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) )
55
- && ! string . IsNullOrEmpty ( typeof ( object ) . Assembly . Location ) ;
56
-
57
45
#if NET6_0_OR_GREATER
58
46
[ System . Runtime . Versioning . SupportedOSPlatformGuard ( "browser" ) ]
59
47
public static readonly bool IsWasm = OperatingSystem . IsBrowser ( ) ;
60
48
#else
61
49
public static readonly bool IsWasm = IsOSPlatform ( OSPlatform . Create ( "BROWSER" ) ) ;
62
50
#endif
63
51
64
- public static readonly bool IsNativeAOT =
65
- Environment . Version . Major >= 5
66
- && string . IsNullOrEmpty ( typeof ( object ) . Assembly . Location ) // it's merged to a single .exe and .Location returns null
67
- && ! IsWasm ; // Wasm also returns "" for assembly locations
68
-
69
52
#if NETSTANDARD2_0
70
- public static readonly bool IsAot = IsAotMethod ( ) ;
53
+ public static readonly bool IsAot = IsAotMethod ( ) || FrameworkDescription . StartsWith ( ".NET Native" , StringComparison . OrdinalIgnoreCase ) ;
71
54
72
55
private static bool IsAotMethod ( )
73
56
{
@@ -88,6 +71,16 @@ private static bool IsAotMethod()
88
71
public static readonly bool IsAot = ! System . Runtime . CompilerServices . RuntimeFeature . IsDynamicCodeCompiled ;
89
72
#endif
90
73
74
+ public static bool IsNetCore
75
+ => ( ( Environment . Version . Major >= 5 ) || FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) )
76
+ && ! IsAot ;
77
+
78
+ public static bool IsNativeAOT
79
+ => Environment . Version . Major >= 5
80
+ && IsAot
81
+ && ! IsWasm && ! IsMono ; // Wasm and MonoAOTLLVM are also AOT
82
+
83
+
91
84
public static readonly bool IsTieredJitEnabled =
92
85
IsNetCore
93
86
&& ( Environment . Version . Major < 3
@@ -171,24 +164,21 @@ private static string GetNetCoreVersion()
171
164
{
172
165
return $ ".NET { Environment . Version } ";
173
166
}
174
- else
175
- {
176
- var coreclrAssemblyInfo = FileVersionInfo . GetVersionInfo ( typeof ( object ) . GetTypeInfo ( ) . Assembly . Location ) ;
177
- var corefxAssemblyInfo = FileVersionInfo . GetVersionInfo ( typeof ( Regex ) . GetTypeInfo ( ) . Assembly . Location ) ;
178
167
179
- if ( CoreRuntime . TryGetVersion ( out var version ) && version >= new Version ( 5 , 0 ) )
180
- {
181
- // after the merge of dotnet/corefx and dotnet/coreclr into dotnet/runtime the version should always be the same
182
- Debug . Assert ( coreclrAssemblyInfo . FileVersion == corefxAssemblyInfo . FileVersion ) ;
183
-
184
- return $ ".NET { version } ({ coreclrAssemblyInfo . FileVersion } )";
185
- }
186
- else
187
- {
188
- string runtimeVersion = version != default ? version . ToString ( ) : Unknown ;
168
+ return CoreRuntime . TryGetVersion ( out var version ) && version . Major >= 5
169
+ ? $ ".NET { version } ({ GetDetailedVersion ( ) } )"
170
+ : $ ".NET Core { version ? . ToString ( ) ?? Unknown } ({ GetDetailedVersion ( ) } )";
189
171
190
- return $ ".NET Core { runtimeVersion } (CoreCLR { coreclrAssemblyInfo . FileVersion } , CoreFX { corefxAssemblyInfo . FileVersion } )";
191
- }
172
+ string GetDetailedVersion ( )
173
+ {
174
+ string coreclrLocation = typeof ( object ) . GetTypeInfo ( ) . Assembly . Location ;
175
+ // Single-file publish has empty assembly location.
176
+ if ( string . IsNullOrEmpty ( coreclrLocation ) )
177
+ return CoreRuntime . GetVersionFromFrameworkDescription ( ) ;
178
+ // .Net Core 2.X has confusing FrameworkDescription like 4.6.X.
179
+ if ( version ? . Major >= 3 )
180
+ return $ "{ CoreRuntime . GetVersionFromFrameworkDescription ( ) } , { FileVersionInfo . GetVersionInfo ( coreclrLocation ) . FileVersion } ";
181
+ return FileVersionInfo . GetVersionInfo ( coreclrLocation ) . FileVersion ;
192
182
}
193
183
}
194
184
@@ -271,7 +261,7 @@ internal static string GetJitInfo()
271
261
{
272
262
if ( IsNativeAOT )
273
263
return "NativeAOT" ;
274
- if ( IsNetNative || IsAot )
264
+ if ( IsAot )
275
265
return "AOT" ;
276
266
if ( IsMono || IsWasm )
277
267
return "" ; // There is no helpful information about JIT on Mono
0 commit comments